fix broken links in SWAT due to upper case anchors in the generated
[Samba/gbeck.git] / source / web / swat.c
blob0497eeb12a24ada59d0c326b1607e94357d6aa81
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
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.
22 #ifdef SYSLOG
23 #undef SYSLOG
24 #endif
26 #include "includes.h"
27 #include "smb.h"
29 #define GLOBALS_SNUM -1
31 static pstring servicesf = CONFIGFILE;
32 static BOOL demo_mode = False;
33 static BOOL have_write_access = False;
34 static BOOL have_read_access = False;
35 static int iNumNonAutoPrintServices = 0;
38 * Password Management Globals
40 #define SWAT_USER "username"
41 #define OLD_PSWD "old_passwd"
42 #define NEW_PSWD "new_passwd"
43 #define NEW2_PSWD "new2_passwd"
44 #define CHG_S_PASSWD_FLAG "chg_s_passwd_flag"
45 #define CHG_R_PASSWD_FLAG "chg_r_passwd_flag"
46 #define ADD_USER_FLAG "add_user_flag"
47 #define DELETE_USER_FLAG "delete_user_flag"
48 #define DISABLE_USER_FLAG "disable_user_flag"
49 #define ENABLE_USER_FLAG "enable_user_flag"
50 #define RHOST "remote_host"
52 /* we need these because we link to locking*.o */
53 void become_root(void) {}
54 void unbecome_root(void) {}
56 /****************************************************************************
57 ****************************************************************************/
58 static int enum_index(int value, struct enum_list *enumlist)
60 int i;
61 for (i=0;enumlist[i].name;i++)
62 if (value == enumlist[i].value) break;
63 return(i);
66 static char *fix_backslash(char *str)
68 static char newstring[1024];
69 char *p = newstring;
71 while (*str) {
72 if (*str == '\\') {*p++ = '\\';*p++ = '\\';}
73 else *p++ = *str;
74 ++str;
76 *p = '\0';
77 return newstring;
80 static char *stripspace(char *str)
82 static char newstring[1024];
83 char *p = newstring;
85 while (*str) {
86 if (*str != ' ') *p++ = *str;
87 ++str;
89 *p = '\0';
90 return newstring;
93 static char *make_parm_name(char *label)
95 static char parmname[1024];
96 char *p = parmname;
98 while (*label) {
99 if (*label == ' ') *p++ = '_';
100 else *p++ = *label;
101 ++label;
103 *p = '\0';
104 return parmname;
107 /****************************************************************************
108 include a lump of html in a page
109 ****************************************************************************/
110 static int include_html(char *fname)
112 FILE *f = sys_fopen(fname,"r");
113 char buf[1024];
114 int ret;
116 if (!f) {
117 printf("ERROR: Can't open %s\n", fname);
118 return 0;
121 while (!feof(f)) {
122 ret = fread(buf, 1, sizeof(buf), f);
123 if (ret <= 0) break;
124 fwrite(buf, 1, ret, stdout);
127 fclose(f);
128 return 1;
131 /****************************************************************************
132 start the page with standard stuff
133 ****************************************************************************/
134 static void print_header(void)
136 if (!cgi_waspost()) {
137 printf("Expires: 0\r\n");
139 printf("Content-type: text/html\r\n\r\n");
141 if (!include_html("include/header.html")) {
142 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
143 printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY background=\"/swat/images/background.jpg\">\n\n");
147 /****************************************************************************
148 finish off the page
149 ****************************************************************************/
150 static void print_footer(void)
152 if (!include_html("include/footer.html")) {
153 printf("\n</BODY>\n</HTML>\n");
157 /****************************************************************************
158 display one editable parameter in a form
159 ****************************************************************************/
160 static void show_parameter(int snum, struct parm_struct *parm)
162 int i;
163 void *ptr = parm->ptr;
164 char* str;
166 if (parm->class == P_LOCAL && snum >= 0) {
167 ptr = lp_local_ptr(snum, ptr);
170 str = stripspace(parm->label);
171 strupper (str);
172 printf("<tr><td><A HREF=\"/swat/help/smb.conf.5.html#%s\" target=\"docs\">Help</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %s</td><td>",
173 str, parm->label);
175 switch (parm->type) {
176 case P_CHAR:
177 printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
178 make_parm_name(parm->label), *(char *)ptr);
179 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%c\'\">",
180 make_parm_name(parm->label),(char)(parm->def.cvalue));
181 break;
183 case P_STRING:
184 case P_USTRING:
185 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
186 make_parm_name(parm->label), *(char **)ptr);
187 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
188 make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
189 break;
191 case P_GSTRING:
192 case P_UGSTRING:
193 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
194 make_parm_name(parm->label), (char *)ptr);
195 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
196 make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
197 break;
199 case P_BOOL:
200 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
201 printf("<option %s>Yes", (*(BOOL *)ptr)?"selected":"");
202 printf("<option %s>No", (*(BOOL *)ptr)?"":"selected");
203 printf("</select>");
204 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
205 make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?0:1);
206 break;
208 case P_BOOLREV:
209 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
210 printf("<option %s>Yes", (*(BOOL *)ptr)?"":"selected");
211 printf("<option %s>No", (*(BOOL *)ptr)?"selected":"");
212 printf("</select>");
213 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
214 make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?1:0);
215 break;
217 case P_INTEGER:
218 printf("<input type=text size=8 name=\"parm_%s\" value=%d>", make_parm_name(parm->label), *(int *)ptr);
219 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%d\'\">",
220 make_parm_name(parm->label),(int)(parm->def.ivalue));
221 break;
223 case P_OCTAL:
224 printf("<input type=text size=8 name=\"parm_%s\" value=%s>", make_parm_name(parm->label), octal_string(*(int *)ptr));
225 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
226 make_parm_name(parm->label),
227 octal_string((int)(parm->def.ivalue)));
228 break;
230 case P_ENUM:
231 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
232 for (i=0;parm->enum_list[i].name;i++) {
233 if (i == 0 || parm->enum_list[i].value != parm->enum_list[i-1].value) {
234 printf("<option %s>%s",(*(int *)ptr)==parm->enum_list[i].value?"selected":"",parm->enum_list[i].name);
237 printf("</select>");
238 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
239 make_parm_name(parm->label),enum_index((int)(parm->def.ivalue),parm->enum_list));
240 break;
241 case P_SEP:
242 break;
244 printf("</td></tr>\n");
247 /****************************************************************************
248 display a set of parameters for a service
249 ****************************************************************************/
250 static void show_parameters(int snum, int allparameters, int advanced, int printers)
252 int i = 0;
253 struct parm_struct *parm;
254 char *heading = NULL;
255 char *last_heading = NULL;
257 while ((parm = lp_next_parameter(snum, &i, allparameters))) {
258 if (snum < 0 && parm->class == P_LOCAL && !(parm->flags & FLAG_GLOBAL))
259 continue;
260 if (parm->class == P_SEPARATOR) {
261 heading = parm->label;
262 continue;
264 if (parm->flags & FLAG_HIDE) continue;
265 if (snum >= 0) {
266 if (printers & !(parm->flags & FLAG_PRINT)) continue;
267 if (!printers & !(parm->flags & FLAG_SHARE)) continue;
269 if (!advanced) {
270 if (!(parm->flags & FLAG_BASIC)) {
271 void *ptr = parm->ptr;
273 if (parm->class == P_LOCAL && snum >= 0) {
274 ptr = lp_local_ptr(snum, ptr);
277 switch (parm->type) {
278 case P_CHAR:
279 if (*(char *)ptr == (char)(parm->def.cvalue)) continue;
280 break;
282 case P_STRING:
283 case P_USTRING:
284 if (!strcmp(*(char **)ptr,(char *)(parm->def.svalue))) continue;
285 break;
287 case P_GSTRING:
288 case P_UGSTRING:
289 if (!strcmp((char *)ptr,(char *)(parm->def.svalue))) continue;
290 break;
292 case P_BOOL:
293 case P_BOOLREV:
294 if (*(BOOL *)ptr == (BOOL)(parm->def.bvalue)) continue;
295 break;
297 case P_INTEGER:
298 case P_OCTAL:
299 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
300 break;
303 case P_ENUM:
304 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
305 break;
306 case P_SEP:
307 continue;
310 if (printers && !(parm->flags & FLAG_PRINT)) continue;
312 if (heading && heading != last_heading) {
313 printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", heading);
314 last_heading = heading;
316 show_parameter(snum, parm);
320 /****************************************************************************
321 load the smb.conf file into loadparm.
322 ****************************************************************************/
323 static BOOL load_config(BOOL save_def)
325 lp_resetnumservices();
326 return lp_load(servicesf,False,save_def,False);
329 /****************************************************************************
330 write a config file
331 ****************************************************************************/
332 static void write_config(FILE *f, BOOL show_defaults, char *(*dos_to_ext)(char *, BOOL))
334 fprintf(f, "# Samba config file created using SWAT\n");
335 fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
336 fprintf(f, "# Date: %s\n\n", timestring(False));
338 lp_dump(f, show_defaults, iNumNonAutoPrintServices, dos_to_ext);
341 /****************************************************************************
342 save and reoad the smb.conf config file
343 ****************************************************************************/
344 static int save_reload(int snum)
346 FILE *f;
348 f = sys_fopen(servicesf,"w");
349 if (!f) {
350 printf("failed to open %s for writing\n", servicesf);
351 return 0;
354 write_config(f, False, _dos_to_unix);
355 if (snum)
356 lp_dump_one(f, False, snum, _dos_to_unix);
357 fclose(f);
359 lp_killunused(NULL);
361 if (!load_config(False)) {
362 printf("Can't reload %s\n", servicesf);
363 return 0;
365 iNumNonAutoPrintServices = lp_numservices();
366 load_printers();
368 return 1;
371 /****************************************************************************
372 commit one parameter
373 ****************************************************************************/
374 static void commit_parameter(int snum, struct parm_struct *parm, char *v)
376 int i;
377 char *s;
379 /* lp_do_parameter() will do unix_to_dos(v). */
380 if(parm->flags & FLAG_DOS_STRING)
381 dos_to_unix(v, True);
383 if (snum < 0 && parm->class == P_LOCAL) {
384 /* this handles the case where we are changing a local
385 variable globally. We need to change the parameter in
386 all shares where it is currently set to the default */
387 for (i=0;i<lp_numservices();i++) {
388 s = lp_servicename(i);
389 if (s && (*s) && lp_is_default(i, parm)) {
390 lp_do_parameter(i, parm->label, v);
395 lp_do_parameter(snum, parm->label, v);
398 /****************************************************************************
399 commit a set of parameters for a service
400 ****************************************************************************/
401 static void commit_parameters(int snum)
403 int i = 0;
404 struct parm_struct *parm;
405 pstring label;
406 char *v;
408 while ((parm = lp_next_parameter(snum, &i, 1))) {
409 slprintf(label, sizeof(label)-1, "parm_%s", make_parm_name(parm->label));
410 if ((v = cgi_variable(label))) {
411 if (parm->flags & FLAG_HIDE) continue;
412 commit_parameter(snum, parm, v);
417 /****************************************************************************
418 spit out the html for a link with an image
419 ****************************************************************************/
420 static void image_link(char *name,char *hlink, char *src)
422 printf("<A HREF=\"%s/%s\"><img src=\"/swat/%s\" alt=\"%s\"></A>\n",
423 cgi_baseurl(), hlink, src, name);
426 /****************************************************************************
427 display the main navigation controls at the top of each page along
428 with a title
429 ****************************************************************************/
430 static void show_main_buttons(void)
432 char *p;
434 if ((p = cgi_user_name()) && strcmp(p, "root")) {
435 printf("Logged in as <b>%s</b><p>\n", p);
438 image_link("Home", "", "images/home.gif");
439 if (have_write_access) {
440 image_link("Globals", "globals", "images/globals.gif");
441 image_link("Shares", "shares", "images/shares.gif");
442 image_link("Printers", "printers", "images/printers.gif");
444 if (have_read_access) {
445 image_link("Status", "status", "images/status.gif");
446 image_link("View Config", "viewconfig","images/viewconfig.gif");
448 image_link("Password Management", "passwd", "images/passwd.gif");
450 printf("<HR>\n");
453 /****************************************************************************
454 display a welcome page
455 ****************************************************************************/
456 static void welcome_page(void)
458 include_html("help/welcome.html");
461 /****************************************************************************
462 display the current smb.conf
463 ****************************************************************************/
464 static void viewconfig_page(void)
466 int full_view=0;
468 if (cgi_variable("full_view")) {
469 full_view = 1;
472 printf("<H2>Current Config</H2>\n");
473 printf("<form method=post>\n");
475 if (full_view) {
476 printf("<input type=submit name=\"normal_view\" value=\"Normal View\">\n");
477 } else {
478 printf("<input type=submit name=\"full_view\" value=\"Full View\">\n");
481 printf("<p><pre>");
482 write_config(stdout, full_view, _dos_to_dos);
483 printf("</pre>");
484 printf("</form>\n");
487 /****************************************************************************
488 display a globals editing page
489 ****************************************************************************/
490 static void globals_page(void)
492 int advanced = 0;
494 printf("<H2>Global Variables</H2>\n");
496 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
497 advanced = 1;
499 if (cgi_variable("Commit")) {
500 commit_parameters(GLOBALS_SNUM);
501 save_reload(0);
504 printf("<FORM name=\"swatform\" method=post>\n");
506 if (have_write_access) {
507 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
510 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
511 if (advanced == 0) {
512 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
513 } else {
514 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
516 printf("<p>\n");
518 printf("<table>\n");
519 show_parameters(GLOBALS_SNUM, 1, advanced, 0);
520 printf("</table>\n");
522 if (advanced) {
523 printf("<input type=hidden name=\"Advanced\" value=1>\n");
526 printf("</FORM>\n");
529 /****************************************************************************
530 display a shares editing page. share is in unix codepage, and must be in
531 dos codepage. FIXME !!! JRA.
532 ****************************************************************************/
533 static void shares_page(void)
535 char *share = cgi_variable("share");
536 char *s;
537 int snum=-1;
538 int i;
539 int advanced = 0;
541 if (share)
542 snum = lp_servicenumber(share);
544 printf("<H2>Share Parameters</H2>\n");
546 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
547 advanced = 1;
549 if (cgi_variable("Commit") && snum >= 0) {
550 commit_parameters(snum);
551 save_reload(0);
554 if (cgi_variable("Delete") && snum >= 0) {
555 lp_remove_service(snum);
556 save_reload(0);
557 share = NULL;
558 snum = -1;
561 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
562 /* add_a_service() which is called by lp_copy_service()
563 will do unix_to_dos() conversion, so we need dos_to_unix() before the lp_copy_service(). */
564 pstring unix_share;
565 pstrcpy(unix_share, dos_to_unix(share, False));
566 load_config(False);
567 lp_copy_service(GLOBALS_SNUM, unix_share);
568 iNumNonAutoPrintServices = lp_numservices();
569 save_reload(0);
570 snum = lp_servicenumber(share);
573 printf("<FORM name=\"swatform\" method=post>\n");
575 printf("<table>\n");
576 printf("<tr>\n");
577 printf("<td><input type=submit name=selectshare value=\"Choose Share\"></td>\n");
578 printf("<td><select name=share>\n");
579 if (snum < 0)
580 printf("<option value=\" \"> \n");
581 for (i=0;i<lp_numservices();i++) {
582 s = lp_servicename(i);
583 if (s && (*s) && strcmp(s,"IPC$") && !lp_print_ok(i)) {
584 printf("<option %s value=\"%s\">%s\n",
585 (share && strcmp(share,s)==0)?"SELECTED":"",
586 s, s);
589 printf("</select></td>\n");
590 if (have_write_access) {
591 printf("<td><input type=submit name=\"Delete\" value=\"Delete Share\"></td>\n");
593 printf("</tr>\n");
594 printf("</table>");
595 printf("<table>");
596 if (have_write_access) {
597 printf("<tr>\n");
598 printf("<td><input type=submit name=createshare value=\"Create Share\"></td>\n");
599 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
601 printf("</table>");
604 if (snum >= 0) {
605 if (have_write_access) {
606 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
609 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
610 if (advanced == 0) {
611 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
612 } else {
613 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
615 printf("<p>\n");
618 if (snum >= 0) {
619 printf("<table>\n");
620 show_parameters(snum, 1, advanced, 0);
621 printf("</table>\n");
624 if (advanced) {
625 printf("<input type=hidden name=\"Advanced\" value=1>\n");
628 printf("</FORM>\n");
631 /*************************************************************
632 change a password either locally or remotely
633 *************************************************************/
634 static BOOL change_password(const char *remote_machine, char *user_name,
635 char *old_passwd, char *new_passwd,
636 int local_flags)
638 BOOL ret = False;
639 pstring err_str;
640 pstring msg_str;
642 if (demo_mode) {
643 printf("password change in demo mode rejected\n<p>");
644 return False;
647 if (remote_machine != NULL) {
648 ret = remote_password_change(remote_machine, user_name, old_passwd,
649 new_passwd, err_str, sizeof(err_str));
650 if(*err_str)
651 printf("%s\n<p>", err_str);
652 return ret;
655 if(!initialize_password_db(True)) {
656 printf("Can't setup password database vectors.\n<p>");
657 return False;
660 ret = local_password_change(user_name, local_flags, new_passwd, err_str, sizeof(err_str),
661 msg_str, sizeof(msg_str));
663 if(*msg_str)
664 printf("%s\n<p>", msg_str);
665 if(*err_str)
666 printf("%s\n<p>", err_str);
668 return ret;
671 /****************************************************************************
672 do the stuff required to add or change a password
673 ****************************************************************************/
674 static void chg_passwd(void)
676 char *host;
677 BOOL rslt;
678 int local_flags = 0;
680 /* Make sure users name has been specified */
681 if (strlen(cgi_variable(SWAT_USER)) == 0) {
682 printf("<p> Must specify \"User Name\" \n");
683 return;
687 * smbpasswd doesn't require anything but the users name to delete, disable or enable the user,
688 * so if that's what we're doing, skip the rest of the checks
690 if (!cgi_variable(DISABLE_USER_FLAG) && !cgi_variable(ENABLE_USER_FLAG) && !cgi_variable(DELETE_USER_FLAG)) {
693 * If current user is not root, make sure old password has been specified
694 * If REMOTE change, even root must provide old password
696 if (((!am_root()) && (strlen( cgi_variable(OLD_PSWD)) <= 0)) ||
697 ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable(OLD_PSWD)) <= 0))) {
698 printf("<p> Must specify \"Old Password\" \n");
699 return;
702 /* If changing a users password on a remote hosts we have to know what host */
703 if ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable(RHOST)) <= 0)) {
704 printf("<p> Must specify \"Remote Machine\" \n");
705 return;
708 /* Make sure new passwords have been specified */
709 if ((strlen( cgi_variable(NEW_PSWD)) <= 0) ||
710 (strlen( cgi_variable(NEW2_PSWD)) <= 0)) {
711 printf("<p> Must specify \"New, and Re-typed Passwords\" \n");
712 return;
715 /* Make sure new passwords was typed correctly twice */
716 if (strcmp(cgi_variable(NEW_PSWD), cgi_variable(NEW2_PSWD)) != 0) {
717 printf("<p> Re-typed password didn't match new password\n");
718 return;
722 if (cgi_variable(CHG_R_PASSWD_FLAG)) {
723 host = cgi_variable(RHOST);
724 } else if (am_root()) {
725 host = NULL;
726 } else {
727 host = "127.0.0.1";
731 * Set up the local flags.
734 local_flags |= (cgi_variable(ADD_USER_FLAG) ? LOCAL_ADD_USER : 0);
735 local_flags |= (cgi_variable(DELETE_USER_FLAG) ? LOCAL_DELETE_USER : 0);
736 local_flags |= (cgi_variable(ENABLE_USER_FLAG) ? LOCAL_ENABLE_USER : 0);
737 local_flags |= (cgi_variable(DISABLE_USER_FLAG) ? LOCAL_DISABLE_USER : 0);
739 rslt = change_password(host,
740 cgi_variable(SWAT_USER),
741 cgi_variable(OLD_PSWD), cgi_variable(NEW_PSWD),
742 local_flags);
744 if(local_flags == 0) {
745 if (rslt == True) {
746 printf("<p> The passwd for '%s' has been changed. \n", cgi_variable(SWAT_USER));
747 } else {
748 printf("<p> The passwd for '%s' has NOT been changed. \n",cgi_variable(SWAT_USER));
752 return;
755 /****************************************************************************
756 display a password editing page
757 ****************************************************************************/
758 static void passwd_page(void)
760 char *new_name = cgi_user_name();
763 * After the first time through here be nice. If the user
764 * changed the User box text to another users name, remember it.
766 if (cgi_variable(SWAT_USER)) {
767 new_name = cgi_variable(SWAT_USER);
770 if (!new_name) new_name = "";
772 printf("<H2>Server Password Management</H2>\n");
774 printf("<FORM name=\"swatform\" method=post>\n");
776 printf("<table>\n");
779 * Create all the dialog boxes for data collection
781 printf("<tr><td> User Name : </td>\n");
782 printf("<td><input type=text size=30 name=%s value=%s></td></tr> \n", SWAT_USER, new_name);
783 if (!am_root()) {
784 printf("<tr><td> Old Password : </td>\n");
785 printf("<td><input type=password size=30 name=%s></td></tr> \n",OLD_PSWD);
787 printf("<tr><td> New Password : </td>\n");
788 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
789 printf("<tr><td> Re-type New Password : </td>\n");
790 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
791 printf("</table>\n");
794 * Create all the control buttons for requesting action
796 printf("<input type=submit name=%s value=\"Change Password\">\n",
797 CHG_S_PASSWD_FLAG);
798 if (demo_mode || am_root()) {
799 printf("<input type=submit name=%s value=\"Add New User\">\n",
800 ADD_USER_FLAG);
801 printf("<input type=submit name=%s value=\"Delete User\">\n",
802 DELETE_USER_FLAG);
803 printf("<input type=submit name=%s value=\"Disable User\">\n",
804 DISABLE_USER_FLAG);
805 printf("<input type=submit name=%s value=\"Enable User\">\n",
806 ENABLE_USER_FLAG);
808 printf("<p></FORM>\n");
811 * Do some work if change, add, disable or enable was
812 * requested. It could be this is the first time through this
813 * code, so there isn't anything to do. */
814 if ((cgi_variable(CHG_S_PASSWD_FLAG)) || (cgi_variable(ADD_USER_FLAG)) || (cgi_variable(DELETE_USER_FLAG)) ||
815 (cgi_variable(DISABLE_USER_FLAG)) || (cgi_variable(ENABLE_USER_FLAG))) {
816 chg_passwd();
819 printf("<H2>Client/Server Password Management</H2>\n");
821 printf("<FORM name=\"swatform\" method=post>\n");
823 printf("<table>\n");
826 * Create all the dialog boxes for data collection
828 printf("<tr><td> User Name : </td>\n");
829 printf("<td><input type=text size=30 name=%s value=%s></td></tr>\n",SWAT_USER, new_name);
830 printf("<tr><td> Old Password : </td>\n");
831 printf("<td><input type=password size=30 name=%s></td></tr>\n",OLD_PSWD);
832 printf("<tr><td> New Password : </td>\n");
833 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
834 printf("<tr><td> Re-type New Password : </td>\n");
835 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
836 printf("<tr><td> Remote Machine : </td>\n");
837 printf("<td><input type=text size=30 name=%s></td></tr>\n",RHOST);
839 printf("</table>");
842 * Create all the control buttons for requesting action
844 printf("<input type=submit name=%s value=\"Change Password\">",
845 CHG_R_PASSWD_FLAG);
847 printf("<p></FORM>\n");
850 * Do some work if a request has been made to change the
851 * password somewhere other than the server. It could be this
852 * is the first time through this code, so there isn't
853 * anything to do. */
854 if (cgi_variable(CHG_R_PASSWD_FLAG)) {
855 chg_passwd();
860 /****************************************************************************
861 display a printers editing page
862 ****************************************************************************/
863 static void printers_page(void)
865 char *share = cgi_variable("share");
866 char *s;
867 int snum=-1;
868 int i;
869 int advanced = 0;
871 if (share)
872 snum = lp_servicenumber(share);
874 printf("<H2>Printer Parameters</H2>\n");
876 printf("<H3>Important Note:</H3>\n");
877 printf("Printer names marked with [*] in the Choose Printer drop-down box ");
878 printf("are autoloaded printers from ");
879 printf("<A HREF=\"/swat/help/smb.conf.5.html#PRINTCAPNAME\" target=\"docs\">Printcap Name</A>.\n");
880 printf("Attempting to delete these printers from SWAT will have no effect.\n");
882 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
883 advanced = 1;
885 if (cgi_variable("Commit") && snum >= 0) {
886 commit_parameters(snum);
887 if (snum >= iNumNonAutoPrintServices)
888 save_reload(snum);
889 else
890 save_reload(0);
893 if (cgi_variable("Delete") && snum >= 0) {
894 lp_remove_service(snum);
895 save_reload(0);
896 share = NULL;
897 snum = -1;
900 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
901 /* add_a_service() which is called by lp_copy_service()
902 will do unix_to_dos() conversion, so we need dos_to_unix() before the lp_copy_service(). */
903 pstring unix_share;
904 pstrcpy(unix_share, dos_to_unix(share, False));
905 load_config(False);
906 lp_copy_service(GLOBALS_SNUM, unix_share);
907 iNumNonAutoPrintServices = lp_numservices();
908 snum = lp_servicenumber(share);
909 lp_do_parameter(snum, "print ok", "Yes");
910 save_reload(0);
911 snum = lp_servicenumber(share);
914 printf("<FORM name=\"swatform\" method=post>\n");
916 printf("<table>\n");
917 printf("<tr><td><input type=submit name=selectshare value=\"Choose Printer\"></td>\n");
918 printf("<td><select name=share>\n");
919 if (snum < 0 || !lp_print_ok(snum))
920 printf("<option value=\" \"> \n");
921 for (i=0;i<lp_numservices();i++) {
922 s = lp_servicename(i);
923 if (s && (*s) && strcmp(s,"IPC$") && lp_print_ok(i)) {
924 if (i >= iNumNonAutoPrintServices)
925 printf("<option %s value=\"%s\">[*]%s\n",
926 (share && strcmp(share,s)==0)?"SELECTED":"",
927 s, s);
928 else
929 printf("<option %s value=\"%s\">%s\n",
930 (share && strcmp(share,s)==0)?"SELECTED":"",
931 s, s);
934 printf("</select></td>");
935 if (have_write_access) {
936 printf("<td><input type=submit name=\"Delete\" value=\"Delete Printer\"></td>\n");
938 printf("</tr>");
939 printf("</table>\n");
941 if (have_write_access) {
942 printf("<table>\n");
943 printf("<tr><td><input type=submit name=createshare value=\"Create Printer\"></td>\n");
944 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
945 printf("</table>");
949 if (snum >= 0) {
950 if (have_write_access) {
951 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
953 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
954 if (advanced == 0) {
955 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
956 } else {
957 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
959 printf("<p>\n");
962 if (snum >= 0) {
963 printf("<table>\n");
964 show_parameters(snum, 1, advanced, 1);
965 printf("</table>\n");
968 if (advanced) {
969 printf("<input type=hidden name=\"Advanced\" value=1>\n");
972 printf("</FORM>\n");
975 /****************************************************************************
976 MAIN()
977 ****************************************************************************/
978 int main(int argc, char *argv[])
980 extern char *optarg;
981 extern int optind;
982 extern FILE *dbf;
983 int opt;
984 char *page;
986 fault_setup(NULL);
988 #if defined(HAVE_SET_AUTH_PARAMETERS)
989 set_auth_parameters(argc, argv);
990 #endif /* HAVE_SET_AUTH_PARAMETERS */
992 /* just in case it goes wild ... */
993 alarm(300);
995 /* we don't want any SIGPIPE messages */
996 BlockSignals(True,SIGPIPE);
998 dbf = sys_fopen("/dev/null", "w");
999 if (!dbf) dbf = stderr;
1001 /* we don't want stderr screwing us up */
1002 close(2);
1003 open("/dev/null", O_WRONLY);
1005 while ((opt = getopt(argc, argv,"s:a")) != EOF) {
1006 switch (opt) {
1007 case 's':
1008 pstrcpy(servicesf,optarg);
1009 break;
1010 case 'a':
1011 demo_mode = True;
1012 break;
1016 setup_logging(argv[0],False);
1017 charset_initialise();
1018 load_config(True);
1019 iNumNonAutoPrintServices = lp_numservices();
1020 load_printers();
1022 cgi_setup(SWATDIR, !demo_mode);
1024 print_header();
1026 cgi_load_variables(NULL);
1028 if (!file_exist(servicesf, NULL)) {
1029 have_read_access = True;
1030 have_write_access = True;
1031 } else {
1032 /* check if the authenticated user has write access - if not then
1033 don't show write options */
1034 have_write_access = (access(servicesf,W_OK) == 0);
1036 /* if the user doesn't have read access to smb.conf then
1037 don't let them view it */
1038 have_read_access = (access(servicesf,R_OK) == 0);
1042 show_main_buttons();
1044 page = cgi_pathinfo();
1046 /* Root gets full functionality */
1047 if (have_read_access && strcmp(page, "globals")==0) {
1048 globals_page();
1049 } else if (have_read_access && strcmp(page,"shares")==0) {
1050 shares_page();
1051 } else if (have_read_access && strcmp(page,"printers")==0) {
1052 printers_page();
1053 } else if (have_read_access && strcmp(page,"status")==0) {
1054 status_page();
1055 } else if (have_read_access && strcmp(page,"viewconfig")==0) {
1056 viewconfig_page();
1057 } else if (strcmp(page,"passwd")==0) {
1058 passwd_page();
1059 } else {
1060 welcome_page();
1063 print_footer();
1064 return 0;