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