4 Copyright (C) 2006-2009 Jonathan Zarate
10 #include <sys/sysinfo.h>
12 #include <arpa/inet.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
;
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
)
44 _dprintf("exec_service: %s\n", action
);
47 while ((!nvram_match("action_service", "")) && (i
-- > 0)) {
48 _dprintf("%s: waiting before %d\n", __FUNCTION__
, i
);
52 nvram_set("action_service", action
);
56 while ((nvram_match("action_service", (char *)action
)) && (i
-- > 0)) {
57 _dprintf("%s: waiting after %d\n", __FUNCTION__
, i
);
62 if (atoi(webcgi_safeget("_service_wait", ""))) {
64 while ((nvram_match("action_service", (char *)action)) && (i-- > 0)) {
65 _dprintf("%s: waiting after %d\n", __FUNCTION__, i);
72 static void wi_generic_noid(char *url
, int len
, char *boundary
)
75 if (len
>= (32 * 1024)) {
76 // syslog(LOG_WARNING, "POST max");
80 if (post_buf
) free(post_buf
);
81 if ((post_buf
= malloc(len
+ 1)) == NULL
) {
82 // syslog(LOG_CRIT, "Unable to allocate post buffer");
86 if (web_read_x(post_buf
, len
) != len
) {
90 webcgi_init(post_buf
);
94 void wi_generic(char *url
, int len
, char *boundary
)
96 wi_generic_noid(url
, len
, boundary
);
100 // !!TB - CGI Support
101 void wi_cgi_bin(char *url
, int len
, char *boundary
)
103 if (post_buf
) free(post_buf
);
107 if (len
>= (32 * 1024)) {
108 syslog(LOG_WARNING
, "POST length exceeded maximum allowed");
113 if ((post_buf
= malloc(len
+ 1)) == NULL
) {
116 if (web_read_x(post_buf
, len
) != len
) {
124 static void _execute_command(char *url
, char *command
, char *query
, char *output
)
126 char webExecFile
[] = "/tmp/.wxXXXXXX";
127 char webQueryFile
[] = "/tmp/.wqXXXXXX";
131 if (query
) mktemp(webQueryFile
);
133 if ((f
= fopen(webExecFile
, "wb")) != NULL
) {
136 "export REQUEST_METHOD=\"%s\"\n"
140 post
? "POST" : "GET", getenv("PATH"),
141 command
? "" : "./", command
? command
: url
,
142 query
? "<" : "", query
? webQueryFile
: "");
149 chmod(webExecFile
, 0700);
152 if ((f
= fopen(webQueryFile
, "wb")) != NULL
) {
153 fprintf(f
, "%s\n", query
);
164 sprintf(cmd
, "%s >%s 2>&1", webExecFile
, output
);
166 unlink(webQueryFile
);
170 static void wo_cgi_bin(char *url
)
172 char webOutpFile
[] = "/tmp/.woXXXXXX";
175 _execute_command(url
, NULL
, post_buf
, webOutpFile
);
185 static void wo_shell(char *url
)
187 char webOutpFile
[] = "/tmp/.woXXXXXX";
190 _execute_command(NULL
, webcgi_get("command"), NULL
, webOutpFile
);
192 web_puts("\ncmdresult = '");
193 web_putfile(webOutpFile
, WOF_JAVASCRIPT
);
198 static void wo_blank(char *url
)
200 web_puts("\n\n\n\n");
203 static void wo_favicon(char *url
)
205 send_header(200, NULL
, "image/vnd.microsoft.icon", 0);
208 if (nvram_match("web_favicon", "1")) {
209 send_header(200, NULL, "image/vnd.microsoft.icon", 0);
213 send_error(404, NULL, NULL);
218 static void wo_cfe(char *url
)
220 do_file("/dev/mtd/0ro");
223 static void wo_nvram(char *url
)
225 web_pipecmd("nvram show", WOF_NONE
);
228 static void wo_iptables(char *url
)
230 web_pipecmd("iptables -nvL; iptables -t nat -nvL; iptables -t mangle -nvL", WOF_NONE
);
234 static void wo_spin(char *url)
238 strlcpy(s, nvram_safe_get("web_css"), sizeof(s));
239 strlcat(s, "_spin.gif", sizeof(s));
240 if (f_exists(s)) do_file(s);
241 else do_file("_spin.gif");
245 void common_redirect(void)
247 if (atoi(webcgi_safeget("_ajax", ""))) {
248 send_header(200, NULL
, mime_html
, 0);
252 redirect(webcgi_safeget("_redirect", "/"));
256 // ----------------------------------------------------------------------------
258 const struct mime_handler mime_handlers
[] = {
259 { "update.cgi", mime_javascript
, 0, wi_generic
, wo_update
, 1 },
260 { "tomato.cgi", NULL
, 0, wi_generic
, wo_tomato
, 1 },
262 { "debug.js", mime_javascript
, 5, wi_generic_noid
, wo_blank
, 1 }, // while debugging
263 { "cfe/*.bin", mime_binary
, 0, wi_generic
, wo_cfe
, 1 },
264 { "nvram/*.txt", mime_binary
, 0, wi_generic
, wo_nvram
, 1 },
265 { "ipt/*.txt", mime_binary
, 0, wi_generic
, wo_iptables
, 1 },
267 { "cfg/*.cfg", NULL
, 0, wi_generic
, wo_backup
, 1 },
268 { "cfg/restore.cgi", mime_html
, 0, wi_restore
, wo_restore
, 1 },
269 { "cfg/defaults.cgi", NULL
, 0, wi_generic
, wo_defaults
, 1 },
271 { "bwm/*.gz", NULL
, 0, wi_generic
, wo_bwmbackup
, 1 },
272 { "bwm/restore.cgi", NULL
, 0, wi_bwmrestore
, wo_bwmrestore
, 1 },
274 { "logs/view.cgi", NULL
, 0, wi_generic
, wo_viewlog
, 1 },
275 { "logs/*.txt", NULL
, 0, wi_generic
, wo_syslog
, 1 },
277 { "logout.asp", NULL
, 0, wi_generic
, wo_asp
, 1 },
278 { "clearcookies.asp", NULL
, 0, wi_generic
, wo_asp
, 1 },
280 // { "spin.gif", NULL, 0, wi_generic_noid, wo_spin, 1 },
282 { "**.asp", NULL
, 0, wi_generic_noid
, wo_asp
, 1 },
283 { "**.css", "text/css", 2, wi_generic_noid
, do_file
, 1 },
284 { "**.htm", mime_html
, 2, wi_generic_noid
, do_file
, 1 },
285 { "**.gif", "image/gif", 5, wi_generic_noid
, do_file
, 1 },
286 { "**.jpg", "image/jpeg", 5, wi_generic_noid
, do_file
, 1 },
287 { "**.png", "image/png", 5, wi_generic_noid
, do_file
, 1 },
288 { "**.js", mime_javascript
, 2, wi_generic_noid
, do_file
, 1 },
289 { "**.jsx", mime_javascript
, 0, wi_generic
, wo_asp
, 1 },
290 { "**.svg", "image/svg+xml", 2, wi_generic_noid
, do_file
, 1 },
291 { "**.txt", mime_plain
, 2, wi_generic_noid
, do_file
, 1 },
292 { "**.bin", mime_binary
, 0, wi_generic_noid
, do_file
, 1 },
293 { "**.bino", mime_octetstream
, 0, wi_generic_noid
, do_file
, 1 },
294 { "favicon.ico", NULL
, 5, wi_generic_noid
, wo_favicon
, 1 },
295 // !!TB - CGI Support, enable downloading archives
296 { "**/cgi-bin/**|**.sh", NULL
, 0, wi_cgi_bin
, wo_cgi_bin
, 1 },
297 { "**.tar|**.gz", mime_binary
, 0, wi_generic_noid
, do_file
, 1 },
298 { "shell.cgi", mime_javascript
, 0, wi_generic
, wo_shell
, 1 },
300 { "dhcpc.cgi", NULL
, 0, wi_generic
, wo_dhcpc
, 1 },
301 { "dhcpd.cgi", mime_javascript
, 0, wi_generic
, wo_dhcpd
, 1 },
302 { "nvcommit.cgi", NULL
, 0, wi_generic
, wo_nvcommit
, 1 },
303 { "ping.cgi", mime_javascript
, 0, wi_generic
, wo_ping
, 1 },
304 { "trace.cgi", mime_javascript
, 0, wi_generic
, wo_trace
, 1 },
305 { "upgrade.cgi", mime_html
, 0, wi_upgrade
, wo_flash
, 1 },
306 { "upnp.cgi", NULL
, 0, wi_generic
, wo_upnp
, 1 },
307 { "wakeup.cgi", NULL
, 0, wi_generic
, wo_wakeup
, 1 },
308 { "wlmnoise.cgi", mime_html
, 0, wi_generic
, wo_wlmnoise
, 1 },
309 { "wlradio.cgi", NULL
, 0, wi_generic
, wo_wlradio
, 1 },
310 { "resolve.cgi", mime_javascript
, 0, wi_generic
, wo_resolve
, 1 },
311 { "expct.cgi", mime_html
, 0, wi_generic
, wo_expct
, 1 },
312 { "service.cgi", NULL
, 0, wi_generic
, wo_service
, 1 },
313 // { "logout.cgi", NULL, 0, wi_generic, wo_logout, 0 }, // see httpd.c
314 { "shutdown.cgi", mime_html
, 0, wi_generic
, wo_shutdown
, 1 },
316 { "usbcmd.cgi", mime_javascript
, 0, wi_generic
, wo_usbcommand
, 1 }, //!!TB - USB
319 { "blackhole.cgi", NULL
, 0, wi_blackhole
, NULL
, 1 },
321 // { "test", mime_html, 0, wi_generic, wo_test, 1 },
322 { NULL
, NULL
, 0, NULL
, NULL
, 1 }
325 const aspapi_t aspapi
[] = {
326 { "activeroutes", asp_activeroutes
},
327 { "arplist", asp_arplist
},
328 { "bandwidth", asp_bandwidth
},
329 { "build_time", asp_build_time
},
330 { "cgi_get", asp_cgi_get
},
331 { "compmac", asp_compmac
},
332 { "ctcount", asp_ctcount
},
333 { "ctdump", asp_ctdump
},
334 { "ddnsx", asp_ddnsx
},
335 { "devlist", asp_devlist
},
336 { "dhcpc_time", asp_dhcpc_time
},
338 { "ident", asp_ident
},
339 { "lanip", asp_lanip
},
340 { "layer7", asp_layer7
},
341 { "link_uptime", asp_link_uptime
},
342 { "lipp", asp_lipp
},
343 { "netdev", asp_netdev
},
344 { "notice", asp_notice
},
346 { "nvram", asp_nvram
},
347 { "nvramseq", asp_nvramseq
},
348 { "psup", asp_psup
},
349 { "qrate", asp_qrate
},
350 { "resmsg", asp_resmsg
},
351 { "rrule", asp_rrule
},
352 { "statfs", asp_statfs
},
353 { "sysinfo", asp_sysinfo
},
354 { "time", asp_time
},
355 { "upnpinfo", asp_upnpinfo
},
356 { "version", asp_version
},
357 { "wanstatus", asp_wanstatus
},
358 { "wanup", asp_wanup
},
360 { "wlchannel", asp_wlchannel
},
361 { "wlclient", asp_wlclient
},
362 { "wlcrssi", asp_wlcrssi
},
363 { "wlnoise", asp_wlnoise
},
364 { "wlradio", asp_wlradio
},
365 { "wlscan", asp_wlscan
},
366 { "wlchannels", asp_wlchannels
}, //!!TB
368 { "sharelist", asp_sharelist
},
371 { "usbdevices", asp_usbdevices
}, //!!TB - USB Support
376 // -----------------------------------------------------------------------------
378 static void asp_css(int argc
, char **argv
)
380 const char *css
= nvram_safe_get("web_css");
382 if (strcmp(css
, "tomato") != 0) {
383 web_printf("<link rel='stylesheet' type='text/css' href='%s.css'>", css
);
387 // -----------------------------------------------------------------------------
389 const char *resmsg_get(void)
391 return webcgi_safeget("resmsg", "");
394 void resmsg_set(const char *msg
)
396 webcgi_set("resmsg", strdup(msg
)); // m ok
399 int resmsg_fread(const char *fname
)
404 f_read_string(fname
, s
, sizeof(s
));
405 if ((p
= strchr(s
, '\n')) != NULL
) *p
= 0;
413 static void asp_resmsg(int argc
, char **argv
)
417 if ((p
= js_string(webcgi_safeget("resmsg", (argc
> 0) ? argv
[0] : ""))) == NULL
) return;
418 web_printf("\nresmsg='%s';\n", p
);
422 // ----------------------------------------------------------------------------
424 // verification... simple sanity checks. UI should verify all fields.
426 // todo: move and re-use for filtering - zzz
437 VT_NONE
, // no checking
438 VT_LENGTH
, // check length of string
439 VT_TEXT
, // strip \r, check length of string
440 VT_RANGE
, // expect an integer, check range
441 VT_IP
, // expect an ip address
442 VT_MAC
, // expect a mac address
443 VT_TEMP
// no checks, no commit
450 #define V_NONE VT_NONE, { }, { }
451 #define V_01 VT_RANGE, { .l = 0 }, { .l = 1 }
452 #define V_PORT VT_RANGE, { .l = 2 }, { .l = 65535 }
453 #define V_ONOFF VT_LENGTH, { .i = 2 }, { .i = 3 }
454 #define V_WORD VT_LENGTH, { .i = 1 }, { .i = 16 }
455 #define V_LENGTH(min, max) VT_LENGTH, { .i = min }, { .i = max }
456 #define V_TEXT(min, max) VT_TEXT, { .i = min }, { .i = max }
457 #define V_RANGE(min, max) VT_RANGE, { .l = min }, { .l = max }
458 #define V_IP VT_IP, { }, { }
459 #define V_OCTET VT_RANGE, { .l = 0 }, { .l = 255 }
460 #define V_NUM VT_RANGE, { .l = 0 }, { .l = 0x7FFFFFFF }
461 #define V_TEMP VT_TEMP, { }, { }
463 static const nvset_t nvset_list
[] = {
466 { "router_name", V_LENGTH(0, 32) },
467 { "wan_hostname", V_LENGTH(0, 32) },
468 { "wan_domain", V_LENGTH(0, 32) },
471 { "tm_tz", V_LENGTH(1, 64) }, // PST8PDT
472 { "tm_sel", V_LENGTH(1, 64) }, // PST8PDT
474 { "ntp_updates", V_RANGE(-1, 24) },
475 { "ntp_tdod", V_01
},
476 { "ntp_server", V_LENGTH(1, 150) }, // x y z
477 { "ntp_kiss", V_LENGTH(0, 255) },
480 { "dhcpd_static", V_LENGTH(0, 106*101)}, // 106 (max chars per entry) x 100 entries
483 { "ddnsx0", V_LENGTH(0, 2048) },
484 { "ddnsx1", V_LENGTH(0, 2048) },
485 { "ddnsx0_cache", V_LENGTH(0, 1) }, // only to clear
486 { "ddnsx1_cache", V_LENGTH(0, 1) },
487 { "ddnsx_ip", V_LENGTH(0, 32) },
488 { "ddnsx_save", V_01
},
489 { "ddnsx_refresh", V_RANGE(0, 365) },
493 { "wan_proto", V_LENGTH(1, 16) }, // disabled, dhcp, static, pppoe, pptp, l2tp
494 { "wan_ipaddr", V_IP
},
495 { "wan_netmask", V_IP
},
496 { "wan_gateway", V_IP
},
497 { "hb_server_ip", V_LENGTH(0, 32) },
498 { "l2tp_server_ip", V_IP
},
499 { "pptp_server_ip", V_IP
},
500 { "ppp_username", V_LENGTH(0, 50) },
501 { "ppp_passwd", V_LENGTH(0, 50) },
502 { "ppp_service", V_LENGTH(0, 50) },
503 { "ppp_demand", V_01
},
504 { "ppp_idletime", V_RANGE(0, 1440) },
505 { "ppp_redialperiod", V_RANGE(1, 86400) },
506 { "mtu_enable", V_01
},
507 { "wan_mtu", V_RANGE(576, 1500) },
508 { "wan_islan", V_01
},
511 { "lan_ipaddr", V_IP
},
512 { "lan_netmask", V_IP
},
513 { "lan_gateway", V_IP
},
514 { "wan_dns", V_LENGTH(0, 50) }, // ip ip ip
515 { "lan_proto", V_WORD
}, // static, dhcp
516 { "dhcp_start", V_RANGE(1, 254) }, // remove !
517 { "dhcp_num", V_RANGE(1, 255) }, // remove !
518 { "dhcpd_startip", V_IP
},
519 { "dhcpd_endip", V_IP
},
520 { "dhcp_lease", V_RANGE(1, 10080) },
521 { "wan_wins", V_IP
},
524 { "wl_radio", V_01
},
525 { "wl_mode", V_LENGTH(2, 3) }, // ap, sta, wet, wds
526 // { "wl_net_mode", V_LENGTH(5, 8) }, // disabled, mixed, b-only, g-only, bg-mixed, n-only [speedbooster]
527 { "wl_ssid", V_LENGTH(1, 32) },
528 { "wl_closed", V_01
},
529 { "wl_channel", V_RANGE(0, 14) }, //!!TB - 0=Auto
534 { "security_mode2", V_LENGTH(1, 32) }, // disabled, radius, wep, wpa_personal, wpa_enterprise, wpa2_personal, wpa2_enterprise
535 { "wl_radius_ipaddr", V_IP
},
536 { "wl_radius_port", V_PORT
},
537 { "wl_radius_key", V_LENGTH(1, 64) },
538 { "wl_wep_bit", V_RANGE(64, 128) }, // 64 or 128
539 { "wl_passphrase", V_LENGTH(0, 20) },
540 { "wl_key", V_RANGE(1, 4) },
541 { "wl_key1", V_LENGTH(0, 26) },
542 { "wl_key2", V_LENGTH(0, 26) },
543 { "wl_key3", V_LENGTH(0, 26) },
544 { "wl_key4", V_LENGTH(0, 26) },
545 { "wl_crypto", V_LENGTH(3, 8) }, // tkip, aes, tkip+aes
546 { "wl_wpa_psk", V_LENGTH(8, 64) },
547 { "wl_wpa_gtk_rekey", V_RANGE(60, 7200) },
549 { "wl_lazywds", V_01
},
550 { "wl_wds", V_LENGTH(0, 180) }, // mac mac mac (x 10)
552 { "security_mode", V_LENGTH(1, 32) }, // disabled, radius, wpa, psk,wep, wpa2, psk2, wpa wpa2, psk psk2
553 { "wds_enable", V_01
},
554 { "wl_gmode", V_RANGE(-1, 6) },
555 { "wl_wep", V_LENGTH(1, 32) }, // off, on, restricted,tkip,aes,tkip+aes
556 { "wl_akm", V_LENGTH(0, 32) }, // wpa, wpa2, psk, psk2, wpa wpa2, psk psk2, ""
557 { "wl_auth_mode", V_LENGTH(4, 6) }, // none, radius
560 { "wl_nmode", V_NONE
},
561 { "wl_nreqd", V_NONE
},
565 { "wl_macmode", V_NONE
}, // allow, deny, disabled
566 { "wl_maclist", V_LENGTH(0, 18*201) }, // 18 x 200 (11:22:33:44:55:66 ...)
567 { "macnames", V_LENGTH(0, 62*201) }, // 62 (12+1+48+1) x 50 (112233445566<..>) todo: re-use -- zzz
570 { "ct_max", V_RANGE(128, 10240) },
571 { "ct_tcp_timeout", V_LENGTH(20, 70) },
572 { "ct_udp_timeout", V_LENGTH(5, 15) },
573 { "ct_timeout", V_LENGTH(5, 15) },
574 { "nf_ttl", V_RANGE(-10, 10) },
582 { "dhcpd_slt", V_RANGE(-1, 43200) }, // -1=infinite, 0=follow normal lease time, >=1 custom
583 { "dhcpd_dmdns", V_01
},
584 { "dhcpd_lmax", V_NUM
},
585 { "dns_addget", V_01
},
586 { "dns_intcpt", V_01
},
587 { "dhcpc_minpkt", V_01
},
588 { "dnsmasq_custom", V_TEXT(0, 2048) },
589 // { "dnsmasq_norw", V_01 },
592 { "block_wan", V_01
},
593 { "multicast_pass", V_01
},
594 { "block_loopback", V_01
},
595 { "nf_loopback", V_NUM
},
596 { "ne_syncookies", V_01
},
599 { "wait_time", V_RANGE(3, 20) },
600 { "wan_speed", V_RANGE(0, 4) },
603 { "mac_wan", V_LENGTH(0, 17) },
604 { "mac_wl", V_LENGTH(0, 17) },
607 { "routes_static", V_LENGTH(0, 2048) },
608 { "lan_stp", V_RANGE(0, 1) },
609 { "wk_mode", V_LENGTH(1, 32) }, // gateway, router
611 { "dr_setting", V_RANGE(0, 3) },
612 { "dr_lan_tx", V_LENGTH(0, 32) },
613 { "dr_lan_rx", V_LENGTH(0, 32) },
614 { "dr_wan_tx", V_LENGTH(0, 32) },
615 { "dr_wan_rx", V_LENGTH(0, 32) },
619 { "wl_country", V_LENGTH(0, 64) }, // !!TB - Country code
620 { "wl_country_code", V_LENGTH(0, 4) }, // !!TB - Country code
621 { "wl_btc_mode", V_RANGE(0, 2) }, // !!TB - BT Coexistence Mode: 0 (disable), 1 (enable), 2 (preemption)
622 { "wl_afterburner", V_LENGTH(2, 4) }, // off, on, auto
624 { "wl_rateset", V_LENGTH(2, 7) }, // all, default, 12
625 { "wl_rate", V_RANGE(0, 54 * 1000 * 1000) },
626 { "wl_mrate", V_RANGE(0, 54 * 1000 * 1000) },
627 { "wl_gmode_protection",V_LENGTH(3, 4) }, // off, auto
628 { "wl_frameburst", V_ONOFF
}, // off, on
629 { "wl_bcn", V_RANGE(1, 65535) },
630 { "wl_dtim", V_RANGE(1, 255) },
631 { "wl_frag", V_RANGE(256, 2346) },
632 { "wl_rts", V_RANGE(0, 2347) },
633 { "wl_ap_isolate", V_01
},
634 { "wl_plcphdr", V_LENGTH(4, 5) }, // long, short
635 { "wl_antdiv", V_RANGE(0, 3) },
636 { "wl_txant", V_RANGE(0, 3) },
637 { "wl_txpwr", V_RANGE(0, 255) },
638 { "wl_wme", V_ONOFF
}, // off, on
639 { "wl_wme_no_ack", V_ONOFF
}, // off, on
640 { "wl_maxassoc", V_RANGE(0, 255) },
641 { "wl_distance", V_LENGTH(0, 5) }, // "", 1-99999
642 { "wlx_hpamp", V_01
},
643 { "wlx_hperx", V_01
},
644 { "wl_reg_mode", V_LENGTH(1, 3) }, // !!TB - Regulatory: off, h, d
647 { "wl_nmode_protection",V_WORD
, }, // off, auto
648 { "wl_nmcsidx", V_RANGE(-2, 15), }, // -2 - 15
652 { "dmz_enable", V_01
},
653 { "dmz_ipaddr", V_LENGTH(0, 15) },
654 { "dmz_sip", V_LENGTH(0, 512) },
657 { "upnp_enable", V_NUM
},
658 { "upnp_secure", V_01
},
659 { "upnp_port", V_RANGE(0, 65535) },
660 { "upnp_ssdp_interval", V_RANGE(10, 9999) },
661 { "upnp_mnp", V_01
},
662 { "upnp_clean", V_01
},
663 { "upnp_clean_interval", V_RANGE(60, 65535) },
664 { "upnp_clean_threshold", V_RANGE(0, 9999) },
665 { "upnp_min_port_int", V_PORT
},
666 { "upnp_max_port_int", V_PORT
},
667 { "upnp_min_port_ext", V_PORT
},
668 { "upnp_max_port_ext", V_PORT
},
669 #ifndef USE_MINIUPNPD
670 // { "upnp_config", V_01 },
671 { "upnp_max_age", V_RANGE(5, 9999) },
675 { "portforward", V_LENGTH(0, 4096) },
678 { "trigforward", V_LENGTH(0, 4096) },
681 // access restriction
682 { "rruleN", V_RANGE(0, 49) },
683 // { "rrule##", V_LENGTH(0, 2048) }, // in save_variables()
686 { "http_enable", V_01
},
687 { "https_enable", V_01
},
688 { "https_crt_save", V_01
},
689 { "https_crt_cn", V_LENGTH(0, 64) },
690 { "https_crt_gen", V_TEMP
},
691 { "remote_management", V_01
},
692 { "remote_mgt_https", V_01
},
693 { "http_lanport", V_PORT
},
694 { "https_lanport", V_PORT
},
695 { "web_wl_filter", V_01
},
696 // { "web_favicon", V_01 },
697 { "web_css", V_LENGTH(1, 32) },
698 { "http_wanport", V_PORT
},
699 { "telnetd_eas", V_01
},
700 { "telnetd_port", V_PORT
},
701 { "sshd_eas", V_01
},
702 { "sshd_pass", V_01
},
703 { "sshd_port", V_PORT
},
704 { "sshd_remote", V_01
},
705 { "sshd_forwarding", V_01
},
706 { "sshd_rport", V_PORT
},
707 { "sshd_authkeys", V_TEXT(0, 4096) },
708 { "rmgt_sip", V_LENGTH(0, 512) },
709 { "ne_shlimit", V_TEXT(1, 50) },
712 { "rstats_enable", V_01
},
713 { "rstats_path", V_LENGTH(0, 48) },
714 { "rstats_stime", V_RANGE(1, 168) },
715 { "rstats_offset", V_RANGE(1, 31) },
716 { "rstats_exclude", V_LENGTH(0, 64) },
717 { "rstats_sshut", V_01
},
718 { "rstats_bak", V_01
},
721 { "sesx_b0", V_RANGE(0, 5) }, // 0-5: toggle wireless, reboot, shutdown, script, usb unmount
722 { "sesx_b1", V_RANGE(0, 5) }, // "
723 { "sesx_b2", V_RANGE(0, 5) }, // "
724 { "sesx_b3", V_RANGE(0, 5) }, // "
725 { "sesx_script", V_TEXT(0, 1024) }, //
728 { "debug_nocommit", V_01
},
729 { "debug_cprintf", V_01
},
730 { "debug_cprintf_file", V_01
},
731 // { "debug_keepfiles", V_01 },
732 { "debug_ddns", V_01
},
733 { "debug_norestart", V_TEXT(0, 128) },
734 { "console_loglevel", V_RANGE(1, 8) },
735 { "t_cafree", V_01
},
736 { "t_hidelr", V_01
},
739 { "sch_rboot", V_TEXT(0, 64) },
740 { "sch_rcon", V_TEXT(0, 64) },
741 { "sch_c1", V_TEXT(0, 64) },
742 { "sch_c1_cmd", V_TEXT(0, 2048) },
743 { "sch_c2", V_TEXT(0, 64) },
744 { "sch_c2_cmd", V_TEXT(0, 2048) },
745 { "sch_c3", V_TEXT(0, 64) },
746 { "sch_c3_cmd", V_TEXT(0, 2048) },
749 { "script_init", V_TEXT(0, 4096) },
750 { "script_shut", V_TEXT(0, 4096) },
751 { "script_fire", V_TEXT(0, 8192) },
752 { "script_wanup", V_TEXT(0, 4096) },
755 { "log_remote", V_01
},
756 { "log_remoteip", V_IP
},
757 { "log_remoteport", V_PORT
},
758 { "log_file", V_01
},
759 { "log_limit", V_RANGE(0, 2400) },
760 { "log_in", V_RANGE(0, 3) },
761 { "log_out", V_RANGE(0, 3) },
762 { "log_mark", V_RANGE(0, 1440) },
763 { "log_events", V_TEXT(0, 32) }, // "acre,crond,ntp"
766 { "cifs1", V_LENGTH(1, 1024) },
767 { "cifs2", V_LENGTH(1, 1024) },
770 { "jffs2_on", V_01
},
771 { "jffs2_exec", V_LENGTH(0, 64) },
772 { "jffs2_format", V_01
},
776 { "usb_enable", V_01
},
777 { "usb_uhci", V_01
},
778 { "usb_ohci", V_01
},
779 { "usb_usb2", V_01
},
780 { "usb_storage", V_01
},
781 { "usb_printer", V_01
},
782 { "usb_printer_bidirect", V_01
},
783 { "usb_fs_ext3", V_01
},
784 { "usb_fs_fat", V_01
},
786 { "usb_fs_ntfs", V_01
},
788 { "usb_automount", V_01
},
789 { "script_usbhotplug", V_TEXT(0, 2048) },
790 { "script_usbmount", V_TEXT(0, 2048) },
791 { "script_usbumount", V_TEXT(0, 2048) },
796 { "ftp_enable", V_RANGE(0, 2) },
797 { "ftp_super", V_01
},
798 { "ftp_anonymous", V_RANGE(0, 3) },
799 { "ftp_dirlist", V_RANGE(0, 2) },
800 { "ftp_port", V_PORT
},
801 { "ftp_max", V_RANGE(0, 12) },
802 { "ftp_ipmax", V_RANGE(0, 12) },
803 { "ftp_staytimeout", V_RANGE(0, 65535) },
804 { "ftp_rate", V_RANGE(0, 99999) },
805 { "ftp_anonrate", V_RANGE(0, 99999) },
806 { "ftp_anonroot", V_LENGTH(0, 256) },
807 { "ftp_pubroot", V_LENGTH(0, 256) },
808 { "ftp_pvtroot", V_LENGTH(0, 256) },
809 { "ftp_users", V_LENGTH(0, 4096) },
810 { "ftp_custom", V_TEXT(0, 2048) },
811 { "ftp_sip", V_LENGTH(0, 512) },
812 { "ftp_limit", V_TEXT(1, 50) },
816 #ifdef TCONFIG_SAMBASRV
818 { "smbd_enable", V_RANGE(0, 2) },
819 { "smbd_wgroup", V_LENGTH(0, 20) },
820 { "smbd_master", V_01
},
821 { "smbd_wins", V_01
},
822 { "smbd_cpage", V_LENGTH(0, 4) },
823 { "smbd_cset", V_LENGTH(0, 20) },
824 { "smbd_loglevel", V_RANGE(0, 100) },
825 { "smbd_custom", V_TEXT(0, 2048) },
826 { "smbd_autoshare", V_RANGE(0, 3) },
827 { "smbd_shares", V_LENGTH(0, 4096) },
828 { "smbd_user", V_LENGTH(0, 50) },
829 { "smbd_passwd", V_LENGTH(0, 50) },
833 { "qos_enable", V_01
},
838 { "qos_icmp", V_01
},
839 { "qos_reset", V_01
},
840 { "qos_pfifo", V_01
}, // !!TB
841 { "qos_obw", V_RANGE(10, 999999) },
842 { "qos_ibw", V_RANGE(10, 999999) },
843 { "qos_orules", V_LENGTH(0, 4096) },
844 { "qos_default", V_RANGE(0, 9) },
845 { "qos_irates", V_LENGTH(0, 128) },
846 { "qos_orates", V_LENGTH(0, 128) },
848 { "ne_vegas", V_01
},
849 { "ne_valpha", V_NUM
},
850 { "ne_vbeta", V_NUM
},
851 { "ne_vgamma", V_NUM
},
873 port_flow_control_1 0,1
874 port_rate_limit_1 0-8
876 port_flow_control_2 0,1
877 port_rate_limit_2 0-8
879 port_flow_control_3 0,1
880 port_rate_limit_3 0-8
882 port_flow_control_4 0,1
883 port_rate_limit_4 0-8
891 static int save_variables(int write
)
901 static const char *msgf
= "The field \"%s\" is invalid. Please report this problem.";
904 for (v
= nvset_list
; v
->name
; ++v
) {
905 // _dprintf("[%s] %p\n", v->name, webcgi_get((char*)v->name));
906 if ((p
= webcgi_get((char*)v
->name
)) == NULL
) continue;
910 p
= unix_string(p
); // NOTE: p = malloc'd
914 if ((n
< v
->va
.i
) || (n
> v
->vb
.i
)) ok
= 0;
917 l
= strtol(p
, &e
, 10);
918 if ((p
== e
) || (*e
) || (l
< v
->va
.l
) || (l
> v
->vb
.l
)) ok
= 0;
921 if ((sscanf(p
, "%3u.%3u.%3u.%3u", &u
[0], &u
[1], &u
[2], &u
[3]) != 4) ||
922 (u
[0] > 255) || (u
[1] > 255) || (u
[2] > 255) || (u
[3] > 255)) ok
= 0;
925 if ((sscanf(p
, "%2x:%2x:%2x:%2x:%2x:%2x", &u
[0], &u
[1], &u
[2], &u
[3], &u
[4], &u
[5]) != 6) ||
926 (u
[0] > 255) || (u
[1] > 255) || (u
[2] > 255) || (u
[3] > 255) || (u
[4] > 255) || (u
[5] > 255)) ok
= 0;
933 if (v
->vtype
== VT_TEXT
) free(p
);
935 sprintf(s
, msgf
, v
->name
);
940 if (!nvram_match((char *)v
->name
, p
)) {
941 if (v
->vtype
!= VT_TEMP
) dirty
= 1;
942 nvram_set(v
->name
, p
);
945 if (v
->vtype
== VT_TEXT
) free(p
);
952 if (((p1
= webcgi_get("set_password_1")) != NULL
) && (strcmp(p1
, "**********") != 0)) {
953 if (((p2
= webcgi_get("set_password_2")) != NULL
) && (strcmp(p1
, p2
) == 0)) {
954 if ((write
) && (!nvram_match("http_passwd", p1
))) {
956 nvram_set("http_passwd", p1
);
960 sprintf(s
, msgf
, "password");
966 for (n
= 0; n
< 50; ++n
) {
967 sprintf(s
, "rrule%d", n
);
968 if ((p
= webcgi_get(s
)) != NULL
) {
969 if (strlen(p
) > 2048) {
974 if ((write
) && (!nvram_match(s
, p
))) {
981 return (write
) ? dirty
: 1;
984 static void wo_tomato(char *url
)
993 // _dprintf("tomato.cgi\n");
995 red
= webcgi_safeget("_redirect", "");
996 if (!*red
) send_header(200, NULL
, mime_html
, 0);
998 commit
= atoi(webcgi_safeget("_commit", "1"));
999 ajax
= atoi(webcgi_safeget("_ajax", "0"));
1001 nvset
= atoi(webcgi_safeget("_nvset", "1"));
1003 if (!save_variables(0)) {
1005 web_printf("@msg:%s", resmsg_get());
1008 parse_asp("error.asp");
1012 commit
= save_variables(1) && commit
;
1014 resmsg_set("Settings saved.");
1017 rboot
= atoi(webcgi_safeget("_reboot", "0"));
1019 parse_asp("reboot.asp");
1023 web_printf("@msg:%s", resmsg_get());
1025 else if (atoi(webcgi_safeget("_moveip", "0"))) {
1026 parse_asp("saved-moved.asp");
1029 parse_asp("saved.asp");
1034 _dprintf("commit from tomato.cgi\n");
1038 if ((v
= webcgi_get("_service")) != NULL
) {
1040 if (ajax
) web_printf(" Some services are being restarted...");
1053 for (i
= atoi(webcgi_safeget("_sleep", "0")); i
> 0; --i
) sleep(1);
1055 if (*red
) redirect(red
);
1065 // ----------------------------------------------------------------------------
1068 static void wo_update(char *url
)
1070 const aspapi_t
*api
;
1076 if ((name
= webcgi_get("exec")) != NULL
) {
1077 for (api
= aspapi
; api
->name
; ++api
) {
1078 if (strcmp(api
->name
, name
) == 0) {
1079 for (argc
= 0; argc
< 16; ++argc
) {
1080 sprintf(s
, "arg%d", argc
);
1081 if ((argv
[argc
] = (char *)webcgi_get(s
)) == NULL
) break;
1083 api
->exec(argc
, argv
);
1090 static void wo_service(char *url
)
1094 exec_service(webcgi_safeget("_service", ""));
1096 if ((n
= atoi(webcgi_safeget("_sleep", "2"))) <= 0) n
= 2;
1103 static void wo_logout(char *url)
1107 // doesn't work with all browsers...
1109 if (((user_agent) && (strstr(user_agent, "Opera") != NULL))) {
1110 sprintf(s, "%llx", (unsigned long long)time(NULL) * rand());
1111 send_authenticate(s);
1114 send_authenticate(NULL);
1119 static void wo_shutdown(char *url
)
1121 parse_asp("shutdown.asp");
1128 static void wo_nvcommit(char *url
)
1130 parse_asp("saved.asp");