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 SDEFAULTS "Service defaults"
30 #define SGLOBAL "Global Parameters"
31 #define GLOBALS_SNUM -2
32 #define DEFAULTS_SNUM -1
34 static pstring servicesf = CONFIGFILE;
37 /* start the page with standard stuff */
38 static void print_header(void)
40 printf("Content-type: text/html\r\n\r\n");
41 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
42 printf("<HTML>\n<HEAD>\n<TITLE>smb.conf</TITLE>\n</HEAD>\n<BODY>\n\n");
46 /* finish off the page */
47 static void print_footer(void)
49 printf("\n</BODY>\n</HTML>\n");
52 /* display a servce, ready for editing */
53 static void show_service(int snum, int allparameters)
59 if (snum == GLOBALS_SNUM)
61 else if (snum == DEFAULTS_SNUM)
63 else sname = lp_servicename(snum);
65 printf("\n<p><table border=0>\n<tr>\n<td></td><td>\n\n");
66 printf("<form method=POST>\n");
67 printf("<H3>%s</H3>\n", sname);
68 printf("<input type=hidden name=service value=\"%s\">\n", sname);
69 printf("<input type=submit name=request value=Change>\n");
70 printf("<input type=submit name=request value=Rename>\n");
71 printf("<input type=submit name=request value=Copy>\n");
72 printf("<input type=submit name=request value=Remove>\n");
73 printf("<br><input name=newvalue><br>\n");
74 printf("<select name=parameter size=5>\n");
76 while (lp_next_parameter(snum, &i, label, value, allparameters)) {
77 printf("<option value=\"%s\">%s = %s\n",
81 printf("</select>\n");
82 printf("</form>\n</td>\n</tr>\n</table>\n");
88 /* loop over all services, displaying them one after the other */
89 static void show_services(void)
93 int allparameters = cgi_boolean("allparameters", 0);
95 printf("<FORM METHOD=POST>\n");
96 printf("<p>Show all parameters?\n");
97 printf("<INPUT NAME=allparameters TYPE=checkbox VALUE=1 %s>\n",
98 allparameters?"CHECKED":"");
100 printf("<INPUT TYPE=submit NAME=reload VALUE=Reload>\n");
104 n = lp_numservices();
106 show_service(GLOBALS_SNUM, allparameters);
107 show_service(DEFAULTS_SNUM, allparameters);
111 show_service(i, allparameters);
115 /* load the smb.conf file into loadparm. */
116 static int load_config(void)
119 if (!lp_load(servicesf,False)) {
120 printf("<b>Can't load %s - using defaults</b><p>\n",
127 static int save_reload(void)
131 f = fopen(servicesf,"w");
133 printf("failed to open %s for writing\n", servicesf);
137 fprintf(f, "# Samba config file created using wsmbconf\n");
145 if (!lp_load(servicesf,False)) {
146 printf("Can't reload %s\n", servicesf);
153 static void process_requests(void)
155 char *req = cgi_variable("request");
156 char *newvalue = cgi_variable("newvalue");
157 char *parameter = cgi_variable("parameter");
158 char *service = cgi_variable("service");
164 /* work out what service it is */
165 if (strcmp(service,SGLOBAL) == 0) {
167 } else if (strcmp(service,SDEFAULTS) == 0) {
168 snum = DEFAULTS_SNUM;
170 snum = lp_servicenumber(service);
171 if (snum < 0) return;
178 if (strcmp(req,"Change") == 0) {
179 /* change the value of a parameter */
180 if (!parameter || !service) return;
182 lp_do_parameter(snum, parameter, newvalue);
183 } else if (strcmp(req,"Rename") == 0) {
184 /* rename a service */
185 if (!newvalue || !service) return;
187 lp_rename_service(snum, newvalue);
188 } else if (strcmp(req,"Remove") == 0) {
189 /* remove a service */
190 if (!service) return;
192 lp_remove_service(snum);
193 } else if (strcmp(req,"Copy") == 0) {
195 if (!service || !newvalue) return;
197 lp_copy_service(snum, newvalue);
204 int main(int argc, char *argv[])
211 dbf = fopen("/dev/null", "w");
213 if (!dbf) dbf = stderr;
218 while ((opt = getopt(argc, argv,"s:")) != EOF) {
221 pstrcpy(servicesf,optarg);
229 charset_initialise();
232 cgi_load_variables(NULL);