Merge branch 'Teaman-ND' into Toastman-IPT-ND
[tomato.git] / release / src / router / httpd / tomato.c
blobfb3ee52b91857ad2f05a9cf42441badcbc4c356a
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_USB
339 { "usbcmd.cgi", mime_javascript, 0, wi_generic, wo_usbcommand, 1 }, //!!TB - USB
340 #endif
341 #ifdef BLACKHOLE
342 { "blackhole.cgi", NULL, 0, wi_blackhole, NULL, 1 },
343 #endif
344 #ifdef TCONFIG_NOCAT
345 { "uploadsplash.cgi", NULL, 0, wi_uploadsplash, wo_uploadsplash, 1 },
346 { "ext/uploadsplash.cgi", NULL, 0, wi_uploadsplash, wo_uploadsplash, 1 },
347 #endif
348 { NULL, NULL, 0, NULL, NULL, 1 }
351 const aspapi_t aspapi[] = {
352 { "activeroutes", asp_activeroutes },
353 { "arplist", asp_arplist },
354 { "bandwidth", asp_bandwidth },
355 { "build_time", asp_build_time },
356 { "cgi_get", asp_cgi_get },
357 { "compmac", asp_compmac },
358 { "ctcount", asp_ctcount },
359 { "ctdump", asp_ctdump },
360 { "ctrate", asp_ctrate },
361 { "ddnsx", asp_ddnsx },
362 { "devlist", asp_devlist },
363 { "webmon", asp_webmon },
364 { "dhcpc_time", asp_dhcpc_time },
365 { "dns", asp_dns },
366 { "ident", asp_ident },
367 { "lanip", asp_lanip },
368 { "layer7", asp_layer7 },
369 { "link_uptime", asp_link_uptime },
370 { "lipp", asp_lipp },
371 { "netdev", asp_netdev },
372 { "iptraffic", asp_iptraffic },
373 { "iptmon", asp_iptmon },
374 { "ipt_bandwidth", asp_ipt_bandwidth },
375 { "notice", asp_notice },
376 { "nv", asp_nv },
377 { "nvram", asp_nvram },
378 { "nvramseq", asp_nvramseq },
379 { "nvstat", asp_nvstat },
380 { "psup", asp_psup },
381 { "qrate", asp_qrate },
382 { "resmsg", asp_resmsg },
383 { "rrule", asp_rrule },
384 { "statfs", asp_statfs },
385 { "sysinfo", asp_sysinfo },
386 { "jiffies", asp_jiffies },
387 { "time", asp_time },
388 { "upnpinfo", asp_upnpinfo },
389 { "version", asp_version },
390 { "wanstatus", asp_wanstatus },
391 { "wanup", asp_wanup },
392 { "wlstats", asp_wlstats },
393 { "wlclient", asp_wlclient },
394 { "wlnoise", asp_wlnoise },
395 { "wlscan", asp_wlscan },
396 { "wlchannels", asp_wlchannels }, //!!TB
397 { "wlcountries", asp_wlcountries },
398 { "wlifaces", asp_wlifaces },
399 { "wlbands", asp_wlbands },
400 #ifdef TCONFIG_USB
401 { "usbdevices", asp_usbdevices }, //!!TB - USB Support
402 #endif
403 { "css", asp_css },
404 { NULL, NULL }
407 // -----------------------------------------------------------------------------
409 static void asp_css(int argc, char **argv)
411 const char *css = nvram_safe_get("web_css");
413 if (strcmp(css, "tomato") != 0) {
414 web_printf("<link rel='stylesheet' type='text/css' href='%s.css'>", css);
418 // -----------------------------------------------------------------------------
420 const char *resmsg_get(void)
422 return webcgi_safeget("resmsg", "");
425 void resmsg_set(const char *msg)
427 webcgi_set("resmsg", strdup(msg)); // m ok
430 int resmsg_fread(const char *fname)
432 char s[256];
433 char *p;
435 f_read_string(fname, s, sizeof(s));
436 if ((p = strchr(s, '\n')) != NULL) *p = 0;
437 if (s[0]) {
438 resmsg_set(s);
439 return 1;
441 return 0;
444 static void asp_resmsg(int argc, char **argv)
446 char *p;
448 if ((p = js_string(webcgi_safeget("resmsg", (argc > 0) ? argv[0] : ""))) == NULL) return;
449 web_printf("\nresmsg='%s';\n", p);
450 free(p);
453 // ----------------------------------------------------------------------------
455 // verification... simple sanity checks. UI should verify all fields.
457 // todo: move and re-use for filtering - zzz
459 typedef union {
460 int i;
461 long l;
462 const char *s;
463 } nvset_varg_t;
465 typedef struct {
466 const char *name;
467 enum {
468 VT_NONE, // no checking
469 VT_LENGTH, // check length of string
470 VT_TEXT, // strip \r, check length of string
471 VT_RANGE, // expect an integer, check range
472 VT_IP, // expect an ip address
473 VT_MAC, // expect a mac address
474 #ifdef TCONFIG_IPV6
475 VT_IPV6, // expect an ipv6 address
476 #endif
477 VT_TEMP // no checks, no commit
478 } vtype;
479 nvset_varg_t va;
480 nvset_varg_t vb;
481 } nvset_t;
484 #define V_NONE VT_NONE, { }, { }
485 #define V_01 VT_RANGE, { .l = 0 }, { .l = 1 }
486 #define V_PORT VT_RANGE, { .l = 2 }, { .l = 65535 }
487 #define V_ONOFF VT_LENGTH, { .i = 2 }, { .i = 3 }
488 #define V_WORD VT_LENGTH, { .i = 1 }, { .i = 16 }
489 #define V_LENGTH(min, max) VT_LENGTH, { .i = min }, { .i = max }
490 #define V_TEXT(min, max) VT_TEXT, { .i = min }, { .i = max }
491 #define V_RANGE(min, max) VT_RANGE, { .l = min }, { .l = max }
492 #define V_IP VT_IP, { }, { }
493 #define V_OCTET VT_RANGE, { .l = 0 }, { .l = 255 }
494 #define V_NUM VT_RANGE, { .l = 0 }, { .l = 0x7FFFFFFF }
495 #define V_TEMP VT_TEMP, { }, { }
496 #ifdef TCONFIG_IPV6
497 #define V_IPV6(required) VT_IPV6, { .i = required }, { }
498 #endif
500 static const nvset_t nvset_list[] = {
502 // basic-ident
503 { "router_name", V_LENGTH(0, 32) },
504 { "wan_hostname", V_LENGTH(0, 32) },
505 { "wan_domain", V_LENGTH(0, 32) },
507 // basic-time
508 { "tm_tz", V_LENGTH(1, 64) }, // PST8PDT
509 { "tm_sel", V_LENGTH(1, 64) }, // PST8PDT
510 { "tm_dst", V_01 },
511 { "ntp_updates", V_RANGE(-1, 24) },
512 { "ntp_tdod", V_01 },
513 { "ntp_server", V_LENGTH(1, 150) }, // x y z
514 { "ntp_kiss", V_LENGTH(0, 255) },
516 // basic-static
517 { "dhcpd_static", V_LENGTH(0, 106*251)}, // 106 (max chars per entry) x 250 entries
518 { "dhcpd_static_only", V_01 },
519 { "arpbind_static", V_LENGTH(0, 34*251)}, // 34 (max chars per entry) x 250 entries
520 { "arpbind_listed", V_01 }, // AB - Enable static ARP for all devices on list
522 // basic-ddns
523 { "ddnsx0", V_LENGTH(0, 2048) },
524 { "ddnsx1", V_LENGTH(0, 2048) },
525 { "ddnsx0_cache", V_LENGTH(0, 1) }, // only to clear
526 { "ddnsx1_cache", V_LENGTH(0, 1) },
527 { "ddnsx_ip", V_LENGTH(0, 32) },
528 { "ddnsx_save", V_01 },
529 { "ddnsx_refresh", V_RANGE(0, 365) },
531 // basic-network
532 // WAN
533 { "wan_proto", V_LENGTH(1, 16) }, // disabled, dhcp, static, pppoe, pptp, l2tp
534 { "wan_ipaddr", V_IP },
535 { "wan_netmask", V_IP },
536 { "wan_gateway", V_IP },
537 { "hb_server_ip", V_LENGTH(0, 32) },
538 { "l2tp_server_ip", V_LENGTH(0, 128) },
539 { "pptp_server_ip", V_LENGTH(0, 128) },
540 { "pptp_dhcp", V_01 },
541 { "ppp_username", V_LENGTH(0, 60) },
542 { "ppp_passwd", V_LENGTH(0, 60) },
543 { "ppp_service", V_LENGTH(0, 50) },
544 { "ppp_demand", V_01 },
545 { "ppp_custom", V_LENGTH(0, 256) },
546 { "ppp_idletime", V_RANGE(0, 1440) },
547 { "ppp_redialperiod", V_RANGE(1, 86400) },
548 { "ppp_mlppp", V_01 },
549 { "mtu_enable", V_01 },
550 { "wan_mtu", V_RANGE(576, 1500) },
551 { "wan_islan", V_01 },
552 { "modem_ipaddr", V_IP },
554 // LAN
555 { "lan_ipaddr", V_IP },
556 { "lan_netmask", V_IP },
557 { "lan_gateway", V_IP },
558 { "wan_dns", V_LENGTH(0, 50) }, // ip ip ip
559 { "lan_proto", V_WORD }, // static, dhcp
560 { "dhcp_start", V_LENGTH(0, 15) }, // remove !
561 { "dhcp_num", V_LENGTH(0, 4) }, // remove !
562 { "dhcpd_startip", V_LENGTH(0, 15) },
563 { "dhcpd_endip", V_LENGTH(0, 15) },
564 { "dhcp_lease", V_LENGTH(0, 5) },
565 { "wan_wins", V_IP },
568 #ifdef TCONFIG_VLAN
569 // LAN networks
570 { "lan_ifname", V_LENGTH(0, 5) },
572 { "lan1_ifname", V_LENGTH(0, 5) },
573 { "lan1_ifnames", V_TEXT(0,64) },
574 { "lan1_ipaddr", V_LENGTH(0, 15) },
575 { "lan1_netmask", V_LENGTH(0, 15) },
576 { "lan1_proto", V_LENGTH(0, 6) },
577 { "lan1_stp", V_LENGTH(0, 1) },
578 { "dhcp1_start", V_LENGTH(0, 15) },
579 { "dhcp1_num", V_LENGTH(0, 4) },
580 { "dhcpd1_startip", V_LENGTH(0, 15) },
581 { "dhcpd1_endip", V_LENGTH(0, 15) },
582 { "dhcp1_lease", V_LENGTH(0, 5) },
584 { "lan2_ifname", V_LENGTH(0, 5) },
585 { "lan2_ifnames", V_TEXT(0,64) },
586 { "lan2_ipaddr", V_LENGTH(0, 15) },
587 { "lan2_netmask", V_LENGTH(0, 15) },
588 { "lan2_proto", V_LENGTH(0, 6) },
589 { "lan2_stp", V_LENGTH(0, 1) },
590 { "dhcp2_start", V_LENGTH(0, 15) },
591 { "dhcp2_num", V_LENGTH(0, 4) },
592 { "dhcpd2_startip", V_LENGTH(0, 15) },
593 { "dhcpd2_endip", V_LENGTH(0, 15) },
594 { "dhcp2_lease", V_LENGTH(0, 5) },
596 { "lan3_ifname", V_LENGTH(0, 5) },
597 { "lan3_ifnames", V_TEXT(0,64) },
598 { "lan3_ipaddr", V_LENGTH(0, 15) },
599 { "lan3_netmask", V_LENGTH(0, 15) },
600 { "lan3_proto", V_LENGTH(0, 6) },
601 { "lan3_stp", V_LENGTH(0, 1) },
602 { "dhcp3_start", V_LENGTH(0, 15) },
603 { "dhcp3_num", V_LENGTH(0, 4) },
604 { "dhcpd3_startip", V_LENGTH(0, 15) },
605 { "dhcpd3_endip", V_LENGTH(0, 15) },
606 { "dhcp3_lease", V_LENGTH(0, 5) },
607 #endif
610 // wireless
611 { "wl_radio", V_01 },
612 { "wl_mode", V_LENGTH(2, 3) }, // ap, sta, wet, wds
613 { "wl_net_mode", V_LENGTH(5, 8) }, // disabled, mixed, b-only, g-only, bg-mixed, n-only [speedbooster]
614 { "wl_ssid", V_LENGTH(1, 32) },
615 { "wl_closed", V_01 },
616 { "wl_channel", V_RANGE(0, 216) },
618 #ifdef TCONFIG_VLAN
619 { "wl_vifs", V_LENGTH(0, 64) }, // multiple/virtual BSSIDs
620 #ifndef LINUX26
621 { "nas_alternate", V_01 }, // only meaningful for ND/K24 builds
622 #endif
623 #endif
625 { "wl_security_mode", V_LENGTH(1, 32) }, // disabled, radius, wep, wpa_personal, wpa_enterprise, wpa2_personal, wpa2_enterprise
626 { "wl_radius_ipaddr", V_IP },
627 { "wl_radius_port", V_PORT },
628 { "wl_radius_key", V_LENGTH(1, 64) },
629 { "wl_wep_bit", V_RANGE(64, 128) }, // 64 or 128
630 { "wl_passphrase", V_LENGTH(0, 20) },
631 { "wl_key", V_RANGE(1, 4) },
632 { "wl_key1", V_LENGTH(0, 26) },
633 { "wl_key2", V_LENGTH(0, 26) },
634 { "wl_key3", V_LENGTH(0, 26) },
635 { "wl_key4", V_LENGTH(0, 26) },
636 { "wl_crypto", V_LENGTH(3, 8) }, // tkip, aes, tkip+aes
637 { "wl_wpa_psk", V_LENGTH(8, 64) },
638 { "wl_wpa_gtk_rekey", V_RANGE(60, 7200) },
640 { "wl_lazywds", V_01 },
641 { "wl_wds", V_LENGTH(0, 180) }, // mac mac mac (x 10)
643 { "wl_wds_enable", V_01 },
644 { "wl_gmode", V_RANGE(-1, 6) },
645 { "wl_wep", V_LENGTH(1, 32) }, // off, on, restricted,tkip,aes,tkip+aes
646 { "wl_akm", V_LENGTH(0, 32) }, // wpa, wpa2, psk, psk2, wpa wpa2, psk psk2, ""
647 { "wl_auth_mode", V_LENGTH(4, 6) }, // none, radius
649 { "wl_nmode", V_NONE },
650 { "wl_nband", V_RANGE(0, 2) }, // 2 - 2.4GHz, 1 - 5GHz, 0 - Auto
651 { "wl_nreqd", V_NONE },
652 { "wl_nbw_cap", V_RANGE(0, 2) }, // 0 - 20MHz, 1 - 40MHz, 2 - Auto
653 { "wl_nbw", V_NONE },
654 { "wl_mimo_preamble", V_WORD }, // 802.11n Preamble: mm/gf/auto/gfbcm
655 { "wl_nctrlsb", V_NONE }, // none, lower, upper
657 #ifdef TCONFIG_IPV6
658 // basic-ipv6
659 { "ipv6_service", V_LENGTH(0, 16) }, // '', native, native-pd, 6to4, sit, other
660 { "ipv6_prefix", V_IPV6(0) },
661 { "ipv6_prefix_length", V_RANGE(3, 127) },
662 { "ipv6_rtr_addr", V_IPV6(0) },
663 { "ipv6_radvd", V_01 },
664 { "ipv6_accept_ra", V_NUM },
665 { "ipv6_tun_addr", V_IPV6(1) },
666 { "ipv6_tun_addrlen", V_RANGE(3, 127) },
667 { "ipv6_ifname", V_LENGTH(0, 8) },
668 { "ipv6_tun_v4end", V_IP },
669 { "ipv6_relay", V_RANGE(1, 254) },
670 { "ipv6_tun_mtu", V_NUM }, // Tunnel MTU
671 { "ipv6_tun_ttl", V_NUM }, // Tunnel TTL
672 { "ipv6_dns", V_LENGTH(0, 40*3) }, // ip6 ip6 ip6
673 #endif
675 // basic-wfilter
676 { "wl_macmode", V_NONE }, // allow, deny, disabled
677 { "wl_maclist", V_LENGTH(0, 18*251) }, // 18 x 250 (11:22:33:44:55:66 ...)
678 { "macnames", V_LENGTH(0, 62*251) }, // 62 (12+1+48+1) x 50 (112233445566<..>) todo: re-use -- zzz
680 // advanced-ctnf
681 { "ct_max", V_NUM },
682 { "ct_tcp_timeout", V_LENGTH(20, 70) },
683 { "ct_udp_timeout", V_LENGTH(5, 15) },
684 { "ct_timeout", V_LENGTH(5, 15) },
685 { "nf_ttl", V_LENGTH(1, 6) },
686 { "nf_l7in", V_01 },
687 #ifdef LINUX26
688 { "nf_sip", V_01 },
689 { "ct_hashsize", V_NUM },
690 #endif
691 { "nf_rtsp", V_01 },
692 { "nf_pptp", V_01 },
693 { "nf_h323", V_01 },
694 { "nf_ftp", V_01 },
696 // advanced-dhcpdns
697 { "dhcpd_slt", V_RANGE(-1, 43200) }, // -1=infinite, 0=follow normal lease time, >=1 custom
698 { "dhcpd_dmdns", V_01 },
699 { "dhcpd_lmax", V_NUM },
700 { "dhcpd_gwmode", V_NUM },
701 { "dns_addget", V_01 },
702 { "dns_intcpt", V_01 },
703 { "dhcpc_minpkt", V_01 },
704 { "dhcpc_custom", V_LENGTH(0, 80) },
705 { "dns_norebind", V_01 },
706 { "dnsmasq_custom", V_TEXT(0, 2048) },
707 { "dhcpd_static_only", V_01 },
708 // { "dnsmasq_norw", V_01 },
710 // advanced-firewall
711 { "block_wan", V_01 },
712 { "multicast_pass", V_01 },
714 #ifdef TCONFIG_VLAN
715 { "multicast_lan", V_01 },
716 { "multicast_lan1", V_01 },
717 { "multicast_lan2", V_01 },
718 { "multicast_lan3", V_01 },
719 #endif
720 { "udpxy_enable", V_01 },
721 { "udpxy_stats", V_01 },
722 { "udpxy_clients", V_RANGE(1, 5000) },
723 { "udpxy_port", V_RANGE(0, 65535) },
724 { "block_loopback", V_01 },
725 { "nf_loopback", V_NUM },
726 { "ne_syncookies", V_01 },
727 { "ne_snat", V_01 },
728 { "dhcp_pass", V_01 },
729 #ifdef TCONFIG_EMF
730 { "emf_entry", V_NONE },
731 { "emf_uffp_entry", V_NONE },
732 { "emf_rtport_entry", V_NONE },
733 { "emf_enable", V_01 },
734 #endif
736 // advanced-misc
737 { "wait_time", V_RANGE(3, 20) },
738 { "wan_speed", V_RANGE(0, 4) },
739 { "clkfreq", V_NONE }, // Toastman
740 { "jumbo_frame_enable", V_01 }, // Jumbo Frames support (for RT-N16/WNR3500L)
741 { "jumbo_frame_size", V_RANGE(1, 9720) },
742 #ifdef CONFIG_BCMWL5
743 { "ctf_disable", V_01 },
744 #endif
745 // advanced-vlan
746 { "vlan0ports", V_TEXT(0,16) },
747 { "vlan1ports", V_TEXT(0,16) },
748 { "vlan2ports", V_TEXT(0,16) },
749 { "vlan3ports", V_TEXT(0,16) },
750 { "vlan4ports", V_TEXT(0,16) },
751 { "vlan5ports", V_TEXT(0,16) },
752 { "vlan6ports", V_TEXT(0,16) },
753 { "vlan7ports", V_TEXT(0,16) },
754 { "vlan8ports", V_TEXT(0,16) },
755 { "vlan9ports", V_TEXT(0,16) },
756 { "vlan10ports", V_TEXT(0,16) },
757 { "vlan11ports", V_TEXT(0,16) },
758 { "vlan12ports", V_TEXT(0,16) },
759 { "vlan13ports", V_TEXT(0,16) },
760 { "vlan14ports", V_TEXT(0,16) },
761 { "vlan15ports", V_TEXT(0,16) },
762 { "vlan0hwname", V_TEXT(0,8) },
763 { "vlan1hwname", V_TEXT(0,8) },
764 { "vlan2hwname", V_TEXT(0,8) },
765 { "vlan3hwname", V_TEXT(0,8) },
766 { "vlan4hwname", V_TEXT(0,8) },
767 { "vlan5hwname", V_TEXT(0,8) },
768 { "vlan6hwname", V_TEXT(0,8) },
769 { "vlan7hwname", V_TEXT(0,8) },
770 { "vlan8hwname", V_TEXT(0,8) },
771 { "vlan9hwname", V_TEXT(0,8) },
772 { "vlan10hwname", V_TEXT(0,8) },
773 { "vlan11hwname", V_TEXT(0,8) },
774 { "vlan12hwname", V_TEXT(0,8) },
775 { "vlan13hwname", V_TEXT(0,8) },
776 { "vlan14hwname", V_TEXT(0,8) },
777 { "vlan15hwname", V_TEXT(0,8) },
778 { "wan_ifnameX", V_TEXT(0,8) },
779 { "lan_ifnames", V_TEXT(0,64) },
780 { "manual_boot_nv", V_01 },
781 { "trunk_vlan_so", V_01 },
783 #ifdef TCONFIG_VLAN
784 // advanced-vlan
785 { "vlan0ports", V_TEXT(0,16) },
786 { "vlan1ports", V_TEXT(0,16) },
787 { "vlan2ports", V_TEXT(0,16) },
788 { "vlan3ports", V_TEXT(0,16) },
789 { "vlan4ports", V_TEXT(0,16) },
790 { "vlan5ports", V_TEXT(0,16) },
791 { "vlan6ports", V_TEXT(0,16) },
792 { "vlan7ports", V_TEXT(0,16) },
793 { "vlan8ports", V_TEXT(0,16) },
794 { "vlan9ports", V_TEXT(0,16) },
795 { "vlan10ports", V_TEXT(0,16) },
796 { "vlan11ports", V_TEXT(0,16) },
797 { "vlan12ports", V_TEXT(0,16) },
798 { "vlan13ports", V_TEXT(0,16) },
799 { "vlan14ports", V_TEXT(0,16) },
800 { "vlan15ports", V_TEXT(0,16) },
801 { "vlan0hwname", V_TEXT(0,8) },
802 { "vlan1hwname", V_TEXT(0,8) },
803 { "vlan2hwname", V_TEXT(0,8) },
804 { "vlan3hwname", V_TEXT(0,8) },
805 { "vlan4hwname", V_TEXT(0,8) },
806 { "vlan5hwname", V_TEXT(0,8) },
807 { "vlan6hwname", V_TEXT(0,8) },
808 { "vlan7hwname", V_TEXT(0,8) },
809 { "vlan8hwname", V_TEXT(0,8) },
810 { "vlan9hwname", V_TEXT(0,8) },
811 { "vlan10hwname", V_TEXT(0,8) },
812 { "vlan11hwname", V_TEXT(0,8) },
813 { "vlan12hwname", V_TEXT(0,8) },
814 { "vlan13hwname", V_TEXT(0,8) },
815 { "vlan14hwname", V_TEXT(0,8) },
816 { "vlan15hwname", V_TEXT(0,8) },
817 { "wan_ifnameX", V_TEXT(0,8) },
818 { "lan_ifnames", V_TEXT(0,64) },
819 { "manual_boot_nv", V_01 },
820 { "trunk_vlan_so", V_01 },
821 #endif
823 // advanced-mac
824 { "mac_wan", V_LENGTH(0, 17) },
825 { "wl_macaddr", V_LENGTH(0, 17) },
826 { "wl_hwaddr", V_LENGTH(0, 17) },
828 // advanced-routing
829 { "routes_static", V_LENGTH(0, 2048) },
830 { "dhcp_routes", V_01 },
831 { "lan_stp", V_RANGE(0, 1) },
832 { "wk_mode", V_LENGTH(1, 32) }, // gateway, router
833 #ifdef TCONFIG_ZEBRA
834 { "dr_setting", V_RANGE(0, 3) },
835 { "dr_lan_tx", V_LENGTH(0, 32) },
836 { "dr_lan_rx", V_LENGTH(0, 32) },
838 #ifdef TCONFIG_VLAN
839 { "dr_lan1_tx", V_LENGTH(0, 32) },
840 { "dr_lan1_rx", V_LENGTH(0, 32) },
841 { "dr_lan2_tx", V_LENGTH(0, 32) },
842 { "dr_lan2_rx", V_LENGTH(0, 32) },
843 { "dr_lan3_tx", V_LENGTH(0, 32) },
844 { "dr_lan3_rx", V_LENGTH(0, 32) },
845 #endif
846 { "dr_wan_tx", V_LENGTH(0, 32) },
847 { "dr_wan_rx", V_LENGTH(0, 32) },
848 #endif
851 #ifdef TCONFIG_VLAN
852 // advanced-access
853 { "lan_access", V_LENGTH(0, 4096) },
854 #endif
856 // advanced-wireless
857 { "wl_country", V_LENGTH(0, 64) }, // !!TB - Country code
858 { "wl_country_code", V_LENGTH(0, 4) }, // !!TB - Country code
859 { "wl_btc_mode", V_RANGE(0, 2) }, // !!TB - BT Coexistence Mode: 0 (disable), 1 (enable), 2 (preemption)
860 { "wl_afterburner", V_LENGTH(2, 4) }, // off, on, auto
861 { "wl_auth", V_01 },
862 { "wl_rateset", V_LENGTH(2, 7) }, // all, default, 12
863 { "wl_rate", V_RANGE(0, 54 * 1000 * 1000) },
864 { "wl_mrate", V_RANGE(0, 54 * 1000 * 1000) },
865 { "wl_gmode_protection",V_LENGTH(3, 4) }, // off, auto
866 { "wl_frameburst", V_ONOFF }, // off, on
867 { "wl_bcn", V_RANGE(1, 65535) },
868 { "wl_dtim", V_RANGE(1, 255) },
869 { "wl_frag", V_RANGE(256, 2346) },
870 { "wl_rts", V_RANGE(0, 2347) },
871 { "wl_ap_isolate", V_01 },
872 { "wl_plcphdr", V_LENGTH(4, 5) }, // long, short
873 { "wl_antdiv", V_RANGE(0, 3) },
874 { "wl_txant", V_RANGE(0, 3) },
875 { "wl_txpwr", V_RANGE(0, 400) },
876 { "wl_wme", V_WORD }, // auto, off, on
877 { "wl_wme_no_ack", V_ONOFF }, // off, on
878 { "wl_wme_apsd", V_ONOFF }, // off, on
879 { "wl_maxassoc", V_RANGE(0, 255) },
880 { "wl_distance", V_LENGTH(0, 5) }, // "", 1-99999
881 { "wlx_hpamp", V_01 },
882 { "wlx_hperx", V_01 },
883 { "wl_reg_mode", V_LENGTH(1, 3) }, // !!TB - Regulatory: off, h, d
884 { "wl_mitigation", V_RANGE(0, 3) }, // Interference Mitigation Mode (0|1|2|3)
886 { "wl_nmode_protection", V_WORD, }, // off, auto
887 { "wl_nmcsidx", V_RANGE(-2, 32), }, // -2 - 32
888 { "wl_obss_coex", V_01 },
890 // forward-dmz
891 { "dmz_enable", V_01 },
892 { "dmz_ipaddr", V_LENGTH(0, 15) },
893 { "dmz_sip", V_LENGTH(0, 512) },
896 // bwm-client monitor
897 { "cmon_enable", V_01 },
898 { "cmon_ipaddr", V_IP },
901 // forward-upnp
902 { "upnp_enable", V_NUM },
903 { "upnp_secure", V_01 },
904 { "upnp_port", V_RANGE(0, 65535) },
905 { "upnp_ssdp_interval", V_RANGE(10, 9999) },
906 { "upnp_mnp", V_01 },
907 { "upnp_clean", V_01 },
908 { "upnp_clean_interval", V_RANGE(60, 65535) },
909 { "upnp_clean_threshold", V_RANGE(0, 9999) },
910 { "upnp_min_port_int", V_PORT },
911 { "upnp_max_port_int", V_PORT },
912 { "upnp_min_port_ext", V_PORT },
913 { "upnp_max_port_ext", V_PORT },
915 #ifdef TCONFIG_VLAN
916 { "upnp_lan", V_01 },
917 { "upnp_lan1", V_01 },
918 { "upnp_lan2", V_01 },
919 { "upnp_lan3", V_01 },
920 #endif
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, 16384) }, // 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 { "web_mx", V_LENGTH(0, 128) },
951 { "http_wanport", V_PORT },
952 { "telnetd_eas", V_01 },
953 { "telnetd_port", V_PORT },
954 { "sshd_eas", V_01 },
955 { "sshd_pass", V_01 },
956 { "sshd_port", V_PORT },
957 { "sshd_remote", V_01 },
958 { "sshd_forwarding", V_01 },
959 { "sshd_rport", V_PORT },
960 { "sshd_authkeys", V_TEXT(0, 4096) },
961 { "rmgt_sip", V_LENGTH(0, 512) },
962 { "ne_shlimit", V_TEXT(1, 50) },
964 // admin-bwm
965 { "rstats_enable", V_01 },
966 { "rstats_path", V_LENGTH(0, 48) },
967 { "rstats_stime", V_RANGE(1, 168) },
968 { "rstats_offset", V_RANGE(1, 31) },
969 { "rstats_exclude", V_LENGTH(0, 64) },
970 { "rstats_sshut", V_01 },
971 { "rstats_bak", V_01 },
973 // admin-ipt
974 { "cstats_enable", V_01 },
975 { "cstats_path", V_LENGTH(0, 48) },
976 { "cstats_stime", V_RANGE(1, 168) },
977 { "cstats_offset", V_RANGE(1, 31) },
978 { "cstats_labels", V_RANGE(0, 2) },
979 { "cstats_exclude", V_LENGTH(0, 512) },
980 { "cstats_include", V_LENGTH(0, 2048) },
981 { "cstats_all", V_01 },
982 { "cstats_sshut", V_01 },
983 { "cstats_bak", V_01 },
985 // admin-buttons
986 { "sesx_led", V_RANGE(0, 255) }, // amber, white, aoss
987 { "sesx_b0", V_RANGE(0, 5) }, // 0-5: toggle wireless, reboot, shutdown, script, usb unmount
988 { "sesx_b1", V_RANGE(0, 5) }, // "
989 { "sesx_b2", V_RANGE(0, 5) }, // "
990 { "sesx_b3", V_RANGE(0, 5) }, // "
991 { "sesx_script", V_TEXT(0, 1024) }, //
992 { "script_brau", V_TEXT(0, 1024) }, //
994 // admin-debug
995 { "debug_nocommit", V_01 },
996 { "debug_cprintf", V_01 },
997 { "debug_cprintf_file", V_01 },
998 // { "debug_keepfiles", V_01 },
999 { "debug_ddns", V_01 },
1000 { "debug_norestart", V_TEXT(0, 128) },
1001 { "console_loglevel", V_RANGE(1, 8) },
1002 { "t_cafree", V_01 },
1003 { "t_hidelr", V_01 },
1005 // admin-sched
1006 { "sch_rboot", V_TEXT(0, 64) },
1007 { "sch_rcon", V_TEXT(0, 64) },
1008 { "sch_c1", V_TEXT(0, 64) },
1009 { "sch_c1_cmd", V_TEXT(0, 2048) },
1010 { "sch_c2", V_TEXT(0, 64) },
1011 { "sch_c2_cmd", V_TEXT(0, 2048) },
1012 { "sch_c3", V_TEXT(0, 64) },
1013 { "sch_c3_cmd", V_TEXT(0, 2048) },
1015 // admin-scripts
1016 { "script_init", V_TEXT(0, 4096) },
1017 { "script_shut", V_TEXT(0, 4096) },
1018 { "script_fire", V_TEXT(0, 8192) },
1019 { "script_wanup", V_TEXT(0, 4096) },
1021 // admin-log
1022 { "log_remote", V_01 },
1023 { "log_remoteip", V_LENGTH(0, 512) },
1024 { "log_remoteport", V_PORT },
1025 { "log_file", V_01 },
1026 { "log_file_custom", V_01 },
1027 { "log_file_path", V_TEXT(0, 4096) },
1028 { "log_file_size", V_RANGE(0, 99999) },
1029 { "log_file_keep", V_RANGE(0, 99) },
1030 { "log_limit", V_RANGE(0, 2400) },
1031 { "log_in", V_RANGE(0, 3) },
1032 { "log_out", V_RANGE(0, 3) },
1033 { "log_mark", V_RANGE(0, 99999) },
1034 { "log_events", V_TEXT(0, 32) }, // "acre,crond,ntp"
1036 // admin-log-webmonitor
1037 { "log_wm", V_01 },
1038 { "log_wmtype", V_RANGE(0, 2) },
1039 { "log_wmip", V_LENGTH(0, 512) },
1040 { "log_wmdmax", V_RANGE(0, 9999) },
1041 { "log_wmsmax", V_RANGE(0, 9999) },
1043 // admin-cifs
1044 { "cifs1", V_LENGTH(1, 1024) },
1045 { "cifs2", V_LENGTH(1, 1024) },
1047 // admin-jffs2
1048 { "jffs2_on", V_01 },
1049 { "jffs2_exec", V_LENGTH(0, 64) },
1050 { "jffs2_format", V_01 },
1052 // nas-usb - !!TB
1053 #ifdef TCONFIG_USB
1054 { "usb_enable", V_01 },
1055 { "usb_uhci", V_RANGE(-1, 1) }, // -1 - disabled, 0 - off, 1 - on
1056 { "usb_ohci", V_RANGE(-1, 1) },
1057 { "usb_usb2", V_RANGE(-1, 1) },
1058 #if defined(LINUX26) && defined(TCONFIG_USB_EXTRAS)
1059 { "usb_mmc", V_RANGE(-1, 1) },
1060 #endif
1061 { "usb_irq_thresh", V_RANGE(0, 6) },
1062 { "usb_storage", V_01 },
1063 { "usb_printer", V_01 },
1064 { "usb_printer_bidirect", V_01 },
1065 { "usb_fs_ext3", V_01 },
1066 { "usb_fs_fat", V_01 },
1067 #ifdef TCONFIG_NTFS
1068 { "usb_fs_ntfs", V_01 },
1069 #endif
1070 { "usb_automount", V_01 },
1071 { "script_usbhotplug", V_TEXT(0, 2048) },
1072 { "script_usbmount", V_TEXT(0, 2048) },
1073 { "script_usbumount", V_TEXT(0, 2048) },
1074 #endif
1076 // nas-ftp - !!TB
1077 #ifdef TCONFIG_FTP
1078 { "ftp_enable", V_RANGE(0, 2) },
1079 { "ftp_super", V_01 },
1080 { "ftp_anonymous", V_RANGE(0, 3) },
1081 { "ftp_dirlist", V_RANGE(0, 2) },
1082 { "ftp_port", V_PORT },
1083 { "ftp_max", V_RANGE(0, 12) },
1084 { "ftp_ipmax", V_RANGE(0, 12) },
1085 { "ftp_staytimeout", V_RANGE(0, 65535) },
1086 { "ftp_rate", V_RANGE(0, 99999) },
1087 { "ftp_anonrate", V_RANGE(0, 99999) },
1088 { "ftp_anonroot", V_LENGTH(0, 256) },
1089 { "ftp_pubroot", V_LENGTH(0, 256) },
1090 { "ftp_pvtroot", V_LENGTH(0, 256) },
1091 { "ftp_users", V_LENGTH(0, 4096) },
1092 { "ftp_custom", V_TEXT(0, 2048) },
1093 { "ftp_sip", V_LENGTH(0, 512) },
1094 { "ftp_limit", V_TEXT(1, 50) },
1095 { "log_ftp", V_01 },
1096 #endif
1098 #ifdef TCONFIG_SNMP
1099 { "snmp_enable", V_RANGE(0, 1) },
1100 { "snmp_location", V_LENGTH(0, 20) },
1101 { "snmp_contact", V_LENGTH(0, 20) },
1102 { "snmp_ro", V_LENGTH(0, 20) },
1103 #endif
1105 #ifdef TCONFIG_SAMBASRV
1106 // nas-samba - !!TB
1107 { "smbd_enable", V_RANGE(0, 2) },
1108 { "smbd_wgroup", V_LENGTH(0, 20) },
1109 { "smbd_master", V_01 },
1110 { "smbd_wins", V_01 },
1111 { "smbd_cpage", V_LENGTH(0, 4) },
1112 { "smbd_cset", V_LENGTH(0, 20) },
1113 { "smbd_custom", V_TEXT(0, 2048) },
1114 { "smbd_autoshare", V_RANGE(0, 3) },
1115 { "smbd_shares", V_LENGTH(0, 4096) },
1116 { "smbd_user", V_LENGTH(0, 50) },
1117 { "smbd_passwd", V_LENGTH(0, 50) },
1118 #endif
1120 #ifdef TCONFIG_MEDIA_SERVER
1121 // nas-media
1122 { "ms_enable", V_01 },
1123 { "ms_dirs", V_LENGTH(0, 1024) },
1124 { "ms_port", V_RANGE(0, 65535) },
1125 { "ms_dbdir", V_LENGTH(0, 256) },
1126 { "ms_tivo", V_01 },
1127 { "ms_stdlna", V_01 },
1128 { "ms_rescan", V_01 },
1129 { "ms_sas", V_01 },
1130 #endif
1132 // qos
1133 { "qos_enable", V_01 },
1134 { "qos_pfifo", V_01 },
1135 { "qos_ack", V_01 },
1136 { "qos_syn", V_01 },
1137 { "qos_fin", V_01 },
1138 { "qos_rst", V_01 },
1139 { "qos_icmp", V_01 },
1140 { "qos_udp", V_01 },
1141 { "qos_reset", V_01 },
1142 { "qos_pfifo", V_01 }, // !!TB
1143 { "qos_obw", V_RANGE(10, 999999) },
1144 { "qos_ibw", V_RANGE(10, 999999) },
1145 { "qos_orules", V_LENGTH(0, 4096) },
1146 { "qos_default", V_RANGE(0, 9) },
1147 { "qos_irates", V_LENGTH(0, 128) },
1148 { "qos_orates", V_LENGTH(0, 128) },
1149 { "qos_classnames", V_LENGTH(10, 128) }, // !!TOASTMAN
1151 { "ne_vegas", V_01 },
1152 { "ne_valpha", V_NUM },
1153 { "ne_vbeta", V_NUM },
1154 { "ne_vgamma", V_NUM },
1156 // qos-bw-limiter
1157 { "qosl_enable", V_01 },
1158 { "qosl_rules", V_LENGTH(0, 4096) },
1159 { "qosl_denable", V_01 },
1160 { "qosl_dulr", V_RANGE(0, 999999) },
1161 { "qosl_dulc", V_RANGE(0, 999999) },
1162 { "qosl_ddlr", V_RANGE(0, 999999) },
1163 { "qosl_ddlc", V_RANGE(0, 999999) },
1164 { "qosl_dtcp", V_RANGE(0, 1000) },
1165 { "qosl_dudp", V_RANGE(0, 100) },
1166 /*qosl_ibw unused - qos_ibw shared*/
1167 /*qosl_obw unused - qos_obw shared*/
1169 // arpbind
1170 { "arpbind_enable", V_01 },
1171 { "arpbind_only", V_01 },
1172 { "arpbind_list", V_LENGTH(0, 4096) },
1174 //NotCatSplash. Victek.
1175 #ifdef TCONFIG_NOCAT
1176 { "NC_enable", V_01 },
1177 { "NC_Verbosity", V_RANGE(0, 10) },
1178 { "NC_GatewayName", V_LENGTH(0, 255) },
1179 { "NC_GatewayPort", V_PORT },
1180 { "NC_ForcedRedirect", V_01 },
1181 { "NC_HomePage", V_LENGTH(0, 255) },
1182 { "NC_DocumentRoot", V_LENGTH(0, 255) },
1183 { "NC_SplashURL", V_LENGTH(0, 255) },
1184 { "NC_LoginTimeout", V_RANGE(0, 86400000) },
1185 { "NC_IdleTimeout", V_RANGE(0, 86400000) },
1186 { "NC_MaxMissedARP", V_RANGE(0, 10) },
1187 { "NC_PeerChecktimeout", V_RANGE(0, 60) },
1188 { "NC_ExcludePorts", V_LENGTH(0, 255) },
1189 { "NC_IncludePorts", V_LENGTH(0, 255) },
1190 { "NC_AllowedWebHosts", V_LENGTH(0, 255) },
1191 { "NC_MACWhiteList", V_LENGTH(0, 255) },
1192 { "NC_SplashFile", V_LENGTH(0, 8192) },
1193 #endif
1195 #ifdef TCONFIG_OPENVPN
1196 // vpn
1197 { "vpn_debug", V_01 },
1198 { "vpn_server_eas", V_NONE },
1199 { "vpn_server_dns", V_NONE },
1200 { "vpn_server1_poll", V_RANGE(0, 1440) },
1201 { "vpn_server1_if", V_TEXT(3, 3) }, // tap, tun
1202 { "vpn_server1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1203 { "vpn_server1_port", V_PORT },
1204 { "vpn_server1_firewall", V_TEXT(0, 8) }, // auto, external, custom
1205 { "vpn_server1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1206 { "vpn_server1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1207 { "vpn_server1_cipher", V_TEXT(0, 16) },
1208 { "vpn_server1_dhcp", V_01 },
1209 { "vpn_server1_r1", V_IP },
1210 { "vpn_server1_r2", V_IP },
1211 { "vpn_server1_sn", V_IP },
1212 { "vpn_server1_nm", V_IP },
1213 { "vpn_server1_local", V_IP },
1214 { "vpn_server1_remote", V_IP },
1215 { "vpn_server1_reneg", V_RANGE(-1,2147483647)},
1216 { "vpn_server1_hmac", V_RANGE(-1, 2) },
1217 { "vpn_server1_plan", V_01 },
1218 { "vpn_server1_ccd", V_01 },
1219 { "vpn_server1_c2c", V_01 },
1220 { "vpn_server1_ccd_excl", V_01 },
1221 { "vpn_server1_ccd_val", V_NONE },
1222 { "vpn_server1_pdns", V_01 },
1223 { "vpn_server1_rgw", V_01 },
1224 { "vpn_server1_custom", V_NONE },
1225 { "vpn_server1_static", V_NONE },
1226 { "vpn_server1_ca", V_NONE },
1227 { "vpn_server1_crt", V_NONE },
1228 { "vpn_server1_key", V_NONE },
1229 { "vpn_server1_dh", V_NONE },
1230 { "vpn_server2_poll", V_RANGE(0, 1440) },
1231 { "vpn_server2_if", V_TEXT(3, 3) }, // tap, tun
1232 { "vpn_server2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1233 { "vpn_server2_port", V_PORT },
1234 { "vpn_server2_firewall", V_TEXT(0, 8) }, // auto, external, custom
1235 { "vpn_server2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1236 { "vpn_server2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1237 { "vpn_server2_cipher", V_TEXT(0, 16) },
1238 { "vpn_server2_dhcp", V_01 },
1239 { "vpn_server2_r1", V_IP },
1240 { "vpn_server2_r2", V_IP },
1241 { "vpn_server2_sn", V_IP },
1242 { "vpn_server2_nm", V_IP },
1243 { "vpn_server2_local", V_IP },
1244 { "vpn_server2_remote", V_IP },
1245 { "vpn_server2_reneg", V_RANGE(-1,2147483647)},
1246 { "vpn_server2_hmac", V_RANGE(-1, 2) },
1247 { "vpn_server2_plan", V_01 },
1248 { "vpn_server2_pdns", V_01 },
1249 { "vpn_server2_rgw", V_01 },
1250 { "vpn_server2_custom", V_NONE },
1251 { "vpn_server2_ccd", V_01 },
1252 { "vpn_server2_c2c", V_01 },
1253 { "vpn_server2_ccd_excl", V_01 },
1254 { "vpn_server2_ccd_val", V_NONE },
1255 { "vpn_server2_static", V_NONE },
1256 { "vpn_server2_ca", V_NONE },
1257 { "vpn_server2_crt", V_NONE },
1258 { "vpn_server2_key", V_NONE },
1259 { "vpn_server2_dh", V_NONE },
1260 { "vpn_client_eas", V_NONE },
1261 { "vpn_client1_poll", V_RANGE(0, 1440) },
1262 { "vpn_client1_if", V_TEXT(3, 3) }, // tap, tun
1263 { "vpn_client1_bridge", V_01 },
1264 { "vpn_client1_nat", V_01 },
1265 { "vpn_client1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1266 { "vpn_client1_addr", V_NONE },
1267 { "vpn_client1_port", V_PORT },
1268 { "vpn_client1_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1269 { "vpn_client1_firewall", V_TEXT(0, 6) }, // auto, custom
1270 { "vpn_client1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1271 { "vpn_client1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1272 { "vpn_client1_cipher", V_TEXT(0, 16) },
1273 { "vpn_client1_local", V_IP },
1274 { "vpn_client1_remote", V_IP },
1275 { "vpn_client1_nm", V_IP },
1276 { "vpn_client1_reneg", V_RANGE(-1,2147483647)},
1277 { "vpn_client1_hmac", V_RANGE(-1, 2) },
1278 { "vpn_client1_adns", V_RANGE(0, 3) },
1279 { "vpn_client1_rgw", V_01 },
1280 { "vpn_client1_gw", V_TEXT(0, 15) },
1281 { "vpn_client1_custom", V_NONE },
1282 { "vpn_client1_static", V_NONE },
1283 { "vpn_client1_ca", V_NONE },
1284 { "vpn_client1_crt", V_NONE },
1285 { "vpn_client1_key", V_NONE },
1286 { "vpn_client1_userauth", V_01 },
1287 { "vpn_client1_username", V_TEXT(0,50) },
1288 { "vpn_client1_password", V_TEXT(0,50) },
1289 { "vpn_client1_useronly", V_01 },
1290 { "vpn_client1_tlsremote",V_01 },
1291 { "vpn_client1_cn", V_NONE },
1292 { "vpn_client2_poll", V_RANGE(0, 1440) },
1293 { "vpn_client2_if", V_TEXT(3, 3) }, // tap, tun
1294 { "vpn_client2_bridge", V_01 },
1295 { "vpn_client2_nat", V_01 },
1296 { "vpn_client2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1297 { "vpn_client2_addr", V_NONE },
1298 { "vpn_client2_port", V_PORT },
1299 { "vpn_client2_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1300 { "vpn_client2_firewall", V_TEXT(0, 6) }, // auto, custom
1301 { "vpn_client2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1302 { "vpn_client2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1303 { "vpn_client2_cipher", V_TEXT(0, 16) },
1304 { "vpn_client2_local", V_IP },
1305 { "vpn_client2_remote", V_IP },
1306 { "vpn_client2_nm", V_IP },
1307 { "vpn_client2_reneg", V_RANGE(-1,2147483647)},
1308 { "vpn_client2_hmac", V_RANGE(-1, 2) },
1309 { "vpn_client2_adns", V_RANGE(0, 3) },
1310 { "vpn_client2_rgw", V_01 },
1311 { "vpn_client2_gw", V_TEXT(0, 15) },
1312 { "vpn_client2_custom", V_NONE },
1313 { "vpn_client2_static", V_NONE },
1314 { "vpn_client2_ca", V_NONE },
1315 { "vpn_client2_crt", V_NONE },
1316 { "vpn_client2_key", V_NONE },
1317 { "vpn_client2_userauth", V_01 },
1318 { "vpn_client2_username", V_TEXT(0,50) },
1319 { "vpn_client2_password", V_TEXT(0,50) },
1320 { "vpn_client2_useronly", V_01 },
1321 { "vpn_client2_tlsremote",V_01 },
1322 { "vpn_client2_cn", V_NONE },
1323 #endif // vpn
1328 ppp_static 0/1
1329 ppp_static_ip IP
1330 wl_enable 0/1
1331 wl_wds_timeout
1332 wl_maxassoc 1-256
1333 wl_phytype a,b,g
1334 wl_net_reauth
1335 wl_preauth
1336 wl_wme_ap_bk
1337 wl_wme_ap_be
1338 wl_wme_ap_vi
1339 wl_wme_ap_vo
1340 wl_wme_sta_bk
1341 wl_wme_sta_be
1342 wl_wme_sta_vi
1343 wl_wme_sta_vo
1345 port_priority_1 0-2
1346 port_flow_control_1 0,1
1347 port_rate_limit_1 0-8
1348 port_priority_2 0-2
1349 port_flow_control_2 0,1
1350 port_rate_limit_2 0-8
1351 port_priority_3 0-2
1352 port_flow_control_3 0,1
1353 port_rate_limit_3 0-8
1354 port_priority_4 0-2
1355 port_flow_control_4 0,1
1356 port_rate_limit_4 0-8
1357 wl_ap_ip
1358 wl_ap_ssid
1360 { "pptp_client_enable", V_01 },
1361 { "pptp_client_peerdns", V_RANGE(0,2) },
1362 { "pptp_client_mtuenable",V_01 },
1363 { "pptp_client_mtu", V_RANGE(576, 1500) },
1364 { "pptp_client_mruenable",V_01 },
1365 { "pptp_client_mru", V_RANGE(576, 1500) },
1366 { "pptp_client_nat", V_01 },
1367 { "pptp_client_srvip", V_NONE },
1368 { "pptp_client_srvsub", V_IP },
1369 { "pptp_client_srvsubmsk",V_IP },
1370 { "pptp_client_username", V_TEXT(0,50) },
1371 { "pptp_client_passwd", V_TEXT(0,50) },
1372 { "pptp_client_crypt", V_RANGE(0, 3) },
1373 { "pptp_client_custom", V_NONE },
1374 { "pptp_client_dfltroute",V_01 },
1375 { "pptp_client_stateless",V_01 },
1377 { NULL }
1381 static int webcgi_nvram_set(const nvset_t *v, const char *name, int write)
1383 char *p, *e;
1384 int n;
1385 long l;
1386 unsigned u[6];
1387 int ok;
1388 int dirty;
1389 #ifdef TCONFIG_IPV6
1390 struct in6_addr addr;
1391 #endif
1393 if ((p = webcgi_get((char*)name)) == NULL) return 0;
1395 _dprintf("[%s] %s=%s\n", v->name, (char*)name, p);
1396 dirty = 0;
1397 ok = 1;
1398 switch (v->vtype) {
1399 case VT_TEXT:
1400 p = unix_string(p); // NOTE: p = malloc'd
1401 // drop
1402 case VT_LENGTH:
1403 n = strlen(p);
1404 if ((n < v->va.i) || (n > v->vb.i)) ok = 0;
1405 break;
1406 case VT_RANGE:
1407 l = strtol(p, &e, 10);
1408 if ((p == e) || (*e) || (l < v->va.l) || (l > v->vb.l)) ok = 0;
1409 break;
1410 case VT_IP:
1411 if ((sscanf(p, "%3u.%3u.%3u.%3u", &u[0], &u[1], &u[2], &u[3]) != 4) ||
1412 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255)) ok = 0;
1413 break;
1414 case VT_MAC:
1415 if ((sscanf(p, "%2x:%2x:%2x:%2x:%2x:%2x", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]) != 6) ||
1416 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255) || (u[4] > 255) || (u[5] > 255)) ok = 0;
1417 break;
1418 #ifdef TCONFIG_IPV6
1419 case VT_IPV6:
1420 if (strlen(p) > 0 || v->va.i) {
1421 if (inet_pton(AF_INET6, p, &addr) != 1) ok = 0;
1423 break;
1424 #endif
1425 default:
1426 // shutup gcc
1427 break;
1429 if (!ok) {
1430 if (v->vtype == VT_TEXT) free(p);
1431 return -1;
1433 if (write) {
1434 if (!nvram_match((char *)name, p)) {
1435 if (v->vtype != VT_TEMP) dirty = 1;
1436 DEBUG_NVRAMSET(name, p);
1437 nvram_set(name, p);
1440 if (v->vtype == VT_TEXT) free(p);
1442 return dirty;
1445 typedef struct {
1446 const nvset_t *v;
1447 int write;
1448 int dirty;
1449 } nv_list_t;
1451 static int nv_wl_find(int idx, int unit, int subunit, void *param)
1453 nv_list_t *p = param;
1455 int ok = webcgi_nvram_set(p->v, wl_nvname(p->v->name + 3, unit, subunit), p->write);
1456 if (ok < 0)
1457 return 1;
1458 else {
1459 p->dirty |= ok;
1460 return 0;
1464 static int save_variables(int write)
1466 const nvset_t *v;
1467 char *p;
1468 int n;
1469 int ok;
1470 char s[256];
1471 int dirty;
1472 static const char *msgf = "The field \"%s\" is invalid. Please report this problem.";
1473 nv_list_t nv;
1475 dirty = 0;
1476 nv.write = write;
1477 for (v = nvset_list; v->name; ++v) {
1478 ok = webcgi_nvram_set(v, v->name, write);
1480 if ((ok >= 0) && (strncmp(v->name, "wl_", 3) == 0)) {
1481 nv.dirty = dirty;
1482 nv.v = v;
1483 if (foreach_wif(1, &nv, nv_wl_find) == 0)
1484 ok |= nv.dirty;
1485 else
1486 ok = -1;
1489 if (ok < 0) {
1490 sprintf(s, msgf, v->name);
1491 resmsg_set(s);
1492 return 0;
1494 dirty |= ok;
1497 // special cases
1499 char *p1, *p2;
1500 if (((p1 = webcgi_get("set_password_1")) != NULL) && (strcmp(p1, "**********") != 0)) {
1501 if (((p2 = webcgi_get("set_password_2")) != NULL) && (strcmp(p1, p2) == 0)) {
1502 if ((write) && (!nvram_match("http_passwd", p1))) {
1503 dirty = 1;
1504 nvram_set("http_passwd", p1);
1507 else {
1508 sprintf(s, msgf, "password");
1509 resmsg_set(s);
1510 return 0;
1514 for (n = 0; n < 50; ++n) {
1515 sprintf(s, "rrule%d", n);
1516 if ((p = webcgi_get(s)) != NULL) {
1517 if (strlen(p) > 8192) { //Toastman
1518 sprintf(s, msgf, s);
1519 resmsg_set(s);
1520 return 0;
1522 if ((write) && (!nvram_match(s, p))) {
1523 dirty = 1;
1524 DEBUG_NVRAMSET(s, p);
1525 nvram_set(s, p);
1530 return (write) ? dirty : 1;
1533 static void wo_tomato(char *url)
1535 char *v;
1536 int i;
1537 int ajax;
1538 int nvset;
1539 const char *red;
1540 int commit;
1542 // _dprintf("tomato.cgi\n");
1544 red = webcgi_safeget("_redirect", "");
1545 if (!*red) send_header(200, NULL, mime_html, 0);
1547 commit = atoi(webcgi_safeget("_commit", "1"));
1548 ajax = atoi(webcgi_safeget("_ajax", "0"));
1550 nvset = atoi(webcgi_safeget("_nvset", "1"));
1551 if (nvset) {
1552 if (!save_variables(0)) {
1553 if (ajax) {
1554 web_printf("@msg:%s", resmsg_get());
1556 else {
1557 parse_asp("error.asp");
1559 return;
1561 commit = save_variables(1) && commit;
1563 resmsg_set("Settings saved.");
1566 rboot = atoi(webcgi_safeget("_reboot", "0"));
1567 if (rboot) {
1568 parse_asp("reboot.asp");
1570 else {
1571 if (ajax) {
1572 web_printf("@msg:%s", resmsg_get());
1574 else if (atoi(webcgi_safeget("_moveip", "0"))) {
1575 parse_asp("saved-moved.asp");
1577 else if (!*red) {
1578 parse_asp("saved.asp");
1582 if (commit) {
1583 _dprintf("commit from tomato.cgi\n");
1584 nvram_commit_x();
1587 if ((v = webcgi_get("_service")) != NULL && *v != 0) {
1588 if (!*red) {
1589 if (ajax) web_printf(" Some services are being restarted...");
1590 web_close();
1592 sleep(1);
1594 if (*v == '*') {
1595 kill(1, SIGHUP);
1597 else {
1598 exec_service(v);
1602 for (i = atoi(webcgi_safeget("_sleep", "0")); i > 0; --i) sleep(1);
1604 if (*red) redirect(red);
1606 if (rboot) {
1607 web_close();
1608 sleep(1);
1609 kill(1, SIGTERM);
1614 // ----------------------------------------------------------------------------
1617 static void wo_update(char *url)
1619 const aspapi_t *api;
1620 const char *name;
1621 int argc;
1622 char *argv[16];
1623 char s[32];
1625 if ((name = webcgi_get("exec")) != NULL) {
1626 for (api = aspapi; api->name; ++api) {
1627 if (strcmp(api->name, name) == 0) {
1628 for (argc = 0; argc < 16; ++argc) {
1629 sprintf(s, "arg%d", argc);
1630 if ((argv[argc] = (char *)webcgi_get(s)) == NULL) break;
1632 api->exec(argc, argv);
1633 break;
1639 static void wo_service(char *url)
1641 int n;
1643 exec_service(webcgi_safeget("_service", ""));
1645 if ((n = atoi(webcgi_safeget("_sleep", "2"))) <= 0) n = 2;
1646 sleep(n);
1648 common_redirect();
1651 static void wo_shutdown(char *url)
1653 parse_asp("shutdown.asp");
1654 web_close();
1655 sleep(1);
1657 kill(1, SIGQUIT);
1660 static void wo_nvcommit(char *url)
1662 parse_asp("saved.asp");
1663 web_close();
1664 nvram_commit();