Changes from Tomato 1.28 beta (1808)
[tomato.git] / release / src / router / httpd / tomato.c
blob0645be8039ea28c3d50458af9f7d57b1c938a303
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[128];
180 sprintf(cmd, "%s >%s 2>&1", webExecFile, output);
181 system(cmd);
182 unlink(webQueryFile);
183 unlink(webExecFile);
186 static void wo_cgi_bin(char *url)
188 char webOutpFile[] = "/tmp/.woXXXXXX";
189 int fd;
191 if ((fd = mkstemp(webOutpFile)) < 0)
192 exit(1);
193 close(fd);
195 _execute_command(url, NULL, post_buf, webOutpFile);
197 if (post_buf) {
198 free(post_buf);
199 post_buf = NULL;
201 wo_asp(webOutpFile);
202 unlink(webOutpFile);
205 static void wo_shell(char *url)
207 char webOutpFile[] = "/tmp/.woXXXXXX";
208 int fd;
210 if ((fd = mkstemp(webOutpFile)) < 0)
211 exit(1);
212 close(fd);
214 _execute_command(NULL, webcgi_get("command"), NULL, webOutpFile);
216 web_puts("\ncmdresult = '");
217 web_putfile(webOutpFile, WOF_JAVASCRIPT);
218 web_puts("';");
219 unlink(webOutpFile);
222 static void wo_blank(char *url)
224 web_puts("\n\n\n\n");
227 static void wo_favicon(char *url)
229 send_header(200, NULL, "image/vnd.microsoft.icon", 0);
230 do_file(url);
232 if (nvram_match("web_favicon", "1")) {
233 send_header(200, NULL, "image/vnd.microsoft.icon", 0);
234 do_file(url);
236 else {
237 send_error(404, NULL, NULL);
242 static void wo_cfe(char *url)
244 do_file(MTD_DEV(0ro));
247 static void wo_nvram(char *url)
249 web_pipecmd("nvram show", WOF_NONE);
252 static void wo_iptables(char *url)
254 web_pipecmd("iptables -nvL; iptables -t nat -nvL; iptables -t mangle -nvL", WOF_NONE);
258 static void wo_spin(char *url)
260 char s[64];
262 strlcpy(s, nvram_safe_get("web_css"), sizeof(s));
263 strlcat(s, "_spin.gif", sizeof(s));
264 if (f_exists(s)) do_file(s);
265 else do_file("_spin.gif");
269 void common_redirect(void)
271 if (atoi(webcgi_safeget("_ajax", ""))) {
272 send_header(200, NULL, mime_html, 0);
273 web_puts("OK");
275 else {
276 redirect(webcgi_safeget("_redirect", "/"));
280 // ----------------------------------------------------------------------------
282 const struct mime_handler mime_handlers[] = {
283 { "update.cgi", mime_javascript, 0, wi_generic, wo_update, 1 },
284 { "tomato.cgi", NULL, 0, wi_generic, wo_tomato, 1 },
286 { "debug.js", mime_javascript, 5, wi_generic_noid, wo_blank, 1 }, // while debugging
287 { "cfe/*.bin", mime_binary, 0, wi_generic, wo_cfe, 1 },
288 { "nvram/*.txt", mime_binary, 0, wi_generic, wo_nvram, 1 },
289 { "ipt/*.txt", mime_binary, 0, wi_generic, wo_iptables, 1 },
291 { "cfg/*.cfg", NULL, 0, wi_generic, wo_backup, 1 },
292 { "cfg/restore.cgi", mime_html, 0, wi_restore, wo_restore, 1 },
293 { "cfg/defaults.cgi", NULL, 0, wi_generic, wo_defaults, 1 },
295 { "bwm/*.gz", NULL, 0, wi_generic, wo_bwmbackup, 1 },
296 { "bwm/restore.cgi", NULL, 0, wi_bwmrestore, wo_bwmrestore, 1 },
298 { "logs/view.cgi", NULL, 0, wi_generic, wo_viewlog, 1 },
299 { "logs/*.txt", 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 },
324 { "dhcpc.cgi", NULL, 0, wi_generic, wo_dhcpc, 1 },
325 { "dhcpd.cgi", mime_javascript, 0, wi_generic, wo_dhcpd, 1 },
326 { "nvcommit.cgi", NULL, 0, wi_generic, wo_nvcommit, 1 },
327 { "ping.cgi", mime_javascript, 0, wi_generic, wo_ping, 1 },
328 { "trace.cgi", mime_javascript, 0, wi_generic, wo_trace, 1 },
329 { "upgrade.cgi", mime_html, 0, wi_upgrade, wo_flash, 1 },
330 { "upnp.cgi", NULL, 0, wi_generic, wo_upnp, 1 },
331 { "wakeup.cgi", NULL, 0, wi_generic, wo_wakeup, 1 },
332 { "wlmnoise.cgi", mime_html, 0, wi_generic, wo_wlmnoise, 1 },
333 { "wlradio.cgi", NULL, 0, wi_generic, wo_wlradio, 1 },
334 { "resolve.cgi", mime_javascript, 0, wi_generic, wo_resolve, 1 },
335 { "expct.cgi", mime_html, 0, wi_generic, wo_expct, 1 },
336 { "service.cgi", NULL, 0, wi_generic, wo_service, 1 },
337 // { "logout.cgi", NULL, 0, wi_generic, wo_logout, 0 }, // see httpd.c
338 { "shutdown.cgi", mime_html, 0, wi_generic, wo_shutdown, 1 },
339 #ifdef TCONFIG_OPENVPN
340 { "vpnstatus.cgi", mime_javascript, 0, wi_generic, wo_vpn_status, 1 },
341 #endif
342 #ifdef TCONFIG_USB
343 { "usbcmd.cgi", mime_javascript, 0, wi_generic, wo_usbcommand, 1 }, //!!TB - USB
344 #endif
345 #ifdef BLACKHOLE
346 { "blackhole.cgi", NULL, 0, wi_blackhole, NULL, 1 },
347 #endif
348 // { "test", mime_html, 0, wi_generic, wo_test, 1 },
349 { NULL, NULL, 0, NULL, NULL, 1 }
352 const aspapi_t aspapi[] = {
353 { "activeroutes", asp_activeroutes },
354 { "arplist", asp_arplist },
355 { "bandwidth", asp_bandwidth },
356 { "build_time", asp_build_time },
357 { "cgi_get", asp_cgi_get },
358 { "compmac", asp_compmac },
359 { "ctcount", asp_ctcount },
360 { "ctdump", asp_ctdump },
361 { "ddnsx", asp_ddnsx },
362 { "devlist", asp_devlist },
363 { "dhcpc_time", asp_dhcpc_time },
364 { "dns", asp_dns },
365 { "ident", asp_ident },
366 { "lanip", asp_lanip },
367 { "layer7", asp_layer7 },
368 { "link_uptime", asp_link_uptime },
369 { "lipp", asp_lipp },
370 { "netdev", asp_netdev },
371 { "notice", asp_notice },
372 { "nv", asp_nv },
373 { "nvram", asp_nvram },
374 { "nvramseq", asp_nvramseq },
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 { "wlchannel", asp_wlchannel },
387 { "wlclient", asp_wlclient },
388 { "wlcrssi", asp_wlcrssi },
389 { "wlnoise", asp_wlnoise },
390 { "wlnbw", asp_wlnbw },
391 { "wlnctrlsb", asp_wlnctrlsb },
392 { "wlradio", asp_wlradio },
393 { "wlscan", asp_wlscan },
394 { "wlchannels", asp_wlchannels }, //!!TB
395 { "wlcountries", asp_wlcountries },
396 { "wlrate", asp_wlrate },
397 #ifdef TCONFIG_USB
398 { "usbdevices", asp_usbdevices }, //!!TB - USB Support
399 #endif
400 { "css", asp_css },
401 { NULL, NULL }
404 // -----------------------------------------------------------------------------
406 static void asp_css(int argc, char **argv)
408 const char *css = nvram_safe_get("web_css");
410 if (strcmp(css, "tomato") != 0) {
411 web_printf("<link rel='stylesheet' type='text/css' href='%s.css'>", css);
415 // -----------------------------------------------------------------------------
417 const char *resmsg_get(void)
419 return webcgi_safeget("resmsg", "");
422 void resmsg_set(const char *msg)
424 webcgi_set("resmsg", strdup(msg)); // m ok
427 int resmsg_fread(const char *fname)
429 char s[256];
430 char *p;
432 f_read_string(fname, s, sizeof(s));
433 if ((p = strchr(s, '\n')) != NULL) *p = 0;
434 if (s[0]) {
435 resmsg_set(s);
436 return 1;
438 return 0;
441 static void asp_resmsg(int argc, char **argv)
443 char *p;
445 if ((p = js_string(webcgi_safeget("resmsg", (argc > 0) ? argv[0] : ""))) == NULL) return;
446 web_printf("\nresmsg='%s';\n", p);
447 free(p);
450 // ----------------------------------------------------------------------------
452 // verification... simple sanity checks. UI should verify all fields.
454 // todo: move and re-use for filtering - zzz
456 typedef union {
457 int i;
458 long l;
459 const char *s;
460 } nvset_varg_t;
462 typedef struct {
463 const char *name;
464 enum {
465 VT_NONE, // no checking
466 VT_LENGTH, // check length of string
467 VT_TEXT, // strip \r, check length of string
468 VT_RANGE, // expect an integer, check range
469 VT_IP, // expect an ip address
470 VT_MAC, // expect a mac address
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, { }, { }
491 static const nvset_t nvset_list[] = {
493 // basic-ident
494 { "router_name", V_LENGTH(0, 32) },
495 { "wan_hostname", V_LENGTH(0, 32) },
496 { "wan_domain", V_LENGTH(0, 32) },
498 // basic-time
499 { "tm_tz", V_LENGTH(1, 64) }, // PST8PDT
500 { "tm_sel", V_LENGTH(1, 64) }, // PST8PDT
501 { "tm_dst", V_01 },
502 { "ntp_updates", V_RANGE(-1, 24) },
503 { "ntp_tdod", V_01 },
504 { "ntp_server", V_LENGTH(1, 150) }, // x y z
505 { "ntp_kiss", V_LENGTH(0, 255) },
507 // basic-static
508 { "dhcpd_static", V_LENGTH(0, 106*101)}, // 106 (max chars per entry) x 100 entries
510 // basic-ddns
511 { "ddnsx0", V_LENGTH(0, 2048) },
512 { "ddnsx1", V_LENGTH(0, 2048) },
513 { "ddnsx0_cache", V_LENGTH(0, 1) }, // only to clear
514 { "ddnsx1_cache", V_LENGTH(0, 1) },
515 { "ddnsx_ip", V_LENGTH(0, 32) },
516 { "ddnsx_save", V_01 },
517 { "ddnsx_refresh", V_RANGE(0, 365) },
519 // basic-network
520 // WAN
521 { "wan_proto", V_LENGTH(1, 16) }, // disabled, dhcp, static, pppoe, pptp, l2tp
522 { "wan_ipaddr", V_IP },
523 { "wan_netmask", V_IP },
524 { "wan_gateway", V_IP },
525 { "hb_server_ip", V_LENGTH(0, 32) },
526 { "l2tp_server_ip", V_LENGTH(0, 128) },
527 { "pptp_server_ip", V_LENGTH(0, 128) },
528 { "pptp_dhcp", V_01 },
529 { "ppp_username", V_LENGTH(0, 60) },
530 { "ppp_passwd", V_LENGTH(0, 60) },
531 { "ppp_service", V_LENGTH(0, 50) },
532 { "ppp_demand", V_01 },
533 { "ppp_idletime", V_RANGE(0, 1440) },
534 { "ppp_redialperiod", V_RANGE(1, 86400) },
535 { "mtu_enable", V_01 },
536 { "wan_mtu", V_RANGE(576, 1500) },
537 { "wan_islan", V_01 },
539 // LAN
540 { "lan_ipaddr", V_IP },
541 { "lan_netmask", V_IP },
542 { "lan_gateway", V_IP },
543 { "wan_dns", V_LENGTH(0, 50) }, // ip ip ip
544 { "lan_proto", V_WORD }, // static, dhcp
545 { "dhcp_start", V_RANGE(1, 254) }, // remove !
546 { "dhcp_num", V_RANGE(1, 255) }, // remove !
547 { "dhcpd_startip", V_IP },
548 { "dhcpd_endip", V_IP },
549 { "dhcp_lease", V_RANGE(1, 10080) },
550 { "wan_wins", V_IP },
552 // wireless
553 { "wl_radio", V_01 },
554 { "wl_mode", V_LENGTH(2, 3) }, // ap, sta, wet, wds
555 { "wl_net_mode", V_LENGTH(5, 8) }, // disabled, mixed, b-only, g-only, bg-mixed, n-only [speedbooster]
556 { "wl_ssid", V_LENGTH(1, 32) },
557 { "wl_closed", V_01 },
558 { "wl_channel", V_RANGE(0, 14) }, //!!TB - 0=Auto
559 #if TOMATO_N
560 // ! update
561 #endif
563 { "security_mode2", V_LENGTH(1, 32) }, // disabled, radius, wep, wpa_personal, wpa_enterprise, wpa2_personal, wpa2_enterprise
564 { "wl_radius_ipaddr", V_IP },
565 { "wl_radius_port", V_PORT },
566 { "wl_radius_key", V_LENGTH(1, 64) },
567 { "wl_wep_bit", V_RANGE(64, 128) }, // 64 or 128
568 { "wl_passphrase", V_LENGTH(0, 20) },
569 { "wl_key", V_RANGE(1, 4) },
570 { "wl_key1", V_LENGTH(0, 26) },
571 { "wl_key2", V_LENGTH(0, 26) },
572 { "wl_key3", V_LENGTH(0, 26) },
573 { "wl_key4", V_LENGTH(0, 26) },
574 { "wl_crypto", V_LENGTH(3, 8) }, // tkip, aes, tkip+aes
575 { "wl_wpa_psk", V_LENGTH(8, 64) },
576 { "wl_wpa_gtk_rekey", V_RANGE(60, 7200) },
578 { "wl_lazywds", V_01 },
579 { "wl_wds", V_LENGTH(0, 180) }, // mac mac mac (x 10)
581 { "security_mode", V_LENGTH(1, 32) }, // disabled, radius, wpa, psk,wep, wpa2, psk2, wpa wpa2, psk psk2
582 { "wds_enable", V_01 },
583 { "wl_gmode", V_RANGE(-1, 6) },
584 { "wl_wep", V_LENGTH(1, 32) }, // off, on, restricted,tkip,aes,tkip+aes
585 { "wl_akm", V_LENGTH(0, 32) }, // wpa, wpa2, psk, psk2, wpa wpa2, psk psk2, ""
586 { "wl_auth_mode", V_LENGTH(4, 6) }, // none, radius
588 { "wl_nmode", V_NONE },
589 { "wl_nreqd", V_NONE },
590 { "wl_nbw_cap", V_RANGE(0, 2) }, // 0 - 20MHz, 1 - 40MHz, 2 - Auto
591 { "wl_nbw", V_NONE },
592 { "wl_mimo_preamble", V_WORD }, // 802.11n Preamble: mm/gf/auto/gfbcm
593 { "wl_nctrlsb", V_NONE }, // none, lower, upper
595 // basic-wfilter
596 { "wl_macmode", V_NONE }, // allow, deny, disabled
597 { "wl_maclist", V_LENGTH(0, 18*201) }, // 18 x 200 (11:22:33:44:55:66 ...)
598 { "macnames", V_LENGTH(0, 62*201) }, // 62 (12+1+48+1) x 50 (112233445566<..>) todo: re-use -- zzz
600 // advanced-ctnf
601 { "ct_max", V_RANGE(128, 300000) },
602 { "ct_tcp_timeout", V_LENGTH(20, 70) },
603 { "ct_udp_timeout", V_LENGTH(5, 15) },
604 { "ct_timeout", V_LENGTH(5, 15) },
605 { "nf_ttl", V_RANGE(-10, 10) },
606 { "nf_l7in", V_01 },
607 #ifdef LINUX26
608 { "nf_sip", V_01 },
609 { "ct_hashsize", V_RANGE(127, 65535) },
610 #endif
611 { "nf_rtsp", V_01 },
612 { "nf_pptp", V_01 },
613 { "nf_h323", V_01 },
614 { "nf_ftp", V_01 },
616 // advanced-dhcpdns
617 { "dhcpd_slt", V_RANGE(-1, 43200) }, // -1=infinite, 0=follow normal lease time, >=1 custom
618 { "dhcpd_dmdns", V_01 },
619 { "dhcpd_lmax", V_NUM },
620 { "dhcpd_gwmode", V_NUM },
621 { "dns_addget", V_01 },
622 { "dns_intcpt", V_01 },
623 { "dhcpc_minpkt", V_01 },
624 { "dnsmasq_custom", V_TEXT(0, 2048) },
625 // { "dnsmasq_norw", V_01 },
627 // advanced-firewall
628 { "block_wan", V_01 },
629 { "multicast_pass", V_01 },
630 { "block_loopback", V_01 },
631 { "nf_loopback", V_NUM },
632 { "ne_syncookies", V_01 },
634 // advanced-misc
635 { "wait_time", V_RANGE(3, 20) },
636 { "wan_speed", V_RANGE(0, 4) },
637 { "jumbo_frame_enable", V_01 }, // Jumbo Frames support (for RT-N16/WNR3500L)
638 { "jumbo_frame_size", V_RANGE(1, 9720) },
640 // advanced-mac
641 { "mac_wan", V_LENGTH(0, 17) },
642 { "mac_wl", V_LENGTH(0, 17) },
644 // advanced-routing
645 { "routes_static", V_LENGTH(0, 2048) },
646 { "dhcp_routes", V_01 },
647 { "lan_stp", V_RANGE(0, 1) },
648 { "wk_mode", V_LENGTH(1, 32) }, // gateway, router
649 #ifdef TCONFIG_ZEBRA
650 { "dr_setting", V_RANGE(0, 3) },
651 { "dr_lan_tx", V_LENGTH(0, 32) },
652 { "dr_lan_rx", V_LENGTH(0, 32) },
653 { "dr_wan_tx", V_LENGTH(0, 32) },
654 { "dr_wan_rx", V_LENGTH(0, 32) },
655 #endif
657 // advanced-wireless
658 { "wl_country", V_LENGTH(0, 64) }, // !!TB - Country code
659 { "wl_country_code", V_LENGTH(0, 4) }, // !!TB - Country code
660 { "wl_btc_mode", V_RANGE(0, 2) }, // !!TB - BT Coexistence Mode: 0 (disable), 1 (enable), 2 (preemption)
661 { "wl_afterburner", V_LENGTH(2, 4) }, // off, on, auto
662 { "wl_auth", V_01 },
663 { "wl_rateset", V_LENGTH(2, 7) }, // all, default, 12
664 { "wl_rate", V_RANGE(0, 54 * 1000 * 1000) },
665 { "wl_mrate", V_RANGE(0, 54 * 1000 * 1000) },
666 { "wl_gmode_protection",V_LENGTH(3, 4) }, // off, auto
667 { "wl_frameburst", V_ONOFF }, // off, on
668 { "wl_bcn", V_RANGE(1, 65535) },
669 { "wl_dtim", V_RANGE(1, 255) },
670 { "wl_frag", V_RANGE(256, 2346) },
671 { "wl_rts", V_RANGE(0, 2347) },
672 { "wl_ap_isolate", V_01 },
673 { "wl_plcphdr", V_LENGTH(4, 5) }, // long, short
674 { "wl_antdiv", V_RANGE(0, 3) },
675 { "wl_txant", V_RANGE(0, 3) },
676 { "wl_txpwr", V_RANGE(0, 255) },
677 { "wl_wme", V_WORD }, // auto, off, on
678 { "wl_wme_no_ack", V_ONOFF }, // off, on
679 { "wl_wme_apsd", V_ONOFF }, // off, on
680 { "wl_maxassoc", V_RANGE(0, 255) },
681 { "wl_distance", V_LENGTH(0, 5) }, // "", 1-99999
682 { "wlx_hpamp", V_01 },
683 { "wlx_hperx", V_01 },
684 { "wl_reg_mode", V_LENGTH(1, 3) }, // !!TB - Regulatory: off, h, d
686 { "wl_nmode_protection", V_WORD, }, // off, auto
687 { "wl_nmcsidx", V_RANGE(-2, 32), }, // -2 - 32
689 // forward-dmz
690 { "dmz_enable", V_01 },
691 { "dmz_ipaddr", V_LENGTH(0, 15) },
692 { "dmz_sip", V_LENGTH(0, 512) },
694 // forward-upnp
695 { "upnp_enable", V_NUM },
696 { "upnp_secure", V_01 },
697 { "upnp_port", V_RANGE(0, 65535) },
698 { "upnp_ssdp_interval", V_RANGE(10, 9999) },
699 { "upnp_mnp", V_01 },
700 { "upnp_clean", V_01 },
701 { "upnp_clean_interval", V_RANGE(60, 65535) },
702 { "upnp_clean_threshold", V_RANGE(0, 9999) },
703 { "upnp_min_port_int", V_PORT },
704 { "upnp_max_port_int", V_PORT },
705 { "upnp_min_port_ext", V_PORT },
706 { "upnp_max_port_ext", V_PORT },
707 #ifndef USE_MINIUPNPD
708 // { "upnp_config", V_01 },
709 { "upnp_max_age", V_RANGE(5, 9999) },
710 #endif
712 // forward-basic
713 { "portforward", V_LENGTH(0, 4096) },
715 // forward-triggered
716 { "trigforward", V_LENGTH(0, 4096) },
719 // access restriction
720 { "rruleN", V_RANGE(0, 49) },
721 // { "rrule##", V_LENGTH(0, 2048) }, // in save_variables()
723 // admin-access
724 { "http_enable", V_01 },
725 { "https_enable", V_01 },
726 { "https_crt_save", V_01 },
727 { "https_crt_cn", V_LENGTH(0, 64) },
728 { "https_crt_gen", V_TEMP },
729 { "remote_management", V_01 },
730 { "remote_mgt_https", V_01 },
731 { "http_lanport", V_PORT },
732 { "https_lanport", V_PORT },
733 { "web_wl_filter", V_01 },
734 { "web_css", V_LENGTH(1, 32) },
735 { "web_mx", V_LENGTH(0, 128) },
736 { "http_wanport", V_PORT },
737 { "telnetd_eas", V_01 },
738 { "telnetd_port", V_PORT },
739 { "sshd_eas", V_01 },
740 { "sshd_pass", V_01 },
741 { "sshd_port", V_PORT },
742 { "sshd_remote", V_01 },
743 { "sshd_forwarding", V_01 },
744 { "sshd_rport", V_PORT },
745 { "sshd_authkeys", V_TEXT(0, 4096) },
746 { "rmgt_sip", V_LENGTH(0, 512) },
747 { "ne_shlimit", V_TEXT(1, 50) },
749 // admin-bwm
750 { "rstats_enable", V_01 },
751 { "rstats_path", V_LENGTH(0, 48) },
752 { "rstats_stime", V_RANGE(1, 168) },
753 { "rstats_offset", V_RANGE(1, 31) },
754 { "rstats_exclude", V_LENGTH(0, 64) },
755 { "rstats_sshut", V_01 },
756 { "rstats_bak", V_01 },
758 // admin-buttons
759 { "sesx_led", V_RANGE(0, 255) }, // amber, white, aoss
760 { "sesx_b0", V_RANGE(0, 5) }, // 0-5: toggle wireless, reboot, shutdown, script, usb unmount
761 { "sesx_b1", V_RANGE(0, 5) }, // "
762 { "sesx_b2", V_RANGE(0, 5) }, // "
763 { "sesx_b3", V_RANGE(0, 5) }, // "
764 { "sesx_script", V_TEXT(0, 1024) }, //
765 { "script_brau", V_TEXT(0, 1024) }, //
767 // admin-debug
768 { "debug_nocommit", V_01 },
769 { "debug_cprintf", V_01 },
770 { "debug_cprintf_file", V_01 },
771 // { "debug_keepfiles", V_01 },
772 { "debug_ddns", V_01 },
773 { "debug_norestart", V_TEXT(0, 128) },
774 { "console_loglevel", V_RANGE(1, 8) },
775 { "t_cafree", V_01 },
776 { "t_hidelr", V_01 },
778 // admin-sched
779 { "sch_rboot", V_TEXT(0, 64) },
780 { "sch_rcon", V_TEXT(0, 64) },
781 { "sch_c1", V_TEXT(0, 64) },
782 { "sch_c1_cmd", V_TEXT(0, 2048) },
783 { "sch_c2", V_TEXT(0, 64) },
784 { "sch_c2_cmd", V_TEXT(0, 2048) },
785 { "sch_c3", V_TEXT(0, 64) },
786 { "sch_c3_cmd", V_TEXT(0, 2048) },
788 // admin-scripts
789 { "script_init", V_TEXT(0, 4096) },
790 { "script_shut", V_TEXT(0, 4096) },
791 { "script_fire", V_TEXT(0, 8192) },
792 { "script_wanup", V_TEXT(0, 4096) },
794 // admin-log
795 { "log_remote", V_01 },
796 { "log_remoteip", V_IP },
797 { "log_remoteport", V_PORT },
798 { "log_file", V_01 },
799 { "log_limit", V_RANGE(0, 2400) },
800 { "log_in", V_RANGE(0, 3) },
801 { "log_out", V_RANGE(0, 3) },
802 { "log_mark", V_RANGE(0, 1440) },
803 { "log_events", V_TEXT(0, 32) }, // "acre,crond,ntp"
805 // admin-cifs
806 { "cifs1", V_LENGTH(1, 1024) },
807 { "cifs2", V_LENGTH(1, 1024) },
809 // admin-jffs2
810 { "jffs2_on", V_01 },
811 { "jffs2_exec", V_LENGTH(0, 64) },
812 { "jffs2_format", V_01 },
814 // nas-usb - !!TB
815 #ifdef TCONFIG_USB
816 { "usb_enable", V_01 },
817 { "usb_uhci", V_01 },
818 { "usb_ohci", V_01 },
819 { "usb_usb2", V_01 },
820 { "usb_storage", V_01 },
821 { "usb_printer", V_01 },
822 { "usb_printer_bidirect", V_01 },
823 { "usb_fs_ext3", V_01 },
824 { "usb_fs_fat", V_01 },
825 #ifdef TCONFIG_NTFS
826 { "usb_fs_ntfs", V_01 },
827 #endif
828 { "usb_automount", V_01 },
829 { "script_usbhotplug", V_TEXT(0, 2048) },
830 { "script_usbmount", V_TEXT(0, 2048) },
831 { "script_usbumount", V_TEXT(0, 2048) },
832 #endif
834 // nas-ftp - !!TB
835 #ifdef TCONFIG_FTP
836 { "ftp_enable", V_RANGE(0, 2) },
837 { "ftp_super", V_01 },
838 { "ftp_anonymous", V_RANGE(0, 3) },
839 { "ftp_dirlist", V_RANGE(0, 2) },
840 { "ftp_port", V_PORT },
841 { "ftp_max", V_RANGE(0, 12) },
842 { "ftp_ipmax", V_RANGE(0, 12) },
843 { "ftp_staytimeout", V_RANGE(0, 65535) },
844 { "ftp_rate", V_RANGE(0, 99999) },
845 { "ftp_anonrate", V_RANGE(0, 99999) },
846 { "ftp_anonroot", V_LENGTH(0, 256) },
847 { "ftp_pubroot", V_LENGTH(0, 256) },
848 { "ftp_pvtroot", V_LENGTH(0, 256) },
849 { "ftp_users", V_LENGTH(0, 4096) },
850 { "ftp_custom", V_TEXT(0, 2048) },
851 { "ftp_sip", V_LENGTH(0, 512) },
852 { "ftp_limit", V_TEXT(1, 50) },
853 { "log_ftp", V_01 },
854 #endif
856 #ifdef TCONFIG_SAMBASRV
857 // nas-samba - !!TB
858 { "smbd_enable", V_RANGE(0, 2) },
859 { "smbd_wgroup", V_LENGTH(0, 20) },
860 { "smbd_master", V_01 },
861 { "smbd_wins", V_01 },
862 { "smbd_cpage", V_LENGTH(0, 4) },
863 { "smbd_cset", V_LENGTH(0, 20) },
864 { "smbd_loglevel", V_RANGE(0, 100) },
865 { "smbd_custom", V_TEXT(0, 2048) },
866 { "smbd_autoshare", V_RANGE(0, 3) },
867 { "smbd_shares", V_LENGTH(0, 4096) },
868 { "smbd_user", V_LENGTH(0, 50) },
869 { "smbd_passwd", V_LENGTH(0, 50) },
870 #endif
872 // qos
873 { "qos_enable", V_01 },
874 { "qos_ack", V_01 },
875 { "qos_syn", V_01 },
876 { "qos_fin", V_01 },
877 { "qos_rst", V_01 },
878 { "qos_icmp", V_01 },
879 { "qos_reset", V_01 },
880 { "qos_pfifo", V_01 }, // !!TB
881 { "qos_obw", V_RANGE(10, 999999) },
882 { "qos_ibw", V_RANGE(10, 999999) },
883 { "qos_orules", V_LENGTH(0, 4096) },
884 { "qos_default", V_RANGE(0, 9) },
885 { "qos_irates", V_LENGTH(0, 128) },
886 { "qos_orates", V_LENGTH(0, 128) },
888 { "ne_vegas", V_01 },
889 { "ne_valpha", V_NUM },
890 { "ne_vbeta", V_NUM },
891 { "ne_vgamma", V_NUM },
893 #ifdef TCONFIG_OPENVPN
894 // vpn
895 { "vpn_debug", V_01 },
896 { "vpn_server_eas", V_NONE },
897 { "vpn_server_dns", V_NONE },
898 { "vpn_server1_poll", V_RANGE(0, 1440) },
899 { "vpn_server1_if", V_TEXT(3, 3) }, // tap, tun
900 { "vpn_server1_proto", V_TEXT(3, 10) }, // udp, tcp-server
901 { "vpn_server1_port", V_PORT },
902 { "vpn_server1_firewall", V_TEXT(0, 8) }, // auto, external, custom
903 { "vpn_server1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
904 { "vpn_server1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
905 { "vpn_server1_cipher", V_TEXT(0, 16) },
906 { "vpn_server1_dhcp", V_01 },
907 { "vpn_server1_r1", V_IP },
908 { "vpn_server1_r2", V_IP },
909 { "vpn_server1_sn", V_IP },
910 { "vpn_server1_nm", V_IP },
911 { "vpn_server1_local", V_IP },
912 { "vpn_server1_remote", V_IP },
913 { "vpn_server1_reneg", V_RANGE(-1,2147483647)},
914 { "vpn_server1_hmac", V_RANGE(-1, 2) },
915 { "vpn_server1_plan", V_01 },
916 { "vpn_server1_ccd", V_01 },
917 { "vpn_server1_c2c", V_01 },
918 { "vpn_server1_ccd_excl", V_01 },
919 { "vpn_server1_ccd_val", V_NONE },
920 { "vpn_server1_pdns", V_01 },
921 { "vpn_server1_rgw", V_01 },
922 { "vpn_server1_custom", V_NONE },
923 { "vpn_server1_static", V_NONE },
924 { "vpn_server1_ca", V_NONE },
925 { "vpn_server1_crt", V_NONE },
926 { "vpn_server1_key", V_NONE },
927 { "vpn_server1_dh", V_NONE },
928 { "vpn_server2_poll", V_RANGE(0, 1440) },
929 { "vpn_server2_if", V_TEXT(3, 3) }, // tap, tun
930 { "vpn_server2_proto", V_TEXT(3, 10) }, // udp, tcp-server
931 { "vpn_server2_port", V_PORT },
932 { "vpn_server2_firewall", V_TEXT(0, 8) }, // auto, external, custom
933 { "vpn_server2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
934 { "vpn_server2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
935 { "vpn_server2_cipher", V_TEXT(0, 16) },
936 { "vpn_server2_dhcp", V_01 },
937 { "vpn_server2_r1", V_IP },
938 { "vpn_server2_r2", V_IP },
939 { "vpn_server2_sn", V_IP },
940 { "vpn_server2_nm", V_IP },
941 { "vpn_server2_local", V_IP },
942 { "vpn_server2_remote", V_IP },
943 { "vpn_server2_reneg", V_RANGE(-1,2147483647)},
944 { "vpn_server2_hmac", V_RANGE(-1, 2) },
945 { "vpn_server2_plan", V_01 },
946 { "vpn_server2_pdns", V_01 },
947 { "vpn_server2_rgw", V_01 },
948 { "vpn_server2_custom", V_NONE },
949 { "vpn_server2_ccd", V_01 },
950 { "vpn_server2_c2c", V_01 },
951 { "vpn_server2_ccd_excl", V_01 },
952 { "vpn_server2_ccd_val", V_NONE },
953 { "vpn_server2_static", V_NONE },
954 { "vpn_server2_ca", V_NONE },
955 { "vpn_server2_crt", V_NONE },
956 { "vpn_server2_key", V_NONE },
957 { "vpn_server2_dh", V_NONE },
958 { "vpn_client_eas", V_NONE },
959 { "vpn_client1_poll", V_RANGE(0, 1440) },
960 { "vpn_client1_if", V_TEXT(3, 3) }, // tap, tun
961 { "vpn_client1_bridge", V_01 },
962 { "vpn_client1_nat", V_01 },
963 { "vpn_client1_proto", V_TEXT(3, 10) }, // udp, tcp-server
964 { "vpn_client1_addr", V_NONE },
965 { "vpn_client1_port", V_PORT },
966 { "vpn_client1_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
967 { "vpn_client1_firewall", V_TEXT(0, 6) }, // auto, custom
968 { "vpn_client1_crypt", V_TEXT(0, 6) }, // tls, secret, custom
969 { "vpn_client1_comp", V_TEXT(0, 8) }, // yes, no, adaptive
970 { "vpn_client1_cipher", V_TEXT(0, 16) },
971 { "vpn_client1_local", V_IP },
972 { "vpn_client1_remote", V_IP },
973 { "vpn_client1_nm", V_IP },
974 { "vpn_client1_reneg", V_RANGE(-1,2147483647)},
975 { "vpn_client1_hmac", V_RANGE(-1, 2) },
976 { "vpn_client1_adns", V_RANGE(0, 3) },
977 { "vpn_client1_rgw", V_01 },
978 { "vpn_client1_gw", V_TEXT(0, 15) },
979 { "vpn_client1_custom", V_NONE },
980 { "vpn_client1_static", V_NONE },
981 { "vpn_client1_ca", V_NONE },
982 { "vpn_client1_crt", V_NONE },
983 { "vpn_client1_key", V_NONE },
984 { "vpn_client2_poll", V_RANGE(0, 1440) },
985 { "vpn_client2_if", V_TEXT(3, 3) }, // tap, tun
986 { "vpn_client2_bridge", V_01 },
987 { "vpn_client2_nat", V_01 },
988 { "vpn_client2_proto", V_TEXT(3, 10) }, // udp, tcp-server
989 { "vpn_client2_addr", V_NONE },
990 { "vpn_client2_port", V_PORT },
991 { "vpn_client2_retry", V_RANGE(-1,32767) }, // -1 infinite, 0 disabled, >= 1 custom
992 { "vpn_client2_firewall", V_TEXT(0, 6) }, // auto, custom
993 { "vpn_client2_crypt", V_TEXT(0, 6) }, // tls, secret, custom
994 { "vpn_client2_comp", V_TEXT(0, 8) }, // yes, no, adaptive
995 { "vpn_client2_cipher", V_TEXT(0, 16) },
996 { "vpn_client2_local", V_IP },
997 { "vpn_client2_remote", V_IP },
998 { "vpn_client2_nm", V_IP },
999 { "vpn_client2_reneg", V_RANGE(-1,2147483647)},
1000 { "vpn_client2_hmac", V_RANGE(-1, 2) },
1001 { "vpn_client2_adns", V_RANGE(0, 3) },
1002 { "vpn_client2_rgw", V_01 },
1003 { "vpn_client2_gw", V_TEXT(0, 15) },
1004 { "vpn_client2_custom", V_NONE },
1005 { "vpn_client2_static", V_NONE },
1006 { "vpn_client2_ca", V_NONE },
1007 { "vpn_client2_crt", V_NONE },
1008 { "vpn_client2_key", V_NONE },
1009 #endif // vpn
1012 ppp_static 0/1
1013 ppp_static_ip IP
1014 wl_enable 0/1
1015 wl_wds_timeout
1016 wl_maxassoc 1-256
1017 wl_phytype a,b,g
1018 wl_net_reauth
1019 wl_preauth
1020 wl_wme_ap_bk
1021 wl_wme_ap_be
1022 wl_wme_ap_vi
1023 wl_wme_ap_vo
1024 wl_wme_sta_bk
1025 wl_wme_sta_be
1026 wl_wme_sta_vi
1027 wl_wme_sta_vo
1029 port_priority_1 0-2
1030 port_flow_control_1 0,1
1031 port_rate_limit_1 0-8
1032 port_priority_2 0-2
1033 port_flow_control_2 0,1
1034 port_rate_limit_2 0-8
1035 port_priority_3 0-2
1036 port_flow_control_3 0,1
1037 port_rate_limit_3 0-8
1038 port_priority_4 0-2
1039 port_flow_control_4 0,1
1040 port_rate_limit_4 0-8
1041 wl_ap_ip
1042 wl_ap_ssid
1045 { NULL }
1048 static int save_variables(int write)
1050 const nvset_t *v;
1051 char *p, *e;
1052 int n;
1053 long l;
1054 unsigned u[6];
1055 int ok;
1056 char s[256];
1057 int dirty;
1058 static const char *msgf = "The field \"%s\" is invalid. Please report this problem.";
1060 dirty = 0;
1061 for (v = nvset_list; v->name; ++v) {
1062 // _dprintf("[%s] %p\n", v->name, webcgi_get((char*)v->name));
1063 if ((p = webcgi_get((char*)v->name)) == NULL) continue;
1064 ok = 1;
1065 switch (v->vtype) {
1066 case VT_TEXT:
1067 p = unix_string(p); // NOTE: p = malloc'd
1068 // drop
1069 case VT_LENGTH:
1070 n = strlen(p);
1071 if ((n < v->va.i) || (n > v->vb.i)) ok = 0;
1072 break;
1073 case VT_RANGE:
1074 l = strtol(p, &e, 10);
1075 if ((p == e) || (*e) || (l < v->va.l) || (l > v->vb.l)) ok = 0;
1076 break;
1077 case VT_IP:
1078 if ((sscanf(p, "%3u.%3u.%3u.%3u", &u[0], &u[1], &u[2], &u[3]) != 4) ||
1079 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255)) ok = 0;
1080 break;
1081 case VT_MAC:
1082 if ((sscanf(p, "%2x:%2x:%2x:%2x:%2x:%2x", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]) != 6) ||
1083 (u[0] > 255) || (u[1] > 255) || (u[2] > 255) || (u[3] > 255) || (u[4] > 255) || (u[5] > 255)) ok = 0;
1084 break;
1085 default:
1086 // shutup gcc
1087 break;
1089 if (!ok) {
1090 if (v->vtype == VT_TEXT) free(p);
1092 sprintf(s, msgf, v->name);
1093 resmsg_set(s);
1094 return 0;
1096 if (write) {
1097 if (!nvram_match((char *)v->name, p)) {
1098 if (v->vtype != VT_TEMP) dirty = 1;
1099 nvram_set(v->name, p);
1102 if (v->vtype == VT_TEXT) free(p);
1106 // special cases
1108 char *p1, *p2;
1109 if (((p1 = webcgi_get("set_password_1")) != NULL) && (strcmp(p1, "**********") != 0)) {
1110 if (((p2 = webcgi_get("set_password_2")) != NULL) && (strcmp(p1, p2) == 0)) {
1111 if ((write) && (!nvram_match("http_passwd", p1))) {
1112 dirty = 1;
1113 nvram_set("http_passwd", p1);
1116 else {
1117 sprintf(s, msgf, "password");
1118 resmsg_set(s);
1119 return 0;
1123 for (n = 0; n < 50; ++n) {
1124 sprintf(s, "rrule%d", n);
1125 if ((p = webcgi_get(s)) != NULL) {
1126 if (strlen(p) > 2048) {
1127 sprintf(s, msgf, s);
1128 resmsg_set(s);
1129 return 0;
1131 if ((write) && (!nvram_match(s, p))) {
1132 dirty = 1;
1133 nvram_set(s, p);
1138 return (write) ? dirty : 1;
1141 static void wo_tomato(char *url)
1143 char *v;
1144 int i;
1145 int ajax;
1146 int nvset;
1147 const char *red;
1148 int commit;
1150 // _dprintf("tomato.cgi\n");
1152 red = webcgi_safeget("_redirect", "");
1153 if (!*red) send_header(200, NULL, mime_html, 0);
1155 commit = atoi(webcgi_safeget("_commit", "1"));
1156 ajax = atoi(webcgi_safeget("_ajax", "0"));
1158 nvset = atoi(webcgi_safeget("_nvset", "1"));
1159 if (nvset) {
1160 if (!save_variables(0)) {
1161 if (ajax) {
1162 web_printf("@msg:%s", resmsg_get());
1164 else {
1165 parse_asp("error.asp");
1167 return;
1169 commit = save_variables(1) && commit;
1171 resmsg_set("Settings saved.");
1174 rboot = atoi(webcgi_safeget("_reboot", "0"));
1175 if (rboot) {
1176 parse_asp("reboot.asp");
1178 else {
1179 if (ajax) {
1180 web_printf("@msg:%s", resmsg_get());
1182 else if (atoi(webcgi_safeget("_moveip", "0"))) {
1183 parse_asp("saved-moved.asp");
1185 else if (!*red) {
1186 parse_asp("saved.asp");
1190 if (commit) {
1191 _dprintf("commit from tomato.cgi\n");
1192 nvram_commit_x();
1195 if ((v = webcgi_get("_service")) != NULL && *v != 0) {
1196 if (!*red) {
1197 if (ajax) web_printf(" Some services are being restarted...");
1198 web_close();
1200 sleep(1);
1202 if (*v == '*') {
1203 kill(1, SIGHUP);
1205 else {
1206 exec_service(v);
1210 for (i = atoi(webcgi_safeget("_sleep", "0")); i > 0; --i) sleep(1);
1212 if (*red) redirect(red);
1214 if (rboot) {
1215 web_close();
1216 sleep(1);
1217 kill(1, SIGTERM);
1222 // ----------------------------------------------------------------------------
1225 static void wo_update(char *url)
1227 const aspapi_t *api;
1228 const char *name;
1229 int argc;
1230 char *argv[16];
1231 char s[32];
1233 if ((name = webcgi_get("exec")) != NULL) {
1234 for (api = aspapi; api->name; ++api) {
1235 if (strcmp(api->name, name) == 0) {
1236 for (argc = 0; argc < 16; ++argc) {
1237 sprintf(s, "arg%d", argc);
1238 if ((argv[argc] = (char *)webcgi_get(s)) == NULL) break;
1240 api->exec(argc, argv);
1241 break;
1247 static void wo_service(char *url)
1249 int n;
1251 exec_service(webcgi_safeget("_service", ""));
1253 if ((n = atoi(webcgi_safeget("_sleep", "2"))) <= 0) n = 2;
1254 sleep(n);
1256 common_redirect();
1259 static void wo_shutdown(char *url)
1261 parse_asp("shutdown.asp");
1262 web_close();
1263 sleep(1);
1265 kill(1, SIGQUIT);
1268 static void wo_nvcommit(char *url)
1270 parse_asp("saved.asp");
1271 web_close();
1272 nvram_commit();