synchro with tomato-shibby v116
[tomato.git] / release / src / router / httpd / tomato.c
blobcd5813a779354303a5853f4fc88375ea9d1dad98
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 { "etherstates", asp_etherstates }, //Ethernet States
414 { "anonupdate", asp_anonupdate }, //Tomato update notification system
415 #ifdef TCONFIG_IPV6
416 { "calc6rdlocalprefix", asp_calc6rdlocalprefix },
417 #endif
419 { "css", asp_css },
420 { NULL, NULL }
423 // -----------------------------------------------------------------------------
425 static void asp_css(int argc, char **argv)
427 const char *css = nvram_safe_get("web_css");
428 const char *ttb = nvram_safe_get("ttb_css");
430 if( nvram_match( "web_css", "online" ) ) {
431 web_printf("<link rel='stylesheet' type='text/css' href='ext/%s.css'>", ttb);
432 } else {
433 if (strcmp(css, "tomato") != 0) {
434 web_printf("<link rel='stylesheet' type='text/css' href='%s.css'>", css);
439 // -----------------------------------------------------------------------------
441 const char *resmsg_get(void)
443 return webcgi_safeget("resmsg", "");
446 void resmsg_set(const char *msg)
448 webcgi_set("resmsg", strdup(msg)); // m ok
451 int resmsg_fread(const char *fname)
453 char s[256];
454 char *p;
456 f_read_string(fname, s, sizeof(s));
457 if ((p = strchr(s, '\n')) != NULL) *p = 0;
458 if (s[0]) {
459 resmsg_set(s);
460 return 1;
462 return 0;
465 static void asp_resmsg(int argc, char **argv)
467 char *p;
469 if ((p = js_string(webcgi_safeget("resmsg", (argc > 0) ? argv[0] : ""))) == NULL) return;
470 web_printf("\nresmsg='%s';\n", p);
471 free(p);
474 // ----------------------------------------------------------------------------
476 // verification... simple sanity checks. UI should verify all fields.
478 // todo: move and re-use for filtering - zzz
480 typedef union {
481 int i;
482 long l;
483 const char *s;
484 } nvset_varg_t;
486 typedef struct {
487 const char *name;
488 enum {
489 VT_NONE, // no checking
490 VT_LENGTH, // check length of string
491 VT_TEXT, // strip \r, check length of string
492 VT_RANGE, // expect an integer, check range
493 VT_IP, // expect an ip address
494 VT_MAC, // expect a mac address
495 #ifdef TCONFIG_IPV6
496 VT_IPV6, // expect an ipv6 address
497 #endif
498 VT_TEMP // no checks, no commit
499 } vtype;
500 nvset_varg_t va;
501 nvset_varg_t vb;
502 } nvset_t;
505 #define V_NONE VT_NONE, { }, { }
506 #define V_01 VT_RANGE, { .l = 0 }, { .l = 1 }
507 #define V_PORT VT_RANGE, { .l = 2 }, { .l = 65535 }
508 #define V_ONOFF VT_LENGTH, { .i = 2 }, { .i = 3 }
509 #define V_WORD VT_LENGTH, { .i = 1 }, { .i = 16 }
510 #define V_LENGTH(min, max) VT_LENGTH, { .i = min }, { .i = max }
511 #define V_TEXT(min, max) VT_TEXT, { .i = min }, { .i = max }
512 #define V_RANGE(min, max) VT_RANGE, { .l = min }, { .l = max }
513 #define V_IP VT_IP, { }, { }
514 #define V_OCTET VT_RANGE, { .l = 0 }, { .l = 255 }
515 #define V_NUM VT_RANGE, { .l = 0 }, { .l = 0x7FFFFFFF }
516 #define V_TEMP VT_TEMP, { }, { }
517 #ifdef TCONFIG_IPV6
518 #define V_IPV6(required) VT_IPV6, { .i = required }, { }
519 #endif
521 static const nvset_t nvset_list[] = {
523 // basic-ident
524 { "router_name", V_LENGTH(0, 32) },
525 { "wan_hostname", V_LENGTH(0, 32) },
526 { "wan_domain", V_LENGTH(0, 32) },
528 // basic-time
529 { "tm_tz", V_LENGTH(1, 64) }, // PST8PDT
530 { "tm_sel", V_LENGTH(1, 64) }, // PST8PDT
531 { "tm_dst", V_01 },
532 { "ntp_updates", V_RANGE(-1, 24) },
533 { "ntp_tdod", V_01 },
534 { "ntp_server", V_LENGTH(1, 150) }, // x y z
535 { "ntp_kiss", V_LENGTH(0, 255) },
537 // basic-static
538 { "dhcpd_static", V_LENGTH(0, 108*251) }, // 108 (max chars per entry) x 250 entries
539 { "dhcpd_static_only", V_01 },
541 // basic-ddns
542 { "ddnsx0", V_LENGTH(0, 2048) },
543 { "ddnsx1", V_LENGTH(0, 2048) },
544 { "ddnsx0_cache", V_LENGTH(0, 1) }, // only to clear
545 { "ddnsx1_cache", V_LENGTH(0, 1) },
546 { "ddnsx_ip", V_LENGTH(0, 32) },
547 { "ddnsx_save", V_01 },
548 { "ddnsx_refresh", V_RANGE(0, 365) },
550 // basic-network
551 // WAN
552 { "wan_proto", V_LENGTH(1, 16) }, // disabled, dhcp, static, pppoe, pptp, l2tp
553 { "wan_ipaddr", V_IP },
554 { "wan_netmask", V_IP },
555 { "wan_gateway", V_IP },
556 { "hb_server_ip", V_LENGTH(0, 32) },
557 { "l2tp_server_ip", V_LENGTH(0, 128) },
558 { "pptp_server_ip", V_LENGTH(0, 128) },
559 { "pptp_dhcp", V_01 },
560 { "ppp_username", V_LENGTH(0, 60) },
561 { "ppp_passwd", V_LENGTH(0, 60) },
562 { "ppp_service", V_LENGTH(0, 50) },
563 { "ppp_demand", V_01 },
564 { "ppp_custom", V_LENGTH(0, 256) },
565 { "ppp_idletime", V_RANGE(0, 1440) },
566 { "ppp_redialperiod", V_RANGE(1, 86400) },
567 { "ppp_mlppp", V_01 },
568 { "mtu_enable", V_01 },
569 { "wan_mtu", V_RANGE(576, 1500) },
570 { "wan_islan", V_01 },
571 { "modem_ipaddr", V_IP },
572 { "pppoe_lei", V_RANGE(1, 60) },
573 { "pppoe_lef", V_RANGE(1, 10) },
575 // LAN
576 { "lan_ipaddr", V_IP },
577 { "lan_netmask", V_IP },
578 { "lan_gateway", V_IP },
579 { "wan_dns", V_LENGTH(0, 50) }, // ip ip ip
580 #ifdef TCONFIG_DNSCRYPT
581 { "dnscrypt_proxy", V_01 },
582 { "dnscrypt_port", V_PORT },
583 { "dnscrypt_cmd", V_LENGTH(0, 256) },
584 #endif
585 { "lan_state", V_01 },
586 { "lan_desc", V_01 },
587 { "lan_invert", V_01 },
588 { "lan_proto", V_WORD }, // static, dhcp
589 { "dhcp_start", V_LENGTH(0, 15) }, // remove !
590 { "dhcp_num", V_LENGTH(0, 4) }, // remove !
591 { "dhcpd_startip", V_LENGTH(0, 15) },
592 { "dhcpd_endip", V_LENGTH(0, 15) },
593 { "dhcp_lease", V_LENGTH(0, 5) },
594 { "wan_wins", V_IP },
596 #ifdef TCONFIG_USB
597 // 3G MODEM
598 { "modem_pin", V_LENGTH(0,6) },
599 { "modem_dev", V_LENGTH(0,8) },
600 { "modem_init", V_LENGTH(0,25) },
601 { "modem_apn", V_LENGTH(0,25) },
602 #endif
604 // LAN networks
605 { "lan_ifname", V_LENGTH(0, 5) },
607 { "lan1_ifname", V_LENGTH(0, 5) },
608 { "lan1_ifnames", V_TEXT(0,64) },
609 { "lan1_ipaddr", V_LENGTH(0, 15) },
610 { "lan1_netmask", V_LENGTH(0, 15) },
611 { "lan1_proto", V_LENGTH(0, 6) },
612 { "lan1_stp", V_LENGTH(0, 1) },
613 { "dhcp1_start", V_LENGTH(0, 15) },
614 { "dhcp1_num", V_LENGTH(0, 4) },
615 { "dhcpd1_startip", V_LENGTH(0, 15) },
616 { "dhcpd1_endip", V_LENGTH(0, 15) },
617 { "dhcp1_lease", V_LENGTH(0, 5) },
619 { "lan2_ifname", V_LENGTH(0, 5) },
620 { "lan2_ifnames", V_TEXT(0,64) },
621 { "lan2_ipaddr", V_LENGTH(0, 15) },
622 { "lan2_netmask", V_LENGTH(0, 15) },
623 { "lan2_proto", V_LENGTH(0, 6) },
624 { "lan2_stp", V_LENGTH(0, 1) },
625 { "dhcp2_start", V_LENGTH(0, 15) },
626 { "dhcp2_num", V_LENGTH(0, 4) },
627 { "dhcpd2_startip", V_LENGTH(0, 15) },
628 { "dhcpd2_endip", V_LENGTH(0, 15) },
629 { "dhcp2_lease", V_LENGTH(0, 5) },
631 { "lan3_ifname", V_LENGTH(0, 5) },
632 { "lan3_ifnames", V_TEXT(0,64) },
633 { "lan3_ipaddr", V_LENGTH(0, 15) },
634 { "lan3_netmask", V_LENGTH(0, 15) },
635 { "lan3_proto", V_LENGTH(0, 6) },
636 { "lan3_stp", V_LENGTH(0, 1) },
637 { "dhcp3_start", V_LENGTH(0, 15) },
638 { "dhcp3_num", V_LENGTH(0, 4) },
639 { "dhcpd3_startip", V_LENGTH(0, 15) },
640 { "dhcpd3_endip", V_LENGTH(0, 15) },
641 { "dhcp3_lease", V_LENGTH(0, 5) },
643 // wireless
644 { "wl_radio", V_01 },
645 { "wl_mode", V_LENGTH(2, 3) }, // ap, sta, wet, wds
646 { "wl_net_mode", V_LENGTH(5, 8) }, // disabled, mixed, b-only, g-only, bg-mixed, n-only [speedbooster]
647 { "wl_ssid", V_LENGTH(1, 32) },
648 { "wl_closed", V_01 },
649 { "wl_channel", V_RANGE(0, 216) },
651 { "wl_vifs", V_LENGTH(0, 64) }, // multiple/virtual BSSIDs
652 #ifndef LINUX26
653 { "nas_alternate", V_01 }, // only meaningful for ND/K24 builds
654 #endif
656 { "wl_security_mode", V_LENGTH(1, 32) }, // disabled, radius, wep, wpa_personal, wpa_enterprise, wpa2_personal, wpa2_enterprise
657 { "wl_radius_ipaddr", V_IP },
658 { "wl_radius_port", V_PORT },
659 { "wl_radius_key", V_LENGTH(1, 64) },
660 { "wl_wep_bit", V_RANGE(64, 128) }, // 64 or 128
661 { "wl_passphrase", V_LENGTH(0, 20) },
662 { "wl_key", V_RANGE(1, 4) },
663 { "wl_key1", V_LENGTH(0, 26) },
664 { "wl_key2", V_LENGTH(0, 26) },
665 { "wl_key3", V_LENGTH(0, 26) },
666 { "wl_key4", V_LENGTH(0, 26) },
667 { "wl_crypto", V_LENGTH(3, 8) }, // tkip, aes, tkip+aes
668 { "wl_wpa_psk", V_LENGTH(8, 64) },
669 { "wl_wpa_gtk_rekey", V_RANGE(60, 7200) },
671 { "wl_lazywds", V_01 },
672 { "wl_wds", V_LENGTH(0, 180) }, // mac mac mac (x 10)
674 { "wl_wds_enable", V_01 },
675 { "wl_gmode", V_RANGE(-1, 6) },
676 { "wl_wep", V_LENGTH(1, 32) }, // off, on, restricted,tkip,aes,tkip+aes
677 { "wl_akm", V_LENGTH(0, 32) }, // wpa, wpa2, psk, psk2, wpa wpa2, psk psk2, ""
678 { "wl_auth_mode", V_LENGTH(4, 6) }, // none, radius
680 { "wl_nmode", V_NONE },
681 { "wl_nband", V_RANGE(0, 2) }, // 2 - 2.4GHz, 1 - 5GHz, 0 - Auto
682 { "wl_nreqd", V_NONE },
683 { "wl_nbw_cap", V_RANGE(0, 3) }, // 0 - 20MHz, 1 - 40MHz, 2 - Auto, 3 - 80M
684 { "wl_nbw", V_NONE },
685 { "wl_mimo_preamble", V_WORD }, // 802.11n Preamble: mm/gf/auto/gfbcm
686 { "wl_nctrlsb", V_NONE }, // none, lower, upper
688 #ifdef TCONFIG_IPV6
689 // basic-ipv6
690 { "ipv6_service", V_LENGTH(0, 16) }, // '', native, native-pd, 6to4, sit, other
691 { "ipv6_prefix", V_IPV6(0) },
692 { "ipv6_prefix_length", V_RANGE(3, 127) },
693 { "ipv6_rtr_addr", V_IPV6(0) },
694 { "ipv6_radvd", V_01 },
695 { "ipv6_accept_ra", V_NUM },
696 { "ipv6_tun_addr", V_IPV6(1) },
697 { "ipv6_tun_addrlen", V_RANGE(3, 127) },
698 { "ipv6_ifname", V_LENGTH(0, 8) },
699 { "ipv6_tun_v4end", V_IP },
700 { "ipv6_relay", V_RANGE(1, 254) },
701 { "ipv6_tun_mtu", V_NUM }, // Tunnel MTU
702 { "ipv6_tun_ttl", V_NUM }, // Tunnel TTL
703 { "ipv6_dns", V_LENGTH(0, 40*3) }, // ip6 ip6 ip6
704 { "ipv6_6rd_prefix", V_IPV6(0) },
705 { "ipv6_6rd_prefix_length", V_RANGE(32, 62) },
706 { "ipv6_6rd_borderrelay", V_IP },
707 { "ipv6_6rd_ipv4masklen", V_RANGE(0, 30) },
708 #endif
710 // basic-wfilter
711 { "wl_macmode", V_NONE }, // allow, deny, disabled
712 { "wl_maclist", V_LENGTH(0, 18*201) }, // 18 x 200 (11:22:33:44:55:66 ...)
713 { "macnames", V_LENGTH(0, 62*201) }, // 62 (12+1+48+1) x 50 (112233445566<..>) todo: re-use -- zzz
715 // advanced-ctnf
716 { "ct_max", V_NUM },
717 { "ct_tcp_timeout", V_LENGTH(20, 70) },
718 { "ct_udp_timeout", V_LENGTH(5, 15) },
719 { "ct_timeout", V_LENGTH(5, 15) },
720 { "nf_ttl", V_LENGTH(1, 6) },
721 { "nf_l7in", V_01 },
722 #ifdef LINUX26
723 { "nf_sip", V_01 },
724 { "ct_hashsize", V_NUM },
725 #endif
726 { "nf_rtsp", V_01 },
727 { "nf_pptp", V_01 },
728 { "nf_h323", V_01 },
729 { "nf_ftp", V_01 },
731 // advanced-dhcpdns
732 { "dhcpd_slt", V_RANGE(-1, 43200) }, // -1=infinite, 0=follow normal lease time, >=1 custom
733 { "dhcpd_dmdns", V_01 },
734 { "dhcpd_lmax", V_NUM },
735 { "dhcpd_gwmode", V_NUM },
736 { "dns_addget", V_01 },
737 { "dns_intcpt", V_01 },
738 { "dhcpc_minpkt", V_01 },
739 { "dhcpc_custom", V_LENGTH(0, 80) },
740 { "dns_norebind", V_01 },
741 { "dnsmasq_custom", V_TEXT(0, 2048) },
742 { "dnsmasq_q", V_RANGE(0,7) }, //bitfield quiet bit0=dhcp, 1=dhcp6, 2=ra
743 // { "dnsmasq_norw", V_01 },
745 // advanced-firewall
746 { "block_wan", V_01 },
747 { "block_wan_limit", V_01 },
748 { "block_wan_limit_icmp", V_RANGE(1, 300) },
749 { "block_wan_limit_tr", V_RANGE(1, 300) },
750 { "multicast_pass", V_01 },
751 { "multicast_lan", V_01 },
752 { "multicast_lan1", V_01 },
753 { "multicast_lan2", V_01 },
754 { "multicast_lan3", V_01 },
755 { "block_loopback", V_01 },
756 { "udpxy_enable", V_01 },
757 { "udpxy_stats", V_01 },
758 { "udpxy_clients", V_RANGE(1, 5000) },
759 { "udpxy_port", V_RANGE(0, 65535) },
760 { "nf_loopback", V_NUM },
761 { "ne_syncookies", V_01 },
762 { "ne_snat", V_01 },
763 { "dhcp_pass", V_01 },
764 #ifdef TCONFIG_EMF
765 { "emf_entry", V_NONE },
766 { "emf_uffp_entry", V_NONE },
767 { "emf_rtport_entry", V_NONE },
768 { "emf_enable", V_01 },
769 #endif
771 // advanced-misc
772 { "wait_time", V_RANGE(3, 20) },
773 { "wan_speed", V_RANGE(0, 4) },
774 { "jumbo_frame_enable", V_01 }, // Jumbo Frames support (for RT-N16/WNR3500L)
775 { "jumbo_frame_size", V_RANGE(1, 9720) },
776 #ifdef CONFIG_BCMWL5
777 { "ctf_disable", V_01 },
778 #endif
779 // advanced-vlan
780 { "vlan0ports", V_TEXT(0,16) },
781 { "vlan1ports", V_TEXT(0,16) },
782 { "vlan2ports", V_TEXT(0,16) },
783 { "vlan3ports", V_TEXT(0,16) },
784 { "vlan4ports", V_TEXT(0,16) },
785 { "vlan5ports", V_TEXT(0,16) },
786 { "vlan6ports", V_TEXT(0,16) },
787 { "vlan7ports", V_TEXT(0,16) },
788 { "vlan8ports", V_TEXT(0,16) },
789 { "vlan9ports", V_TEXT(0,16) },
790 { "vlan10ports", V_TEXT(0,16) },
791 { "vlan11ports", V_TEXT(0,16) },
792 { "vlan12ports", V_TEXT(0,16) },
793 { "vlan13ports", V_TEXT(0,16) },
794 { "vlan14ports", V_TEXT(0,16) },
795 { "vlan15ports", V_TEXT(0,16) },
796 { "vlan0hwname", V_TEXT(0,8) },
797 { "vlan1hwname", V_TEXT(0,8) },
798 { "vlan2hwname", V_TEXT(0,8) },
799 { "vlan3hwname", V_TEXT(0,8) },
800 { "vlan4hwname", V_TEXT(0,8) },
801 { "vlan5hwname", V_TEXT(0,8) },
802 { "vlan6hwname", V_TEXT(0,8) },
803 { "vlan7hwname", V_TEXT(0,8) },
804 { "vlan8hwname", V_TEXT(0,8) },
805 { "vlan9hwname", V_TEXT(0,8) },
806 { "vlan10hwname", V_TEXT(0,8) },
807 { "vlan11hwname", V_TEXT(0,8) },
808 { "vlan12hwname", V_TEXT(0,8) },
809 { "vlan13hwname", V_TEXT(0,8) },
810 { "vlan14hwname", V_TEXT(0,8) },
811 { "vlan15hwname", V_TEXT(0,8) },
812 { "wan_ifnameX", V_TEXT(0,8) },
813 { "lan_ifnames", V_TEXT(0,64) },
814 { "manual_boot_nv", V_01 },
815 { "trunk_vlan_so", V_01 },
816 { "vlan0tag", V_TEXT(0,5) },
817 { "vlan0vid", V_TEXT(0,5) },
818 { "vlan1vid", V_TEXT(0,5) },
819 { "vlan2vid", V_TEXT(0,5) },
820 { "vlan3vid", V_TEXT(0,5) },
821 { "vlan4vid", V_TEXT(0,5) },
822 { "vlan5vid", V_TEXT(0,5) },
823 { "vlan6vid", V_TEXT(0,5) },
824 { "vlan7vid", V_TEXT(0,5) },
825 { "vlan8vid", V_TEXT(0,5) },
826 { "vlan9vid", V_TEXT(0,5) },
827 { "vlan10vid", V_TEXT(0,5) },
828 { "vlan11vid", V_TEXT(0,5) },
829 { "vlan12vid", V_TEXT(0,5) },
830 { "vlan13vid", V_TEXT(0,5) },
831 { "vlan14vid", V_TEXT(0,5) },
832 { "vlan15vid", V_TEXT(0,5) },
834 // advanced-mac
835 { "mac_wan", V_LENGTH(0, 17) },
836 { "wl_macaddr", V_LENGTH(0, 17) },
837 { "wl_hwaddr", V_LENGTH(0, 17) },
839 // advanced-routing
840 { "routes_static", V_LENGTH(0, 2048) },
841 { "dhcp_routes", V_01 },
842 { "lan_stp", V_RANGE(0, 1) },
843 { "wk_mode", V_LENGTH(1, 32) }, // gateway, router
844 #ifdef TCONFIG_ZEBRA
845 { "dr_setting", V_RANGE(0, 3) },
846 { "dr_lan_tx", V_LENGTH(0, 32) },
847 { "dr_lan_rx", V_LENGTH(0, 32) },
848 { "dr_lan1_tx", V_LENGTH(0, 32) },
849 { "dr_lan1_rx", V_LENGTH(0, 32) },
850 { "dr_lan2_tx", V_LENGTH(0, 32) },
851 { "dr_lan2_rx", V_LENGTH(0, 32) },
852 { "dr_lan3_tx", V_LENGTH(0, 32) },
853 { "dr_lan3_rx", V_LENGTH(0, 32) },
854 { "dr_wan_tx", V_LENGTH(0, 32) },
855 { "dr_wan_rx", V_LENGTH(0, 32) },
856 #endif
858 // advanced-access
859 { "lan_access", V_LENGTH(0, 4096) },
861 // advanced-wireless
862 { "wl_country", V_LENGTH(0, 64) }, // !!TB - Country code
863 { "wl_country_code", V_LENGTH(0, 4) }, // !!TB - Country code
864 { "wl_btc_mode", V_RANGE(0, 2) }, // !!TB - BT Coexistence Mode: 0 (disable), 1 (enable), 2 (preemption)
865 { "wl_afterburner", V_LENGTH(2, 4) }, // off, on, auto
866 { "wl_auth", V_01 },
867 { "wl_rateset", V_LENGTH(2, 7) }, // all, default, 12
868 { "wl_rate", V_RANGE(0, 54 * 1000 * 1000) },
869 { "wl_mrate", V_RANGE(0, 54 * 1000 * 1000) },
870 { "wl_gmode_protection",V_LENGTH(3, 4) }, // off, auto
871 { "wl_frameburst", V_ONOFF }, // off, on
872 { "wl_bcn", V_RANGE(1, 65535) },
873 { "wl_dtim", V_RANGE(1, 255) },
874 { "wl_frag", V_RANGE(256, 2346) },
875 { "wl_rts", V_RANGE(0, 2347) },
876 { "wl_ap_isolate", V_01 },
877 { "wl_plcphdr", V_LENGTH(4, 5) }, // long, short
878 { "wl_antdiv", V_RANGE(0, 3) },
879 { "wl_txant", V_RANGE(0, 3) },
880 { "wl_txpwr", V_RANGE(0, 400) },
881 { "wl_wme", V_WORD }, // auto, off, on
882 { "wl_wme_no_ack", V_ONOFF }, // off, on
883 { "wl_wme_apsd", V_ONOFF }, // off, on
884 { "wl_maxassoc", V_RANGE(0, 255) },
885 { "wl_distance", V_LENGTH(0, 5) }, // "", 1-99999
886 { "wlx_hpamp", V_01 },
887 { "wlx_hperx", V_01 },
888 { "wl_reg_mode", V_LENGTH(1, 3) }, // !!TB - Regulatory: off, h, d
889 { "wl_mitigation", V_RANGE(0, 4) }, // Interference Mitigation Mode (0|1|2|3|4)
891 { "wl_nmode_protection", V_WORD, }, // off, auto
892 { "wl_nmcsidx", V_RANGE(-2, 32), }, // -2 - 32
893 { "wl_obss_coex", V_01 },
894 { "wl_wmf_bss_enable", V_01 }, // Toastman
896 // forward-dmz
897 { "dmz_enable", V_01 },
898 { "dmz_ipaddr", V_LENGTH(0, 15) },
899 { "dmz_sip", V_LENGTH(0, 512) },
900 { "dmz_ifname", V_LENGTH(0, 5) },
901 { "dmz_ra", V_01 },
903 // forward-upnp
904 { "upnp_enable", V_NUM },
905 { "upnp_secure", V_01 },
906 { "upnp_port", V_RANGE(0, 65535) },
907 { "upnp_ssdp_interval", V_RANGE(10, 9999) },
908 { "upnp_mnp", V_01 },
909 { "upnp_clean", V_01 },
910 { "upnp_clean_interval", V_RANGE(60, 65535) },
911 { "upnp_clean_threshold", V_RANGE(0, 9999) },
912 { "upnp_min_port_int", V_PORT },
913 { "upnp_max_port_int", V_PORT },
914 { "upnp_min_port_ext", V_PORT },
915 { "upnp_max_port_ext", V_PORT },
916 { "upnp_lan", V_01 },
917 { "upnp_lan1", V_01 },
918 { "upnp_lan2", V_01 },
919 { "upnp_lan3", V_01 },
920 { "upnp_custom", V_TEXT(0, 2048) },
922 // forward-basic
923 { "portforward", V_LENGTH(0, 4096) },
925 #ifdef TCONFIG_IPV6
926 // forward-basic-ipv6
927 { "ipv6_portforward", V_LENGTH(0, 4096) },
928 #endif
930 // forward-triggered
931 { "trigforward", V_LENGTH(0, 4096) },
934 // access restriction
935 { "rruleN", V_RANGE(0, 99) },
936 // { "rrule##", V_LENGTH(0, 2048) }, // in save_variables()
938 // admin-access
939 { "http_enable", V_01 },
940 { "https_enable", V_01 },
941 { "https_crt_save", V_01 },
942 { "https_crt_cn", V_LENGTH(0, 64) },
943 { "https_crt_gen", V_TEMP },
944 { "remote_management", V_01 },
945 { "remote_mgt_https", V_01 },
946 { "http_lanport", V_PORT },
947 { "https_lanport", V_PORT },
948 { "web_wl_filter", V_01 },
949 { "web_css", V_LENGTH(1, 32) },
950 { "ttb_css", V_LENGTH(0, 128) },
951 { "web_mx", V_LENGTH(0, 128) },
952 { "http_wanport", V_PORT },
953 { "telnetd_eas", V_01 },
954 { "telnetd_port", V_PORT },
955 { "sshd_eas", V_01 },
956 { "sshd_pass", V_01 },
957 { "sshd_port", V_PORT },
958 { "sshd_remote", V_01 },
959 { "sshd_motd", V_01 },
960 { "sshd_forwarding", V_01 },
961 { "sshd_rport", V_PORT },
962 { "sshd_authkeys", V_TEXT(0, 4096) },
963 { "rmgt_sip", V_LENGTH(0, 512) },
964 { "ne_shlimit", V_TEXT(1, 50) },
966 // admin-bwm
967 { "rstats_enable", V_01 },
968 { "rstats_path", V_LENGTH(0, 48) },
969 { "rstats_stime", V_RANGE(1, 168) },
970 { "rstats_offset", V_RANGE(1, 31) },
971 { "rstats_exclude", V_LENGTH(0, 64) },
972 { "rstats_sshut", V_01 },
973 { "rstats_bak", V_01 },
975 // admin-ipt
976 { "cstats_enable", V_01 },
977 { "cstats_path", V_LENGTH(0, 48) },
978 { "cstats_stime", V_RANGE(1, 168) },
979 { "cstats_offset", V_RANGE(1, 31) },
980 { "cstats_labels", V_RANGE(0, 2) },
981 { "cstats_exclude", V_LENGTH(0, 512) },
982 { "cstats_include", V_LENGTH(0, 2048) },
983 { "cstats_all", V_01 },
984 { "cstats_sshut", V_01 },
985 { "cstats_bak", V_01 },
987 // admin-buttons
988 { "sesx_led", V_RANGE(0, 255) }, // amber, white, aoss
989 { "sesx_b0", V_RANGE(0, 5) }, // 0-5: toggle wireless, reboot, shutdown, script, usb unmount
990 { "sesx_b1", V_RANGE(0, 5) }, // "
991 { "sesx_b2", V_RANGE(0, 5) }, // "
992 { "sesx_b3", V_RANGE(0, 5) }, // "
993 { "sesx_script", V_TEXT(0, 1024) }, //
994 { "script_brau", V_TEXT(0, 1024) }, //
996 // admin-debug
997 { "debug_nocommit", V_01 },
998 { "debug_cprintf", V_01 },
999 { "debug_cprintf_file", V_01 },
1000 // { "debug_keepfiles", V_01 },
1001 { "debug_ddns", V_01 },
1002 { "debug_norestart", V_TEXT(0, 128) },
1003 { "console_loglevel", V_RANGE(1, 8) },
1004 { "t_cafree", V_01 },
1005 { "t_hidelr", V_01 },
1007 // admin-sched
1008 { "sch_rboot", V_TEXT(0, 64) },
1009 { "sch_rcon", V_TEXT(0, 64) },
1010 { "sch_c1", V_TEXT(0, 64) },
1011 { "sch_c1_cmd", V_TEXT(0, 2048) },
1012 { "sch_c2", V_TEXT(0, 64) },
1013 { "sch_c2_cmd", V_TEXT(0, 2048) },
1014 { "sch_c3", V_TEXT(0, 64) },
1015 { "sch_c3_cmd", V_TEXT(0, 2048) },
1016 { "sch_c4", V_TEXT(0, 64) },
1017 { "sch_c4_cmd", V_TEXT(0, 2048) },
1018 { "sch_c5", V_TEXT(0, 64) },
1019 { "sch_c5_cmd", V_TEXT(0, 2048) },
1021 // admin-scripts
1022 { "script_init", V_TEXT(0, 4096) },
1023 { "script_shut", V_TEXT(0, 4096) },
1024 { "script_fire", V_TEXT(0, 8192) },
1025 { "script_wanup", V_TEXT(0, 4096) },
1027 // admin-log
1028 { "log_remote", V_01 },
1029 { "log_remoteip", V_LENGTH(0, 512) },
1030 { "log_remoteport", V_PORT },
1031 { "log_file", V_01 },
1032 { "log_file_custom", V_01 },
1033 { "log_file_path", V_TEXT(0, 4096) },
1034 { "log_file_size", V_RANGE(0, 99999) },
1035 { "log_file_keep", V_RANGE(0, 99) },
1036 { "log_limit", V_RANGE(0, 2400) },
1037 { "log_in", V_RANGE(0, 3) },
1038 { "log_out", V_RANGE(0, 3) },
1039 { "log_mark", V_RANGE(0, 99999) },
1040 { "log_events", V_TEXT(0, 32) }, // "acre,crond,ntp"
1042 // admin-log-webmonitor
1043 { "log_wm", V_01 },
1044 { "log_wmtype", V_RANGE(0, 2) },
1045 { "log_wmip", V_LENGTH(0, 512) },
1046 { "log_wmdmax", V_RANGE(0, 9999) },
1047 { "log_wmsmax", V_RANGE(0, 9999) },
1048 { "webmon_bkp", V_01 },
1049 { "webmon_dir", V_LENGTH(0, 256) },
1050 { "webmon_shrink", V_01 },
1053 // admin-cifs
1054 { "cifs1", V_LENGTH(1, 1024) },
1055 { "cifs2", V_LENGTH(1, 1024) },
1057 // admin-jffs2
1058 { "jffs2_on", V_01 },
1059 { "jffs2_exec", V_LENGTH(0, 64) },
1060 { "jffs2_format", V_01 },
1062 #ifdef TCONFIG_SDHC
1063 // admin-sdhc
1064 { "mmc_on", V_01 },
1065 { "mmc_cs", V_RANGE(1, 7) }, // GPIO pin
1066 { "mmc_clk", V_RANGE(1, 7) }, // GPIO pin
1067 { "mmc_din", V_RANGE(1, 7) }, // GPIO pin
1068 { "mmc_dout", V_RANGE(1, 7) }, // GPIO pin
1069 { "mmc_fs_partition", V_RANGE(1, 4) }, // partition number in partition table
1070 { "mmc_fs_type", V_LENGTH(4, 4) }, // ext2, ext3, vfat
1071 { "mmc_exec_mount", V_LENGTH(0, 64) },
1072 { "mmc_exec_umount", V_LENGTH(0, 64) },
1073 #endif
1075 // admin-tomatoanon
1076 { "tomatoanon_answer", V_RANGE(0, 1) },
1077 { "tomatoanon_enable", V_RANGE(-1, 1) },
1078 { "tomatoanon_id", V_LENGTH(0, 32) },
1079 { "tomatoanon_notify", V_01 },
1081 // nas-usb - !!TB
1082 #ifdef TCONFIG_USB
1083 { "usb_enable", V_01 },
1084 { "usb_uhci", V_RANGE(-1, 1) }, // -1 - disabled, 0 - off, 1 - on
1085 { "usb_ohci", V_RANGE(-1, 1) },
1086 { "usb_usb2", V_RANGE(-1, 1) },
1087 { "usb_usb3", V_RANGE(-1, 1) },
1088 #if defined(LINUX26) && defined(TCONFIG_MICROSD)
1089 { "usb_mmc", V_RANGE(-1, 1) },
1090 #endif
1091 { "usb_irq_thresh", V_RANGE(0, 6) },
1092 { "usb_storage", V_01 },
1093 { "usb_printer", V_01 },
1094 { "usb_printer_bidirect", V_01 },
1095 { "usb_fs_ext3", V_01 },
1096 { "usb_fs_ext4", V_01 },
1097 { "usb_fs_fat", V_01 },
1098 #ifdef TCONFIG_NTFS
1099 { "usb_fs_ntfs", V_01 },
1100 #endif
1101 #ifdef TCONFIG_HFS
1102 { "usb_fs_hfs", V_01 }, //!Victek
1103 #endif
1104 { "usb_automount", V_01 },
1105 { "script_usbhotplug", V_TEXT(0, 2048) },
1106 { "script_usbmount", V_TEXT(0, 2048) },
1107 { "script_usbumount", V_TEXT(0, 2048) },
1108 { "idle_enable", V_01 },
1109 { "usb_3g", V_01 },
1110 #endif
1112 // nas-ftp - !!TB
1113 #ifdef TCONFIG_FTP
1114 { "ftp_enable", V_RANGE(0, 2) },
1115 { "ftp_super", V_01 },
1116 { "ftp_anonymous", V_RANGE(0, 3) },
1117 { "ftp_dirlist", V_RANGE(0, 2) },
1118 { "ftp_port", V_PORT },
1119 { "ftp_max", V_RANGE(0, 12) },
1120 { "ftp_ipmax", V_RANGE(0, 12) },
1121 { "ftp_staytimeout", V_RANGE(0, 65535) },
1122 { "ftp_rate", V_RANGE(0, 99999) },
1123 { "ftp_anonrate", V_RANGE(0, 99999) },
1124 { "ftp_anonroot", V_LENGTH(0, 256) },
1125 { "ftp_pubroot", V_LENGTH(0, 256) },
1126 { "ftp_pvtroot", V_LENGTH(0, 256) },
1127 { "ftp_users", V_LENGTH(0, 4096) },
1128 { "ftp_custom", V_TEXT(0, 2048) },
1129 { "ftp_sip", V_LENGTH(0, 512) },
1130 { "ftp_limit", V_TEXT(1, 50) },
1131 { "log_ftp", V_01 },
1132 #endif
1134 #ifdef TCONFIG_SNMP
1135 { "snmp_enable", V_RANGE(0, 1) },
1136 { "snmp_port", V_RANGE(1, 65535) },
1137 { "snmp_remote", V_RANGE(0, 1) },
1138 { "snmp_remote_sip", V_LENGTH(0, 512) },
1139 { "snmp_location", V_LENGTH(0, 40) },
1140 { "snmp_contact", V_LENGTH(0, 40) },
1141 { "snmp_ro", V_LENGTH(0, 40) },
1142 #endif
1144 #ifdef TCONFIG_SAMBASRV
1145 // nas-samba - !!TB
1146 { "smbd_enable", V_RANGE(0, 2) },
1147 { "smbd_wgroup", V_LENGTH(0, 20) },
1148 { "smbd_master", V_01 },
1149 { "smbd_wins", V_01 },
1150 { "smbd_cpage", V_LENGTH(0, 4) },
1151 { "smbd_cset", V_LENGTH(0, 20) },
1152 { "smbd_custom", V_TEXT(0, 2048) },
1153 { "smbd_autoshare", V_RANGE(0, 3) },
1154 { "smbd_shares", V_LENGTH(0, 4096) },
1155 { "smbd_user", V_LENGTH(0, 50) },
1156 { "smbd_passwd", V_LENGTH(0, 50) },
1157 #endif
1159 #ifdef TCONFIG_MEDIA_SERVER
1160 // nas-media
1161 { "ms_enable", V_01 },
1162 { "ms_dirs", V_LENGTH(0, 1024) },
1163 { "ms_port", V_RANGE(0, 65535) },
1164 { "ms_dbdir", V_LENGTH(0, 256) },
1165 { "ms_tivo", V_01 },
1166 { "ms_stdlna", V_01 },
1167 { "ms_rescan", V_01 },
1168 { "ms_sas", V_01 },
1169 #endif
1171 // qos
1172 { "qos_enable", V_01 },
1173 { "qos_ack", V_01 },
1174 { "qos_syn", V_01 },
1175 { "qos_fin", V_01 },
1176 { "qos_rst", V_01 },
1177 { "qos_icmp", V_01 },
1178 { "qos_udp", V_01 },
1179 { "qos_reset", V_01 },
1180 { "qos_pfifo", V_01 }, // !!TB
1181 { "qos_obw", V_RANGE(10, 999999) },
1182 { "qos_ibw", V_RANGE(10, 999999) },
1183 { "qos_orules", V_LENGTH(0, 4096) },
1184 { "qos_default", V_RANGE(0, 9) },
1185 { "qos_irates", V_LENGTH(0, 128) },
1186 { "qos_orates", V_LENGTH(0, 128) },
1187 { "qos_classnames", V_LENGTH(10, 128) }, // !!TOASTMAN
1188 { "atm_overhead", V_RANGE(-127, 128) },
1189 { "ne_vegas", V_01 },
1190 { "ne_valpha", V_NUM },
1191 { "ne_vbeta", V_NUM },
1192 { "ne_vgamma", V_NUM },
1194 // new_qoslimit
1195 { "new_qoslimit_enable", V_01 },
1196 { "new_qoslimit_rules", V_LENGTH(0, 4096) },
1197 { "qosl_enable", V_01 },
1198 { "qosl_ulr", V_RANGE(0, 999999) },
1199 { "qosl_ulc", V_RANGE(0, 999999) },
1200 { "qosl_dlr", V_RANGE(0, 999999) },
1201 { "qosl_dlc", V_RANGE(0, 999999) },
1202 { "qosl_tcp", V_RANGE(0, 1000) },
1203 { "qosl_udp", V_RANGE(0, 100) },
1204 { "limit_br1_enable", V_01 },
1205 { "limit_br1_ulr", V_RANGE(0, 999999) },
1206 { "limit_br1_ulc", V_RANGE(0, 999999) },
1207 { "limit_br1_dlr", V_RANGE(0, 999999) },
1208 { "limit_br1_dlc", V_RANGE(0, 999999) },
1209 { "limit_br1_prio", V_RANGE(0, 5) },
1210 { "limit_br2_enable", V_01 },
1211 { "limit_br2_ulr", V_RANGE(0, 999999) },
1212 { "limit_br2_ulc", V_RANGE(0, 999999) },
1213 { "limit_br2_dlr", V_RANGE(0, 999999) },
1214 { "limit_br2_dlc", V_RANGE(0, 999999) },
1215 { "limit_br2_prio", V_RANGE(0, 5) },
1216 { "limit_br3_enable", V_01 },
1217 { "limit_br3_ulr", V_RANGE(0, 999999) },
1218 { "limit_br3_ulc", V_RANGE(0, 999999) },
1219 { "limit_br3_dlr", V_RANGE(0, 999999) },
1220 { "limit_br3_dlc", V_RANGE(0, 999999) },
1221 { "limit_br3_prio", V_RANGE(0, 5) },
1224 #ifdef TCONFIG_BT
1225 // nas-transmission
1226 { "bt_enable", V_01 },
1227 { "bt_binary", V_LENGTH(0, 50) },
1228 { "bt_binary_custom", V_LENGTH(0, 50) },
1229 { "bt_custom", V_TEXT(0, 2048) },
1230 { "bt_port", V_PORT },
1231 { "bt_dir", V_LENGTH(0, 50) },
1232 { "bt_settings", V_LENGTH(0, 50) },
1233 { "bt_settings_custom", V_LENGTH(0, 50) },
1234 { "bt_incomplete", V_01 },
1235 { "bt_rpc_enable", V_01 },
1236 { "bt_rpc_wan", V_01 },
1237 { "bt_auth", V_01 },
1238 { "bt_login", V_LENGTH(0, 50) },
1239 { "bt_password", V_LENGTH(0, 50) },
1240 { "bt_port_gui", V_PORT },
1241 { "bt_dl_enable", V_01 },
1242 { "bt_ul_enable", V_01 },
1243 { "bt_dl", V_RANGE(1, 999999) },
1244 { "bt_ul", V_RANGE(1, 999999) },
1245 { "bt_peer_limit_global", V_RANGE(10, 1000) },
1246 { "bt_peer_limit_per_torrent", V_RANGE(1, 200) },
1247 { "bt_ul_slot_per_torrent", V_RANGE(1, 50) },
1248 { "bt_ratio_enable", V_01 },
1249 { "bt_ratio", V_LENGTH(0, 999999) },
1250 { "bt_ratio_idle_enable", V_01 },
1251 { "bt_ratio_idle", V_RANGE(1, 55) },
1252 { "bt_dht", V_01 },
1253 { "bt_pex", V_01 },
1254 { "bt_lpd", V_01 },
1255 { "bt_utp", V_01 },
1256 { "bt_blocklist", V_01 },
1257 { "bt_blocklist_url", V_LENGTH(0, 80) },
1258 { "bt_sleep", V_RANGE(1, 60) },
1259 { "bt_check", V_01 },
1260 { "bt_check_time", V_RANGE(1, 55) },
1261 { "bt_dl_queue_enable", V_01 },
1262 { "bt_dl_queue_size", V_RANGE(1, 30) },
1263 { "bt_ul_queue_enable", V_01 },
1264 { "bt_ul_queue_size", V_RANGE(1, 30) },
1265 { "bt_message", V_RANGE(0, 3) },
1266 #endif
1268 #ifdef TCONFIG_NFS
1269 { "nfs_enable", V_01 },
1270 { "nfs_exports", V_LENGTH(0, 4096) },
1271 #endif
1273 //NotCatSplash. Victek.
1274 #ifdef TCONFIG_NOCAT
1275 { "NC_enable", V_01 },
1276 { "NC_Verbosity", V_RANGE(0, 10) },
1277 { "NC_GatewayName", V_LENGTH(0, 255) },
1278 { "NC_GatewayPort", V_PORT },
1279 { "NC_ForcedRedirect", V_01 },
1280 { "NC_HomePage", V_LENGTH(0, 255) },
1281 { "NC_DocumentRoot", V_LENGTH(0, 255) },
1282 { "NC_SplashURL", V_LENGTH(0, 255) },
1283 { "NC_LoginTimeout", V_RANGE(0, 86400000) },
1284 { "NC_IdleTimeout", V_RANGE(0, 86400000) },
1285 { "NC_MaxMissedARP", V_RANGE(0, 10) },
1286 { "NC_PeerChecktimeout", V_RANGE(0, 60) },
1287 { "NC_ExcludePorts", V_LENGTH(0, 255) },
1288 { "NC_IncludePorts", V_LENGTH(0, 255) },
1289 { "NC_AllowedWebHosts", V_LENGTH(0, 255) },
1290 { "NC_MACWhiteList", V_LENGTH(0, 255) },
1291 { "NC_SplashFile", V_LENGTH(0, 8192) },
1292 { "NC_BridgeLAN", V_LENGTH(0, 50) },
1293 #endif
1295 #ifdef TCONFIG_OPENVPN
1296 // vpn
1297 { "vpn_debug", V_01 },
1298 { "vpn_server_eas", V_NONE },
1299 { "vpn_server_dns", V_NONE },
1300 { "vpn_server1_poll", V_RANGE(0, 1440) },
1301 { "vpn_server1_if", V_TEXT(3, 3) }, // tap, tun
1302 { "vpn_server1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1303 { "vpn_server1_port", V_PORT },
1304 { "vpn_server1_firewall", V_TEXT(0, 8) }, // auto, external, custom
1305 { "vpn_server1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1306 { "vpn_server1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1307 { "vpn_server1_cipher", V_TEXT(0, 16) },
1308 { "vpn_server1_dhcp", V_01 },
1309 { "vpn_server1_r1", V_IP },
1310 { "vpn_server1_r2", V_IP },
1311 { "vpn_server1_sn", V_IP },
1312 { "vpn_server1_nm", V_IP },
1313 { "vpn_server1_local", V_IP },
1314 { "vpn_server1_remote", V_IP },
1315 { "vpn_server1_reneg", V_RANGE(-1,2147483647)},
1316 { "vpn_server1_hmac", V_RANGE(-1, 2) },
1317 { "vpn_server1_plan", V_01 },
1318 { "vpn_server1_ccd", V_01 },
1319 { "vpn_server1_c2c", V_01 },
1320 { "vpn_server1_ccd_excl", V_01 },
1321 { "vpn_server1_ccd_val", V_NONE },
1322 { "vpn_server1_pdns", V_01 },
1323 { "vpn_server1_rgw", V_01 },
1324 { "vpn_server1_userpass", V_01 },
1325 { "vpn_server1_nocert", V_01 },
1326 { "vpn_server1_users_val",V_NONE },
1327 { "vpn_server1_custom", V_NONE },
1328 { "vpn_server1_static", V_NONE },
1329 { "vpn_server1_ca", V_NONE },
1330 { "vpn_server1_crt", V_NONE },
1331 { "vpn_server1_key", V_NONE },
1332 { "vpn_server1_dh", V_NONE },
1333 { "vpn_server2_poll", V_RANGE(0, 1440) },
1334 { "vpn_server2_if", V_TEXT(3, 3) }, // tap, tun
1335 { "vpn_server2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1336 { "vpn_server2_port", V_PORT },
1337 { "vpn_server2_firewall", V_TEXT(0, 8) }, // auto, external, custom
1338 { "vpn_server2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1339 { "vpn_server2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1340 { "vpn_server2_cipher", V_TEXT(0, 16) },
1341 { "vpn_server2_dhcp", V_01 },
1342 { "vpn_server2_r1", V_IP },
1343 { "vpn_server2_r2", V_IP },
1344 { "vpn_server2_sn", V_IP },
1345 { "vpn_server2_nm", V_IP },
1346 { "vpn_server2_local", V_IP },
1347 { "vpn_server2_remote", V_IP },
1348 { "vpn_server2_reneg", V_RANGE(-1,2147483647)},
1349 { "vpn_server2_hmac", V_RANGE(-1, 2) },
1350 { "vpn_server2_plan", V_01 },
1351 { "vpn_server2_pdns", V_01 },
1352 { "vpn_server2_rgw", V_01 },
1353 { "vpn_server2_userpass", V_01 },
1354 { "vpn_server2_nocert", V_01 },
1355 { "vpn_server2_users_val",V_NONE },
1356 { "vpn_server2_custom", V_NONE },
1357 { "vpn_server2_ccd", V_01 },
1358 { "vpn_server2_c2c", V_01 },
1359 { "vpn_server2_ccd_excl", V_01 },
1360 { "vpn_server2_ccd_val", V_NONE },
1361 { "vpn_server2_static", V_NONE },
1362 { "vpn_server2_ca", V_NONE },
1363 { "vpn_server2_crt", V_NONE },
1364 { "vpn_server2_key", V_NONE },
1365 { "vpn_server2_dh", V_NONE },
1366 { "vpn_client_eas", V_NONE },
1367 { "vpn_client1_poll", V_RANGE(0, 1440) },
1368 { "vpn_client1_if", V_TEXT(3, 3) }, // tap, tun
1369 { "vpn_client1_bridge", V_01 },
1370 { "vpn_client1_nat", V_01 },
1371 { "vpn_client1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1372 { "vpn_client1_addr", V_NONE },
1373 { "vpn_client1_port", V_PORT },
1374 { "vpn_client1_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1375 { "vpn_client1_firewall", V_TEXT(0, 6) }, // auto, custom
1376 { "vpn_client1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1377 { "vpn_client1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1378 { "vpn_client1_cipher", V_TEXT(0, 16) },
1379 { "vpn_client1_local", V_IP },
1380 { "vpn_client1_remote", V_IP },
1381 { "vpn_client1_nm", V_IP },
1382 { "vpn_client1_reneg", V_RANGE(-1,2147483647)},
1383 { "vpn_client1_hmac", V_RANGE(-1, 2) },
1384 { "vpn_client1_adns", V_RANGE(0, 3) },
1385 { "vpn_client1_rgw", V_01 },
1386 { "vpn_client1_gw", V_TEXT(0, 15) },
1387 { "vpn_client1_custom", V_NONE },
1388 { "vpn_client1_static", V_NONE },
1389 { "vpn_client1_ca", V_NONE },
1390 { "vpn_client1_crt", V_NONE },
1391 { "vpn_client1_key", V_NONE },
1392 { "vpn_client1_userauth", V_01 },
1393 { "vpn_client1_username", V_TEXT(0,50) },
1394 { "vpn_client1_password", V_TEXT(0,50) },
1395 { "vpn_client1_useronly", V_01 },
1396 { "vpn_client1_tlsremote",V_01 },
1397 { "vpn_client1_cn", V_NONE },
1398 { "vpn_client2_poll", V_RANGE(0, 1440) },
1399 { "vpn_client2_if", V_TEXT(3, 3) }, // tap, tun
1400 { "vpn_client2_bridge", V_01 },
1401 { "vpn_client2_nat", V_01 },
1402 { "vpn_client2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1403 { "vpn_client2_addr", V_NONE },
1404 { "vpn_client2_port", V_PORT },
1405 { "vpn_client2_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1406 { "vpn_client2_firewall", V_TEXT(0, 6) }, // auto, custom
1407 { "vpn_client2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1408 { "vpn_client2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1409 { "vpn_client2_cipher", V_TEXT(0, 16) },
1410 { "vpn_client2_local", V_IP },
1411 { "vpn_client2_remote", V_IP },
1412 { "vpn_client2_nm", V_IP },
1413 { "vpn_client2_reneg", V_RANGE(-1,2147483647)},
1414 { "vpn_client2_hmac", V_RANGE(-1, 2) },
1415 { "vpn_client2_adns", V_RANGE(0, 3) },
1416 { "vpn_client2_rgw", V_01 },
1417 { "vpn_client2_gw", V_TEXT(0, 15) },
1418 { "vpn_client2_custom", V_NONE },
1419 { "vpn_client2_static", V_NONE },
1420 { "vpn_client2_ca", V_NONE },
1421 { "vpn_client2_crt", V_NONE },
1422 { "vpn_client2_key", V_NONE },
1423 { "vpn_client2_userauth", V_01 },
1424 { "vpn_client2_username", V_TEXT(0,50) },
1425 { "vpn_client2_password", V_TEXT(0,50) },
1426 { "vpn_client2_useronly", V_01 },
1427 { "vpn_client2_tlsremote",V_01 },
1428 { "vpn_client2_cn", V_NONE },
1429 #endif // vpn
1431 #ifdef TCONFIG_PPTPD
1432 // pptp server
1433 { "pptpd_enable", V_01 },
1434 { "pptpd_remoteip", V_TEXT(0,24) },
1435 { "pptpd_forcemppe", V_01 },
1436 { "pptpd_users", V_TEXT(0, 67*16) },
1437 { "pptpd_broadcast", V_TEXT(0,8) },
1438 { "pptpd_dns1", V_TEXT(0, 15) },
1439 { "pptpd_dns2", V_TEXT(0, 15) },
1440 { "pptpd_wins1", V_TEXT(0, 15) },
1441 { "pptpd_wins2", V_TEXT(0, 15) },
1442 { "pptpd_mtu", V_RANGE(576, 1500) },
1443 { "pptpd_mru", V_RANGE(576, 1500) },
1444 { "pptpd_custom", V_TEXT(0, 2048) },
1445 #endif
1447 #ifdef TCONFIG_TOR
1448 { "tor_enable", V_01 },
1449 { "tor_socksport", V_RANGE(1,65535) },
1450 { "tor_transport", V_RANGE(1,65535) },
1451 { "tor_dnsport", V_RANGE(1,65535) },
1452 { "tor_datadir", V_TEXT(0,24) },
1453 { "tor_iface", V_LENGTH(0, 50) },
1454 { "tor_users", V_LENGTH(0, 4096) },
1455 { "tor_custom", V_TEXT(0, 2048) },
1456 #endif
1459 ppp_static 0/1
1460 ppp_static_ip IP
1461 wl_enable 0/1
1462 wl_wds_timeout
1463 wl_maxassoc 1-256
1464 wl_phytype a,b,g
1465 wl_net_reauth
1466 wl_preauth
1467 wl_wme_ap_bk
1468 wl_wme_ap_be
1469 wl_wme_ap_vi
1470 wl_wme_ap_vo
1471 wl_wme_sta_bk
1472 wl_wme_sta_be
1473 wl_wme_sta_vi
1474 wl_wme_sta_vo
1476 port_priority_1 0-2
1477 port_flow_control_1 0,1
1478 port_rate_limit_1 0-8
1479 port_priority_2 0-2
1480 port_flow_control_2 0,1
1481 port_rate_limit_2 0-8
1482 port_priority_3 0-2
1483 port_flow_control_3 0,1
1484 port_rate_limit_3 0-8
1485 port_priority_4 0-2
1486 port_flow_control_4 0,1
1487 port_rate_limit_4 0-8
1488 wl_ap_ip
1489 wl_ap_ssid
1491 #ifdef TCONFIG_PPTPD
1492 { "pptp_client_enable", V_01 },
1493 { "pptp_client_peerdns", V_RANGE(0,2) },
1494 { "pptp_client_mtuenable",V_01 },
1495 { "pptp_client_mtu", V_RANGE(576, 1500) },
1496 { "pptp_client_mruenable",V_01 },
1497 { "pptp_client_mru", V_RANGE(576, 1500) },
1498 { "pptp_client_nat", V_01 },
1499 { "pptp_client_srvip", V_NONE },
1500 { "pptp_client_srvsub", V_IP },
1501 { "pptp_client_srvsubmsk",V_IP },
1502 { "pptp_client_username", V_TEXT(0,50) },
1503 { "pptp_client_passwd", V_TEXT(0,50) },
1504 { "pptp_client_crypt", V_RANGE(0, 3) },
1505 { "pptp_client_custom", V_NONE },
1506 { "pptp_client_dfltroute",V_01 },
1507 { "pptp_client_stateless",V_01 },
1508 #endif
1510 { NULL }
1514 static int webcgi_nvram_set(const nvset_t *v, const char *name, int write)
1516 char *p, *e;
1517 int n;
1518 long l;
1519 unsigned u[6];
1520 int ok;
1521 int dirty;
1522 #ifdef TCONFIG_IPV6
1523 struct in6_addr addr;
1524 #endif
1526 if ((p = webcgi_get((char*)name)) == NULL) return 0;
1528 _dprintf("[%s] %s=%s\n", v->name, (char*)name, p);
1529 dirty = 0;
1530 ok = 1;
1531 switch (v->vtype) {
1532 case VT_TEXT:
1533 p = unix_string(p); // NOTE: p = malloc'd
1534 // drop
1535 case VT_LENGTH:
1536 n = strlen(p);
1537 if ((n < v->va.i) || (n > v->vb.i)) ok = 0;
1538 break;
1539 case VT_RANGE:
1540 l = strtol(p, &e, 10);
1541 if ((p == e) || (*e) || (l < v->va.l) || (l > v->vb.l)) ok = 0;
1542 break;
1543 case VT_IP:
1544 if ((sscanf(p, "%3u.%3u.%3u.%3u", &u[0], &u[1], &u[2], &u[3]) != 4) ||
1545 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255)) ok = 0;
1546 break;
1547 case VT_MAC:
1548 if ((sscanf(p, "%2x:%2x:%2x:%2x:%2x:%2x", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]) != 6) ||
1549 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255) || (u[4] > 255) || (u[5] > 255)) ok = 0;
1550 break;
1551 #ifdef TCONFIG_IPV6
1552 case VT_IPV6:
1553 if (strlen(p) > 0 || v->va.i) {
1554 if (inet_pton(AF_INET6, p, &addr) != 1) ok = 0;
1556 break;
1557 #endif
1558 default:
1559 // shutup gcc
1560 break;
1562 if (!ok) {
1563 if (v->vtype == VT_TEXT) free(p);
1564 return -1;
1566 if (write) {
1567 if (!nvram_match((char *)name, p)) {
1568 if (v->vtype != VT_TEMP) dirty = 1;
1569 DEBUG_NVRAMSET(name, p);
1570 nvram_set(name, p);
1573 if (v->vtype == VT_TEXT) free(p);
1575 return dirty;
1578 typedef struct {
1579 const nvset_t *v;
1580 int write;
1581 int dirty;
1582 } nv_list_t;
1584 static int nv_wl_find(int idx, int unit, int subunit, void *param)
1586 nv_list_t *p = param;
1588 int ok = webcgi_nvram_set(p->v, wl_nvname(p->v->name + 3, unit, subunit), p->write);
1589 if (ok < 0)
1590 return 1;
1591 else {
1592 p->dirty |= ok;
1593 return 0;
1597 #ifdef CONFIG_BCMWL6
1598 static int nv_wl_bwcap_chanspec(int idx, int unit, int subunit, void *param){
1599 char chan_spec[32];
1600 char *ch,*nbw_cap,*nctrlsb;
1601 int write = *((int *)param);
1602 ch = webcgi_get(wl_nvname("channel",unit,0));
1603 nbw_cap = webcgi_get(wl_nvname("nbw_cap",unit,0));
1604 nctrlsb = webcgi_get(wl_nvname("nctrlsb",unit,0));
1605 if(!ch && !nbw_cap && !nctrlsb)
1606 return 0;
1607 if(ch == NULL || !*ch) ch = nvram_get(wl_nvname("channel",unit,0));
1608 if(nbw_cap == NULL || !*nbw_cap) nbw_cap = nvram_get(wl_nvname("nbw_cap",unit,0));
1609 if(nctrlsb == NULL || !*nctrlsb) nctrlsb = nvram_get(wl_nvname("nctrlsb",unit,0));
1611 if(!ch || !nbw_cap || !nctrlsb || !*ch || !*nbw_cap || !*nctrlsb)
1612 return 1;
1614 memset(chan_spec,0,sizeof(chan_spec));
1615 strncpy(chan_spec,ch,sizeof(chan_spec));
1616 switch(atoi(nbw_cap)){
1617 case 0:
1618 if(write)
1619 nvram_set(wl_nvname("bw_cap",unit,0), "1");
1620 break;
1621 case 1:
1622 if(write)
1623 nvram_set(wl_nvname("bw_cap",unit,0), "3");
1624 if(*ch != '0')
1625 *(chan_spec + strlen(chan_spec)) = *nctrlsb;
1626 break;
1627 case 3:
1628 if(write)
1629 nvram_set(wl_nvname("bw_cap",unit,0), "7");
1630 if(*ch != '0')
1631 strcpy(chan_spec + strlen(chan_spec),"/80");
1632 break;
1634 if(write)
1635 nvram_set(wl_nvname("chanspec", unit, 0), chan_spec);
1636 return 0;
1638 #endif
1640 static int save_variables(int write)
1642 const nvset_t *v;
1643 char *p;
1644 int n;
1645 int ok;
1646 char s[256];
1647 int dirty;
1648 static const char *msgf = "The field \"%s\" is invalid. Please report this problem.";
1649 nv_list_t nv;
1651 dirty = 0;
1652 nv.write = write;
1653 for (v = nvset_list; v->name; ++v) {
1654 ok = webcgi_nvram_set(v, v->name, write);
1656 if ((ok >= 0) && (strncmp(v->name, "wl_", 3) == 0)) {
1657 nv.dirty = dirty;
1658 nv.v = v;
1659 if (foreach_wif(1, &nv, nv_wl_find) == 0)
1660 ok |= nv.dirty;
1661 else
1662 ok = -1;
1665 if (ok < 0) {
1666 sprintf(s, msgf, v->name);
1667 resmsg_set(s);
1668 return 0;
1670 dirty |= ok;
1673 // special cases
1674 #ifdef CONFIG_BCMWL6
1675 foreach_wif(0, &write, nv_wl_bwcap_chanspec);
1676 #endif
1678 char *p1, *p2;
1679 if (((p1 = webcgi_get("set_password_1")) != NULL) && (strcmp(p1, "**********") != 0)) {
1680 if (((p2 = webcgi_get("set_password_2")) != NULL) && (strcmp(p1, p2) == 0)) {
1681 if ((write) && (!nvram_match("http_passwd", p1))) {
1682 dirty = 1;
1683 nvram_set("http_passwd", p1);
1686 else {
1687 sprintf(s, msgf, "password");
1688 resmsg_set(s);
1689 return 0;
1693 for (n = 0; n < 50; ++n) {
1694 sprintf(s, "rrule%d", n);
1695 if ((p = webcgi_get(s)) != NULL) {
1696 if (strlen(p) > 2048) {
1697 sprintf(s, msgf, s);
1698 resmsg_set(s);
1699 return 0;
1701 if ((write) && (!nvram_match(s, p))) {
1702 dirty = 1;
1703 DEBUG_NVRAMSET(s, p);
1704 nvram_set(s, p);
1709 return (write) ? dirty : 1;
1712 static void wo_tomato(char *url)
1714 char *v;
1715 int i;
1716 int ajax;
1717 int nvset;
1718 const char *red;
1719 int commit;
1720 int force_commit;
1722 // _dprintf("tomato.cgi\n");
1724 red = webcgi_safeget("_redirect", "");
1725 if (!*red) send_header(200, NULL, mime_html, 0);
1727 commit = atoi(webcgi_safeget("_commit", "1"));
1728 force_commit = atoi(webcgi_safeget("_force_commit", "0"));
1729 ajax = atoi(webcgi_safeget("_ajax", "0"));
1731 nvset = atoi(webcgi_safeget("_nvset", "1"));
1732 if (nvset) {
1733 if (!save_variables(0)) {
1734 if (ajax) {
1735 web_printf("@msg:%s", resmsg_get());
1737 else {
1738 parse_asp("error.asp");
1740 return;
1742 commit = save_variables(1) && commit;
1744 resmsg_set("Settings saved.");
1747 rboot = atoi(webcgi_safeget("_reboot", "0"));
1748 if (rboot) {
1749 parse_asp("reboot.asp");
1751 else {
1752 if (ajax) {
1753 web_printf("@msg:%s", resmsg_get());
1755 else if (atoi(webcgi_safeget("_moveip", "0"))) {
1756 parse_asp("saved-moved.asp");
1758 else if (!*red) {
1759 parse_asp("saved.asp");
1763 if (commit || force_commit) {
1764 _dprintf("commit from tomato.cgi\n");
1765 nvram_commit_x();
1768 if ((v = webcgi_get("_service")) != NULL && *v != 0) {
1769 if (!*red) {
1770 if (ajax) web_printf(" Some services are being restarted...");
1771 web_close();
1773 sleep(1);
1775 if (*v == '*') {
1776 kill(1, SIGHUP);
1778 else {
1779 exec_service(v);
1783 for (i = atoi(webcgi_safeget("_sleep", "0")); i > 0; --i) sleep(1);
1785 if (*red) redirect(red);
1787 if (rboot) {
1788 web_close();
1789 sleep(1);
1790 kill(1, SIGTERM);
1795 // ----------------------------------------------------------------------------
1798 static void wo_update(char *url)
1800 const aspapi_t *api;
1801 const char *name;
1802 int argc;
1803 char *argv[16];
1804 char s[32];
1806 if ((name = webcgi_get("exec")) != NULL) {
1807 for (api = aspapi; api->name; ++api) {
1808 if (strcmp(api->name, name) == 0) {
1809 for (argc = 0; argc < 16; ++argc) {
1810 sprintf(s, "arg%d", argc);
1811 if ((argv[argc] = (char *)webcgi_get(s)) == NULL) break;
1813 api->exec(argc, argv);
1814 break;
1820 static void wo_service(char *url)
1822 int n;
1824 exec_service(webcgi_safeget("_service", ""));
1826 if ((n = atoi(webcgi_safeget("_sleep", "2"))) <= 0) n = 2;
1827 sleep(n);
1829 common_redirect();
1832 static void wo_shutdown(char *url)
1834 parse_asp("shutdown.asp");
1835 web_close();
1836 sleep(1);
1838 kill(1, SIGQUIT);
1841 static void wo_nvcommit(char *url)
1843 parse_asp("saved.asp");
1844 web_close();
1845 nvram_commit();