Пример #1
0
static void
on_client_ifup(void)
{
	char buf[256];

	nvram_set_int_temp("vpnc_state_t", 1);

	buf[0] = 0;
	if (nvram_get_int("vpnc_pdns") > 0) {
		int i, i_dns, buf_len;
		char *value;
		char foption[32], fdns[128];
		
		for (i=0, i_dns=0; i < 20 && i_dns < 3; i++) {
			sprintf(foption, "foreign_option_%d", i);
			value = getenv(foption);
			if (value) {
				fdns[0] = 0;
				if (sscanf(value, "dhcp-option DNS %s", fdns) == 1) {
					buf_len = strlen(buf);
					snprintf(buf + buf_len, sizeof(buf) - buf_len, "%s%s", (buf_len) ? " " : "", fdns);
					i_dns++;
				}
			}
		}
	}

	nvram_set_temp("vpnc_dns_t", buf);
	if (strlen(buf) > 0)
		update_resolvconf(0, 0);
}
Пример #2
0
void
stop_vpn_server(void)
{
	int i;
	char pppd_pid[32];
	char* svcs[] = { "bcrelay", "pptpd", NULL,  NULL };

	if (get_xl2tpd_vpns_active()) {
		svcs[2] = "xl2tpd";
		xl2tpd_killed_vpns = 1;
	}

	kill_services(svcs, 5, 1);

	/* force kill all clients pppd */
	for (i=0; i<MAX_CLIENTS_NUM; i++) {
		sprintf(pppd_pid, "/var/run/ppp%d.pid", VPN_SERVER_PPP_UNIT+i);
		kill_pidfile_s(pppd_pid, SIGKILL);
	}

	nvram_set_int_temp("l2tp_srv_t", 0);

	unlink(VPNS_PPP_UP_SCRIPT);
	unlink(VPNS_PPP_DW_SCRIPT);

#if defined(APP_OPENVPN)
	stop_openvpn_server();
#endif

	unlink(VPN_SERVER_LEASE_FILE);
}
Пример #3
0
static void
on_client_ifdown(void)
{
	nvram_set_int_temp("vpnc_state_t", 0);

	restore_dns_from_vpnc();
}
Пример #4
0
void set_usb_modem_dev_wan(int unit, int devnum)
{
	char tmp[100];
	char prefix[16];

	snprintf(prefix, sizeof(prefix), "wan%d_", unit);
	nvram_set_int_temp(strcat_r(prefix, "modem_dev", tmp), devnum);
}
Пример #5
0
void
notify_watchdog_wifi(int is_5ghz)
{
    int wd_notify_id = (is_5ghz) ? WD_NOTIFY_ID_WIFI5 : WD_NOTIFY_ID_WIFI2;

    nvram_set_int_temp("wd_notify_id", wd_notify_id);
    kill_pidfile_s(WD_PID_FILE, SIGUSR1);
}
Пример #6
0
static void
on_client_ifdown(void)
{
    nvram_set_int_temp("vpnc_state_t", 0);

    restore_dns_from_vpnc();

    call_client_script(VPN_CLIENT_UPDOWN_SCRIPT, "down");
}
Пример #7
0
static void
update_svc_status_wifi2()
{
    nvram_set_int_temp("reload_svc_rt", 0);
    svcStatus[RADIO2_ACTIVE] = is_radio_allowed_rt();

    if (svcStatus[RADIO2_ACTIVE] > 0)
        svcStatus[GUEST2_ACTIVE] = is_guest_allowed_rt();
    else
        svcStatus[GUEST2_ACTIVE] = -1;
}
Пример #8
0
void 
stop_vpn_client(void)
{
	char pppd_pid[32];

	if (get_xl2tpd_vpnc_active() && pids("xl2tpd"))
		control_xl2tpd("d", "VPNC");

	sprintf(pppd_pid, "/var/run/ppp-%s.pid", VPNC_PPP_LINK_NAME);
	kill_process_pidfile(pppd_pid, 5, 1);

#if defined(APP_OPENVPN)
	stop_openvpn_client();
#endif

	nvram_set_int_temp("l2tp_cli_t", 0);
	nvram_set_int_temp("vpnc_state_t", 0);

	unlink(VPNC_PPP_UP_SCRIPT);
	unlink(VPNC_PPP_DW_SCRIPT);
}
Пример #9
0
static void
update_svc_status_wifi5()
{
#if BOARD_HAS_5G_RADIO
    nvram_set_int_temp("reload_svc_wl", 0);
    svcStatus[RADIO5_ACTIVE] = is_radio_allowed_wl();

    if (svcStatus[RADIO5_ACTIVE] > 0)
        svcStatus[GUEST5_ACTIVE] = is_guest_allowed_wl();
    else
        svcStatus[GUEST5_ACTIVE] = -1;
#endif
}
Пример #10
0
static void
on_client_ifup(void)
{
	int i, i_dns = 0;
	char buf[256];
	char *script_name = VPN_CLIENT_UPDOWN_SCRIPT;

	nvram_set_int_temp("vpnc_state_t", 1);

	buf[0] = 0;
	if (nvram_get_int("vpnc_pdns") > 0) {
		int buf_len;
		char *value;
		char foption[32], fdns[128];
		
		for (i = 0; i < 20 && i_dns < 3; i++) {
			sprintf(foption, "foreign_option_%d", i);
			value = getenv(foption);
			if (value) {
				fdns[0] = 0;
				if (sscanf(value, "dhcp-option DNS %s", fdns) == 1) {
					buf_len = strlen(buf);
					snprintf(buf + buf_len, sizeof(buf) - buf_len, "%s%s", (buf_len) ? " " : "", fdns);
					i_dns++;
					if (i_dns == 1)
						setenv("DNS1", fdns, 1);
					else if (i_dns == 2)
						setenv("DNS2", fdns, 1);
				}
			}
		}
	}

	nvram_set_temp("vpnc_dns_t", buf);
	if (strlen(buf) > 0)
		update_resolvconf(0, 0);

	if (check_if_file_exist(script_name)) {
		for (i = 0; i < ARRAY_SIZE(env_ovpn); i++)
			setenv(env_pppd[i], safe_getenv(env_ovpn[i]), 1);
		doSystem("%s %s", script_name, "up");
		for (i = 0; i < ARRAY_SIZE(env_ovpn); i++)
			unsetenv(env_pppd[i]);
	}

	if (i_dns > 1)
		unsetenv("DNS2");
	if (i_dns > 0)
		unsetenv("DNS1");
}
Пример #11
0
static void
on_client_ifdown(void)
{
	int i;
	char *script_name = VPN_CLIENT_UPDOWN_SCRIPT;

	nvram_set_int_temp("vpnc_state_t", 0);

	restore_dns_from_vpnc();

	if (check_if_file_exist(script_name)) {
		for (i = 0; i < ARRAY_SIZE(env_ovpn); i++)
			setenv(env_pppd[i], safe_getenv(env_ovpn[i]), 1);
		doSystem("%s %s", script_name, "down");
		for (i = 0; i < ARRAY_SIZE(env_ovpn); i++)
			unsetenv(env_pppd[i]);
	}
}
Пример #12
0
void
on_deferred_hotplug_usb(void)
{
	int plug_modem = 0;
	int unplug_modem = 0;

	if (nvram_match("usb_hotplug_ms", "1"))
	{
		nvram_set_int_temp("usb_hotplug_ms", 0);
		try_start_usb_apps();
		nvram_set_int_temp("usb_opt_start", 0);
	}

	if (nvram_match("usb_unplug_lp", "1"))
	{
		nvram_set_int_temp("usb_unplug_lp", 0);
		if (!usb_port_module_used("usblp"))
			stop_usb_printer_spoolers();
	}

	if (nvram_match("usb_hotplug_lp", "1"))
	{
		nvram_set_int_temp("usb_hotplug_lp", 0);
		try_start_usb_printer_spoolers();
	}

	if (nvram_match("usb_unplug_md", "1"))
	{
		nvram_set_int_temp("usb_unplug_md", 0);
		if (nvram_get_int("modem_rule") > 0)
			unplug_modem = 1;
	}

	if (nvram_match("usb_hotplug_md", "1"))
	{
		plug_modem = 1;
		nvram_set_int_temp("usb_hotplug_md", 0);
	}

	if (unplug_modem)
	{
		try_wan_reconnect(1, 0);
	}

	if (plug_modem && !unplug_modem)
	{
		try_start_usb_modem_to_wan();
	}
}
Пример #13
0
int
ntpc_updated_main(int argc, char *argv[])
{
    char *offset;
    int ntpc_counter;

    if (argc < 2)
        return -1;

    if (strcmp(argv[1], "step") != 0)
        return 0;

    ntpc_counter = nvram_get_int("ntpc_counter");
    nvram_set_int_temp("ntpc_counter", ntpc_counter + 1);

    offset = getenv("offset");
    if (offset)
        logmessage("NTP Client", "System time changed, offset: %ss", offset);

    return 0;
}
Пример #14
0
int
ipdown_vpnc_main(int argc, char **argv)
{
	char *script_name = VPN_CLIENT_UPDOWN_SCRIPT;
	char *ifname = safe_getenv("IFNAME");
	char *gw = getenv("IPREMOTE");

	umask(0000);

	vpnc_route_dgw(ifname, gw, 0);
	vpnc_route_to_remote_lan(ifname, gw, 0);

	nvram_set_int_temp("vpnc_state_t", 0);

	restore_dns_from_vpnc();

	if (check_if_file_exist(script_name))
		doSystem("%s %s", script_name, "down");

	return 0;
}
Пример #15
0
int
ipup_vpnc_main(int argc, char **argv)
{
	char buf[256];
	char *script_name = VPN_CLIENT_UPDOWN_SCRIPT;
	char *ifname = safe_getenv("IFNAME");
	char *gw = getenv("IPREMOTE");

	umask(0000);

	vpnc_route_to_remote_lan(ifname, gw, 1);
	vpnc_route_dgw(ifname, gw, 1);

	set_vpn_balancing(ifname);

	nvram_set_int_temp("vpnc_state_t", 1);

	buf[0] = 0;
	if (nvram_get_int("vpnc_pdns") > 0) {
		char *value;
		
		value = getenv("DNS1");
		if (value)
			snprintf(buf, sizeof(buf), "%s", value);
		value = getenv("DNS2");
		if (value && strcmp(value, buf) != 0) {
			int buf_len = strlen(buf);
			snprintf(buf + buf_len, sizeof(buf) - buf_len, "%s%s", (buf_len) ? " " : "", value);
		}
	}

	nvram_set_temp("vpnc_dns_t", buf);
	if (strlen(buf) > 0)
		update_resolvconf(0, 0);

	if (check_if_file_exist(script_name))
		doSystem("%s %s", script_name, "up");

	return 0;
}
Пример #16
0
int
watchdog_main(int argc, char *argv[])
{
    FILE *fp;
    pid_t pid;
    struct sigaction sa;

    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = catch_sig_watchdog;
    sigemptyset(&sa.sa_mask);
    sigaddset(&sa.sa_mask, SIGALRM);
    sigaddset(&sa.sa_mask, SIGHUP);
    sigaddset(&sa.sa_mask, SIGUSR1);
    sigaddset(&sa.sa_mask, SIGUSR2);
    sigaction(SIGHUP, &sa, NULL);
    sigaction(SIGUSR1, &sa, NULL);
    sigaction(SIGUSR2, &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);
    sigaction(SIGALRM, &sa, NULL);

    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = SIG_IGN;
    sigemptyset(&sa.sa_mask);
    sigaction(SIGPIPE, &sa, NULL);

    if (daemon(0, 0) < 0) {
        perror("daemon");
        exit(errno);
    }

    pid = getpid();

    /* never invoke oom killer */
    oom_score_adjust(pid, OOM_SCORE_ADJ_MIN);

    /* write pid */
    if ((fp = fopen(WD_PID_FILE, "w")) != NULL) {
        fprintf(fp, "%d", pid);
        fclose(fp);
    }

    nvram_set_int_temp("wd_notify_id", 0);

#if defined (BOARD_GPIO_BTN_WPS)
    cpu_gpio_irq_set(BOARD_GPIO_BTN_WPS, 0, 1, pid);
#endif
#if defined (BOARD_GPIO_BTN_WLTOG)
    cpu_gpio_irq_set(BOARD_GPIO_BTN_WLTOG, 0, 1, pid);
#endif
#if defined (BOARD_GPIO_BTN_RESET)
    cpu_gpio_irq_set(BOARD_GPIO_BTN_RESET, 0, 1, pid);
#endif

    /* set timer */
    wd_alarmtimer(WD_NORMAL_PERIOD, 0);

    /* most of time it goes to sleep */
    while (1) {
        pause();
    }

    return 0;
}
Пример #17
0
int
start_vpn_server(void)
{
	FILE *fp;
	int i, i_type, i_vuse, i_cli0, i_cli1;
	char *vpns_cfg, *vpns_sec, *lanip;
	struct in_addr pool_in;
	unsigned int laddr, lmask, lsnet;

	if (nvram_invmatch("vpns_enable", "1") || get_ap_mode())
		return 0;

	unlink(VPN_SERVER_LEASE_FILE);

	i_type = nvram_get_int("vpns_type");
#if defined(APP_OPENVPN)
	if (i_type == 2)
		return start_openvpn_server();
#endif
	vpns_cfg = "/etc/pptpd.conf";
	vpns_sec = "/tmp/ppp/chap-secrets";

	mkdir("/tmp/ppp", 0777);
	symlink("/sbin/rc", VPNS_PPP_UP_SCRIPT);
	symlink("/sbin/rc", VPNS_PPP_DW_SCRIPT);

	i_vuse = nvram_get_int("vpns_vuse");
	lanip  = nvram_safe_get("lan_ipaddr");

	if (i_vuse == 0) {
		laddr = ntohl(inet_addr(lanip));
		lmask = ntohl(inet_addr(nvram_safe_get("lan_netmask")));
		lsnet = (~lmask) - 1;
		
		i_cli0 = nvram_safe_get_int("vpns_cli0", 245, 1, 254);
		i_cli1 = nvram_safe_get_int("vpns_cli1", 254, 2, 254);
		if (i_cli0 >= (int)lsnet) i_cli0 = (int)(lsnet - 1);
		if (i_cli1 >  (int)lsnet) i_cli1 = (int)lsnet;
		if (i_cli1 <= i_cli0) i_cli1 = i_cli0 + 1;
		laddr = (laddr & lmask) | (unsigned int)i_cli0;
		i_cli0 += 1;
	} else {
		laddr = ntohl(inet_addr(nvram_safe_get("vpns_vnet")));
		lmask = ntohl(inet_addr(VPN_SERVER_SUBNET_MASK));
		laddr = (laddr & lmask) | 1;
		
		i_cli0 = 2;
		i_cli1 = i_cli0 + MAX_CLIENTS_NUM - 1;
	}

	if (i_type != 1) {
		if (!(fp = fopen(vpns_cfg, "w")))
			return -1;
		
		fprintf(fp, "option %s\n", VPN_SERVER_PPPD_OPTIONS);
		fprintf(fp, "connections %d\n", MAX_CLIENTS_NUM);
		
		pool_in.s_addr = htonl(laddr);
		fprintf(fp, "localip %s\n", inet_ntoa(pool_in));
		
		pool_in.s_addr = htonl((laddr & lmask) | (unsigned int)i_cli0);
		fprintf(fp, "remoteip %s-%d\n", inet_ntoa(pool_in), i_cli1);
		
		fclose(fp);
		
		chmod(vpns_cfg, 0644);
	}

	create_vpns_pppd_options(i_type);

	/* create /tmp/ppp/chap-secrets */
	fp = fopen(vpns_sec, "w+");
	if (fp) {
		char *acl_user, *acl_pass;
		char acl_user_var[32], acl_pass_var[32], acl_addr_var[32];
		int i_cli2;
		int i_max = nvram_get_int("vpns_num_x");
		if (i_max > MAX_CLIENTS_NUM) i_max = MAX_CLIENTS_NUM;
		for (i = 0; i < i_max; i++) {
			sprintf(acl_user_var, "vpns_user_x%d", i);
			sprintf(acl_pass_var, "vpns_pass_x%d", i);
			acl_user = nvram_safe_get(acl_user_var);
			acl_pass = nvram_safe_get(acl_pass_var);
			if (*acl_user && *acl_pass) {
				sprintf(acl_addr_var, "vpns_addr_x%d", i);
				i_cli2 = nvram_get_int(acl_addr_var);
				if (i_cli2 >= i_cli0 && i_cli2 <= i_cli1 ) {
					pool_in.s_addr = htonl((laddr & lmask) | (unsigned int)i_cli2);
					strcpy(acl_addr_var, inet_ntoa(pool_in));
				} else
					strcpy(acl_addr_var, "*");
				
				fprintf(fp, "\"%s\"	*	\"%s\"	%s\n", acl_user, acl_pass, acl_addr_var);
			}
		}
		fclose(fp);
		
		chmod(vpns_sec, 0600);
	}

	if (i_type == 1) {
		nvram_set_int_temp("l2tp_srv_t", 1);
		
		safe_start_xl2tpd();
	} else {
		nvram_set_int_temp("l2tp_srv_t", 0);
		
		/* execute pptpd daemon */
		return eval("/usr/sbin/pptpd", "-c", vpns_cfg);
	}

	return 0;
}
Пример #18
0
void 
handle_notifications(void)
{
	int i, stop_handle = 0;
	char notify_name[256];

	DIR *directory = opendir(DIR_RC_NOTIFY);
	if (!directory)
		return;

	// handle max 10 requests at once (prevent deadlock)
	for (i=0; i < 10; i++)
	{
		struct dirent *entry;
		FILE *test_fp;
		
		entry = readdir(directory);
		if (!entry)
			break;
		if (strcmp(entry->d_name, ".") == 0)
			continue;
		if (strcmp(entry->d_name, "..") == 0)
			continue;
		
		/* Remove the marker file. */
		snprintf(notify_name, sizeof(notify_name), "%s/%s", DIR_RC_NOTIFY, entry->d_name);
		remove(notify_name);
		
		printf("rc notification: %s\n", entry->d_name);
		
		/* Take the appropriate action. */
		if (!strcmp(entry->d_name, RCN_RESTART_REBOOT))
		{
			stop_handle = 1;
			sys_exit();
		}
		else if (!strcmp(entry->d_name, "flash_firmware"))
		{
			stop_handle = 1;
			flash_firmware();
		}
#if defined (USE_IPV6)
		else if (!strcmp(entry->d_name, RCN_RESTART_IPV6))
		{
			if (!get_ap_mode()) {
				full_restart_ipv6(nvram_ipv6_type);
				nvram_ipv6_type = get_ipv6_type();
			}
		}
		else if (strcmp(entry->d_name, RCN_RESTART_RADVD) == 0)
		{
			restart_dhcpd();
			restart_radvd();
		}
#endif
		else if (!strcmp(entry->d_name, RCN_RESTART_WAN))
		{
			full_restart_wan();
		}
		else if (!strcmp(entry->d_name, RCN_RESTART_LAN))
		{
			full_restart_lan();
		}
		else if (!strcmp(entry->d_name, "stop_whole_wan"))
		{
			stop_wan();
		}
		else if (!strcmp(entry->d_name, RCN_RESTART_IPTV))
		{
			int is_ap_mode = get_ap_mode();
			restart_iptv(is_ap_mode);
			if (!is_ap_mode)
				restart_firewall();
		}
		else if(!strcmp(entry->d_name, "deferred_wan_connect"))
		{
			deferred_wan_connect();
		}
		else if(!strcmp(entry->d_name, "auto_wan_reconnect"))
		{
			auto_wan_reconnect();
		}
		else if(!strcmp(entry->d_name, "auto_wan_reconnect_pause"))
		{
			auto_wan_reconnect_pause();
		}
		else if(!strcmp(entry->d_name, "manual_wan_reconnect"))
		{
			manual_wan_reconnect();
		}
		else if(!strcmp(entry->d_name, "manual_wan_disconnect"))
		{
			manual_wan_disconnect();
		}
		else if(!strcmp(entry->d_name, "manual_ddns_hostname_check"))
		{
			manual_ddns_hostname_check();
		}
#if (BOARD_NUM_USB_PORTS > 0)
		else if (!strcmp(entry->d_name, RCN_RESTART_MODEM))
		{
			int wan_stopped = 0;
			int modules_reloaded = 0;
			int need_restart_wan = get_usb_modem_wan(0);
			int modem_rule = nvram_get_int("modem_rule");
			int modem_type = nvram_get_int("modem_type");
			if (nvram_modem_rule != modem_rule)
			{
				nvram_modem_rule = modem_rule;
				if (need_restart_wan) {
					wan_stopped = 1;
					stop_wan();
				}
				if (modem_rule > 0) {
					modules_reloaded = 1;
					reload_modem_modules(modem_type, 1);
				} else {
					unload_modem_modules();
				}
			}
			if (nvram_modem_type != modem_type)
			{
				if (nvram_modem_type == 3 || modem_type == 3) {
					if (modem_rule > 0 && !modules_reloaded) {
						if (need_restart_wan && !wan_stopped)
							stop_wan();
						reload_modem_modules(modem_type, 1);
					}
				}
				nvram_modem_type = modem_type;
			}
			if (need_restart_wan)
				full_restart_wan();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_SPOOLER) == 0)
		{
			restart_usb_printer_spoolers();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_HDDTUNE) == 0)
		{
			system("/sbin/hddtune.sh");
			set_pagecache_reclaim();
		}
