2 Unix SMB/Netbios implementation.
4 html smb.conf editing - prototype only
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.
29 #define GLOBALS_SNUM -2
30 #define DEFAULTS_SNUM -1
32 static pstring servicesf = CONFIGFILE;
35 /* start the page with standard stuff */
36 static void print_header(void)
38 printf("Expires: %s\r\n", http_timestring(time(NULL)));
39 printf("Content-type: text/html\r\n\r\n");
40 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
41 printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY>\n\n");
45 /* finish off the page */
46 static void print_footer(void)
48 printf("\n</BODY>\n</HTML>\n");
51 /* include a lump of html in a page */
52 static void include_html(char *fname)
54 FILE *f = fopen(fname,"r");
59 printf("ERROR: Can't open %s\n", fname);
64 ret = fread(buf, 1, sizeof(buf), f);
66 fwrite(buf, 1, ret, stdout);
73 /* display one editable parameter */
74 static void show_parameter(int snum, struct parm_struct *parm)
77 void *ptr = parm->ptr;
79 if (parm->class == P_LOCAL) {
80 ptr = lp_local_ptr(snum, ptr);
83 printf("<tr><td><A HREF=\"help/parameters.html#%s\">?</A> %s</td><td>",
84 parm->label, parm->label);
88 printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
89 parm->label, *(char *)ptr);
94 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
95 parm->label, *(char **)ptr);
100 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
101 parm->label, (char *)ptr);
105 printf("<input type=radio name=\"parm_%s\" value=Yes %s>yes ", parm->label, (*(BOOL *)ptr)?"CHECKED":"");
106 printf("<input type=radio name=\"parm_%s\" value=No %s>no", parm->label, (*(BOOL *)ptr)?"":"CHECKED");
110 printf("<input type=radio name=\"parm_%s\" value=Yes %s>yes ", parm->label, (*(BOOL *)ptr)?"":"CHECKED");
111 printf("<input type=radio name=\"parm_%s\" value=No %s>no", parm->label, (*(BOOL *)ptr)?"CHECKED":"");
115 printf("<input type=text size=8 name=\"parm_%s\" value=%d>", parm->label, *(int *)ptr);
119 printf("<input type=text size=8 name=\"parm_%s\" value=0%o>", parm->label, *(int *)ptr);
123 for (i=0;parm->enum_list[i].name;i++)
124 printf("<input type=radio name=\"parm_%s\" value=%s %s>%s ",
125 parm->label, parm->enum_list[i].name,
126 (*(int *)ptr)==parm->enum_list[i].value?"CHECKED":"",
127 parm->enum_list[i].name);
131 printf("</td></tr>\n");
134 /* display a set of parameters for a service */
135 static void show_parameters(int snum, int allparameters, int advanced, int printers)
138 struct parm_struct *parm;
142 while ((parm = lp_next_parameter(snum, &i, allparameters))) {
143 if (parm->flags & FLAG_HIDE) continue;
145 if (!printers && !(parm->flags & FLAG_BASIC)) continue;
146 if (printers && !(parm->flags & FLAG_PRINT)) continue;
148 show_parameter(snum, parm);
150 printf("</table>\n");
154 static int save_reload(void)
158 f = fopen(servicesf,"w");
160 printf("failed to open %s for writing\n", servicesf);
164 fprintf(f, "# Samba config file created using SWAT\n");
172 if (!lp_load(servicesf,False)) {
173 printf("Can't reload %s\n", servicesf);
182 /* commit a set of parameters for a service */
183 static void commit_parameters(int snum)
186 struct parm_struct *parm;
190 while ((parm = lp_next_parameter(snum, &i, 1))) {
191 sprintf(label, "parm_%s", parm->label);
192 if ((v = cgi_variable(label))) {
193 lp_do_parameter(snum, parm->label, v);
201 /* load the smb.conf file into loadparm. */
202 static void load_config(void)
204 if (!lp_load(servicesf,False)) {
205 printf("<b>Can't load %s - using defaults</b><p>\n",
210 /* spit out the html for a link with an image */
211 static void image_link(char *name,char *hlink, char *src, int width, int height)
213 printf("<A HREF=\"%s\"><img width=%d height=%d src=\"%s\" alt=\"%s\"></A>\n", hlink, width, height, src, name);
216 /* display the main navigation controls at the top of each page along
218 static void show_main_buttons(void)
220 printf("<H2 align=center>Samba Web Administration Tool</H2>\n");
222 image_link("Home", "", "images/home.gif", 50, 50);
223 image_link("Globals", "globals", "images/globals.gif", 50, 50);
224 image_link("Shares", "shares", "images/shares.gif", 50, 50);
225 image_link("Printers", "printers", "images/printers.gif", 50, 50);
230 /* display a welcome page */
231 static void welcome_page(void)
233 include_html("help/welcome.html");
237 /* display a globals editing page */
238 static void globals_page(void)
242 printf("<H2>Global Variables</H2>\n");
244 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
247 if (cgi_variable("Commit")) {
248 commit_parameters(GLOBALS_SNUM);
251 printf("<FORM method=post>\n");
253 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
255 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
257 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
261 show_parameters(GLOBALS_SNUM, 1, advanced, 0);
264 printf("<input type=hidden name=\"Advanced\" value=1>\n");
270 /* display a shares editing page */
271 static void shares_page(void)
273 char *share = cgi_variable("share");
280 snum = lp_servicenumber(share);
282 printf("<H2>Share Parameters</H2>\n");
284 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
287 if (cgi_variable("Commit") && snum >= 0) {
288 commit_parameters(snum);
291 if (cgi_variable("Delete") && snum >= 0) {
292 lp_remove_service(snum);
298 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
299 lp_copy_service(DEFAULTS_SNUM, share);
301 snum = lp_servicenumber(share);
304 printf("<FORM method=post>\n");
307 printf("<tr><td><input type=submit name=selectshare value=\"Choose Share\"></td>\n");
308 printf("<td><select name=share>\n");
310 printf("<option value=\" \"> \n");
311 for (i=0;i<lp_numservices();i++) {
312 s = lp_servicename(i);
313 if (s && (*s) && strcmp(s,"IPC$") && !lp_print_ok(i)) {
314 printf("<option %s value=\"%s\">%s\n",
315 (share && strcmp(share,s)==0)?"SELECTED":"",
319 printf("</select></td></tr><p>");
321 printf("<tr><td><input type=submit name=createshare value=\"Create Share\"></td>\n");
322 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
327 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
328 printf("<input type=submit name=\"Delete\" value=\"Delete Share\">\n");
330 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
332 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
338 show_parameters(snum, 1, advanced, 0);
342 printf("<input type=hidden name=\"Advanced\" value=1>\n");
349 /* display a printers editing page */
350 static void printers_page(void)
352 char *share = cgi_variable("share");
359 snum = lp_servicenumber(share);
361 printf("<H2>Printer Parameters</H2>\n");
363 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
366 if (cgi_variable("Commit") && snum >= 0) {
367 commit_parameters(snum);
370 if (cgi_variable("Delete") && snum >= 0) {
371 lp_remove_service(snum);
377 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
378 lp_copy_service(DEFAULTS_SNUM, share);
379 snum = lp_servicenumber(share);
380 lp_do_parameter(snum, "print ok", "Yes");
382 snum = lp_servicenumber(share);
385 printf("<FORM method=post>\n");
388 printf("<tr><td><input type=submit name=selectshare value=\"Choose Printer\"></td>\n");
389 printf("<td><select name=share>\n");
390 if (snum < 0 || !lp_print_ok(snum))
391 printf("<option value=\" \"> \n");
392 for (i=0;i<lp_numservices();i++) {
393 s = lp_servicename(i);
394 if (s && (*s) && strcmp(s,"IPC$") && lp_print_ok(i)) {
395 printf("<option %s value=\"%s\">%s\n",
396 (share && strcmp(share,s)==0)?"SELECTED":"",
400 printf("</select></td></tr><p>");
402 printf("<tr><td><input type=submit name=createshare value=\"Create Printer\"></td>\n");
403 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
408 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
409 printf("<input type=submit name=\"Delete\" value=\"Delete Printer\">\n");
411 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
413 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
419 show_parameters(snum, 1, advanced, 1);
423 printf("<input type=hidden name=\"Advanced\" value=1>\n");
430 int main(int argc, char *argv[])
437 int auth_required = 1;
439 /* just in case it goes wild ... */
442 dbf = fopen("/dev/null", "w");
444 if (!dbf) dbf = stderr;
446 while ((opt = getopt(argc, argv,"s:a")) != EOF) {
449 pstrcpy(servicesf,optarg);
457 cgi_setup(SWATDIR, auth_required);
461 charset_initialise();
463 /* if this binary is setuid then run completely as root */
468 cgi_load_variables(NULL);
472 page = cgi_baseurl();
474 if (strcmp(page, "globals")==0) {
476 } else if (strcmp(page,"shares")==0) {
478 } else if (strcmp(page,"printers")==0) {