cosmetics
[tomato.git] / release / src / router / httpd / tomato.c
blob205a68069d61a7a5c836b6557cf6129d4aa007eb
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 { "climon", asp_climon },
370 { "notice", asp_notice },
371 { "nv", asp_nv },
372 { "nvram", asp_nvram },
373 { "nvramseq", asp_nvramseq },
374 { "nvstat", asp_nvstat },
375 { "psup", asp_psup },
376 { "qrate", asp_qrate },
377 { "resmsg", asp_resmsg },
378 { "rrule", asp_rrule },
379 { "statfs", asp_statfs },
380 { "sysinfo", asp_sysinfo },
381 { "time", asp_time },
382 { "upnpinfo", asp_upnpinfo },
383 { "version", asp_version },
384 { "wanstatus", asp_wanstatus },
385 { "wanup", asp_wanup },
386 { "wlstats", asp_wlstats },
387 { "wlclient", asp_wlclient },
388 { "wlnoise", asp_wlnoise },
389 { "wlscan", asp_wlscan },
390 { "wlchannels", asp_wlchannels }, //!!TB
391 { "wlcountries", asp_wlcountries },
392 { "wlifaces", asp_wlifaces },
393 { "wlbands", asp_wlbands },
394 #ifdef TCONFIG_USB
395 { "usbdevices", asp_usbdevices }, //!!TB - USB Support
396 #endif
397 { "css", asp_css },
398 { NULL, NULL }
401 // -----------------------------------------------------------------------------
403 static void asp_css(int argc, char **argv)
405 const char *css = nvram_safe_get("web_css");
407 if (strcmp(css, "tomato") != 0) {
408 web_printf("<link rel='stylesheet' type='text/css' href='%s.css'>", css);
412 // -----------------------------------------------------------------------------
414 const char *resmsg_get(void)
416 return webcgi_safeget("resmsg", "");
419 void resmsg_set(const char *msg)
421 webcgi_set("resmsg", strdup(msg)); // m ok
424 int resmsg_fread(const char *fname)
426 char s[256];
427 char *p;
429 f_read_string(fname, s, sizeof(s));
430 if ((p = strchr(s, '\n')) != NULL) *p = 0;
431 if (s[0]) {
432 resmsg_set(s);
433 return 1;
435 return 0;
438 static void asp_resmsg(int argc, char **argv)
440 char *p;
442 if ((p = js_string(webcgi_safeget("resmsg", (argc > 0) ? argv[0] : ""))) == NULL) return;
443 web_printf("\nresmsg='%s';\n", p);
444 free(p);
447 // ----------------------------------------------------------------------------
449 // verification... simple sanity checks. UI should verify all fields.
451 // todo: move and re-use for filtering - zzz
453 typedef union {
454 int i;
455 long l;
456 const char *s;
457 } nvset_varg_t;
459 typedef struct {
460 const char *name;
461 enum {
462 VT_NONE, // no checking
463 VT_LENGTH, // check length of string
464 VT_TEXT, // strip \r, check length of string
465 VT_RANGE, // expect an integer, check range
466 VT_IP, // expect an ip address
467 VT_MAC, // expect a mac address
468 #ifdef TCONFIG_IPV6
469 VT_IPV6, // expect an ipv6 address
470 #endif
471 VT_TEMP // no checks, no commit
472 } vtype;
473 nvset_varg_t va;
474 nvset_varg_t vb;
475 } nvset_t;
478 #define V_NONE VT_NONE, { }, { }
479 #define V_01 VT_RANGE, { .l = 0 }, { .l = 1 }
480 #define V_PORT VT_RANGE, { .l = 2 }, { .l = 65535 }
481 #define V_ONOFF VT_LENGTH, { .i = 2 }, { .i = 3 }
482 #define V_WORD VT_LENGTH, { .i = 1 }, { .i = 16 }
483 #define V_LENGTH(min, max) VT_LENGTH, { .i = min }, { .i = max }
484 #define V_TEXT(min, max) VT_TEXT, { .i = min }, { .i = max }
485 #define V_RANGE(min, max) VT_RANGE, { .l = min }, { .l = max }
486 #define V_IP VT_IP, { }, { }
487 #define V_OCTET VT_RANGE, { .l = 0 }, { .l = 255 }
488 #define V_NUM VT_RANGE, { .l = 0 }, { .l = 0x7FFFFFFF }
489 #define V_TEMP VT_TEMP, { }, { }
490 #ifdef TCONFIG_IPV6
491 #define V_IPV6(required) VT_IPV6, { .i = required }, { }
492 #endif
494 static const nvset_t nvset_list[] = {
496 // basic-ident
497 { "router_name", V_LENGTH(0, 32) },
498 { "wan_hostname", V_LENGTH(0, 32) },
499 { "wan_domain", V_LENGTH(0, 32) },
501 // basic-time
502 { "tm_tz", V_LENGTH(1, 64) }, // PST8PDT
503 { "tm_sel", V_LENGTH(1, 64) }, // PST8PDT
504 { "tm_dst", V_01 },
505 { "ntp_updates", V_RANGE(-1, 24) },
506 { "ntp_tdod", V_01 },
507 { "ntp_server", V_LENGTH(1, 150) }, // x y z
508 { "ntp_kiss", V_LENGTH(0, 255) },
510 // basic-static
511 { "dhcpd_static", V_LENGTH(0, 106*251)}, // 106 (max chars per entry) x "n" entries
512 { "bwm_client", V_LENGTH(0, 4096) },
513 { "dhcpd_static_only", V_01 },
514 { "arpbind_static", V_LENGTH(0, 34*251)}, // 34 (max chars per entry) x n entries
516 // basic-ddns
517 { "ddnsx0", V_LENGTH(0, 2048) },
518 { "ddnsx1", V_LENGTH(0, 2048) },
519 { "ddnsx0_cache", V_LENGTH(0, 1) }, // only to clear
520 { "ddnsx1_cache", V_LENGTH(0, 1) },
521 { "ddnsx_ip", V_LENGTH(0, 32) },
522 { "ddnsx_save", V_01 },
523 { "ddnsx_refresh", V_RANGE(0, 365) },
525 // basic-network
526 // WAN
527 { "wan_proto", V_LENGTH(1, 16) }, // disabled, dhcp, static, pppoe, pptp, l2tp
528 { "wan_ipaddr", V_IP },
529 { "wan_netmask", V_IP },
530 { "wan_gateway", V_IP },
531 { "hb_server_ip", V_LENGTH(0, 32) },
532 { "l2tp_server_ip", V_LENGTH(0, 128) },
533 { "pptp_server_ip", V_LENGTH(0, 128) },
534 { "pptp_dhcp", V_01 },
535 { "ppp_username", V_LENGTH(0, 60) },
536 { "ppp_passwd", V_LENGTH(0, 60) },
537 { "ppp_service", V_LENGTH(0, 50) },
538 { "ppp_demand", V_01 },
539 { "ppp_custom", V_LENGTH(0, 256) },
540 { "ppp_idletime", V_RANGE(0, 1440) },
541 { "ppp_redialperiod", V_RANGE(1, 86400) },
542 { "mtu_enable", V_01 },
543 { "wan_mtu", V_RANGE(576, 1500) },
544 { "wan_islan", V_01 },
546 // LAN
547 { "lan_ipaddr", V_IP },
548 { "lan_netmask", V_IP },
549 { "lan_gateway", V_IP },
550 { "wan_dns", V_LENGTH(0, 50) }, // ip ip ip
551 { "lan_proto", V_WORD }, // static, dhcp
552 { "dhcp_start", V_RANGE(1, 254) }, // remove !
553 { "dhcp_num", V_RANGE(1, 255) }, // remove !
554 { "dhcpd_startip", V_IP },
555 { "dhcpd_endip", V_IP },
556 { "dhcp_lease", V_RANGE(1, 10080) },
557 { "wan_wins", V_IP },
559 // wireless
560 { "wl_radio", V_01 },
561 { "wl_mode", V_LENGTH(2, 3) }, // ap, sta, wet, wds
562 { "wl_net_mode", V_LENGTH(5, 8) }, // disabled, mixed, b-only, g-only, bg-mixed, n-only [speedbooster]
563 { "wl_ssid", V_LENGTH(1, 32) },
564 { "wl_closed", V_01 },
565 { "wl_channel", V_RANGE(0, 216) },
567 { "wl_security_mode", V_LENGTH(1, 32) }, // disabled, radius, wep, wpa_personal, wpa_enterprise, wpa2_personal, wpa2_enterprise
568 { "wl_radius_ipaddr", V_IP },
569 { "wl_radius_port", V_PORT },
570 { "wl_radius_key", V_LENGTH(1, 64) },
571 { "wl_wep_bit", V_RANGE(64, 128) }, // 64 or 128
572 { "wl_passphrase", V_LENGTH(0, 20) },
573 { "wl_key", V_RANGE(1, 4) },
574 { "wl_key1", V_LENGTH(0, 26) },
575 { "wl_key2", V_LENGTH(0, 26) },
576 { "wl_key3", V_LENGTH(0, 26) },
577 { "wl_key4", V_LENGTH(0, 26) },
578 { "wl_crypto", V_LENGTH(3, 8) }, // tkip, aes, tkip+aes
579 { "wl_wpa_psk", V_LENGTH(8, 64) },
580 { "wl_wpa_gtk_rekey", V_RANGE(60, 7200) },
582 { "wl_lazywds", V_01 },
583 { "wl_wds", V_LENGTH(0, 180) }, // mac mac mac (x 10)
585 { "wl_wds_enable", V_01 },
586 { "wl_gmode", V_RANGE(-1, 6) },
587 { "wl_wep", V_LENGTH(1, 32) }, // off, on, restricted,tkip,aes,tkip+aes
588 { "wl_akm", V_LENGTH(0, 32) }, // wpa, wpa2, psk, psk2, wpa wpa2, psk psk2, ""
589 { "wl_auth_mode", V_LENGTH(4, 6) }, // none, radius
591 { "wl_nmode", V_NONE },
592 { "wl_nband", V_RANGE(0, 2) }, // 2 - 2.4GHz, 1 - 5GHz, 0 - Auto
593 { "wl_nreqd", V_NONE },
594 { "wl_nbw_cap", V_RANGE(0, 2) }, // 0 - 20MHz, 1 - 40MHz, 2 - Auto
595 { "wl_nbw", V_NONE },
596 { "wl_mimo_preamble", V_WORD }, // 802.11n Preamble: mm/gf/auto/gfbcm
597 { "wl_nctrlsb", V_NONE }, // none, lower, upper
599 #ifdef TCONFIG_IPV6
600 // basic-ipv6
601 { "ipv6_service", V_LENGTH(0, 16) }, // '', native, native-pd, 6to4, sit, other
602 { "ipv6_prefix", V_IPV6(0) },
603 { "ipv6_prefix_length", V_RANGE(3, 127) },
604 { "ipv6_rtr_addr", V_IPV6(0) },
605 { "ipv6_radvd", V_01 },
606 { "ipv6_accept_ra", V_NUM },
607 { "ipv6_tun_addr", V_IPV6(1) },
608 { "ipv6_tun_addrlen", V_RANGE(3, 127) },
609 { "ipv6_ifname", V_LENGTH(0, 8) },
610 { "ipv6_tun_v4end", V_IP },
611 { "ipv6_relay", V_RANGE(1, 254) },
612 { "ipv6_tun_mtu", V_NUM }, // Tunnel MTU
613 { "ipv6_tun_ttl", V_NUM }, // Tunnel TTL
614 { "ipv6_dns", V_LENGTH(0, 40*3) }, // ip6 ip6 ip6
615 #endif
617 // basic-wfilter
618 { "wl_macmode", V_NONE }, // allow, deny, disabled
619 { "wl_maclist", V_LENGTH(0, 18*251) }, // 18 x 250 (11:22:33:44:55:66 ...)
620 { "macnames", V_LENGTH(0, 62*251) }, // 62 (12+1+48+1) x 50 (112233445566<..>) todo: re-use -- zzz
622 // advanced-ctnf
623 { "ct_max", V_NUM },
624 { "ct_tcp_timeout", V_LENGTH(20, 70) },
625 { "ct_udp_timeout", V_LENGTH(5, 15) },
626 { "ct_timeout", V_LENGTH(5, 15) },
627 { "nf_ttl", V_LENGTH(1, 6) },
628 { "nf_l7in", V_01 },
629 #ifdef LINUX26
630 { "nf_sip", V_01 },
631 { "ct_hashsize", V_NUM },
632 #endif
633 { "nf_rtsp", V_01 },
634 { "nf_pptp", V_01 },
635 { "nf_h323", V_01 },
636 { "nf_ftp", V_01 },
638 // advanced-dhcpdns
639 { "dhcpd_slt", V_RANGE(-1, 43200) }, // -1=infinite, 0=follow normal lease time, >=1 custom
640 { "dhcpd_dmdns", V_01 },
641 { "dhcpd_lmax", V_NUM },
642 { "dhcpd_gwmode", V_NUM },
643 { "dns_addget", V_01 },
644 { "dns_intcpt", V_01 },
645 { "dhcpc_minpkt", V_01 },
646 { "dhcpc_custom", V_LENGTH(0, 80) },
647 { "dns_norebind", V_01 },
648 { "dnsmasq_custom", V_TEXT(0, 2048) },
649 // { "dnsmasq_norw", V_01 },
651 // advanced-firewall
652 { "block_wan", V_01 },
653 { "multicast_pass", V_01 },
654 { "block_loopback", V_01 },
655 { "nf_loopback", V_NUM },
656 { "ne_syncookies", V_01 },
657 { "dhcp_pass", V_01 },
658 #ifdef TCONFIG_EMF
659 { "emf_entry", V_NONE },
660 { "emf_uffp_entry", V_NONE },
661 { "emf_rtport_entry", V_NONE },
662 { "emf_enable", V_01 },
663 #endif
665 // advanced-misc
666 { "wait_time", V_RANGE(3, 20) },
667 { "wan_speed", V_RANGE(0, 4) },
668 { "clkfreq", V_NONE }, // Toastman
669 { "jumbo_frame_enable", V_01 }, // Jumbo Frames support (for RT-N16/WNR3500L)
670 { "jumbo_frame_size", V_RANGE(1, 9720) },
671 #ifdef CONFIG_BCMWL5
672 { "ctf_disable", V_01 },
673 #endif
675 // advanced-mac
676 { "mac_wan", V_LENGTH(0, 17) },
677 { "wl_macaddr", V_LENGTH(0, 17) },
679 // advanced-routing
680 { "routes_static", V_LENGTH(0, 2048) },
681 { "dhcp_routes", V_01 },
682 { "lan_stp", V_RANGE(0, 1) },
683 { "wk_mode", V_LENGTH(1, 32) }, // gateway, router
684 #ifdef TCONFIG_ZEBRA
685 { "dr_setting", V_RANGE(0, 3) },
686 { "dr_lan_tx", V_LENGTH(0, 32) },
687 { "dr_lan_rx", V_LENGTH(0, 32) },
688 { "dr_wan_tx", V_LENGTH(0, 32) },
689 { "dr_wan_rx", V_LENGTH(0, 32) },
690 #endif
692 // advanced-wireless
693 { "wl_country", V_LENGTH(0, 64) }, // !!TB - Country code
694 { "wl_country_code", V_LENGTH(0, 4) }, // !!TB - Country code
695 { "wl_btc_mode", V_RANGE(0, 2) }, // !!TB - BT Coexistence Mode: 0 (disable), 1 (enable), 2 (preemption)
696 { "wl_afterburner", V_LENGTH(2, 4) }, // off, on, auto
697 { "wl_auth", V_01 },
698 { "wl_rateset", V_LENGTH(2, 7) }, // all, default, 12
699 { "wl_rate", V_RANGE(0, 54 * 1000 * 1000) },
700 { "wl_mrate", V_RANGE(0, 54 * 1000 * 1000) },
701 { "wl_gmode_protection",V_LENGTH(3, 4) }, // off, auto
702 { "wl_frameburst", V_ONOFF }, // off, on
703 { "wl_bcn", V_RANGE(1, 65535) },
704 { "wl_dtim", V_RANGE(1, 255) },
705 { "wl_frag", V_RANGE(256, 2346) },
706 { "wl_rts", V_RANGE(0, 2347) },
707 { "wl_ap_isolate", V_01 },
708 { "wl_plcphdr", V_LENGTH(4, 5) }, // long, short
709 { "wl_antdiv", V_RANGE(0, 3) },
710 { "wl_txant", V_RANGE(0, 3) },
711 { "wl_txpwr", V_RANGE(0, 400) },
712 { "wl_wme", V_WORD }, // auto, off, on
713 { "wl_wme_no_ack", V_ONOFF }, // off, on
714 { "wl_wme_apsd", V_ONOFF }, // off, on
715 { "wl_maxassoc", V_RANGE(0, 255) },
716 { "wl_distance", V_LENGTH(0, 5) }, // "", 1-99999
717 { "wlx_hpamp", V_01 },
718 { "wlx_hperx", V_01 },
719 { "wl_reg_mode", V_LENGTH(1, 3) }, // !!TB - Regulatory: off, h, d
720 { "wl_mitigation", V_RANGE(0, 3) }, // Interference Mitigation Mode (0|1|2|3)
722 { "wl_nmode_protection", V_WORD, }, // off, auto
723 { "wl_nmcsidx", V_RANGE(-2, 32), }, // -2 - 32
724 { "wl_obss_coex", V_01 },
726 // forward-dmz
727 { "dmz_enable", V_01 },
728 { "dmz_ipaddr", V_LENGTH(0, 15) },
729 { "dmz_sip", V_LENGTH(0, 512) },
731 // forward-upnp
732 { "upnp_enable", V_NUM },
733 { "upnp_secure", V_01 },
734 { "upnp_port", V_RANGE(0, 65535) },
735 { "upnp_ssdp_interval", V_RANGE(10, 9999) },
736 { "upnp_mnp", V_01 },
737 { "upnp_clean", V_01 },
738 { "upnp_clean_interval", V_RANGE(60, 65535) },
739 { "upnp_clean_threshold", V_RANGE(0, 9999) },
740 { "upnp_min_port_int", V_PORT },
741 { "upnp_max_port_int", V_PORT },
742 { "upnp_min_port_ext", V_PORT },
743 { "upnp_max_port_ext", V_PORT },
745 // forward-basic
746 { "portforward", V_LENGTH(0, 4096) },
748 #ifdef TCONFIG_IPV6
749 // forward-basic-ipv6
750 { "ipv6_portforward", V_LENGTH(0, 4096) },
751 #endif
753 // forward-triggered
754 { "trigforward", V_LENGTH(0, 4096) },
757 // access restriction
758 { "rruleN", V_RANGE(0, 99) },
759 // { "rrule##", V_LENGTH(0, 16384) }, // in save_variables()
761 // admin-access
762 { "http_enable", V_01 },
763 { "https_enable", V_01 },
764 { "https_crt_save", V_01 },
765 { "https_crt_cn", V_LENGTH(0, 64) },
766 { "https_crt_gen", V_TEMP },
767 { "remote_management", V_01 },
768 { "remote_mgt_https", V_01 },
769 { "http_lanport", V_PORT },
770 { "https_lanport", V_PORT },
771 { "web_wl_filter", V_01 },
772 { "web_css", V_LENGTH(1, 32) },
773 { "web_mx", V_LENGTH(0, 128) },
774 { "http_wanport", V_PORT },
775 { "telnetd_eas", V_01 },
776 { "telnetd_port", V_PORT },
777 { "sshd_eas", V_01 },
778 { "sshd_pass", V_01 },
779 { "sshd_port", V_PORT },
780 { "sshd_remote", V_01 },
781 { "sshd_forwarding", V_01 },
782 { "sshd_rport", V_PORT },
783 { "sshd_authkeys", V_TEXT(0, 4096) },
784 { "rmgt_sip", V_LENGTH(0, 512) },
785 { "ne_shlimit", V_TEXT(1, 50) },
787 // admin-bwm
788 { "rstats_enable", V_01 },
789 { "rstats_path", V_LENGTH(0, 48) },
790 { "rstats_stime", V_RANGE(1, 168) },
791 { "rstats_offset", V_RANGE(1, 31) },
792 { "rstats_exclude", V_LENGTH(0, 64) },
793 { "rstats_sshut", V_01 },
794 { "rstats_bak", V_01 },
796 // admin-buttons
797 { "sesx_led", V_RANGE(0, 255) }, // amber, white, aoss
798 { "sesx_b0", V_RANGE(0, 5) }, // 0-5: toggle wireless, reboot, shutdown, script, usb unmount
799 { "sesx_b1", V_RANGE(0, 5) }, // "
800 { "sesx_b2", V_RANGE(0, 5) }, // "
801 { "sesx_b3", V_RANGE(0, 5) }, // "
802 { "sesx_script", V_TEXT(0, 1024) }, //
803 { "script_brau", V_TEXT(0, 1024) }, //
805 // admin-debug
806 { "debug_nocommit", V_01 },
807 { "debug_cprintf", V_01 },
808 { "debug_cprintf_file", V_01 },
809 // { "debug_keepfiles", V_01 },
810 { "debug_ddns", V_01 },
811 { "debug_norestart", V_TEXT(0, 128) },
812 { "console_loglevel", V_RANGE(1, 8) },
813 { "t_cafree", V_01 },
814 { "t_hidelr", V_01 },
816 // admin-sched
817 { "sch_rboot", V_TEXT(0, 64) },
818 { "sch_rcon", V_TEXT(0, 64) },
819 { "sch_c1", V_TEXT(0, 64) },
820 { "sch_c1_cmd", V_TEXT(0, 2048) },
821 { "sch_c2", V_TEXT(0, 64) },
822 { "sch_c2_cmd", V_TEXT(0, 2048) },
823 { "sch_c3", V_TEXT(0, 64) },
824 { "sch_c3_cmd", V_TEXT(0, 2048) },
826 // admin-scripts
827 { "script_init", V_TEXT(0, 4096) },
828 { "script_shut", V_TEXT(0, 4096) },
829 { "script_fire", V_TEXT(0, 8192) },
830 { "script_wanup", V_TEXT(0, 4096) },
832 // admin-log
833 { "log_remote", V_01 },
834 { "log_remoteip", V_LENGTH(0, 512) },
835 { "log_remoteport", V_PORT },
836 { "log_file", V_01 },
837 { "log_file_custom", V_01 },
838 { "log_file_path", V_TEXT(0, 4096) },
839 { "log_limit", V_RANGE(0, 2400) },
840 { "log_in", V_RANGE(0, 3) },
841 { "log_out", V_RANGE(0, 3) },
842 { "log_mark", V_RANGE(0, 99999) },
843 { "log_events", V_TEXT(0, 32) }, // "acre,crond,ntp"
845 // admin-log-webmonitor
846 { "log_wm", V_01 },
847 { "log_wmtype", V_RANGE(0, 2) },
848 { "log_wmip", V_LENGTH(0, 512) },
849 { "log_wmdmax", V_RANGE(0, 9999) },
850 { "log_wmsmax", V_RANGE(0, 9999) },
852 // admin-cifs
853 { "cifs1", V_LENGTH(1, 1024) },
854 { "cifs2", V_LENGTH(1, 1024) },
856 // admin-jffs2
857 { "jffs2_on", V_01 },
858 { "jffs2_exec", V_LENGTH(0, 64) },
859 { "jffs2_format", V_01 },
861 // nas-usb - !!TB
862 #ifdef TCONFIG_USB
863 { "usb_enable", V_01 },
864 { "usb_uhci", V_RANGE(-1, 1) }, // -1 - disabled, 0 - off, 1 - on
865 { "usb_ohci", V_RANGE(-1, 1) },
866 { "usb_usb2", V_RANGE(-1, 1) },
867 { "usb_irq_thresh", V_RANGE(0, 6) },
868 { "usb_storage", V_01 },
869 { "usb_printer", V_01 },
870 { "usb_printer_bidirect", V_01 },
871 { "usb_fs_ext3", V_01 },
872 { "usb_fs_fat", V_01 },
873 #ifdef TCONFIG_NTFS
874 { "usb_fs_ntfs", V_01 },
875 #endif
876 { "usb_fs_hfs", V_01 }, //!Victek
877 { "usb_fs_hfsplus", V_01 }, //!Victek
878 { "usb_automount", V_01 },
879 { "script_usbhotplug", V_TEXT(0, 2048) },
880 { "script_usbmount", V_TEXT(0, 2048) },
881 { "script_usbumount", V_TEXT(0, 2048) },
882 { "idle_enable", V_01 },
883 #endif
885 // nas-ftp - !!TB
886 #ifdef TCONFIG_FTP
887 { "ftp_enable", V_RANGE(0, 2) },
888 { "ftp_super", V_01 },
889 { "ftp_anonymous", V_RANGE(0, 3) },
890 { "ftp_dirlist", V_RANGE(0, 2) },
891 { "ftp_port", V_PORT },
892 { "ftp_max", V_RANGE(0, 12) },
893 { "ftp_ipmax", V_RANGE(0, 12) },
894 { "ftp_staytimeout", V_RANGE(0, 65535) },
895 { "ftp_rate", V_RANGE(0, 99999) },
896 { "ftp_anonrate", V_RANGE(0, 99999) },
897 { "ftp_anonroot", V_LENGTH(0, 256) },
898 { "ftp_pubroot", V_LENGTH(0, 256) },
899 { "ftp_pvtroot", V_LENGTH(0, 256) },
900 { "ftp_users", V_LENGTH(0, 4096) },
901 { "ftp_custom", V_TEXT(0, 2048) },
902 { "ftp_sip", V_LENGTH(0, 512) },
903 { "ftp_limit", V_TEXT(1, 50) },
904 { "log_ftp", V_01 },
905 #endif
907 #ifdef TCONFIG_SNMP
908 { "snmp_enable", V_RANGE(0, 1) },
909 { "snmp_location", V_LENGTH(0, 20) },
910 { "snmp_contact", V_LENGTH(0, 20) },
911 { "snmp_ro", V_LENGTH(0, 20) },
912 #endif
914 #ifdef TCONFIG_SAMBASRV
915 // nas-samba - !!TB
916 { "smbd_enable", V_RANGE(0, 2) },
917 { "smbd_wgroup", V_LENGTH(0, 20) },
918 { "smbd_master", V_01 },
919 { "smbd_wins", V_01 },
920 { "smbd_cpage", V_LENGTH(0, 4) },
921 { "smbd_cset", V_LENGTH(0, 20) },
922 { "smbd_custom", V_TEXT(0, 2048) },
923 { "smbd_autoshare", V_RANGE(0, 3) },
924 { "smbd_shares", V_LENGTH(0, 4096) },
925 { "smbd_user", V_LENGTH(0, 50) },
926 { "smbd_passwd", V_LENGTH(0, 50) },
927 #endif
929 #ifdef TCONFIG_MEDIA_SERVER
930 // nas-media
931 { "ms_enable", V_01 },
932 { "ms_dirs", V_LENGTH(0, 1024) },
933 { "ms_port", V_RANGE(0, 65535) },
934 { "ms_dbdir", V_LENGTH(0, 256) },
935 { "ms_tivo", V_01 },
936 { "ms_stdlna", V_01 },
937 { "ms_rescan", V_01 },
938 { "ms_sas", V_01 },
939 #endif
941 // qos
942 { "qos_enable", V_01 },
943 { "qos_pfifo", V_01 },
944 { "qos_ack", V_01 },
945 { "qos_syn", V_01 },
946 { "qos_fin", V_01 },
947 { "qos_rst", V_01 },
948 { "qos_icmp", V_01 },
949 { "qos_reset", V_01 },
950 { "qos_pfifo", V_01 }, // !!TB
951 { "qos_obw", V_RANGE(10, 999999) },
952 { "qos_ibw", V_RANGE(10, 999999) },
953 { "qos_orules", V_LENGTH(0, 8192) },
954 { "qos_default", V_RANGE(0, 9) },
955 { "qos_irates", V_LENGTH(0, 128) },
956 { "qos_orates", V_LENGTH(0, 128) },
957 { "qos_classnames", V_LENGTH(10, 128) }, // !!TOASTMAN
959 { "ne_vegas", V_01 },
960 { "ne_valpha", V_NUM },
961 { "ne_vbeta", V_NUM },
962 { "ne_vgamma", V_NUM },
964 // qos-bw-limiter
965 { "qosl_enable", V_01 },
966 { "qosl_rules", V_LENGTH(0, 4096) },
967 { "qosl_denable", V_01 },
968 { "qosl_dulr", V_RANGE(0, 999999) },
969 { "qosl_dulc", V_RANGE(0, 999999) },
970 { "qosl_ddlr", V_RANGE(0, 999999) },
971 { "qosl_ddlc", V_RANGE(0, 999999) },
972 { "qosl_dtcp", V_RANGE(0, 1000) },
973 { "qosl_dudp", V_RANGE(0, 100) },
974 /*qosl_ibw unused - qos_ibw shared*/
975 /*qosl_obw unused - qos_obw shared*/
977 //NoCatSplash. Victek.
978 #ifdef TCONFIG_NOCAT
979 { "NC_enable", V_01 },
980 { "NC_Verbosity", V_RANGE(0, 10) },
981 { "NC_GatewayName", V_LENGTH(0, 255) },
982 { "NC_GatewayPort", V_PORT },
983 { "NC_ForcedRedirect", V_01 },
984 { "NC_HomePage", V_LENGTH(0, 255) },
985 { "NC_DocumentRoot", V_LENGTH(0, 255) },
986 { "NC_SplashURL", V_LENGTH(0, 255) },
987 { "NC_LoginTimeout", V_RANGE(0, 86400000) },
988 { "NC_IdleTimeout", V_RANGE(0, 86400000) },
989 { "NC_MaxMissedARP", V_RANGE(0, 10) },
990 { "NC_PeerChecktimeout", V_RANGE(0, 60) },
991 { "NC_ExcludePorts", V_LENGTH(0, 255) },
992 { "NC_IncludePorts", V_LENGTH(0, 255) },
993 { "NC_AllowedWebHosts", V_LENGTH(0, 255) },
994 { "NC_MACWhiteList", V_LENGTH(0, 255) },
995 { "NC_SplashFile", V_LENGTH(0, 8192) },
996 #endif
998 #ifdef TCONFIG_OPENVPN
999 // vpn
1000 { "vpn_debug", V_01 },
1001 { "vpn_server_eas", V_NONE },
1002 { "vpn_server_dns", V_NONE },
1003 { "vpn_server1_poll", V_RANGE(0, 1440) },
1004 { "vpn_server1_if", V_TEXT(3, 3) }, // tap, tun
1005 { "vpn_server1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1006 { "vpn_server1_port", V_PORT },
1007 { "vpn_server1_firewall", V_TEXT(0, 8) }, // auto, external, custom
1008 { "vpn_server1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1009 { "vpn_server1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1010 { "vpn_server1_cipher", V_TEXT(0, 16) },
1011 { "vpn_server1_dhcp", V_01 },
1012 { "vpn_server1_r1", V_IP },
1013 { "vpn_server1_r2", V_IP },
1014 { "vpn_server1_sn", V_IP },
1015 { "vpn_server1_nm", V_IP },
1016 { "vpn_server1_local", V_IP },
1017 { "vpn_server1_remote", V_IP },
1018 { "vpn_server1_reneg", V_RANGE(-1,2147483647)},
1019 { "vpn_server1_hmac", V_RANGE(-1, 2) },
1020 { "vpn_server1_plan", V_01 },
1021 { "vpn_server1_ccd", V_01 },
1022 { "vpn_server1_c2c", V_01 },
1023 { "vpn_server1_ccd_excl", V_01 },
1024 { "vpn_server1_ccd_val", V_NONE },
1025 { "vpn_server1_pdns", V_01 },
1026 { "vpn_server1_rgw", V_01 },
1027 { "vpn_server1_custom", V_NONE },
1028 { "vpn_server1_static", V_NONE },
1029 { "vpn_server1_ca", V_NONE },
1030 { "vpn_server1_crt", V_NONE },
1031 { "vpn_server1_key", V_NONE },
1032 { "vpn_server1_dh", V_NONE },
1033 { "vpn_server2_poll", V_RANGE(0, 1440) },
1034 { "vpn_server2_if", V_TEXT(3, 3) }, // tap, tun
1035 { "vpn_server2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1036 { "vpn_server2_port", V_PORT },
1037 { "vpn_server2_firewall", V_TEXT(0, 8) }, // auto, external, custom
1038 { "vpn_server2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1039 { "vpn_server2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1040 { "vpn_server2_cipher", V_TEXT(0, 16) },
1041 { "vpn_server2_dhcp", V_01 },
1042 { "vpn_server2_r1", V_IP },
1043 { "vpn_server2_r2", V_IP },
1044 { "vpn_server2_sn", V_IP },
1045 { "vpn_server2_nm", V_IP },
1046 { "vpn_server2_local", V_IP },
1047 { "vpn_server2_remote", V_IP },
1048 { "vpn_server2_reneg", V_RANGE(-1,2147483647)},
1049 { "vpn_server2_hmac", V_RANGE(-1, 2) },
1050 { "vpn_server2_plan", V_01 },
1051 { "vpn_server2_pdns", V_01 },
1052 { "vpn_server2_rgw", V_01 },
1053 { "vpn_server2_custom", V_NONE },
1054 { "vpn_server2_ccd", V_01 },
1055 { "vpn_server2_c2c", V_01 },
1056 { "vpn_server2_ccd_excl", V_01 },
1057 { "vpn_server2_ccd_val", V_NONE },
1058 { "vpn_server2_static", V_NONE },
1059 { "vpn_server2_ca", V_NONE },
1060 { "vpn_server2_crt", V_NONE },
1061 { "vpn_server2_key", V_NONE },
1062 { "vpn_server2_dh", V_NONE },
1063 { "vpn_client_eas", V_NONE },
1064 { "vpn_client1_poll", V_RANGE(0, 1440) },
1065 { "vpn_client1_if", V_TEXT(3, 3) }, // tap, tun
1066 { "vpn_client1_bridge", V_01 },
1067 { "vpn_client1_nat", V_01 },
1068 { "vpn_client1_proto", V_TEXT(3, 10) }, // udp, tcp-server
1069 { "vpn_client1_addr", V_NONE },
1070 { "vpn_client1_port", V_PORT },
1071 { "vpn_client1_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1072 { "vpn_client1_firewall", V_TEXT(0, 6) }, // auto, custom
1073 { "vpn_client1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1074 { "vpn_client1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1075 { "vpn_client1_cipher", V_TEXT(0, 16) },
1076 { "vpn_client1_local", V_IP },
1077 { "vpn_client1_remote", V_IP },
1078 { "vpn_client1_nm", V_IP },
1079 { "vpn_client1_reneg", V_RANGE(-1,2147483647)},
1080 { "vpn_client1_hmac", V_RANGE(-1, 2) },
1081 { "vpn_client1_adns", V_RANGE(0, 3) },
1082 { "vpn_client1_rgw", V_01 },
1083 { "vpn_client1_gw", V_TEXT(0, 15) },
1084 { "vpn_client1_custom", V_NONE },
1085 { "vpn_client1_static", V_NONE },
1086 { "vpn_client1_ca", V_NONE },
1087 { "vpn_client1_crt", V_NONE },
1088 { "vpn_client1_key", V_NONE },
1089 { "vpn_client2_poll", V_RANGE(0, 1440) },
1090 { "vpn_client2_if", V_TEXT(3, 3) }, // tap, tun
1091 { "vpn_client2_bridge", V_01 },
1092 { "vpn_client2_nat", V_01 },
1093 { "vpn_client2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1094 { "vpn_client2_addr", V_NONE },
1095 { "vpn_client2_port", V_PORT },
1096 { "vpn_client2_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1097 { "vpn_client2_firewall", V_TEXT(0, 6) }, // auto, custom
1098 { "vpn_client2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1099 { "vpn_client2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1100 { "vpn_client2_cipher", V_TEXT(0, 16) },
1101 { "vpn_client2_local", V_IP },
1102 { "vpn_client2_remote", V_IP },
1103 { "vpn_client2_nm", V_IP },
1104 { "vpn_client2_reneg", V_RANGE(-1,2147483647)},
1105 { "vpn_client2_hmac", V_RANGE(-1, 2) },
1106 { "vpn_client2_adns", V_RANGE(0, 3) },
1107 { "vpn_client2_rgw", V_01 },
1108 { "vpn_client2_gw", V_TEXT(0, 15) },
1109 { "vpn_client2_custom", V_NONE },
1110 { "vpn_client2_static", V_NONE },
1111 { "vpn_client2_ca", V_NONE },
1112 { "vpn_client2_crt", V_NONE },
1113 { "vpn_client2_key", V_NONE },
1114 #endif // vpn
1119 ppp_static 0/1
1120 ppp_static_ip IP
1121 wl_enable 0/1
1122 wl_wds_timeout
1123 wl_maxassoc 1-256
1124 wl_phytype a,b,g
1125 wl_net_reauth
1126 wl_preauth
1127 wl_wme_ap_bk
1128 wl_wme_ap_be
1129 wl_wme_ap_vi
1130 wl_wme_ap_vo
1131 wl_wme_sta_bk
1132 wl_wme_sta_be
1133 wl_wme_sta_vi
1134 wl_wme_sta_vo
1136 port_priority_1 0-2
1137 port_flow_control_1 0,1
1138 port_rate_limit_1 0-8
1139 port_priority_2 0-2
1140 port_flow_control_2 0,1
1141 port_rate_limit_2 0-8
1142 port_priority_3 0-2
1143 port_flow_control_3 0,1
1144 port_rate_limit_3 0-8
1145 port_priority_4 0-2
1146 port_flow_control_4 0,1
1147 port_rate_limit_4 0-8
1148 wl_ap_ip
1149 wl_ap_ssid
1152 { NULL }
1156 static int webcgi_nvram_set(const nvset_t *v, const char *name, int write)
1158 char *p, *e;
1159 int n;
1160 long l;
1161 unsigned u[6];
1162 int ok;
1163 int dirty;
1164 #ifdef TCONFIG_IPV6
1165 struct in6_addr addr;
1166 #endif
1168 if ((p = webcgi_get((char*)name)) == NULL) return 0;
1170 _dprintf("[%s] %s=%s\n", v->name, (char*)name, p);
1171 dirty = 0;
1172 ok = 1;
1173 switch (v->vtype) {
1174 case VT_TEXT:
1175 p = unix_string(p); // NOTE: p = malloc'd
1176 // drop
1177 case VT_LENGTH:
1178 n = strlen(p);
1179 if ((n < v->va.i) || (n > v->vb.i)) ok = 0;
1180 break;
1181 case VT_RANGE:
1182 l = strtol(p, &e, 10);
1183 if ((p == e) || (*e) || (l < v->va.l) || (l > v->vb.l)) ok = 0;
1184 break;
1185 case VT_IP:
1186 if ((sscanf(p, "%3u.%3u.%3u.%3u", &u[0], &u[1], &u[2], &u[3]) != 4) ||
1187 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255)) ok = 0;
1188 break;
1189 case VT_MAC:
1190 if ((sscanf(p, "%2x:%2x:%2x:%2x:%2x:%2x", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]) != 6) ||
1191 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255) || (u[4] > 255) || (u[5] > 255)) ok = 0;
1192 break;
1193 #ifdef TCONFIG_IPV6
1194 case VT_IPV6:
1195 if (strlen(p) > 0 || v->va.i) {
1196 if (inet_pton(AF_INET6, p, &addr) != 1) ok = 0;
1198 break;
1199 #endif
1200 default:
1201 // shutup gcc
1202 break;
1204 if (!ok) {
1205 if (v->vtype == VT_TEXT) free(p);
1206 return -1;
1208 if (write) {
1209 if (!nvram_match((char *)name, p)) {
1210 if (v->vtype != VT_TEMP) dirty = 1;
1211 DEBUG_NVRAMSET(name, p);
1212 nvram_set(name, p);
1215 if (v->vtype == VT_TEXT) free(p);
1217 return dirty;
1220 typedef struct {
1221 const nvset_t *v;
1222 int write;
1223 int dirty;
1224 } nv_list_t;
1226 static int nv_wl_find(int idx, int unit, int subunit, void *param)
1228 nv_list_t *p = param;
1230 int ok = webcgi_nvram_set(p->v, wl_nvname(p->v->name + 3, unit, subunit), p->write);
1231 if (ok < 0)
1232 return 1;
1233 else {
1234 p->dirty |= ok;
1235 return 0;
1239 static int save_variables(int write)
1241 const nvset_t *v;
1242 char *p;
1243 int n;
1244 int ok;
1245 char s[256];
1246 int dirty;
1247 static const char *msgf = "The field \"%s\" is invalid. Please report this problem.";
1248 nv_list_t nv;
1250 dirty = 0;
1251 nv.write = write;
1252 for (v = nvset_list; v->name; ++v) {
1253 ok = webcgi_nvram_set(v, v->name, write);
1255 if ((ok >= 0) && (strncmp(v->name, "wl_", 3) == 0)) {
1256 nv.dirty = dirty;
1257 nv.v = v;
1258 if (foreach_wif(1, &nv, nv_wl_find) == 0)
1259 ok |= nv.dirty;
1260 else
1261 ok = -1;
1264 if (ok < 0) {
1265 sprintf(s, msgf, v->name);
1266 resmsg_set(s);
1267 return 0;
1269 dirty |= ok;
1272 // special cases
1274 char *p1, *p2;
1275 if (((p1 = webcgi_get("set_password_1")) != NULL) && (strcmp(p1, "**********") != 0)) {
1276 if (((p2 = webcgi_get("set_password_2")) != NULL) && (strcmp(p1, p2) == 0)) {
1277 if ((write) && (!nvram_match("http_passwd", p1))) {
1278 dirty = 1;
1279 nvram_set("http_passwd", p1);
1282 else {
1283 sprintf(s, msgf, "password");
1284 resmsg_set(s);
1285 return 0;
1289 for (n = 0; n < 50; ++n) {
1290 sprintf(s, "rrule%d", n);
1291 if ((p = webcgi_get(s)) != NULL) {
1292 if (strlen(p) > 8192) { //Toastman
1293 sprintf(s, msgf, s);
1294 resmsg_set(s);
1295 return 0;
1297 if ((write) && (!nvram_match(s, p))) {
1298 dirty = 1;
1299 DEBUG_NVRAMSET(s, p);
1300 nvram_set(s, p);
1305 return (write) ? dirty : 1;
1308 static void wo_tomato(char *url)
1310 char *v;
1311 int i;
1312 int ajax;
1313 int nvset;
1314 const char *red;
1315 int commit;
1317 // _dprintf("tomato.cgi\n");
1319 red = webcgi_safeget("_redirect", "");
1320 if (!*red) send_header(200, NULL, mime_html, 0);
1322 commit = atoi(webcgi_safeget("_commit", "1"));
1323 ajax = atoi(webcgi_safeget("_ajax", "0"));
1325 nvset = atoi(webcgi_safeget("_nvset", "1"));
1326 if (nvset) {
1327 if (!save_variables(0)) {
1328 if (ajax) {
1329 web_printf("@msg:%s", resmsg_get());
1331 else {
1332 parse_asp("error.asp");
1334 return;
1336 commit = save_variables(1) && commit;
1338 resmsg_set("Settings saved.");
1341 rboot = atoi(webcgi_safeget("_reboot", "0"));
1342 if (rboot) {
1343 parse_asp("reboot.asp");
1345 else {
1346 if (ajax) {
1347 web_printf("@msg:%s", resmsg_get());
1349 else if (atoi(webcgi_safeget("_moveip", "0"))) {
1350 parse_asp("saved-moved.asp");
1352 else if (!*red) {
1353 parse_asp("saved.asp");
1357 if (commit) {
1358 _dprintf("commit from tomato.cgi\n");
1359 nvram_commit_x();
1362 if ((v = webcgi_get("_service")) != NULL && *v != 0) {
1363 if (!*red) {
1364 if (ajax) web_printf(" Some services are being restarted...");
1365 web_close();
1367 sleep(1);
1369 if (*v == '*') {
1370 kill(1, SIGHUP);
1372 else {
1373 exec_service(v);
1377 for (i = atoi(webcgi_safeget("_sleep", "0")); i > 0; --i) sleep(1);
1379 if (*red) redirect(red);
1381 if (rboot) {
1382 web_close();
1383 sleep(1);
1384 kill(1, SIGTERM);
1389 // ----------------------------------------------------------------------------
1392 static void wo_update(char *url)
1394 const aspapi_t *api;
1395 const char *name;
1396 int argc;
1397 char *argv[16];
1398 char s[32];
1400 if ((name = webcgi_get("exec")) != NULL) {
1401 for (api = aspapi; api->name; ++api) {
1402 if (strcmp(api->name, name) == 0) {
1403 for (argc = 0; argc < 16; ++argc) {
1404 sprintf(s, "arg%d", argc);
1405 if ((argv[argc] = (char *)webcgi_get(s)) == NULL) break;
1407 api->exec(argc, argv);
1408 break;
1414 static void wo_service(char *url)
1416 int n;
1418 exec_service(webcgi_safeget("_service", ""));
1420 if ((n = atoi(webcgi_safeget("_sleep", "2"))) <= 0) n = 2;
1421 sleep(n);
1423 common_redirect();
1426 static void wo_shutdown(char *url)
1428 parse_asp("shutdown.asp");
1429 web_close();
1430 sleep(1);
1432 kill(1, SIGQUIT);
1435 static void wo_nvcommit(char *url)
1437 parse_asp("saved.asp");
1438 web_close();
1439 nvram_commit();