wl dual-band: get the available bands list from the driver
[tomato.git] / release / src / router / httpd / tomato.c
blob57b61a8b0515c63e8598c0e44df13ae9517e5701
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 <arpa/inet.h>
13 #include <time.h>
16 // #define DEBUG_NOEXECSERVICE
17 // #define DEBUG_NVRAMSET(k, v) cprintf("nvram set %s=%s\n", k, v);
18 #define DEBUG_NVRAMSET(k, v) do { } while(0);
21 char *post_buf = NULL;
22 int rboot = 0;
23 extern int post;
25 static void asp_css(int argc, char **argv);
26 static void asp_resmsg(int argc, char **argv);
29 static void wo_tomato(char *url);
30 static void wo_update(char *url);
31 static void wo_service(char *url);
32 static void wo_shutdown(char *url);
33 static void wo_nvcommit(char *url);
34 // static void wo_logout(char *url);
37 // ----------------------------------------------------------------------------
40 void exec_service(const char *action)
42 int i;
44 _dprintf("exec_service: %s\n", action);
46 i = 10;
47 while ((!nvram_match("action_service", "")) && (i-- > 0)) {
48 _dprintf("%s: waiting before %d\n", __FUNCTION__, i);
49 sleep(1);
52 nvram_set("action_service", action);
53 kill(1, SIGUSR1);
55 i = 3;
56 while ((nvram_match("action_service", (char *)action)) && (i-- > 0)) {
57 _dprintf("%s: waiting after %d\n", __FUNCTION__, i);
58 sleep(1);
62 if (atoi(webcgi_safeget("_service_wait", ""))) {
63 i = 10;
64 while ((nvram_match("action_service", (char *)action)) && (i-- > 0)) {
65 _dprintf("%s: waiting after %d\n", __FUNCTION__, i);
66 sleep(1);
72 static void wi_generic_noid(char *url, int len, char *boundary)
74 if (post == 1) {
75 if (len >= (32 * 1024)) {
76 // syslog(LOG_WARNING, "POST max");
77 exit(1);
80 if (post_buf) free(post_buf);
81 if ((post_buf = malloc(len + 1)) == NULL) {
82 // syslog(LOG_CRIT, "Unable to allocate post buffer");
83 exit(1);
86 if (web_read_x(post_buf, len) != len) {
87 exit(1);
89 post_buf[len] = 0;
90 webcgi_init(post_buf);
94 void wi_generic(char *url, int len, char *boundary)
96 wi_generic_noid(url, len, boundary);
97 check_id(url);
100 // !!TB - CGI Support
101 void wi_cgi_bin(char *url, int len, char *boundary)
103 if (post_buf) free(post_buf);
104 post_buf = NULL;
106 if (post) {
107 if (len >= (32 * 1024)) {
108 syslog(LOG_WARNING, "POST length exceeded maximum allowed");
109 exit(1);
112 if (len > 0) {
113 if ((post_buf = malloc(len + 1)) == NULL) {
114 exit(1);
116 if (web_read_x(post_buf, len) != len) {
117 exit(1);
119 post_buf[len] = 0;
124 static void _execute_command(char *url, char *command, char *query, char *output)
126 char webExecFile[] = "/tmp/.wxXXXXXX";
127 char webQueryFile[] = "/tmp/.wqXXXXXX";
128 FILE *f;
129 int fe, fq = -1;
131 if ((fe = mkstemp(webExecFile)) < 0)
132 exit(1);
133 if (query) {
134 if ((fq = mkstemp(webQueryFile)) < 0) {
135 close(fe);
136 unlink(webExecFile);
137 exit(1);
141 if ((f = fdopen(fe, "wb")) != NULL) {
142 fprintf(f,
143 "#!/bin/sh\n"
144 "export REQUEST_METHOD=\"%s\"\n"
145 "export PATH=%s\n"
146 ". /etc/profile\n"
147 "%s%s %s%s\n",
148 post ? "POST" : "GET", getenv("PATH"),
149 command ? "" : "./", command ? command : url,
150 query ? "<" : "", query ? webQueryFile : "");
151 fclose(f);
153 else {
154 unlink(output);
155 close(fe);
156 unlink(webExecFile);
157 if (query) {
158 close(fq);
159 unlink(webQueryFile);
161 exit(1);
163 chmod(webExecFile, 0700);
165 if (query) {
166 if ((f = fdopen(fq, "wb")) != NULL) {
167 fprintf(f, "%s\n", query);
168 fclose(f);
170 else {
171 unlink(output);
172 unlink(webExecFile);
173 close(fq);
174 unlink(webQueryFile);
175 exit(1);
179 char *cmd[] = { webExecFile, NULL };
180 _eval(cmd, output, 0, NULL);
181 unlink(webQueryFile);
182 unlink(webExecFile);
185 static void wo_cgi_bin(char *url)
187 char webOutpFile[] = "/tmp/.woXXXXXX";
188 int fd;
190 if ((fd = mkstemp(webOutpFile)) < 0)
191 exit(1);
192 close(fd);
194 _execute_command(url, NULL, post_buf, webOutpFile);
196 if (post_buf) {
197 free(post_buf);
198 post_buf = NULL;
200 wo_asp(webOutpFile);
201 unlink(webOutpFile);
204 static void wo_shell(char *url)
206 char webOutpFile[] = "/tmp/.woXXXXXX";
207 int fd;
209 if ((fd = mkstemp(webOutpFile)) < 0)
210 exit(1);
211 close(fd);
213 _execute_command(NULL, webcgi_get("command"), NULL, webOutpFile);
215 web_puts("\ncmdresult = '");
216 web_putfile(webOutpFile, WOF_JAVASCRIPT);
217 web_puts("';");
218 unlink(webOutpFile);
221 static void wo_blank(char *url)
223 web_puts("\n\n\n\n");
226 static void wo_favicon(char *url)
228 send_header(200, NULL, "image/vnd.microsoft.icon", 0);
229 do_file(url);
231 if (nvram_match("web_favicon", "1")) {
232 send_header(200, NULL, "image/vnd.microsoft.icon", 0);
233 do_file(url);
235 else {
236 send_error(404, NULL, NULL);
241 static void wo_cfe(char *url)
243 do_file(MTD_DEV(0ro));
246 static void wo_nvram(char *url)
248 web_pipecmd("nvram show", WOF_NONE);
251 static void wo_iptables(char *url)
253 web_pipecmd("iptables -nvL; iptables -t nat -nvL; iptables -t mangle -nvL", WOF_NONE);
257 static void wo_spin(char *url)
259 char s[64];
261 strlcpy(s, nvram_safe_get("web_css"), sizeof(s));
262 strlcat(s, "_spin.gif", sizeof(s));
263 if (f_exists(s)) do_file(s);
264 else do_file("_spin.gif");
268 void common_redirect(void)
270 if (atoi(webcgi_safeget("_ajax", ""))) {
271 send_header(200, NULL, mime_html, 0);
272 web_puts("OK");
274 else {
275 redirect(webcgi_safeget("_redirect", "/"));
279 // ----------------------------------------------------------------------------
281 const struct mime_handler mime_handlers[] = {
282 { "update.cgi", mime_javascript, 0, wi_generic, wo_update, 1 },
283 { "tomato.cgi", NULL, 0, wi_generic, wo_tomato, 1 },
285 { "debug.js", mime_javascript, 5, wi_generic_noid, wo_blank, 1 }, // while debugging
286 { "cfe/*.bin", mime_binary, 0, wi_generic, wo_cfe, 1 },
287 { "nvram/*.txt", mime_binary, 0, wi_generic, wo_nvram, 1 },
288 { "ipt/*.txt", mime_binary, 0, wi_generic, wo_iptables, 1 },
290 { "cfg/*.cfg", NULL, 0, wi_generic, wo_backup, 1 },
291 { "cfg/restore.cgi", mime_html, 0, wi_restore, wo_restore, 1 },
292 { "cfg/defaults.cgi", NULL, 0, wi_generic, wo_defaults, 1 },
294 { "bwm/*.gz", NULL, 0, wi_generic, wo_bwmbackup, 1 },
295 { "bwm/restore.cgi", NULL, 0, wi_bwmrestore, wo_bwmrestore, 1 },
297 { "logs/view.cgi", NULL, 0, wi_generic, wo_viewlog, 1 },
298 { "logs/*.txt", NULL, 0, wi_generic, wo_syslog, 1 },
299 { "webmon_**", NULL, 0, wi_generic, wo_syslog, 1 },
301 { "logout.asp", NULL, 0, wi_generic, wo_asp, 1 },
302 { "clearcookies.asp", NULL, 0, wi_generic, wo_asp, 1 },
304 // { "spin.gif", NULL, 0, wi_generic_noid, wo_spin, 1 },
306 { "**.asp", NULL, 0, wi_generic_noid, wo_asp, 1 },
307 { "**.css", "text/css", 2, wi_generic_noid, do_file, 1 },
308 { "**.htm|**.html", mime_html, 2, wi_generic_noid, do_file, 1 },
309 { "**.gif", "image/gif", 5, wi_generic_noid, do_file, 1 },
310 { "**.jpg", "image/jpeg", 5, wi_generic_noid, do_file, 1 },
311 { "**.png", "image/png", 5, wi_generic_noid, do_file, 1 },
312 { "**.js", mime_javascript, 2, wi_generic_noid, do_file, 1 },
313 { "**.jsx", mime_javascript, 0, wi_generic, wo_asp, 1 },
314 { "**.svg", "image/svg+xml", 2, wi_generic_noid, do_file, 1 },
315 { "**.txt", mime_plain, 2, wi_generic_noid, do_file, 1 },
316 { "**.bin", mime_binary, 0, wi_generic_noid, do_file, 1 },
317 { "**.bino", mime_octetstream, 0, wi_generic_noid, do_file, 1 },
318 { "favicon.ico", NULL, 5, wi_generic_noid, wo_favicon, 1 },
319 // !!TB - CGI Support, enable downloading archives
320 { "**/cgi-bin/**|**.sh", NULL, 0, wi_cgi_bin, wo_cgi_bin, 1 },
321 { "**.tar|**.gz", mime_binary, 0, wi_generic_noid, do_file, 1 },
322 { "shell.cgi", mime_javascript, 0, wi_generic, wo_shell, 1 },
323 { "wpad.dat|proxy.pac", "application/x-ns-proxy-autoconfig", 0, wi_generic_noid, do_file, 0 },
325 { "webmon.cgi", mime_javascript, 0, wi_generic, wo_webmon, 1 },
326 { "dhcpc.cgi", NULL, 0, wi_generic, wo_dhcpc, 1 },
327 { "dhcpd.cgi", mime_javascript, 0, wi_generic, wo_dhcpd, 1 },
328 { "nvcommit.cgi", NULL, 0, wi_generic, wo_nvcommit, 1 },
329 { "ping.cgi", mime_javascript, 0, wi_generic, wo_ping, 1 },
330 { "trace.cgi", mime_javascript, 0, wi_generic, wo_trace, 1 },
331 { "upgrade.cgi", mime_html, 0, wi_upgrade, wo_flash, 1 },
332 { "upnp.cgi", NULL, 0, wi_generic, wo_upnp, 1 },
333 { "wakeup.cgi", NULL, 0, wi_generic, wo_wakeup, 1 },
334 { "wlmnoise.cgi", mime_html, 0, wi_generic, wo_wlmnoise, 1 },
335 { "wlradio.cgi", NULL, 0, wi_generic, wo_wlradio, 1 },
336 { "resolve.cgi", mime_javascript, 0, wi_generic, wo_resolve, 1 },
337 { "expct.cgi", mime_html, 0, wi_generic, wo_expct, 1 },
338 { "service.cgi", NULL, 0, wi_generic, wo_service, 1 },
339 // { "logout.cgi", NULL, 0, wi_generic, wo_logout, 0 }, // see httpd.c
340 { "shutdown.cgi", mime_html, 0, wi_generic, wo_shutdown, 1 },
341 #ifdef TCONFIG_OPENVPN
342 { "vpnstatus.cgi", mime_javascript, 0, wi_generic, wo_vpn_status, 1 },
343 #endif
344 #ifdef TCONFIG_USB
345 { "usbcmd.cgi", mime_javascript, 0, wi_generic, wo_usbcommand, 1 }, //!!TB - USB
346 #endif
347 #ifdef BLACKHOLE
348 { "blackhole.cgi", NULL, 0, wi_blackhole, NULL, 1 },
349 #endif
350 // { "test", mime_html, 0, wi_generic, wo_test, 1 },
351 { NULL, NULL, 0, NULL, NULL, 1 }
354 const aspapi_t aspapi[] = {
355 { "activeroutes", asp_activeroutes },
356 { "arplist", asp_arplist },
357 { "bandwidth", asp_bandwidth },
358 { "build_time", asp_build_time },
359 { "cgi_get", asp_cgi_get },
360 { "compmac", asp_compmac },
361 { "ctcount", asp_ctcount },
362 { "ctdump", asp_ctdump },
363 { "ddnsx", asp_ddnsx },
364 { "devlist", asp_devlist },
365 { "webmon", asp_webmon },
366 { "dhcpc_time", asp_dhcpc_time },
367 { "dns", asp_dns },
368 { "ident", asp_ident },
369 { "lanip", asp_lanip },
370 { "layer7", asp_layer7 },
371 { "link_uptime", asp_link_uptime },
372 { "lipp", asp_lipp },
373 { "netdev", asp_netdev },
374 { "notice", asp_notice },
375 { "nv", asp_nv },
376 { "nvram", asp_nvram },
377 { "nvramseq", asp_nvramseq },
378 { "nvstat", asp_nvstat },
379 { "psup", asp_psup },
380 { "qrate", asp_qrate },
381 { "resmsg", asp_resmsg },
382 { "rrule", asp_rrule },
383 { "statfs", asp_statfs },
384 { "sysinfo", asp_sysinfo },
385 { "time", asp_time },
386 { "upnpinfo", asp_upnpinfo },
387 { "version", asp_version },
388 { "wanstatus", asp_wanstatus },
389 { "wanup", asp_wanup },
390 { "wlchannel", asp_wlchannel },
391 { "wlclient", asp_wlclient },
392 { "wlcrssi", asp_wlcrssi },
393 { "wlnoise", asp_wlnoise },
394 { "wlnbw", asp_wlnbw },
395 { "wlnctrlsb", asp_wlnctrlsb },
396 { "wlradio", asp_wlradio },
397 { "wlscan", asp_wlscan },
398 { "wlchannels", asp_wlchannels }, //!!TB
399 { "wlcountries", asp_wlcountries },
400 { "wlrate", asp_wlrate },
401 { "wlbands", asp_wlbands },
402 #ifdef TCONFIG_USB
403 { "usbdevices", asp_usbdevices }, //!!TB - USB Support
404 #endif
405 { "css", asp_css },
406 { NULL, NULL }
409 // -----------------------------------------------------------------------------
411 static void asp_css(int argc, char **argv)
413 const char *css = nvram_safe_get("web_css");
415 if (strcmp(css, "tomato") != 0) {
416 web_printf("<link rel='stylesheet' type='text/css' href='%s.css'>", css);
420 // -----------------------------------------------------------------------------
422 const char *resmsg_get(void)
424 return webcgi_safeget("resmsg", "");
427 void resmsg_set(const char *msg)
429 webcgi_set("resmsg", strdup(msg)); // m ok
432 int resmsg_fread(const char *fname)
434 char s[256];
435 char *p;
437 f_read_string(fname, s, sizeof(s));
438 if ((p = strchr(s, '\n')) != NULL) *p = 0;
439 if (s[0]) {
440 resmsg_set(s);
441 return 1;
443 return 0;
446 static void asp_resmsg(int argc, char **argv)
448 char *p;
450 if ((p = js_string(webcgi_safeget("resmsg", (argc > 0) ? argv[0] : ""))) == NULL) return;
451 web_printf("\nresmsg='%s';\n", p);
452 free(p);
455 // ----------------------------------------------------------------------------
457 // verification... simple sanity checks. UI should verify all fields.
459 // todo: move and re-use for filtering - zzz
461 typedef union {
462 int i;
463 long l;
464 const char *s;
465 } nvset_varg_t;
467 typedef struct {
468 const char *name;
469 enum {
470 VT_NONE, // no checking
471 VT_LENGTH, // check length of string
472 VT_TEXT, // strip \r, check length of string
473 VT_RANGE, // expect an integer, check range
474 VT_IP, // expect an ip address
475 VT_MAC, // expect a mac address
476 VT_TEMP // no checks, no commit
477 } vtype;
478 nvset_varg_t va;
479 nvset_varg_t vb;
480 } nvset_t;
483 #define V_NONE VT_NONE, { }, { }
484 #define V_01 VT_RANGE, { .l = 0 }, { .l = 1 }
485 #define V_PORT VT_RANGE, { .l = 2 }, { .l = 65535 }
486 #define V_ONOFF VT_LENGTH, { .i = 2 }, { .i = 3 }
487 #define V_WORD VT_LENGTH, { .i = 1 }, { .i = 16 }
488 #define V_LENGTH(min, max) VT_LENGTH, { .i = min }, { .i = max }
489 #define V_TEXT(min, max) VT_TEXT, { .i = min }, { .i = max }
490 #define V_RANGE(min, max) VT_RANGE, { .l = min }, { .l = max }
491 #define V_IP VT_IP, { }, { }
492 #define V_OCTET VT_RANGE, { .l = 0 }, { .l = 255 }
493 #define V_NUM VT_RANGE, { .l = 0 }, { .l = 0x7FFFFFFF }
494 #define V_TEMP VT_TEMP, { }, { }
496 static const nvset_t nvset_list[] = {
498 // basic-ident
499 { "router_name", V_LENGTH(0, 32) },
500 { "wan_hostname", V_LENGTH(0, 32) },
501 { "wan_domain", V_LENGTH(0, 32) },
503 // basic-time
504 { "tm_tz", V_LENGTH(1, 64) }, // PST8PDT
505 { "tm_sel", V_LENGTH(1, 64) }, // PST8PDT
506 { "tm_dst", V_01 },
507 { "ntp_updates", V_RANGE(-1, 24) },
508 { "ntp_tdod", V_01 },
509 { "ntp_server", V_LENGTH(1, 150) }, // x y z
510 { "ntp_kiss", V_LENGTH(0, 255) },
512 // basic-static
513 { "dhcpd_static", V_LENGTH(0, 106*101)}, // 106 (max chars per entry) x 100 entries
515 // basic-ddns
516 { "ddnsx0", V_LENGTH(0, 2048) },
517 { "ddnsx1", V_LENGTH(0, 2048) },
518 { "ddnsx0_cache", V_LENGTH(0, 1) }, // only to clear
519 { "ddnsx1_cache", V_LENGTH(0, 1) },
520 { "ddnsx_ip", V_LENGTH(0, 32) },
521 { "ddnsx_save", V_01 },
522 { "ddnsx_refresh", V_RANGE(0, 365) },
524 // basic-network
525 // WAN
526 { "wan_proto", V_LENGTH(1, 16) }, // disabled, dhcp, static, pppoe, pptp, l2tp
527 { "wan_ipaddr", V_IP },
528 { "wan_netmask", V_IP },
529 { "wan_gateway", V_IP },
530 { "hb_server_ip", V_LENGTH(0, 32) },
531 { "l2tp_server_ip", V_LENGTH(0, 128) },
532 { "pptp_server_ip", V_LENGTH(0, 128) },
533 { "pptp_dhcp", V_01 },
534 { "ppp_defgw", 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 { "security_mode2", 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 { "security_mode", V_LENGTH(1, 32) }, // disabled, radius, wpa, psk,wep, wpa2, psk2, wpa wpa2, psk psk2
586 { "wds_enable", V_01 },
587 { "wl_gmode", V_RANGE(-1, 6) },
588 { "wl_wep", V_LENGTH(1, 32) }, // off, on, restricted,tkip,aes,tkip+aes
589 { "wl_akm", V_LENGTH(0, 32) }, // wpa, wpa2, psk, psk2, wpa wpa2, psk psk2, ""
590 { "wl_auth_mode", V_LENGTH(4, 6) }, // none, radius
592 { "wl_nmode", V_NONE },
593 { "wl_nband", V_RANGE(0, 2) }, // 2 - 2.4GHz, 1 - 5GHz, 0 - Auto
594 { "wl_nreqd", V_NONE },
595 { "wl_nbw_cap", V_RANGE(0, 2) }, // 0 - 20MHz, 1 - 40MHz, 2 - Auto
596 { "wl_nbw", V_NONE },
597 { "wl_mimo_preamble", V_WORD }, // 802.11n Preamble: mm/gf/auto/gfbcm
598 { "wl_nctrlsb", V_NONE }, // none, lower, upper
600 // basic-wfilter
601 { "wl_macmode", V_NONE }, // allow, deny, disabled
602 { "wl_maclist", V_LENGTH(0, 18*201) }, // 18 x 200 (11:22:33:44:55:66 ...)
603 { "macnames", V_LENGTH(0, 62*201) }, // 62 (12+1+48+1) x 50 (112233445566<..>) todo: re-use -- zzz
605 // advanced-ctnf
606 { "ct_max", V_RANGE(128, 300000) },
607 { "ct_tcp_timeout", V_LENGTH(20, 70) },
608 { "ct_udp_timeout", V_LENGTH(5, 15) },
609 { "ct_timeout", V_LENGTH(5, 15) },
610 { "nf_ttl", V_LENGTH(1, 6) },
611 { "nf_l7in", V_01 },
612 #ifdef LINUX26
613 { "nf_sip", V_01 },
614 { "ct_hashsize", V_RANGE(127, 65535) },
615 #endif
616 { "nf_rtsp", V_01 },
617 { "nf_pptp", V_01 },
618 { "nf_h323", V_01 },
619 { "nf_ftp", V_01 },
621 // advanced-dhcpdns
622 { "dhcpd_slt", V_RANGE(-1, 43200) }, // -1=infinite, 0=follow normal lease time, >=1 custom
623 { "dhcpd_dmdns", V_01 },
624 { "dhcpd_lmax", V_NUM },
625 { "dhcpd_gwmode", V_NUM },
626 { "dns_addget", V_01 },
627 { "dns_intcpt", V_01 },
628 { "dhcpc_minpkt", V_01 },
629 { "dhcpc_vendorclass", V_LENGTH(0, 80) },
630 { "dhcpc_requestip", V_LENGTH(0, 16) },
631 { "dns_norebind", V_01 },
632 { "dnsmasq_custom", V_TEXT(0, 2048) },
633 // { "dnsmasq_norw", V_01 },
635 // advanced-firewall
636 { "block_wan", V_01 },
637 { "multicast_pass", V_01 },
638 { "block_loopback", V_01 },
639 { "nf_loopback", V_NUM },
640 { "ne_syncookies", V_01 },
641 { "dhcp_pass", V_01 },
643 // advanced-misc
644 { "wait_time", V_RANGE(3, 20) },
645 { "wan_speed", V_RANGE(0, 4) },
646 { "jumbo_frame_enable", V_01 }, // Jumbo Frames support (for RT-N16/WNR3500L)
647 { "jumbo_frame_size", V_RANGE(1, 9720) },
649 // advanced-mac
650 { "mac_wan", V_LENGTH(0, 17) },
651 { "mac_wl", V_LENGTH(0, 17) },
653 // advanced-routing
654 { "routes_static", V_LENGTH(0, 2048) },
655 { "dhcp_routes", V_01 },
656 { "lan_stp", V_RANGE(0, 1) },
657 { "wk_mode", V_LENGTH(1, 32) }, // gateway, router
658 #ifdef TCONFIG_ZEBRA
659 { "dr_setting", V_RANGE(0, 3) },
660 { "dr_lan_tx", V_LENGTH(0, 32) },
661 { "dr_lan_rx", V_LENGTH(0, 32) },
662 { "dr_wan_tx", V_LENGTH(0, 32) },
663 { "dr_wan_rx", V_LENGTH(0, 32) },
664 #endif
666 // advanced-wireless
667 { "wl_country", V_LENGTH(0, 64) }, // !!TB - Country code
668 { "wl_country_code", V_LENGTH(0, 4) }, // !!TB - Country code
669 { "wl_btc_mode", V_RANGE(0, 2) }, // !!TB - BT Coexistence Mode: 0 (disable), 1 (enable), 2 (preemption)
670 { "wl_afterburner", V_LENGTH(2, 4) }, // off, on, auto
671 { "wl_auth", V_01 },
672 { "wl_rateset", V_LENGTH(2, 7) }, // all, default, 12
673 { "wl_rate", V_RANGE(0, 54 * 1000 * 1000) },
674 { "wl_mrate", V_RANGE(0, 54 * 1000 * 1000) },
675 { "wl_gmode_protection",V_LENGTH(3, 4) }, // off, auto
676 { "wl_frameburst", V_ONOFF }, // off, on
677 { "wl_bcn", V_RANGE(1, 65535) },
678 { "wl_dtim", V_RANGE(1, 255) },
679 { "wl_frag", V_RANGE(256, 2346) },
680 { "wl_rts", V_RANGE(0, 2347) },
681 { "wl_ap_isolate", V_01 },
682 { "wl_plcphdr", V_LENGTH(4, 5) }, // long, short
683 { "wl_antdiv", V_RANGE(0, 3) },
684 { "wl_txant", V_RANGE(0, 3) },
685 { "wl_txpwr", V_RANGE(0, 400) },
686 { "wl_wme", V_WORD }, // auto, off, on
687 { "wl_wme_no_ack", V_ONOFF }, // off, on
688 { "wl_wme_apsd", V_ONOFF }, // off, on
689 { "wl_maxassoc", V_RANGE(0, 255) },
690 { "wl_distance", V_LENGTH(0, 5) }, // "", 1-99999
691 { "wlx_hpamp", V_01 },
692 { "wlx_hperx", V_01 },
693 { "wl_reg_mode", V_LENGTH(1, 3) }, // !!TB - Regulatory: off, h, d
694 { "wl_interfmode", V_RANGE(0, 3) }, // Interference Mitigation Mode (0|1|2|3)
696 { "wl_nmode_protection", V_WORD, }, // off, auto
697 { "wl_nmcsidx", V_RANGE(-2, 32), }, // -2 - 32
698 { "wl_obss_coex", V_01 },
700 // forward-dmz
701 { "dmz_enable", V_01 },
702 { "dmz_ipaddr", V_LENGTH(0, 15) },
703 { "dmz_sip", V_LENGTH(0, 512) },
705 // forward-upnp
706 { "upnp_enable", V_NUM },
707 { "upnp_secure", V_01 },
708 { "upnp_port", V_RANGE(0, 65535) },
709 { "upnp_ssdp_interval", V_RANGE(10, 9999) },
710 { "upnp_mnp", V_01 },
711 { "upnp_clean", V_01 },
712 { "upnp_clean_interval", V_RANGE(60, 65535) },
713 { "upnp_clean_threshold", V_RANGE(0, 9999) },
714 { "upnp_min_port_int", V_PORT },
715 { "upnp_max_port_int", V_PORT },
716 { "upnp_min_port_ext", V_PORT },
717 { "upnp_max_port_ext", V_PORT },
718 #ifndef USE_MINIUPNPD
719 // { "upnp_config", V_01 },
720 { "upnp_max_age", V_RANGE(5, 9999) },
721 #endif
723 // forward-basic
724 { "portforward", V_LENGTH(0, 4096) },
726 // forward-triggered
727 { "trigforward", V_LENGTH(0, 4096) },
730 // access restriction
731 { "rruleN", V_RANGE(0, 49) },
732 // { "rrule##", V_LENGTH(0, 2048) }, // in save_variables()
734 // admin-access
735 { "http_enable", V_01 },
736 { "https_enable", V_01 },
737 { "https_crt_save", V_01 },
738 { "https_crt_cn", V_LENGTH(0, 64) },
739 { "https_crt_gen", V_TEMP },
740 { "remote_management", V_01 },
741 { "remote_mgt_https", V_01 },
742 { "http_lanport", V_PORT },
743 { "https_lanport", V_PORT },
744 { "web_wl_filter", V_01 },
745 { "web_css", V_LENGTH(1, 32) },
746 { "web_mx", V_LENGTH(0, 128) },
747 { "http_wanport", V_PORT },
748 { "telnetd_eas", V_01 },
749 { "telnetd_port", V_PORT },
750 { "sshd_eas", V_01 },
751 { "sshd_pass", V_01 },
752 { "sshd_port", V_PORT },
753 { "sshd_remote", V_01 },
754 { "sshd_forwarding", V_01 },
755 { "sshd_rport", V_PORT },
756 { "sshd_authkeys", V_TEXT(0, 4096) },
757 { "rmgt_sip", V_LENGTH(0, 512) },
758 { "ne_shlimit", V_TEXT(1, 50) },
760 // admin-bwm
761 { "rstats_enable", V_01 },
762 { "rstats_path", V_LENGTH(0, 48) },
763 { "rstats_stime", V_RANGE(1, 168) },
764 { "rstats_offset", V_RANGE(1, 31) },
765 { "rstats_exclude", V_LENGTH(0, 64) },
766 { "rstats_sshut", V_01 },
767 { "rstats_bak", V_01 },
769 // admin-buttons
770 { "sesx_led", V_RANGE(0, 255) }, // amber, white, aoss
771 { "sesx_b0", V_RANGE(0, 5) }, // 0-5: toggle wireless, reboot, shutdown, script, usb unmount
772 { "sesx_b1", V_RANGE(0, 5) }, // "
773 { "sesx_b2", V_RANGE(0, 5) }, // "
774 { "sesx_b3", V_RANGE(0, 5) }, // "
775 { "sesx_script", V_TEXT(0, 1024) }, //
776 { "script_brau", V_TEXT(0, 1024) }, //
778 // admin-debug
779 { "debug_nocommit", V_01 },
780 { "debug_cprintf", V_01 },
781 { "debug_cprintf_file", V_01 },
782 // { "debug_keepfiles", V_01 },
783 { "debug_ddns", V_01 },
784 { "debug_norestart", V_TEXT(0, 128) },
785 { "console_loglevel", V_RANGE(1, 8) },
786 { "t_cafree", V_01 },
787 { "t_hidelr", V_01 },
789 // admin-sched
790 { "sch_rboot", V_TEXT(0, 64) },
791 { "sch_rcon", V_TEXT(0, 64) },
792 { "sch_c1", V_TEXT(0, 64) },
793 { "sch_c1_cmd", V_TEXT(0, 2048) },
794 { "sch_c2", V_TEXT(0, 64) },
795 { "sch_c2_cmd", V_TEXT(0, 2048) },
796 { "sch_c3", V_TEXT(0, 64) },
797 { "sch_c3_cmd", V_TEXT(0, 2048) },
799 // admin-scripts
800 { "script_init", V_TEXT(0, 4096) },
801 { "script_shut", V_TEXT(0, 4096) },
802 { "script_fire", V_TEXT(0, 8192) },
803 { "script_wanup", V_TEXT(0, 4096) },
805 // admin-log
806 { "log_remote", V_01 },
807 { "log_remoteip", V_LENGTH(0, 512) },
808 { "log_remoteport", V_PORT },
809 { "log_file", V_01 },
810 { "log_limit", V_RANGE(0, 2400) },
811 { "log_in", V_RANGE(0, 3) },
812 { "log_out", V_RANGE(0, 3) },
813 { "log_mark", V_RANGE(0, 99999) },
814 { "log_events", V_TEXT(0, 32) }, // "acre,crond,ntp"
816 // admin-log-webmonitor
817 { "log_wm", V_01 },
818 { "log_wmtype", V_RANGE(0, 2) },
819 { "log_wmip", V_LENGTH(0, 512) },
820 { "log_wmdmax", V_RANGE(0, 9999) },
821 { "log_wmsmax", V_RANGE(0, 9999) },
823 // admin-cifs
824 { "cifs1", V_LENGTH(1, 1024) },
825 { "cifs2", V_LENGTH(1, 1024) },
827 // admin-jffs2
828 { "jffs2_on", V_01 },
829 { "jffs2_exec", V_LENGTH(0, 64) },
830 { "jffs2_format", V_01 },
832 // nas-usb - !!TB
833 #ifdef TCONFIG_USB
834 { "usb_enable", V_01 },
835 { "usb_uhci", V_RANGE(-1, 1) }, // -1 - disabled, 0 - off, 1 - on
836 { "usb_ohci", V_RANGE(-1, 1) },
837 { "usb_usb2", V_RANGE(-1, 1) },
838 { "usb_irq_thresh", V_RANGE(0, 6) },
839 { "usb_storage", V_01 },
840 { "usb_printer", V_01 },
841 { "usb_printer_bidirect", V_01 },
842 { "usb_fs_ext3", V_01 },
843 { "usb_fs_fat", V_01 },
844 #ifdef TCONFIG_NTFS
845 { "usb_fs_ntfs", V_01 },
846 #endif
847 { "usb_automount", V_01 },
848 { "script_usbhotplug", V_TEXT(0, 2048) },
849 { "script_usbmount", V_TEXT(0, 2048) },
850 { "script_usbumount", V_TEXT(0, 2048) },
851 #endif
853 // nas-ftp - !!TB
854 #ifdef TCONFIG_FTP
855 { "ftp_enable", V_RANGE(0, 2) },
856 { "ftp_super", V_01 },
857 { "ftp_anonymous", V_RANGE(0, 3) },
858 { "ftp_dirlist", V_RANGE(0, 2) },
859 { "ftp_port", V_PORT },
860 { "ftp_max", V_RANGE(0, 12) },
861 { "ftp_ipmax", V_RANGE(0, 12) },
862 { "ftp_staytimeout", V_RANGE(0, 65535) },
863 { "ftp_rate", V_RANGE(0, 99999) },
864 { "ftp_anonrate", V_RANGE(0, 99999) },
865 { "ftp_anonroot", V_LENGTH(0, 256) },
866 { "ftp_pubroot", V_LENGTH(0, 256) },
867 { "ftp_pvtroot", V_LENGTH(0, 256) },
868 { "ftp_users", V_LENGTH(0, 4096) },
869 { "ftp_custom", V_TEXT(0, 2048) },
870 { "ftp_sip", V_LENGTH(0, 512) },
871 { "ftp_limit", V_TEXT(1, 50) },
872 { "log_ftp", V_01 },
873 #endif
875 #ifdef TCONFIG_SAMBASRV
876 // nas-samba - !!TB
877 { "smbd_enable", V_RANGE(0, 2) },
878 { "smbd_wgroup", V_LENGTH(0, 20) },
879 { "smbd_master", V_01 },
880 { "smbd_wins", V_01 },
881 { "smbd_cpage", V_LENGTH(0, 4) },
882 { "smbd_cset", V_LENGTH(0, 20) },
883 { "smbd_custom", V_TEXT(0, 2048) },
884 { "smbd_autoshare", V_RANGE(0, 3) },
885 { "smbd_shares", V_LENGTH(0, 4096) },
886 { "smbd_user", V_LENGTH(0, 50) },
887 { "smbd_passwd", V_LENGTH(0, 50) },
888 #endif
890 #ifdef TCONFIG_MEDIA_SERVER
891 // nas-media
892 { "ms_enable", V_01 },
893 { "ms_dirs", V_LENGTH(0, 1024) },
894 { "ms_port", V_RANGE(0, 65535) },
895 { "ms_dbdir", V_LENGTH(0, 256) },
896 { "ms_tivo", V_01 },
897 { "ms_stdlna", V_01 },
898 { "ms_rescan", V_01 },
899 { "ms_sas", V_01 },
900 #endif
902 // qos
903 { "qos_enable", V_01 },
904 { "qos_ack", V_01 },
905 { "qos_syn", V_01 },
906 { "qos_fin", V_01 },
907 { "qos_rst", V_01 },
908 { "qos_icmp", V_01 },
909 { "qos_reset", V_01 },
910 { "qos_pfifo", V_01 }, // !!TB
911 { "qos_obw", V_RANGE(10, 999999) },
912 { "qos_ibw", V_RANGE(10, 999999) },
913 { "qos_orules", V_LENGTH(0, 4096) },
914 { "qos_default", V_RANGE(0, 9) },
915 { "qos_irates", V_LENGTH(0, 128) },
916 { "qos_orates", V_LENGTH(0, 128) },
918 { "ne_vegas", V_01 },
919 { "ne_valpha", V_NUM },
920 { "ne_vbeta", V_NUM },
921 { "ne_vgamma", V_NUM },
923 #ifdef TCONFIG_OPENVPN
924 // vpn
925 { "vpn_debug", V_01 },
926 { "vpn_server_eas", V_NONE },
927 { "vpn_server_dns", V_NONE },
928 { "vpn_server1_poll", V_RANGE(0, 1440) },
929 { "vpn_server1_if", V_TEXT(3, 3) }, // tap, tun
930 { "vpn_server1_proto", V_TEXT(3, 10) }, // udp, tcp-server
931 { "vpn_server1_port", V_PORT },
932 { "vpn_server1_firewall", V_TEXT(0, 8) }, // auto, external, custom
933 { "vpn_server1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
934 { "vpn_server1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
935 { "vpn_server1_cipher", V_TEXT(0, 16) },
936 { "vpn_server1_dhcp", V_01 },
937 { "vpn_server1_r1", V_IP },
938 { "vpn_server1_r2", V_IP },
939 { "vpn_server1_sn", V_IP },
940 { "vpn_server1_nm", V_IP },
941 { "vpn_server1_local", V_IP },
942 { "vpn_server1_remote", V_IP },
943 { "vpn_server1_reneg", V_RANGE(-1,2147483647)},
944 { "vpn_server1_hmac", V_RANGE(-1, 2) },
945 { "vpn_server1_plan", V_01 },
946 { "vpn_server1_ccd", V_01 },
947 { "vpn_server1_c2c", V_01 },
948 { "vpn_server1_ccd_excl", V_01 },
949 { "vpn_server1_ccd_val", V_NONE },
950 { "vpn_server1_pdns", V_01 },
951 { "vpn_server1_rgw", V_01 },
952 { "vpn_server1_custom", V_NONE },
953 { "vpn_server1_static", V_NONE },
954 { "vpn_server1_ca", V_NONE },
955 { "vpn_server1_crt", V_NONE },
956 { "vpn_server1_key", V_NONE },
957 { "vpn_server1_dh", V_NONE },
958 { "vpn_server2_poll", V_RANGE(0, 1440) },
959 { "vpn_server2_if", V_TEXT(3, 3) }, // tap, tun
960 { "vpn_server2_proto", V_TEXT(3, 10) }, // udp, tcp-server
961 { "vpn_server2_port", V_PORT },
962 { "vpn_server2_firewall", V_TEXT(0, 8) }, // auto, external, custom
963 { "vpn_server2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
964 { "vpn_server2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
965 { "vpn_server2_cipher", V_TEXT(0, 16) },
966 { "vpn_server2_dhcp", V_01 },
967 { "vpn_server2_r1", V_IP },
968 { "vpn_server2_r2", V_IP },
969 { "vpn_server2_sn", V_IP },
970 { "vpn_server2_nm", V_IP },
971 { "vpn_server2_local", V_IP },
972 { "vpn_server2_remote", V_IP },
973 { "vpn_server2_reneg", V_RANGE(-1,2147483647)},
974 { "vpn_server2_hmac", V_RANGE(-1, 2) },
975 { "vpn_server2_plan", V_01 },
976 { "vpn_server2_pdns", V_01 },
977 { "vpn_server2_rgw", V_01 },
978 { "vpn_server2_custom", V_NONE },
979 { "vpn_server2_ccd", V_01 },
980 { "vpn_server2_c2c", V_01 },
981 { "vpn_server2_ccd_excl", V_01 },
982 { "vpn_server2_ccd_val", V_NONE },
983 { "vpn_server2_static", V_NONE },
984 { "vpn_server2_ca", V_NONE },
985 { "vpn_server2_crt", V_NONE },
986 { "vpn_server2_key", V_NONE },
987 { "vpn_server2_dh", V_NONE },
988 { "vpn_client_eas", V_NONE },
989 { "vpn_client1_poll", V_RANGE(0, 1440) },
990 { "vpn_client1_if", V_TEXT(3, 3) }, // tap, tun
991 { "vpn_client1_bridge", V_01 },
992 { "vpn_client1_nat", V_01 },
993 { "vpn_client1_proto", V_TEXT(3, 10) }, // udp, tcp-server
994 { "vpn_client1_addr", V_NONE },
995 { "vpn_client1_port", V_PORT },
996 { "vpn_client1_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
997 { "vpn_client1_firewall", V_TEXT(0, 6) }, // auto, custom
998 { "vpn_client1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
999 { "vpn_client1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1000 { "vpn_client1_cipher", V_TEXT(0, 16) },
1001 { "vpn_client1_local", V_IP },
1002 { "vpn_client1_remote", V_IP },
1003 { "vpn_client1_nm", V_IP },
1004 { "vpn_client1_reneg", V_RANGE(-1,2147483647)},
1005 { "vpn_client1_hmac", V_RANGE(-1, 2) },
1006 { "vpn_client1_adns", V_RANGE(0, 3) },
1007 { "vpn_client1_rgw", V_01 },
1008 { "vpn_client1_gw", V_TEXT(0, 15) },
1009 { "vpn_client1_custom", V_NONE },
1010 { "vpn_client1_static", V_NONE },
1011 { "vpn_client1_ca", V_NONE },
1012 { "vpn_client1_crt", V_NONE },
1013 { "vpn_client1_key", V_NONE },
1014 { "vpn_client2_poll", V_RANGE(0, 1440) },
1015 { "vpn_client2_if", V_TEXT(3, 3) }, // tap, tun
1016 { "vpn_client2_bridge", V_01 },
1017 { "vpn_client2_nat", V_01 },
1018 { "vpn_client2_proto", V_TEXT(3, 10) }, // udp, tcp-server
1019 { "vpn_client2_addr", V_NONE },
1020 { "vpn_client2_port", V_PORT },
1021 { "vpn_client2_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
1022 { "vpn_client2_firewall", V_TEXT(0, 6) }, // auto, custom
1023 { "vpn_client2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
1024 { "vpn_client2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
1025 { "vpn_client2_cipher", V_TEXT(0, 16) },
1026 { "vpn_client2_local", V_IP },
1027 { "vpn_client2_remote", V_IP },
1028 { "vpn_client2_nm", V_IP },
1029 { "vpn_client2_reneg", V_RANGE(-1,2147483647)},
1030 { "vpn_client2_hmac", V_RANGE(-1, 2) },
1031 { "vpn_client2_adns", V_RANGE(0, 3) },
1032 { "vpn_client2_rgw", V_01 },
1033 { "vpn_client2_gw", V_TEXT(0, 15) },
1034 { "vpn_client2_custom", V_NONE },
1035 { "vpn_client2_static", V_NONE },
1036 { "vpn_client2_ca", V_NONE },
1037 { "vpn_client2_crt", V_NONE },
1038 { "vpn_client2_key", V_NONE },
1039 #endif // vpn
1042 ppp_static 0/1
1043 ppp_static_ip IP
1044 wl_enable 0/1
1045 wl_wds_timeout
1046 wl_maxassoc 1-256
1047 wl_phytype a,b,g
1048 wl_net_reauth
1049 wl_preauth
1050 wl_wme_ap_bk
1051 wl_wme_ap_be
1052 wl_wme_ap_vi
1053 wl_wme_ap_vo
1054 wl_wme_sta_bk
1055 wl_wme_sta_be
1056 wl_wme_sta_vi
1057 wl_wme_sta_vo
1059 port_priority_1 0-2
1060 port_flow_control_1 0,1
1061 port_rate_limit_1 0-8
1062 port_priority_2 0-2
1063 port_flow_control_2 0,1
1064 port_rate_limit_2 0-8
1065 port_priority_3 0-2
1066 port_flow_control_3 0,1
1067 port_rate_limit_3 0-8
1068 port_priority_4 0-2
1069 port_flow_control_4 0,1
1070 port_rate_limit_4 0-8
1071 wl_ap_ip
1072 wl_ap_ssid
1075 { NULL }
1078 static int save_variables(int write)
1080 const nvset_t *v;
1081 char *p, *e;
1082 int n;
1083 long l;
1084 unsigned u[6];
1085 int ok;
1086 char s[256];
1087 int dirty;
1088 static const char *msgf = "The field \"%s\" is invalid. Please report this problem.";
1090 dirty = 0;
1091 for (v = nvset_list; v->name; ++v) {
1092 // _dprintf("[%s] %p\n", v->name, webcgi_get((char*)v->name));
1093 if ((p = webcgi_get((char*)v->name)) == NULL) continue;
1094 ok = 1;
1095 switch (v->vtype) {
1096 case VT_TEXT:
1097 p = unix_string(p); // NOTE: p = malloc'd
1098 // drop
1099 case VT_LENGTH:
1100 n = strlen(p);
1101 if ((n < v->va.i) || (n > v->vb.i)) ok = 0;
1102 break;
1103 case VT_RANGE:
1104 l = strtol(p, &e, 10);
1105 if ((p == e) || (*e) || (l < v->va.l) || (l > v->vb.l)) ok = 0;
1106 break;
1107 case VT_IP:
1108 if ((sscanf(p, "%3u.%3u.%3u.%3u", &u[0], &u[1], &u[2], &u[3]) != 4) ||
1109 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255)) ok = 0;
1110 break;
1111 case VT_MAC:
1112 if ((sscanf(p, "%2x:%2x:%2x:%2x:%2x:%2x", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]) != 6) ||
1113 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255) || (u[4] > 255) || (u[5] > 255)) ok = 0;
1114 break;
1115 default:
1116 // shutup gcc
1117 break;
1119 if (!ok) {
1120 if (v->vtype == VT_TEXT) free(p);
1122 sprintf(s, msgf, v->name);
1123 resmsg_set(s);
1124 return 0;
1126 if (write) {
1127 if (!nvram_match((char *)v->name, p)) {
1128 if (v->vtype != VT_TEMP) dirty = 1;
1129 nvram_set(v->name, p);
1132 if (v->vtype == VT_TEXT) free(p);
1136 // special cases
1138 char *p1, *p2;
1139 if (((p1 = webcgi_get("set_password_1")) != NULL) && (strcmp(p1, "**********") != 0)) {
1140 if (((p2 = webcgi_get("set_password_2")) != NULL) && (strcmp(p1, p2) == 0)) {
1141 if ((write) && (!nvram_match("http_passwd", p1))) {
1142 dirty = 1;
1143 nvram_set("http_passwd", p1);
1146 else {
1147 sprintf(s, msgf, "password");
1148 resmsg_set(s);
1149 return 0;
1153 for (n = 0; n < 50; ++n) {
1154 sprintf(s, "rrule%d", n);
1155 if ((p = webcgi_get(s)) != NULL) {
1156 if (strlen(p) > 2048) {
1157 sprintf(s, msgf, s);
1158 resmsg_set(s);
1159 return 0;
1161 if ((write) && (!nvram_match(s, p))) {
1162 dirty = 1;
1163 nvram_set(s, p);
1168 return (write) ? dirty : 1;
1171 static void wo_tomato(char *url)
1173 char *v;
1174 int i;
1175 int ajax;
1176 int nvset;
1177 const char *red;
1178 int commit;
1180 // _dprintf("tomato.cgi\n");
1182 red = webcgi_safeget("_redirect", "");
1183 if (!*red) send_header(200, NULL, mime_html, 0);
1185 commit = atoi(webcgi_safeget("_commit", "1"));
1186 ajax = atoi(webcgi_safeget("_ajax", "0"));
1188 nvset = atoi(webcgi_safeget("_nvset", "1"));
1189 if (nvset) {
1190 if (!save_variables(0)) {
1191 if (ajax) {
1192 web_printf("@msg:%s", resmsg_get());
1194 else {
1195 parse_asp("error.asp");
1197 return;
1199 commit = save_variables(1) && commit;
1201 resmsg_set("Settings saved.");
1204 rboot = atoi(webcgi_safeget("_reboot", "0"));
1205 if (rboot) {
1206 parse_asp("reboot.asp");
1208 else {
1209 if (ajax) {
1210 web_printf("@msg:%s", resmsg_get());
1212 else if (atoi(webcgi_safeget("_moveip", "0"))) {
1213 parse_asp("saved-moved.asp");
1215 else if (!*red) {
1216 parse_asp("saved.asp");
1220 if (commit) {
1221 _dprintf("commit from tomato.cgi\n");
1222 nvram_commit_x();
1225 if ((v = webcgi_get("_service")) != NULL && *v != 0) {
1226 if (!*red) {
1227 if (ajax) web_printf(" Some services are being restarted...");
1228 web_close();
1230 sleep(1);
1232 if (*v == '*') {
1233 kill(1, SIGHUP);
1235 else {
1236 exec_service(v);
1240 for (i = atoi(webcgi_safeget("_sleep", "0")); i > 0; --i) sleep(1);
1242 if (*red) redirect(red);
1244 if (rboot) {
1245 web_close();
1246 sleep(1);
1247 kill(1, SIGTERM);
1252 // ----------------------------------------------------------------------------
1255 static void wo_update(char *url)
1257 const aspapi_t *api;
1258 const char *name;
1259 int argc;
1260 char *argv[16];
1261 char s[32];
1263 if ((name = webcgi_get("exec")) != NULL) {
1264 for (api = aspapi; api->name; ++api) {
1265 if (strcmp(api->name, name) == 0) {
1266 for (argc = 0; argc < 16; ++argc) {
1267 sprintf(s, "arg%d", argc);
1268 if ((argv[argc] = (char *)webcgi_get(s)) == NULL) break;
1270 api->exec(argc, argv);
1271 break;
1277 static void wo_service(char *url)
1279 int n;
1281 exec_service(webcgi_safeget("_service", ""));
1283 if ((n = atoi(webcgi_safeget("_sleep", "2"))) <= 0) n = 2;
1284 sleep(n);
1286 common_redirect();
1289 static void wo_shutdown(char *url)
1291 parse_asp("shutdown.asp");
1292 web_close();
1293 sleep(1);
1295 kill(1, SIGQUIT);
1298 static void wo_nvcommit(char *url)
1300 parse_asp("saved.asp");
1301 web_close();
1302 nvram_commit();