#if defined(APP_FTPD)
		else if (strcmp(entry->d_name, RCN_RESTART_FTPD) == 0)
		{
			restart_ftpd();
		}
#endif
#if defined(APP_SMBD)
		else if (strcmp(entry->d_name, RCN_RESTART_SMBD) == 0)
		{
			restart_smbd();
		}
#endif
#if defined(APP_NFSD)
		else if (strcmp(entry->d_name, RCN_RESTART_NFSD) == 0)
		{
			restart_nfsd();
		}
#endif
#if defined(APP_MINIDLNA)
		else if (strcmp(entry->d_name, "restart_dms_rescan") == 0)
		{
			restart_dms(1);
		}
		else if (strcmp(entry->d_name, RCN_RESTART_DMS) == 0)
		{
			restart_dms(0);
		}
#endif
#if defined(APP_FIREFLY)
		else if (strcmp(entry->d_name, RCN_RESTART_ITUNES) == 0)
		{
			restart_itunes();
		}
#endif
#if defined(APP_TRMD)
		else if (strcmp(entry->d_name, RCN_RESTART_TRMD) == 0)
		{
			restart_torrent();
		}
#endif
#if defined(APP_ARIA)
		else if (strcmp(entry->d_name, RCN_RESTART_ARIA) == 0)
		{
			restart_aria();
		}
