Fixed interface code so that a UUID is transmitted as the following fields :
[Samba/ekacnet.git] / source / web / swat.c
blob44cbdf66e465622d8131b2b8ca5bdca5f7d35066
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 DISABLE_USER_FLAG "disable_user_flag"
48 #define ENABLE_USER_FLAG "enable_user_flag"
49 #define RHOST "remote_host"
51 /* we need these because we link to locking*.o */
52 void become_root(BOOL save_dir) {}
53 void unbecome_root(BOOL restore_dir) {}
55 /****************************************************************************
56 ****************************************************************************/
57 static int enum_index(int value, struct enum_list *enumlist)
59 int i;
60 for (i=0;enumlist[i].name;i++)
61 if (value == enumlist[i].value) break;
62 return(i);
65 static char *fix_backslash(char *str)
67 static char newstring[1024];
68 char *p = newstring;
70 while (*str) {
71 if (*str == '\\') {*p++ = '\\';*p++ = '\\';}
72 else *p++ = *str;
73 ++str;
75 *p = '\0';
76 return newstring;
79 static char *stripspace(char *str)
81 static char newstring[1024];
82 char *p = newstring;
84 while (*str) {
85 if (*str != ' ') *p++ = *str;
86 ++str;
88 *p = '\0';
89 return newstring;
92 static char *make_parm_name(char *label)
94 static char parmname[1024];
95 char *p = parmname;
97 while (*label) {
98 if (*label == ' ') *p++ = '_';
99 else *p++ = *label;
100 ++label;
102 *p = '\0';
103 return parmname;
106 /****************************************************************************
107 include a lump of html in a page
108 ****************************************************************************/
109 static int include_html(char *fname)
111 FILE *f = sys_fopen(fname,"r");
112 char buf[1024];
113 int ret;
115 if (!f) {
116 printf("ERROR: Can't open %s\n", fname);
117 return 0;
120 while (!feof(f)) {
121 ret = fread(buf, 1, sizeof(buf), f);
122 if (ret <= 0) break;
123 fwrite(buf, 1, ret, stdout);
126 fclose(f);
127 return 1;
130 /****************************************************************************
131 start the page with standard stuff
132 ****************************************************************************/
133 static void print_header(void)
135 if (!cgi_waspost()) {
136 printf("Expires: 0\r\n");
138 printf("Content-type: text/html\r\n\r\n");
140 if (!include_html("include/header.html")) {
141 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
142 printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY background=\"/swat/images/background.jpg\">\n\n");
146 /****************************************************************************
147 finish off the page
148 ****************************************************************************/
149 static void print_footer(void)
151 if (!include_html("include/footer.html")) {
152 printf("\n</BODY>\n</HTML>\n");
156 /****************************************************************************
157 display one editable parameter in a form
158 ****************************************************************************/
159 static void show_parameter(int snum, struct parm_struct *parm)
161 int i;
162 void *ptr = parm->ptr;
164 if (parm->class == P_LOCAL && snum >= 0) {
165 ptr = lp_local_ptr(snum, ptr);
168 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>",
169 stripspace(parm->label), parm->label);
171 switch (parm->type) {
172 case P_CHAR:
173 printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
174 make_parm_name(parm->label), *(char *)ptr);
175 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%c\'\">",
176 make_parm_name(parm->label),(char)(parm->def.cvalue));
177 break;
179 case P_STRING:
180 case P_USTRING:
181 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
182 make_parm_name(parm->label), *(char **)ptr);
183 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
184 make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
185 break;
187 case P_GSTRING:
188 case P_UGSTRING:
189 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
190 make_parm_name(parm->label), (char *)ptr);
191 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
192 make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
193 break;
195 case P_BOOL:
196 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
197 printf("<option %s>Yes", (*(BOOL *)ptr)?"selected":"");
198 printf("<option %s>No", (*(BOOL *)ptr)?"":"selected");
199 printf("</select>");
200 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
201 make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?0:1);
202 break;
204 case P_BOOLREV:
205 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
206 printf("<option %s>Yes", (*(BOOL *)ptr)?"":"selected");
207 printf("<option %s>No", (*(BOOL *)ptr)?"selected":"");
208 printf("</select>");
209 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
210 make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?1:0);
211 break;
213 case P_INTEGER:
214 printf("<input type=text size=8 name=\"parm_%s\" value=%d>", make_parm_name(parm->label), *(int *)ptr);
215 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%d\'\">",
216 make_parm_name(parm->label),(int)(parm->def.ivalue));
217 break;
219 case P_OCTAL:
220 printf("<input type=text size=8 name=\"parm_%s\" value=0%o>", make_parm_name(parm->label), *(int *)ptr);
221 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'0%o\'\">",
222 make_parm_name(parm->label),(int)(parm->def.ivalue));
223 break;
225 case P_ENUM:
226 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
227 for (i=0;parm->enum_list[i].name;i++)
228 printf("<option %s>%s",(*(int *)ptr)==parm->enum_list[i].value?"selected":"",parm->enum_list[i].name);
229 printf("</select>");
230 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
231 make_parm_name(parm->label),enum_index((int)(parm->def.ivalue),parm->enum_list));
232 break;
233 case P_SEP:
234 break;
236 printf("</td></tr>\n");
239 /****************************************************************************
240 display a set of parameters for a service
241 ****************************************************************************/
242 static void show_parameters(int snum, int allparameters, int advanced, int printers)
244 int i = 0;
245 struct parm_struct *parm;
246 char *heading = NULL;
247 char *last_heading = NULL;
249 while ((parm = lp_next_parameter(snum, &i, allparameters))) {
250 if (snum < 0 && parm->class == P_LOCAL && !(parm->flags & FLAG_GLOBAL))
251 continue;
252 if (parm->class == P_SEPARATOR) {
253 heading = parm->label;
254 continue;
256 if (parm->flags & FLAG_HIDE) continue;
257 if (snum >= 0) {
258 if (printers & !(parm->flags & FLAG_PRINT)) continue;
259 if (!printers & !(parm->flags & FLAG_SHARE)) continue;
261 if (!advanced) {
262 if (!(parm->flags & FLAG_BASIC)) {
263 void *ptr = parm->ptr;
265 if (parm->class == P_LOCAL && snum >= 0) {
266 ptr = lp_local_ptr(snum, ptr);
269 switch (parm->type) {
270 case P_CHAR:
271 if (*(char *)ptr == (char)(parm->def.cvalue)) continue;
272 break;
274 case P_STRING:
275 case P_USTRING:
276 if (!strcmp(*(char **)ptr,(char *)(parm->def.svalue))) continue;
277 break;
279 case P_GSTRING:
280 case P_UGSTRING:
281 if (!strcmp((char *)ptr,(char *)(parm->def.svalue))) continue;
282 break;
284 case P_BOOL:
285 case P_BOOLREV:
286 if (*(BOOL *)ptr == (BOOL)(parm->def.bvalue)) continue;
287 break;
289 case P_INTEGER:
290 case P_OCTAL:
291 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
292 break;
295 case P_ENUM:
296 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
297 break;
298 case P_SEP:
299 continue;
302 if (printers && !(parm->flags & FLAG_PRINT)) continue;
304 if (heading && heading != last_heading) {
305 printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", heading);
306 last_heading = heading;
308 show_parameter(snum, parm);
312 /****************************************************************************
313 load the smb.conf file into loadparm.
314 ****************************************************************************/
315 static BOOL load_config(BOOL save_def)
317 lp_resetnumservices();
318 return lp_load(servicesf,False,save_def,False);
321 /****************************************************************************
322 write a config file
323 ****************************************************************************/
324 static void write_config(FILE *f, BOOL show_defaults)
326 fprintf(f, "# Samba config file created using SWAT\n");
327 fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
328 fprintf(f, "# Date: %s\n\n", timestring());
330 lp_dump(f, show_defaults, iNumNonAutoPrintServices);
333 /****************************************************************************
334 save and reoad the smb.conf config file
335 ****************************************************************************/
336 static int save_reload(int snum)
338 FILE *f;
340 f = sys_fopen(servicesf,"w");
341 if (!f) {
342 printf("failed to open %s for writing\n", servicesf);
343 return 0;
346 write_config(f, False);
347 if (snum)
348 lp_dump_one(f, False, snum);
349 fclose(f);
351 lp_killunused(NULL);
353 if (!load_config(False)) {
354 printf("Can't reload %s\n", servicesf);
355 return 0;
357 iNumNonAutoPrintServices = lp_numservices();
358 load_printers();
360 return 1;
363 /****************************************************************************
364 commit one parameter
365 ****************************************************************************/
366 static void commit_parameter(int snum, struct parm_struct *parm, char *v)
368 int i;
369 char *s;
371 if (snum < 0 && parm->class == P_LOCAL) {
372 /* this handles the case where we are changing a local
373 variable globally. We need to change the parameter in
374 all shares where it is currently set to the default */
375 for (i=0;i<lp_numservices();i++) {
376 s = lp_servicename(i);
377 if (s && (*s) && lp_is_default(i, parm)) {
378 lp_do_parameter(i, parm->label, v);
383 lp_do_parameter(snum, parm->label, v);
386 /****************************************************************************
387 commit a set of parameters for a service
388 ****************************************************************************/
389 static void commit_parameters(int snum)
391 int i = 0;
392 struct parm_struct *parm;
393 pstring label;
394 char *v;
396 while ((parm = lp_next_parameter(snum, &i, 1))) {
397 slprintf(label, sizeof(label)-1, "parm_%s", make_parm_name(parm->label));
398 if ((v = cgi_variable(label))) {
399 if (parm->flags & FLAG_HIDE) continue;
400 commit_parameter(snum, parm, v);
405 /****************************************************************************
406 spit out the html for a link with an image
407 ****************************************************************************/
408 static void image_link(char *name,char *hlink, char *src)
410 printf("<A HREF=\"%s/%s\"><img src=\"/swat/%s\" alt=\"%s\"></A>\n",
411 cgi_baseurl(), hlink, src, name);
414 /****************************************************************************
415 display the main navigation controls at the top of each page along
416 with a title
417 ****************************************************************************/
418 static void show_main_buttons(void)
420 image_link("Home", "", "images/home.gif");
421 if (have_read_access) {
422 image_link("Globals", "globals", "images/globals.gif");
423 image_link("Shares", "shares", "images/shares.gif");
424 image_link("Printers", "printers", "images/printers.gif");
425 image_link("Status", "status", "images/status.gif");
426 image_link("View Config", "viewconfig","images/viewconfig.gif");
428 image_link("Password Management", "passwd", "images/passwd.gif");
430 printf("<HR>\n");
433 /****************************************************************************
434 display a welcome page
435 ****************************************************************************/
436 static void welcome_page(void)
438 include_html("help/welcome.html");
441 /****************************************************************************
442 display the current smb.conf
443 ****************************************************************************/
444 static void viewconfig_page(void)
446 int full_view=0;
448 if (cgi_variable("full_view")) {
449 full_view = 1;
452 printf("<H2>Current Config</H2>\n");
453 printf("<form method=post>\n");
455 if (full_view) {
456 printf("<input type=submit name=\"normal_view\" value=\"Normal View\">\n");
457 } else {
458 printf("<input type=submit name=\"full_view\" value=\"Full View\">\n");
461 printf("<p><pre>");
462 write_config(stdout, full_view);
463 printf("</pre>");
464 printf("</form>\n");
467 /****************************************************************************
468 display a globals editing page
469 ****************************************************************************/
470 static void globals_page(void)
472 int advanced = 0;
474 printf("<H2>Global Variables</H2>\n");
476 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
477 advanced = 1;
479 if (cgi_variable("Commit")) {
480 commit_parameters(GLOBALS_SNUM);
481 save_reload(0);
484 printf("<FORM name=\"swatform\" method=post>\n");
486 if (have_write_access) {
487 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
490 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
491 if (advanced == 0) {
492 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
493 } else {
494 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
496 printf("<p>\n");
498 printf("<table>\n");
499 show_parameters(GLOBALS_SNUM, 1, advanced, 0);
500 printf("</table>\n");
502 if (advanced) {
503 printf("<input type=hidden name=\"Advanced\" value=1>\n");
506 printf("</FORM>\n");
509 /****************************************************************************
510 display a shares editing page
511 ****************************************************************************/
512 static void shares_page(void)
514 char *share = cgi_variable("share");
515 char *s;
516 int snum=-1;
517 int i;
518 int advanced = 0;
520 if (share)
521 snum = lp_servicenumber(share);
523 printf("<H2>Share Parameters</H2>\n");
525 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
526 advanced = 1;
528 if (cgi_variable("Commit") && snum >= 0) {
529 commit_parameters(snum);
530 save_reload(0);
533 if (cgi_variable("Delete") && snum >= 0) {
534 lp_remove_service(snum);
535 save_reload(0);
536 share = NULL;
537 snum = -1;
540 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
541 load_config(False);
542 lp_copy_service(GLOBALS_SNUM, share);
543 iNumNonAutoPrintServices = lp_numservices();
544 save_reload(0);
545 snum = lp_servicenumber(share);
548 printf("<FORM name=\"swatform\" method=post>\n");
550 printf("<table>\n");
551 printf("<tr>\n");
552 printf("<td><input type=submit name=selectshare value=\"Choose Share\"></td>\n");
553 printf("<td><select name=share>\n");
554 if (snum < 0)
555 printf("<option value=\" \"> \n");
556 for (i=0;i<lp_numservices();i++) {
557 s = lp_servicename(i);
558 if (s && (*s) && strcmp(s,"IPC$") && !lp_print_ok(i)) {
559 printf("<option %s value=\"%s\">%s\n",
560 (share && strcmp(share,s)==0)?"SELECTED":"",
561 s, s);
564 printf("</select></td>\n");
565 if (have_write_access) {
566 printf("<td><input type=submit name=\"Delete\" value=\"Delete Share\"></td>\n");
568 printf("</tr>\n");
569 printf("</table>");
570 printf("<table>");
571 if (have_write_access) {
572 printf("<tr>\n");
573 printf("<td><input type=submit name=createshare value=\"Create Share\"></td>\n");
574 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
576 printf("</table>");
579 if (snum >= 0) {
580 if (have_write_access) {
581 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
584 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
585 if (advanced == 0) {
586 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
587 } else {
588 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
590 printf("<p>\n");
593 if (snum >= 0) {
594 printf("<table>\n");
595 show_parameters(snum, 1, advanced, 0);
596 printf("</table>\n");
599 if (advanced) {
600 printf("<input type=hidden name=\"Advanced\" value=1>\n");
603 printf("</FORM>\n");
606 /*************************************************************
607 change a password either locally or remotely
608 *************************************************************/
609 static BOOL change_password(const char *remote_machine, char *user_name,
610 char *old_passwd, char *new_passwd,
611 BOOL add_user, BOOL enable_user, BOOL disable_user)
613 BOOL ret = False;
614 pstring err_str;
615 pstring msg_str;
617 if (demo_mode) {
618 printf("password change in demo mode rejected\n<p>");
619 return False;
622 if (remote_machine != NULL) {
623 ret = remote_password_change(remote_machine, user_name, old_passwd,
624 new_passwd, err_str, sizeof(err_str));
625 if(*err_str)
626 printf("%s\n<p>", err_str);
627 return ret;
630 if(!initialize_password_db()) {
631 printf("Can't setup password database vectors.\n<p>");
632 return False;
635 ret = local_password_change(user_name, False, add_user, enable_user,
636 disable_user, False, new_passwd, err_str, sizeof(err_str),
637 msg_str, sizeof(msg_str));
639 if(*msg_str)
640 printf("%s\n<p>", msg_str);
641 if(*err_str)
642 printf("%s\n<p>", err_str);
644 return ret;
647 /****************************************************************************
648 do the stuff required to add or change a password
649 ****************************************************************************/
650 static void chg_passwd(void)
652 char *host;
653 BOOL rslt;
655 /* Make sure users name has been specified */
656 if (strlen(cgi_variable(SWAT_USER)) == 0) {
657 printf("<p> Must specify \"User Name\" \n");
658 return;
662 * smbpasswd doesn't require anything but the users name to disable or enable the user,
663 * so if that's what we're doing, skip the rest of the checks
665 if (!cgi_variable(DISABLE_USER_FLAG) && !cgi_variable(ENABLE_USER_FLAG)) {
668 * If current user is not root, make sure old password has been specified
669 * If REMOTE change, even root must provide old password
671 if (((!am_root()) && (strlen( cgi_variable(OLD_PSWD)) <= 0)) ||
672 ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable(OLD_PSWD)) <= 0))) {
673 printf("<p> Must specify \"Old Password\" \n");
674 return;
677 /* If changing a users password on a remote hosts we have to know what host */
678 if ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable(RHOST)) <= 0)) {
679 printf("<p> Must specify \"Remote Machine\" \n");
680 return;
683 /* Make sure new passwords have been specified */
684 if ((strlen( cgi_variable(NEW_PSWD)) <= 0) ||
685 (strlen( cgi_variable(NEW2_PSWD)) <= 0)) {
686 printf("<p> Must specify \"New, and Re-typed Passwords\" \n");
687 return;
690 /* Make sure new passwords was typed correctly twice */
691 if (strcmp(cgi_variable(NEW_PSWD), cgi_variable(NEW2_PSWD)) != 0) {
692 printf("<p> Re-typed password didn't match new password\n");
693 return;
697 if (cgi_variable(CHG_R_PASSWD_FLAG)) {
698 host = cgi_variable(RHOST);
699 } else if (am_root()) {
700 host = NULL;
701 } else {
702 host = "127.0.0.1";
704 rslt = change_password(host,
705 cgi_variable(SWAT_USER),
706 cgi_variable(OLD_PSWD), cgi_variable(NEW_PSWD),
707 cgi_variable(ADD_USER_FLAG)? True : False,
708 cgi_variable(ENABLE_USER_FLAG)? True : False,
709 cgi_variable(DISABLE_USER_FLAG)? True : False);
712 if (rslt == True) {
713 printf("<p> The passwd for '%s' has been changed. \n", cgi_variable(SWAT_USER));
714 } else {
715 printf("<p> The passwd for '%s' has NOT been changed. \n",cgi_variable(SWAT_USER));
718 return;
721 /****************************************************************************
722 display a password editing page
723 ****************************************************************************/
724 static void passwd_page(void)
726 char *new_name = cgi_user_name();
729 * After the first time through here be nice. If the user
730 * changed the User box text to another users name, remember it.
732 if (cgi_variable(SWAT_USER)) {
733 new_name = cgi_variable(SWAT_USER);
736 if (!new_name) new_name = "";
738 printf("<H2>Server Password Management</H2>\n");
740 printf("<FORM name=\"swatform\" method=post>\n");
742 printf("<table>\n");
745 * Create all the dialog boxes for data collection
747 printf("<tr><td> User Name : </td>\n");
748 printf("<td><input type=text size=30 name=%s value=%s></td></tr> \n", SWAT_USER, new_name);
749 if (!am_root()) {
750 printf("<tr><td> Old Password : </td>\n");
751 printf("<td><input type=password size=30 name=%s></td></tr> \n",OLD_PSWD);
753 printf("<tr><td> New Password : </td>\n");
754 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
755 printf("<tr><td> Re-type New Password : </td>\n");
756 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
757 printf("</table>\n");
760 * Create all the control buttons for requesting action
762 printf("<input type=submit name=%s value=\"Change Password\">\n",
763 CHG_S_PASSWD_FLAG);
764 if (demo_mode || am_root()) {
765 printf("<input type=submit name=%s value=\"Add New User\">\n",
766 ADD_USER_FLAG);
767 printf("<input type=submit name=%s value=\"Disable User\">\n",
768 DISABLE_USER_FLAG);
769 printf("<input type=submit name=%s value=\"Enable User\">\n",
770 ENABLE_USER_FLAG);
772 printf("<p></FORM>\n");
775 * Do some work if change, add, disable or enable was
776 * requested. It could be this is the first time through this
777 * code, so there isn't anything to do. */
778 if ((cgi_variable(CHG_S_PASSWD_FLAG)) || (cgi_variable(ADD_USER_FLAG)) ||
779 (cgi_variable(DISABLE_USER_FLAG)) || (cgi_variable(ENABLE_USER_FLAG))) {
780 chg_passwd();
783 printf("<H2>Client/Server Password Management</H2>\n");
785 printf("<FORM name=\"swatform\" method=post>\n");
787 printf("<table>\n");
790 * Create all the dialog boxes for data collection
792 printf("<tr><td> User Name : </td>\n");
793 printf("<td><input type=text size=30 name=%s value=%s></td></tr>\n",SWAT_USER, new_name);
794 printf("<tr><td> Old Password : </td>\n");
795 printf("<td><input type=password size=30 name=%s></td></tr>\n",OLD_PSWD);
796 printf("<tr><td> New Password : </td>\n");
797 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
798 printf("<tr><td> Re-type New Password : </td>\n");
799 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
800 printf("<tr><td> Remote Machine : </td>\n");
801 printf("<td><input type=password size=30 name=%s></td></tr>\n",RHOST);
803 printf("</table>");
806 * Create all the control buttons for requesting action
808 printf("<input type=submit name=%s value=\"Change Password\">",
809 CHG_R_PASSWD_FLAG);
811 printf("<p></FORM>\n");
814 * Do some work if a request has been made to change the
815 * password somewhere other than the server. It could be this
816 * is the first time through this code, so there isn't
817 * anything to do. */
818 if (cgi_variable(CHG_R_PASSWD_FLAG)) {
819 chg_passwd();
824 /****************************************************************************
825 display a printers editing page
826 ****************************************************************************/
827 static void printers_page(void)
829 char *share = cgi_variable("share");
830 char *s;
831 int snum=-1;
832 int i;
833 int advanced = 0;
835 if (share)
836 snum = lp_servicenumber(share);
838 printf("<H2>Printer Parameters</H2>\n");
840 printf("<H3>Important Note:</H3>\n");
841 printf("Printer names marked with [*] in the Choose Printer drop-down box ");
842 printf("are autoloaded printers from ");
843 printf("<A HREF=\"/swat/help/smb.conf.5.html#printcapname\" target=\"docs\">Printcap Name</A>.\n");
844 printf("Attempting to delete these printers from SWAT will have no effect.\n");
846 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
847 advanced = 1;
849 if (cgi_variable("Commit") && snum >= 0) {
850 commit_parameters(snum);
851 if (snum >= iNumNonAutoPrintServices)
852 save_reload(snum);
853 else
854 save_reload(0);
857 if (cgi_variable("Delete") && snum >= 0) {
858 lp_remove_service(snum);
859 save_reload(0);
860 share = NULL;
861 snum = -1;
864 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
865 load_config(False);
866 lp_copy_service(GLOBALS_SNUM, share);
867 iNumNonAutoPrintServices = lp_numservices();
868 snum = lp_servicenumber(share);
869 lp_do_parameter(snum, "print ok", "Yes");
870 save_reload(0);
871 snum = lp_servicenumber(share);
874 printf("<FORM name=\"swatform\" method=post>\n");
876 printf("<table>\n");
877 printf("<tr><td><input type=submit name=selectshare value=\"Choose Printer\"></td>\n");
878 printf("<td><select name=share>\n");
879 if (snum < 0 || !lp_print_ok(snum))
880 printf("<option value=\" \"> \n");
881 for (i=0;i<lp_numservices();i++) {
882 s = lp_servicename(i);
883 if (s && (*s) && strcmp(s,"IPC$") && lp_print_ok(i)) {
884 if (i >= iNumNonAutoPrintServices)
885 printf("<option %s value=\"%s\">[*]%s\n",
886 (share && strcmp(share,s)==0)?"SELECTED":"",
887 s, s);
888 else
889 printf("<option %s value=\"%s\">%s\n",
890 (share && strcmp(share,s)==0)?"SELECTED":"",
891 s, s);
894 printf("</select></td>");
895 if (have_write_access) {
896 printf("<td><input type=submit name=\"Delete\" value=\"Delete Printer\"></td>\n");
898 printf("</tr>");
899 printf("</table>\n");
901 if (have_write_access) {
902 printf("<table>\n");
903 printf("<tr><td><input type=submit name=createshare value=\"Create Printer\"></td>\n");
904 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
905 printf("</table>");
909 if (snum >= 0) {
910 if (have_write_access) {
911 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
913 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
914 if (advanced == 0) {
915 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
916 } else {
917 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
919 printf("<p>\n");
922 if (snum >= 0) {
923 printf("<table>\n");
924 show_parameters(snum, 1, advanced, 1);
925 printf("</table>\n");
928 if (advanced) {
929 printf("<input type=hidden name=\"Advanced\" value=1>\n");
932 printf("</FORM>\n");
935 /****************************************************************************
936 MAIN()
937 ****************************************************************************/
938 int main(int argc, char *argv[])
940 extern char *optarg;
941 extern int optind;
942 extern FILE *dbf;
943 int opt;
944 char *page;
946 #if defined(HAVE_SET_AUTH_PARAMETERS)
947 set_auth_parameters(argc, argv);
948 #endif /* HAVE_SET_AUTH_PARAMETERS */
950 /* just in case it goes wild ... */
951 alarm(300);
953 dbf = sys_fopen("/dev/null", "w");
955 if (!dbf) dbf = stderr;
957 while ((opt = getopt(argc, argv,"s:a")) != EOF) {
958 switch (opt) {
959 case 's':
960 pstrcpy(servicesf,optarg);
961 break;
962 case 'a':
963 demo_mode = True;
964 break;
968 charset_initialise();
969 load_config(True);
970 iNumNonAutoPrintServices = lp_numservices();
971 load_printers();
973 cgi_setup(SWATDIR, !demo_mode);
975 print_header();
977 cgi_load_variables(NULL);
979 if (!file_exist(servicesf, NULL)) {
980 have_read_access = True;
981 have_write_access = True;
982 } else {
983 /* check if the authenticated user has write access - if not then
984 don't show write options */
985 have_write_access = (access(servicesf,W_OK) == 0);
987 /* if the user doesn't have read access to smb.conf then
988 don't let them view it */
989 have_read_access = (access(servicesf,R_OK) == 0);
994 show_main_buttons();
996 page = cgi_pathinfo();
998 /* Root gets full functionality */
999 if (have_read_access && strcmp(page, "globals")==0) {
1000 globals_page();
1001 } else if (have_read_access && strcmp(page,"shares")==0) {
1002 shares_page();
1003 } else if (have_read_access && strcmp(page,"printers")==0) {
1004 printers_page();
1005 } else if (have_read_access && strcmp(page,"status")==0) {
1006 status_page();
1007 } else if (have_read_access && strcmp(page,"viewconfig")==0) {
1008 viewconfig_page();
1009 } else if (strcmp(page,"passwd")==0) {
1010 passwd_page();
1011 } else {
1012 welcome_page();
1015 print_footer();
1016 return 0;