// <% nvram("x,y,z"); %> -> nvram = {'x': '1','y': '2','z': '3'}; void asp_nvram(int argc, char **argv) { char *list; char *p, *k; char *value; if ((argc != 1) || ((list = strdup(argv[0])) == NULL)) return; web_puts("\nnvram = {\n"); p = list; while ((k = strsep(&p, ",")) != NULL) { if (*k == 0) continue; if (strcmp(k, "wl_unit") == 0) continue; web_printf("\t'%s': '", k); // AB multiSSID // web_putj(nvram_safe_get(k)); value = nvram_safe_get(k); web_putj_utf8(value); web_puts("',\n"); if (strncmp(k, "wl_", 3) == 0) { foreach_wif(1, k, print_wlnv); } } free(list); web_puts("\t'wl_unit': '"); // AB multiSSID web_putj(nvram_safe_get("wl_unit")); web_puts("',\n"); web_puts("\t'http_id': '"); // AB multiSSID web_putj(nvram_safe_get("http_id")); web_puts("',\n"); web_puts("\t'web_mx': '"); // AB multiSSID web_putj(nvram_safe_get("web_mx")); web_puts("',\n"); web_puts("\t'web_pb': '"); // AB multiSSID web_putj(nvram_safe_get("web_pb")); web_puts("'};\n"); }
int rcheck_main(int argc, char *argv[]) { char buf[256]; char *p; int sched_begin; int sched_end; int sched_dow; time_t now; struct tm *tms; int now_dow; int now_mins; int n; int nrule; char comp; int insch; unsigned long long activated; int count; int radio; int r; #ifdef TCONFIG_IPV6 int r6; #endif #ifdef LINUX26 int ipt_active; #endif if (!nvram_contains_word("log_events", "acre")) { setlogmask(LOG_MASK(LOG_EMERG)); // can't set to 0 } simple_lock("restrictions"); now = time(0); if (now < Y2K) { if (!nvram_match("rrules_timewarn", "1")) { nvram_set("rrules_timewarn", "1"); syslog(LOG_INFO, "Time not yet set. Only \"all day, everyday\" restrictions will be activated."); } now_mins = now_dow = 0; } else { tms = localtime(&now); now_dow = 1 << tms->tm_wday; now_mins = (tms->tm_hour * 60) + tms->tm_min; } #ifdef LINUX26 ipt_active = 0; #endif activated = strtoull(nvram_safe_get("rrules_activated"), NULL, 16); count = 0; radio = foreach_wif(0, NULL, radio_on) ? -1 : -2; for (nrule = 0; nrule < MAX_NRULES; ++nrule) { sprintf(buf, "rrule%d", nrule); if ((p = nvram_get(buf)) == NULL) continue; if (sscanf(p, "%d|%d|%d|%d|%c", &n, &sched_begin, &sched_end, &sched_dow, &comp) != 5) continue; if (n == 0) continue; ++count; if (now < Y2K) { if ((sched_begin >= 0) || (sched_end >= 0) || (sched_dow != 0x7F)) continue; insch = 1; } else { insch = in_sched(now_mins, now_dow, sched_begin, sched_end, sched_dow); } #ifdef LINUX26 if ((insch) && (comp != '~')) ++ipt_active; #endif n = 1 << nrule; if ((insch) == ((activated & n) != 0)) { continue; } syslog(LOG_INFO, "%sctivating rule %d", insch ? "A" : "Dea", nrule); if (comp == '~') { if ((radio != 0) && (radio != -2)) radio = !insch; } else { sprintf(buf, "r%s%02d", (comp != '|') ? "dev" : "res", nrule); r = eval("iptables", "-D", "restrict", "-j", buf); if (insch) { // ignore error above (if any) r = eval("iptables", "-A", "restrict", "-j", buf); } #ifdef TCONFIG_IPV6 r6 = eval("ip6tables", "-D", "restrict", "-j", buf); if (ipv6_enabled()) { if (insch) { // ignore error above (if any) r6 = eval("ip6tables", "-A", "restrict", "-j", buf); } r |= r6; } #endif if (r != 0) { syslog(LOG_ERR, "Iptables: %sactivating chain \"%s\" failed. Retrying in 15 minutes.", insch ? "" : "de", buf); continue; } } if (insch) activated |= n; else activated &= ~n; } sprintf(buf, "%llx", activated); nvram_set("rrules_activated", buf); if (count > 0) { if ((argc != 2) || (strcmp(argv[1], "--cron") != 0)) { eval("cru", "a", "rcheck", "*/15 * * * * rcheck --cron"); } } else { unsched_restrictions(); } if (radio >= 0) { nvram_set("rrules_radio", radio ? "0" : "1"); #if 1 // changed for dual radio support _dprintf("%s: radio = %d\n", __FUNCTION__, radio); eval("radio", radio ? "on" : "off"); #else if (get_radio() != radio) { _dprintf("%s: radio = %d\n", __FUNCTION__, radio); eval("radio", radio ? "on" : "off"); } else { _dprintf("%s: no radio change = %d\n", __FUNCTION__, radio); } #endif } #ifdef LINUX26 allow_fastnat("restrictions", (ipt_active == 0)); try_enabling_fastnat(); #endif simple_unlock("restrictions"); return 0; }
void asp_devlist(int argc, char **argv) { char *p; FILE *f; char buf[1024]; char comma; // must be here for easier call via update.cgi. arg is ignored asp_arplist(0, NULL); asp_wlnoise(0, NULL); // p = js_string(nvram_safe_get("dhcpd_static")); web_printf("dhcpd_static = '%s'.split('>');\n", p ? p : ""); free(p); // web_puts("wldev = ["); comma = ' '; foreach_wif(1, &comma, get_wl_clients); web_puts("];\n"); // unsigned long expires; char mac[32]; char ip[32]; char hostname[256]; char *host; web_puts("dhcpd_lease = ["); #ifdef TCONFIG_VLAN if ((nvram_match("lan_proto", "dhcp")) || (nvram_match("lan1_proto", "dhcp")) || (nvram_match("lan2_proto", "dhcp")) || (nvram_match("lan3_proto", "dhcp")) ) { #else if (nvram_match("lan_proto", "dhcp")) { #endif f_write("/var/tmp/dhcp/leases.!", NULL, 0, 0, 0666); // dump the leases to a file if (killall("dnsmasq", SIGUSR2) == 0) { // helper in dnsmasq will remove this when it's done f_wait_notexists("/var/tmp/dhcp/leases.!", 5); } if ((f = fopen("/var/tmp/dhcp/leases", "r")) != NULL) { comma = ' '; while (fgets(buf, sizeof(buf), f)) { if (sscanf(buf, "%lu %17s %15s %255s", &expires, mac, ip, hostname) != 4) continue; host = js_string((hostname[0] == '*') ? "" : hostname); web_printf("%c['%s','%s','%s','%s']", comma, (host ? host : ""), ip, mac, ((expires == 0) ? "non-expiring" : reltime(buf, expires))); free(host); comma = ','; } fclose(f); } unlink("/var/tmp/dhcp/leases"); } web_puts("];"); }