#endif
		else if (!strcmp(entry->d_name, "on_hotplug_usb_storage"))
		{
			// deferred run usb apps
			nvram_set_int_temp("usb_hotplug_ms", 1);
			alarm(5);
		}
		else if (!strcmp(entry->d_name, "on_unplug_usb_storage"))
		{
			umount_ejected();
		}
		else if (!strcmp(entry->d_name, "on_hotplug_usb_printer"))
		{
			// deferred run usb printer daemons
			nvram_set_int_temp("usb_hotplug_lp", 1);
			alarm(5);
		}
		else if (!strcmp(entry->d_name, "on_unplug_usb_printer"))
		{
			// deferred stop usb printer daemons
			nvram_set_int_temp("usb_unplug_lp", 1);
			alarm(5);
		}
		else if (!strcmp(entry->d_name, "on_hotplug_usb_modem"))
		{
			// deferred run usb modem to wan
			nvram_set_int_temp("usb_hotplug_md", 1);
			alarm(5);
		}
		else if (!strcmp(entry->d_name, "on_unplug_usb_modem"))
		{
			// deferred restart wan
			nvram_set_int_temp("usb_unplug_md", 1);
			alarm(5);
		}
#endif
		else if (strcmp(entry->d_name, RCN_RESTART_HTTPD) == 0)
		{
			restart_httpd();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_TELNETD) == 0)
		{
			stop_telnetd();
			start_telnetd();
		}
