From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/web/swat.c | 343 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 290 insertions(+), 53 deletions(-) (limited to 'source3/web') diff --git a/source3/web/swat.c b/source3/web/swat.c index 80d3232d2b..af6fa82ffe 100644 --- a/source3/web/swat.c +++ b/source3/web/swat.c @@ -1,7 +1,9 @@ /* Unix SMB/CIFS implementation. Samba Web Administration Tool - Copyright (C) Andrew Tridgell 1997-1998 + Version 3.0.0 + Copyright (C) Andrew Tridgell 1997-2002 + Copyright (C) John H Terpstra 2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -297,7 +299,7 @@ static void show_parameter(int snum, struct parm_struct *parm) /**************************************************************************** display a set of parameters for a service ****************************************************************************/ -static void show_parameters(int snum, int allparameters, int advanced, int printers) +static void show_parameters(int snum, int allparameters, unsigned int parm_filter, int printers) { int i = 0; struct parm_struct *parm; @@ -316,7 +318,7 @@ static void show_parameters(int snum, int allparameters, int advanced, int print if (printers & !(parm->flags & FLAG_PRINT)) continue; if (!printers & !(parm->flags & FLAG_SHARE)) continue; } - if (!advanced) { + if (parm_filter == FLAG_BASIC) { if (!(parm->flags & FLAG_BASIC)) { void *ptr = parm->ptr; @@ -363,6 +365,12 @@ static void show_parameters(int snum, int allparameters, int advanced, int print } if (printers && !(parm->flags & FLAG_PRINT)) continue; } + if (parm_filter == FLAG_WIZARD) { + if (!((parm->flags & FLAG_WIZARD))) continue; + } + if (parm_filter == FLAG_ADVANCED) { + if (!((parm->flags & FLAG_ADVANCED))) continue; + } if (heading && heading != last_heading) { d_printf("%s\n", _(heading)); last_heading = heading; @@ -393,7 +401,7 @@ static void write_config(FILE *f, BOOL show_defaults) } /**************************************************************************** - save and reoad the smb.conf config file + save and reload the smb.conf config file ****************************************************************************/ static int save_reload(int snum) { @@ -497,6 +505,7 @@ static void show_main_buttons(void) image_link(_("Globals"), "globals", "images/globals.gif"); image_link(_("Shares"), "shares", "images/shares.gif"); image_link(_("Printers"), "printers", "images/printers.gif"); + image_link(_("Wizard"), "wizard", "images/wizard.gif"); } if (have_read_access) { image_link(_("Status"), "status", "images/status.gif"); @@ -507,6 +516,18 @@ static void show_main_buttons(void) d_printf("
\n"); } +/**************************************************************************** + * Handle Display/Edit Mode CGI + ****************************************************************************/ +static void ViewModeBoxes(int mode) +{ + d_printf("

%s\n", _("Configuration View: ")); + d_printf("Basic\n", (mode == 0) ? "checked" : ""); + d_printf("Advanced\n", (mode == 1) ? "checked" : ""); + d_printf("Developer\n", (mode == 2) ? "checked" : ""); + d_printf("


\n"); +} + /**************************************************************************** display a welcome page ****************************************************************************/ @@ -541,25 +562,240 @@ static void viewconfig_page(void) d_printf("\n"); } +/**************************************************************************** + second screen of the wizard ... Fetch Configuration Parameters +****************************************************************************/ +static void wizard_params_page(void) +{ + unsigned int parm_filter = FLAG_WIZARD; + + /* Here we first set and commit all the parameters that were selected + in the previous screen. */ + + d_printf("

Wizard Parameter Edit Page

\n"); + + if (cgi_variable("Commit")) { + commit_parameters(GLOBALS_SNUM); + save_reload(0); + } + + d_printf("
\n"); + + if (have_write_access) { + d_printf("\n"); + } + + d_printf("\n"); + d_printf("

\n"); + + d_printf("\n"); + show_parameters(GLOBALS_SNUM, 1, parm_filter, 0); + d_printf("
\n"); + d_printf("

\n"); +} + +/**************************************************************************** + Utility to just rewrite the smb.conf file - effectively just cleans it up +****************************************************************************/ +static void rewritecfg_file(void) +{ + commit_parameters(GLOBALS_SNUM); + save_reload(0); + d_printf("

Note: smb.conf %s

\n", _("file has been read and rewritten")); +} + +/**************************************************************************** + wizard to create/modify the smb.conf file +****************************************************************************/ +static void wizard_page(void) +{ + /* Set some variables to collect data from smb.conf */ + int role = 0; + int winstype = 0; + int have_home = -1; + int HomeExpo = 0; + int SerType = 0; + + if (cgi_variable("Rewrite")) { + (void) rewritecfg_file(); + return; + } + + if (cgi_variable("GetWizardParams")){ + (void) wizard_params_page(); + return; + } + + if (cgi_variable("Commit")){ + SerType = atoi(cgi_variable("ServerType")); + winstype = atoi(cgi_variable("WINSType")); + have_home = lp_servicenumber(HOMES_NAME); + HomeExpo = atoi(cgi_variable("HomeExpo")); + + /* Plain text passwords are too badly broken - use encrypted passwords only */ + lp_do_parameter( GLOBALS_SNUM, "encrypt passwords", "Yes"); + + switch ( SerType ){ + case 0: + /* Stand-alone Server */ + lp_do_parameter( GLOBALS_SNUM, "security", "USER" ); + lp_do_parameter( GLOBALS_SNUM, "domain logons", "No" ); + break; + case 1: + /* Domain Member */ + lp_do_parameter( GLOBALS_SNUM, "security", "DOMAIN" ); + lp_do_parameter( GLOBALS_SNUM, "domain logons", "No" ); + break; + case 2: + /* Domain Controller */ + lp_do_parameter( GLOBALS_SNUM, "security", "USER" ); + lp_do_parameter( GLOBALS_SNUM, "domain logons", "Yes" ); + break; + } + switch ( winstype ) { + case 0: + lp_do_parameter( GLOBALS_SNUM, "wins support", "No" ); + lp_do_parameter( GLOBALS_SNUM, "wins server", "" ); + break; + case 1: + lp_do_parameter( GLOBALS_SNUM, "wins support", "Yes" ); + lp_do_parameter( GLOBALS_SNUM, "wins server", "" ); + break; + case 2: + lp_do_parameter( GLOBALS_SNUM, "wins support", "No" ); + lp_do_parameter( GLOBALS_SNUM, "wins server", cgi_variable("WINSAddr")); + break; + } + + /* Have to create Homes share? */ + if ((HomeExpo == 1) && (have_home == -1)) { + pstring unix_share; + + pstrcpy(unix_share,HOMES_NAME); + load_config(False); + lp_copy_service(GLOBALS_SNUM, unix_share); + iNumNonAutoPrintServices = lp_numservices(); + have_home = lp_servicenumber(HOMES_NAME); + lp_do_parameter( have_home, "read only", "No"); + lp_do_parameter( have_home, "valid users", "%S"); + lp_do_parameter( have_home, "browseable", "No"); + commit_parameters(have_home); + } + + /* Need to Delete Homes share? */ + if ((HomeExpo == 0) && (have_home != -1)) { + lp_remove_service(have_home); + have_home = -1; + } + + commit_parameters(GLOBALS_SNUM); + save_reload(0); + } + else + { + /* Now determine smb.conf WINS settings */ + if (lp_wins_support()) + winstype = 1; +/* if (strlen(lp_wins_server_list()) != 0 ) + * winstype = 2; + */ + + /* Do we have a homes share? */ + have_home = lp_servicenumber(HOMES_NAME); + } + if ((winstype == 2) && lp_wins_support()) + winstype = 3; + + role = lp_server_role(); + + /* Here we go ... */ + d_printf("

Samba Configuration Wizard

\n"); + d_printf("
\n"); + + if (have_write_access) { + d_printf(_("The \"Rewrite smb.conf file\" button will clear the smb.conf file of all default values and of comments.\n")); + d_printf(_("The same will happen if you press the commit button.")); + d_printf("

"); + d_printf("
"); + d_printf("   ",_("Rewrite smb.conf file")); + d_printf("   ",_("Commit")); + d_printf("", _("Edit Parameter Values")); + d_printf("
"); + } + + d_printf("
"); + d_printf("
"); + d_printf("\n", "Server Type: "); + d_printf("", (role == ROLE_STANDALONE) ? "checked" : ""); + d_printf("", (role == ROLE_DOMAIN_MEMBER) ? "checked" : ""); + d_printf("", (role == ROLE_DOMAIN_PDC) ? "checked" : ""); + d_printf(""); + if (role == ROLE_DOMAIN_BDC) { + d_printf(""); + } + d_printf("\n", "Configure WINS As: "); + d_printf("", (winstype == 0) ? "checked" : ""); + d_printf("", (winstype == 1) ? "checked" : ""); + d_printf("", (winstype == 2) ? "checked" : ""); + d_printf("",lp_wins_server_list()); + if (winstype == 3) { + d_printf(""); + d_printf(""); + } + d_printf(""); + d_printf("\n","Expose Home Directories: "); + d_printf("", (have_home == -1) ? "" : "checked "); + d_printf("", (have_home == -1 ) ? "checked" : ""); + d_printf(""); + + /* Enable this when we are ready .... + * d_printf("\n","Is Print Server: "); + * d_printf(""); + * d_printf(""); + * d_printf(""); + */ + + d_printf("
%s Stand Alone  Domain Member  Domain Controller 
Unusual Type in smb.conf - Please Select New Mode
%s Not Used  Server for client use  Client of another WINS server 
Remote WINS Server 
Error: WINS Server Mode and WINS Support both set in smb.conf
Please Select desired WINS mode above.
%s Yes No
%s Yes No
"); + d_printf("
"); + + d_printf(_("The above configuration options will set multiple parameters and will generally assist with rapid Samba deployment.\n")); + d_printf("
\n"); +} + + /**************************************************************************** display a globals editing page ****************************************************************************/ static void globals_page(void) { - int advanced = 0; + unsigned int parm_filter = FLAG_BASIC; + int mode = 0; d_printf("

%s

\n", _("Global Variables")); - if (cgi_variable("Advanced") && !cgi_variable("Basic")) - advanced = 1; - if (cgi_variable("Commit")) { commit_parameters(GLOBALS_SNUM); save_reload(0); } - d_printf("
\n"); - + if ( cgi_variable("ViewMode") ) + mode = atoi(cgi_variable("ViewMode")); + + d_printf("\n"); + + ViewModeBoxes( mode ); + switch ( mode ) { + case 0: + parm_filter = FLAG_BASIC; + break; + case 1: + parm_filter = FLAG_ADVANCED; + break; + case 2: + parm_filter = FLAG_DEVELOPER; + break; + } + d_printf("
\n"); if (have_write_access) { d_printf("\n", _("Commit Changes")); @@ -567,22 +803,12 @@ static void globals_page(void) d_printf("\n", _("Reset Values")); - if (advanced == 0) { - d_printf("\n", _("Advanced View")); - } else { - d_printf("\n", _("Basic View")); - } + d_printf("

\n"); - d_printf("\n"); - show_parameters(GLOBALS_SNUM, 1, advanced, 0); + show_parameters(GLOBALS_SNUM, 1, parm_filter, 0); d_printf("
\n"); - - if (advanced) { - d_printf("\n"); - } - - d_printf("

\n"); + d_printf("\n"); } /**************************************************************************** @@ -595,16 +821,14 @@ static void shares_page(void) char *s; int snum = -1; int i; - int advanced = 0; + int mode = 0; + unsigned int parm_filter = FLAG_BASIC; if (share) snum = lp_servicenumber(share); d_printf("

%s

\n", _("Share Parameters")); - if (cgi_variable("Advanced") && !cgi_variable("Basic")) - advanced = 1; - if (cgi_variable("Commit") && snum >= 0) { commit_parameters(snum); save_reload(0); @@ -628,7 +852,21 @@ static void shares_page(void) d_printf("
\n"); d_printf("\n"); - d_printf("\n"); + if ( cgi_variable("ViewMode") ) + mode = atoi(cgi_variable("ViewMode")); + ViewModeBoxes( mode ); + switch ( mode ) { + case 0: + parm_filter = FLAG_BASIC; + break; + case 1: + parm_filter = FLAG_ADVANCED; + break; + case 2: + parm_filter = FLAG_DEVELOPER; + break; + } + d_printf("
\n"); d_printf("\n", _("Choose Share")); d_printf("
\n", _("Reset Values")); - if (advanced == 0) { - d_printf("\n", _("Advanced View")); - } else { - d_printf("\n", _("Basic View")); - } d_printf("

\n"); } if (snum >= 0) { d_printf("\n"); - show_parameters(snum, 1, advanced, 0); + show_parameters(snum, 1, parm_filter, 0); d_printf("
\n"); } - if (advanced) { - d_printf("\n"); - } - d_printf("\n"); } @@ -922,7 +1151,8 @@ static void printers_page(void) char *s; int snum=-1; int i; - int advanced = 0; + int mode = 0; + unsigned int parm_filter = FLAG_BASIC; if (share) snum = lp_servicenumber(share); @@ -935,9 +1165,6 @@ static void printers_page(void) d_printf("%s\n", _("Printcap Name")); d_printf(_("Attempting to delete these printers from SWAT will have no effect.\n")); - if (cgi_variable("Advanced") && !cgi_variable("Basic")) - advanced = 1; - if (cgi_variable("Commit") && snum >= 0) { commit_parameters(snum); if (snum >= iNumNonAutoPrintServices) @@ -965,6 +1192,20 @@ static void printers_page(void) d_printf("

\n"); + if ( cgi_variable("ViewMode") ) + mode = atoi(cgi_variable("ViewMode")); + ViewModeBoxes( mode ); + switch ( mode ) { + case 0: + parm_filter = FLAG_BASIC; + break; + case 1: + parm_filter = FLAG_ADVANCED; + break; + case 2: + parm_filter = FLAG_DEVELOPER; + break; + } d_printf("\n"); d_printf("\n", _("Choose Printer")); d_printf("
\n", _("Commit Changes")); } d_printf("\n", _("Reset Values")); - if (advanced == 0) { - d_printf("\n", _("Advanced View")); - } else { - d_printf("\n", _("Basic View")); - } d_printf("

\n"); } if (snum >= 0) { d_printf("\n"); - show_parameters(snum, 1, advanced, 1); + show_parameters(snum, 1, parm_filter, 1); d_printf("
\n"); } - - if (advanced) { - d_printf("\n"); - } - d_printf("\n"); } @@ -1109,6 +1340,12 @@ static void printers_page(void) viewconfig_page(); } else if (strcmp(page,"passwd")==0) { passwd_page(); + } else if (have_read_access && strcmp(page,"wizard")==0) { + wizard_page(); + } else if (have_read_access && strcmp(page,"wizard_params")==0) { + wizard_params_page(); + } else if (have_read_access && strcmp(page,"rewritecfg")==0) { + rewritecfg_file(); } else { welcome_page(); } -- cgit