Routing is now multi-LAN aware (static routes and Zebra/RIP, if enabled)
[tomato.git] / release / src / router / httpd / tomato.c
blobec2c618549a027b06be7c64f4eb606f38e48435e
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 }, // see httpd.c
330 { "shutdown.cgi", mime_html, 0, wi_generic, wo_shutdown, 1 },
331 #ifdef TCONFIG_OPENVPN
332 { "vpnstatus.cgi", mime_javascript, 0, wi_generic, wo_vpn_status, 1 },
333 #endif
334 #ifdef TCONFIG_USB
335 { "usbcmd.cgi", mime_javascript, 0, wi_generic, wo_usbcommand, 1 }, //!!TB - USB
336 #endif
337 #ifdef BLACKHOLE
338 { "blackhole.cgi", NULL, 0, wi_blackhole, NULL, 1 },
339 #endif
340 // { "test", mime_html, 0, wi_generic, wo_test, 1 },
341 { NULL, NULL, 0, NULL, NULL, 1 }
344 const aspapi_t aspapi[] = {
345 { "activeroutes", asp_activeroutes },
346 { "arplist", asp_arplist },
347 { "bandwidth", asp_bandwidth },
348 { "build_time", asp_build_time },
349 { "cgi_get", asp_cgi_get },
350 { "compmac", asp_compmac },
351 { "ctcount", asp_ctcount },
352 { "ctdump", asp_ctdump },
353 { "ctrate", asp_ctrate },
354 { "ddnsx", asp_ddnsx },
355 { "devlist", asp_devlist },
356 { "webmon", asp_webmon },
357 { "dhcpc_time", asp_dhcpc_time },
358 { "dns", asp_dns },
359 { "ident", asp_ident },
360 { "lanip", asp_lanip },
361 { "layer7", asp_layer7 },
362 { "link_uptime", asp_link_uptime },
363 { "lipp", asp_lipp },
364 { "netdev", asp_netdev },
365 { "notice", asp_notice },
366 { "nv", asp_nv },
367 { "nvram", asp_nvram },
368 { "nvramseq", asp_nvramseq },
369 { "nvstat", asp_nvstat },
370 { "psup", asp_psup },
371 { "qrate", asp_qrate },
372 { "resmsg", asp_resmsg },
373 { "rrule", asp_rrule },
374 { "statfs", asp_statfs },
375 { "sysinfo", asp_sysinfo },
376 { "time", asp_time },
377 { "upnpinfo", asp_upnpinfo },
378 { "version", asp_version },
379 { "wanstatus", asp_wanstatus },
380 { "wanup", asp_wanup },
381 { "wlstats", asp_wlstats },
382 { "wlclient", asp_wlclient },
383 { "wlnoise", asp_wlnoise },
384 { "wlscan", asp_wlscan },
385 { "wlchannels", asp_wlchannels }, //!!TB
386 { "wlcountries", asp_wlcountries },
387 { "wlifaces", asp_wlifaces },
388 { "wlbands", asp_wlbands },
389 #ifdef TCONFIG_USB
390 { "usbdevices", asp_usbdevices }, //!!TB - USB Support
391 #endif
392 { "css", asp_css },
393 { NULL, NULL }
396 // -----------------------------------------------------------------------------
398 static void asp_css(int argc, char **argv)
400 const char *css = nvram_safe_get("web_css");
402 if (strcmp(css, "tomato") != 0) {
403 web_printf("<link rel='stylesheet' type='text/css' href='%s.css'>", css);
407 // -----------------------------------------------------------------------------
409 const char *resmsg_get(void)
411 return webcgi_safeget("resmsg", "");
414 void resmsg_set(const char *msg)
416 webcgi_set("resmsg", strdup(msg)); // m ok
419 int resmsg_fread(const char *fname)
421 char s[256];
422 char *p;
424 f_read_string(fname, s, sizeof(s));
425 if ((p = strchr(s, '\n')) != NULL) *p = 0;
426 if (s[0]) {
427 resmsg_set(s);
428 return 1;
430 return 0;
433 static void asp_resmsg(int argc, char **argv)
435 char *p;
437 if ((p = js_string(webcgi_safeget("resmsg", (argc > 0) ? argv[0] : ""))) == NULL) return;
438 web_printf("\nresmsg='%s';\n", p);
439 free(p);
442 // ----------------------------------------------------------------------------
444 // verification... simple sanity checks. UI should verify all fields.
446 // todo: move and re-use for filtering - zzz
448 typedef union {
449 int i;
450 long l;
451 const char *s;
452 } nvset_varg_t;
454 typedef struct {
455 const char *name;
456 enum {
457 VT_NONE, // no checking
458 VT_LENGTH, // check length of string
459 VT_TEXT, // strip \r, check length of string
460 VT_RANGE, // expect an integer, check range
461 VT_IP, // expect an ip address
462 VT_MAC, // expect a mac address
463 #ifdef TCONFIG_IPV6
464 VT_IPV6, // expect an ipv6 address
465 #endif
466 VT_TEMP // no checks, no commit
467 } vtype;
468 nvset_varg_t va;
469 nvset_varg_t vb;
470 } nvset_t;
473 #define V_NONE VT_NONE, { }, { }
474 #define V_01 VT_RANGE, { .l = 0 }, { .l = 1 }
475 #define V_PORT VT_RANGE, { .l = 2 }, { .l = 65535 }
476 #define V_ONOFF VT_LENGTH, { .i = 2 }, { .i = 3 }
477 #define V_WORD VT_LENGTH, { .i = 1 }, { .i = 16 }
478 #define V_LENGTH(min, max) VT_LENGTH, { .i = min }, { .i = max }
479 #define V_TEXT(min, max) VT_TEXT, { .i = min }, { .i = max }
480 #define V_RANGE(min, max) VT_RANGE, { .l = min }, { .l = max }
481 #define V_IP VT_IP, { }, { }
482 #define V_OCTET VT_RANGE, { .l = 0 }, { .l = 255 }
483 #define V_NUM VT_RANGE, { .l = 0 }, { .l = 0x7FFFFFFF }
484 #define V_TEMP VT_TEMP, { }, { }
485 #ifdef TCONFIG_IPV6
486 #define V_IPV6 VT_IPV6, { }, { }
487 #endif
489 static const nvset_t nvset_list[] = {
491 // basic-ident
492 { "router_name", V_LENGTH(0, 32) },
493 { "wan_hostname", V_LENGTH(0, 32) },
494 { "wan_domain", V_LENGTH(0, 32) },
496 // basic-time
497 { "tm_tz", V_LENGTH(1, 64) }, // PST8PDT
498 { "tm_sel", V_LENGTH(1, 64) }, // PST8PDT
499 { "tm_dst", V_01 },
500 { "ntp_updates", V_RANGE(-1, 24) },
501 { "ntp_tdod", V_01 },
502 { "ntp_server", V_LENGTH(1, 150) }, // x y z
503 { "ntp_kiss", V_LENGTH(0, 255) },
505 // basic-static
506 { "dhcpd_static", V_LENGTH(0, 106*101)}, // 106 (max chars per entry) x 100 entries
508 // basic-ddns
509 { "ddnsx0", V_LENGTH(0, 2048) },
510 { "ddnsx1", V_LENGTH(0, 2048) },
511 { "ddnsx0_cache", V_LENGTH(0, 1) }, // only to clear
512 { "ddnsx1_cache", V_LENGTH(0, 1) },
513 { "ddnsx_ip", V_LENGTH(0, 32) },
514 { "ddnsx_save", V_01 },
515 { "ddnsx_refresh", V_RANGE(0, 365) },
517 // basic-network
518 // WAN
519 { "wan_proto", V_LENGTH(1, 16) }, // disabled, dhcp, static, pppoe, pptp, l2tp
520 { "wan_ipaddr", V_IP },
521 { "wan_netmask", V_IP },
522 { "wan_gateway", V_IP },
523 { "hb_server_ip", V_LENGTH(0, 32) },
524 { "l2tp_server_ip", V_LENGTH(0, 128) },
525 { "pptp_server_ip", V_LENGTH(0, 128) },
526 { "pptp_dhcp", V_01 },
527 { "ppp_defgw", V_01 },
528 { "ppp_username", V_LENGTH(0, 60) },
529 { "ppp_passwd", V_LENGTH(0, 60) },
530 { "ppp_service", V_LENGTH(0, 50) },
531 { "ppp_demand", V_01 },
532 { "ppp_custom", V_LENGTH(0, 256) },
533 { "ppp_idletime", V_RANGE(0, 1440) },
534 { "ppp_redialperiod", V_RANGE(1, 86400) },
535 { "mtu_enable", V_01 },
536 { "wan_mtu", V_RANGE(576, 1500) },
537 { "wan_islan", V_01 },
539 // LAN
540 { "lan_ipaddr", V_IP },
541 { "lan_netmask", V_IP },
542 { "lan_gateway", V_IP },
543 { "wan_dns", V_LENGTH(0, 50) }, // ip ip ip
544 { "lan_proto", V_WORD }, // static, dhcp
545 { "dhcp_start", V_LENGTH(0, 15) }, // remove !
546 { "dhcp_num", V_LENGTH(0, 4) }, // remove !
547 { "dhcpd_startip", V_LENGTH(0, 15) },
548 { "dhcpd_endip", V_LENGTH(0, 15) },
549 { "dhcp_lease", V_LENGTH(0, 5) },
550 { "wan_wins", V_IP },
552 // LAN networks
553 { "lan_ifname", V_LENGTH(0, 5) },
555 { "lan1_ifname", V_LENGTH(0, 5) },
556 { "lan1_ifnames", V_TEXT(0,64) },
557 { "lan1_ipaddr", V_LENGTH(0, 15) },
558 { "lan1_netmask", V_LENGTH(0, 15) },
559 { "lan1_proto", V_LENGTH(0, 6) },
560 { "lan1_stp", V_LENGTH(0, 1) },
561 { "dhcp1_start", V_LENGTH(0, 15) },
562 { "dhcp1_num", V_LENGTH(0, 4) },
563 { "dhcpd1_startip", V_LENGTH(0, 15) },
564 { "dhcpd1_endip", V_LENGTH(0, 15) },
565 { "dhcp1_lease", V_LENGTH(0, 5) },
567 { "lan2_ifname", V_LENGTH(0, 5) },
568 { "lan2_ifnames", V_TEXT(0,64) },
569 { "lan2_ipaddr", V_LENGTH(0, 15) },
570 { "lan2_netmask", V_LENGTH(0, 15) },
571 { "lan2_proto", V_LENGTH(0, 6) },
572 { "lan2_stp", V_LENGTH(0, 1) },
573 { "dhcp2_start", V_LENGTH(0, 15) },
574 { "dhcp2_num", V_LENGTH(0, 4) },
575 { "dhcpd2_startip", V_LENGTH(0, 15) },
576 { "dhcpd2_endip", V_LENGTH(0, 15) },
577 { "dhcp2_lease", V_LENGTH(0, 5) },
579 { "lan3_ifname", V_LENGTH(0, 5) },
580 { "lan3_ifnames", V_TEXT(0,64) },
581 { "lan3_ipaddr", V_LENGTH(0, 15) },
582 { "lan3_netmask", V_LENGTH(0, 15) },
583 { "lan3_proto", V_LENGTH(0, 6) },
584 { "lan3_stp", V_LENGTH(0, 1) },
585 { "dhcp3_start", V_LENGTH(0, 15) },
586 { "dhcp3_num", V_LENGTH(0, 4) },
587 { "dhcpd3_startip", V_LENGTH(0, 15) },
588 { "dhcpd3_endip", V_LENGTH(0, 15) },
589 { "dhcp3_lease", V_LENGTH(0, 5) },
591 // wireless
592 { "wl_radio", V_01 },
593 { "wl_mode", V_LENGTH(2, 3) }, // ap, sta, wet, wds
594 { "wl_net_mode", V_LENGTH(5, 8) }, // disabled, mixed, b-only, g-only, bg-mixed, n-only [speedbooster]
595 { "wl_ssid", V_LENGTH(1, 32) },
596 { "wl_closed", V_01 },
597 { "wl_channel", V_RANGE(0, 216) },
599 { "wl_security_mode", V_LENGTH(1, 32) }, // disabled, radius, wep, wpa_personal, wpa_enterprise, wpa2_personal, wpa2_enterprise
600 { "wl_radius_ipaddr", V_IP },
601 { "wl_radius_port", V_PORT },
602 { "wl_radius_key", V_LENGTH(1, 64) },
603 { "wl_wep_bit", V_RANGE(64, 128) }, // 64 or 128
604 { "wl_passphrase", V_LENGTH(0, 20) },
605 { "wl_key", V_RANGE(1, 4) },
606 { "wl_key1", V_LENGTH(0, 26) },
607 { "wl_key2", V_LENGTH(0, 26) },
608 { "wl_key3", V_LENGTH(0, 26) },
609 { "wl_key4", V_LENGTH(0, 26) },
610 { "wl_crypto", V_LENGTH(3, 8) }, // tkip, aes, tkip+aes
611 { "wl_wpa_psk", V_LENGTH(8, 64) },
612 { "wl_wpa_gtk_rekey", V_RANGE(60, 7200) },
614 { "wl_lazywds", V_01 },
615 { "wl_wds", V_LENGTH(0, 180) }, // mac mac mac (x 10)
617 { "wl_wds_enable", V_01 },
618 { "wl_gmode", V_RANGE(-1, 6) },
619 { "wl_wep", V_LENGTH(1, 32) }, // off, on, restricted,tkip,aes,tkip+aes
620 { "wl_akm", V_LENGTH(0, 32) }, // wpa, wpa2, psk, psk2, wpa wpa2, psk psk2, ""
621 { "wl_auth_mode", V_LENGTH(4, 6) }, // none, radius
623 { "wl_nmode", V_NONE },
624 { "wl_nband", V_RANGE(0, 2) }, // 2 - 2.4GHz, 1 - 5GHz, 0 - Auto
625 { "wl_nreqd", V_NONE },
626 { "wl_nbw_cap", V_RANGE(0, 2) }, // 0 - 20MHz, 1 - 40MHz, 2 - Auto
627 { "wl_nbw", V_NONE },
628 { "wl_mimo_preamble", V_WORD }, // 802.11n Preamble: mm/gf/auto/gfbcm
629 { "wl_nctrlsb", V_NONE }, // none, lower, upper
631 #ifdef TCONFIG_IPV6
632 // basic-ipv6
633 { "ipv6_service", V_LENGTH(0, 16) }, // '', native, native-pd, sit, other
634 { "ipv6_prefix", V_IPV6 },
635 { "ipv6_prefix_length", V_RANGE(3, 127) },
636 { "ipv6_rtr_addr", V_LENGTH(0, 40) },
637 { "ipv6_radvd", V_01 },
638 { "ipv6_accept_ra", V_NUM },
639 { "ipv6_tun_addr", V_IPV6 },
640 { "ipv6_tun_addrlen", V_RANGE(3, 127) },
641 { "ipv6_ifname", V_LENGTH(0, 8) },
642 { "ipv6_tun_v4end", V_IP },
643 { "ipv6_tun_mtu", V_NUM }, // Tunnel MTU
644 { "ipv6_tun_ttl", V_NUM }, // Tunnel TTL
645 { "ipv6_dns", V_LENGTH(0, 40*3) }, // ip6 ip6 ip6
646 #endif
648 // basic-wfilter
649 { "wl_macmode", V_NONE }, // allow, deny, disabled
650 { "wl_maclist", V_LENGTH(0, 18*201) }, // 18 x 200 (11:22:33:44:55:66 ...)
651 { "macnames", V_LENGTH(0, 62*201) }, // 62 (12+1+48+1) x 50 (112233445566<..>) todo: re-use -- zzz
653 // advanced-ctnf
654 { "ct_max", V_NUM },
655 { "ct_tcp_timeout", V_LENGTH(20, 70) },
656 { "ct_udp_timeout", V_LENGTH(5, 15) },
657 { "ct_timeout", V_LENGTH(5, 15) },
658 { "nf_ttl", V_LENGTH(1, 6) },
659 { "nf_l7in", V_01 },
660 #ifdef LINUX26
661 { "nf_sip", V_01 },
662 { "ct_hashsize", V_NUM },
663 #endif
664 { "nf_rtsp", V_01 },
665 { "nf_pptp", V_01 },
666 { "nf_h323", V_01 },
667 { "nf_ftp", V_01 },
669 // advanced-dhcpdns
670 { "dhcpd_slt", V_RANGE(-1, 43200) }, // -1=infinite, 0=follow normal lease time, >=1 custom
671 { "dhcpd_dmdns", V_01 },
672 { "dhcpd_lmax", V_NUM },
673 { "dhcpd_gwmode", V_NUM },
674 { "dns_addget", V_01 },
675 { "dns_intcpt", V_01 },
676 { "dhcpc_minpkt", V_01 },
677 { "dhcpc_custom", V_LENGTH(0, 80) },
678 { "dns_norebind", V_01 },
679 { "dnsmasq_custom", V_TEXT(0, 2048) },
680 // { "dnsmasq_norw", V_01 },
682 // advanced-firewall
683 { "block_wan", V_01 },
684 { "multicast_pass", V_01 },
685 { "block_loopback", V_01 },
686 { "nf_loopback", V_NUM },
687 { "ne_syncookies", V_01 },
688 { "dhcp_pass", V_01 },
689 #ifdef TCONFIG_EMF
690 { "emf_entry", V_NONE },
691 { "emf_uffp_entry", V_NONE },
692 { "emf_rtport_entry", V_NONE },
693 { "emf_enable", V_01 },
694 #endif
696 // advanced-misc
697 { "wait_time", V_RANGE(3, 20) },
698 { "wan_speed", V_RANGE(0, 4) },
699 { "jumbo_frame_enable", V_01 }, // Jumbo Frames support (for RT-N16/WNR3500L)
700 { "jumbo_frame_size", V_RANGE(1, 9720) },
701 #ifdef CONFIG_BCMWL5
702 { "ctf_disable", V_01 },
703 #endif
704 // advanced-vlan
705 { "vlan0ports", V_TEXT(0,16) },
706 { "vlan1ports", V_TEXT(0,16) },
707 { "vlan2ports", V_TEXT(0,16) },
708 { "vlan3ports", V_TEXT(0,16) },
709 { "vlan4ports", V_TEXT(0,16) },
710 { "vlan5ports", V_TEXT(0,16) },
711 { "vlan6ports", V_TEXT(0,16) },
712 { "vlan7ports", V_TEXT(0,16) },
713 { "vlan8ports", V_TEXT(0,16) },
714 { "vlan9ports", V_TEXT(0,16) },
715 { "vlan10ports", V_TEXT(0,16) },
716 { "vlan11ports", V_TEXT(0,16) },
717 { "vlan12ports", V_TEXT(0,16) },
718 { "vlan13ports", V_TEXT(0,16) },
719 { "vlan14ports", V_TEXT(0,16) },
720 { "vlan15ports", V_TEXT(0,16) },
721 { "vlan0hwname", V_TEXT(0,8) },
722 { "vlan1hwname", V_TEXT(0,8) },
723 { "vlan2hwname", V_TEXT(0,8) },
724 { "vlan3hwname", V_TEXT(0,8) },
725 { "vlan4hwname", V_TEXT(0,8) },
726 { "vlan5hwname", V_TEXT(0,8) },
727 { "vlan6hwname", V_TEXT(0,8) },
728 { "vlan7hwname", V_TEXT(0,8) },
729 { "vlan8hwname", V_TEXT(0,8) },
730 { "vlan9hwname", V_TEXT(0,8) },
731 { "vlan10hwname", V_TEXT(0,8) },
732 { "vlan11hwname", V_TEXT(0,8) },
733 { "vlan12hwname", V_TEXT(0,8) },
734 { "vlan13hwname", V_TEXT(0,8) },
735 { "vlan14hwname", V_TEXT(0,8) },
736 { "vlan15hwname", V_TEXT(0,8) },
737 { "wan_ifnameX", V_TEXT(0,8) },
738 { "lan_ifnames", V_TEXT(0,64) },
739 { "manual_boot_nv", V_01 },
740 { "trunk_vlan_so", V_01 },
742 // advanced-mac
743 { "mac_wan", V_LENGTH(0, 17) },
744 { "wl_macaddr", V_LENGTH(0, 17) },
746 // advanced-routing
747 { "routes_static", V_LENGTH(0, 2048) },
748 { "dhcp_routes", V_01 },
749 { "lan_stp", V_RANGE(0, 1) },
750 { "wk_mode", V_LENGTH(1, 32) }, // gateway, router
751 #ifdef TCONFIG_ZEBRA
752 { "dr_setting", V_RANGE(0, 3) },
753 { "dr_lan_tx", V_LENGTH(0, 32) },
754 { "dr_lan_rx", V_LENGTH(0, 32) },
755 { "dr_lan1_tx", V_LENGTH(0, 32) },
756 { "dr_lan1_rx", V_LENGTH(0, 32) },
757 { "dr_lan2_tx", V_LENGTH(0, 32) },
758 { "dr_lan2_rx", V_LENGTH(0, 32) },
759 { "dr_lan3_tx", V_LENGTH(0, 32) },
760 { "dr_lan3_rx", V_LENGTH(0, 32) },
761 { "dr_wan_tx", V_LENGTH(0, 32) },
762 { "dr_wan_rx", V_LENGTH(0, 32) },
763 #endif
765 // advanced-wireless
766 { "wl_country", V_LENGTH(0, 64) }, // !!TB - Country code
767 { "wl_country_code", V_LENGTH(0, 4) }, // !!TB - Country code
768 { "wl_btc_mode", V_RANGE(0, 2) }, // !!TB - BT Coexistence Mode: 0 (disable), 1 (enable), 2 (preemption)
769 { "wl_afterburner", V_LENGTH(2, 4) }, // off, on, auto
770 { "wl_auth", V_01 },
771 { "wl_rateset", V_LENGTH(2, 7) }, // all, default, 12
772 { "wl_rate", V_RANGE(0, 54 * 1000 * 1000) },
773 { "wl_mrate", V_RANGE(0, 54 * 1000 * 1000) },
774 { "wl_gmode_protection",V_LENGTH(3, 4) }, // off, auto
775 { "wl_frameburst", V_ONOFF }, // off, on
776 { "wl_bcn", V_RANGE(1, 65535) },
777 { "wl_dtim", V_RANGE(1, 255) },
778 { "wl_frag", V_RANGE(256, 2346) },
779 { "wl_rts", V_RANGE(0, 2347) },
780 { "wl_ap_isolate", V_01 },
781 { "wl_plcphdr", V_LENGTH(4, 5) }, // long, short
782 { "wl_antdiv", V_RANGE(0, 3) },
783 { "wl_txant", V_RANGE(0, 3) },
784 { "wl_txpwr", V_RANGE(0, 400) },
785 { "wl_wme", V_WORD }, // auto, off, on
786 { "wl_wme_no_ack", V_ONOFF }, // off, on
787 { "wl_wme_apsd", V_ONOFF }, // off, on
788 { "wl_maxassoc", V_RANGE(0, 255) },
789 { "wl_distance", V_LENGTH(0, 5) }, // "", 1-99999
790 { "wlx_hpamp", V_01 },
791 { "wlx_hperx", V_01 },
792 { "wl_reg_mode", V_LENGTH(1, 3) }, // !!TB - Regulatory: off, h, d
793 { "wl_interfmode", V_RANGE(0, 3) }, // Interference Mitigation Mode (0|1|2|3)
795 { "wl_nmode_protection", V_WORD, }, // off, auto
796 { "wl_nmcsidx", V_RANGE(-2, 32), }, // -2 - 32
797 { "wl_obss_coex", V_01 },
799 // forward-dmz
800 { "dmz_enable", V_01 },
801 { "dmz_ipaddr", V_LENGTH(0, 15) },
802 { "dmz_sip", V_LENGTH(0, 512) },
804 // forward-upnp
805 { "upnp_enable", V_NUM },
806 { "upnp_secure", V_01 },
807 { "upnp_port", V_RANGE(0, 65535) },
808 { "upnp_ssdp_interval", V_RANGE(10, 9999) },
809 { "upnp_mnp", V_01 },
810 { "upnp_clean", V_01 },
811 { "upnp_clean_interval", V_RANGE(60, 65535) },
812 { "upnp_clean_threshold", V_RANGE(0, 9999) },
813 { "upnp_min_port_int", V_PORT },
814 { "upnp_max_port_int", V_PORT },
815 { "upnp_min_port_ext", V_PORT },
816 { "upnp_max_port_ext", V_PORT },
818 // forward-basic
819 { "portforward", V_LENGTH(0, 4096) },
821 #ifdef TCONFIG_IPV6
822 // forward-basic-ipv6
823 { "ipv6_portforward", V_LENGTH(0, 4096) },
824 #endif
826 // forward-triggered
827 { "trigforward", V_LENGTH(0, 4096) },
830 // access restriction
831 { "rruleN", V_RANGE(0, 49) },
832 // { "rrule##", V_LENGTH(0, 2048) }, // in save_variables()
834 // admin-access
835 { "http_enable", V_01 },
836 { "https_enable", V_01 },
837 { "https_crt_save", V_01 },
838 { "https_crt_cn", V_LENGTH(0, 64) },
839 { "https_crt_gen", V_TEMP },
840 { "remote_management", V_01 },
841 { "remote_mgt_https", V_01 },
842 { "http_lanport", V_PORT },
843 { "https_lanport", V_PORT },
844 { "web_wl_filter", V_01 },
845 { "web_css", V_LENGTH(1, 32) },
846 { "web_mx", V_LENGTH(0, 128) },
847 { "http_wanport", V_PORT },
848 { "telnetd_eas", V_01 },
849 { "telnetd_port", V_PORT },
850 { "sshd_eas", V_01 },
851 { "sshd_pass", V_01 },
852 { "sshd_port", V_PORT },
853 { "sshd_remote", V_01 },
854 { "sshd_forwarding", V_01 },
855 { "sshd_rport", V_PORT },
856 { "sshd_authkeys", V_TEXT(0, 4096) },
857 { "rmgt_sip", V_LENGTH(0, 512) },
858 { "ne_shlimit", V_TEXT(1, 50) },
860 // admin-bwm
861 { "rstats_enable", V_01 },
862 { "rstats_path", V_LENGTH(0, 48) },
863 { "rstats_stime", V_RANGE(1, 168) },
864 { "rstats_offset", V_RANGE(1, 31) },
865 { "rstats_exclude", V_LENGTH(0, 64) },
866 { "rstats_sshut", V_01 },
867 { "rstats_bak", V_01 },
869 // admin-buttons
870 { "sesx_led", V_RANGE(0, 255) }, // amber, white, aoss
871 { "sesx_b0", V_RANGE(0, 5) }, // 0-5: toggle wireless, reboot, shutdown, script, usb unmount
872 { "sesx_b1", V_RANGE(0, 5) }, // "
873 { "sesx_b2", V_RANGE(0, 5) }, // "
874 { "sesx_b3", V_RANGE(0, 5) }, // "
875 { "sesx_script", V_TEXT(0, 1024) }, //
876 { "script_brau", V_TEXT(0, 1024) }, //
878 // admin-debug
879 { "debug_nocommit", V_01 },
880 { "debug_cprintf", V_01 },
881 { "debug_cprintf_file", V_01 },
882 // { "debug_keepfiles", V_01 },
883 { "debug_ddns", V_01 },
884 { "debug_norestart", V_TEXT(0, 128) },
885 { "console_loglevel", V_RANGE(1, 8) },
886 { "t_cafree", V_01 },
887 { "t_hidelr", V_01 },
889 // admin-sched
890 { "sch_rboot", V_TEXT(0, 64) },
891 { "sch_rcon", V_TEXT(0, 64) },
892 { "sch_c1", V_TEXT(0, 64) },
893 { "sch_c1_cmd", V_TEXT(0, 2048) },
894 { "sch_c2", V_TEXT(0, 64) },
895 { "sch_c2_cmd", V_TEXT(0, 2048) },
896 { "sch_c3", V_TEXT(0, 64) },
897 { "sch_c3_cmd", V_TEXT(0, 2048) },
899 // admin-scripts
900 { "script_init", V_TEXT(0, 4096) },
901 { "script_shut", V_TEXT(0, 4096) },
902 { "script_fire", V_TEXT(0, 8192) },
903 { "script_wanup", V_TEXT(0, 4096) },
905 // admin-log
906 { "log_remote", V_01 },
907 { "log_remoteip", V_LENGTH(0, 512) },
908 { "log_remoteport", V_PORT },
909 { "log_file", V_01 },
910 { "log_limit", V_RANGE(0, 2400) },
911 { "log_in", V_RANGE(0, 3) },
912 { "log_out", V_RANGE(0, 3) },
913 { "log_mark", V_RANGE(0, 99999) },
914 { "log_events", V_TEXT(0, 32) }, // "acre,crond,ntp"
916 // admin-log-webmonitor
917 { "log_wm", V_01 },
918 { "log_wmtype", V_RANGE(0, 2) },
919 { "log_wmip", V_LENGTH(0, 512) },
920 { "log_wmdmax", V_RANGE(0, 9999) },
921 { "log_wmsmax", V_RANGE(0, 9999) },
923 // admin-cifs
924 { "cifs1", V_LENGTH(1, 1024) },
925 { "cifs2", V_LENGTH(1, 1024) },
927 // admin-jffs2
928 { "jffs2_on", V_01 },
929 { "jffs2_exec", V_LENGTH(0, 64) },
930 { "jffs2_format", V_01 },
932 // nas-usb - !!TB
933 #ifdef TCONFIG_USB
934 { "usb_enable", V_01 },
935 { "usb_uhci", V_RANGE(-1, 1) }, // -1 - disabled, 0 - off, 1 - on
936 { "usb_ohci", V_RANGE(-1, 1) },
937 { "usb_usb2", V_RANGE(-1, 1) },
938 { "usb_irq_thresh", V_RANGE(0, 6) },
939 { "usb_storage", V_01 },
940 { "usb_printer", V_01 },
941 { "usb_printer_bidirect", V_01 },
942 { "usb_fs_ext3", V_01 },
943 { "usb_fs_fat", V_01 },
944 #ifdef TCONFIG_NTFS
945 { "usb_fs_ntfs", V_01 },
946 #endif
947 { "usb_automount", V_01 },
948 { "script_usbhotplug", V_TEXT(0, 2048) },
949 { "script_usbmount", V_TEXT(0, 2048) },
950 { "script_usbumount", V_TEXT(0, 2048) },
951 #endif
953 // nas-ftp - !!TB
954 #ifdef TCONFIG_FTP
955 { "ftp_enable", V_RANGE(0, 2) },
956 { "ftp_super", V_01 },
957 { "ftp_anonymous", V_RANGE(0, 3) },
958 { "ftp_dirlist", V_RANGE(0, 2) },
959 { "ftp_port", V_PORT },
960 { "ftp_max", V_RANGE(0, 12) },
961 { "ftp_ipmax", V_RANGE(0, 12) },
962 { "ftp_staytimeout", V_RANGE(0, 65535) },
963 { "ftp_rate", V_RANGE(0, 99999) },
964 { "ftp_anonrate", V_RANGE(0, 99999) },
965 { "ftp_anonroot", V_LENGTH(0, 256) },
966 { "ftp_pubroot", V_LENGTH(0, 256) },
967 { "ftp_pvtroot", V_LENGTH(0, 256) },
968 { "ftp_users", V_LENGTH(0, 4096) },
969 { "ftp_custom", V_TEXT(0, 2048) },
970 { "ftp_sip", V_LENGTH(0, 512) },
971 { "ftp_limit", V_TEXT(1, 50) },
972 { "log_ftp", V_01 },
973 #endif
975 #ifdef TCONFIG_SAMBASRV
976 // nas-samba - !!TB
977 { "smbd_enable", V_RANGE(0, 2) },
978 { "smbd_wgroup", V_LENGTH(0, 20) },
979 { "smbd_master", V_01 },
980 { "smbd_wins", V_01 },
981 { "smbd_cpage", V_LENGTH(0, 4) },
982 { "smbd_cset", V_LENGTH(0, 20) },
983 { "smbd_custom", V_TEXT(0, 2048) },
984 { "smbd_autoshare", V_RANGE(0, 3) },
985 { "smbd_shares", V_LENGTH(0, 4096) },
986 { "smbd_user", V_LENGTH(0, 50) },
987 { "smbd_passwd", V_LENGTH(0, 50) },
988 #endif
990 #ifdef TCONFIG_MEDIA_SERVER
991 // nas-media
992 { "ms_enable", V_01 },
993 { "ms_dirs", V_LENGTH(0, 1024) },
994 { "ms_port", V_RANGE(0, 65535) },
995 { "ms_dbdir", V_LENGTH(0, 256) },
996 { "ms_tivo", V_01 },
997 { "ms_stdlna", V_01 },
998 { "ms_rescan", V_01 },
999 { "ms_sas", V_01 },
1000 #endif
1002 // qos
1003 { "qos_enable", V_01 },
1004 { "qos_ack", V_01 },
1005 { "qos_syn", V_01 },
1006 { "qos_fin", V_01 },
1007 { "qos_rst", V_01 },
1008 { "qos_icmp", V_01 },
1009 { "qos_reset", V_01 },
1010 { "qos_pfifo", V_01 }, // !!TB
1011 { "qos_obw", V_RANGE(10, 999999) },
1012 { "qos_ibw", V_RANGE(10, 999999) },
1013 { "qos_orules", V_LENGTH(0, 4096) },
1014 { "qos_default", V_RANGE(0, 9) },
1015 { "qos_irates", V_LENGTH(0, 128) },
1016 { "qos_orates", V_LENGTH(0, 128) },
1018 { "ne_vegas", V_01 },
1019 { "ne_valpha", V_NUM },
1020 { "ne_vbeta", V_NUM },
1021 { "ne_vgamma", V_NUM },
1023 #ifdef TCONFIG_OPENVPN
1024 // vpn
1025 { "vpn_debug", V_01 },
1026 { "vpn_server_eas", V_NONE },
1027 { "vpn_server_dns", V_NONE },
1028 { "vpn_server1_poll", V_RANGE(0, 1440) },
1029 { "vpn_server1_if", V_TEXT(3, 3) }, // tap, tun
1030 { "vpn_server1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1031 { "vpn_server1_port", V_PORT },
1032 { "vpn_server1_firewall", V_TEXT(0, 8) }, // auto, external, custom
1033 { "vpn_server1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1034 { "vpn_server1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1035 { "vpn_server1_cipher", V_TEXT(0, 16) },
1036 { "vpn_server1_dhcp", V_01 },
1037 { "vpn_server1_r1", V_IP },
1038 { "vpn_server1_r2", V_IP },
1039 { "vpn_server1_sn", V_IP },
1040 { "vpn_server1_nm", V_IP },
1041 { "vpn_server1_local", V_IP },
1042 { "vpn_server1_remote", V_IP },
1043 { "vpn_server1_reneg", V_RANGE(-1,2147483647)},
1044 { "vpn_server1_hmac", V_RANGE(-1, 2) },
1045 { "vpn_server1_plan", V_01 },
1046 { "vpn_server1_ccd", V_01 },
1047 { "vpn_server1_c2c", V_01 },
1048 { "vpn_server1_ccd_excl", V_01 },
1049 { "vpn_server1_ccd_val", V_NONE },
1050 { "vpn_server1_pdns", V_01 },
1051 { "vpn_server1_rgw", V_01 },
1052 { "vpn_server1_custom", V_NONE },
1053 { "vpn_server1_static", V_NONE },
1054 { "vpn_server1_ca", V_NONE },
1055 { "vpn_server1_crt", V_NONE },
1056 { "vpn_server1_key", V_NONE },
1057 { "vpn_server1_dh", V_NONE },
1058 { "vpn_server2_poll", V_RANGE(0, 1440) },
1059 { "vpn_server2_if", V_TEXT(3, 3) }, // tap, tun
1060 { "vpn_server2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1061 { "vpn_server2_port", V_PORT },
1062 { "vpn_server2_firewall", V_TEXT(0, 8) }, // auto, external, custom
1063 { "vpn_server2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1064 { "vpn_server2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1065 { "vpn_server2_cipher", V_TEXT(0, 16) },
1066 { "vpn_server2_dhcp", V_01 },
1067 { "vpn_server2_r1", V_IP },
1068 { "vpn_server2_r2", V_IP },
1069 { "vpn_server2_sn", V_IP },
1070 { "vpn_server2_nm", V_IP },
1071 { "vpn_server2_local", V_IP },
1072 { "vpn_server2_remote", V_IP },
1073 { "vpn_server2_reneg", V_RANGE(-1,2147483647)},
1074 { "vpn_server2_hmac", V_RANGE(-1, 2) },
1075 { "vpn_server2_plan", V_01 },
1076 { "vpn_server2_pdns", V_01 },
1077 { "vpn_server2_rgw", V_01 },
1078 { "vpn_server2_custom", V_NONE },
1079 { "vpn_server2_ccd", V_01 },
1080 { "vpn_server2_c2c", V_01 },
1081 { "vpn_server2_ccd_excl", V_01 },
1082 { "vpn_server2_ccd_val", V_NONE },
1083 { "vpn_server2_static", V_NONE },
1084 { "vpn_server2_ca", V_NONE },
1085 { "vpn_server2_crt", V_NONE },
1086 { "vpn_server2_key", V_NONE },
1087 { "vpn_server2_dh", V_NONE },
1088 { "vpn_client_eas", V_NONE },
1089 { "vpn_client1_poll", V_RANGE(0, 1440) },
1090 { "vpn_client1_if", V_TEXT(3, 3) }, // tap, tun
1091 { "vpn_client1_bridge", V_01 },
1092 { "vpn_client1_nat", V_01 },
1093 { "vpn_client1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1094 { "vpn_client1_addr", V_NONE },
1095 { "vpn_client1_port", V_PORT },
1096 { "vpn_client1_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1097 { "vpn_client1_firewall", V_TEXT(0, 6) }, // auto, custom
1098 { "vpn_client1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1099 { "vpn_client1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1100 { "vpn_client1_cipher", V_TEXT(0, 16) },
1101 { "vpn_client1_local", V_IP },
1102 { "vpn_client1_remote", V_IP },
1103 { "vpn_client1_nm", V_IP },
1104 { "vpn_client1_reneg", V_RANGE(-1,2147483647)},
1105 { "vpn_client1_hmac", V_RANGE(-1, 2) },
1106 { "vpn_client1_adns", V_RANGE(0, 3) },
1107 { "vpn_client1_rgw", V_01 },
1108 { "vpn_client1_gw", V_TEXT(0, 15) },
1109 { "vpn_client1_custom", V_NONE },
1110 { "vpn_client1_static", V_NONE },
1111 { "vpn_client1_ca", V_NONE },
1112 { "vpn_client1_crt", V_NONE },
1113 { "vpn_client1_key", V_NONE },
1114 { "vpn_client2_poll", V_RANGE(0, 1440) },
1115 { "vpn_client2_if", V_TEXT(3, 3) }, // tap, tun
1116 { "vpn_client2_bridge", V_01 },
1117 { "vpn_client2_nat", V_01 },
1118 { "vpn_client2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1119 { "vpn_client2_addr", V_NONE },
1120 { "vpn_client2_port", V_PORT },
1121 { "vpn_client2_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1122 { "vpn_client2_firewall", V_TEXT(0, 6) }, // auto, custom
1123 { "vpn_client2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1124 { "vpn_client2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1125 { "vpn_client2_cipher", V_TEXT(0, 16) },
1126 { "vpn_client2_local", V_IP },
1127 { "vpn_client2_remote", V_IP },
1128 { "vpn_client2_nm", V_IP },
1129 { "vpn_client2_reneg", V_RANGE(-1,2147483647)},
1130 { "vpn_client2_hmac", V_RANGE(-1, 2) },
1131 { "vpn_client2_adns", V_RANGE(0, 3) },
1132 { "vpn_client2_rgw", V_01 },
1133 { "vpn_client2_gw", V_TEXT(0, 15) },
1134 { "vpn_client2_custom", V_NONE },
1135 { "vpn_client2_static", V_NONE },
1136 { "vpn_client2_ca", V_NONE },
1137 { "vpn_client2_crt", V_NONE },
1138 { "vpn_client2_key", V_NONE },
1139 #endif // vpn
1142 ppp_static 0/1
1143 ppp_static_ip IP
1144 wl_enable 0/1
1145 wl_wds_timeout
1146 wl_maxassoc 1-256
1147 wl_phytype a,b,g
1148 wl_net_reauth
1149 wl_preauth
1150 wl_wme_ap_bk
1151 wl_wme_ap_be
1152 wl_wme_ap_vi
1153 wl_wme_ap_vo
1154 wl_wme_sta_bk
1155 wl_wme_sta_be
1156 wl_wme_sta_vi
1157 wl_wme_sta_vo
1159 port_priority_1 0-2
1160 port_flow_control_1 0,1
1161 port_rate_limit_1 0-8
1162 port_priority_2 0-2
1163 port_flow_control_2 0,1
1164 port_rate_limit_2 0-8
1165 port_priority_3 0-2
1166 port_flow_control_3 0,1
1167 port_rate_limit_3 0-8
1168 port_priority_4 0-2
1169 port_flow_control_4 0,1
1170 port_rate_limit_4 0-8
1171 wl_ap_ip
1172 wl_ap_ssid
1175 { NULL }
1179 static int webcgi_nvram_set(const nvset_t *v, const char *name, int write)
1181 char *p, *e;
1182 int n;
1183 long l;
1184 unsigned u[6];
1185 int ok;
1186 int dirty;
1187 #ifdef TCONFIG_IPV6
1188 struct in6_addr addr;
1189 #endif
1191 if ((p = webcgi_get((char*)name)) == NULL) return 0;
1193 _dprintf("[%s] %s=%s\n", v->name, (char*)name, p);
1194 dirty = 0;
1195 ok = 1;
1196 switch (v->vtype) {
1197 case VT_TEXT:
1198 p = unix_string(p); // NOTE: p = malloc'd
1199 // drop
1200 case VT_LENGTH:
1201 n = strlen(p);
1202 if ((n < v->va.i) || (n > v->vb.i)) ok = 0;
1203 break;
1204 case VT_RANGE:
1205 l = strtol(p, &e, 10);
1206 if ((p == e) || (*e) || (l < v->va.l) || (l > v->vb.l)) ok = 0;
1207 break;
1208 case VT_IP:
1209 if ((sscanf(p, "%3u.%3u.%3u.%3u", &u[0], &u[1], &u[2], &u[3]) != 4) ||
1210 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255)) ok = 0;
1211 break;
1212 case VT_MAC:
1213 if ((sscanf(p, "%2x:%2x:%2x:%2x:%2x:%2x", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]) != 6) ||
1214 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255) || (u[4] > 255) || (u[5] > 255)) ok = 0;
1215 break;
1216 #ifdef TCONFIG_IPV6
1217 case VT_IPV6:
1218 if (inet_pton(AF_INET6, p, &addr) != 1) ok = 0;
1219 break;
1220 #endif
1221 default:
1222 // shutup gcc
1223 break;
1225 if (!ok) {
1226 if (v->vtype == VT_TEXT) free(p);
1227 return -1;
1229 if (write) {
1230 if (!nvram_match((char *)name, p)) {
1231 if (v->vtype != VT_TEMP) dirty = 1;
1232 DEBUG_NVRAMSET(name, p);
1233 nvram_set(name, p);
1236 if (v->vtype == VT_TEXT) free(p);
1238 return dirty;
1241 typedef struct {
1242 const nvset_t *v;
1243 int write;
1244 int dirty;
1245 } nv_list_t;
1247 static int nv_wl_find(int idx, int unit, int subunit, void *param)
1249 nv_list_t *p = param;
1251 int ok = webcgi_nvram_set(p->v, wl_nvname(p->v->name + 3, unit, subunit), p->write);
1252 if (ok < 0)
1253 return 1;
1254 else {
1255 p->dirty |= ok;
1256 return 0;
1260 static int save_variables(int write)
1262 const nvset_t *v;
1263 char *p;
1264 int n;
1265 int ok;
1266 char s[256];
1267 int dirty;
1268 static const char *msgf = "The field \"%s\" is invalid. Please report this problem.";
1269 nv_list_t nv;
1271 dirty = 0;
1272 nv.write = write;
1273 for (v = nvset_list; v->name; ++v) {
1274 ok = webcgi_nvram_set(v, v->name, write);
1276 if ((ok >= 0) && (strncmp(v->name, "wl_", 3) == 0)) {
1277 nv.dirty = dirty;
1278 nv.v = v;
1279 if (foreach_wif(1, &nv, nv_wl_find) == 0)
1280 ok |= nv.dirty;
1281 else
1282 ok = -1;
1285 if (ok < 0) {
1286 sprintf(s, msgf, v->name);
1287 resmsg_set(s);
1288 return 0;
1290 dirty |= ok;
1293 // special cases
1295 char *p1, *p2;
1296 if (((p1 = webcgi_get("set_password_1")) != NULL) && (strcmp(p1, "**********") != 0)) {
1297 if (((p2 = webcgi_get("set_password_2")) != NULL) && (strcmp(p1, p2) == 0)) {
1298 if ((write) && (!nvram_match("http_passwd", p1))) {
1299 dirty = 1;
1300 nvram_set("http_passwd", p1);
1303 else {
1304 sprintf(s, msgf, "password");
1305 resmsg_set(s);
1306 return 0;
1310 for (n = 0; n < 50; ++n) {
1311 sprintf(s, "rrule%d", n);
1312 if ((p = webcgi_get(s)) != NULL) {
1313 if (strlen(p) > 2048) {
1314 sprintf(s, msgf, s);
1315 resmsg_set(s);
1316 return 0;
1318 if ((write) && (!nvram_match(s, p))) {
1319 dirty = 1;
1320 DEBUG_NVRAMSET(s, p);
1321 nvram_set(s, p);
1326 return (write) ? dirty : 1;
1329 static void wo_tomato(char *url)
1331 char *v;
1332 int i;
1333 int ajax;
1334 int nvset;
1335 const char *red;
1336 int commit;
1338 // _dprintf("tomato.cgi\n");
1340 red = webcgi_safeget("_redirect", "");
1341 if (!*red) send_header(200, NULL, mime_html, 0);
1343 commit = atoi(webcgi_safeget("_commit", "1"));
1344 ajax = atoi(webcgi_safeget("_ajax", "0"));
1346 nvset = atoi(webcgi_safeget("_nvset", "1"));
1347 if (nvset) {
1348 if (!save_variables(0)) {
1349 if (ajax) {
1350 web_printf("@msg:%s", resmsg_get());
1352 else {
1353 parse_asp("error.asp");
1355 return;
1357 commit = save_variables(1) && commit;
1359 resmsg_set("Settings saved.");
1362 rboot = atoi(webcgi_safeget("_reboot", "0"));
1363 if (rboot) {
1364 parse_asp("reboot.asp");
1366 else {
1367 if (ajax) {
1368 web_printf("@msg:%s", resmsg_get());
1370 else if (atoi(webcgi_safeget("_moveip", "0"))) {
1371 parse_asp("saved-moved.asp");
1373 else if (!*red) {
1374 parse_asp("saved.asp");
1378 if (commit) {
1379 _dprintf("commit from tomato.cgi\n");
1380 nvram_commit_x();
1383 if ((v = webcgi_get("_service")) != NULL && *v != 0) {
1384 if (!*red) {
1385 if (ajax) web_printf(" Some services are being restarted...");
1386 web_close();
1388 sleep(1);
1390 if (*v == '*') {
1391 kill(1, SIGHUP);
1393 else {
1394 exec_service(v);
1398 for (i = atoi(webcgi_safeget("_sleep", "0")); i > 0; --i) sleep(1);
1400 if (*red) redirect(red);
1402 if (rboot) {
1403 web_close();
1404 sleep(1);
1405 kill(1, SIGTERM);
1410 // ----------------------------------------------------------------------------
1413 static void wo_update(char *url)
1415 const aspapi_t *api;
1416 const char *name;
1417 int argc;
1418 char *argv[16];
1419 char s[32];
1421 if ((name = webcgi_get("exec")) != NULL) {
1422 for (api = aspapi; api->name; ++api) {
1423 if (strcmp(api->name, name) == 0) {
1424 for (argc = 0; argc < 16; ++argc) {
1425 sprintf(s, "arg%d", argc);
1426 if ((argv[argc] = (char *)webcgi_get(s)) == NULL) break;
1428 api->exec(argc, argv);
1429 break;
1435 static void wo_service(char *url)
1437 int n;
1439 exec_service(webcgi_safeget("_service", ""));
1441 if ((n = atoi(webcgi_safeget("_sleep", "2"))) <= 0) n = 2;
1442 sleep(n);
1444 common_redirect();
1447 static void wo_shutdown(char *url)
1449 parse_asp("shutdown.asp");
1450 web_close();
1451 sleep(1);
1453 kill(1, SIGQUIT);
1456 static void wo_nvcommit(char *url)
1458 parse_asp("saved.asp");
1459 web_close();
1460 nvram_commit();