#if defined(APP_SSHD)
		else if (strcmp(entry->d_name, RCN_RESTART_SSHD) == 0)
		{
			restart_sshd();
		}
#endif
#if defined(APP_SMBD) || defined(APP_NMBD)
		else if (strcmp(entry->d_name, RCN_RESTART_NMBD) == 0)
		{
			restart_nmbd();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_WINS) == 0)
		{
			restart_nmbd();
			restart_dhcpd();
			reload_vpn_server();
		}
#endif
		else if (strcmp(entry->d_name, RCN_RESTART_LLTD) == 0)
		{
			restart_lltd();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_ADSC) == 0)
		{
			restart_infosvr();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_VPNSVR) == 0)
		{
			restart_vpn_server();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_VPNCLI) == 0)
		{
			restart_vpn_client();
		}
		else if (strcmp(entry->d_name, "start_vpn_client") == 0)
		{
			start_vpn_client();
		}
		else if (strcmp(entry->d_name, "stop_vpn_client") == 0)
		{
			stop_vpn_client();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_DDNS) == 0)
		{
			stop_ddns();
			start_ddns(1);
		}
		else if (strcmp(entry->d_name, RCN_RESTART_DI) == 0)
		{
			if (get_ap_mode() || has_wan_ip4(0))
				notify_run_detect_internet(2);
		}
		else if (strcmp(entry->d_name, RCN_RESTART_DHCPD) == 0)
		{
			if (get_ap_mode())
				update_hosts_ap();
			restart_dhcpd();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_UPNP) == 0)
		{
			restart_upnp();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_SWITCH_CFG) == 0)
		{
			config_bridge(get_ap_mode());
			switch_config_base();
			switch_config_storm();
			switch_config_link();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_SWITCH_VLAN) == 0)
		{
			notify_reset_detect_link();
			switch_config_vlan(0);
		}
		else if (strcmp(entry->d_name, RCN_RESTART_SYSLOG) == 0)
		{
			stop_logger();
			start_logger(0);
		}
		else if (strcmp(entry->d_name, RCN_RESTART_WDG) == 0)
		{
			restart_watchdog_cpu();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_TWEAKS) == 0)
		{
			notify_leds_detect_link();
		}
		else if (strcmp(entry->d_name, "restart_firewall_wan") == 0)
		{
			restart_firewall();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_FIREWALL) == 0)
		{
			reload_nat_modules();
			restart_firewall();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_NTPC) == 0)
		{
			notify_watchdog_time();
		}
		else if (strcmp(entry->d_name, RCN_RESTART_TIME) == 0)
		{
			stop_logger();
			set_timezone();
			notify_watchdog_time();
			notify_rstats_time();
			start_logger(0);
		}
		else if (strcmp(entry->d_name, RCN_RESTART_SYSCTL) == 0)
		{
			int nf_nat_type = nvram_get_int("nf_nat_type");
			
			restart_all_sysctl();
			
			/* flush conntrack after NAT model changing */
			if (nvram_nf_nat_type != nf_nat_type)
			{
				nvram_nf_nat_type = nf_nat_type;
				flush_conntrack_table(NULL);
			}
		}
		else if (!strcmp(entry->d_name, RCN_RESTART_WIFI5))
		{
			int radio_on = get_enabled_radio_wl();
			if (radio_on)
				radio_on = is_radio_allowed_wl();
			restart_wifi_wl(radio_on, 1);
		}
		else if (!strcmp(entry->d_name, RCN_RESTART_WIFI2))
		{
			int radio_on = get_enabled_radio_rt();
			if (radio_on)
				radio_on = is_radio_allowed_rt();
			restart_wifi_rt(radio_on, 1);
		}
		else if (!strcmp(entry->d_name, "control_wifi_guest_wl"))
		{
			int guest_on = is_guest_allowed_wl();
			control_guest_wl(guest_on, 1);
		}
		else if (!strcmp(entry->d_name, "control_wifi_guest_rt"))
		{
			int guest_on = is_guest_allowed_rt();
			control_guest_rt(guest_on, 1);
		}
		else if (!strcmp(entry->d_name, "control_wifi_guest_wl_on"))
		{
			control_guest_wl(1, 0);
		}
		else if (!strcmp(entry->d_name, "control_wifi_guest_wl_off"))
		{
			control_guest_wl(0, 0);
		}
		else if (!strcmp(entry->d_name, "control_wifi_guest_rt_on"))
		{
			control_guest_rt(1, 0);
		}
		else if (!strcmp(entry->d_name, "control_wifi_guest_rt_off"))
		{
			control_guest_rt(0, 0);
		}
		else if (!strcmp(entry->d_name, "control_wifi_radio_wl"))
		{
			int radio_on = get_enabled_radio_wl();
			if (radio_on)
				radio_on = is_radio_allowed_wl();
			control_radio_wl(radio_on, 1);
		}
		else if (!strcmp(entry->d_name, "control_wifi_radio_rt"))
		{
			int radio_on = get_enabled_radio_rt();
			if (radio_on)
				radio_on = is_radio_allowed_rt();
			control_radio_rt(radio_on, 1);
		}
		else if (!strcmp(entry->d_name, "control_wifi_radio_wl_on"))
		{
			control_radio_wl(1, 0);
		}
		else if (!strcmp(entry->d_name, "control_wifi_radio_wl_off"))
		{
			control_radio_wl(0, 0);
		}
		else if (!strcmp(entry->d_name, "control_wifi_radio_rt_on"))
		{
			control_radio_rt(1, 0);
		}
		else if (!strcmp(entry->d_name, "control_wifi_radio_rt_off"))
		{
			control_radio_rt(0, 0);
		}
		else if (!strcmp(entry->d_name, "control_wifi_config_wl"))
		{
			gen_ralink_config_5g(0);
		}
		else if (!strcmp(entry->d_name, "control_wifi_config_rt"))
		{
			gen_ralink_config_2g(0);
		}
		else
		{
			dbg("WARNING: rc notified of unrecognized event `%s'.\n", entry->d_name);
		}
		
		/*
		 * If there hasn't been another request for the same event made since
		 * we started, we can safely remove the ``action incomplete'' marker.
		 * Otherwise, we leave the marker because we'll go through here again
		 * for this even and mark it complete only after we've completed it
		 * without getting another request for the same event while handling
		 * it.
		 */
		test_fp = fopen(notify_name, "r");
		if (test_fp != NULL)
		{
			fclose(test_fp);
		}
		else
		{
			/* Remove the marker file. */
			snprintf(notify_name, sizeof(notify_name), "%s/%s", DIR_RC_INCOMPLETE, entry->d_name);
			remove(notify_name);
		}
		
		if (stop_handle)
			break;
	}

	closedir(directory);
}
Пример #19
0
static void
nvram_convert_misc_values(void)
{
	char buff[64];
	int sw_mode;

	/* check router mode */
	sw_mode = nvram_get_int("sw_mode");
	if (sw_mode == 1) {
		/* Internet gateway mode */
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 4) {
		/* Pure router mode */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 3) {
		/* AP mode (Ethernet convertor) */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Bridged");
	} else {
		nvram_set_int("sw_mode", 1);
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	}

	if (strlen(nvram_wlan_get("wl", "ssid")) < 1)
		nvram_wlan_set("wl", "ssid", DEF_WLAN_5G_SSID);

	if (strlen(nvram_wlan_get("rt", "ssid")) < 1)
		nvram_wlan_set("rt", "ssid", DEF_WLAN_5G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get("wl", "ssid"));
	nvram_wlan_set("wl", "ssid2", buff);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get("rt", "ssid"));
	nvram_wlan_set("rt", "ssid2", buff);

	if (strlen(nvram_safe_get("wl_wpa_mode")) < 1)
		nvram_set_int("wl_wpa_mode", 0);

	if (strlen(nvram_safe_get("wl_gmode")) < 1)
		nvram_set_int("wl_gmode", 2); // a/n Mixed

	if (strlen(nvram_safe_get("rt_gmode")) < 1)
		nvram_set_int("rt_gmode", 2); // b/g/n Mixed

	if (nvram_get_int("wl_HT_BW") > 1)
		nvram_set_int("wl_HT_BW", 1);

	if (nvram_get_int("rt_HT_BW") > 1)
		nvram_set_int("rt_HT_BW", 1);

	if (nvram_get_int("wl_stream_tx") > BOARD_NUM_ANT_5G_TX)
		nvram_set_int("wl_stream_tx", BOARD_NUM_ANT_5G_TX);

	if (nvram_get_int("wl_stream_rx") > BOARD_NUM_ANT_5G_RX)
		nvram_set_int("wl_stream_rx", BOARD_NUM_ANT_5G_RX);

	if (nvram_get_int("rt_stream_tx") > BOARD_NUM_ANT_2G_TX)
		nvram_set_int("rt_stream_tx", BOARD_NUM_ANT_2G_TX);

	if (nvram_get_int("rt_stream_rx") > BOARD_NUM_ANT_2G_RX)
		nvram_set_int("rt_stream_rx", BOARD_NUM_ANT_2G_RX);

	nvram_set_temp("ntpc_counter", "0000000000");
	nvram_set_temp("login_timestamp", "0000000000");

	nvram_set_int_temp("networkmap_fullscan", 0);
	nvram_set_int_temp("link_internet", 2);
	nvram_set_int_temp("link_wan", 0);

	nvram_set_int_temp("reload_svc_wl", 0);
	nvram_set_int_temp("reload_svc_rt", 0);

	nvram_set_int_temp("usb_hotplug_ms", 0);
	nvram_set_int_temp("usb_hotplug_lp", 0);
	nvram_set_int_temp("usb_hotplug_md", 0);
	nvram_set_int_temp("usb_unplug_lp", 0);
	nvram_set_int_temp("usb_unplug_md", 0);
	nvram_set_int_temp("usb_opt_start", 0);

	nvram_set_int_temp("l2tp_wan_t", 0);
	nvram_set_int_temp("l2tp_cli_t", 0);
	nvram_set_int_temp("l2tp_srv_t", 0);
	nvram_set_int_temp("vpnc_state_t", 0);
	nvram_set_temp("deferred_wanup_t", "0000000000");
	nvram_set_temp("vpnc_dns_t", "");
	nvram_set_temp("viptv_ifname", "");

	/* setup wan0 variables */
	set_wan0_vars();
	set_wan_unit_value(0, "uptime", "0000000000");
	set_wan_unit_value(0, "dltime", "0000000000");
	set_wan_unit_value(0, "bytes_rx", "00000000000000000000");
	set_wan_unit_value(0, "bytes_tx", "00000000000000000000");
	set_wan_unit_value(0, "ifname_t", "");
	set_usb_modem_dev_wan(0, 0);
	reset_wan_vars();

	/* setup lan variables */
	reset_lan_vars();
	reset_lan_temp();

	time_zone_x_mapping();
}
Пример #20
0
/* Check for time-dependent service */
static int
svc_timecheck(void)
{
    int activeNow;

#if BOARD_HAS_5G_RADIO
    if (get_enabled_radio_wl())
    {
        /* Initialize */
        if (nvram_match("reload_svc_wl", "1"))
        {
            nvram_set_int_temp("reload_svc_wl", 0);
            svcStatus[RADIO5_ACTIVE] = -1;
            svcStatus[GUEST5_ACTIVE] = -1;
        }

        activeNow = is_radio_allowed_wl();
        if (activeNow != svcStatus[RADIO5_ACTIVE])
        {
            svcStatus[RADIO5_ACTIVE] = activeNow;

            if (activeNow)
                notify_rc("control_wifi_radio_wl_on");
            else
                notify_rc("control_wifi_radio_wl_off");
        }

        if (svcStatus[RADIO5_ACTIVE] > 0)
        {
            activeNow = is_guest_allowed_wl();
            if (activeNow != svcStatus[GUEST5_ACTIVE])
            {
                svcStatus[GUEST5_ACTIVE] = activeNow;

                if (activeNow)
                    notify_rc("control_wifi_guest_wl_on");
                else
                    notify_rc("control_wifi_guest_wl_off");
            }
        }
        else
        {
            if (svcStatus[GUEST5_ACTIVE] >= 0)
                svcStatus[GUEST5_ACTIVE] = -1;
        }
    }
#endif

    if (get_enabled_radio_rt())
    {
        /* Initialize */
        if (nvram_match("reload_svc_rt", "1"))
        {
            nvram_set_int_temp("reload_svc_rt", 0);
            svcStatus[RADIO2_ACTIVE] = -1;
            svcStatus[GUEST2_ACTIVE] = -1;
        }

        activeNow = is_radio_allowed_rt();
        if (activeNow != svcStatus[RADIO2_ACTIVE])
        {
            svcStatus[RADIO2_ACTIVE] = activeNow;

            if (activeNow)
                notify_rc("control_wifi_radio_rt_on");
            else
                notify_rc("control_wifi_radio_rt_off");
        }

        if (svcStatus[RADIO2_ACTIVE] > 0)
        {
            activeNow = is_guest_allowed_rt();
            if (activeNow != svcStatus[GUEST2_ACTIVE])
            {
                svcStatus[GUEST2_ACTIVE] = activeNow;

                if (activeNow)
                    notify_rc("control_wifi_guest_rt_on");
                else
                    notify_rc("control_wifi_guest_rt_off");
            }
        }
        else
        {
            if (svcStatus[GUEST2_ACTIVE] >= 0)
                svcStatus[GUEST2_ACTIVE] = -1;
        }
    }

    return 0;
}
Пример #21
0
int
start_vpn_client(void)
{
	FILE *fp;
	int i_type, i_mppe, i_auth;
	char *vpnc_peer, *vpnc_opt, tmp[256];

	if (nvram_invmatch("vpnc_enable", "1") || get_ap_mode())
		return 1;

	vpnc_peer = nvram_safe_get("vpnc_peer");
	if (strlen(vpnc_peer) < 1) {
		logmessage(VPNC_LOG_NAME, "Unable to start - remote server host is not defined!");
		return 1;
	}

	nvram_set_temp("vpnc_dns_t", "");
	nvram_set_temp("vpnc_dom_t", "");
	nvram_set_int_temp("vpnc_state_t", 0);

	i_type = nvram_get_int("vpnc_type");
#if defined(APP_OPENVPN)
	if (i_type == 2)
		return start_openvpn_client();
#endif
	vpnc_opt = VPN_CLIENT_PPPD_OPTIONS;

	mkdir("/tmp/ppp", 0777);
	symlink("/sbin/rc", VPNC_PPP_UP_SCRIPT);
	symlink("/sbin/rc", VPNC_PPP_DW_SCRIPT);

	i_auth = nvram_get_int("vpnc_auth");
	i_mppe = nvram_get_int("vpnc_mppe");

	// Create options for pppd
	if (!(fp = fopen(vpnc_opt, "w"))) {
		return -1;
	}
	
	fprintf(fp, "noauth\n");
	fprintf(fp, "user '%s'\n", safe_pppd_line(nvram_safe_get("vpnc_user"), tmp, sizeof(tmp)));
	fprintf(fp, "password '%s'\n", safe_pppd_line(nvram_safe_get("vpnc_pass"), tmp, sizeof(tmp)));
	fprintf(fp, "refuse-eap\n");

	if (i_auth == 1) {
		/* MS-CHAPv2 */
		fprintf(fp, "refuse-pap\n");
		fprintf(fp, "refuse-chap\n");
		fprintf(fp, "refuse-mschap\n");
	}
	else if (i_auth == 2) {
		/* CHAP */
		fprintf(fp, "refuse-pap\n");
		fprintf(fp, "refuse-mschap\n");
		fprintf(fp, "refuse-mschap-v2\n");
	}
	else if (i_auth == 3) {
		/* PAP */
		fprintf(fp, "refuse-chap\n");
		fprintf(fp, "refuse-mschap\n");
		fprintf(fp, "refuse-mschap-v2\n");
	}

	if (i_type != 1)
	{
		fprintf(fp, "plugin pptp.so\n");
		fprintf(fp, "pptp_server '%s'\n", vpnc_peer);
		fprintf(fp, "route_rdgw %d\n", (nvram_match("vpnc_dgw", "1")) ? 2 : 0);
		fprintf(fp, "persist\n");
		fprintf(fp, "linkname %s\n", VPNC_PPP_LINK_NAME);
	}

	fprintf(fp, "mtu %d\n", nvram_safe_get_int("vpnc_mtu", 1450, 1000, 1460));
	fprintf(fp, "mru %d\n", nvram_safe_get_int("vpnc_mru", 1450, 1000, 1460));

	fprintf(fp, "maxfail %d\n", 0);		// pppd re-call count (0=infinite)
	fprintf(fp, "holdoff %d\n", 10);	// pppd re-call time (10s)

	fprintf(fp, "ipcp-accept-remote ipcp-accept-local\n");
	fprintf(fp, "noipdefault\n");
	fprintf(fp, "usepeerdns\n");

	fprintf(fp, "default-asyncmap\n");

	/* looks like pptp also likes them */
	fprintf(fp, "nopcomp noaccomp\n");

	/* ccp should still be enabled - mppe/mppc requires this */
	fprintf(fp, "novj nobsdcomp nodeflate\n");

	if (i_mppe == 3) {
		fprintf(fp, "nomppe nomppc\n");
	} else {
		if (i_mppe == 1) {
			fprintf(fp, "+mppe\n");
			fprintf(fp, "-mppe-40\n");
			fprintf(fp, "+mppe-128\n");
		} else if (i_mppe == 2) {
			fprintf(fp, "+mppe\n");
			fprintf(fp, "+mppe-40\n");
			fprintf(fp, "-mppe-128\n");
		} else {
			fprintf(fp, "+mppe-40\n");
			fprintf(fp, "+mppe-128\n");
		}
		fprintf(fp, "nomppe-stateful\n");
	}

	if (i_type == 1)
	{
		// Don't wait for LCP term responses; exit immediately when killed
		fprintf(fp, "lcp-max-terminate %d\n", 0);
	}

	/* echo failures (6*20s) */
	fprintf(fp, "lcp-echo-interval %d\n", 20);
	fprintf(fp, "lcp-echo-failure %d\n", 6);
	fprintf(fp, "lcp-echo-adaptive\n");

	fprintf(fp, "ip-up-script %s\n", VPNC_PPP_UP_SCRIPT);
	fprintf(fp, "ip-down-script %s\n", VPNC_PPP_DW_SCRIPT);

	fprintf(fp, "minunit %d\n", VPNC_PPP_UNIT);
	fprintf(fp, "ktune\n");

	/* user specific options */
	fprintf(fp, "%s\n", nvram_safe_get("vpnc_pppd"));

	fclose(fp);

	chmod(vpnc_opt, 0600);

	if (i_type == 1)
	{
		nvram_set_int_temp("l2tp_cli_t", 1);
		
		if (safe_start_xl2tpd() != 0)
			control_xl2tpd("c", "VPNC");
	}
	else
	{
		nvram_set_int_temp("l2tp_cli_t", 0);
		
		return eval("/usr/sbin/pppd", "file", vpnc_opt);
	}

	return 0;
}
Пример #22
0
static void
nvram_convert_misc_values(void)
{
	char buff[64];
	int sw_mode;
#if defined (BOARD_GPIO_BTN_ROUTER)
	int i_router_switch = BTN_PRESSED;

	if (cpu_gpio_get_pin(BOARD_GPIO_BTN_ROUTER, &i_router_switch) >= 0) {
		if (i_router_switch != BTN_PRESSED)
			nvram_set_int("sw_mode", 3);
	}
#endif

	/* check router mode */
	sw_mode = nvram_get_int("sw_mode");
	if (sw_mode == 1) {
		/* Internet gateway mode */
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 4) {
		/* Pure router mode */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 3) {
		/* AP mode (Ethernet convertor) */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Bridged");
	} else {
		sw_mode = 1;
		nvram_set_int("sw_mode", 1);
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	}

#if defined (BOARD_GPIO_LED_ROUTER)
	if (sw_mode != 3)
		LED_CONTROL(BOARD_GPIO_LED_ROUTER, LED_ON);
#endif

#if BOARD_HAS_5G_RADIO
	if (strlen(nvram_wlan_get(1, "ssid")) < 1)
		nvram_wlan_set(1, "ssid", DEF_WLAN_5G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get(1, "ssid"));
	nvram_wlan_set(1, "ssid2", buff);

	if (strlen(nvram_wlan_get(1, "wpa_mode")) < 1)
		nvram_wlan_set_int(1, "wpa_mode", 0);

#if BOARD_HAS_5G_11AC
	if (strlen(nvram_wlan_get(1, "gmode")) < 1)
		nvram_wlan_set_int(1, "gmode", 4); // a/n/ac Mixed

	if (nvram_wlan_get_int(1, "HT_BW") > 2)
		nvram_wlan_set_int(1, "HT_BW", 2);
#else
	if (strlen(nvram_wlan_get(1, "gmode")) < 1)
		nvram_wlan_set_int(1, "gmode", 2); // a/n Mixed

	if (nvram_wlan_get_int(1, "HT_BW") > 1)
		nvram_wlan_set_int(1, "HT_BW", 1);
#endif

	if (nvram_wlan_get_int(1, "stream_tx") > BOARD_NUM_ANT_5G_TX)
		nvram_wlan_set_int(1, "stream_tx", BOARD_NUM_ANT_5G_TX);

	if (nvram_wlan_get_int(1, "stream_rx") > BOARD_NUM_ANT_5G_RX)
		nvram_wlan_set_int(1, "stream_rx", BOARD_NUM_ANT_5G_RX);
#endif

	if (strlen(nvram_wlan_get(0, "ssid")) < 1)
		nvram_wlan_set(0, "ssid", DEF_WLAN_2G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get(0, "ssid"));
	nvram_wlan_set(0, "ssid2", buff);

	if (strlen(nvram_wlan_get(0, "gmode")) < 1)
		nvram_wlan_set_int(0, "gmode", 2); // b/g/n Mixed

	if (nvram_wlan_get_int(0, "HT_BW") > 1)
		nvram_wlan_set_int(0, "HT_BW", 1);

	if (nvram_wlan_get_int(0, "stream_tx") > BOARD_NUM_ANT_2G_TX)
		nvram_wlan_set_int(0, "stream_tx", BOARD_NUM_ANT_2G_TX);

	if (nvram_wlan_get_int(0, "stream_rx") > BOARD_NUM_ANT_2G_RX)
		nvram_wlan_set_int(0, "stream_rx", BOARD_NUM_ANT_2G_RX);

	nvram_set_temp("ntpc_counter", "0000000000");
	nvram_set_temp("login_timestamp", "0000000000");

	nvram_set_int_temp("networkmap_fullscan", 0);
	nvram_set_int_temp("link_internet", 2);
	nvram_set_int_temp("link_wan", 0);

	nvram_set_int_temp("reload_svc_wl", 0);
	nvram_set_int_temp("reload_svc_rt", 0);

	nvram_set_int_temp("usb_hotplug_ms", 0);
	nvram_set_int_temp("usb_hotplug_lp", 0);
	nvram_set_int_temp("usb_hotplug_md", 0);
	nvram_set_int_temp("usb_unplug_lp", 0);
	nvram_set_int_temp("usb_unplug_md", 0);
	nvram_set_int_temp("usb_opt_start", 0);

	nvram_set_int_temp("l2tp_wan_t", 0);
	nvram_set_int_temp("l2tp_cli_t", 0);
	nvram_set_int_temp("l2tp_srv_t", 0);
	nvram_set_int_temp("vpnc_state_t", 0);
	nvram_set_temp("deferred_wanup_t", "0000000000");
	nvram_set_temp("vpnc_dns_t", "");
	nvram_set_temp("vpnc_dom_t", "");
	nvram_set_temp("viptv_ifname", "");

	nvram_set_temp(RSTATS_NVKEY_24, (sw_mode != 3) ? IFDESC_WAN : IFDESC_LAN);
	nvram_set_temp(RSTATS_NVKEY_DM, IFDESC_WAN);

	/* setup wan0 variables */
	set_wan0_vars();
	set_wan_unit_value(0, "uptime", "0000000000");
	set_wan_unit_value(0, "dltime", "0000000000");
	set_wan_unit_value(0, "bytes_rx", "00000000000000000000");
	set_wan_unit_value(0, "bytes_tx", "00000000000000000000");
	set_wan_unit_value(0, "ifname_t", "");
	set_usb_modem_dev_wan(0, 0);
	reset_wan_vars();

	/* setup lan variables */
	reset_lan_vars();
	reset_lan_temp();

	time_zone_x_mapping();
}
Пример #23
0
int main(int argc, char *argv[])
{
    int                 sockfd , clisockfd;
    unsigned int        clilen;
    int                 childpid;
    struct sockaddr_in  serv_addr,cli_addr;
    int err_select;//JY1113

#ifdef LPR_with_ASUS//JY1112
    int 		LPRflag = 0;
    fd_set		rfds, afds;
    int			nfds;
    int			sockfd_ASUS;
    unsigned int        clilen_ASUS;
    int                 childpid_ASUS;
    struct sockaddr_in  serv_addr_ASUS,cli_addr_ASUS;
#endif
#ifdef Raw_Printing_with_ASUS  //Lisa
	int		netfd, fd, clientlen, one = 1;
	struct sockaddr_in	netaddr, client;
#endif
	int lock;
	int pid = 0;
	FILE *fp;

	fp = fopen("/var/run/lpdparent.pid", "r");
	if (fp) {
		fscanf(fp, "%d", &pid);
		fclose(fp);
	}

	if ((pid > 1) && (kill(pid, 0) == 0 || errno != ESRCH)) {
		syslog(LOGOPTS, "another lpd daemon exists!!\n");
		exit(0);
	}

	update_pidfile();

    //Initial the server the not busy
    lptstatus.busy = FALSE;

    sigset_t sigs_to_catch;
    sigemptyset(&sigs_to_catch);
    sigaddset(&sigs_to_catch, SIGCLD);
    sigaddset(&sigs_to_catch, SIGINT);
    sigaddset(&sigs_to_catch, SIGQUIT);
    sigaddset(&sigs_to_catch, SIGKILL);
    sigaddset(&sigs_to_catch, SIGUSR2);
    sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL);

    //Setup the signal handler
    signal(SIGCLD, sig_child); 
    signal(SIGINT, sig_cleanup); 
    signal(SIGQUIT, sig_cleanup); 
    signal(SIGKILL, sig_cleanup);
    signal(SIGUSR2, sig_remove);//JY1110 
    
    if((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0 )
    {
        syslog(LOGOPTS, "can't open stream socket: %m");
        exit(0);
    }
    
    bzero((char *)&serv_addr , sizeof(serv_addr));
    serv_addr.sin_family        = AF_INET;
    serv_addr.sin_addr.s_addr   = htonl(INADDR_ANY);
    serv_addr.sin_port          = htons(PNT_SVR_PORT_LPR);

    
    if(bind(sockfd,(struct sockaddr *)&serv_addr , sizeof(serv_addr)) < 0 )
    {
        syslog(LOGOPTS, "can't bind socket with port %d: %m", PNT_SVR_PORT_LPR);
        exit(0);
    }
    /*JY1111*/
    int windowsize=2920;
    setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (char *)&windowsize, sizeof(windowsize));
    int no_delay=1;
    setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &no_delay, sizeof(no_delay));	// by Jiahao. 20080808.

    listen(sockfd , 15);

