int main(int argc, char **argv) { openlog("ntpc", LOG_PID, LOG_USER); if (!nvram_contains_word("log_events", "ntp")) { setlogmask(LOG_MASK(LOG_EMERG)); // can't set to 0 } if (strstr(argv[0], "ntpsync") != NULL) return ntpsync_main(argc, argv); if (strstr(argv[0], "ntpstep") != NULL) return ntpstep_main(argc, argv); return ntpc_main(argc, argv); }
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; }