2 Unix SMB/Netbios implementation.
4 Samba Web Administration Tool
5 Copyright (C) Andrew Tridgell 1997-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #define GLOBALS_SNUM -1
32 static pstring servicesf = CONFIGFILE;
33 static BOOL demo_mode = False;
34 static BOOL have_write_access = False;
35 static BOOL have_read_access = False;
36 static int iNumNonAutoPrintServices = 0;
39 * Password Management Globals
41 #define SWAT_USER "username"
42 #define OLD_PSWD "old_passwd"
43 #define NEW_PSWD "new_passwd"
44 #define NEW2_PSWD "new2_passwd"
45 #define CHG_S_PASSWD_FLAG "chg_s_passwd_flag"
46 #define CHG_R_PASSWD_FLAG "chg_r_passwd_flag"
47 #define ADD_USER_FLAG "add_user_flag"
48 #define DELETE_USER_FLAG "delete_user_flag"
49 #define DISABLE_USER_FLAG "disable_user_flag"
50 #define ENABLE_USER_FLAG "enable_user_flag"
51 #define RHOST "remote_host"
53 /* we need these because we link to locking*.o */
54 void become_root(void) {}
55 void unbecome_root(void) {}
57 /****************************************************************************
58 ****************************************************************************/
59 static int enum_index(int value, struct enum_list *enumlist)
62 for (i=0;enumlist[i].name;i++)
63 if (value == enumlist[i].value) break;
67 static char *fix_backslash(char *str)
69 static char newstring[1024];
73 if (*str == '\\') {*p++ = '\\';*p++ = '\\';}
81 static char *stripspace(char *str)
83 static char newstring[1024];
87 if (*str != ' ') *p++ = *str;
94 static char *make_parm_name(char *label)
96 static char parmname[1024];
100 if (*label == ' ') *p++ = '_';
108 /****************************************************************************
109 include a lump of html in a page
110 ****************************************************************************/
111 static int include_html(char *fname)
117 f = sys_fopen((char*)LN_(fname), "r");
120 d_printf(_("ERROR: Can't open %s\n"), fname);
125 ret = fread(buf, 1, sizeof(buf), f);
127 fwrite(buf, 1, ret, stdout);
134 /****************************************************************************
135 start the page with standard stuff
136 ****************************************************************************/
137 static void print_header(void)
139 if (!cgi_waspost()) {
140 d_printf("Expires: 0\r\n");
142 d_printf("Content-type: text/html\r\n\r\n");
144 if (!include_html("include/header.html")) {
145 d_printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
146 d_printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY background=\"/swat/images/background.jpg\">\n\n");
150 /* *******************************************************************
151 show parameter label with translated name in the following form
152 because showing original and translated label in one line looks
153 too long, and showing translated label only is unusable for
155 -------------------------------
156 HELP security [combo box][button]
158 -------------------------------
159 (capital words are translated by gettext.)
160 if no translation is available, then same form as original is
162 "i18n_translated_parm" class is used to change the color of the
163 translated parameter with CSS.
164 **************************************************************** */
165 static const char* get_parm_translated(
166 const char* pAnchor, const char* pHelp, const char* pLabel)
168 const char* pTranslated = _(pLabel);
169 static pstring output;
170 if(strcmp(pLabel, pTranslated) != 0)
172 snprintf(output, sizeof(output),
173 "<A HREF=\"/swat/help/smb.conf.5.html#%s\" target=\"docs\"> %s</A> %s <br><span class=\"i18n_translated_parm\">%s</span>",
174 pAnchor, pHelp, pLabel, pTranslated);
177 snprintf(output, sizeof(output),
178 "<A HREF=\"/swat/help/smb.conf.5.html#%s\" target=\"docs\"> %s</A> %s",
179 pAnchor, pHelp, pLabel);
182 /****************************************************************************
184 ****************************************************************************/
185 static void print_footer(void)
187 if (!include_html("include/footer.html")) {
188 d_printf("\n</BODY>\n</HTML>\n");
192 /****************************************************************************
193 display one editable parameter in a form
194 ****************************************************************************/
195 static void show_parameter(int snum, struct parm_struct *parm)
198 void *ptr = parm->ptr;
200 if (parm->class == P_LOCAL && snum >= 0) {
201 ptr = lp_local_ptr(snum, ptr);
204 printf("<tr><td>%s</td><td>", get_parm_translated(stripspace(parm->label), _("Help"), parm->label));
205 switch (parm->type) {
207 d_printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
208 make_parm_name(parm->label), *(char *)ptr);
209 d_printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%c\'\">",
210 _("Set Default"), make_parm_name(parm->label),(char)(parm->def.cvalue));
214 d_printf("<input type=text size=40 name=\"parm_%s\" value=\"",
215 make_parm_name(parm->label));
216 if ((char ***)ptr && *(char ***)ptr && **(char ***)ptr) {
217 char **list = *(char ***)ptr;
218 for (;*list;list++) {
219 d_printf("%s%s", *list, ((*(list+1))?" ":""));
223 d_printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'",
224 _("Set Default"), make_parm_name(parm->label));
225 if (parm->def.lvalue) {
226 char **list = (char **)(parm->def.lvalue);
227 for (; *list; list++) {
228 d_printf("%s%s", *list, ((*(list+1))?" ":""));
236 d_printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
237 make_parm_name(parm->label), *(char **)ptr);
238 d_printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
239 _("Set Default"), make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
244 d_printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
245 make_parm_name(parm->label), (char *)ptr);
246 d_printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
247 _("Set Default"), make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
251 d_printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
252 d_printf("<option %s>Yes", (*(BOOL *)ptr)?"selected":"");
253 d_printf("<option %s>No", (*(BOOL *)ptr)?"":"selected");
254 d_printf("</select>");
255 d_printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
256 _("Set Default"), make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?0:1);
260 d_printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
261 d_printf("<option %s>Yes", (*(BOOL *)ptr)?"":"selected");
262 d_printf("<option %s>No", (*(BOOL *)ptr)?"selected":"");
263 d_printf("</select>");
264 d_printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
265 _("Set Default"), make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?1:0);
269 d_printf("<input type=text size=8 name=\"parm_%s\" value=%d>", make_parm_name(parm->label), *(int *)ptr);
270 d_printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%d\'\">",
271 _("Set Default"), make_parm_name(parm->label),(int)(parm->def.ivalue));
275 d_printf("<input type=text size=8 name=\"parm_%s\" value=%s>", make_parm_name(parm->label), octal_string(*(int *)ptr));
276 d_printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
277 _("Set Default"), make_parm_name(parm->label),
278 octal_string((int)(parm->def.ivalue)));
282 d_printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
283 for (i=0;parm->enum_list[i].name;i++) {
284 if (i == 0 || parm->enum_list[i].value != parm->enum_list[i-1].value) {
285 d_printf("<option %s>%s",(*(int *)ptr)==parm->enum_list[i].value?"selected":"",parm->enum_list[i].name);
288 d_printf("</select>");
289 d_printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
290 _("Set Default"), make_parm_name(parm->label),enum_index((int)(parm->def.ivalue),parm->enum_list));
295 d_printf("</td></tr>\n");
298 /****************************************************************************
299 display a set of parameters for a service
300 ****************************************************************************/
301 static void show_parameters(int snum, int allparameters, int advanced, int printers)
304 struct parm_struct *parm;
305 char *heading = NULL;
306 char *last_heading = NULL;
308 while ((parm = lp_next_parameter(snum, &i, allparameters))) {
309 if (snum < 0 && parm->class == P_LOCAL && !(parm->flags & FLAG_GLOBAL))
311 if (parm->class == P_SEPARATOR) {
312 heading = parm->label;
315 if (parm->flags & FLAG_HIDE) continue;
317 if (printers & !(parm->flags & FLAG_PRINT)) continue;
318 if (!printers & !(parm->flags & FLAG_SHARE)) continue;
321 if (!(parm->flags & FLAG_BASIC)) {
322 void *ptr = parm->ptr;
324 if (parm->class == P_LOCAL && snum >= 0) {
325 ptr = lp_local_ptr(snum, ptr);
328 switch (parm->type) {
330 if (*(char *)ptr == (char)(parm->def.cvalue)) continue;
334 if (!lp_list_compare(*(char ***)ptr, (char **)(parm->def.lvalue))) continue;
339 if (!strcmp(*(char **)ptr,(char *)(parm->def.svalue))) continue;
344 if (!strcmp((char *)ptr,(char *)(parm->def.svalue))) continue;
349 if (*(BOOL *)ptr == (BOOL)(parm->def.bvalue)) continue;
354 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
359 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
365 if (printers && !(parm->flags & FLAG_PRINT)) continue;
367 if (heading && heading != last_heading) {
368 d_printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", _(heading));
369 last_heading = heading;
371 show_parameter(snum, parm);
375 /****************************************************************************
376 load the smb.conf file into loadparm.
377 ****************************************************************************/
378 static BOOL load_config(BOOL save_def)
380 lp_resetnumservices();
381 return lp_load(servicesf,False,save_def,False);
384 /****************************************************************************
386 ****************************************************************************/
387 static void write_config(FILE *f, BOOL show_defaults)
389 fprintf(f, "# Samba config file created using SWAT\n");
390 fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
391 fprintf(f, "# Date: %s\n\n", timestring(False));
393 lp_dump(f, show_defaults, iNumNonAutoPrintServices);
396 /****************************************************************************
397 save and reoad the smb.conf config file
398 ****************************************************************************/
399 static int save_reload(int snum)
404 f = sys_fopen(servicesf,"w");
406 d_printf("failed to open %s for writing\n", servicesf);
410 /* just in case they have used the buggy xinetd to create the file */
411 if (fstat(fileno(f), &st) == 0 &&
412 (st.st_mode & S_IWOTH)) {
413 fchmod(fileno(f), S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
416 write_config(f, False);
418 lp_dump_one(f, False, snum);
423 if (!load_config(False)) {
424 d_printf("Can't reload %s\n", servicesf);
427 iNumNonAutoPrintServices = lp_numservices();
433 /****************************************************************************
435 ****************************************************************************/
436 static void commit_parameter(int snum, struct parm_struct *parm, char *v)
441 if (snum < 0 && parm->class == P_LOCAL) {
442 /* this handles the case where we are changing a local
443 variable globally. We need to change the parameter in
444 all shares where it is currently set to the default */
445 for (i=0;i<lp_numservices();i++) {
446 s = lp_servicename(i);
447 if (s && (*s) && lp_is_default(i, parm)) {
448 lp_do_parameter(i, parm->label, v);
453 lp_do_parameter(snum, parm->label, v);
456 /****************************************************************************
457 commit a set of parameters for a service
458 ****************************************************************************/
459 static void commit_parameters(int snum)
462 struct parm_struct *parm;
466 while ((parm = lp_next_parameter(snum, &i, 1))) {
467 slprintf(label, sizeof(label)-1, "parm_%s", make_parm_name(parm->label));
468 if ((v = cgi_variable(label))) {
469 if (parm->flags & FLAG_HIDE) continue;
470 commit_parameter(snum, parm, v);
475 /****************************************************************************
476 spit out the html for a link with an image
477 ****************************************************************************/
478 static void image_link(char *name,char *hlink, char *src)
480 d_printf("<A HREF=\"%s/%s\"><img border=\"0\" src=\"/swat/%s\" alt=\"%s\"></A>\n",
481 cgi_baseurl(), hlink, src, name);
484 /****************************************************************************
485 display the main navigation controls at the top of each page along
487 ****************************************************************************/
488 static void show_main_buttons(void)
492 if ((p = cgi_user_name()) && strcmp(p, "root")) {
493 d_printf(_("Logged in as <b>%s</b><p>\n"), p);
496 image_link(_("Home"), "", "images/home.gif");
497 if (have_write_access) {
498 image_link(_("Globals"), "globals", "images/globals.gif");
499 image_link(_("Shares"), "shares", "images/shares.gif");
500 image_link(_("Printers"), "printers", "images/printers.gif");
502 if (have_read_access) {
503 image_link(_("Status"), "status", "images/status.gif");
504 image_link(_("View Config"), "viewconfig", "images/viewconfig.gif");
506 image_link(_("Password Management"), "passwd", "images/passwd.gif");
511 /****************************************************************************
512 display a welcome page
513 ****************************************************************************/
514 static void welcome_page(void)
516 include_html("help/welcome.html");
519 /****************************************************************************
520 display the current smb.conf
521 ****************************************************************************/
522 static void viewconfig_page(void)
526 if (cgi_variable("full_view")) {
530 d_printf("<H2>%s</H2>\n", _("Current Config"));
531 d_printf("<form method=post>\n");
534 d_printf("<input type=submit name=\"normal_view\" value=\"%s\">\n", _("Normal View"));
536 d_printf("<input type=submit name=\"full_view\" value=\"%s\">\n", _("Full View"));
539 d_printf("<p><pre>");
540 write_config(stdout, full_view);
542 d_printf("</form>\n");
545 /****************************************************************************
546 display a globals editing page
547 ****************************************************************************/
548 static void globals_page(void)
552 d_printf("<H2>%s</H2>\n", _("Global Variables"));
554 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
557 if (cgi_variable("Commit")) {
558 commit_parameters(GLOBALS_SNUM);
562 d_printf("<FORM name=\"swatform\" method=post>\n");
564 if (have_write_access) {
565 d_printf("<input type=submit name=\"Commit\" value=\"%s\">\n",
566 _("Commit Changes"));
569 d_printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n",
572 d_printf("<input type=submit name=\"Advanced\" value=\"%s\">\n", _("Advanced View"));
574 d_printf("<input type=submit name=\"Basic\" value=\"%s\">\n", _("Basic View"));
578 d_printf("<table>\n");
579 show_parameters(GLOBALS_SNUM, 1, advanced, 0);
580 d_printf("</table>\n");
583 d_printf("<input type=hidden name=\"Advanced\" value=1>\n");
586 d_printf("</FORM>\n");
589 /****************************************************************************
590 display a shares editing page. share is in unix codepage, and must be in
591 dos codepage. FIXME !!! JRA.
592 ****************************************************************************/
593 static void shares_page(void)
595 char *share = cgi_variable("share");
602 snum = lp_servicenumber(share);
604 d_printf("<H2>%s</H2>\n", _("Share Parameters"));
606 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
609 if (cgi_variable("Commit") && snum >= 0) {
610 commit_parameters(snum);
614 if (cgi_variable("Delete") && snum >= 0) {
615 lp_remove_service(snum);
621 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
623 lp_copy_service(GLOBALS_SNUM, share);
624 iNumNonAutoPrintServices = lp_numservices();
626 snum = lp_servicenumber(share);
629 d_printf("<FORM name=\"swatform\" method=post>\n");
631 d_printf("<table>\n");
633 d_printf("<td><input type=submit name=selectshare value=\"%s\"></td>\n", _("Choose Share"));
634 d_printf("<td><select name=share>\n");
636 d_printf("<option value=\" \"> \n");
637 for (i=0;i<lp_numservices();i++) {
638 s = lp_servicename(i);
639 if (s && (*s) && strcmp(s,"IPC$") && !lp_print_ok(i)) {
640 d_printf("<option %s value=\"%s\">%s\n",
641 (share && strcmp(share,s)==0)?"SELECTED":"",
645 d_printf("</select></td>\n");
646 if (have_write_access) {
647 d_printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Share"));
650 d_printf("</table>");
652 if (have_write_access) {
654 d_printf("<td><input type=submit name=createshare value=\"%s\"></td>\n", _("Create Share"));
655 d_printf("<td><input type=text size=30 name=newshare></td></tr>\n");
657 d_printf("</table>");
661 if (have_write_access) {
662 d_printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes"));
665 d_printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values"));
667 d_printf("<input type=submit name=\"Advanced\" value=\"%s\">\n", _("Advanced View"));
669 d_printf("<input type=submit name=\"Basic\" value=\"%s\">\n", _("Basic View"));
675 d_printf("<table>\n");
676 show_parameters(snum, 1, advanced, 0);
677 d_printf("</table>\n");
681 d_printf("<input type=hidden name=\"Advanced\" value=1>\n");
684 d_printf("</FORM>\n");
687 /*************************************************************
688 change a password either locally or remotely
689 *************************************************************/
690 static BOOL change_password(const char *remote_machine, char *user_name,
691 char *old_passwd, char *new_passwd,
699 d_printf("%s<p>", _("password change in demo mode rejected\n"));
703 if (remote_machine != NULL) {
704 ret = remote_password_change(remote_machine, user_name, old_passwd,
705 new_passwd, err_str, sizeof(err_str));
707 d_printf("%s\n<p>", err_str);
711 if(!initialize_password_db(True)) {
712 d_printf("Can't setup password database vectors.\n<p>");
716 ret = local_password_change(user_name, local_flags, new_passwd, err_str, sizeof(err_str),
717 msg_str, sizeof(msg_str));
720 d_printf("%s\n<p>", msg_str);
722 d_printf("%s\n<p>", err_str);
727 /****************************************************************************
728 do the stuff required to add or change a password
729 ****************************************************************************/
730 static void chg_passwd(void)
736 /* Make sure users name has been specified */
737 if (strlen(cgi_variable(SWAT_USER)) == 0) {
738 d_printf("<p>%s", _(" Must specify \"User Name\" \n"));
743 * smbpasswd doesn't require anything but the users name to delete, disable or enable the user,
744 * so if that's what we're doing, skip the rest of the checks
746 if (!cgi_variable(DISABLE_USER_FLAG) && !cgi_variable(ENABLE_USER_FLAG) && !cgi_variable(DELETE_USER_FLAG)) {
749 * If current user is not root, make sure old password has been specified
750 * If REMOTE change, even root must provide old password
752 if (((!am_root()) && (strlen( cgi_variable(OLD_PSWD)) <= 0)) ||
753 ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable(OLD_PSWD)) <= 0))) {
754 d_printf("<p>%s", _(" Must specify \"Old Password\" \n"));
758 /* If changing a users password on a remote hosts we have to know what host */
759 if ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable(RHOST)) <= 0)) {
760 d_printf("<p>%s", _(" Must specify \"Remote Machine\" \n"));
764 /* Make sure new passwords have been specified */
765 if ((strlen( cgi_variable(NEW_PSWD)) <= 0) ||
766 (strlen( cgi_variable(NEW2_PSWD)) <= 0)) {
767 d_printf("<p>%s", _(" Must specify \"New, and Re-typed Passwords\" \n"));
771 /* Make sure new passwords was typed correctly twice */
772 if (strcmp(cgi_variable(NEW_PSWD), cgi_variable(NEW2_PSWD)) != 0) {
773 d_printf("<p>%s", _(" Re-typed password didn't match new password\n"));
778 if (cgi_variable(CHG_R_PASSWD_FLAG)) {
779 host = cgi_variable(RHOST);
780 } else if (am_root()) {
787 * Set up the local flags.
790 local_flags |= (cgi_variable(ADD_USER_FLAG) ? LOCAL_ADD_USER : 0);
791 local_flags |= (cgi_variable(DELETE_USER_FLAG) ? LOCAL_DELETE_USER : 0);
792 local_flags |= (cgi_variable(ENABLE_USER_FLAG) ? LOCAL_ENABLE_USER : 0);
793 local_flags |= (cgi_variable(DISABLE_USER_FLAG) ? LOCAL_DISABLE_USER : 0);
795 rslt = change_password(host,
796 cgi_variable(SWAT_USER),
797 cgi_variable(OLD_PSWD), cgi_variable(NEW_PSWD),
800 if(local_flags == 0) {
803 d_printf(_(" The passwd for '%s' has been changed. \n"), cgi_variable(SWAT_USER));
805 d_printf(_(" The passwd for '%s' has NOT been changed. \n"), cgi_variable(SWAT_USER));
812 /****************************************************************************
813 display a password editing page
814 ****************************************************************************/
815 static void passwd_page(void)
817 char *new_name = cgi_user_name();
820 * After the first time through here be nice. If the user
821 * changed the User box text to another users name, remember it.
823 if (cgi_variable(SWAT_USER)) {
824 new_name = cgi_variable(SWAT_USER);
827 if (!new_name) new_name = "";
829 d_printf("<H2>%s</H2>\n", _("Server Password Management"));
831 d_printf("<FORM name=\"swatform\" method=post>\n");
833 d_printf("<table>\n");
836 * Create all the dialog boxes for data collection
838 d_printf("<tr><td>%s</td>\n", _(" User Name : "));
839 d_printf("<td><input type=text size=30 name=%s value=%s></td></tr> \n", SWAT_USER, new_name);
841 d_printf("<tr><td>%s</td>\n", _(" Old Password : "));
842 d_printf("<td><input type=password size=30 name=%s></td></tr> \n",OLD_PSWD);
844 d_printf("<tr><td>%s</td>\n", _(" New Password : "));
845 d_printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
846 d_printf("<tr><td>%s</td>\n", _(" Re-type New Password : "));
847 d_printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
848 d_printf("</table>\n");
851 * Create all the control buttons for requesting action
853 d_printf("<input type=submit name=%s value=\"%s\">\n",
854 CHG_S_PASSWD_FLAG, _("Change Password"));
855 if (demo_mode || am_root()) {
856 d_printf("<input type=submit name=%s value=\"%s\">\n",
857 ADD_USER_FLAG, _("Add New User"));
858 d_printf("<input type=submit name=%s value=\"%s\">\n",
859 DELETE_USER_FLAG, _("Delete User"));
860 d_printf("<input type=submit name=%s value=\"%s\">\n",
861 DISABLE_USER_FLAG, _("Disable User"));
862 d_printf("<input type=submit name=%s value=\"%s\">\n",
863 ENABLE_USER_FLAG, _("Enable User"));
865 d_printf("<p></FORM>\n");
868 * Do some work if change, add, disable or enable was
869 * requested. It could be this is the first time through this
870 * code, so there isn't anything to do. */
871 if ((cgi_variable(CHG_S_PASSWD_FLAG)) || (cgi_variable(ADD_USER_FLAG)) || (cgi_variable(DELETE_USER_FLAG)) ||
872 (cgi_variable(DISABLE_USER_FLAG)) || (cgi_variable(ENABLE_USER_FLAG))) {
876 d_printf("<H2>%s</H2>\n", _("Client/Server Password Management"));
878 d_printf("<FORM name=\"swatform\" method=post>\n");
880 d_printf("<table>\n");
883 * Create all the dialog boxes for data collection
885 d_printf("<tr><td>%s</td>\n", _(" User Name : "));
886 d_printf("<td><input type=text size=30 name=%s value=%s></td></tr>\n",SWAT_USER, new_name);
887 d_printf("<tr><td>%s</td>\n", _(" Old Password : "));
888 d_printf("<td><input type=password size=30 name=%s></td></tr>\n",OLD_PSWD);
889 d_printf("<tr><td>%s</td>\n", _(" New Password : "));
890 d_printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
891 d_printf("<tr><td>%s</td>\n", _(" Re-type New Password : "));
892 d_printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
893 d_printf("<tr><td>%s</td>\n", _(" Remote Machine : "));
894 d_printf("<td><input type=text size=30 name=%s></td></tr>\n",RHOST);
896 d_printf("</table>");
899 * Create all the control buttons for requesting action
901 d_printf("<input type=submit name=%s value=\"%s\">",
902 CHG_R_PASSWD_FLAG, _("Change Password"));
904 d_printf("<p></FORM>\n");
907 * Do some work if a request has been made to change the
908 * password somewhere other than the server. It could be this
909 * is the first time through this code, so there isn't
911 if (cgi_variable(CHG_R_PASSWD_FLAG)) {
917 /****************************************************************************
918 display a printers editing page
919 ****************************************************************************/
920 static void printers_page(void)
922 char *share = cgi_variable("share");
929 snum = lp_servicenumber(share);
931 d_printf("<H2>%s</H2>\n", _("Printer Parameters"));
933 d_printf("<H3>%s</H3>\n", _("Important Note:"));
934 d_printf(_("Printer names marked with [*] in the Choose Printer drop-down box "));
935 d_printf(_("are autoloaded printers from "));
936 d_printf("<A HREF=\"/swat/help/smb.conf.5.html#printcapname\" target=\"docs\">%s</A>\n", _("Printcap Name"));
937 d_printf(_("Attempting to delete these printers from SWAT will have no effect.\n"));
939 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
942 if (cgi_variable("Commit") && snum >= 0) {
943 commit_parameters(snum);
944 if (snum >= iNumNonAutoPrintServices)
950 if (cgi_variable("Delete") && snum >= 0) {
951 lp_remove_service(snum);
957 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
959 lp_copy_service(GLOBALS_SNUM, share);
960 iNumNonAutoPrintServices = lp_numservices();
961 snum = lp_servicenumber(share);
962 lp_do_parameter(snum, "print ok", "Yes");
964 snum = lp_servicenumber(share);
967 d_printf("<FORM name=\"swatform\" method=post>\n");
969 d_printf("<table>\n");
970 d_printf("<tr><td><input type=submit name=selectshare value=\"%s\"></td>\n", _("Choose Printer"));
971 d_printf("<td><select name=share>\n");
972 if (snum < 0 || !lp_print_ok(snum))
973 d_printf("<option value=\" \"> \n");
974 for (i=0;i<lp_numservices();i++) {
975 s = lp_servicename(i);
976 if (s && (*s) && strcmp(s,"IPC$") && lp_print_ok(i)) {
977 if (i >= iNumNonAutoPrintServices)
978 d_printf("<option %s value=\"%s\">[*]%s\n",
979 (share && strcmp(share,s)==0)?"SELECTED":"",
982 d_printf("<option %s value=\"%s\">%s\n",
983 (share && strcmp(share,s)==0)?"SELECTED":"",
987 d_printf("</select></td>");
988 if (have_write_access) {
989 d_printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Printer"));
992 d_printf("</table>\n");
994 if (have_write_access) {
995 d_printf("<table>\n");
996 d_printf("<tr><td><input type=submit name=createshare value=\"%s\"></td>\n", _("Create Printer"));
997 d_printf("<td><input type=text size=30 name=newshare></td></tr>\n");
998 d_printf("</table>");
1003 if (have_write_access) {
1004 d_printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes"));
1006 d_printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values"));
1007 if (advanced == 0) {
1008 d_printf("<input type=submit name=\"Advanced\" value=\"%s\">\n", _("Advanced View"));
1010 d_printf("<input type=submit name=\"Basic\" value=\"%s\">\n", _("Basic View"));
1016 d_printf("<table>\n");
1017 show_parameters(snum, 1, advanced, 1);
1018 d_printf("</table>\n");
1022 d_printf("<input type=hidden name=\"Advanced\" value=1>\n");
1025 d_printf("</FORM>\n");
1028 /****************************************************************************
1030 ****************************************************************************/
1031 int main(int argc, char *argv[])
1033 extern char *optarg;
1039 umask(S_IWGRP | S_IWOTH);
1041 #if defined(HAVE_SET_AUTH_PARAMETERS)
1042 set_auth_parameters(argc, argv);
1043 #endif /* HAVE_SET_AUTH_PARAMETERS */
1045 /* just in case it goes wild ... */
1048 /* we don't want any SIGPIPE messages */
1049 BlockSignals(True,SIGPIPE);
1051 dbf = x_fopen("/dev/null", O_WRONLY, 0);
1052 if (!dbf) dbf = x_stderr;
1054 /* we don't want stderr screwing us up */
1056 open("/dev/null", O_WRONLY);
1058 while ((opt = getopt(argc, argv,"s:a")) != EOF) {
1061 pstrcpy(servicesf,optarg);
1069 setup_logging(argv[0],False);
1071 iNumNonAutoPrintServices = lp_numservices();
1076 cgi_setup(SWATDIR, !demo_mode);
1079 cgi_setup(SWATDIR, !demo_mode);
1084 cgi_load_variables();
1086 if (!file_exist(servicesf, NULL)) {
1087 have_read_access = True;
1088 have_write_access = True;
1090 /* check if the authenticated user has write access - if not then
1091 don't show write options */
1092 have_write_access = (access(servicesf,W_OK) == 0);
1094 /* if the user doesn't have read access to smb.conf then
1095 don't let them view it */
1096 have_read_access = (access(servicesf,R_OK) == 0);
1099 show_main_buttons();
1101 page = cgi_pathinfo();
1103 /* Root gets full functionality */
1104 if (have_read_access && strcmp(page, "globals")==0) {
1106 } else if (have_read_access && strcmp(page,"shares")==0) {
1108 } else if (have_read_access && strcmp(page,"printers")==0) {
1110 } else if (have_read_access && strcmp(page,"status")==0) {
1112 } else if (have_read_access && strcmp(page,"viewconfig")==0) {
1114 } else if (strcmp(page,"passwd")==0) {