swat.c
来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 1,435 行 · 第 1/3 页
C
1,435 行
return 1;}/**************************************************************************** commit one parameter ****************************************************************************/static void commit_parameter(int snum, struct parm_struct *parm, const char *v){ int i; char *s; if (snum < 0 && parm->p_class == P_LOCAL) { /* this handles the case where we are changing a local variable globally. We need to change the parameter in all shares where it is currently set to the default */ for (i=0;i<lp_numservices();i++) { s = lp_servicename(i); if (s && (*s) && lp_is_default(i, parm)) { lp_do_parameter(i, parm->label, v); } } } lp_do_parameter(snum, parm->label, v);}/**************************************************************************** commit a set of parameters for a service ****************************************************************************/static void commit_parameters(int snum){ int i = 0; struct parm_struct *parm; pstring label; const char *v; while ((parm = lp_next_parameter(snum, &i, 1))) { slprintf(label, sizeof(label)-1, "parm_%s", make_parm_name(parm->label)); if ((v = cgi_variable(label))) { if (parm->flags & FLAG_HIDE) continue; commit_parameter(snum, parm, v); } }}/**************************************************************************** spit out the html for a link with an image ****************************************************************************/static void image_link(const char *name, const char *hlink, const char *src){ printf("<A HREF=\"%s/%s\"><img border=\"0\" src=\"/swat/%s\" alt=\"%s\"></A>\n", cgi_baseurl(), hlink, src, name);}/**************************************************************************** display the main navigation controls at the top of each page along with a title ****************************************************************************/static void show_main_buttons(void){ char *p; if ((p = cgi_user_name()) && strcmp(p, "root")) { printf(_("Logged in as <b>%s</b>"), p); printf("<p>\n"); } image_link(_("Home"), "", "images/home.gif"); if (have_write_access) { 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"); } /* root always gets all buttons, otherwise look for -P */ if ( have_write_access || (!passwd_only && have_read_access) ) { image_link(_("Status"), "status", "images/status.gif"); image_link(_("View Config"), "viewconfig", "images/viewconfig.gif"); } image_link(_("Password Management"), "passwd", "images/passwd.gif"); printf("<HR>\n");}/**************************************************************************** * Handle Display/Edit Mode CGI ****************************************************************************/static void ViewModeBoxes(int mode){ printf("<p>%s: \n", _("Current View Is")); printf("<input type=radio name=\"ViewMode\" value=0 %s>%s\n", ((mode == 0) ? "checked" : ""), _("Basic")); printf("<input type=radio name=\"ViewMode\" value=1 %s>%s\n", ((mode == 1) ? "checked" : ""), _("Advanced")); printf("<br>%s: \n", _("Change View To")); printf("<input type=submit name=\"BasicMode\" value=\"%s\">\n", _("Basic")); printf("<input type=submit name=\"AdvMode\" value=\"%s\">\n", _("Advanced")); printf("</p><br>\n");}/**************************************************************************** display a welcome page ****************************************************************************/static void welcome_page(void){ if (file_exist("help/welcome.html", NULL)) { include_html("help/welcome.html"); } else { include_html("help/welcome-no-samba-doc.html"); }}/**************************************************************************** display the current smb.conf ****************************************************************************/static void viewconfig_page(void){ int full_view=0; if (cgi_variable("full_view")) { full_view = 1; } printf("<H2>%s</H2>\n", _("Current Config")); printf("<form method=post>\n"); if (full_view) { printf("<input type=submit name=\"normal_view\" value=\"%s\">\n", _("Normal View")); } else { printf("<input type=submit name=\"full_view\" value=\"%s\">\n", _("Full View")); } printf("<p><pre>"); write_config(stdout, full_view); printf("</pre>"); printf("</form>\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. */ printf("<H2>%s</H2>\n", _("Wizard Parameter Edit Page")); if (cgi_variable("Commit")) { commit_parameters(GLOBAL_SECTION_SNUM); save_reload(0); } printf("<form name=\"swatform\" method=post action=wizard_params>\n"); if (have_write_access) { printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n"); } printf("<input type=reset name=\"Reset Values\" value=\"Reset\">\n"); printf("<p>\n"); printf("<table>\n"); show_parameters(GLOBAL_SECTION_SNUM, 1, parm_filter, 0); printf("</table>\n"); printf("</form>\n");}/**************************************************************************** Utility to just rewrite the smb.conf file - effectively just cleans it up****************************************************************************/static void rewritecfg_file(void){ commit_parameters(GLOBAL_SECTION_SNUM); save_reload(0); printf("<H2>%s</H2>\n", _("Note: smb.conf 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( GLOBAL_SECTION_SNUM, "encrypt passwords", "Yes"); switch ( SerType ){ case 0: /* Stand-alone Server */ lp_do_parameter( GLOBAL_SECTION_SNUM, "security", "USER" ); lp_do_parameter( GLOBAL_SECTION_SNUM, "domain logons", "No" ); break; case 1: /* Domain Member */ lp_do_parameter( GLOBAL_SECTION_SNUM, "security", "DOMAIN" ); lp_do_parameter( GLOBAL_SECTION_SNUM, "domain logons", "No" ); break; case 2: /* Domain Controller */ lp_do_parameter( GLOBAL_SECTION_SNUM, "security", "USER" ); lp_do_parameter( GLOBAL_SECTION_SNUM, "domain logons", "Yes" ); break; } switch ( winstype ) { case 0: lp_do_parameter( GLOBAL_SECTION_SNUM, "wins support", "No" ); lp_do_parameter( GLOBAL_SECTION_SNUM, "wins server", "" ); break; case 1: lp_do_parameter( GLOBAL_SECTION_SNUM, "wins support", "Yes" ); lp_do_parameter( GLOBAL_SECTION_SNUM, "wins server", "" ); break; case 2: lp_do_parameter( GLOBAL_SECTION_SNUM, "wins support", "No" ); lp_do_parameter( GLOBAL_SECTION_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(GLOBAL_SECTION_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(GLOBAL_SECTION_SNUM); save_reload(0); } else { /* Now determine smb.conf WINS settings */ if (lp_wins_support()) winstype = 1; if (lp_wins_server_list() && strlen(*lp_wins_server_list())) 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 ... */ printf("<H2>%s</H2>\n", _("Samba Configuration Wizard")); printf("<form method=post action=wizard>\n"); if (have_write_access) { printf("%s\n", _("The \"Rewrite smb.conf file\" button will clear the smb.conf file of all default values and of comments.")); printf("%s", _("The same will happen if you press the commit button.")); printf("<br><br>\n"); printf("<center>"); printf("<input type=submit name=\"Rewrite\" value=\"%s\"> ",_("Rewrite smb.conf file")); printf("<input type=submit name=\"Commit\" value=\"%s\"> ",_("Commit")); printf("<input type=submit name=\"GetWizardParams\" value=\"%s\">", _("Edit Parameter Values")); printf("</center>\n"); } printf("<hr>"); printf("<center><table border=0>"); printf("<tr><td><b>%s: </b></td>\n", _("Server Type")); printf("<td><input type=radio name=\"ServerType\" value=\"0\" %s> %s </td>", ((role == ROLE_STANDALONE) ? "checked" : ""), _("Stand Alone")); printf("<td><input type=radio name=\"ServerType\" value=\"1\" %s> %s </td>", ((role == ROLE_DOMAIN_MEMBER) ? "checked" : ""), _("Domain Member")); printf("<td><input type=radio name=\"ServerType\" value=\"2\" %s> %s </td>", ((role == ROLE_DOMAIN_PDC) ? "checked" : ""), _("Domain Controller")); printf("</tr>\n"); if (role == ROLE_DOMAIN_BDC) { printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Unusual Type in smb.conf - Please Select New Mode")); } printf("<tr><td><b>%s: </b></td>\n", _("Configure WINS As")); printf("<td><input type=radio name=\"WINSType\" value=\"0\" %s> %s </td>", ((winstype == 0) ? "checked" : ""), _("Not Used")); printf("<td><input type=radio name=\"WINSType\" value=\"1\" %s> %s </td>", ((winstype == 1) ? "checked" : ""), _("Server for client use")); printf("<td><input type=radio name=\"WINSType\" value=\"2\" %s> %s </td>", ((winstype == 2) ? "checked" : ""), _("Client of another WINS server")); printf("</tr>\n"); printf("<tr><td></td><td></td><td></td><td>%s <input type=text size=\"16\" name=\"WINSAddr\" value=\"", _("Remote WINS Server")); /* Print out the list of wins servers */ if(lp_wins_server_list()) { int i; const char **wins_servers = lp_wins_server_list(); for(i = 0; wins_servers[i]; i++) printf("%s ", wins_servers[i]); } printf("\"></td></tr>\n"); if (winstype == 3) { printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Error: WINS Server Mode and WINS Support both set in smb.conf")); printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Please Select desired WINS mode above.")); } printf("<tr><td><b>%s: </b></td>\n", _("Expose Home Directories")); printf("<td><input type=radio name=\"HomeExpo\" value=\"1\" %s> Yes</td>", (have_home == -1) ? "" : "checked "); printf("<td><input type=radio name=\"HomeExpo\" value=\"0\" %s> No</td>", (have_home == -1 ) ? "checked" : ""); printf("<td></td></tr>\n"); /* Enable this when we are ready .... * printf("<tr><td><b>%s: </b></td>\n", _("Is Print Server")); * printf("<td><input type=radio name=\"PtrSvr\" value=\"1\" %s> Yes</td>"); * printf("<td><input type=radio name=\"PtrSvr\" value=\"0\" %s> No</td>"); * printf("<td></td></tr>\n"); */ printf("</table></center>"); printf("<hr>"); printf("%s\n", _("The above configuration options will set multiple parameters and will generally assist with rapid Samba deployment.")); printf("</form>\n");}/**************************************************************************** display a globals editing page ****************************************************************************/static void globals_page(void){ unsigned int parm_filter = FLAG_BASIC; int mode = 0; printf("<H2>%s</H2>\n", _("Global Parameters")); if (cgi_variable("Commit")) { commit_parameters(GLOBAL_SECTION_SNUM); save_reload(0); } if ( cgi_variable("ViewMode") ) mode = atoi(cgi_variable("ViewMode")); if ( cgi_variable("BasicMode")) mode = 0; if ( cgi_variable("AdvMode")) mode = 1; printf("<form name=\"swatform\" method=post action=globals>\n"); ViewModeBoxes( mode ); switch ( mode ) { case 0: parm_filter = FLAG_BASIC; break; case 1: parm_filter = FLAG_ADVANCED; break; } printf("<br>\n"); if (have_write_access) { printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes")); } printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values")); printf("<p>\n"); printf("<table>\n"); show_parameters(GLOBAL_SECTION_SNUM, 1, parm_filter, 0); printf("</table>\n"); printf("</form>\n");}/**************************************************************************** display a shares editing page. share is in unix codepage, ****************************************************************************/static void shares_page(void){ const char *share = cgi_variable("share"); char *s; char *utf8_s; int snum = -1; int i; int mode = 0; unsigned int parm_filter = FLAG_BASIC; if (share) snum = lp_servicenumber(share); printf("<H2>%s</H2>\n", _("Share Parameters")); if (cgi_variable("Commit") && snum >= 0) { commit_parameters(snum); save_reload(0); } if (cgi_variable("Delete") && snum >= 0) { lp_remove_service(snum); save_reload(0); share = NULL; snum = -1; } if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) { load_config(False); lp_copy_service(GLOBAL_SECTION_SNUM, share); iNumNonAutoPrintServices = lp_numservices(); save_reload(0); snum = lp_servicenumber(share); } printf("<FORM name=\"swatform\" method=post>\n"); printf("<table>\n"); if ( cgi_variable("ViewMode") ) mode = atoi(cgi_variable("ViewMode")); if ( cgi_variable("BasicMode")) mode = 0; if ( cgi_variable("AdvMode")) mode = 1; ViewModeBoxes( mode ); switch ( mode ) { case 0: parm_filter = FLAG_BASIC; break; case 1: parm_filter = FLAG_ADVANCED; break; } printf("<br><tr>\n"); printf("<td><input type=submit name=selectshare value=\"%s\"></td>\n", _("Choose Share")); printf("<td><select name=share>\n"); if (snum < 0) printf("<option value=\" \"> \n"); for (i=0;i<lp_numservices();i++) { s = lp_servicename(i); if (s && (*s) && strcmp(s,"IPC$") && !lp_print_ok(i)) { push_utf8_allocate(&utf8_s, s); printf("<option %s value=\"%s\">%s\n", (share && strcmp(share,s)==0)?"SELECTED":"", utf8_s, utf8_s); SAFE_FREE(utf8_s); } } printf("</select></td>\n"); if (have_write_access) { printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Share")); } printf("</tr>\n"); printf("</table>"); printf("<table>"); if (have_write_access) { printf("<tr>\n"); printf("<td><input type=submit name=createshare value=\"%s\"></td>\n", _("Create Share"));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?