Add option to make DNS configuration retrieved by pptp exclusive
[tomato.git] / release / src / router / httpd / tomato.c
blobf4fd350eb8d1f1cf2280c4ce1d0b4bf5f1018db8
1 /*
3 Tomato Firmware
4 Copyright (C) 2006-2010 Jonathan Zarate
6 */
8 #include "tomato.h"
10 #include <sys/sysinfo.h>
11 #include <sys/stat.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <arpa/inet.h>
15 #include <time.h>
18 // #define DEBUG_NOEXECSERVICE
19 #define DEBUG_NVRAMSET(k, v) _dprintf("nvram set %s=%s\n", k, v);
22 char *post_buf = NULL;
23 int rboot = 0;
24 extern int post;
26 static void asp_css(int argc, char **argv);
27 static void asp_resmsg(int argc, char **argv);
30 static void wo_tomato(char *url);
31 static void wo_update(char *url);
32 static void wo_service(char *url);
33 static void wo_shutdown(char *url);
34 static void wo_nvcommit(char *url);
35 // static void wo_logout(char *url);
38 // ----------------------------------------------------------------------------
41 void exec_service(const char *action)
43 int i;
45 _dprintf("exec_service: %s\n", action);
47 i = 10;
48 while ((!nvram_match("action_service", "")) && (i-- > 0)) {
49 _dprintf("%s: waiting before %d\n", __FUNCTION__, i);
50 sleep(1);
53 nvram_set("action_service", action);
54 kill(1, SIGUSR1);
56 i = 3;
57 while ((nvram_match("action_service", (char *)action)) && (i-- > 0)) {
58 _dprintf("%s: waiting after %d\n", __FUNCTION__, i);
59 sleep(1);
63 if (atoi(webcgi_safeget("_service_wait", ""))) {
64 i = 10;
65 while ((nvram_match("action_service", (char *)action)) && (i-- > 0)) {
66 _dprintf("%s: waiting after %d\n", __FUNCTION__, i);
67 sleep(1);
73 static void wi_generic_noid(char *url, int len, char *boundary)
75 if (post == 1) {
76 if (len >= (32 * 1024)) {
77 // syslog(LOG_WARNING, "POST max");
78 exit(1);
81 if (post_buf) free(post_buf);
82 if ((post_buf = malloc(len + 1)) == NULL) {
83 // syslog(LOG_CRIT, "Unable to allocate post buffer");
84 exit(1);
87 if (web_read_x(post_buf, len) != len) {
88 exit(1);
90 post_buf[len] = 0;
91 webcgi_init(post_buf);
95 void wi_generic(char *url, int len, char *boundary)
97 wi_generic_noid(url, len, boundary);
98 check_id(url);
101 // !!TB - CGI Support
102 void wi_cgi_bin(char *url, int len, char *boundary)
104 if (post_buf) free(post_buf);
105 post_buf = NULL;
107 if (post) {
108 if (len >= (128 * 1024)) {
109 syslog(LOG_WARNING, "POST length exceeded maximum allowed");
110 exit(1);
113 if (len > 0) {
114 if ((post_buf = malloc(len + 1)) == NULL) {
115 exit(1);
117 if (web_read_x(post_buf, len) != len) {
118 exit(1);
120 post_buf[len] = 0;
125 static void _execute_command(char *url, char *command, char *query, wofilter_t wof)
127 char webExecFile[] = "/tmp/.wxXXXXXX";
128 char webQueryFile[] = "/tmp/.wqXXXXXX";
129 char cmd[sizeof(webExecFile) + 10];
130 FILE *f;
131 int fe, fq = -1;
133 if ((fe = mkstemp(webExecFile)) < 0)
134 exit(1);
135 if (query) {
136 if ((fq = mkstemp(webQueryFile)) < 0) {
137 close(fe);
138 unlink(webExecFile);
139 exit(1);
143 if ((f = fdopen(fe, "wb")) != NULL) {
144 fprintf(f,
145 "#!/bin/sh\n"
146 "export REQUEST_METHOD=\"%s\"\n"
147 "export PATH=%s\n"
148 ". /etc/profile\n"
149 "%s%s %s%s\n",
150 post ? "POST" : "GET", getenv("PATH"),
151 command ? "" : "./", command ? command : url,
152 query ? "<" : "", query ? webQueryFile : "");
153 fclose(f);
155 else {
156 close(fe);
157 unlink(webExecFile);
158 if (query) {
159 close(fq);
160 unlink(webQueryFile);
162 exit(1);
164 chmod(webExecFile, 0700);
166 if (query) {
167 if ((f = fdopen(fq, "wb")) != NULL) {
168 fprintf(f, "%s\n", query);
169 fclose(f);
171 else {
172 unlink(webExecFile);
173 close(fq);
174 unlink(webQueryFile);
175 exit(1);
179 sprintf(cmd, "%s 2>&1", webExecFile);
180 web_pipecmd(cmd, wof);
181 unlink(webQueryFile);
182 unlink(webExecFile);
185 static void wo_cgi_bin(char *url)
187 if (!header_sent) send_header(200, NULL, mime_html, 0);
188 _execute_command(url, NULL, post_buf, WOF_NONE);
189 if (post_buf) {
190 free(post_buf);
191 post_buf = NULL;
195 static void wo_shell(char *url)
197 web_puts("\ncmdresult = '");
198 _execute_command(NULL, webcgi_get("command"), NULL, WOF_JAVASCRIPT);
199 web_puts("';");
202 static void wo_blank(char *url)
204 web_puts("\n\n\n\n");
207 static void wo_favicon(char *url)
209 send_header(200, NULL, "image/vnd.microsoft.icon", 0);
210 do_file(url);
212 if (nvram_match("web_favicon", "1")) {
213 send_header(200, NULL, "image/vnd.microsoft.icon", 0);
214 do_file(url);
216 else {
217 send_error(404, NULL, NULL);
222 static void wo_cfe(char *url)
224 do_file(MTD_DEV(0ro));
227 static void wo_nvram(char *url)
229 web_pipecmd("nvram show", WOF_NONE);
232 static void wo_iptables(char *url)
234 web_pipecmd("iptables -nvL; echo; iptables -t nat -nvL; echo; iptables -t mangle -nvL", WOF_NONE);
237 #ifdef TCONFIG_IPV6
238 static void wo_ip6tables(char *url)
240 web_pipecmd("ip6tables -nvL; echo; ip6tables -t mangle -nvL", WOF_NONE);
242 #endif
245 static void wo_spin(char *url)
247 char s[64];
249 strlcpy(s, nvram_safe_get("web_css"), sizeof(s));
250 strlcat(s, "_spin.gif", sizeof(s));
251 if (f_exists(s)) do_file(s);
252 else do_file("_spin.gif");
256 void common_redirect(void)
258 if (atoi(webcgi_safeget("_ajax", ""))) {
259 send_header(200, NULL, mime_html, 0);
260 web_puts("OK");
262 else {
263 redirect(webcgi_safeget("_redirect", "/"));
267 // ----------------------------------------------------------------------------
269 const struct mime_handler mime_handlers[] = {
270 { "update.cgi", mime_javascript, 0, wi_generic, wo_update, 1 },
271 { "tomato.cgi", NULL, 0, wi_generic, wo_tomato, 1 },
273 { "debug.js", mime_javascript, 5, wi_generic_noid, wo_blank, 1 }, // while debugging
274 { "cfe/*.bin", mime_binary, 0, wi_generic, wo_cfe, 1 },
275 { "nvram/*.txt", mime_binary, 0, wi_generic, wo_nvram, 1 },
276 { "ipt/*.txt", mime_binary, 0, wi_generic, wo_iptables, 1 },
277 #ifdef TCONFIG_IPV6
278 { "ip6t/*.txt", mime_binary, 0, wi_generic, wo_ip6tables, 1 },
279 #endif
280 { "cfg/*.cfg", NULL, 0, wi_generic, wo_backup, 1 },
281 { "cfg/restore.cgi", mime_html, 0, wi_restore, wo_restore, 1 },
282 { "cfg/defaults.cgi", NULL, 0, wi_generic, wo_defaults, 1 },
284 { "bwm/*.gz", NULL, 0, wi_generic, wo_bwmbackup, 1 },
285 { "bwm/restore.cgi", NULL, 0, wi_bwmrestore, wo_bwmrestore, 1 },
287 { "ipt/*.gz", NULL, 0, wi_generic, wo_iptbackup, 1 },
288 { "ipt/restore.cgi", NULL, 0, wi_iptrestore, wo_iptrestore, 1 },
290 { "logs/view.cgi", NULL, 0, wi_generic, wo_viewlog, 1 },
291 { "logs/*.txt", NULL, 0, wi_generic, wo_syslog, 1 },
292 { "webmon_**", NULL, 0, wi_generic, wo_syslog, 1 },
294 { "logout.asp", NULL, 0, wi_generic, wo_asp, 1 },
295 { "clearcookies.asp", NULL, 0, wi_generic, wo_asp, 1 },
297 // { "spin.gif", NULL, 0, wi_generic_noid, wo_spin, 1 },
299 { "**.asp", NULL, 0, wi_generic_noid, wo_asp, 1 },
300 { "**.css", "text/css", 2, wi_generic_noid, do_file, 1 },
301 { "**.htm|**.html", mime_html, 2, wi_generic_noid, do_file, 1 },
302 { "**.gif", "image/gif", 5, wi_generic_noid, do_file, 1 },
303 { "**.jpg", "image/jpeg", 5, wi_generic_noid, do_file, 1 },
304 { "**.png", "image/png", 5, wi_generic_noid, do_file, 1 },
305 { "**.js", mime_javascript, 2, wi_generic_noid, do_file, 1 },
306 { "**.jsx", mime_javascript, 0, wi_generic, wo_asp, 1 },
307 { "**.svg", "image/svg+xml", 2, wi_generic_noid, do_file, 1 },
308 { "**.txt", mime_plain, 2, wi_generic_noid, do_file, 1 },
309 { "**.bin", mime_binary, 0, wi_generic_noid, do_file, 1 },
310 { "**.bino", mime_octetstream, 0, wi_generic_noid, do_file, 1 },
311 { "favicon.ico", NULL, 5, wi_generic_noid, wo_favicon, 1 },
312 // !!TB - CGI Support, enable downloading archives
313 { "**/cgi-bin/**|**.sh", NULL, 0, wi_cgi_bin, wo_cgi_bin, 1 },
314 { "**.tar|**.gz", mime_binary, 0, wi_generic_noid, do_file, 1 },
315 { "shell.cgi", mime_javascript, 0, wi_generic, wo_shell, 1 },
316 { "wpad.dat|proxy.pac", "application/x-ns-proxy-autoconfig", 0, wi_generic_noid, do_file, 0 },
318 { "webmon.cgi", mime_javascript, 0, wi_generic, wo_webmon, 1 },
319 { "dhcpc.cgi", NULL, 0, wi_generic, wo_dhcpc, 1 },
320 { "dhcpd.cgi", mime_javascript, 0, wi_generic, wo_dhcpd, 1 },
321 { "nvcommit.cgi", NULL, 0, wi_generic, wo_nvcommit, 1 },
322 { "ping.cgi", mime_javascript, 0, wi_generic, wo_ping, 1 },
323 { "trace.cgi", mime_javascript, 0, wi_generic, wo_trace, 1 },
324 { "upgrade.cgi", mime_html, 0, wi_upgrade, wo_flash, 1 },
325 { "upnp.cgi", NULL, 0, wi_generic, wo_upnp, 1 },
326 { "wakeup.cgi", NULL, 0, wi_generic, wo_wakeup, 1 },
327 { "wlmnoise.cgi", mime_html, 0, wi_generic, wo_wlmnoise, 1 },
328 { "wlradio.cgi", NULL, 0, wi_generic, wo_wlradio, 1 },
329 { "resolve.cgi", mime_javascript, 0, wi_generic, wo_resolve, 1 },
330 { "expct.cgi", mime_html, 0, wi_generic, wo_expct, 1 },
331 { "service.cgi", NULL, 0, wi_generic, wo_service, 1 },
332 // { "logout.cgi", NULL, 0, wi_generic, wo_logout, 0 },
333 // see httpd.c
334 { "shutdown.cgi", mime_html, 0, wi_generic, wo_shutdown, 1 },
335 #ifdef TCONFIG_OPENVPN
336 { "vpnstatus.cgi", mime_javascript, 0, wi_generic, wo_vpn_status, 1 },
337 #endif
338 #ifdef TCONFIG_USB
339 { "usbcmd.cgi", mime_javascript, 0, wi_generic, wo_usbcommand, 1 }, //!!TB - USB
340 #endif
341 #ifdef BLACKHOLE
342 { "blackhole.cgi", NULL, 0, wi_blackhole, NULL, 1 },
343 #endif
344 #ifdef TCONFIG_NOCAT
345 { "uploadsplash.cgi", NULL, 0, wi_uploadsplash, wo_uploadsplash, 1 },
346 { "ext/uploadsplash.cgi", NULL, 0, wi_uploadsplash, wo_uploadsplash, 1 },
347 #endif
348 { NULL, NULL, 0, NULL, NULL, 1 }
351 const aspapi_t aspapi[] = {
352 { "activeroutes", asp_activeroutes },
353 { "arplist", asp_arplist },
354 { "bandwidth", asp_bandwidth },
355 { "build_time", asp_build_time },
356 { "cgi_get", asp_cgi_get },
357 { "compmac", asp_compmac },
358 { "ctcount", asp_ctcount },
359 { "ctdump", asp_ctdump },
360 { "ctrate", asp_ctrate },
361 { "ddnsx", asp_ddnsx },
362 { "devlist", asp_devlist },
363 { "webmon", asp_webmon },
364 { "dhcpc_time", asp_dhcpc_time },
365 { "dns", asp_dns },
366 { "ident", asp_ident },
367 { "lanip", asp_lanip },
368 { "layer7", asp_layer7 },
369 { "link_uptime", asp_link_uptime },
370 { "lipp", asp_lipp },
371 { "netdev", asp_netdev },
373 { "iptraffic", asp_iptraffic },
374 { "iptmon", asp_iptmon },
375 { "ipt_bandwidth", asp_ipt_bandwidth },
377 { "notice", asp_notice },
378 { "nv", asp_nv },
379 { "nvram", asp_nvram },
380 { "nvramseq", asp_nvramseq },
381 { "nvstat", asp_nvstat },
382 { "psup", asp_psup },
383 { "qrate", asp_qrate },
384 { "resmsg", asp_resmsg },
385 { "rrule", asp_rrule },
386 { "statfs", asp_statfs },
387 { "sysinfo", asp_sysinfo },
388 { "time", asp_time },
389 { "upnpinfo", asp_upnpinfo },
390 { "version", asp_version },
391 { "wanstatus", asp_wanstatus },
392 { "wanup", asp_wanup },
393 { "wlstats", asp_wlstats },
394 { "wlclient", asp_wlclient },
395 { "wlnoise", asp_wlnoise },
396 { "wlscan", asp_wlscan },
397 { "wlchannels", asp_wlchannels }, //!!TB
398 { "wlcountries", asp_wlcountries },
399 { "wlifaces", asp_wlifaces },
400 { "wlbands", asp_wlbands },
401 #ifdef TCONFIG_USB
402 { "usbdevices", asp_usbdevices }, //!!TB - USB Support
403 #endif
404 { "css", asp_css },
405 { NULL, NULL }
408 // -----------------------------------------------------------------------------
410 static void asp_css(int argc, char **argv)
412 const char *css = nvram_safe_get("web_css");
414 if (strcmp(css, "tomato") != 0) {
415 web_printf("<link rel='stylesheet' type='text/css' href='%s.css'>", css);
419 // -----------------------------------------------------------------------------
421 const char *resmsg_get(void)
423 return webcgi_safeget("resmsg", "");
426 void resmsg_set(const char *msg)
428 webcgi_set("resmsg", strdup(msg)); // m ok
431 int resmsg_fread(const char *fname)
433 char s[256];
434 char *p;
436 f_read_string(fname, s, sizeof(s));
437 if ((p = strchr(s, '\n')) != NULL) *p = 0;
438 if (s[0]) {
439 resmsg_set(s);
440 return 1;
442 return 0;
445 static void asp_resmsg(int argc, char **argv)
447 char *p;
449 if ((p = js_string(webcgi_safeget("resmsg", (argc > 0) ? argv[0] : ""))) == NULL) return;
450 web_printf("\nresmsg='%s';\n", p);
451 free(p);
454 // ----------------------------------------------------------------------------
456 // verification... simple sanity checks. UI should verify all fields.
458 // todo: move and re-use for filtering - zzz
460 typedef union {
461 int i;
462 long l;
463 const char *s;
464 } nvset_varg_t;
466 typedef struct {
467 const char *name;
468 enum {
469 VT_NONE, // no checking
470 VT_LENGTH, // check length of string
471 VT_TEXT, // strip \r, check length of string
472 VT_RANGE, // expect an integer, check range
473 VT_IP, // expect an ip address
474 VT_MAC, // expect a mac address
475 #ifdef TCONFIG_IPV6
476 VT_IPV6, // expect an ipv6 address
477 #endif
478 VT_TEMP // no checks, no commit
479 } vtype;
480 nvset_varg_t va;
481 nvset_varg_t vb;
482 } nvset_t;
485 #define V_NONE VT_NONE, { }, { }
486 #define V_01 VT_RANGE, { .l = 0 }, { .l = 1 }
487 #define V_PORT VT_RANGE, { .l = 2 }, { .l = 65535 }
488 #define V_ONOFF VT_LENGTH, { .i = 2 }, { .i = 3 }
489 #define V_WORD VT_LENGTH, { .i = 1 }, { .i = 16 }
490 #define V_LENGTH(min, max) VT_LENGTH, { .i = min }, { .i = max }
491 #define V_TEXT(min, max) VT_TEXT, { .i = min }, { .i = max }
492 #define V_RANGE(min, max) VT_RANGE, { .l = min }, { .l = max }
493 #define V_IP VT_IP, { }, { }
494 #define V_OCTET VT_RANGE, { .l = 0 }, { .l = 255 }
495 #define V_NUM VT_RANGE, { .l = 0 }, { .l = 0x7FFFFFFF }
496 #define V_TEMP VT_TEMP, { }, { }
497 #ifdef TCONFIG_IPV6
498 #define V_IPV6(required) VT_IPV6, { .i = required }, { }
499 #endif
501 static const nvset_t nvset_list[] = {
503 // basic-ident
504 { "router_name", V_LENGTH(0, 32) },
505 { "wan_hostname", V_LENGTH(0, 32) },
506 { "wan_domain", V_LENGTH(0, 32) },
508 // basic-time
509 { "tm_tz", V_LENGTH(1, 64) }, // PST8PDT
510 { "tm_sel", V_LENGTH(1, 64) }, // PST8PDT
511 { "tm_dst", V_01 },
512 { "ntp_updates", V_RANGE(-1, 24) },
513 { "ntp_tdod", V_01 },
514 { "ntp_server", V_LENGTH(1, 150) }, // x y z
515 { "ntp_kiss", V_LENGTH(0, 255) },
517 // basic-static
518 { "bwm_client", V_LENGTH(0, 4096) },
519 { "dhcpd_static", V_LENGTH(0, 108*141) }, // 106 (max chars per entry) x 140 entries
520 { "dhcpd_static_only", V_01 },
521 { "arpbind_static", V_LENGTH(0, 34*141) }, // 34 (max chars per entry) x 140 entries
523 // basic-ddns
524 { "ddnsx0", V_LENGTH(0, 2048) },
525 { "ddnsx1", V_LENGTH(0, 2048) },
526 { "ddnsx0_cache", V_LENGTH(0, 1) }, // only to clear
527 { "ddnsx1_cache", V_LENGTH(0, 1) },
528 { "ddnsx_ip", V_LENGTH(0, 32) },
529 { "ddnsx_save", V_01 },
530 { "ddnsx_refresh", V_RANGE(0, 365) },
532 // basic-network
533 // WAN
534 { "wan_proto", V_LENGTH(1, 16) }, // disabled, dhcp, static, pppoe, pptp, l2tp
535 { "wan_ipaddr", V_IP },
536 { "wan_netmask", V_IP },
537 { "wan_gateway", V_IP },
538 { "hb_server_ip", V_LENGTH(0, 32) },
539 { "l2tp_server_ip", V_LENGTH(0, 128) },
540 { "pptp_server_ip", V_LENGTH(0, 128) },
541 { "pptp_dhcp", V_01 },
542 { "ppp_username", V_LENGTH(0, 60) },
543 { "ppp_passwd", V_LENGTH(0, 60) },
544 { "ppp_service", V_LENGTH(0, 50) },
545 { "ppp_demand", V_01 },
546 { "ppp_custom", V_LENGTH(0, 256) },
547 { "ppp_idletime", V_RANGE(0, 1440) },
548 { "ppp_redialperiod", V_RANGE(1, 86400) },
549 { "ppp_mlppp", V_01 },
550 { "mtu_enable", V_01 },
551 { "wan_mtu", V_RANGE(576, 1500) },
552 { "wan_islan", V_01 },
554 // LAN
555 { "lan_ipaddr", V_IP },
556 { "lan_netmask", V_IP },
557 { "lan_gateway", V_IP },
558 { "wan_dns", V_LENGTH(0, 50) }, // ip ip ip
559 { "lan_proto", V_WORD }, // static, dhcp
560 { "dhcp_start", V_LENGTH(0, 15) }, // remove !
561 { "dhcp_num", V_LENGTH(0, 4) }, // remove !
562 { "dhcpd_startip", V_LENGTH(0, 15) },
563 { "dhcpd_endip", V_LENGTH(0, 15) },
564 { "dhcp_lease", V_LENGTH(0, 5) },
565 { "wan_wins", V_IP },
567 #ifdef TCONFIG_VLAN
568 // LAN networks
569 { "lan_ifname", V_LENGTH(0, 5) },
571 { "lan1_ifname", V_LENGTH(0, 5) },
572 { "lan1_ifnames", V_TEXT(0,64) },
573 { "lan1_ipaddr", V_LENGTH(0, 15) },
574 { "lan1_netmask", V_LENGTH(0, 15) },
575 { "lan1_proto", V_LENGTH(0, 6) },
576 { "lan1_stp", V_LENGTH(0, 1) },
577 { "dhcp1_start", V_LENGTH(0, 15) },
578 { "dhcp1_num", V_LENGTH(0, 4) },
579 { "dhcpd1_startip", V_LENGTH(0, 15) },
580 { "dhcpd1_endip", V_LENGTH(0, 15) },
581 { "dhcp1_lease", V_LENGTH(0, 5) },
583 { "lan2_ifname", V_LENGTH(0, 5) },
584 { "lan2_ifnames", V_TEXT(0,64) },
585 { "lan2_ipaddr", V_LENGTH(0, 15) },
586 { "lan2_netmask", V_LENGTH(0, 15) },
587 { "lan2_proto", V_LENGTH(0, 6) },
588 { "lan2_stp", V_LENGTH(0, 1) },
589 { "dhcp2_start", V_LENGTH(0, 15) },
590 { "dhcp2_num", V_LENGTH(0, 4) },
591 { "dhcpd2_startip", V_LENGTH(0, 15) },
592 { "dhcpd2_endip", V_LENGTH(0, 15) },
593 { "dhcp2_lease", V_LENGTH(0, 5) },
595 { "lan3_ifname", V_LENGTH(0, 5) },
596 { "lan3_ifnames", V_TEXT(0,64) },
597 { "lan3_ipaddr", V_LENGTH(0, 15) },
598 { "lan3_netmask", V_LENGTH(0, 15) },
599 { "lan3_proto", V_LENGTH(0, 6) },
600 { "lan3_stp", V_LENGTH(0, 1) },
601 { "dhcp3_start", V_LENGTH(0, 15) },
602 { "dhcp3_num", V_LENGTH(0, 4) },
603 { "dhcpd3_startip", V_LENGTH(0, 15) },
604 { "dhcpd3_endip", V_LENGTH(0, 15) },
605 { "dhcp3_lease", V_LENGTH(0, 5) },
606 #endif
608 // wireless
609 { "wl_radio", V_01 },
610 { "wl_mode", V_LENGTH(2, 3) }, // ap, sta, wet, wds
611 { "wl_net_mode", V_LENGTH(5, 8) }, // disabled, mixed, b-only, g-only, bg-mixed, n-only [speedbooster]
612 { "wl_ssid", V_LENGTH(1, 32) },
613 { "wl_closed", V_01 },
614 { "wl_channel", V_RANGE(0, 216) },
616 { "wl_security_mode", V_LENGTH(1, 32) }, // disabled, radius, wep, wpa_personal, wpa_enterprise, wpa2_personal, wpa2_enterprise
617 { "wl_radius_ipaddr", V_IP },
618 { "wl_radius_port", V_PORT },
619 { "wl_radius_key", V_LENGTH(1, 64) },
620 { "wl_wep_bit", V_RANGE(64, 128) }, // 64 or 128
621 { "wl_passphrase", V_LENGTH(0, 20) },
622 { "wl_key", V_RANGE(1, 4) },
623 { "wl_key1", V_LENGTH(0, 26) },
624 { "wl_key2", V_LENGTH(0, 26) },
625 { "wl_key3", V_LENGTH(0, 26) },
626 { "wl_key4", V_LENGTH(0, 26) },
627 { "wl_crypto", V_LENGTH(3, 8) }, // tkip, aes, tkip+aes
628 { "wl_wpa_psk", V_LENGTH(8, 64) },
629 { "wl_wpa_gtk_rekey", V_RANGE(60, 7200) },
631 { "wl_lazywds", V_01 },
632 { "wl_wds", V_LENGTH(0, 180) }, // mac mac mac (x 10)
634 { "wl_wds_enable", V_01 },
635 { "wl_gmode", V_RANGE(-1, 6) },
636 { "wl_wep", V_LENGTH(1, 32) }, // off, on, restricted,tkip,aes,tkip+aes
637 { "wl_akm", V_LENGTH(0, 32) }, // wpa, wpa2, psk, psk2, wpa wpa2, psk psk2, ""
638 { "wl_auth_mode", V_LENGTH(4, 6) }, // none, radius
640 { "wl_nmode", V_NONE },
641 { "wl_nband", V_RANGE(0, 2) }, // 2 - 2.4GHz, 1 - 5GHz, 0 - Auto
642 { "wl_nreqd", V_NONE },
643 { "wl_nbw_cap", V_RANGE(0, 2) }, // 0 - 20MHz, 1 - 40MHz, 2 - Auto
644 { "wl_nbw", V_NONE },
645 { "wl_mimo_preamble", V_WORD }, // 802.11n Preamble: mm/gf/auto/gfbcm
646 { "wl_nctrlsb", V_NONE }, // none, lower, upper
648 #ifdef TCONFIG_IPV6
649 // basic-ipv6
650 { "ipv6_service", V_LENGTH(0, 16) }, // '', native, native-pd, 6to4, sit, other
651 { "ipv6_prefix", V_IPV6(0) },
652 { "ipv6_prefix_length", V_RANGE(3, 127) },
653 { "ipv6_rtr_addr", V_IPV6(0) },
654 { "ipv6_radvd", V_01 },
655 { "ipv6_accept_ra", V_NUM },
656 { "ipv6_tun_addr", V_IPV6(1) },
657 { "ipv6_tun_addrlen", V_RANGE(3, 127) },
658 { "ipv6_ifname", V_LENGTH(0, 8) },
659 { "ipv6_tun_v4end", V_IP },
660 { "ipv6_relay", V_RANGE(1, 254) },
661 { "ipv6_tun_mtu", V_NUM }, // Tunnel MTU
662 { "ipv6_tun_ttl", V_NUM }, // Tunnel TTL
663 { "ipv6_dns", V_LENGTH(0, 40*3) }, // ip6 ip6 ip6
664 #endif
666 // basic-wfilter
667 { "wl_macmode", V_NONE }, // allow, deny, disabled
668 { "wl_maclist", V_LENGTH(0, 18*251) }, // 18 x 250 (11:22:33:44:55:66 ...)
669 { "macnames", V_LENGTH(0, 62*251) }, // 62 (12+1+48+1) x 50 (112233445566<..>) todo: re-use -- zzz
671 // advanced-ctnf
672 { "ct_max", V_NUM },
673 { "ct_tcp_timeout", V_LENGTH(20, 70) },
674 { "ct_udp_timeout", V_LENGTH(5, 15) },
675 { "ct_timeout", V_LENGTH(5, 15) },
676 { "nf_ttl", V_LENGTH(1, 6) },
677 { "nf_l7in", V_01 },
678 #ifdef LINUX26
679 { "nf_sip", V_01 },
680 { "ct_hashsize", V_NUM },
681 #endif
682 { "nf_rtsp", V_01 },
683 { "nf_pptp", V_01 },
684 { "nf_h323", V_01 },
685 { "nf_ftp", V_01 },
687 // advanced-dhcpdns
688 { "dhcpd_slt", V_RANGE(-1, 43200) }, // -1=infinite, 0=follow normal lease time, >=1 custom
689 { "dhcpd_dmdns", V_01 },
690 { "dhcpd_lmax", V_NUM },
691 { "dhcpd_gwmode", V_NUM },
692 { "dns_addget", V_01 },
693 { "dns_intcpt", V_01 },
694 { "dhcpc_minpkt", V_01 },
695 { "dhcpc_custom", V_LENGTH(0, 80) },
696 { "dns_norebind", V_01 },
697 { "dnsmasq_custom", V_TEXT(0, 2048) },
698 { "dhcpd_static_only", V_01 },
699 // { "dnsmasq_norw", V_01 },
701 // advanced-firewall
702 { "block_wan", V_01 },
703 { "multicast_pass", V_01 },
704 #ifdef TCONFIG_VLAN
705 { "multicast_lan", V_01 },
706 { "multicast_lan1", V_01 },
707 { "multicast_lan2", V_01 },
708 { "multicast_lan3", V_01 },
709 #endif
710 { "block_loopback", V_01 },
711 { "nf_loopback", V_NUM },
712 { "ne_syncookies", V_01 },
713 { "dhcp_pass", V_01 },
714 #ifdef TCONFIG_EMF
715 { "emf_entry", V_NONE },
716 { "emf_uffp_entry", V_NONE },
717 { "emf_rtport_entry", V_NONE },
718 { "emf_enable", V_01 },
719 #endif
721 // advanced-misc
722 { "wait_time", V_RANGE(3, 20) },
723 { "wan_speed", V_RANGE(0, 4) },
724 { "clkfreq", V_NONE }, // Toastman
725 { "jumbo_frame_enable", V_01 }, // Jumbo Frames support (for RT-N16/WNR3500L)
726 { "jumbo_frame_size", V_RANGE(1, 9720) },
727 #ifdef CONFIG_BCMWL5
728 { "ctf_disable", V_01 },
729 #endif
731 #ifdef TCONFIG_VLAN
732 // advanced-vlan
733 { "vlan0ports", V_TEXT(0,16) },
734 { "vlan1ports", V_TEXT(0,16) },
735 { "vlan2ports", V_TEXT(0,16) },
736 { "vlan3ports", V_TEXT(0,16) },
737 { "vlan4ports", V_TEXT(0,16) },
738 { "vlan5ports", V_TEXT(0,16) },
739 { "vlan6ports", V_TEXT(0,16) },
740 { "vlan7ports", V_TEXT(0,16) },
741 { "vlan8ports", V_TEXT(0,16) },
742 { "vlan9ports", V_TEXT(0,16) },
743 { "vlan10ports", V_TEXT(0,16) },
744 { "vlan11ports", V_TEXT(0,16) },
745 { "vlan12ports", V_TEXT(0,16) },
746 { "vlan13ports", V_TEXT(0,16) },
747 { "vlan14ports", V_TEXT(0,16) },
748 { "vlan15ports", V_TEXT(0,16) },
749 { "vlan0hwname", V_TEXT(0,8) },
750 { "vlan1hwname", V_TEXT(0,8) },
751 { "vlan2hwname", V_TEXT(0,8) },
752 { "vlan3hwname", V_TEXT(0,8) },
753 { "vlan4hwname", V_TEXT(0,8) },
754 { "vlan5hwname", V_TEXT(0,8) },
755 { "vlan6hwname", V_TEXT(0,8) },
756 { "vlan7hwname", V_TEXT(0,8) },
757 { "vlan8hwname", V_TEXT(0,8) },
758 { "vlan9hwname", V_TEXT(0,8) },
759 { "vlan10hwname", V_TEXT(0,8) },
760 { "vlan11hwname", V_TEXT(0,8) },
761 { "vlan12hwname", V_TEXT(0,8) },
762 { "vlan13hwname", V_TEXT(0,8) },
763 { "vlan14hwname", V_TEXT(0,8) },
764 { "vlan15hwname", V_TEXT(0,8) },
765 { "wan_ifnameX", V_TEXT(0,8) },
766 { "lan_ifnames", V_TEXT(0,64) },
767 { "manual_boot_nv", V_01 },
768 { "trunk_vlan_so", V_01 },
769 #endif
771 // advanced-mac
772 { "mac_wan", V_LENGTH(0, 17) },
773 { "wl_macaddr", V_LENGTH(0, 17) },
774 { "wl_hwaddr", V_LENGTH(0, 17) },
776 // advanced-routing
777 { "routes_static", V_LENGTH(0, 2048) },
778 { "dhcp_routes", V_01 },
779 { "lan_stp", V_RANGE(0, 1) },
780 { "wk_mode", V_LENGTH(1, 32) }, // gateway, router
781 #ifdef TCONFIG_ZEBRA
782 { "dr_setting", V_RANGE(0, 3) },
783 { "dr_lan_tx", V_LENGTH(0, 32) },
784 { "dr_lan_rx", V_LENGTH(0, 32) },
785 #ifdef TCONFIG_VLAN
786 { "dr_lan1_tx", V_LENGTH(0, 32) },
787 { "dr_lan1_rx", V_LENGTH(0, 32) },
788 { "dr_lan2_tx", V_LENGTH(0, 32) },
789 { "dr_lan2_rx", V_LENGTH(0, 32) },
790 { "dr_lan3_tx", V_LENGTH(0, 32) },
791 { "dr_lan3_rx", V_LENGTH(0, 32) },
792 #endif
793 { "dr_wan_tx", V_LENGTH(0, 32) },
794 { "dr_wan_rx", V_LENGTH(0, 32) },
795 #endif
797 #ifdef TCONFIG_VLAN
798 // advanced-access
799 { "lan_access", V_LENGTH(0, 4096) },
800 #endif
802 // advanced-wireless
803 { "wl_country", V_LENGTH(0, 64) }, // !!TB - Country code
804 { "wl_country_code", V_LENGTH(0, 4) }, // !!TB - Country code
805 { "wl_btc_mode", V_RANGE(0, 2) }, // !!TB - BT Coexistence Mode: 0 (disable), 1 (enable), 2 (preemption)
806 { "wl_afterburner", V_LENGTH(2, 4) }, // off, on, auto
807 { "wl_auth", V_01 },
808 { "wl_rateset", V_LENGTH(2, 7) }, // all, default, 12
809 { "wl_rate", V_RANGE(0, 54 * 1000 * 1000) },
810 { "wl_mrate", V_RANGE(0, 54 * 1000 * 1000) },
811 { "wl_gmode_protection",V_LENGTH(3, 4) }, // off, auto
812 { "wl_frameburst", V_ONOFF }, // off, on
813 { "wl_bcn", V_RANGE(1, 65535) },
814 { "wl_dtim", V_RANGE(1, 255) },
815 { "wl_frag", V_RANGE(256, 2346) },
816 { "wl_rts", V_RANGE(0, 2347) },
817 { "wl_ap_isolate", V_01 },
818 { "wl_plcphdr", V_LENGTH(4, 5) }, // long, short
819 { "wl_antdiv", V_RANGE(0, 3) },
820 { "wl_txant", V_RANGE(0, 3) },
821 { "wl_txpwr", V_RANGE(0, 400) },
822 { "wl_wme", V_WORD }, // auto, off, on
823 { "wl_wme_no_ack", V_ONOFF }, // off, on
824 { "wl_wme_apsd", V_ONOFF }, // off, on
825 { "wl_maxassoc", V_RANGE(0, 255) },
826 { "wl_distance", V_LENGTH(0, 5) }, // "", 1-99999
827 { "wlx_hpamp", V_01 },
828 { "wlx_hperx", V_01 },
829 { "wl_reg_mode", V_LENGTH(1, 3) }, // !!TB - Regulatory: off, h, d
830 { "wl_mitigation", V_RANGE(0, 4) }, // Interference Mitigation Mode (0|1|2|3|4)
832 { "wl_nmode_protection", V_WORD, }, // off, auto
833 { "wl_nmcsidx", V_RANGE(-2, 32), }, // -2 - 32
834 { "wl_obss_coex", V_01 },
835 { "wl_wmf_bss_enable", V_01 }, // Toastman
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, 99) },
876 // { "rrule##", V_LENGTH(0, 16384) }, // 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_file_custom", V_01 },
966 { "log_file_path", V_TEXT(0, 4096) },
967 { "log_limit", V_RANGE(0, 2400) },
968 { "log_in", V_RANGE(0, 3) },
969 { "log_out", V_RANGE(0, 3) },
970 { "log_mark", V_RANGE(0, 99999) },
971 { "log_events", V_TEXT(0, 32) }, // "acre,crond,ntp"
973 // admin-log-webmonitor
974 { "log_wm", V_01 },
975 { "log_wmtype", V_RANGE(0, 2) },
976 { "log_wmip", V_LENGTH(0, 512) },
977 { "log_wmdmax", V_RANGE(0, 9999) },
978 { "log_wmsmax", V_RANGE(0, 9999) },
980 // admin-cifs
981 { "cifs1", V_LENGTH(1, 1024) },
982 { "cifs2", V_LENGTH(1, 1024) },
984 // admin-jffs2
985 { "jffs2_on", V_01 },
986 { "jffs2_exec", V_LENGTH(0, 64) },
987 { "jffs2_format", V_01 },
989 // nas-usb - !!TB
990 #ifdef TCONFIG_USB
991 { "usb_enable", V_01 },
992 { "usb_uhci", V_RANGE(-1, 1) }, // -1 - disabled, 0 - off, 1 - on
993 { "usb_ohci", V_RANGE(-1, 1) },
994 { "usb_usb2", V_RANGE(-1, 1) },
995 #if defined(LINUX26) && defined(TCONFIG_USB_EXTRAS)
996 { "usb_mmc", V_RANGE(-1, 1) },
997 #endif
998 { "usb_irq_thresh", V_RANGE(0, 6) },
999 { "usb_storage", V_01 },
1000 { "usb_printer", V_01 },
1001 { "usb_printer_bidirect", V_01 },
1002 { "usb_fs_ext3", V_01 },
1003 { "usb_fs_fat", V_01 },
1004 #ifdef TCONFIG_NTFS
1005 { "usb_fs_ntfs", V_01 },
1006 #endif
1007 { "usb_fs_hfs", V_01 }, //!Victek
1008 { "usb_fs_hfsplus", V_01 }, //!Victek
1009 { "usb_automount", V_01 },
1010 { "script_usbhotplug", V_TEXT(0, 2048) },
1011 { "script_usbmount", V_TEXT(0, 2048) },
1012 { "script_usbumount", V_TEXT(0, 2048) },
1013 { "idle_enable", V_01 },
1014 #endif
1016 // nas-ftp - !!TB
1017 #ifdef TCONFIG_FTP
1018 { "ftp_enable", V_RANGE(0, 2) },
1019 { "ftp_super", V_01 },
1020 { "ftp_anonymous", V_RANGE(0, 3) },
1021 { "ftp_dirlist", V_RANGE(0, 2) },
1022 { "ftp_port", V_PORT },
1023 { "ftp_max", V_RANGE(0, 12) },
1024 { "ftp_ipmax", V_RANGE(0, 12) },
1025 { "ftp_staytimeout", V_RANGE(0, 65535) },
1026 { "ftp_rate", V_RANGE(0, 99999) },
1027 { "ftp_anonrate", V_RANGE(0, 99999) },
1028 { "ftp_anonroot", V_LENGTH(0, 256) },
1029 { "ftp_pubroot", V_LENGTH(0, 256) },
1030 { "ftp_pvtroot", V_LENGTH(0, 256) },
1031 { "ftp_users", V_LENGTH(0, 4096) },
1032 { "ftp_custom", V_TEXT(0, 2048) },
1033 { "ftp_sip", V_LENGTH(0, 512) },
1034 { "ftp_limit", V_TEXT(1, 50) },
1035 { "log_ftp", V_01 },
1036 #endif
1038 #ifdef TCONFIG_SNMP
1039 { "snmp_enable", V_RANGE(0, 1) },
1040 { "snmp_location", V_LENGTH(0, 20) },
1041 { "snmp_contact", V_LENGTH(0, 20) },
1042 { "snmp_ro", V_LENGTH(0, 20) },
1043 #endif
1045 #ifdef TCONFIG_SAMBASRV
1046 // nas-samba - !!TB
1047 { "smbd_enable", V_RANGE(0, 2) },
1048 { "smbd_wgroup", V_LENGTH(0, 20) },
1049 { "smbd_master", V_01 },
1050 { "smbd_wins", V_01 },
1051 { "smbd_cpage", V_LENGTH(0, 4) },
1052 { "smbd_cset", V_LENGTH(0, 20) },
1053 { "smbd_custom", V_TEXT(0, 2048) },
1054 { "smbd_autoshare", V_RANGE(0, 3) },
1055 { "smbd_shares", V_LENGTH(0, 4096) },
1056 { "smbd_user", V_LENGTH(0, 50) },
1057 { "smbd_passwd", V_LENGTH(0, 50) },
1058 #endif
1060 #ifdef TCONFIG_MEDIA_SERVER
1061 // nas-media
1062 { "ms_enable", V_01 },
1063 { "ms_dirs", V_LENGTH(0, 1024) },
1064 { "ms_port", V_RANGE(0, 65535) },
1065 { "ms_dbdir", V_LENGTH(0, 256) },
1066 { "ms_tivo", V_01 },
1067 { "ms_stdlna", V_01 },
1068 { "ms_rescan", V_01 },
1069 { "ms_sas", V_01 },
1070 #endif
1072 // qos
1073 { "qos_enable", V_01 },
1074 { "qos_pfifo", V_01 },
1075 { "qos_ack", V_01 },
1076 { "qos_syn", V_01 },
1077 { "qos_fin", V_01 },
1078 { "qos_rst", V_01 },
1079 { "qos_icmp", V_01 },
1080 { "qos_reset", V_01 },
1081 { "qos_pfifo", V_01 }, // !!TB
1082 { "qos_obw", V_RANGE(10, 999999) },
1083 { "qos_ibw", V_RANGE(10, 999999) },
1084 { "qos_orules", V_LENGTH(0, 8192) },
1085 { "qos_default", V_RANGE(0, 9) },
1086 { "qos_irates", V_LENGTH(0, 128) },
1087 { "qos_orates", V_LENGTH(0, 128) },
1088 { "qos_classnames", V_LENGTH(10, 128) }, // !!TOASTMAN
1090 { "ne_vegas", V_01 },
1091 { "ne_valpha", V_NUM },
1092 { "ne_vbeta", V_NUM },
1093 { "ne_vgamma", V_NUM },
1095 // qos-bw-limiter
1096 { "qosl_enable", V_01 },
1097 { "qosl_rules", V_LENGTH(0, 4096) },
1098 { "qosl_denable", V_01 },
1099 { "qosl_dulr", V_RANGE(0, 999999) },
1100 { "qosl_dulc", V_RANGE(0, 999999) },
1101 { "qosl_ddlr", V_RANGE(0, 999999) },
1102 { "qosl_ddlc", V_RANGE(0, 999999) },
1103 { "qosl_dtcp", V_RANGE(0, 1000) },
1104 { "qosl_dudp", V_RANGE(0, 100) },
1105 /*qosl_ibw unused - qos_ibw shared*/
1106 /*qosl_obw unused - qos_obw shared*/
1108 //NoCatSplash. Victek.
1109 #ifdef TCONFIG_NOCAT
1110 { "NC_enable", V_01 },
1111 { "NC_Verbosity", V_RANGE(0, 10) },
1112 { "NC_GatewayName", V_LENGTH(0, 255) },
1113 { "NC_GatewayPort", V_PORT },
1114 { "NC_ForcedRedirect", V_01 },
1115 { "NC_HomePage", V_LENGTH(0, 255) },
1116 { "NC_DocumentRoot", V_LENGTH(0, 255) },
1117 { "NC_SplashURL", V_LENGTH(0, 255) },
1118 { "NC_LoginTimeout", V_RANGE(0, 86400000) },
1119 { "NC_IdleTimeout", V_RANGE(0, 86400000) },
1120 { "NC_MaxMissedARP", V_RANGE(0, 10) },
1121 { "NC_PeerChecktimeout", V_RANGE(0, 60) },
1122 { "NC_ExcludePorts", V_LENGTH(0, 255) },
1123 { "NC_IncludePorts", V_LENGTH(0, 255) },
1124 { "NC_AllowedWebHosts", V_LENGTH(0, 255) },
1125 { "NC_MACWhiteList", V_LENGTH(0, 255) },
1126 { "NC_SplashFile", V_LENGTH(0, 8192) },
1127 #endif
1129 #ifdef TCONFIG_OPENVPN
1130 // vpn
1131 { "vpn_debug", V_01 },
1132 { "vpn_server_eas", V_NONE },
1133 { "vpn_server_dns", V_NONE },
1134 { "vpn_server1_poll", V_RANGE(0, 1440) },
1135 { "vpn_server1_if", V_TEXT(3, 3) }, // tap, tun
1136 { "vpn_server1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1137 { "vpn_server1_port", V_PORT },
1138 { "vpn_server1_firewall", V_TEXT(0, 8) }, // auto, external, custom
1139 { "vpn_server1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1140 { "vpn_server1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1141 { "vpn_server1_cipher", V_TEXT(0, 16) },
1142 { "vpn_server1_dhcp", V_01 },
1143 { "vpn_server1_r1", V_IP },
1144 { "vpn_server1_r2", V_IP },
1145 { "vpn_server1_sn", V_IP },
1146 { "vpn_server1_nm", V_IP },
1147 { "vpn_server1_local", V_IP },
1148 { "vpn_server1_remote", V_IP },
1149 { "vpn_server1_reneg", V_RANGE(-1,2147483647)},
1150 { "vpn_server1_hmac", V_RANGE(-1, 2) },
1151 { "vpn_server1_plan", V_01 },
1152 { "vpn_server1_ccd", V_01 },
1153 { "vpn_server1_c2c", V_01 },
1154 { "vpn_server1_ccd_excl", V_01 },
1155 { "vpn_server1_ccd_val", V_NONE },
1156 { "vpn_server1_pdns", V_01 },
1157 { "vpn_server1_rgw", V_01 },
1158 { "vpn_server1_custom", V_NONE },
1159 { "vpn_server1_static", V_NONE },
1160 { "vpn_server1_ca", V_NONE },
1161 { "vpn_server1_crt", V_NONE },
1162 { "vpn_server1_key", V_NONE },
1163 { "vpn_server1_dh", V_NONE },
1164 { "vpn_server2_poll", V_RANGE(0, 1440) },
1165 { "vpn_server2_if", V_TEXT(3, 3) }, // tap, tun
1166 { "vpn_server2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1167 { "vpn_server2_port", V_PORT },
1168 { "vpn_server2_firewall", V_TEXT(0, 8) }, // auto, external, custom
1169 { "vpn_server2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1170 { "vpn_server2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1171 { "vpn_server2_cipher", V_TEXT(0, 16) },
1172 { "vpn_server2_dhcp", V_01 },
1173 { "vpn_server2_r1", V_IP },
1174 { "vpn_server2_r2", V_IP },
1175 { "vpn_server2_sn", V_IP },
1176 { "vpn_server2_nm", V_IP },
1177 { "vpn_server2_local", V_IP },
1178 { "vpn_server2_remote", V_IP },
1179 { "vpn_server2_reneg", V_RANGE(-1,2147483647)},
1180 { "vpn_server2_hmac", V_RANGE(-1, 2) },
1181 { "vpn_server2_plan", V_01 },
1182 { "vpn_server2_pdns", V_01 },
1183 { "vpn_server2_rgw", V_01 },
1184 { "vpn_server2_custom", V_NONE },
1185 { "vpn_server2_ccd", V_01 },
1186 { "vpn_server2_c2c", V_01 },
1187 { "vpn_server2_ccd_excl", V_01 },
1188 { "vpn_server2_ccd_val", V_NONE },
1189 { "vpn_server2_static", V_NONE },
1190 { "vpn_server2_ca", V_NONE },
1191 { "vpn_server2_crt", V_NONE },
1192 { "vpn_server2_key", V_NONE },
1193 { "vpn_server2_dh", V_NONE },
1194 { "vpn_client_eas", V_NONE },
1195 { "vpn_client1_poll", V_RANGE(0, 1440) },
1196 { "vpn_client1_if", V_TEXT(3, 3) }, // tap, tun
1197 { "vpn_client1_bridge", V_01 },
1198 { "vpn_client1_nat", V_01 },
1199 { "vpn_client1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1200 { "vpn_client1_addr", V_NONE },
1201 { "vpn_client1_port", V_PORT },
1202 { "vpn_client1_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1203 { "vpn_client1_firewall", V_TEXT(0, 6) }, // auto, custom
1204 { "vpn_client1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1205 { "vpn_client1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1206 { "vpn_client1_cipher", V_TEXT(0, 16) },
1207 { "vpn_client1_local", V_IP },
1208 { "vpn_client1_remote", V_IP },
1209 { "vpn_client1_nm", V_IP },
1210 { "vpn_client1_reneg", V_RANGE(-1,2147483647)},
1211 { "vpn_client1_hmac", V_RANGE(-1, 2) },
1212 { "vpn_client1_adns", V_RANGE(0, 3) },
1213 { "vpn_client1_rgw", V_01 },
1214 { "vpn_client1_gw", V_TEXT(0, 15) },
1215 { "vpn_client1_custom", V_NONE },
1216 { "vpn_client1_static", V_NONE },
1217 { "vpn_client1_ca", V_NONE },
1218 { "vpn_client1_crt", V_NONE },
1219 { "vpn_client1_key", V_NONE },
1220 { "vpn_client2_poll", V_RANGE(0, 1440) },
1221 { "vpn_client2_if", V_TEXT(3, 3) }, // tap, tun
1222 { "vpn_client2_bridge", V_01 },
1223 { "vpn_client2_nat", V_01 },
1224 { "vpn_client2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1225 { "vpn_client2_addr", V_NONE },
1226 { "vpn_client2_port", V_PORT },
1227 { "vpn_client2_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1228 { "vpn_client2_firewall", V_TEXT(0, 6) }, // auto, custom
1229 { "vpn_client2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1230 { "vpn_client2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1231 { "vpn_client2_cipher", V_TEXT(0, 16) },
1232 { "vpn_client2_local", V_IP },
1233 { "vpn_client2_remote", V_IP },
1234 { "vpn_client2_nm", V_IP },
1235 { "vpn_client2_reneg", V_RANGE(-1,2147483647)},
1236 { "vpn_client2_hmac", V_RANGE(-1, 2) },
1237 { "vpn_client2_adns", V_RANGE(0, 3) },
1238 { "vpn_client2_rgw", V_01 },
1239 { "vpn_client2_gw", V_TEXT(0, 15) },
1240 { "vpn_client2_custom", V_NONE },
1241 { "vpn_client2_static", V_NONE },
1242 { "vpn_client2_ca", V_NONE },
1243 { "vpn_client2_crt", V_NONE },
1244 { "vpn_client2_key", V_NONE },
1245 #endif // vpn
1250 ppp_static 0/1
1251 ppp_static_ip IP
1252 wl_enable 0/1
1253 wl_wds_timeout
1254 wl_maxassoc 1-256
1255 wl_phytype a,b,g
1256 wl_net_reauth
1257 wl_preauth
1258 wl_wme_ap_bk
1259 wl_wme_ap_be
1260 wl_wme_ap_vi
1261 wl_wme_ap_vo
1262 wl_wme_sta_bk
1263 wl_wme_sta_be
1264 wl_wme_sta_vi
1265 wl_wme_sta_vo
1267 port_priority_1 0-2
1268 port_flow_control_1 0,1
1269 port_rate_limit_1 0-8
1270 port_priority_2 0-2
1271 port_flow_control_2 0,1
1272 port_rate_limit_2 0-8
1273 port_priority_3 0-2
1274 port_flow_control_3 0,1
1275 port_rate_limit_3 0-8
1276 port_priority_4 0-2
1277 port_flow_control_4 0,1
1278 port_rate_limit_4 0-8
1279 wl_ap_ip
1280 wl_ap_ssid
1282 { "pptp_client_enable", V_01 },
1283 { "pptp_client_peerdns", V_RANGE(0,2) },
1284 { "pptp_client_mtuenable",V_01 },
1285 { "pptp_client_mtu", V_RANGE(576, 1500) },
1286 { "pptp_client_mruenable",V_01 },
1287 { "pptp_client_mru", V_RANGE(576, 1500) },
1288 { "pptp_client_nat", V_01 },
1289 { "pptp_client_srvip", V_NONE },
1290 { "pptp_client_srvsub", V_IP },
1291 { "pptp_client_srvsubmsk",V_IP },
1292 { "pptp_client_username", V_TEXT(0,50) },
1293 { "pptp_client_passwd", V_TEXT(0,50) },
1294 { "pptp_client_crypt", V_RANGE(0, 3) },
1295 { "pptp_client_custom", V_NONE },
1296 { "pptp_client_dfltroute",V_01 },
1297 { "pptp_client_stateless",V_01 },
1299 { NULL }
1303 static int webcgi_nvram_set(const nvset_t *v, const char *name, int write)
1305 char *p, *e;
1306 int n;
1307 long l;
1308 unsigned u[6];
1309 int ok;
1310 int dirty;
1311 #ifdef TCONFIG_IPV6
1312 struct in6_addr addr;
1313 #endif
1315 if ((p = webcgi_get((char*)name)) == NULL) return 0;
1317 _dprintf("[%s] %s=%s\n", v->name, (char*)name, p);
1318 dirty = 0;
1319 ok = 1;
1320 switch (v->vtype) {
1321 case VT_TEXT:
1322 p = unix_string(p); // NOTE: p = malloc'd
1323 // drop
1324 case VT_LENGTH:
1325 n = strlen(p);
1326 if ((n < v->va.i) || (n > v->vb.i)) ok = 0;
1327 break;
1328 case VT_RANGE:
1329 l = strtol(p, &e, 10);
1330 if ((p == e) || (*e) || (l < v->va.l) || (l > v->vb.l)) ok = 0;
1331 break;
1332 case VT_IP:
1333 if ((sscanf(p, "%3u.%3u.%3u.%3u", &u[0], &u[1], &u[2], &u[3]) != 4) ||
1334 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255)) ok = 0;
1335 break;
1336 case VT_MAC:
1337 if ((sscanf(p, "%2x:%2x:%2x:%2x:%2x:%2x", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]) != 6) ||
1338 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255) || (u[4] > 255) || (u[5] > 255)) ok = 0;
1339 break;
1340 #ifdef TCONFIG_IPV6
1341 case VT_IPV6:
1342 if (strlen(p) > 0 || v->va.i) {
1343 if (inet_pton(AF_INET6, p, &addr) != 1) ok = 0;
1345 break;
1346 #endif
1347 default:
1348 // shutup gcc
1349 break;
1351 if (!ok) {
1352 if (v->vtype == VT_TEXT) free(p);
1353 return -1;
1355 if (write) {
1356 if (!nvram_match((char *)name, p)) {
1357 if (v->vtype != VT_TEMP) dirty = 1;
1358 DEBUG_NVRAMSET(name, p);
1359 nvram_set(name, p);
1362 if (v->vtype == VT_TEXT) free(p);
1364 return dirty;
1367 typedef struct {
1368 const nvset_t *v;
1369 int write;
1370 int dirty;
1371 } nv_list_t;
1373 static int nv_wl_find(int idx, int unit, int subunit, void *param)
1375 nv_list_t *p = param;
1377 int ok = webcgi_nvram_set(p->v, wl_nvname(p->v->name + 3, unit, subunit), p->write);
1378 if (ok < 0)
1379 return 1;
1380 else {
1381 p->dirty |= ok;
1382 return 0;
1386 static int save_variables(int write)
1388 const nvset_t *v;
1389 char *p;
1390 int n;
1391 int ok;
1392 char s[256];
1393 int dirty;
1394 static const char *msgf = "The field \"%s\" is invalid. Please report this problem.";
1395 nv_list_t nv;
1397 dirty = 0;
1398 nv.write = write;
1399 for (v = nvset_list; v->name; ++v) {
1400 ok = webcgi_nvram_set(v, v->name, write);
1402 if ((ok >= 0) && (strncmp(v->name, "wl_", 3) == 0)) {
1403 nv.dirty = dirty;
1404 nv.v = v;
1405 if (foreach_wif(1, &nv, nv_wl_find) == 0)
1406 ok |= nv.dirty;
1407 else
1408 ok = -1;
1411 if (ok < 0) {
1412 sprintf(s, msgf, v->name);
1413 resmsg_set(s);
1414 return 0;
1416 dirty |= ok;
1419 // special cases
1421 char *p1, *p2;
1422 if (((p1 = webcgi_get("set_password_1")) != NULL) && (strcmp(p1, "**********") != 0)) {
1423 if (((p2 = webcgi_get("set_password_2")) != NULL) && (strcmp(p1, p2) == 0)) {
1424 if ((write) && (!nvram_match("http_passwd", p1))) {
1425 dirty = 1;
1426 nvram_set("http_passwd", p1);
1429 else {
1430 sprintf(s, msgf, "password");
1431 resmsg_set(s);
1432 return 0;
1436 for (n = 0; n < 50; ++n) {
1437 sprintf(s, "rrule%d", n);
1438 if ((p = webcgi_get(s)) != NULL) {
1439 if (strlen(p) > 8192) { //Toastman
1440 sprintf(s, msgf, s);
1441 resmsg_set(s);
1442 return 0;
1444 if ((write) && (!nvram_match(s, p))) {
1445 dirty = 1;
1446 DEBUG_NVRAMSET(s, p);
1447 nvram_set(s, p);
1452 return (write) ? dirty : 1;
1455 static void wo_tomato(char *url)
1457 char *v;
1458 int i;
1459 int ajax;
1460 int nvset;
1461 const char *red;
1462 int commit;
1464 // _dprintf("tomato.cgi\n");
1466 red = webcgi_safeget("_redirect", "");
1467 if (!*red) send_header(200, NULL, mime_html, 0);
1469 commit = atoi(webcgi_safeget("_commit", "1"));
1470 ajax = atoi(webcgi_safeget("_ajax", "0"));
1472 nvset = atoi(webcgi_safeget("_nvset", "1"));
1473 if (nvset) {
1474 if (!save_variables(0)) {
1475 if (ajax) {
1476 web_printf("@msg:%s", resmsg_get());
1478 else {
1479 parse_asp("error.asp");
1481 return;
1483 commit = save_variables(1) && commit;
1485 resmsg_set("Settings saved.");
1488 rboot = atoi(webcgi_safeget("_reboot", "0"));
1489 if (rboot) {
1490 parse_asp("reboot.asp");
1492 else {
1493 if (ajax) {
1494 web_printf("@msg:%s", resmsg_get());
1496 else if (atoi(webcgi_safeget("_moveip", "0"))) {
1497 parse_asp("saved-moved.asp");
1499 else if (!*red) {
1500 parse_asp("saved.asp");
1504 if (commit) {
1505 _dprintf("commit from tomato.cgi\n");
1506 nvram_commit_x();
1509 if ((v = webcgi_get("_service")) != NULL && *v != 0) {
1510 if (!*red) {
1511 if (ajax) web_printf(" Some services are being restarted...");
1512 web_close();
1514 sleep(1);
1516 if (*v == '*') {
1517 kill(1, SIGHUP);
1519 else {
1520 exec_service(v);
1524 for (i = atoi(webcgi_safeget("_sleep", "0")); i > 0; --i) sleep(1);
1526 if (*red) redirect(red);
1528 if (rboot) {
1529 web_close();
1530 sleep(1);
1531 kill(1, SIGTERM);
1536 // ----------------------------------------------------------------------------
1539 static void wo_update(char *url)
1541 const aspapi_t *api;
1542 const char *name;
1543 int argc;
1544 char *argv[16];
1545 char s[32];
1547 if ((name = webcgi_get("exec")) != NULL) {
1548 for (api = aspapi; api->name; ++api) {
1549 if (strcmp(api->name, name) == 0) {
1550 for (argc = 0; argc < 16; ++argc) {
1551 sprintf(s, "arg%d", argc);
1552 if ((argv[argc] = (char *)webcgi_get(s)) == NULL) break;
1554 api->exec(argc, argv);
1555 break;
1561 static void wo_service(char *url)
1563 int n;
1565 exec_service(webcgi_safeget("_service", ""));
1567 if ((n = atoi(webcgi_safeget("_sleep", "2"))) <= 0) n = 2;
1568 sleep(n);
1570 common_redirect();
1573 static void wo_shutdown(char *url)
1575 parse_asp("shutdown.asp");
1576 web_close();
1577 sleep(1);
1579 kill(1, SIGQUIT);
1582 static void wo_nvcommit(char *url)
1584 parse_asp("saved.asp");
1585 web_close();
1586 nvram_commit();