#ifdef Raw_Printing_with_ASUS //Lisa
	if ((netfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) < 0)
	{
		syslog(LOGOPTS, "cannot open stream socket for raw printing: %m\n");
		exit(1);
	}
	if (setsockopt(netfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0)
	{
		syslog(LOGOPTS, "cannot setsocketopt for raw printing: %m\n");
		exit(1);
	}
	netaddr.sin_family = AF_INET;
	netaddr.sin_port = htons(BASEPORT);
	netaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	memset(netaddr.sin_zero, 0, sizeof(netaddr.sin_zero));
	if (bind(netfd, (struct sockaddr*) &netaddr, sizeof(netaddr)) < 0)
	{
		syslog(LOGOPTS, "cannot bind socket with port %d for raw printing: %m\n", BASEPORT);
		exit(1);
	}
	if (listen(netfd, 5) < 0)
	{
		syslog(LOGOPTS, "cannot listen socket for raw printing: %m\n");
		exit(1);
	}
	//clientlen = sizeof(client);
	//memset(&client, 0, sizeof(client));
#endif

#ifdef LPR_with_ASUS//JY1112
	if((sockfd_ASUS = socket(AF_INET,SOCK_STREAM,0)) < 0 )
	{
	        syslog(LOG_ERR, "can't open stream socket for LPR: %m");
	        exit(0);
	}
    	bzero((char *)&serv_addr_ASUS , sizeof(serv_addr_ASUS));
    	serv_addr_ASUS.sin_family        = AF_INET;
    	serv_addr_ASUS.sin_addr.s_addr   = htonl(INADDR_ANY);
    	serv_addr_ASUS.sin_port          = htons(PNT_SVR_PORT_ASUS);

    	if(bind(sockfd_ASUS,(struct sockaddr *)&serv_addr_ASUS , sizeof(serv_addr_ASUS)) < 0 )
    	{
		syslog(LOG_ERR, "can't bind socket for LPR: %m");
		exit(0);
   	}

    	setsockopt(sockfd_ASUS, SOL_SOCKET, SO_RCVBUF, (char *)&windowsize, sizeof(windowsize));

    	listen(sockfd_ASUS , 15);
    
    	/*set the fds*/
    	nfds=MAX(sockfd, sockfd_ASUS);
    	FD_ZERO(&afds);
#endif
    
    while(TRUE)
    {
	//if (busy) syslog(LOG_NOTICE, "busying %d %d\n", lptstatus.busy, busy);

	lock = file_lock("printer");				// by Jiahao for U2EC. 20080808.
	if (lptstatus.busy==FALSE && nvram_invmatch("MFP_busy", "2"))
	{
		busy=FALSE;
		nvram_set_int_temp("MFP_busy", 0);

		nvram_set_temp("u2ec_busyip", "");
	}
	file_unlock(lock);

#ifdef Raw_Printing_with_ASUS //Lisa
	FD_SET(netfd, &afds);
#endif
#ifdef LPR_with_ASUS//JY1112
	FD_SET(sockfd, &afds);
	FD_SET(sockfd_ASUS, &afds);
	memcpy(&rfds, &afds, sizeof(rfds));

	if((err_select=select(nfds+1, &rfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0 )) < 0) 
	{
//JY1120	printf("select error on sockfd: error=%d\n", errno);
		/**/
//		printf("sockfd_FD_ISSET=%d\n", FD_ISSET(sockfd, &rfds));
//JY1120		printf("sockfd_ASUS FD_ISSET=%d\n", FD_ISSET(sockfd_ASUS, &rfds));
		/**/
//		if(errno != 4)//JY1113: delete
		//syslog(LOG_NOTICE, "select error %d\n", err_select);
		continue;
	}
#endif
        clilen = sizeof(cli_addr);

	if(FD_ISSET(sockfd_ASUS, &rfds))
	{
		LPRflag = 0;
		clisockfd   = accept(sockfd_ASUS,(struct sockaddr *)&cli_addr, &clilen);
	}
#ifdef LPR_with_ASUS//JY1112 
	else if(FD_ISSET(sockfd, &rfds))
	{
		LPRflag = 1;
		clisockfd   = accept(sockfd,(struct sockaddr *)&cli_addr, &clilen);
	}
#endif
#ifdef Raw_Printing_with_ASUS //Lisa
//	else if(FD_ISSET(netfd, &rfds) && busy==FALSE)
	else if(FD_ISSET(netfd, &rfds))
	{
		lock = file_lock("printer");	// by Jiahao for U2EC. 20080808.
		if (nvram_match("MFP_busy", "0"))
		{
			file_unlock(lock);
			LPRflag = 2;
			clisockfd = accept(netfd, (struct sockaddr*) &cli_addr, &clilen);
		}
		else
		{
			file_unlock(lock);
			sleep(2);
			continue;
		}
	}
#endif
	else
        {
		//syslog(LOG_NOTICE, "No select\n");
		sleep(2);
		continue;
	}

	strcpy(clientaddr , inet_ntoa(cli_addr.sin_addr));
	
	if(clisockfd < 0)
        {
	     //syslog(LOG_NOTICE, "LPD error: No clisockfd %d\n", LPRflag);
             continue;
        }

	lock = file_lock("printer");
//	if (busy!=FALSE)	/* 2004/09/10 by Joey, process nack in parent for LPR and Remote Prot */
	if (nvram_invmatch("MFP_busy", "0"))		// by Jiahao for U2EC. 20080808.
	{
		file_unlock(lock);
		//syslog(LOG_NOTICE, "Printing others 1 %d %d\n", LPRflag, clisockfd);
		if (LPRflag==0) processReq(clisockfd);
		else if (LPRflag==1) processReq_LPR(clisockfd, 0);
		//syslog(LOG_NOTICE, "Printing others %d %d\n", LPRflag, clisockfd);
		close(clisockfd);
		// For Raw printing, don't resonse to client while busy
		sleep(5);
		continue;
	}

	nvram_set_int_temp("MFP_busy", 1);

	if (nvram_match("lan_ipaddr_t", ""))
		nvram_set_temp("u2ec_busyip", nvram_safe_get("lan_ipaddr"));
	else
		nvram_set_temp("u2ec_busyip", nvram_safe_get("lan_ipaddr_t"));

	file_unlock(lock);

        if( (childpid = fork() ) < 0)
        {
        }
        else if(childpid == 0) 
        {
		//syslog(LOG_NOTICE, "Printing %d\n", LPRflag);

		if(LPRflag==0) processReq(clisockfd); 
#ifdef LPR_with_ASUS//JY1114 
		else if(LPRflag==1) processReq_LPR(clisockfd, 1);
#endif
#ifdef Raw_Printing_with_ASUS //Lisa
		else if(LPRflag == 2) processReq_Raw(clisockfd);
#endif
		close(sockfd);
		close(sockfd_ASUS);
#ifdef Raw_Printing_with_ASUS
		close(netfd);
#endif
        	exit(0);
        }
              
	//syslog(0, "Printing Process %d %d %d\n", busy, lptstatus.busy, childpid);

        //parents process goes on here
        //remark PRINT("fork -- childpid %d\n",childpid);

	if(lptstatus.busy == FALSE)
	{
		lptstatus.busy = TRUE;
//		busy = TRUE;				// remarked by Jiahao for U2EC. 20080808.
		strcpy(lptstatus.addr , inet_ntoa(cli_addr.sin_addr));
		lptstatus.pid = childpid;
	}

        close(clisockfd);
    }

}
Пример #24
0
static void
on_client_ifup(void)
{
#define ENV_SCAN_MAX 20
    int i, i_dns = 0, i_wins = 0, i_dom = 0, vpnc_pdns;
    char buf[256], foption[32], fvalue[128], *value;

    nvram_set_int_temp("vpnc_state_t", 1);

    vpnc_pdns = nvram_get_int("vpnc_pdns");

    buf[0] = 0;
    for (i = 0; i < ENV_SCAN_MAX; i++) {
        snprintf(foption, sizeof(foption), "foreign_option_%d", i);
        value = getenv(foption);
        if (value) {
            memset(fvalue, 0, sizeof(fvalue));
            if (sscanf(value, "dhcp-option DNS %127s", fvalue) == 1) {
                if (vpnc_pdns > 0) {
                    int buf_len = strlen(buf);
                    snprintf(buf + buf_len, sizeof(buf) - buf_len, "%s%s", (buf_len) ? " " : "", fvalue);
                }
                i_dns++;
                if (i_dns == 1)
                    setenv("DNS1", fvalue, 1);
                else if (i_dns == 2)
                    setenv("DNS2", fvalue, 1);
            } else if (sscanf(value, "dhcp-option WINS %127s", fvalue) == 1) {
                i_wins++;
                if (i_wins == 1)
                    setenv("WINS1", fvalue, 1);
                else if (i_wins == 2)
                    setenv("WINS2", fvalue, 1);
            } else if (sscanf(value, "dhcp-option DOMAIN %127s", fvalue) == 1) {
                i_dom++;
                if (i_dom == 1) {
                    if (vpnc_pdns > 0)
                        nvram_set_temp("vpnc_dom_t", fvalue);
                    setenv("DOMAIN", fvalue, 1);
                }
            }
        }
        if (i_dom >= 1 && i_wins >= 2 && i_dns >= 2)
            break;
    }

    nvram_set_temp("vpnc_dns_t", buf);
    if (strlen(buf) > 0)
        update_resolvconf(0, 0);

    call_client_script(VPN_CLIENT_UPDOWN_SCRIPT, "up");

    if (i_dom > 0)
        unsetenv("DOMAIN");
    if (i_wins > 1)
        unsetenv("WINS2");
    if (i_wins > 0)
        unsetenv("WINS1");
    if (i_dns > 1)
        unsetenv("DNS2");
    if (i_dns > 0)
        unsetenv("DNS1");
}