TTB: project integration and GUI
[tomato.git] / release / src / router / httpd / tomato.c
blobdbaeb5a1babba9d3aa11c0e4c9864992cf38d29f
1 /*
3 Tomato Firmware
4 Copyright (C) 2006-2010 Jonathan Zarate
6 */
8 #include "tomato.h"
10 #include <sys/sysinfo.h>
11 #include <sys/stat.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <arpa/inet.h>
15 #include <time.h>
18 // #define DEBUG_NOEXECSERVICE
19 #define DEBUG_NVRAMSET(k, v) _dprintf("nvram set %s=%s\n", k, v);
22 char *post_buf = NULL;
23 int rboot = 0;
24 extern int post;
26 static void asp_css(int argc, char **argv);
27 static void asp_resmsg(int argc, char **argv);
30 static void wo_tomato(char *url);
31 static void wo_update(char *url);
32 static void wo_service(char *url);
33 static void wo_shutdown(char *url);
34 static void wo_nvcommit(char *url);
35 // static void wo_logout(char *url);
38 // ----------------------------------------------------------------------------
41 void exec_service(const char *action)
43 int i;
45 _dprintf("exec_service: %s\n", action);
47 i = 10;
48 while ((!nvram_match("action_service", "")) && (i-- > 0)) {
49 _dprintf("%s: waiting before %d\n", __FUNCTION__, i);
50 sleep(1);
53 nvram_set("action_service", action);
54 kill(1, SIGUSR1);
56 i = 3;
57 while ((nvram_match("action_service", (char *)action)) && (i-- > 0)) {
58 _dprintf("%s: waiting after %d\n", __FUNCTION__, i);
59 sleep(1);
63 if (atoi(webcgi_safeget("_service_wait", ""))) {
64 i = 10;
65 while ((nvram_match("action_service", (char *)action)) && (i-- > 0)) {
66 _dprintf("%s: waiting after %d\n", __FUNCTION__, i);
67 sleep(1);
73 static void wi_generic_noid(char *url, int len, char *boundary)
75 if (post == 1) {
76 if (len >= (32 * 1024)) {
77 // syslog(LOG_WARNING, "POST max");
78 exit(1);
81 if (post_buf) free(post_buf);
82 if ((post_buf = malloc(len + 1)) == NULL) {
83 // syslog(LOG_CRIT, "Unable to allocate post buffer");
84 exit(1);
87 if (web_read_x(post_buf, len) != len) {
88 exit(1);
90 post_buf[len] = 0;
91 webcgi_init(post_buf);
95 void wi_generic(char *url, int len, char *boundary)
97 wi_generic_noid(url, len, boundary);
98 check_id(url);
101 // !!TB - CGI Support
102 void wi_cgi_bin(char *url, int len, char *boundary)
104 if (post_buf) free(post_buf);
105 post_buf = NULL;
107 if (post) {
108 if (len >= (128 * 1024)) {
109 syslog(LOG_WARNING, "POST length exceeded maximum allowed");
110 exit(1);
113 if (len > 0) {
114 if ((post_buf = malloc(len + 1)) == NULL) {
115 exit(1);
117 if (web_read_x(post_buf, len) != len) {
118 exit(1);
120 post_buf[len] = 0;
125 static void _execute_command(char *url, char *command, char *query, wofilter_t wof)
127 char webExecFile[] = "/tmp/.wxXXXXXX";
128 char webQueryFile[] = "/tmp/.wqXXXXXX";
129 char cmd[sizeof(webExecFile) + 10];
130 FILE *f;
131 int fe, fq = -1;
133 if ((fe = mkstemp(webExecFile)) < 0)
134 exit(1);
135 if (query) {
136 if ((fq = mkstemp(webQueryFile)) < 0) {
137 close(fe);
138 unlink(webExecFile);
139 exit(1);
143 if ((f = fdopen(fe, "wb")) != NULL) {
144 fprintf(f,
145 "#!/bin/sh\n"
146 "export REQUEST_METHOD=\"%s\"\n"
147 "export PATH=%s\n"
148 ". /etc/profile\n"
149 "%s%s %s%s\n",
150 post ? "POST" : "GET", getenv("PATH"),
151 command ? "" : "./", command ? command : url,
152 query ? "<" : "", query ? webQueryFile : "");
153 fclose(f);
155 else {
156 close(fe);
157 unlink(webExecFile);
158 if (query) {
159 close(fq);
160 unlink(webQueryFile);
162 exit(1);
164 chmod(webExecFile, 0700);
166 if (query) {
167 if ((f = fdopen(fq, "wb")) != NULL) {
168 fprintf(f, "%s\n", query);
169 fclose(f);
171 else {
172 unlink(webExecFile);
173 close(fq);
174 unlink(webQueryFile);
175 exit(1);
179 sprintf(cmd, "%s 2>&1", webExecFile);
180 web_pipecmd(cmd, wof);
181 unlink(webQueryFile);
182 unlink(webExecFile);
185 static void wo_cgi_bin(char *url)
187 if (!header_sent) send_header(200, NULL, mime_html, 0);
188 _execute_command(url, NULL, post_buf, WOF_NONE);
189 if (post_buf) {
190 free(post_buf);
191 post_buf = NULL;
195 static void wo_shell(char *url)
197 web_puts("\ncmdresult = '");
198 _execute_command(NULL, webcgi_get("command"), NULL, WOF_JAVASCRIPT);
199 web_puts("';");
202 static void wo_blank(char *url)
204 web_puts("\n\n\n\n");
207 static void wo_favicon(char *url)
209 send_header(200, NULL, "image/vnd.microsoft.icon", 0);
210 do_file(url);
212 if (nvram_match("web_favicon", "1")) {
213 send_header(200, NULL, "image/vnd.microsoft.icon", 0);
214 do_file(url);
216 else {
217 send_error(404, NULL, NULL);
222 static void wo_cfe(char *url)
224 do_file(MTD_DEV(0ro));
227 static void wo_nvram(char *url)
229 web_pipecmd("nvram show", WOF_NONE);
232 static void wo_iptables(char *url)
234 web_pipecmd("iptables -nvL; echo; iptables -t nat -nvL; echo; iptables -t mangle -nvL", WOF_NONE);
237 #ifdef TCONFIG_IPV6
238 static void wo_ip6tables(char *url)
240 web_pipecmd("ip6tables -nvL; echo; ip6tables -t mangle -nvL", WOF_NONE);
242 #endif
245 static void wo_spin(char *url)
247 char s[64];
249 strlcpy(s, nvram_safe_get("web_css"), sizeof(s));
250 strlcat(s, "_spin.gif", sizeof(s));
251 if (f_exists(s)) do_file(s);
252 else do_file("_spin.gif");
256 void common_redirect(void)
258 if (atoi(webcgi_safeget("_ajax", ""))) {
259 send_header(200, NULL, mime_html, 0);
260 web_puts("OK");
262 else {
263 redirect(webcgi_safeget("_redirect", "/"));
267 // ----------------------------------------------------------------------------
269 const struct mime_handler mime_handlers[] = {
270 { "update.cgi", mime_javascript, 0, wi_generic, wo_update, 1 },
271 { "tomato.cgi", NULL, 0, wi_generic, wo_tomato, 1 },
273 { "debug.js", mime_javascript, 5, wi_generic_noid, wo_blank, 1 }, // while debugging
274 { "cfe/*.bin", mime_binary, 0, wi_generic, wo_cfe, 1 },
275 { "nvram/*.txt", mime_binary, 0, wi_generic, wo_nvram, 1 },
276 { "ipt/*.txt", mime_binary, 0, wi_generic, wo_iptables, 1 },
277 #ifdef TCONFIG_IPV6
278 { "ip6t/*.txt", mime_binary, 0, wi_generic, wo_ip6tables, 1 },
279 #endif
280 { "cfg/*.cfg", NULL, 0, wi_generic, wo_backup, 1 },
281 { "cfg/restore.cgi", mime_html, 0, wi_restore, wo_restore, 1 },
282 { "cfg/defaults.cgi", NULL, 0, wi_generic, wo_defaults, 1 },
284 { "bwm/*.gz", NULL, 0, wi_generic, wo_bwmbackup, 1 },
285 { "bwm/restore.cgi", NULL, 0, wi_bwmrestore, wo_bwmrestore, 1 },
287 { "ipt/*.gz", NULL, 0, wi_generic, wo_iptbackup, 1 },
288 { "ipt/restore.cgi", NULL, 0, wi_iptrestore, wo_iptrestore, 1 },
290 { "logs/view.cgi", NULL, 0, wi_generic, wo_viewlog, 1 },
291 { "logs/*.txt", NULL, 0, wi_generic, wo_syslog, 1 },
292 { "webmon_**", NULL, 0, wi_generic, wo_syslog, 1 },
294 { "logout.asp", NULL, 0, wi_generic, wo_asp, 1 },
295 { "clearcookies.asp", NULL, 0, wi_generic, wo_asp, 1 },
297 // { "spin.gif", NULL, 0, wi_generic_noid, wo_spin, 1 },
299 { "**.asp", NULL, 0, wi_generic_noid, wo_asp, 1 },
300 { "**.css", "text/css", 2, wi_generic_noid, do_file, 1 },
301 { "**.htm|**.html", mime_html, 2, wi_generic_noid, do_file, 1 },
302 { "**.gif", "image/gif", 5, wi_generic_noid, do_file, 1 },
303 { "**.jpg", "image/jpeg", 5, wi_generic_noid, do_file, 1 },
304 { "**.png", "image/png", 5, wi_generic_noid, do_file, 1 },
305 { "**.js", mime_javascript, 2, wi_generic_noid, do_file, 1 },
306 { "**.jsx", mime_javascript, 0, wi_generic, wo_asp, 1 },
307 { "**.svg", "image/svg+xml", 2, wi_generic_noid, do_file, 1 },
308 { "**.txt", mime_plain, 2, wi_generic_noid, do_file, 1 },
309 { "**.bin", mime_binary, 0, wi_generic_noid, do_file, 1 },
310 { "**.bino", mime_octetstream, 0, wi_generic_noid, do_file, 1 },
311 { "favicon.ico", NULL, 5, wi_generic_noid, wo_favicon, 1 },
312 // !!TB - CGI Support, enable downloading archives
313 { "**/cgi-bin/**|**.sh", NULL, 0, wi_cgi_bin, wo_cgi_bin, 1 },
314 { "**.tar|**.gz", mime_binary, 0, wi_generic_noid, do_file, 1 },
315 { "shell.cgi", mime_javascript, 0, wi_generic, wo_shell, 1 },
316 { "wpad.dat|proxy.pac", "application/x-ns-proxy-autoconfig", 0, wi_generic_noid, do_file, 0 },
318 { "webmon.cgi", mime_javascript, 0, wi_generic, wo_webmon, 1 },
319 { "dhcpc.cgi", NULL, 0, wi_generic, wo_dhcpc, 1 },
320 { "dhcpd.cgi", mime_javascript, 0, wi_generic, wo_dhcpd, 1 },
321 { "nvcommit.cgi", NULL, 0, wi_generic, wo_nvcommit, 1 },
322 { "ping.cgi", mime_javascript, 0, wi_generic, wo_ping, 1 },
323 { "trace.cgi", mime_javascript, 0, wi_generic, wo_trace, 1 },
324 { "upgrade.cgi", mime_html, 0, wi_upgrade, wo_flash, 1 },
325 { "upnp.cgi", NULL, 0, wi_generic, wo_upnp, 1 },
326 { "wakeup.cgi", NULL, 0, wi_generic, wo_wakeup, 1 },
327 { "wlmnoise.cgi", mime_html, 0, wi_generic, wo_wlmnoise, 1 },
328 { "wlradio.cgi", NULL, 0, wi_generic, wo_wlradio, 1 },
329 { "resolve.cgi", mime_javascript, 0, wi_generic, wo_resolve, 1 },
330 { "expct.cgi", mime_html, 0, wi_generic, wo_expct, 1 },
331 { "service.cgi", NULL, 0, wi_generic, wo_service, 1 },
332 // { "logout.cgi", NULL, 0, wi_generic, wo_logout, 0 },
333 // see httpd.c
334 { "shutdown.cgi", mime_html, 0, wi_generic, wo_shutdown, 1 },
335 #ifdef TCONFIG_OPENVPN
336 { "vpnstatus.cgi", mime_javascript, 0, wi_generic, wo_vpn_status, 1 },
337 #endif
338 #ifdef TCONFIG_PPTPD
339 { "pptpd.cgi", mime_javascript, 0, wi_generic, wo_pptpdcmd, 1 }, //!!AB - PPTPD
340 #endif
341 #ifdef TCONFIG_USB
342 { "usbcmd.cgi", mime_javascript, 0, wi_generic, wo_usbcommand, 1 }, //!!TB - USB
343 #endif
344 #ifdef BLACKHOLE
345 { "blackhole.cgi", NULL, 0, wi_blackhole, NULL, 1 },
346 #endif
347 #ifdef TCONFIG_NOCAT
348 { "uploadsplash.cgi", NULL, 0, wi_uploadsplash, wo_uploadsplash, 1 },
349 { "ext/uploadsplash.cgi", NULL, 0, wi_uploadsplash, wo_uploadsplash, 1 },
350 #endif
351 { NULL, NULL, 0, NULL, NULL, 1 }
354 const aspapi_t aspapi[] = {
355 { "activeroutes", asp_activeroutes },
356 { "arplist", asp_arplist },
357 { "bandwidth", asp_bandwidth },
358 { "build_time", asp_build_time },
359 { "cgi_get", asp_cgi_get },
360 { "compmac", asp_compmac },
361 { "ctcount", asp_ctcount },
362 { "ctdump", asp_ctdump },
363 { "ctrate", asp_ctrate },
364 { "ddnsx", asp_ddnsx },
365 { "devlist", asp_devlist },
366 { "webmon", asp_webmon },
367 { "dhcpc_time", asp_dhcpc_time },
368 { "dns", asp_dns },
369 { "ident", asp_ident },
370 { "lanip", asp_lanip },
371 { "layer7", asp_layer7 },
372 { "link_uptime", asp_link_uptime },
373 { "lipp", asp_lipp },
374 { "netdev", asp_netdev },
376 { "iptraffic", asp_iptraffic },
377 { "iptmon", asp_iptmon },
378 { "ipt_bandwidth", asp_ipt_bandwidth },
380 { "notice", asp_notice },
381 { "nv", asp_nv },
382 { "nvram", asp_nvram },
383 { "nvramseq", asp_nvramseq },
384 { "nvstat", asp_nvstat },
385 { "psup", asp_psup },
386 { "qrate", asp_qrate },
387 { "resmsg", asp_resmsg },
388 { "rrule", asp_rrule },
389 { "statfs", asp_statfs },
390 { "sysinfo", asp_sysinfo },
391 { "time", asp_time },
392 { "upnpinfo", asp_upnpinfo },
393 { "version", asp_version },
394 { "wanstatus", asp_wanstatus },
395 { "wanup", asp_wanup },
396 #ifdef TCONFIG_PPTPD
397 { "pptpd_userol", asp_pptpd_userol },
398 #endif
399 { "wlstats", asp_wlstats },
400 { "wlclient", asp_wlclient },
401 { "wlnoise", asp_wlnoise },
402 { "wlscan", asp_wlscan },
403 { "wlchannels", asp_wlchannels }, //!!TB
404 { "wlcountries", asp_wlcountries },
405 { "wlifaces", asp_wlifaces },
406 { "wlbands", asp_wlbands },
407 #ifdef TCONFIG_USB
408 { "usbdevices", asp_usbdevices }, //!!TB - USB Support
409 #endif
410 #ifdef TCONFIG_SDHC
411 { "mmcid", asp_mmcid }, //MMC Support
412 #endif
413 #ifdef TCONFIG_IPV6
414 { "calc6rdlocalprefix", asp_calc6rdlocalprefix },
415 #endif
417 { "css", asp_css },
418 { NULL, NULL }
421 // -----------------------------------------------------------------------------
423 static void asp_css(int argc, char **argv)
425 const char *css = nvram_safe_get("web_css");
426 const char *ttb = nvram_safe_get("ttb_css");
428 if( nvram_match( "web_css", "online" ) ) {
429 web_printf("<link rel='stylesheet' type='text/css' href='ext/%s.css'>", ttb);
430 } else {
431 if (strcmp(css, "tomato") != 0) {
432 web_printf("<link rel='stylesheet' type='text/css' href='%s.css'>", css);
437 // -----------------------------------------------------------------------------
439 const char *resmsg_get(void)
441 return webcgi_safeget("resmsg", "");
444 void resmsg_set(const char *msg)
446 webcgi_set("resmsg", strdup(msg)); // m ok
449 int resmsg_fread(const char *fname)
451 char s[256];
452 char *p;
454 f_read_string(fname, s, sizeof(s));
455 if ((p = strchr(s, '\n')) != NULL) *p = 0;
456 if (s[0]) {
457 resmsg_set(s);
458 return 1;
460 return 0;
463 static void asp_resmsg(int argc, char **argv)
465 char *p;
467 if ((p = js_string(webcgi_safeget("resmsg", (argc > 0) ? argv[0] : ""))) == NULL) return;
468 web_printf("\nresmsg='%s';\n", p);
469 free(p);
472 // ----------------------------------------------------------------------------
474 // verification... simple sanity checks. UI should verify all fields.
476 // todo: move and re-use for filtering - zzz
478 typedef union {
479 int i;
480 long l;
481 const char *s;
482 } nvset_varg_t;
484 typedef struct {
485 const char *name;
486 enum {
487 VT_NONE, // no checking
488 VT_LENGTH, // check length of string
489 VT_TEXT, // strip \r, check length of string
490 VT_RANGE, // expect an integer, check range
491 VT_IP, // expect an ip address
492 VT_MAC, // expect a mac address
493 #ifdef TCONFIG_IPV6
494 VT_IPV6, // expect an ipv6 address
495 #endif
496 VT_TEMP // no checks, no commit
497 } vtype;
498 nvset_varg_t va;
499 nvset_varg_t vb;
500 } nvset_t;
503 #define V_NONE VT_NONE, { }, { }
504 #define V_01 VT_RANGE, { .l = 0 }, { .l = 1 }
505 #define V_PORT VT_RANGE, { .l = 2 }, { .l = 65535 }
506 #define V_ONOFF VT_LENGTH, { .i = 2 }, { .i = 3 }
507 #define V_WORD VT_LENGTH, { .i = 1 }, { .i = 16 }
508 #define V_LENGTH(min, max) VT_LENGTH, { .i = min }, { .i = max }
509 #define V_TEXT(min, max) VT_TEXT, { .i = min }, { .i = max }
510 #define V_RANGE(min, max) VT_RANGE, { .l = min }, { .l = max }
511 #define V_IP VT_IP, { }, { }
512 #define V_OCTET VT_RANGE, { .l = 0 }, { .l = 255 }
513 #define V_NUM VT_RANGE, { .l = 0 }, { .l = 0x7FFFFFFF }
514 #define V_TEMP VT_TEMP, { }, { }
515 #ifdef TCONFIG_IPV6
516 #define V_IPV6(required) VT_IPV6, { .i = required }, { }
517 #endif
519 static const nvset_t nvset_list[] = {
521 // basic-ident
522 { "router_name", V_LENGTH(0, 32) },
523 { "wan_hostname", V_LENGTH(0, 32) },
524 { "wan_domain", V_LENGTH(0, 32) },
526 // basic-time
527 { "tm_tz", V_LENGTH(1, 64) }, // PST8PDT
528 { "tm_sel", V_LENGTH(1, 64) }, // PST8PDT
529 { "tm_dst", V_01 },
530 { "ntp_updates", V_RANGE(-1, 24) },
531 { "ntp_tdod", V_01 },
532 { "ntp_server", V_LENGTH(1, 150) }, // x y z
533 { "ntp_kiss", V_LENGTH(0, 255) },
535 // basic-static
536 { "dhcpd_static", V_LENGTH(0, 108*251) }, // 108 (max chars per entry) x 250 entries
537 { "dhcpd_static_only", V_01 },
539 // basic-ddns
540 { "ddnsx0", V_LENGTH(0, 2048) },
541 { "ddnsx1", V_LENGTH(0, 2048) },
542 { "ddnsx0_cache", V_LENGTH(0, 1) }, // only to clear
543 { "ddnsx1_cache", V_LENGTH(0, 1) },
544 { "ddnsx_ip", V_LENGTH(0, 32) },
545 { "ddnsx_save", V_01 },
546 { "ddnsx_refresh", V_RANGE(0, 365) },
548 // basic-network
549 // WAN
550 { "wan_proto", V_LENGTH(1, 16) }, // disabled, dhcp, static, pppoe, pptp, l2tp
551 { "wan_ipaddr", V_IP },
552 { "wan_netmask", V_IP },
553 { "wan_gateway", V_IP },
554 { "hb_server_ip", V_LENGTH(0, 32) },
555 { "l2tp_server_ip", V_LENGTH(0, 128) },
556 { "pptp_server_ip", V_LENGTH(0, 128) },
557 { "pptp_dhcp", V_01 },
558 { "ppp_username", V_LENGTH(0, 60) },
559 { "ppp_passwd", V_LENGTH(0, 60) },
560 { "ppp_service", V_LENGTH(0, 50) },
561 { "ppp_demand", V_01 },
562 { "ppp_custom", V_LENGTH(0, 256) },
563 { "ppp_idletime", V_RANGE(0, 1440) },
564 { "ppp_redialperiod", V_RANGE(1, 86400) },
565 { "ppp_mlppp", V_01 },
566 { "mtu_enable", V_01 },
567 { "wan_mtu", V_RANGE(576, 1500) },
568 { "wan_islan", V_01 },
569 { "modem_ipaddr", V_IP },
571 // LAN
572 { "lan_ipaddr", V_IP },
573 { "lan_netmask", V_IP },
574 { "lan_gateway", V_IP },
575 { "wan_dns", V_LENGTH(0, 50) }, // ip ip ip
576 #ifdef TCONFIG_DNSCRYPT
577 { "dnscrypt_proxy", V_01 },
578 #endif
579 { "lan_proto", V_WORD }, // static, dhcp
580 { "dhcp_start", V_LENGTH(0, 15) }, // remove !
581 { "dhcp_num", V_LENGTH(0, 4) }, // remove !
582 { "dhcpd_startip", V_LENGTH(0, 15) },
583 { "dhcpd_endip", V_LENGTH(0, 15) },
584 { "dhcp_lease", V_LENGTH(0, 5) },
585 { "wan_wins", V_IP },
587 #ifdef TCONFIG_USB
588 // 3G MODEM
589 { "modem_pin", V_LENGTH(0,6) },
590 { "modem_dev", V_LENGTH(0,8) },
591 { "modem_init", V_LENGTH(0,25) },
592 { "modem_apn", V_LENGTH(0,25) },
593 #endif
595 // LAN networks
596 { "lan_ifname", V_LENGTH(0, 5) },
598 { "lan1_ifname", V_LENGTH(0, 5) },
599 { "lan1_ifnames", V_TEXT(0,64) },
600 { "lan1_ipaddr", V_LENGTH(0, 15) },
601 { "lan1_netmask", V_LENGTH(0, 15) },
602 { "lan1_proto", V_LENGTH(0, 6) },
603 { "lan1_stp", V_LENGTH(0, 1) },
604 { "dhcp1_start", V_LENGTH(0, 15) },
605 { "dhcp1_num", V_LENGTH(0, 4) },
606 { "dhcpd1_startip", V_LENGTH(0, 15) },
607 { "dhcpd1_endip", V_LENGTH(0, 15) },
608 { "dhcp1_lease", V_LENGTH(0, 5) },
610 { "lan2_ifname", V_LENGTH(0, 5) },
611 { "lan2_ifnames", V_TEXT(0,64) },
612 { "lan2_ipaddr", V_LENGTH(0, 15) },
613 { "lan2_netmask", V_LENGTH(0, 15) },
614 { "lan2_proto", V_LENGTH(0, 6) },
615 { "lan2_stp", V_LENGTH(0, 1) },
616 { "dhcp2_start", V_LENGTH(0, 15) },
617 { "dhcp2_num", V_LENGTH(0, 4) },
618 { "dhcpd2_startip", V_LENGTH(0, 15) },
619 { "dhcpd2_endip", V_LENGTH(0, 15) },
620 { "dhcp2_lease", V_LENGTH(0, 5) },
622 { "lan3_ifname", V_LENGTH(0, 5) },
623 { "lan3_ifnames", V_TEXT(0,64) },
624 { "lan3_ipaddr", V_LENGTH(0, 15) },
625 { "lan3_netmask", V_LENGTH(0, 15) },
626 { "lan3_proto", V_LENGTH(0, 6) },
627 { "lan3_stp", V_LENGTH(0, 1) },
628 { "dhcp3_start", V_LENGTH(0, 15) },
629 { "dhcp3_num", V_LENGTH(0, 4) },
630 { "dhcpd3_startip", V_LENGTH(0, 15) },
631 { "dhcpd3_endip", V_LENGTH(0, 15) },
632 { "dhcp3_lease", V_LENGTH(0, 5) },
634 // wireless
635 { "wl_radio", V_01 },
636 { "wl_mode", V_LENGTH(2, 3) }, // ap, sta, wet, wds
637 { "wl_net_mode", V_LENGTH(5, 8) }, // disabled, mixed, b-only, g-only, bg-mixed, n-only [speedbooster]
638 { "wl_ssid", V_LENGTH(1, 32) },
639 { "wl_closed", V_01 },
640 { "wl_channel", V_RANGE(0, 216) },
642 { "wl_vifs", V_LENGTH(0, 64) }, // multiple/virtual BSSIDs
643 #ifndef LINUX26
644 { "nas_alternate", V_01 }, // only meaningful for ND/K24 builds
645 #endif
647 { "wl_security_mode", V_LENGTH(1, 32) }, // disabled, radius, wep, wpa_personal, wpa_enterprise, wpa2_personal, wpa2_enterprise
648 { "wl_radius_ipaddr", V_IP },
649 { "wl_radius_port", V_PORT },
650 { "wl_radius_key", V_LENGTH(1, 64) },
651 { "wl_wep_bit", V_RANGE(64, 128) }, // 64 or 128
652 { "wl_passphrase", V_LENGTH(0, 20) },
653 { "wl_key", V_RANGE(1, 4) },
654 { "wl_key1", V_LENGTH(0, 26) },
655 { "wl_key2", V_LENGTH(0, 26) },
656 { "wl_key3", V_LENGTH(0, 26) },
657 { "wl_key4", V_LENGTH(0, 26) },
658 { "wl_crypto", V_LENGTH(3, 8) }, // tkip, aes, tkip+aes
659 { "wl_wpa_psk", V_LENGTH(8, 64) },
660 { "wl_wpa_gtk_rekey", V_RANGE(60, 7200) },
662 { "wl_lazywds", V_01 },
663 { "wl_wds", V_LENGTH(0, 180) }, // mac mac mac (x 10)
665 { "wl_wds_enable", V_01 },
666 { "wl_gmode", V_RANGE(-1, 6) },
667 { "wl_wep", V_LENGTH(1, 32) }, // off, on, restricted,tkip,aes,tkip+aes
668 { "wl_akm", V_LENGTH(0, 32) }, // wpa, wpa2, psk, psk2, wpa wpa2, psk psk2, ""
669 { "wl_auth_mode", V_LENGTH(4, 6) }, // none, radius
671 { "wl_nmode", V_NONE },
672 { "wl_nband", V_RANGE(0, 2) }, // 2 - 2.4GHz, 1 - 5GHz, 0 - Auto
673 { "wl_nreqd", V_NONE },
674 { "wl_nbw_cap", V_RANGE(0, 2) }, // 0 - 20MHz, 1 - 40MHz, 2 - Auto
675 { "wl_nbw", V_NONE },
676 { "wl_mimo_preamble", V_WORD }, // 802.11n Preamble: mm/gf/auto/gfbcm
677 { "wl_nctrlsb", V_NONE }, // none, lower, upper
679 #ifdef TCONFIG_IPV6
680 // basic-ipv6
681 { "ipv6_service", V_LENGTH(0, 16) }, // '', native, native-pd, 6to4, sit, other
682 { "ipv6_prefix", V_IPV6(0) },
683 { "ipv6_prefix_length", V_RANGE(3, 127) },
684 { "ipv6_rtr_addr", V_IPV6(0) },
685 { "ipv6_radvd", V_01 },
686 { "ipv6_accept_ra", V_NUM },
687 { "ipv6_tun_addr", V_IPV6(1) },
688 { "ipv6_tun_addrlen", V_RANGE(3, 127) },
689 { "ipv6_ifname", V_LENGTH(0, 8) },
690 { "ipv6_tun_v4end", V_IP },
691 { "ipv6_relay", V_RANGE(1, 254) },
692 { "ipv6_tun_mtu", V_NUM }, // Tunnel MTU
693 { "ipv6_tun_ttl", V_NUM }, // Tunnel TTL
694 { "ipv6_dns", V_LENGTH(0, 40*3) }, // ip6 ip6 ip6
695 { "ipv6_6rd_prefix", V_IPV6(0) },
696 { "ipv6_6rd_prefix_length", V_RANGE(3, 127) },
697 { "ipv6_6rd_border_relay", V_IP },
698 { "ipv6_6rd_ipv4masklen", V_RANGE(0, 255) },
699 #endif
701 // basic-wfilter
702 { "wl_macmode", V_NONE }, // allow, deny, disabled
703 { "wl_maclist", V_LENGTH(0, 18*201) }, // 18 x 200 (11:22:33:44:55:66 ...)
704 { "macnames", V_LENGTH(0, 62*201) }, // 62 (12+1+48+1) x 50 (112233445566<..>) todo: re-use -- zzz
706 // advanced-ctnf
707 { "ct_max", V_NUM },
708 { "ct_tcp_timeout", V_LENGTH(20, 70) },
709 { "ct_udp_timeout", V_LENGTH(5, 15) },
710 { "ct_timeout", V_LENGTH(5, 15) },
711 { "nf_ttl", V_LENGTH(1, 6) },
712 { "nf_l7in", V_01 },
713 #ifdef LINUX26
714 { "nf_sip", V_01 },
715 { "ct_hashsize", V_NUM },
716 #endif
717 { "nf_rtsp", V_01 },
718 { "nf_pptp", V_01 },
719 { "nf_h323", V_01 },
720 { "nf_ftp", V_01 },
722 // advanced-dhcpdns
723 { "dhcpd_slt", V_RANGE(-1, 43200) }, // -1=infinite, 0=follow normal lease time, >=1 custom
724 { "dhcpd_dmdns", V_01 },
725 { "dhcpd_lmax", V_NUM },
726 { "dhcpd_gwmode", V_NUM },
727 { "dns_addget", V_01 },
728 { "dns_intcpt", V_01 },
729 { "dhcpc_minpkt", V_01 },
730 { "dhcpc_custom", V_LENGTH(0, 80) },
731 { "dns_norebind", V_01 },
732 { "dnsmasq_custom", V_TEXT(0, 2048) },
733 // { "dnsmasq_norw", V_01 },
735 // advanced-firewall
736 { "block_wan", V_01 },
737 { "block_wan_limit", V_01 },
738 { "block_wan_limit_icmp", V_RANGE(1, 300) },
739 { "block_wan_limit_tr", V_RANGE(1, 300) },
740 { "multicast_pass", V_01 },
741 { "multicast_lan", V_01 },
742 { "multicast_lan1", V_01 },
743 { "multicast_lan2", V_01 },
744 { "multicast_lan3", V_01 },
745 { "block_loopback", V_01 },
746 { "udpxy_enable", V_01 },
747 { "udpxy_stats", V_01 },
748 { "udpxy_clients", V_RANGE(1, 5000) },
749 { "udpxy_port", V_RANGE(0, 65535) },
750 { "nf_loopback", V_NUM },
751 { "ne_syncookies", V_01 },
752 { "ne_snat", V_01 },
753 { "dhcp_pass", V_01 },
754 #ifdef TCONFIG_EMF
755 { "emf_entry", V_NONE },
756 { "emf_uffp_entry", V_NONE },
757 { "emf_rtport_entry", V_NONE },
758 { "emf_enable", V_01 },
759 #endif
761 // advanced-misc
762 { "wait_time", V_RANGE(3, 20) },
763 { "wan_speed", V_RANGE(0, 4) },
764 { "jumbo_frame_enable", V_01 }, // Jumbo Frames support (for RT-N16/WNR3500L)
765 { "jumbo_frame_size", V_RANGE(1, 9720) },
766 #ifdef CONFIG_BCMWL5
767 { "ctf_disable", V_01 },
768 #endif
769 // advanced-vlan
770 { "vlan0ports", V_TEXT(0,16) },
771 { "vlan1ports", V_TEXT(0,16) },
772 { "vlan2ports", V_TEXT(0,16) },
773 { "vlan3ports", V_TEXT(0,16) },
774 { "vlan4ports", V_TEXT(0,16) },
775 { "vlan5ports", V_TEXT(0,16) },
776 { "vlan6ports", V_TEXT(0,16) },
777 { "vlan7ports", V_TEXT(0,16) },
778 { "vlan8ports", V_TEXT(0,16) },
779 { "vlan9ports", V_TEXT(0,16) },
780 { "vlan10ports", V_TEXT(0,16) },
781 { "vlan11ports", V_TEXT(0,16) },
782 { "vlan12ports", V_TEXT(0,16) },
783 { "vlan13ports", V_TEXT(0,16) },
784 { "vlan14ports", V_TEXT(0,16) },
785 { "vlan15ports", V_TEXT(0,16) },
786 { "vlan0hwname", V_TEXT(0,8) },
787 { "vlan1hwname", V_TEXT(0,8) },
788 { "vlan2hwname", V_TEXT(0,8) },
789 { "vlan3hwname", V_TEXT(0,8) },
790 { "vlan4hwname", V_TEXT(0,8) },
791 { "vlan5hwname", V_TEXT(0,8) },
792 { "vlan6hwname", V_TEXT(0,8) },
793 { "vlan7hwname", V_TEXT(0,8) },
794 { "vlan8hwname", V_TEXT(0,8) },
795 { "vlan9hwname", V_TEXT(0,8) },
796 { "vlan10hwname", V_TEXT(0,8) },
797 { "vlan11hwname", V_TEXT(0,8) },
798 { "vlan12hwname", V_TEXT(0,8) },
799 { "vlan13hwname", V_TEXT(0,8) },
800 { "vlan14hwname", V_TEXT(0,8) },
801 { "vlan15hwname", V_TEXT(0,8) },
802 { "wan_ifnameX", V_TEXT(0,8) },
803 { "lan_ifnames", V_TEXT(0,64) },
804 { "manual_boot_nv", V_01 },
805 { "trunk_vlan_so", V_01 },
806 { "vlan0tag", V_TEXT(0,5) },
807 { "vlan0vid", V_TEXT(0,5) },
808 { "vlan1vid", V_TEXT(0,5) },
809 { "vlan2vid", V_TEXT(0,5) },
810 { "vlan3vid", V_TEXT(0,5) },
811 { "vlan4vid", V_TEXT(0,5) },
812 { "vlan5vid", V_TEXT(0,5) },
813 { "vlan6vid", V_TEXT(0,5) },
814 { "vlan7vid", V_TEXT(0,5) },
815 { "vlan8vid", V_TEXT(0,5) },
816 { "vlan9vid", V_TEXT(0,5) },
817 { "vlan10vid", V_TEXT(0,5) },
818 { "vlan11vid", V_TEXT(0,5) },
819 { "vlan12vid", V_TEXT(0,5) },
820 { "vlan13vid", V_TEXT(0,5) },
821 { "vlan14vid", V_TEXT(0,5) },
822 { "vlan15vid", V_TEXT(0,5) },
824 // advanced-mac
825 { "mac_wan", V_LENGTH(0, 17) },
826 { "wl_macaddr", V_LENGTH(0, 17) },
827 { "wl_hwaddr", V_LENGTH(0, 17) },
829 // advanced-routing
830 { "routes_static", V_LENGTH(0, 2048) },
831 { "dhcp_routes", V_01 },
832 { "lan_stp", V_RANGE(0, 1) },
833 { "wk_mode", V_LENGTH(1, 32) }, // gateway, router
834 #ifdef TCONFIG_ZEBRA
835 { "dr_setting", V_RANGE(0, 3) },
836 { "dr_lan_tx", V_LENGTH(0, 32) },
837 { "dr_lan_rx", V_LENGTH(0, 32) },
838 { "dr_lan1_tx", V_LENGTH(0, 32) },
839 { "dr_lan1_rx", V_LENGTH(0, 32) },
840 { "dr_lan2_tx", V_LENGTH(0, 32) },
841 { "dr_lan2_rx", V_LENGTH(0, 32) },
842 { "dr_lan3_tx", V_LENGTH(0, 32) },
843 { "dr_lan3_rx", V_LENGTH(0, 32) },
844 { "dr_wan_tx", V_LENGTH(0, 32) },
845 { "dr_wan_rx", V_LENGTH(0, 32) },
846 #endif
848 // advanced-access
849 { "lan_access", V_LENGTH(0, 4096) },
851 // advanced-wireless
852 { "wl_country", V_LENGTH(0, 64) }, // !!TB - Country code
853 { "wl_country_code", V_LENGTH(0, 4) }, // !!TB - Country code
854 { "wl_btc_mode", V_RANGE(0, 2) }, // !!TB - BT Coexistence Mode: 0 (disable), 1 (enable), 2 (preemption)
855 { "wl_afterburner", V_LENGTH(2, 4) }, // off, on, auto
856 { "wl_auth", V_01 },
857 { "wl_rateset", V_LENGTH(2, 7) }, // all, default, 12
858 { "wl_rate", V_RANGE(0, 54 * 1000 * 1000) },
859 { "wl_mrate", V_RANGE(0, 54 * 1000 * 1000) },
860 { "wl_gmode_protection",V_LENGTH(3, 4) }, // off, auto
861 { "wl_frameburst", V_ONOFF }, // off, on
862 { "wl_bcn", V_RANGE(1, 65535) },
863 { "wl_dtim", V_RANGE(1, 255) },
864 { "wl_frag", V_RANGE(256, 2346) },
865 { "wl_rts", V_RANGE(0, 2347) },
866 { "wl_ap_isolate", V_01 },
867 { "wl_plcphdr", V_LENGTH(4, 5) }, // long, short
868 { "wl_antdiv", V_RANGE(0, 3) },
869 { "wl_txant", V_RANGE(0, 3) },
870 { "wl_txpwr", V_RANGE(0, 400) },
871 { "wl_wme", V_WORD }, // auto, off, on
872 { "wl_wme_no_ack", V_ONOFF }, // off, on
873 { "wl_wme_apsd", V_ONOFF }, // off, on
874 { "wl_maxassoc", V_RANGE(0, 255) },
875 { "wl_distance", V_LENGTH(0, 5) }, // "", 1-99999
876 { "wlx_hpamp", V_01 },
877 { "wlx_hperx", V_01 },
878 { "wl_reg_mode", V_LENGTH(1, 3) }, // !!TB - Regulatory: off, h, d
879 { "wl_mitigation", V_RANGE(0, 3) }, // Interference Mitigation Mode (0|1|2|3)
881 { "wl_nmode_protection", V_WORD, }, // off, auto
882 { "wl_nmcsidx", V_RANGE(-2, 32), }, // -2 - 32
883 { "wl_obss_coex", V_01 },
884 { "wl_wmf_bss_enable", V_01 }, // Toastman
886 // forward-dmz
887 { "dmz_enable", V_01 },
888 { "dmz_ipaddr", V_LENGTH(0, 15) },
889 { "dmz_sip", V_LENGTH(0, 512) },
890 { "dmz_ifname", V_LENGTH(0, 5) },
891 { "dmz_ra", V_01 },
893 // forward-upnp
894 { "upnp_enable", V_NUM },
895 { "upnp_secure", V_01 },
896 { "upnp_port", V_RANGE(0, 65535) },
897 { "upnp_ssdp_interval", V_RANGE(10, 9999) },
898 { "upnp_mnp", V_01 },
899 { "upnp_clean", V_01 },
900 { "upnp_clean_interval", V_RANGE(60, 65535) },
901 { "upnp_clean_threshold", V_RANGE(0, 9999) },
902 { "upnp_min_port_int", V_PORT },
903 { "upnp_max_port_int", V_PORT },
904 { "upnp_min_port_ext", V_PORT },
905 { "upnp_max_port_ext", V_PORT },
906 { "upnp_lan", V_01 },
907 { "upnp_lan1", V_01 },
908 { "upnp_lan2", V_01 },
909 { "upnp_lan3", V_01 },
911 // forward-basic
912 { "portforward", V_LENGTH(0, 4096) },
914 #ifdef TCONFIG_IPV6
915 // forward-basic-ipv6
916 { "ipv6_portforward", V_LENGTH(0, 4096) },
917 #endif
919 // forward-triggered
920 { "trigforward", V_LENGTH(0, 4096) },
923 // access restriction
924 { "rruleN", V_RANGE(0, 99) },
925 // { "rrule##", V_LENGTH(0, 2048) }, // in save_variables()
927 // admin-access
928 { "http_enable", V_01 },
929 { "https_enable", V_01 },
930 { "https_crt_save", V_01 },
931 { "https_crt_cn", V_LENGTH(0, 64) },
932 { "https_crt_gen", V_TEMP },
933 { "remote_management", V_01 },
934 { "remote_mgt_https", V_01 },
935 { "http_lanport", V_PORT },
936 { "https_lanport", V_PORT },
937 { "web_wl_filter", V_01 },
938 { "web_css", V_LENGTH(1, 32) },
939 { "ttb_css", V_LENGTH(1, 32) },
940 { "web_mx", V_LENGTH(0, 128) },
941 { "http_wanport", V_PORT },
942 { "telnetd_eas", V_01 },
943 { "telnetd_port", V_PORT },
944 { "sshd_eas", V_01 },
945 { "sshd_pass", V_01 },
946 { "sshd_port", V_PORT },
947 { "sshd_remote", V_01 },
948 { "sshd_forwarding", V_01 },
949 { "sshd_rport", V_PORT },
950 { "sshd_authkeys", V_TEXT(0, 4096) },
951 { "rmgt_sip", V_LENGTH(0, 512) },
952 { "ne_shlimit", V_TEXT(1, 50) },
954 // admin-bwm
955 { "rstats_enable", V_01 },
956 { "rstats_path", V_LENGTH(0, 48) },
957 { "rstats_stime", V_RANGE(1, 168) },
958 { "rstats_offset", V_RANGE(1, 31) },
959 { "rstats_exclude", V_LENGTH(0, 64) },
960 { "rstats_sshut", V_01 },
961 { "rstats_bak", V_01 },
963 // admin-ipt
964 { "cstats_enable", V_01 },
965 { "cstats_path", V_LENGTH(0, 48) },
966 { "cstats_stime", V_RANGE(1, 168) },
967 { "cstats_offset", V_RANGE(1, 31) },
968 { "cstats_labels", V_RANGE(0, 2) },
969 { "cstats_exclude", V_LENGTH(0, 512) },
970 { "cstats_include", V_LENGTH(0, 2048) },
971 { "cstats_all", V_01 },
972 { "cstats_sshut", V_01 },
973 { "cstats_bak", V_01 },
975 // admin-buttons
976 { "sesx_led", V_RANGE(0, 255) }, // amber, white, aoss
977 { "sesx_b0", V_RANGE(0, 5) }, // 0-5: toggle wireless, reboot, shutdown, script, usb unmount
978 { "sesx_b1", V_RANGE(0, 5) }, // "
979 { "sesx_b2", V_RANGE(0, 5) }, // "
980 { "sesx_b3", V_RANGE(0, 5) }, // "
981 { "sesx_script", V_TEXT(0, 1024) }, //
982 { "script_brau", V_TEXT(0, 1024) }, //
984 // admin-debug
985 { "debug_nocommit", V_01 },
986 { "debug_cprintf", V_01 },
987 { "debug_cprintf_file", V_01 },
988 // { "debug_keepfiles", V_01 },
989 { "debug_ddns", V_01 },
990 { "debug_norestart", V_TEXT(0, 128) },
991 { "console_loglevel", V_RANGE(1, 8) },
992 { "t_cafree", V_01 },
993 { "t_hidelr", V_01 },
995 // admin-sched
996 { "sch_rboot", V_TEXT(0, 64) },
997 { "sch_rcon", V_TEXT(0, 64) },
998 { "sch_c1", V_TEXT(0, 64) },
999 { "sch_c1_cmd", V_TEXT(0, 2048) },
1000 { "sch_c2", V_TEXT(0, 64) },
1001 { "sch_c2_cmd", V_TEXT(0, 2048) },
1002 { "sch_c3", V_TEXT(0, 64) },
1003 { "sch_c3_cmd", V_TEXT(0, 2048) },
1004 { "sch_c4", V_TEXT(0, 64) },
1005 { "sch_c4_cmd", V_TEXT(0, 2048) },
1006 { "sch_c5", V_TEXT(0, 64) },
1007 { "sch_c5_cmd", V_TEXT(0, 2048) },
1009 // admin-scripts
1010 { "script_init", V_TEXT(0, 4096) },
1011 { "script_shut", V_TEXT(0, 4096) },
1012 { "script_fire", V_TEXT(0, 8192) },
1013 { "script_wanup", V_TEXT(0, 4096) },
1015 // admin-log
1016 { "log_remote", V_01 },
1017 { "log_remoteip", V_LENGTH(0, 512) },
1018 { "log_remoteport", V_PORT },
1019 { "log_file", V_01 },
1020 { "log_file_custom", V_01 },
1021 { "log_file_path", V_TEXT(0, 4096) },
1022 { "log_file_size", V_RANGE(0, 99999) },
1023 { "log_file_keep", V_RANGE(0, 99) },
1024 { "log_limit", V_RANGE(0, 2400) },
1025 { "log_in", V_RANGE(0, 3) },
1026 { "log_out", V_RANGE(0, 3) },
1027 { "log_mark", V_RANGE(0, 99999) },
1028 { "log_events", V_TEXT(0, 32) }, // "acre,crond,ntp"
1030 // admin-log-webmonitor
1031 { "log_wm", V_01 },
1032 { "log_wmtype", V_RANGE(0, 2) },
1033 { "log_wmip", V_LENGTH(0, 512) },
1034 { "log_wmdmax", V_RANGE(0, 9999) },
1035 { "log_wmsmax", V_RANGE(0, 9999) },
1037 // admin-cifs
1038 { "cifs1", V_LENGTH(1, 1024) },
1039 { "cifs2", V_LENGTH(1, 1024) },
1041 // admin-jffs2
1042 { "jffs2_on", V_01 },
1043 { "jffs2_exec", V_LENGTH(0, 64) },
1044 { "jffs2_format", V_01 },
1046 #ifdef TCONFIG_SDHC
1047 // admin-sdhc
1048 { "mmc_on", V_01 },
1049 { "mmc_cs", V_RANGE(1, 7) }, // GPIO pin
1050 { "mmc_clk", V_RANGE(1, 7) }, // GPIO pin
1051 { "mmc_din", V_RANGE(1, 7) }, // GPIO pin
1052 { "mmc_dout", V_RANGE(1, 7) }, // GPIO pin
1053 { "mmc_fs_partition", V_RANGE(1, 4) }, // partition number in partition table
1054 { "mmc_fs_type", V_LENGTH(4, 4) }, // ext2, ext3, vfat
1055 { "mmc_exec_mount", V_LENGTH(0, 64) },
1056 { "mmc_exec_umount", V_LENGTH(0, 64) },
1057 #endif
1059 // admin-tomatoanon
1060 { "tomatoanon_answer", V_RANGE(0, 1) },
1061 { "tomatoanon_enable", V_RANGE(-1, 1) },
1062 { "tomatoanon_cru", V_RANGE(1, 12) },
1063 { "tomatoanon_id", V_LENGTH(0, 32) },
1065 // nas-usb - !!TB
1066 #ifdef TCONFIG_USB
1067 { "usb_enable", V_01 },
1068 { "usb_uhci", V_RANGE(-1, 1) }, // -1 - disabled, 0 - off, 1 - on
1069 { "usb_ohci", V_RANGE(-1, 1) },
1070 { "usb_usb2", V_RANGE(-1, 1) },
1071 { "usb_irq_thresh", V_RANGE(0, 6) },
1072 { "usb_storage", V_01 },
1073 { "usb_printer", V_01 },
1074 { "usb_printer_bidirect", V_01 },
1075 { "usb_fs_ext3", V_01 },
1076 { "usb_fs_fat", V_01 },
1077 #ifdef TCONFIG_NTFS
1078 { "usb_fs_ntfs", V_01 },
1079 #endif
1080 #ifdef TCONFIG_HFS
1081 { "usb_fs_hfs", V_01 }, //!Victek
1082 #endif
1083 { "usb_automount", V_01 },
1084 { "script_usbhotplug", V_TEXT(0, 2048) },
1085 { "script_usbmount", V_TEXT(0, 2048) },
1086 { "script_usbumount", V_TEXT(0, 2048) },
1087 { "idle_enable", V_01 },
1088 { "usb_3g", V_01 },
1089 #endif
1091 // nas-ftp - !!TB
1092 #ifdef TCONFIG_FTP
1093 { "ftp_enable", V_RANGE(0, 2) },
1094 { "ftp_super", V_01 },
1095 { "ftp_anonymous", V_RANGE(0, 3) },
1096 { "ftp_dirlist", V_RANGE(0, 2) },
1097 { "ftp_port", V_PORT },
1098 { "ftp_max", V_RANGE(0, 12) },
1099 { "ftp_ipmax", V_RANGE(0, 12) },
1100 { "ftp_staytimeout", V_RANGE(0, 65535) },
1101 { "ftp_rate", V_RANGE(0, 99999) },
1102 { "ftp_anonrate", V_RANGE(0, 99999) },
1103 { "ftp_anonroot", V_LENGTH(0, 256) },
1104 { "ftp_pubroot", V_LENGTH(0, 256) },
1105 { "ftp_pvtroot", V_LENGTH(0, 256) },
1106 { "ftp_users", V_LENGTH(0, 4096) },
1107 { "ftp_custom", V_TEXT(0, 2048) },
1108 { "ftp_sip", V_LENGTH(0, 512) },
1109 { "ftp_limit", V_TEXT(1, 50) },
1110 { "log_ftp", V_01 },
1111 #endif
1113 #ifdef TCONFIG_SNMP
1114 { "snmp_enable", V_RANGE(0, 1) },
1115 { "snmp_port", V_RANGE(1, 65535) },
1116 { "snmp_remote", V_RANGE(0, 1) },
1117 { "snmp_remote_sip", V_LENGTH(0, 512) },
1118 { "snmp_location", V_LENGTH(0, 20) },
1119 { "snmp_contact", V_LENGTH(0, 20) },
1120 { "snmp_ro", V_LENGTH(0, 20) },
1121 #endif
1123 #ifdef TCONFIG_SAMBASRV
1124 // nas-samba - !!TB
1125 { "smbd_enable", V_RANGE(0, 2) },
1126 { "smbd_wgroup", V_LENGTH(0, 20) },
1127 { "smbd_master", V_01 },
1128 { "smbd_wins", V_01 },
1129 { "smbd_cpage", V_LENGTH(0, 4) },
1130 { "smbd_cset", V_LENGTH(0, 20) },
1131 { "smbd_custom", V_TEXT(0, 2048) },
1132 { "smbd_autoshare", V_RANGE(0, 3) },
1133 { "smbd_shares", V_LENGTH(0, 4096) },
1134 { "smbd_user", V_LENGTH(0, 50) },
1135 { "smbd_passwd", V_LENGTH(0, 50) },
1136 #endif
1138 #ifdef TCONFIG_MEDIA_SERVER
1139 // nas-media
1140 { "ms_enable", V_01 },
1141 { "ms_dirs", V_LENGTH(0, 1024) },
1142 { "ms_port", V_RANGE(0, 65535) },
1143 { "ms_dbdir", V_LENGTH(0, 256) },
1144 { "ms_tivo", V_01 },
1145 { "ms_stdlna", V_01 },
1146 { "ms_rescan", V_01 },
1147 { "ms_sas", V_01 },
1148 #endif
1150 // qos
1151 { "qos_enable", V_01 },
1152 { "qos_ack", V_01 },
1153 { "qos_syn", V_01 },
1154 { "qos_fin", V_01 },
1155 { "qos_rst", V_01 },
1156 { "qos_icmp", V_01 },
1157 { "qos_reset", V_01 },
1158 { "qos_pfifo", V_01 }, // !!TB
1159 { "qos_obw", V_RANGE(10, 999999) },
1160 { "qos_ibw", V_RANGE(10, 999999) },
1161 { "qos_orules", V_LENGTH(0, 4096) },
1162 { "qos_default", V_RANGE(0, 9) },
1163 { "qos_irates", V_LENGTH(0, 128) },
1164 { "qos_orates", V_LENGTH(0, 128) },
1165 { "qos_classnames", V_LENGTH(10, 128) }, // !!TOASTMAN
1167 { "ne_vegas", V_01 },
1168 { "ne_valpha", V_NUM },
1169 { "ne_vbeta", V_NUM },
1170 { "ne_vgamma", V_NUM },
1172 // new_qoslimit
1173 { "new_qoslimit_enable", V_01 },
1174 { "new_qoslimit_rules", V_LENGTH(0, 4096) },
1175 { "qosl_enable", V_01 },
1176 { "qosl_ulr", V_RANGE(0, 999999) },
1177 { "qosl_ulc", V_RANGE(0, 999999) },
1178 { "qosl_dlr", V_RANGE(0, 999999) },
1179 { "qosl_dlc", V_RANGE(0, 999999) },
1180 { "qosl_tcp", V_RANGE(0, 1000) },
1181 { "qosl_udp", V_RANGE(0, 100) },
1182 { "limit_br1_enable", V_01 },
1183 { "limit_br1_ulr", V_RANGE(0, 999999) },
1184 { "limit_br1_ulc", V_RANGE(0, 999999) },
1185 { "limit_br1_dlr", V_RANGE(0, 999999) },
1186 { "limit_br1_dlc", V_RANGE(0, 999999) },
1187 { "limit_br1_prio", V_RANGE(0, 5) },
1188 { "limit_br2_enable", V_01 },
1189 { "limit_br2_ulr", V_RANGE(0, 999999) },
1190 { "limit_br2_ulc", V_RANGE(0, 999999) },
1191 { "limit_br2_dlr", V_RANGE(0, 999999) },
1192 { "limit_br2_dlc", V_RANGE(0, 999999) },
1193 { "limit_br2_prio", V_RANGE(0, 5) },
1194 { "limit_br3_enable", V_01 },
1195 { "limit_br3_ulr", V_RANGE(0, 999999) },
1196 { "limit_br3_ulc", V_RANGE(0, 999999) },
1197 { "limit_br3_dlr", V_RANGE(0, 999999) },
1198 { "limit_br3_dlc", V_RANGE(0, 999999) },
1199 { "limit_br3_prio", V_RANGE(0, 5) },
1202 #ifdef TCONFIG_BT
1203 // nas-transmission
1204 { "bt_enable", V_01 },
1205 { "bt_binary", V_LENGTH(0, 50) },
1206 { "bt_binary_custom", V_LENGTH(0, 50) },
1207 { "bt_custom", V_TEXT(0, 2048) },
1208 { "bt_port", V_PORT },
1209 { "bt_dir", V_LENGTH(0, 50) },
1210 { "bt_settings", V_LENGTH(0, 50) },
1211 { "bt_settings_custom", V_LENGTH(0, 50) },
1212 { "bt_incomplete", V_01 },
1213 { "bt_rpc_enable", V_01 },
1214 { "bt_rpc_wan", V_01 },
1215 { "bt_auth", V_01 },
1216 { "bt_login", V_LENGTH(0, 50) },
1217 { "bt_password", V_LENGTH(0, 50) },
1218 { "bt_port_gui", V_PORT },
1219 { "bt_dl_enable", V_01 },
1220 { "bt_ul_enable", V_01 },
1221 { "bt_dl", V_RANGE(1, 999999) },
1222 { "bt_ul", V_RANGE(1, 999999) },
1223 { "bt_peer_limit_global", V_RANGE(10, 1000) },
1224 { "bt_peer_limit_per_torrent", V_RANGE(1, 200) },
1225 { "bt_ul_slot_per_torrent", V_RANGE(1, 50) },
1226 { "bt_ratio_enable", V_01 },
1227 { "bt_ratio", V_LENGTH(0, 999999) },
1228 { "bt_ratio_idle_enable", V_01 },
1229 { "bt_ratio_idle", V_RANGE(1, 55) },
1230 { "bt_dht", V_01 },
1231 { "bt_pex", V_01 },
1232 { "bt_lpd", V_01 },
1233 { "bt_utp", V_01 },
1234 { "bt_blocklist", V_01 },
1235 { "bt_blocklist_url", V_LENGTH(0, 80) },
1236 { "bt_sleep", V_RANGE(1, 60) },
1237 { "bt_check", V_01 },
1238 { "bt_check_time", V_RANGE(1, 55) },
1239 { "bt_dl_queue_enable", V_01 },
1240 { "bt_dl_queue_size", V_RANGE(1, 30) },
1241 { "bt_ul_queue_enable", V_01 },
1242 { "bt_ul_queue_size", V_RANGE(1, 30) },
1243 { "bt_message", V_RANGE(0, 3) },
1244 #endif
1246 #ifdef TCONFIG_NFS
1247 { "nfs_enable", V_01 },
1248 { "nfs_exports", V_LENGTH(0, 4096) },
1249 #endif
1251 //NotCatSplash. Victek.
1252 #ifdef TCONFIG_NOCAT
1253 { "NC_enable", V_01 },
1254 { "NC_Verbosity", V_RANGE(0, 10) },
1255 { "NC_GatewayName", V_LENGTH(0, 255) },
1256 { "NC_GatewayPort", V_PORT },
1257 { "NC_ForcedRedirect", V_01 },
1258 { "NC_HomePage", V_LENGTH(0, 255) },
1259 { "NC_DocumentRoot", V_LENGTH(0, 255) },
1260 { "NC_SplashURL", V_LENGTH(0, 255) },
1261 { "NC_LoginTimeout", V_RANGE(0, 86400000) },
1262 { "NC_IdleTimeout", V_RANGE(0, 86400000) },
1263 { "NC_MaxMissedARP", V_RANGE(0, 10) },
1264 { "NC_PeerChecktimeout", V_RANGE(0, 60) },
1265 { "NC_ExcludePorts", V_LENGTH(0, 255) },
1266 { "NC_IncludePorts", V_LENGTH(0, 255) },
1267 { "NC_AllowedWebHosts", V_LENGTH(0, 255) },
1268 { "NC_MACWhiteList", V_LENGTH(0, 255) },
1269 { "NC_SplashFile", V_LENGTH(0, 8192) },
1270 { "NC_BridgeLAN", V_LENGTH(0, 50) },
1271 #endif
1273 #ifdef TCONFIG_OPENVPN
1274 // vpn
1275 { "vpn_debug", V_01 },
1276 { "vpn_server_eas", V_NONE },
1277 { "vpn_server_dns", V_NONE },
1278 { "vpn_server1_poll", V_RANGE(0, 1440) },
1279 { "vpn_server1_if", V_TEXT(3, 3) }, // tap, tun
1280 { "vpn_server1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1281 { "vpn_server1_port", V_PORT },
1282 { "vpn_server1_firewall", V_TEXT(0, 8) }, // auto, external, custom
1283 { "vpn_server1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1284 { "vpn_server1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1285 { "vpn_server1_cipher", V_TEXT(0, 16) },
1286 { "vpn_server1_dhcp", V_01 },
1287 { "vpn_server1_r1", V_IP },
1288 { "vpn_server1_r2", V_IP },
1289 { "vpn_server1_sn", V_IP },
1290 { "vpn_server1_nm", V_IP },
1291 { "vpn_server1_local", V_IP },
1292 { "vpn_server1_remote", V_IP },
1293 { "vpn_server1_reneg", V_RANGE(-1,2147483647)},
1294 { "vpn_server1_hmac", V_RANGE(-1, 2) },
1295 { "vpn_server1_plan", V_01 },
1296 { "vpn_server1_ccd", V_01 },
1297 { "vpn_server1_c2c", V_01 },
1298 { "vpn_server1_ccd_excl", V_01 },
1299 { "vpn_server1_ccd_val", V_NONE },
1300 { "vpn_server1_pdns", V_01 },
1301 { "vpn_server1_rgw", V_01 },
1302 { "vpn_server1_custom", V_NONE },
1303 { "vpn_server1_static", V_NONE },
1304 { "vpn_server1_ca", V_NONE },
1305 { "vpn_server1_crt", V_NONE },
1306 { "vpn_server1_key", V_NONE },
1307 { "vpn_server1_dh", V_NONE },
1308 { "vpn_server2_poll", V_RANGE(0, 1440) },
1309 { "vpn_server2_if", V_TEXT(3, 3) }, // tap, tun
1310 { "vpn_server2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1311 { "vpn_server2_port", V_PORT },
1312 { "vpn_server2_firewall", V_TEXT(0, 8) }, // auto, external, custom
1313 { "vpn_server2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1314 { "vpn_server2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1315 { "vpn_server2_cipher", V_TEXT(0, 16) },
1316 { "vpn_server2_dhcp", V_01 },
1317 { "vpn_server2_r1", V_IP },
1318 { "vpn_server2_r2", V_IP },
1319 { "vpn_server2_sn", V_IP },
1320 { "vpn_server2_nm", V_IP },
1321 { "vpn_server2_local", V_IP },
1322 { "vpn_server2_remote", V_IP },
1323 { "vpn_server2_reneg", V_RANGE(-1,2147483647)},
1324 { "vpn_server2_hmac", V_RANGE(-1, 2) },
1325 { "vpn_server2_plan", V_01 },
1326 { "vpn_server2_pdns", V_01 },
1327 { "vpn_server2_rgw", V_01 },
1328 { "vpn_server2_custom", V_NONE },
1329 { "vpn_server2_ccd", V_01 },
1330 { "vpn_server2_c2c", V_01 },
1331 { "vpn_server2_ccd_excl", V_01 },
1332 { "vpn_server2_ccd_val", V_NONE },
1333 { "vpn_server2_static", V_NONE },
1334 { "vpn_server2_ca", V_NONE },
1335 { "vpn_server2_crt", V_NONE },
1336 { "vpn_server2_key", V_NONE },
1337 { "vpn_server2_dh", V_NONE },
1338 { "vpn_client_eas", V_NONE },
1339 { "vpn_client1_poll", V_RANGE(0, 1440) },
1340 { "vpn_client1_if", V_TEXT(3, 3) }, // tap, tun
1341 { "vpn_client1_bridge", V_01 },
1342 { "vpn_client1_nat", V_01 },
1343 { "vpn_client1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1344 { "vpn_client1_addr", V_NONE },
1345 { "vpn_client1_port", V_PORT },
1346 { "vpn_client1_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1347 { "vpn_client1_firewall", V_TEXT(0, 6) }, // auto, custom
1348 { "vpn_client1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1349 { "vpn_client1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1350 { "vpn_client1_cipher", V_TEXT(0, 16) },
1351 { "vpn_client1_local", V_IP },
1352 { "vpn_client1_remote", V_IP },
1353 { "vpn_client1_nm", V_IP },
1354 { "vpn_client1_reneg", V_RANGE(-1,2147483647)},
1355 { "vpn_client1_hmac", V_RANGE(-1, 2) },
1356 { "vpn_client1_adns", V_RANGE(0, 3) },
1357 { "vpn_client1_rgw", V_01 },
1358 { "vpn_client1_gw", V_TEXT(0, 15) },
1359 { "vpn_client1_custom", V_NONE },
1360 { "vpn_client1_static", V_NONE },
1361 { "vpn_client1_ca", V_NONE },
1362 { "vpn_client1_crt", V_NONE },
1363 { "vpn_client1_key", V_NONE },
1364 { "vpn_client1_userauth", V_01 },
1365 { "vpn_client1_username", V_TEXT(0,50) },
1366 { "vpn_client1_password", V_TEXT(0,50) },
1367 { "vpn_client1_useronly", V_01 },
1368 { "vpn_client1_tlsremote",V_01 },
1369 { "vpn_client1_cn", V_NONE },
1370 { "vpn_client2_poll", V_RANGE(0, 1440) },
1371 { "vpn_client2_if", V_TEXT(3, 3) }, // tap, tun
1372 { "vpn_client2_bridge", V_01 },
1373 { "vpn_client2_nat", V_01 },
1374 { "vpn_client2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1375 { "vpn_client2_addr", V_NONE },
1376 { "vpn_client2_port", V_PORT },
1377 { "vpn_client2_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1378 { "vpn_client2_firewall", V_TEXT(0, 6) }, // auto, custom
1379 { "vpn_client2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1380 { "vpn_client2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1381 { "vpn_client2_cipher", V_TEXT(0, 16) },
1382 { "vpn_client2_local", V_IP },
1383 { "vpn_client2_remote", V_IP },
1384 { "vpn_client2_nm", V_IP },
1385 { "vpn_client2_reneg", V_RANGE(-1,2147483647)},
1386 { "vpn_client2_hmac", V_RANGE(-1, 2) },
1387 { "vpn_client2_adns", V_RANGE(0, 3) },
1388 { "vpn_client2_rgw", V_01 },
1389 { "vpn_client2_gw", V_TEXT(0, 15) },
1390 { "vpn_client2_custom", V_NONE },
1391 { "vpn_client2_static", V_NONE },
1392 { "vpn_client2_ca", V_NONE },
1393 { "vpn_client2_crt", V_NONE },
1394 { "vpn_client2_key", V_NONE },
1395 { "vpn_client2_userauth", V_01 },
1396 { "vpn_client2_username", V_TEXT(0,50) },
1397 { "vpn_client2_password", V_TEXT(0,50) },
1398 { "vpn_client2_useronly", V_01 },
1399 { "vpn_client2_tlsremote",V_01 },
1400 { "vpn_client2_cn", V_NONE },
1401 #endif // vpn
1403 #ifdef TCONFIG_PPTPD
1404 // pptp server
1405 { "pptpd_enable", V_01 },
1406 { "pptpd_remoteip", V_TEXT(0,24) },
1407 { "pptpd_forcemppe", V_01 },
1408 { "pptpd_users", V_TEXT(0, 67*16) },
1409 { "pptpd_broadcast", V_TEXT(0,8) },
1410 { "pptpd_dns1", V_TEXT(0, 15) },
1411 { "pptpd_dns2", V_TEXT(0, 15) },
1412 { "pptpd_wins1", V_TEXT(0, 15) },
1413 { "pptpd_wins2", V_TEXT(0, 15) },
1414 { "pptpd_mtu", V_RANGE(576, 1500) },
1415 { "pptpd_mru", V_RANGE(576, 1500) },
1416 { "pptpd_custom", V_TEXT(0, 2048) },
1417 #endif
1419 #ifdef TCONFIG_TOR
1420 { "tor_enable", V_01 },
1421 { "tor_socksport", V_RANGE(1,65535) },
1422 { "tor_transport", V_RANGE(1,65535) },
1423 { "tor_dnsport", V_RANGE(1,65535) },
1424 { "tor_datadir", V_TEXT(0,24) },
1425 { "tor_iface", V_LENGTH(0, 50) },
1426 { "tor_users", V_LENGTH(0, 4096) },
1427 { "tor_custom", V_TEXT(0, 2048) },
1428 #endif
1431 ppp_static 0/1
1432 ppp_static_ip IP
1433 wl_enable 0/1
1434 wl_wds_timeout
1435 wl_maxassoc 1-256
1436 wl_phytype a,b,g
1437 wl_net_reauth
1438 wl_preauth
1439 wl_wme_ap_bk
1440 wl_wme_ap_be
1441 wl_wme_ap_vi
1442 wl_wme_ap_vo
1443 wl_wme_sta_bk
1444 wl_wme_sta_be
1445 wl_wme_sta_vi
1446 wl_wme_sta_vo
1448 port_priority_1 0-2
1449 port_flow_control_1 0,1
1450 port_rate_limit_1 0-8
1451 port_priority_2 0-2
1452 port_flow_control_2 0,1
1453 port_rate_limit_2 0-8
1454 port_priority_3 0-2
1455 port_flow_control_3 0,1
1456 port_rate_limit_3 0-8
1457 port_priority_4 0-2
1458 port_flow_control_4 0,1
1459 port_rate_limit_4 0-8
1460 wl_ap_ip
1461 wl_ap_ssid
1463 #ifdef TCONFIG_PPTPD
1464 { "pptp_client_enable", V_01 },
1465 { "pptp_client_peerdns", V_RANGE(0,2) },
1466 { "pptp_client_mtuenable",V_01 },
1467 { "pptp_client_mtu", V_RANGE(576, 1500) },
1468 { "pptp_client_mruenable",V_01 },
1469 { "pptp_client_mru", V_RANGE(576, 1500) },
1470 { "pptp_client_nat", V_01 },
1471 { "pptp_client_srvip", V_NONE },
1472 { "pptp_client_srvsub", V_IP },
1473 { "pptp_client_srvsubmsk",V_IP },
1474 { "pptp_client_username", V_TEXT(0,50) },
1475 { "pptp_client_passwd", V_TEXT(0,50) },
1476 { "pptp_client_crypt", V_RANGE(0, 3) },
1477 { "pptp_client_custom", V_NONE },
1478 { "pptp_client_dfltroute",V_01 },
1479 { "pptp_client_stateless",V_01 },
1480 #endif
1482 { NULL }
1486 static int webcgi_nvram_set(const nvset_t *v, const char *name, int write)
1488 char *p, *e;
1489 int n;
1490 long l;
1491 unsigned u[6];
1492 int ok;
1493 int dirty;
1494 #ifdef TCONFIG_IPV6
1495 struct in6_addr addr;
1496 #endif
1498 if ((p = webcgi_get((char*)name)) == NULL) return 0;
1500 _dprintf("[%s] %s=%s\n", v->name, (char*)name, p);
1501 dirty = 0;
1502 ok = 1;
1503 switch (v->vtype) {
1504 case VT_TEXT:
1505 p = unix_string(p); // NOTE: p = malloc'd
1506 // drop
1507 case VT_LENGTH:
1508 n = strlen(p);
1509 if ((n < v->va.i) || (n > v->vb.i)) ok = 0;
1510 break;
1511 case VT_RANGE:
1512 l = strtol(p, &e, 10);
1513 if ((p == e) || (*e) || (l < v->va.l) || (l > v->vb.l)) ok = 0;
1514 break;
1515 case VT_IP:
1516 if ((sscanf(p, "%3u.%3u.%3u.%3u", &u[0], &u[1], &u[2], &u[3]) != 4) ||
1517 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255)) ok = 0;
1518 break;
1519 case VT_MAC:
1520 if ((sscanf(p, "%2x:%2x:%2x:%2x:%2x:%2x", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]) != 6) ||
1521 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255) || (u[4] > 255) || (u[5] > 255)) ok = 0;
1522 break;
1523 #ifdef TCONFIG_IPV6
1524 case VT_IPV6:
1525 if (strlen(p) > 0 || v->va.i) {
1526 if (inet_pton(AF_INET6, p, &addr) != 1) ok = 0;
1528 break;
1529 #endif
1530 default:
1531 // shutup gcc
1532 break;
1534 if (!ok) {
1535 if (v->vtype == VT_TEXT) free(p);
1536 return -1;
1538 if (write) {
1539 if (!nvram_match((char *)name, p)) {
1540 if (v->vtype != VT_TEMP) dirty = 1;
1541 DEBUG_NVRAMSET(name, p);
1542 nvram_set(name, p);
1545 if (v->vtype == VT_TEXT) free(p);
1547 return dirty;
1550 typedef struct {
1551 const nvset_t *v;
1552 int write;
1553 int dirty;
1554 } nv_list_t;
1556 static int nv_wl_find(int idx, int unit, int subunit, void *param)
1558 nv_list_t *p = param;
1560 int ok = webcgi_nvram_set(p->v, wl_nvname(p->v->name + 3, unit, subunit), p->write);
1561 if (ok < 0)
1562 return 1;
1563 else {
1564 p->dirty |= ok;
1565 return 0;
1569 static int save_variables(int write)
1571 const nvset_t *v;
1572 char *p;
1573 int n;
1574 int ok;
1575 char s[256];
1576 int dirty;
1577 static const char *msgf = "The field \"%s\" is invalid. Please report this problem.";
1578 nv_list_t nv;
1580 dirty = 0;
1581 nv.write = write;
1582 for (v = nvset_list; v->name; ++v) {
1583 ok = webcgi_nvram_set(v, v->name, write);
1585 if ((ok >= 0) && (strncmp(v->name, "wl_", 3) == 0)) {
1586 nv.dirty = dirty;
1587 nv.v = v;
1588 if (foreach_wif(1, &nv, nv_wl_find) == 0)
1589 ok |= nv.dirty;
1590 else
1591 ok = -1;
1594 if (ok < 0) {
1595 sprintf(s, msgf, v->name);
1596 resmsg_set(s);
1597 return 0;
1599 dirty |= ok;
1602 // special cases
1604 char *p1, *p2;
1605 if (((p1 = webcgi_get("set_password_1")) != NULL) && (strcmp(p1, "**********") != 0)) {
1606 if (((p2 = webcgi_get("set_password_2")) != NULL) && (strcmp(p1, p2) == 0)) {
1607 if ((write) && (!nvram_match("http_passwd", p1))) {
1608 dirty = 1;
1609 nvram_set("http_passwd", p1);
1612 else {
1613 sprintf(s, msgf, "password");
1614 resmsg_set(s);
1615 return 0;
1619 for (n = 0; n < 50; ++n) {
1620 sprintf(s, "rrule%d", n);
1621 if ((p = webcgi_get(s)) != NULL) {
1622 if (strlen(p) > 2048) {
1623 sprintf(s, msgf, s);
1624 resmsg_set(s);
1625 return 0;
1627 if ((write) && (!nvram_match(s, p))) {
1628 dirty = 1;
1629 DEBUG_NVRAMSET(s, p);
1630 nvram_set(s, p);
1635 return (write) ? dirty : 1;
1638 static void wo_tomato(char *url)
1640 char *v;
1641 int i;
1642 int ajax;
1643 int nvset;
1644 const char *red;
1645 int commit;
1646 int force_commit;
1648 // _dprintf("tomato.cgi\n");
1650 red = webcgi_safeget("_redirect", "");
1651 if (!*red) send_header(200, NULL, mime_html, 0);
1653 commit = atoi(webcgi_safeget("_commit", "1"));
1654 force_commit = atoi(webcgi_safeget("_force_commit", "0"));
1655 ajax = atoi(webcgi_safeget("_ajax", "0"));
1657 nvset = atoi(webcgi_safeget("_nvset", "1"));
1658 if (nvset) {
1659 if (!save_variables(0)) {
1660 if (ajax) {
1661 web_printf("@msg:%s", resmsg_get());
1663 else {
1664 parse_asp("error.asp");
1666 return;
1668 commit = save_variables(1) && commit;
1670 resmsg_set("Settings saved.");
1673 rboot = atoi(webcgi_safeget("_reboot", "0"));
1674 if (rboot) {
1675 parse_asp("reboot.asp");
1677 else {
1678 if (ajax) {
1679 web_printf("@msg:%s", resmsg_get());
1681 else if (atoi(webcgi_safeget("_moveip", "0"))) {
1682 parse_asp("saved-moved.asp");
1684 else if (!*red) {
1685 parse_asp("saved.asp");
1689 if (commit || force_commit) {
1690 _dprintf("commit from tomato.cgi\n");
1691 nvram_commit_x();
1694 if ((v = webcgi_get("_service")) != NULL && *v != 0) {
1695 if (!*red) {
1696 if (ajax) web_printf(" Some services are being restarted...");
1697 web_close();
1699 sleep(1);
1701 if (*v == '*') {
1702 kill(1, SIGHUP);
1704 else {
1705 exec_service(v);
1709 for (i = atoi(webcgi_safeget("_sleep", "0")); i > 0; --i) sleep(1);
1711 if (*red) redirect(red);
1713 if (rboot) {
1714 web_close();
1715 sleep(1);
1716 kill(1, SIGTERM);
1721 // ----------------------------------------------------------------------------
1724 static void wo_update(char *url)
1726 const aspapi_t *api;
1727 const char *name;
1728 int argc;
1729 char *argv[16];
1730 char s[32];
1732 if ((name = webcgi_get("exec")) != NULL) {
1733 for (api = aspapi; api->name; ++api) {
1734 if (strcmp(api->name, name) == 0) {
1735 for (argc = 0; argc < 16; ++argc) {
1736 sprintf(s, "arg%d", argc);
1737 if ((argv[argc] = (char *)webcgi_get(s)) == NULL) break;
1739 api->exec(argc, argv);
1740 break;
1746 static void wo_service(char *url)
1748 int n;
1750 exec_service(webcgi_safeget("_service", ""));
1752 if ((n = atoi(webcgi_safeget("_sleep", "2"))) <= 0) n = 2;
1753 sleep(n);
1755 common_redirect();
1758 static void wo_shutdown(char *url)
1760 parse_asp("shutdown.asp");
1761 web_close();
1762 sleep(1);
1764 kill(1, SIGQUIT);
1767 static void wo_nvcommit(char *url)
1769 parse_asp("saved.asp");
1770 web_close();
1771 nvram_commit();