2 Unix SMB/Netbios implementation.
4 html smb.conf editing - prototype only
5 Copyright (C) Andrew Tridgell 1997
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
35 /* start the page with standard stuff */
36 static void print_header(void)
38 printf("Content-type: text/html\n\n");
39 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
40 printf("<HTML>\n<HEAD>\n<TITLE>smb.conf</TITLE>\n</HEAD>\n<BODY>\n\n");
44 /* finish off the page */
45 static void print_footer(void)
47 printf("\n</BODY>\n</HTML>\n");
50 /* setup persisant variables */
51 static void set_persistent(char *name
)
54 p
= cgi_variable(name
);
56 printf("<input type=hidden name=%s value=%s>\n", name
, p
);
59 /* display a servce, ready for editing */
60 static void show_service(int snum
, int allparameters
)
66 if (snum
== GLOBALS_SNUM
)
68 else if (snum
== DEFAULTS_SNUM
)
70 else sname
= lp_servicename(snum
);
72 printf("\n<p><table border=0>\n<tr>\n<td></td><td>\n\n");
73 printf("<form method=POST>\n");
74 printf("<H3>%s</H3>\n", sname
);
75 printf("<input type=hidden name=service value=\"%s\">\n", sname
);
76 printf("<input type=submit name=request value=Change>\n");
77 printf("<input type=submit name=request value=Rename>\n");
78 printf("<input type=submit name=request value=Copy>\n");
79 printf("<input type=submit name=request value=Remove>\n");
80 printf("<br><input name=newvalue><br>\n");
81 printf("<select name=parameter size=5>\n");
83 while (lp_next_parameter(snum
, &i
, label
, value
, allparameters
)) {
84 printf("<option value=\"%s\">%s = %s\n",
88 printf("</select>\n");
89 printf("</form>\n</td>\n</tr>\n</table>\n");
95 /* loop over all services, displaying them one after the other */
96 static void show_services(void)
100 int allparameters
= cgi_boolean("allparameters", 0);
102 printf("<FORM METHOD=POST>\n");
103 printf("<p>Show all parameters?\n");
104 printf("<INPUT NAME=allparameters TYPE=checkbox VALUE=1 %s>\n",
105 allparameters
?"CHECKED":"");
107 printf("<INPUT TYPE=submit NAME=reload VALUE=Reload>\n");
111 n
= lp_numservices();
113 show_service(GLOBALS_SNUM
, allparameters
);
114 show_service(DEFAULTS_SNUM
, allparameters
);
118 show_service(i
, allparameters
);
122 /* load the smb.conf file into loadparm. this also does the chroot
123 to the config directory. This must be called _BEFORE_ any client
124 supplied data is parsed */
125 static int load_config(void)
127 static pstring servicesf
= CONFIGFILE
;
130 p
= strrchr(servicesf
,'/');
137 if (chdir(servicesf
) || chroot(servicesf
)) {
138 printf("wsmbconf is not configured correctly\n");
144 if (!lp_load(p
,False
)) {
145 printf("<b>Can't load %s - using defaults</b><p>\n",
152 static int save_reload(void)
154 static pstring servicesf
= CONFIGFILE
;
158 p
= strrchr(servicesf
,'/');
163 printf("failed to open %s for writing\n", servicesf
);
167 fprintf(f
, "# Samba config file created using wsmbconf\n");
175 if (!lp_load(p
,False
)) {
176 printf("Can't reload %s\n", servicesf
);
183 static void process_requests(void)
185 char *req
= cgi_variable("request");
186 char *newvalue
= cgi_variable("newvalue");
187 char *parameter
= cgi_variable("parameter");
188 char *service
= cgi_variable("service");
194 /* work out what service it is */
195 if (strcmp(service
,SGLOBAL
) == 0) {
197 } else if (strcmp(service
,SDEFAULTS
) == 0) {
198 snum
= DEFAULTS_SNUM
;
200 snum
= lp_servicenumber(service
);
201 if (snum
< 0) return;
208 if (strcmp(req
,"Change") == 0) {
209 /* change the value of a parameter */
210 if (!parameter
|| !service
) return;
212 lp_do_parameter(snum
, parameter
, newvalue
);
213 } else if (strcmp(req
,"Rename") == 0) {
214 /* rename a service */
215 if (!newvalue
|| !service
) return;
217 lp_rename_service(snum
, newvalue
);
218 } else if (strcmp(req
,"Remove") == 0) {
219 /* remove a service */
220 if (!service
) return;
222 lp_remove_service(snum
);
223 } else if (strcmp(req
,"Copy") == 0) {
225 if (!service
|| !newvalue
) return;
227 lp_copy_service(snum
, newvalue
);
234 int main(int argc
, char *argv
[])
242 charset_initialise();
245 cgi_load_variables();