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