Example #1
0
static int
write_pppd_ras_conf(const char* call_path, const char *modem_node, int unit)
{
	FILE *fp;
	int modem_type, vid = 0, pid = 0;
	char tmp[256], *user, *pass, *isp, *connect;

	if (!get_modem_vid_pid(modem_node, &vid, &pid))
		return 0;

	if (!(fp = fopen(call_path, "w+")))
		return 0;

	modem_type = nvram_get_int("modem_type");
	user = nvram_safe_get("modem_user");
	pass = nvram_safe_get("modem_pass");
	isp = nvram_safe_get("modem_isp");

	fprintf(fp, "/dev/%s\n", modem_node);
	fprintf(fp, "crtscts\n");
	fprintf(fp, "modem\n");
	fprintf(fp, "noauth\n");

	if(strlen(user) > 0)
		fprintf(fp, "user '%s'\n", safe_pppd_line(user, tmp, sizeof(tmp)));
	if(strlen(pass) > 0)
		fprintf(fp, "password '%s'\n", safe_pppd_line(pass, tmp, sizeof(tmp)));

	if(!strcmp(isp, "Virgin") || !strcmp(isp, "CDMA-UA")){
		fprintf(fp, "refuse-chap\n");
		fprintf(fp, "refuse-mschap\n");
		fprintf(fp, "refuse-mschap-v2\n");
	}

	fprintf(fp, "mtu %d\n", nvram_safe_get_int("modem_mtu", 1500, 1000, 1500));
	fprintf(fp, "mru %d\n", 1500);

	fprintf(fp, "persist\n");
	fprintf(fp, "maxfail %d\n", 0);
	fprintf(fp, "holdoff %d\n", 10);

	fprintf(fp, "nopcomp noaccomp\n");
	fprintf(fp, "novj nobsdcomp nodeflate\n");

	fprintf(fp, "noipdefault\n");

	if (nvram_invmatch("modem_dnsa", "0"))
		fprintf(fp, "usepeerdns\n");

	fprintf(fp, "minunit %d\n", RAS_PPP_UNIT);
	fprintf(fp, "linkname wan%d\n", unit);

	if (nvram_get_int("modem_dbg") == 1)
		fprintf(fp, "debug\n");

	connect = "Generic_conn.scr";

	if (modem_type == 1) {
		connect = "EVDO_conn.scr";
	} else if( modem_type == 2) {
		connect = "td_conn.scr";
	} else {
		if (vid == 0x0b05 && pid == 0x0302) // T500
			connect = "t500_conn.scr";
		else if (vid == 0x0421 && pid == 0x0612) // CS-15
			connect = "t500_conn.scr";
		else if (vid == 0x106c && pid == 0x3716)
			connect = "verizon_conn.scr";
		else if (vid == 0x1410 && pid == 0x4400)
			connect = "rogers_conn.scr";
	}

	fprintf(fp, "%s \"/bin/comgt -d /dev/%s -s %s/ppp/3g/%s\"\n", "connect", modem_node, MODEM_SCRIPTS_DIR, connect);
	fprintf(fp, "%s \"/bin/comgt -d /dev/%s -s %s/ppp/3g/%s\"\n", "disconnect", modem_node, MODEM_SCRIPTS_DIR, "Generic_disconn.scr");

	fclose(fp);

	return 1;
}
Example #2
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;
}