fix last commit
[tomato.git] / release / src / router / httpd / tomato.c
bloba09c323d2270d2586d8161ea8657bbcbc03f6d0f
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 { "logs/view.cgi", NULL, 0, wi_generic, wo_viewlog, 1 },
288 { "logs/*.txt", NULL, 0, wi_generic, wo_syslog, 1 },
289 { "webmon_**", NULL, 0, wi_generic, wo_syslog, 1 },
291 { "logout.asp", NULL, 0, wi_generic, wo_asp, 1 },
292 { "clearcookies.asp", NULL, 0, wi_generic, wo_asp, 1 },
294 // { "spin.gif", NULL, 0, wi_generic_noid, wo_spin, 1 },
296 { "**.asp", NULL, 0, wi_generic_noid, wo_asp, 1 },
297 { "**.css", "text/css", 2, wi_generic_noid, do_file, 1 },
298 { "**.htm|**.html", mime_html, 2, wi_generic_noid, do_file, 1 },
299 { "**.gif", "image/gif", 5, wi_generic_noid, do_file, 1 },
300 { "**.jpg", "image/jpeg", 5, wi_generic_noid, do_file, 1 },
301 { "**.png", "image/png", 5, wi_generic_noid, do_file, 1 },
302 { "**.js", mime_javascript, 2, wi_generic_noid, do_file, 1 },
303 { "**.jsx", mime_javascript, 0, wi_generic, wo_asp, 1 },
304 { "**.svg", "image/svg+xml", 2, wi_generic_noid, do_file, 1 },
305 { "**.txt", mime_plain, 2, wi_generic_noid, do_file, 1 },
306 { "**.bin", mime_binary, 0, wi_generic_noid, do_file, 1 },
307 { "**.bino", mime_octetstream, 0, wi_generic_noid, do_file, 1 },
308 { "favicon.ico", NULL, 5, wi_generic_noid, wo_favicon, 1 },
309 // !!TB - CGI Support, enable downloading archives
310 { "**/cgi-bin/**|**.sh", NULL, 0, wi_cgi_bin, wo_cgi_bin, 1 },
311 { "**.tar|**.gz", mime_binary, 0, wi_generic_noid, do_file, 1 },
312 { "shell.cgi", mime_javascript, 0, wi_generic, wo_shell, 1 },
313 { "wpad.dat|proxy.pac", "application/x-ns-proxy-autoconfig", 0, wi_generic_noid, do_file, 0 },
315 { "webmon.cgi", mime_javascript, 0, wi_generic, wo_webmon, 1 },
316 { "dhcpc.cgi", NULL, 0, wi_generic, wo_dhcpc, 1 },
317 { "dhcpd.cgi", mime_javascript, 0, wi_generic, wo_dhcpd, 1 },
318 { "nvcommit.cgi", NULL, 0, wi_generic, wo_nvcommit, 1 },
319 { "ping.cgi", mime_javascript, 0, wi_generic, wo_ping, 1 },
320 { "trace.cgi", mime_javascript, 0, wi_generic, wo_trace, 1 },
321 { "upgrade.cgi", mime_html, 0, wi_upgrade, wo_flash, 1 },
322 { "upnp.cgi", NULL, 0, wi_generic, wo_upnp, 1 },
323 { "wakeup.cgi", NULL, 0, wi_generic, wo_wakeup, 1 },
324 { "wlmnoise.cgi", mime_html, 0, wi_generic, wo_wlmnoise, 1 },
325 { "wlradio.cgi", NULL, 0, wi_generic, wo_wlradio, 1 },
326 { "resolve.cgi", mime_javascript, 0, wi_generic, wo_resolve, 1 },
327 { "expct.cgi", mime_html, 0, wi_generic, wo_expct, 1 },
328 { "service.cgi", NULL, 0, wi_generic, wo_service, 1 },
329 // { "logout.cgi", NULL, 0, wi_generic, wo_logout, 0 },
330 // see httpd.c
331 { "shutdown.cgi", mime_html, 0, wi_generic, wo_shutdown, 1 },
332 #ifdef TCONFIG_OPENVPN
333 { "vpnstatus.cgi", mime_javascript, 0, wi_generic, wo_vpn_status, 1 },
334 #endif
335 #ifdef TCONFIG_USB
336 { "usbcmd.cgi", mime_javascript, 0, wi_generic, wo_usbcommand, 1 }, //!!TB - USB
337 #endif
338 #ifdef BLACKHOLE
339 { "blackhole.cgi", NULL, 0, wi_blackhole, NULL, 1 },
340 #endif
341 #ifdef TCONFIG_NOCAT
342 { "uploadsplash.cgi", NULL, 0, wi_uploadsplash, wo_uploadsplash, 1 },
343 { "ext/uploadsplash.cgi", NULL, 0, wi_uploadsplash, wo_uploadsplash, 1 },
344 #endif
345 { NULL, NULL, 0, NULL, NULL, 1 }
348 const aspapi_t aspapi[] = {
349 { "activeroutes", asp_activeroutes },
350 { "arplist", asp_arplist },
351 { "bandwidth", asp_bandwidth },
352 { "build_time", asp_build_time },
353 { "cgi_get", asp_cgi_get },
354 { "compmac", asp_compmac },
355 { "ctcount", asp_ctcount },
356 { "ctdump", asp_ctdump },
357 { "ctrate", asp_ctrate },
358 { "ddnsx", asp_ddnsx },
359 { "devlist", asp_devlist },
360 { "webmon", asp_webmon },
361 { "dhcpc_time", asp_dhcpc_time },
362 { "dns", asp_dns },
363 { "ident", asp_ident },
364 { "lanip", asp_lanip },
365 { "layer7", asp_layer7 },
366 { "link_uptime", asp_link_uptime },
367 { "lipp", asp_lipp },
368 { "netdev", asp_netdev },
369 { "notice", asp_notice },
370 { "nv", asp_nv },
371 { "nvram", asp_nvram },
372 { "nvramseq", asp_nvramseq },
373 { "nvstat", asp_nvstat },
374 { "psup", asp_psup },
375 { "qrate", asp_qrate },
376 { "resmsg", asp_resmsg },
377 { "rrule", asp_rrule },
378 { "statfs", asp_statfs },
379 { "sysinfo", asp_sysinfo },
380 { "time", asp_time },
381 { "upnpinfo", asp_upnpinfo },
382 { "version", asp_version },
383 { "wanstatus", asp_wanstatus },
384 { "wanup", asp_wanup },
385 { "wlstats", asp_wlstats },
386 { "wlclient", asp_wlclient },
387 { "wlnoise", asp_wlnoise },
388 { "wlscan", asp_wlscan },
389 { "wlchannels", asp_wlchannels }, //!!TB
390 { "wlcountries", asp_wlcountries },
391 { "wlifaces", asp_wlifaces },
392 { "wlbands", asp_wlbands },
393 #ifdef TCONFIG_USB
394 { "usbdevices", asp_usbdevices }, //!!TB - USB Support
395 #endif
396 { "css", asp_css },
397 { NULL, NULL }
400 // -----------------------------------------------------------------------------
402 static void asp_css(int argc, char **argv)
404 const char *css = nvram_safe_get("web_css");
406 if (strcmp(css, "tomato") != 0) {
407 web_printf("<link rel='stylesheet' type='text/css' href='%s.css'>", css);
411 // -----------------------------------------------------------------------------
413 const char *resmsg_get(void)
415 return webcgi_safeget("resmsg", "");
418 void resmsg_set(const char *msg)
420 webcgi_set("resmsg", strdup(msg)); // m ok
423 int resmsg_fread(const char *fname)
425 char s[256];
426 char *p;
428 f_read_string(fname, s, sizeof(s));
429 if ((p = strchr(s, '\n')) != NULL) *p = 0;
430 if (s[0]) {
431 resmsg_set(s);
432 return 1;
434 return 0;
437 static void asp_resmsg(int argc, char **argv)
439 char *p;
441 if ((p = js_string(webcgi_safeget("resmsg", (argc > 0) ? argv[0] : ""))) == NULL) return;
442 web_printf("\nresmsg='%s';\n", p);
443 free(p);
446 // ----------------------------------------------------------------------------
448 // verification... simple sanity checks. UI should verify all fields.
450 // todo: move and re-use for filtering - zzz
452 typedef union {
453 int i;
454 long l;
455 const char *s;
456 } nvset_varg_t;
458 typedef struct {
459 const char *name;
460 enum {
461 VT_NONE, // no checking
462 VT_LENGTH, // check length of string
463 VT_TEXT, // strip \r, check length of string
464 VT_RANGE, // expect an integer, check range
465 VT_IP, // expect an ip address
466 VT_MAC, // expect a mac address
467 #ifdef TCONFIG_IPV6
468 VT_IPV6, // expect an ipv6 address
469 #endif
470 VT_TEMP // no checks, no commit
471 } vtype;
472 nvset_varg_t va;
473 nvset_varg_t vb;
474 } nvset_t;
477 #define V_NONE VT_NONE, { }, { }
478 #define V_01 VT_RANGE, { .l = 0 }, { .l = 1 }
479 #define V_PORT VT_RANGE, { .l = 2 }, { .l = 65535 }
480 #define V_ONOFF VT_LENGTH, { .i = 2 }, { .i = 3 }
481 #define V_WORD VT_LENGTH, { .i = 1 }, { .i = 16 }
482 #define V_LENGTH(min, max) VT_LENGTH, { .i = min }, { .i = max }
483 #define V_TEXT(min, max) VT_TEXT, { .i = min }, { .i = max }
484 #define V_RANGE(min, max) VT_RANGE, { .l = min }, { .l = max }
485 #define V_IP VT_IP, { }, { }
486 #define V_OCTET VT_RANGE, { .l = 0 }, { .l = 255 }
487 #define V_NUM VT_RANGE, { .l = 0 }, { .l = 0x7FFFFFFF }
488 #define V_TEMP VT_TEMP, { }, { }
489 #ifdef TCONFIG_IPV6
490 #define V_IPV6(required) VT_IPV6, { .i = required }, { }
491 #endif
493 static const nvset_t nvset_list[] = {
495 // basic-ident
496 { "router_name", V_LENGTH(0, 32) },
497 { "wan_hostname", V_LENGTH(0, 32) },
498 { "wan_domain", V_LENGTH(0, 32) },
500 // basic-time
501 { "tm_tz", V_LENGTH(1, 64) }, // PST8PDT
502 { "tm_sel", V_LENGTH(1, 64) }, // PST8PDT
503 { "tm_dst", V_01 },
504 { "ntp_updates", V_RANGE(-1, 24) },
505 { "ntp_tdod", V_01 },
506 { "ntp_server", V_LENGTH(1, 150) }, // x y z
507 { "ntp_kiss", V_LENGTH(0, 255) },
509 // basic-static
510 { "dhcpd_static", V_LENGTH(0, 106*251)}, // 106 (max chars per entry) x 250 entries
512 // basic-ddns
513 { "ddnsx0", V_LENGTH(0, 2048) },
514 { "ddnsx1", V_LENGTH(0, 2048) },
515 { "ddnsx0_cache", V_LENGTH(0, 1) }, // only to clear
516 { "ddnsx1_cache", V_LENGTH(0, 1) },
517 { "ddnsx_ip", V_LENGTH(0, 32) },
518 { "ddnsx_save", V_01 },
519 { "ddnsx_refresh", V_RANGE(0, 365) },
521 // basic-network
522 // WAN
523 { "wan_proto", V_LENGTH(1, 16) }, // disabled, dhcp, static, pppoe, pptp, l2tp
524 { "wan_ipaddr", V_IP },
525 { "wan_netmask", V_IP },
526 { "wan_gateway", V_IP },
527 { "hb_server_ip", V_LENGTH(0, 32) },
528 { "l2tp_server_ip", V_LENGTH(0, 128) },
529 { "pptp_server_ip", V_LENGTH(0, 128) },
530 { "pptp_dhcp", V_01 },
531 { "ppp_username", V_LENGTH(0, 60) },
532 { "ppp_passwd", V_LENGTH(0, 60) },
533 { "ppp_service", V_LENGTH(0, 50) },
534 { "ppp_demand", V_01 },
535 { "ppp_custom", V_LENGTH(0, 256) },
536 { "ppp_idletime", V_RANGE(0, 1440) },
537 { "ppp_redialperiod", V_RANGE(1, 86400) },
538 { "mtu_enable", V_01 },
539 { "wan_mtu", V_RANGE(576, 1500) },
540 { "wan_islan", V_01 },
542 // LAN
543 { "lan_ipaddr", V_IP },
544 { "lan_netmask", V_IP },
545 { "lan_gateway", V_IP },
546 { "wan_dns", V_LENGTH(0, 50) }, // ip ip ip
547 { "lan_proto", V_WORD }, // static, dhcp
548 { "dhcp_start", V_RANGE(1, 254) }, // remove !
549 { "dhcp_num", V_RANGE(1, 255) }, // remove !
550 { "dhcpd_startip", V_IP },
551 { "dhcpd_endip", V_IP },
552 { "dhcp_lease", V_RANGE(1, 10080) },
553 { "wan_wins", V_IP },
555 // wireless
556 { "wl_radio", V_01 },
557 { "wl_mode", V_LENGTH(2, 3) }, // ap, sta, wet, wds
558 { "wl_net_mode", V_LENGTH(5, 8) }, // disabled, mixed, b-only, g-only, bg-mixed, n-only [speedbooster]
559 { "wl_ssid", V_LENGTH(1, 32) },
560 { "wl_closed", V_01 },
561 { "wl_channel", V_RANGE(0, 216) },
563 { "wl_security_mode", V_LENGTH(1, 32) }, // disabled, radius, wep, wpa_personal, wpa_enterprise, wpa2_personal, wpa2_enterprise
564 { "wl_radius_ipaddr", V_IP },
565 { "wl_radius_port", V_PORT },
566 { "wl_radius_key", V_LENGTH(1, 64) },
567 { "wl_wep_bit", V_RANGE(64, 128) }, // 64 or 128
568 { "wl_passphrase", V_LENGTH(0, 20) },
569 { "wl_key", V_RANGE(1, 4) },
570 { "wl_key1", V_LENGTH(0, 26) },
571 { "wl_key2", V_LENGTH(0, 26) },
572 { "wl_key3", V_LENGTH(0, 26) },
573 { "wl_key4", V_LENGTH(0, 26) },
574 { "wl_crypto", V_LENGTH(3, 8) }, // tkip, aes, tkip+aes
575 { "wl_wpa_psk", V_LENGTH(8, 64) },
576 { "wl_wpa_gtk_rekey", V_RANGE(60, 7200) },
578 { "wl_lazywds", V_01 },
579 { "wl_wds", V_LENGTH(0, 180) }, // mac mac mac (x 10)
581 { "wl_wds_enable", V_01 },
582 { "wl_gmode", V_RANGE(-1, 6) },
583 { "wl_wep", V_LENGTH(1, 32) }, // off, on, restricted,tkip,aes,tkip+aes
584 { "wl_akm", V_LENGTH(0, 32) }, // wpa, wpa2, psk, psk2, wpa wpa2, psk psk2, ""
585 { "wl_auth_mode", V_LENGTH(4, 6) }, // none, radius
587 { "wl_nmode", V_NONE },
588 { "wl_nband", V_RANGE(0, 2) }, // 2 - 2.4GHz, 1 - 5GHz, 0 - Auto
589 { "wl_nreqd", V_NONE },
590 { "wl_nbw_cap", V_RANGE(0, 2) }, // 0 - 20MHz, 1 - 40MHz, 2 - Auto
591 { "wl_nbw", V_NONE },
592 { "wl_mimo_preamble", V_WORD }, // 802.11n Preamble: mm/gf/auto/gfbcm
593 { "wl_nctrlsb", V_NONE }, // none, lower, upper
595 #ifdef TCONFIG_IPV6
596 // basic-ipv6
597 { "ipv6_service", V_LENGTH(0, 16) }, // '', native, native-pd, 6to4, sit, other
598 { "ipv6_prefix", V_IPV6(0) },
599 { "ipv6_prefix_length", V_RANGE(3, 127) },
600 { "ipv6_rtr_addr", V_IPV6(0) },
601 { "ipv6_radvd", V_01 },
602 { "ipv6_accept_ra", V_NUM },
603 { "ipv6_tun_addr", V_IPV6(1) },
604 { "ipv6_tun_addrlen", V_RANGE(3, 127) },
605 { "ipv6_ifname", V_LENGTH(0, 8) },
606 { "ipv6_tun_v4end", V_IP },
607 { "ipv6_relay", V_RANGE(1, 254) },
608 { "ipv6_tun_mtu", V_NUM }, // Tunnel MTU
609 { "ipv6_tun_ttl", V_NUM }, // Tunnel TTL
610 { "ipv6_dns", V_LENGTH(0, 40*3) }, // ip6 ip6 ip6
611 #endif
613 // basic-wfilter
614 { "wl_macmode", V_NONE }, // allow, deny, disabled
615 { "wl_maclist", V_LENGTH(0, 18*201) }, // 18 x 200 (11:22:33:44:55:66 ...)
616 { "macnames", V_LENGTH(0, 62*201) }, // 62 (12+1+48+1) x 50 (112233445566<..>) todo: re-use -- zzz
618 // advanced-ctnf
619 { "ct_max", V_NUM },
620 { "ct_tcp_timeout", V_LENGTH(20, 70) },
621 { "ct_udp_timeout", V_LENGTH(5, 15) },
622 { "ct_timeout", V_LENGTH(5, 15) },
623 { "nf_ttl", V_LENGTH(1, 6) },
624 { "nf_l7in", V_01 },
625 #ifdef LINUX26
626 { "nf_sip", V_01 },
627 { "ct_hashsize", V_NUM },
628 #endif
629 { "nf_rtsp", V_01 },
630 { "nf_pptp", V_01 },
631 { "nf_h323", V_01 },
632 { "nf_ftp", V_01 },
634 // advanced-dhcpdns
635 { "dhcpd_slt", V_RANGE(-1, 43200) }, // -1=infinite, 0=follow normal lease time, >=1 custom
636 { "dhcpd_dmdns", V_01 },
637 { "dhcpd_lmax", V_NUM },
638 { "dhcpd_gwmode", V_NUM },
639 { "dns_addget", V_01 },
640 { "dns_intcpt", V_01 },
641 { "dhcpc_minpkt", V_01 },
642 { "dhcpc_custom", V_LENGTH(0, 80) },
643 { "dns_norebind", V_01 },
644 { "dnsmasq_custom", V_TEXT(0, 2048) },
645 // { "dnsmasq_norw", V_01 },
647 // advanced-firewall
648 { "block_wan", V_01 },
649 { "multicast_pass", V_01 },
650 { "block_loopback", V_01 },
651 { "nf_loopback", V_NUM },
652 { "ne_syncookies", V_01 },
653 { "dhcp_pass", V_01 },
654 { "imq_enable", V_01 },
655 { "imq_numdevs", V_RANGE(2, 16) },
656 #ifdef TCONFIG_EMF
657 { "emf_entry", V_NONE },
658 { "emf_uffp_entry", V_NONE },
659 { "emf_rtport_entry", V_NONE },
660 { "emf_enable", V_01 },
661 #endif
663 { "cmon_enable", V_01 },
664 { "cmon_users", V_LENGTH(0, 4096) },
666 // advanced-misc
667 { "wait_time", V_RANGE(3, 20) },
668 { "wan_speed", V_RANGE(0, 4) },
669 { "jumbo_frame_enable", V_01 }, // Jumbo Frames support (for RT-N16/WNR3500L)
670 { "jumbo_frame_size", V_RANGE(1, 9720) },
671 #ifdef CONFIG_BCMWL5
672 { "ctf_disable", V_01 },
673 #endif
675 // advanced-mac
676 { "mac_wan", V_LENGTH(0, 17) },
677 { "wl_macaddr", V_LENGTH(0, 17) },
679 // advanced-routing
680 { "routes_static", V_LENGTH(0, 2048) },
681 { "dhcp_routes", V_01 },
682 { "lan_stp", V_RANGE(0, 1) },
683 { "wk_mode", V_LENGTH(1, 32) }, // gateway, router
684 #ifdef TCONFIG_ZEBRA
685 { "dr_setting", V_RANGE(0, 3) },
686 { "dr_lan_tx", V_LENGTH(0, 32) },
687 { "dr_lan_rx", V_LENGTH(0, 32) },
688 { "dr_wan_tx", V_LENGTH(0, 32) },
689 { "dr_wan_rx", V_LENGTH(0, 32) },
690 #endif
692 // advanced-wireless
693 { "wl_country", V_LENGTH(0, 64) }, // !!TB - Country code
694 { "wl_country_code", V_LENGTH(0, 4) }, // !!TB - Country code
695 { "wl_btc_mode", V_RANGE(0, 2) }, // !!TB - BT Coexistence Mode: 0 (disable), 1 (enable), 2 (preemption)
696 { "wl_afterburner", V_LENGTH(2, 4) }, // off, on, auto
697 { "wl_auth", V_01 },
698 { "wl_rateset", V_LENGTH(2, 7) }, // all, default, 12
699 { "wl_rate", V_RANGE(0, 54 * 1000 * 1000) },
700 { "wl_mrate", V_RANGE(0, 54 * 1000 * 1000) },
701 { "wl_gmode_protection",V_LENGTH(3, 4) }, // off, auto
702 { "wl_frameburst", V_ONOFF }, // off, on
703 { "wl_bcn", V_RANGE(1, 65535) },
704 { "wl_dtim", V_RANGE(1, 255) },
705 { "wl_frag", V_RANGE(256, 2346) },
706 { "wl_rts", V_RANGE(0, 2347) },
707 { "wl_ap_isolate", V_01 },
708 { "wl_plcphdr", V_LENGTH(4, 5) }, // long, short
709 { "wl_antdiv", V_RANGE(0, 3) },
710 { "wl_txant", V_RANGE(0, 3) },
711 { "wl_txpwr", V_RANGE(0, 400) },
712 { "wl_wme", V_WORD }, // auto, off, on
713 { "wl_wme_no_ack", V_ONOFF }, // off, on
714 { "wl_wme_apsd", V_ONOFF }, // off, on
715 { "wl_maxassoc", V_RANGE(0, 255) },
716 { "wl_distance", V_LENGTH(0, 5) }, // "", 1-99999
717 { "wlx_hpamp", V_01 },
718 { "wlx_hperx", V_01 },
719 { "wl_reg_mode", V_LENGTH(1, 3) }, // !!TB - Regulatory: off, h, d
720 { "wl_mitigation", V_RANGE(0, 3) }, // Interference Mitigation Mode (0|1|2|3)
722 { "wl_nmode_protection", V_WORD, }, // off, auto
723 { "wl_nmcsidx", V_RANGE(-2, 32), }, // -2 - 32
724 { "wl_obss_coex", V_01 },
726 // forward-dmz
727 { "dmz_enable", V_01 },
728 { "dmz_ipaddr", V_LENGTH(0, 15) },
729 { "dmz_sip", V_LENGTH(0, 512) },
731 // forward-upnp
732 { "upnp_enable", V_NUM },
733 { "upnp_secure", V_01 },
734 { "upnp_port", V_RANGE(0, 65535) },
735 { "upnp_ssdp_interval", V_RANGE(10, 9999) },
736 { "upnp_mnp", V_01 },
737 { "upnp_clean", V_01 },
738 { "upnp_clean_interval", V_RANGE(60, 65535) },
739 { "upnp_clean_threshold", V_RANGE(0, 9999) },
740 { "upnp_min_port_int", V_PORT },
741 { "upnp_max_port_int", V_PORT },
742 { "upnp_min_port_ext", V_PORT },
743 { "upnp_max_port_ext", V_PORT },
745 // forward-basic
746 { "portforward", V_LENGTH(0, 4096) },
748 #ifdef TCONFIG_IPV6
749 // forward-basic-ipv6
750 { "ipv6_portforward", V_LENGTH(0, 4096) },
751 #endif
753 // forward-triggered
754 { "trigforward", V_LENGTH(0, 4096) },
757 // access restriction
758 { "rruleN", V_RANGE(0, 99) },
759 // { "rrule##", V_LENGTH(0, 2048) }, // in save_variables()
761 // admin-access
762 { "http_enable", V_01 },
763 { "https_enable", V_01 },
764 { "https_crt_save", V_01 },
765 { "https_crt_cn", V_LENGTH(0, 64) },
766 { "https_crt_gen", V_TEMP },
767 { "remote_management", V_01 },
768 { "remote_mgt_https", V_01 },
769 { "http_lanport", V_PORT },
770 { "https_lanport", V_PORT },
771 { "web_wl_filter", V_01 },
772 { "web_css", V_LENGTH(1, 32) },
773 { "web_mx", V_LENGTH(0, 128) },
774 { "http_wanport", V_PORT },
775 { "telnetd_eas", V_01 },
776 { "telnetd_port", V_PORT },
777 { "sshd_eas", V_01 },
778 { "sshd_pass", V_01 },
779 { "sshd_port", V_PORT },
780 { "sshd_remote", V_01 },
781 { "sshd_forwarding", V_01 },
782 { "sshd_rport", V_PORT },
783 { "sshd_authkeys", V_TEXT(0, 4096) },
784 { "rmgt_sip", V_LENGTH(0, 512) },
785 { "ne_shlimit", V_TEXT(1, 50) },
787 // admin-bwm
788 { "rstats_enable", V_01 },
789 { "rstats_path", V_LENGTH(0, 48) },
790 { "rstats_stime", V_RANGE(1, 168) },
791 { "rstats_offset", V_RANGE(1, 31) },
792 { "rstats_exclude", V_LENGTH(0, 64) },
793 { "rstats_sshut", V_01 },
794 { "rstats_bak", V_01 },
796 // admin-buttons
797 { "sesx_led", V_RANGE(0, 255) }, // amber, white, aoss
798 { "sesx_b0", V_RANGE(0, 5) }, // 0-5: toggle wireless, reboot, shutdown, script, usb unmount
799 { "sesx_b1", V_RANGE(0, 5) }, // "
800 { "sesx_b2", V_RANGE(0, 5) }, // "
801 { "sesx_b3", V_RANGE(0, 5) }, // "
802 { "sesx_script", V_TEXT(0, 1024) }, //
803 { "script_brau", V_TEXT(0, 1024) }, //
805 // admin-debug
806 { "debug_nocommit", V_01 },
807 { "debug_cprintf", V_01 },
808 { "debug_cprintf_file", V_01 },
809 // { "debug_keepfiles", V_01 },
810 { "debug_ddns", V_01 },
811 { "debug_norestart", V_TEXT(0, 128) },
812 { "console_loglevel", V_RANGE(1, 8) },
813 { "t_cafree", V_01 },
814 { "t_hidelr", V_01 },
816 // admin-sched
817 { "sch_rboot", V_TEXT(0, 64) },
818 { "sch_rcon", V_TEXT(0, 64) },
819 { "sch_c1", V_TEXT(0, 64) },
820 { "sch_c1_cmd", V_TEXT(0, 2048) },
821 { "sch_c2", V_TEXT(0, 64) },
822 { "sch_c2_cmd", V_TEXT(0, 2048) },
823 { "sch_c3", V_TEXT(0, 64) },
824 { "sch_c3_cmd", V_TEXT(0, 2048) },
826 // admin-scripts
827 { "script_init", V_TEXT(0, 4096) },
828 { "script_shut", V_TEXT(0, 4096) },
829 { "script_fire", V_TEXT(0, 8192) },
830 { "script_wanup", V_TEXT(0, 4096) },
832 // admin-log
833 { "log_remote", V_01 },
834 { "log_remoteip", V_LENGTH(0, 512) },
835 { "log_remoteport", V_PORT },
836 { "log_file", V_01 },
837 { "log_file_custom", V_01 },
838 { "log_file_path", V_TEXT(0, 4096) },
839 { "log_limit", V_RANGE(0, 2400) },
840 { "log_in", V_RANGE(0, 3) },
841 { "log_out", V_RANGE(0, 3) },
842 { "log_mark", V_RANGE(0, 99999) },
843 { "log_events", V_TEXT(0, 32) }, // "acre,crond,ntp"
845 // admin-log-webmonitor
846 { "log_wm", V_01 },
847 { "log_wmtype", V_RANGE(0, 2) },
848 { "log_wmip", V_LENGTH(0, 512) },
849 { "log_wmdmax", V_RANGE(0, 9999) },
850 { "log_wmsmax", V_RANGE(0, 9999) },
852 // admin-cifs
853 { "cifs1", V_LENGTH(1, 1024) },
854 { "cifs2", V_LENGTH(1, 1024) },
856 // admin-jffs2
857 { "jffs2_on", V_01 },
858 { "jffs2_exec", V_LENGTH(0, 64) },
859 { "jffs2_format", V_01 },
861 // nas-usb - !!TB
862 #ifdef TCONFIG_USB
863 { "usb_enable", V_01 },
864 { "usb_uhci", V_RANGE(-1, 1) }, // -1 - disabled, 0 - off, 1 - on
865 { "usb_ohci", V_RANGE(-1, 1) },
866 { "usb_usb2", V_RANGE(-1, 1) },
867 { "usb_irq_thresh", V_RANGE(0, 6) },
868 { "usb_storage", V_01 },
869 { "usb_printer", V_01 },
870 { "usb_printer_bidirect", V_01 },
871 { "usb_fs_ext3", V_01 },
872 { "usb_fs_fat", V_01 },
873 #ifdef TCONFIG_NTFS
874 { "usb_fs_ntfs", V_01 },
875 #endif
876 { "usb_automount", V_01 },
877 { "script_usbhotplug", V_TEXT(0, 2048) },
878 { "script_usbmount", V_TEXT(0, 2048) },
879 { "script_usbumount", V_TEXT(0, 2048) },
880 #endif
882 // nas-ftp - !!TB
883 #ifdef TCONFIG_FTP
884 { "ftp_enable", V_RANGE(0, 2) },
885 { "ftp_super", V_01 },
886 { "ftp_anonymous", V_RANGE(0, 3) },
887 { "ftp_dirlist", V_RANGE(0, 2) },
888 { "ftp_port", V_PORT },
889 { "ftp_max", V_RANGE(0, 12) },
890 { "ftp_ipmax", V_RANGE(0, 12) },
891 { "ftp_staytimeout", V_RANGE(0, 65535) },
892 { "ftp_rate", V_RANGE(0, 99999) },
893 { "ftp_anonrate", V_RANGE(0, 99999) },
894 { "ftp_anonroot", V_LENGTH(0, 256) },
895 { "ftp_pubroot", V_LENGTH(0, 256) },
896 { "ftp_pvtroot", V_LENGTH(0, 256) },
897 { "ftp_users", V_LENGTH(0, 4096) },
898 { "ftp_custom", V_TEXT(0, 2048) },
899 { "ftp_sip", V_LENGTH(0, 512) },
900 { "ftp_limit", V_TEXT(1, 50) },
901 { "log_ftp", V_01 },
902 #endif
904 #ifdef TCONFIG_SAMBASRV
905 // nas-samba - !!TB
906 { "smbd_enable", V_RANGE(0, 2) },
907 { "smbd_wgroup", V_LENGTH(0, 20) },
908 { "smbd_master", V_01 },
909 { "smbd_wins", V_01 },
910 { "smbd_cpage", V_LENGTH(0, 4) },
911 { "smbd_cset", V_LENGTH(0, 20) },
912 { "smbd_custom", V_TEXT(0, 2048) },
913 { "smbd_autoshare", V_RANGE(0, 3) },
914 { "smbd_shares", V_LENGTH(0, 4096) },
915 { "smbd_user", V_LENGTH(0, 50) },
916 { "smbd_passwd", V_LENGTH(0, 50) },
917 #endif
919 #ifdef TCONFIG_MEDIA_SERVER
920 // nas-media
921 { "ms_enable", V_01 },
922 { "ms_dirs", V_LENGTH(0, 1024) },
923 { "ms_port", V_RANGE(0, 65535) },
924 { "ms_dbdir", V_LENGTH(0, 256) },
925 { "ms_tivo", V_01 },
926 { "ms_stdlna", V_01 },
927 { "ms_rescan", V_01 },
928 { "ms_sas", V_01 },
929 #endif
931 // qos
932 { "qos_enable", V_01 },
933 { "qos_ack", V_01 },
934 { "qos_syn", V_01 },
935 { "qos_fin", V_01 },
936 { "qos_rst", V_01 },
937 { "qos_icmp", V_01 },
938 { "qos_reset", V_01 },
939 { "qos_pfifo", V_01 }, // !!TB
940 { "qos_obw", V_RANGE(10, 999999) },
941 { "qos_ibw", V_RANGE(10, 999999) },
942 { "qos_orules", V_LENGTH(0, 4096) },
943 { "qos_default", V_RANGE(0, 9) },
944 { "qos_irates", V_LENGTH(0, 128) },
945 { "qos_orates", V_LENGTH(0, 128) },
947 { "ne_vegas", V_01 },
948 { "ne_valpha", V_NUM },
949 { "ne_vbeta", V_NUM },
950 { "ne_vgamma", V_NUM },
952 // new_qoslimit
953 { "new_qoslimit_enable", V_01 },
954 { "new_qoslimit_rules", V_LENGTH(0, 4096) },
955 { "qosl_enable", V_01 },
956 { "qosl_ulr", V_RANGE(0, 999999) },
957 { "qosl_ulc", V_RANGE(0, 999999) },
958 { "qosl_dlr", V_RANGE(0, 999999) },
959 { "qosl_dlc", V_RANGE(0, 999999) },
960 { "qosl_tcp", V_RANGE(0, 1000) },
961 { "qosl_udp", V_RANGE(0, 100) },
964 // new_arpbind - static-arp
965 { "new_arpbind_enable", V_01 },
966 { "new_arpbind_only", V_01 },
968 #ifdef TCONFIG_BT
969 // nas-transmission
970 { "bt_enable", V_01 },
971 { "bt_binary", V_LENGTH(0, 50) },
972 { "bt_binary_custom", V_LENGTH(0, 50) },
973 { "bt_custom", V_TEXT(0, 2048) },
974 { "bt_port", V_PORT },
975 { "bt_dir", V_LENGTH(0, 50) },
976 { "bt_settings", V_LENGTH(0, 50) },
977 { "bt_settings_custom", V_LENGTH(0, 50) },
978 { "bt_incomplete", V_01 },
979 { "bt_rpc_enable", V_01 },
980 { "bt_rpc_wan", V_01 },
981 { "bt_auth", V_01 },
982 { "bt_login", V_LENGTH(0, 50) },
983 { "bt_password", V_LENGTH(0, 50) },
984 { "bt_port_gui", V_PORT },
985 { "bt_dl_enable", V_01 },
986 { "bt_ul_enable", V_01 },
987 { "bt_dl", V_RANGE(1, 999999) },
988 { "bt_ul", V_RANGE(1, 999999) },
989 { "bt_peer_limit_global", V_RANGE(10, 500) },
990 { "bt_peer_limit_per_torrent", V_RANGE(10, 100) },
991 { "bt_ul_slot_per_torrent", V_RANGE(5, 50) },
992 { "bt_ratio_enable", V_01 },
993 { "bt_ratio", V_LENGTH(0, 999999) },
994 { "bt_dht", V_01 },
995 { "bt_pex", V_01 },
996 { "bt_blocklist", V_01 },
997 { "bt_blocklist_url", V_LENGTH(0, 80) },
998 { "bt_sleep", V_RANGE(1,60) },
999 { "bt_check", V_01 },
1000 { "bt_queue", V_01 },
1001 { "bt_maxdown", V_RANGE(1,10) },
1002 { "bt_maxactive", V_RANGE(1,20) },
1003 #endif
1005 #ifdef TCONFIG_NFS
1006 { "nfs_enable", V_01 },
1007 { "nfs_exports", V_LENGTH(0, 4096) },
1008 #endif
1010 //NotCatSplash. Victek.
1011 #ifdef TCONFIG_NOCAT
1012 { "NC_enable", V_01 },
1013 { "NC_Verbosity", V_RANGE(0, 10) },
1014 { "NC_GatewayName", V_LENGTH(0, 255) },
1015 { "NC_GatewayPort", V_PORT },
1016 { "NC_ForcedRedirect", V_01 },
1017 { "NC_HomePage", V_LENGTH(0, 255) },
1018 { "NC_DocumentRoot", V_LENGTH(0, 255) },
1019 { "NC_SplashURL", V_LENGTH(0, 255) },
1020 { "NC_LoginTimeout", V_RANGE(0, 86400000) },
1021 { "NC_IdleTimeout", V_RANGE(0, 86400000) },
1022 { "NC_MaxMissedARP", V_RANGE(0, 10) },
1023 { "NC_PeerChecktimeout", V_RANGE(0, 60) },
1024 { "NC_ExcludePorts", V_LENGTH(0, 255) },
1025 { "NC_IncludePorts", V_LENGTH(0, 255) },
1026 { "NC_AllowedWebHosts", V_LENGTH(0, 255) },
1027 { "NC_MACWhiteList", V_LENGTH(0, 255) },
1028 { "NC_SplashFile", V_LENGTH(0, 8192) },
1029 #endif
1031 #ifdef TCONFIG_OPENVPN
1032 // vpn
1033 { "vpn_debug", V_01 },
1034 { "vpn_server_eas", V_NONE },
1035 { "vpn_server_dns", V_NONE },
1036 { "vpn_server1_poll", V_RANGE(0, 1440) },
1037 { "vpn_server1_if", V_TEXT(3, 3) }, // tap, tun
1038 { "vpn_server1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1039 { "vpn_server1_port", V_PORT },
1040 { "vpn_server1_firewall", V_TEXT(0, 8) }, // auto, external, custom
1041 { "vpn_server1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1042 { "vpn_server1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1043 { "vpn_server1_cipher", V_TEXT(0, 16) },
1044 { "vpn_server1_dhcp", V_01 },
1045 { "vpn_server1_r1", V_IP },
1046 { "vpn_server1_r2", V_IP },
1047 { "vpn_server1_sn", V_IP },
1048 { "vpn_server1_nm", V_IP },
1049 { "vpn_server1_local", V_IP },
1050 { "vpn_server1_remote", V_IP },
1051 { "vpn_server1_reneg", V_RANGE(-1,2147483647)},
1052 { "vpn_server1_hmac", V_RANGE(-1, 2) },
1053 { "vpn_server1_plan", V_01 },
1054 { "vpn_server1_ccd", V_01 },
1055 { "vpn_server1_c2c", V_01 },
1056 { "vpn_server1_ccd_excl", V_01 },
1057 { "vpn_server1_ccd_val", V_NONE },
1058 { "vpn_server1_pdns", V_01 },
1059 { "vpn_server1_rgw", V_01 },
1060 { "vpn_server1_custom", V_NONE },
1061 { "vpn_server1_static", V_NONE },
1062 { "vpn_server1_ca", V_NONE },
1063 { "vpn_server1_crt", V_NONE },
1064 { "vpn_server1_key", V_NONE },
1065 { "vpn_server1_dh", V_NONE },
1066 { "vpn_server2_poll", V_RANGE(0, 1440) },
1067 { "vpn_server2_if", V_TEXT(3, 3) }, // tap, tun
1068 { "vpn_server2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1069 { "vpn_server2_port", V_PORT },
1070 { "vpn_server2_firewall", V_TEXT(0, 8) }, // auto, external, custom
1071 { "vpn_server2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1072 { "vpn_server2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1073 { "vpn_server2_cipher", V_TEXT(0, 16) },
1074 { "vpn_server2_dhcp", V_01 },
1075 { "vpn_server2_r1", V_IP },
1076 { "vpn_server2_r2", V_IP },
1077 { "vpn_server2_sn", V_IP },
1078 { "vpn_server2_nm", V_IP },
1079 { "vpn_server2_local", V_IP },
1080 { "vpn_server2_remote", V_IP },
1081 { "vpn_server2_reneg", V_RANGE(-1,2147483647)},
1082 { "vpn_server2_hmac", V_RANGE(-1, 2) },
1083 { "vpn_server2_plan", V_01 },
1084 { "vpn_server2_pdns", V_01 },
1085 { "vpn_server2_rgw", V_01 },
1086 { "vpn_server2_custom", V_NONE },
1087 { "vpn_server2_ccd", V_01 },
1088 { "vpn_server2_c2c", V_01 },
1089 { "vpn_server2_ccd_excl", V_01 },
1090 { "vpn_server2_ccd_val", V_NONE },
1091 { "vpn_server2_static", V_NONE },
1092 { "vpn_server2_ca", V_NONE },
1093 { "vpn_server2_crt", V_NONE },
1094 { "vpn_server2_key", V_NONE },
1095 { "vpn_server2_dh", V_NONE },
1096 { "vpn_client_eas", V_NONE },
1097 { "vpn_client1_poll", V_RANGE(0, 1440) },
1098 { "vpn_client1_if", V_TEXT(3, 3) }, // tap, tun
1099 { "vpn_client1_bridge", V_01 },
1100 { "vpn_client1_nat", V_01 },
1101 { "vpn_client1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1102 { "vpn_client1_addr", V_NONE },
1103 { "vpn_client1_port", V_PORT },
1104 { "vpn_client1_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1105 { "vpn_client1_firewall", V_TEXT(0, 6) }, // auto, custom
1106 { "vpn_client1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1107 { "vpn_client1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1108 { "vpn_client1_cipher", V_TEXT(0, 16) },
1109 { "vpn_client1_local", V_IP },
1110 { "vpn_client1_remote", V_IP },
1111 { "vpn_client1_nm", V_IP },
1112 { "vpn_client1_reneg", V_RANGE(-1,2147483647)},
1113 { "vpn_client1_hmac", V_RANGE(-1, 2) },
1114 { "vpn_client1_adns", V_RANGE(0, 3) },
1115 { "vpn_client1_rgw", V_01 },
1116 { "vpn_client1_gw", V_TEXT(0, 15) },
1117 { "vpn_client1_custom", V_NONE },
1118 { "vpn_client1_static", V_NONE },
1119 { "vpn_client1_ca", V_NONE },
1120 { "vpn_client1_crt", V_NONE },
1121 { "vpn_client1_key", V_NONE },
1122 { "vpn_client2_poll", V_RANGE(0, 1440) },
1123 { "vpn_client2_if", V_TEXT(3, 3) }, // tap, tun
1124 { "vpn_client2_bridge", V_01 },
1125 { "vpn_client2_nat", V_01 },
1126 { "vpn_client2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1127 { "vpn_client2_addr", V_NONE },
1128 { "vpn_client2_port", V_PORT },
1129 { "vpn_client2_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1130 { "vpn_client2_firewall", V_TEXT(0, 6) }, // auto, custom
1131 { "vpn_client2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1132 { "vpn_client2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1133 { "vpn_client2_cipher", V_TEXT(0, 16) },
1134 { "vpn_client2_local", V_IP },
1135 { "vpn_client2_remote", V_IP },
1136 { "vpn_client2_nm", V_IP },
1137 { "vpn_client2_reneg", V_RANGE(-1,2147483647)},
1138 { "vpn_client2_hmac", V_RANGE(-1, 2) },
1139 { "vpn_client2_adns", V_RANGE(0, 3) },
1140 { "vpn_client2_rgw", V_01 },
1141 { "vpn_client2_gw", V_TEXT(0, 15) },
1142 { "vpn_client2_custom", V_NONE },
1143 { "vpn_client2_static", V_NONE },
1144 { "vpn_client2_ca", V_NONE },
1145 { "vpn_client2_crt", V_NONE },
1146 { "vpn_client2_key", V_NONE },
1147 #endif // vpn
1150 ppp_static 0/1
1151 ppp_static_ip IP
1152 wl_enable 0/1
1153 wl_wds_timeout
1154 wl_maxassoc 1-256
1155 wl_phytype a,b,g
1156 wl_net_reauth
1157 wl_preauth
1158 wl_wme_ap_bk
1159 wl_wme_ap_be
1160 wl_wme_ap_vi
1161 wl_wme_ap_vo
1162 wl_wme_sta_bk
1163 wl_wme_sta_be
1164 wl_wme_sta_vi
1165 wl_wme_sta_vo
1167 port_priority_1 0-2
1168 port_flow_control_1 0,1
1169 port_rate_limit_1 0-8
1170 port_priority_2 0-2
1171 port_flow_control_2 0,1
1172 port_rate_limit_2 0-8
1173 port_priority_3 0-2
1174 port_flow_control_3 0,1
1175 port_rate_limit_3 0-8
1176 port_priority_4 0-2
1177 port_flow_control_4 0,1
1178 port_rate_limit_4 0-8
1179 wl_ap_ip
1180 wl_ap_ssid
1183 { NULL }
1187 static int webcgi_nvram_set(const nvset_t *v, const char *name, int write)
1189 char *p, *e;
1190 int n;
1191 long l;
1192 unsigned u[6];
1193 int ok;
1194 int dirty;
1195 #ifdef TCONFIG_IPV6
1196 struct in6_addr addr;
1197 #endif
1199 if ((p = webcgi_get((char*)name)) == NULL) return 0;
1201 _dprintf("[%s] %s=%s\n", v->name, (char*)name, p);
1202 dirty = 0;
1203 ok = 1;
1204 switch (v->vtype) {
1205 case VT_TEXT:
1206 p = unix_string(p); // NOTE: p = malloc'd
1207 // drop
1208 case VT_LENGTH:
1209 n = strlen(p);
1210 if ((n < v->va.i) || (n > v->vb.i)) ok = 0;
1211 break;
1212 case VT_RANGE:
1213 l = strtol(p, &e, 10);
1214 if ((p == e) || (*e) || (l < v->va.l) || (l > v->vb.l)) ok = 0;
1215 break;
1216 case VT_IP:
1217 if ((sscanf(p, "%3u.%3u.%3u.%3u", &u[0], &u[1], &u[2], &u[3]) != 4) ||
1218 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255)) ok = 0;
1219 break;
1220 case VT_MAC:
1221 if ((sscanf(p, "%2x:%2x:%2x:%2x:%2x:%2x", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]) != 6) ||
1222 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255) || (u[4] > 255) || (u[5] > 255)) ok = 0;
1223 break;
1224 #ifdef TCONFIG_IPV6
1225 case VT_IPV6:
1226 if (strlen(p) > 0 || v->va.i) {
1227 if (inet_pton(AF_INET6, p, &addr) != 1) ok = 0;
1229 break;
1230 #endif
1231 default:
1232 // shutup gcc
1233 break;
1235 if (!ok) {
1236 if (v->vtype == VT_TEXT) free(p);
1237 return -1;
1239 if (write) {
1240 if (!nvram_match((char *)name, p)) {
1241 if (v->vtype != VT_TEMP) dirty = 1;
1242 DEBUG_NVRAMSET(name, p);
1243 nvram_set(name, p);
1246 if (v->vtype == VT_TEXT) free(p);
1248 return dirty;
1251 typedef struct {
1252 const nvset_t *v;
1253 int write;
1254 int dirty;
1255 } nv_list_t;
1257 static int nv_wl_find(int idx, int unit, int subunit, void *param)
1259 nv_list_t *p = param;
1261 int ok = webcgi_nvram_set(p->v, wl_nvname(p->v->name + 3, unit, subunit), p->write);
1262 if (ok < 0)
1263 return 1;
1264 else {
1265 p->dirty |= ok;
1266 return 0;
1270 static int save_variables(int write)
1272 const nvset_t *v;
1273 char *p;
1274 int n;
1275 int ok;
1276 char s[256];
1277 int dirty;
1278 static const char *msgf = "The field \"%s\" is invalid. Please report this problem.";
1279 nv_list_t nv;
1281 dirty = 0;
1282 nv.write = write;
1283 for (v = nvset_list; v->name; ++v) {
1284 ok = webcgi_nvram_set(v, v->name, write);
1286 if ((ok >= 0) && (strncmp(v->name, "wl_", 3) == 0)) {
1287 nv.dirty = dirty;
1288 nv.v = v;
1289 if (foreach_wif(1, &nv, nv_wl_find) == 0)
1290 ok |= nv.dirty;
1291 else
1292 ok = -1;
1295 if (ok < 0) {
1296 sprintf(s, msgf, v->name);
1297 resmsg_set(s);
1298 return 0;
1300 dirty |= ok;
1303 // special cases
1305 char *p1, *p2;
1306 if (((p1 = webcgi_get("set_password_1")) != NULL) && (strcmp(p1, "**********") != 0)) {
1307 if (((p2 = webcgi_get("set_password_2")) != NULL) && (strcmp(p1, p2) == 0)) {
1308 if ((write) && (!nvram_match("http_passwd", p1))) {
1309 dirty = 1;
1310 nvram_set("http_passwd", p1);
1313 else {
1314 sprintf(s, msgf, "password");
1315 resmsg_set(s);
1316 return 0;
1320 for (n = 0; n < 50; ++n) {
1321 sprintf(s, "rrule%d", n);
1322 if ((p = webcgi_get(s)) != NULL) {
1323 if (strlen(p) > 2048) {
1324 sprintf(s, msgf, s);
1325 resmsg_set(s);
1326 return 0;
1328 if ((write) && (!nvram_match(s, p))) {
1329 dirty = 1;
1330 DEBUG_NVRAMSET(s, p);
1331 nvram_set(s, p);
1336 return (write) ? dirty : 1;
1339 static void wo_tomato(char *url)
1341 char *v;
1342 int i;
1343 int ajax;
1344 int nvset;
1345 const char *red;
1346 int commit;
1348 // _dprintf("tomato.cgi\n");
1350 red = webcgi_safeget("_redirect", "");
1351 if (!*red) send_header(200, NULL, mime_html, 0);
1353 commit = atoi(webcgi_safeget("_commit", "1"));
1354 ajax = atoi(webcgi_safeget("_ajax", "0"));
1356 nvset = atoi(webcgi_safeget("_nvset", "1"));
1357 if (nvset) {
1358 if (!save_variables(0)) {
1359 if (ajax) {
1360 web_printf("@msg:%s", resmsg_get());
1362 else {
1363 parse_asp("error.asp");
1365 return;
1367 commit = save_variables(1) && commit;
1369 resmsg_set("Settings saved.");
1372 rboot = atoi(webcgi_safeget("_reboot", "0"));
1373 if (rboot) {
1374 parse_asp("reboot.asp");
1376 else {
1377 if (ajax) {
1378 web_printf("@msg:%s", resmsg_get());
1380 else if (atoi(webcgi_safeget("_moveip", "0"))) {
1381 parse_asp("saved-moved.asp");
1383 else if (!*red) {
1384 parse_asp("saved.asp");
1388 if (commit) {
1389 _dprintf("commit from tomato.cgi\n");
1390 nvram_commit_x();
1393 if ((v = webcgi_get("_service")) != NULL && *v != 0) {
1394 if (!*red) {
1395 if (ajax) web_printf(" Some services are being restarted...");
1396 web_close();
1398 sleep(1);
1400 if (*v == '*') {
1401 kill(1, SIGHUP);
1403 else {
1404 exec_service(v);
1408 for (i = atoi(webcgi_safeget("_sleep", "0")); i > 0; --i) sleep(1);
1410 if (*red) redirect(red);
1412 if (rboot) {
1413 web_close();
1414 sleep(1);
1415 kill(1, SIGTERM);
1420 // ----------------------------------------------------------------------------
1423 static void wo_update(char *url)
1425 const aspapi_t *api;
1426 const char *name;
1427 int argc;
1428 char *argv[16];
1429 char s[32];
1431 if ((name = webcgi_get("exec")) != NULL) {
1432 for (api = aspapi; api->name; ++api) {
1433 if (strcmp(api->name, name) == 0) {
1434 for (argc = 0; argc < 16; ++argc) {
1435 sprintf(s, "arg%d", argc);
1436 if ((argv[argc] = (char *)webcgi_get(s)) == NULL) break;
1438 api->exec(argc, argv);
1439 break;
1445 static void wo_service(char *url)
1447 int n;
1449 exec_service(webcgi_safeget("_service", ""));
1451 if ((n = atoi(webcgi_safeget("_sleep", "2"))) <= 0) n = 2;
1452 sleep(n);
1454 common_redirect();
1457 static void wo_shutdown(char *url)
1459 parse_asp("shutdown.asp");
1460 web_close();
1461 sleep(1);
1463 kill(1, SIGQUIT);
1466 static void wo_nvcommit(char *url)
1468 parse_asp("saved.asp");
1469 web_close();
1470 nvram_commit();