Exemplo n.º 1
0
unsigned char *
get_wlmacstr_by_unit(char *unit)
{
	char tmptr[] = "wlXXXXX_hwaddr";
	char *macaddr;

	sprintf(tmptr, "wl%s_hwaddr", unit);

	macaddr = nvram_get(tmptr);

	if (!macaddr)
		return NULL;

	return macaddr;
}
Exemplo n.º 2
0
/*
* Variable should be in format:
*
*	gpio<N>=pin_name
*
* 'def_pin' is returned if there is no such variable found.
*/
static unsigned int get_gpiopin(char *pin_name, unsigned int def_pin)
{
	char name[] = "gpioXXXX";
	char *val;
	unsigned int pin;

	/* Go thru all possibilities till a match in pin name */
	for (pin = 0; pin < 16; pin ++) {
		sprintf(name, "gpio%d", pin);
		val = nvram_get(name);
		if (val && !strcmp(val, pin_name))
			return pin;
	}
	return def_pin;
}
Exemplo n.º 3
0
int nvget_gpio(const char *name, int *gpio, int *inv)
{
	char *p;
	uint32_t n;

	if (((p = nvram_get(name)) != NULL) && (*p)) {
		n = strtoul(p, NULL, 0);
		if ((n & 0xFFFFFF70) == 0) {
			*gpio = (n & 15);
			*inv = ((n & 0x80) != 0);
			return 1;
		}
	}
	return 0;
}
Exemplo n.º 4
0
/*
 *	Set Default should be done by nvram_daemon.
 *	We check the pid file's existence.
 */
int setDefault(void)
{
	FILE *fp;
	int i;

	//retry 15 times (15 seconds)
	for (i = 0; i < 15; i++) {
		fp = fopen("/var/run/nvramd.pid", "r");
		if (fp == NULL) {
			if (i == 0)
				trace(0, T("goahead: waiting for nvram_daemon "));
			else
				trace(0, T(". "));
		}
		else {
			fclose(fp);
#if defined (RT2860_MBSS_SUPPORT)
			int max_bss_num = 8;
			int bssidnum = strtol(nvram_get(RT2860_NVRAM, "BssidNum"), NULL, 10);
			char newBssidNum[3];

#if defined (RT2860_NEW_MBSS_SUPPORT)
			max_bss_num = 16;
#endif
#ifdef CONFIG_RT2860V2_AP_MESH
			max_bss_num--;
#endif
#if defined (RT2860_APCLI_SUPPORT)
			max_bss_num--;
#endif
			if (bssidnum > max_bss_num)
				bssidnum = max_bss_num;
			sprintf(newBssidNum, "%d", bssidnum);
			nvram_set(RT2860_NVRAM, "BssidNum", newBssidNum);
#endif
			nvram_init(RT2860_NVRAM);
#if defined (RTDEV_SUPPORT) || defined (CONFIG_RT2561_AP) || defined (CONFIG_RT2561_AP_MODULE)
			nvram_init(RTDEV_NVRAM);
#endif
			
			return 0;
		}
		Sleep(1);
	}
	error(E_L, E_LOG, T("goahead: please execute nvram_daemon first!"));
	return (-1);
}
Exemplo n.º 5
0
static int ppp_prefix(char **wan_ifname, char *prefix)
{
	char tmp[100];
	int unit;

	*wan_ifname = safe_getenv("IFNAME");

	if ((unit = ppp_ifunit(*wan_ifname)) < 0)
		return -1;

	sprintf(prefix, "wan%d_", unit);

	if (!nvram_get(strcat_r(prefix, "ifname", tmp)))
		return -2;

	return unit;
}
Exemplo n.º 6
0
void start_sshd(void)
{
	int dirty = 0;
	char buf[2048];

	mkdir("/etc/dropbear", 0700);
	mkdir("/root/.ssh", 0700);

	f_write_string("/root/.ssh/authorized_keys", get_parsed_crt("sshd_authkeys", buf), 0, 0700);

	dirty |= check_host_key("rsa", "sshd_hostkey", "/etc/dropbear/dropbear_rsa_host_key");
	dirty |= check_host_key("dss", "sshd_dsskey",  "/etc/dropbear/dropbear_dss_host_key");
	if (dirty)
		nvram_commit_x();

/*
	xstart("dropbear", "-a", "-p", nvram_safe_get("sshd_port"), nvram_get_int("sshd_pass") ? "" : "-s");
*/

	char *argv[9];
	int argc;
	char *p;

	argv[0] = "dropbear";
	argv[1] = "-p";
	argv[2] = nvram_safe_get("sshd_port");
	argc = 3;

	if (!nvram_get_int("sshd_pass")) argv[argc++] = "-s";

	if (nvram_get_int("sshd_forwarding")) {
		argv[argc++] = "-a";
	} else {
		argv[argc++] = "-j";
		argv[argc++] = "-k";
	}

	if (((p = nvram_get("sshd_rwb")) != NULL) && (*p)) {
		argv[argc++] = "-W";
		argv[argc++] = p;
	}

	argv[argc] = NULL;
	_eval(argv, NULL, 0, NULL);

}
Exemplo n.º 7
0
/* NVRAM utility */
int main(int argc, char **argv)
{
	char *name, *value, buf[NVRAM_SPACE];
	int size;

	/* Skip program name */
	--argc;
	++argv;

	if (!*argv)
		usage();

	/* Process the remaining arguments. */
	for (; *argv; argv++) {
		if (!strncmp(*argv, "get", 3)) {
			if (*++argv) {
				if ((value = nvram_get(*argv)))
					puts(value);
			}
		} else if (!strncmp(*argv, "set", 3)) {
			if (*++argv) {
				strncpy(value = buf, *argv, sizeof(buf));
				name = strsep(&value, "=");
				nvram_set(name, value);
			}
		} else if (!strncmp(*argv, "unset", 5)) {
			if (*++argv)
				nvram_unset(*argv);
		} else if (!strncmp(*argv, "commit", 5)) {
			nvram_commit();
		} else if (!strncmp(*argv, "show", 4)
			   || !strncmp(*argv, "getall", 6)) {
			nvram_getall(buf, sizeof(buf));
			for (name = buf; *name; name += strlen(name) + 1)
				puts(name);
			size =
			    sizeof(struct nvram_header) + (int)name - (int)buf;
			fprintf(stderr, "size: %d bytes (%d left)\n", size,
				NVRAM_SPACE - size);
		}
		if (!*argv)
			break;
	}

	return 0;
}
Exemplo n.º 8
0
int
bcmgpio_getpin(char *pin_name)
{
        char name[] = "gpioXXXX";
        char *val;
        uint pin;

        /* Go thru all possibilities till a match in pin name */
        for (pin = 0; pin < BCMGPIO_MAXPINS; pin ++) {
                sprintf(name, "gpio%d", pin);
                val = nvram_get(name);
                if (val && findmatch(val, pin_name))
                        return pin;
        }

        return -1;
}
Exemplo n.º 9
0
/*
 * Search the name=value vars for a specific one and return its value.
 * Returns NULL if not found.
 */
char *getvar(char *vars, char *name)
{
	char *s;
	int len;

	len = strlen(name);

	/* first look in vars[] */
	for (s = vars; s && *s;) {
		if ((bcmp(s, name, len) == 0) && (s[len] == '='))
			return (&s[len + 1]);

		while (*s++);
	}

	/* then query nvram */
	return (nvram_get(name));
}
Exemplo n.º 10
0
int nvram_smbdav_pc_append(const char* ap_str )
{
	char* nv_var_val=NULL;
	Cdbg(1,"call nvram_get");
	if( !( nv_var_val = nvram_get(WEBDAV_SMB_PC)) ){
	   Cdbg(1,"nv_var get null");
	   return -1;
	}
	char tmp_nv_var_val[120]={0};
	strcpy(tmp_nv_var_val, nv_var_val);
	strcat(tmp_nv_var_val, ap_str);
#ifdef APP_IPKG
	free(nv_var_val);
#endif
	nvram_set(WEBDAV_SMB_PC, tmp_nv_var_val);
//	char * test_str = nvram_get(nv_var);
	return 0;
}
Exemplo n.º 11
0
int nvram_commit(void)
{
	int r = 0;
	FILE *fp;

	if (nvram_get(ASUS_STOP_COMMIT) != NULL)
	{
		cprintf("# skip nvram commit #\n");
		return r;
	}

	fp = fopen("/var/log/commit_ret", "w");

	if (wait_action_idle(10)) {
		if (nvram_fd < 0) {
			if ((r = nvram_init(NULL)) != 0) goto finish;
		}
		set_action(ACT_NVRAM_COMMIT);
//		nvram_unset("dirty");
		r = ioctl(nvram_fd, NVRAM_MAGIC, NULL);
		set_action(ACT_IDLE);

		if (r < 0) {
			perror(PATH_DEV_NVRAM);
			cprintf("commit: error\n");
			if(fp!=NULL)
				fprintf(fp,"commit: error\n");
		}
		else {
			if(fp!=NULL)
                                fprintf(fp,"commit: OK\n");
		}
	}
	else {
		cprintf("commit: system busy\n");
		if(fp!=NULL)
                        fprintf(fp,"commit: system busy\n");
	}

finish:
	if(fp!=NULL) fclose(fp);

	return r;
}
Exemplo n.º 12
0
char* nvram_get_ddns_host_name()
{
	/*
	nvram get/set ddns_enable_x
	nvram get/set ddns_server_x (WWW.ASUS.COM)
	nvram get/set ddns_hostname_x (RT-N66U-00E012112233.asuscomm.com)
	rc rc_service restart_ddns or notify_rc(?œrestart_ddns?? through libshared
	 */
	char* ddns_host_name_x=NULL;
	if(!nvram_is_ddns_enable())
	   goto nvram_get_ddns_host_name_EXIT;
	if(!nvram_get_ddns_server_name) 
	   goto nvram_get_ddns_host_name_EXIT;
	 ddns_host_name_x= nvram_get (DDNS_HOST_NAME_X);  
	
nvram_get_ddns_host_name_EXIT:
	Cdbg(DBE,"ddns_hostname_x = %s", ddns_host_name_x);
	return ddns_host_name_x;
}
Exemplo n.º 13
0
void addList(char *listname, char *value)
{
	int listlen = 0;

	if (isListed(listname, value))
		return;
	char *list = nvram_get(listname);
	char *newlist;

	if (list)
		listlen = strlen(list);
	newlist = safe_malloc(strlen(value + 2) + listlen);
	if (list)
		sprintf(newlist, "%s %s", list, value);
	else
		sprintf(newlist, "%s", value);
	nvram_set(listname, newlist);
	free(newlist);
}
Exemplo n.º 14
0
int boot_flags(void)
{
	int bootflags = 0;
	char *val;

	/* Only support chipcommon revision == 38 or BCM4706 for now */
	if ((CHIPID(sih->chip) == BCM4706_CHIP_ID) || sih->ccrev == 38) {
		if (sih->ccrev == 38 && (sih->chipst & (1 << 4)) != 0) {
			/* This is NANDBOOT */
			bootflags = FLASH_BOOT_NFLASH | FLASH_KERNEL_NFLASH;
		}
		else if ((val = nvram_get("bootflags"))) {
			bootflags = simple_strtol(val, NULL, 0);
			bootflags &= FLASH_KERNEL_NFLASH;
		}
	}

	return bootflags;
}
Exemplo n.º 15
0
static int set_stable_flag(void)
{
	int set = 0;
	char *wordlist = nvram_get(UBOOT_NVRAM, "Image1Stable");

	if (wordlist) {
		if (strcmp(wordlist, "1") != 0)
			set = 1;
	}
	else
		set = 1;

	if (set) {
		printf("Set Image1 stable flag\n");
		nvram_set(UBOOT_NVRAM, "Image1Stable", "1");
	}
	
	return 0;

}
Exemplo n.º 16
0
static inline void set_distance(int skfd, char *ifname)
{
	rw_reg_t reg;
	uint32 shm;
	int val = 0;
	char *v;
	
	if (v = nvram_get(wl_var("distance"))) {
		val = strtol(v,NULL,0);
		val = 9+(val/150)+((val%150)?1:0);
		
		shm = 0x10;
		shm |= (val << 16);
		bcom_ioctl(skfd, ifname, 197, &shm, sizeof(shm));
		
		reg.byteoff = 0x684;
		reg.val = val + 510;
		reg.size = 2;
		bcom_ioctl(skfd, ifname, 102, &reg, sizeof(reg));
	}
}
Exemplo n.º 17
0
void start_ttraff(void)
{
	if (!nvram_match("ttraff_enable", "1"))
		return;

	if ((nvram_match("ttraff_iface", "") || !nvram_get("ttraff_iface"))
	    && (nvram_match("wan_proto", "disabled")
		|| getWET()))
		return;

	pid_t pid;

	char *argv[] = { "ttraff", NULL };
	int ret = _evalpid(argv, NULL, 0, &pid);

	dd_syslog(LOG_INFO, "ttraff : traffic counter daemon successfully started\n");

	cprintf("done");

	return;
}
Exemplo n.º 18
0
int
BCMINITFN(nvram_resetgpio_init)(void *si)
{
	char *value;
	int gpio;
	si_t *sih;

	sih = (si_t *)si;

	value = nvram_get("reset_gpio");
	if (!value)
		return -1;

	gpio = (int) bcm_atoi(value);
	if (gpio > 7)
		return -1;

	/* Setup GPIO input */
	si_gpioouten(sih, ((uint32) 1 << gpio), 0, GPIO_DRV_PRIORITY);

	return gpio;
}
Exemplo n.º 19
0
/*
 * Get interfaces belonging to a specific bridge.
 *
 * @param	bridge_name 	pointer to bridge interface name
 * @return	list of interfaces belonging to the bridge or NULL
 *              if not found/empty
 */
char *
get_bridged_interfaces(char *bridge_name)
{
	static char interfaces[255];
	char *ifnames = NULL;
	char bridge[64];

	if (!bridge_name) return NULL;

	memset(interfaces, 0, sizeof(interfaces));
	snprintf(bridge, sizeof(bridge), "%s_ifnames", bridge_name);

	ifnames = nvram_get(bridge);

	if (ifnames)
		strncpy(interfaces, ifnames, sizeof(interfaces));
	else
		return NULL;

	return  interfaces;

}
Exemplo n.º 20
0
static bool
nvram_reset(void *sbh)
{
	chipcregs_t *cc;
	char *value;
	uint32 watchdog = 0, gpio;
	uint idx, msec;

	idx = sb_coreidx(sbh);

	/* Check if we were soft reset */
	if ((cc = sb_setcore(sbh, SB_CC, 0))) {
		watchdog = R_REG(&cc->intstatus) & 0x80000000;
		sb_setcoreidx(sbh, idx);
	}
	if (watchdog)
		return FALSE;

	value = nvram_get("reset_gpio");
	if (!value)
		return FALSE;

	gpio = (uint32) bcm_atoi(value);
	if (gpio > 7)
		return FALSE;

	/* Setup GPIO input */
	sb_gpioouten(sbh, (1 << gpio), 0);

	/* GPIO reset is asserted low */
	for (msec = 0; msec < 5000; msec++) {
		if (sb_gpioin(sbh) & (1 << gpio))
			return FALSE;
		OSL_DELAY(1000);
	}

	return TRUE;
}
Exemplo n.º 21
0
void run_nvscript(const char *nv, const char *arg1, int wtime)
{
	FILE *f;
	char *script;
	char s[256];
	char *argv[3];
	int pid;

	script = nvram_get(nv);
	if ((script) && (*script != 0)) {
		sprintf(s, "/tmp/%s.sh", nv);
		if ((f = fopen(s, "w")) != NULL) {
			fputs("#!/bin/sh\n", f);
			fputs(script, f);
			fputs("\n", f);
			fclose(f);
			chmod(s, 0700);
			
			chdir("/tmp");

			argv[0] = s;
			argv[1] = (char *)arg1;
			argv[2] = NULL;
			if (_eval(argv, NULL, 0, &pid) != 0) {
				pid = -1;
			}
			else {
				while (wtime-- > 0) {
					if (kill(pid, 0) != 0) break;
					sleep(1);
				}
			}
			
			chdir("/");
		}
	}
}
Exemplo n.º 22
0
int
get_real_mac(char *mac, int maclen)
{
    int idx, unit, subunit;
    char *ptr, ifname[32];
    wlif_name_desc_t *wlif_name;

    if (mac == NULL ||
            maclen < ETHER_ADDR_LEN)
        return -1;

    if (mac[0] != 0 || mac[1] != 0 ||
            mac[2] != 0)
        return 0; /* is a real mac, fast path */

    idx = mac[3];
    idx --; /* map to wlif_name_array index */
    unit = mac[4];
    subunit = mac[5];
    if (idx < 0 || idx >= ARRAYSIZE(wlif_name_array))
        return -1;

    /* get wlx.y mac addr */
    wlif_name = &wlif_name_array[idx];
    if (wlif_name->subunit && !wlif_name->wds)
        snprintf(ifname, sizeof(ifname), "wl%d.%d_hwaddr", unit, subunit);
    else
        snprintf(ifname, sizeof(ifname), "wl%d_hwaddr", unit);

    ptr = nvram_get(ifname);
    if (ptr == NULL)
        return -1;

    ether_atoe(ptr, mac);
    return 0;
}
Exemplo n.º 23
0
void start_radvd(void)
{
	int ret = 0;
	int c = 0;
	char *buf, *buf2;
	int i;
	FILE *fp;

	if (!nvram_match("radvd_enable", "1"))
		return;
	if (!nvram_match("ipv6_enable", "1"))
		return;
	buf = nvram_get("radvd_conf");
	if (buf != NULL)
		writenvram("radvd_conf", "/tmp/radvd.conf");

	system2("sync");

	ret = eval("radvd", "-C", "/tmp/radvd.conf");
	dd_syslog(LOG_INFO, "radvd : RADV daemon successfully started\n");

	cprintf("done\n");
	return;
}
Exemplo n.º 24
0
int build_nocat_conf( void )
{
    char *p;
    FILE *fp;


    if( !( fp = fopen( NOCAT_CONF, "w" ) ) )
    {
	perror( NOCAT_CONF );
	return errno;
    }

    fprintf( fp, "#\n" );

    /*
     * settings that need to be set based on router configurations 
     * Autodetected on the device: lan_ifname & NC_Iface variable
     */
        fprintf( fp, "ExternalDevice\t%s\n", nvram_safe_get("wan_iface"));
        fprintf( fp, "RouteOnly\t%s\n", "1" );

#ifdef TCONFIG_VLAN
    if (nvram_match( "NC_BridgeLAN", "br0") )
    {
            fprintf( fp, "InternalDevice\t%s\n", nvram_safe_get( "lan_ifname" ));
            fprintf( fp, "GatewayAddr\t%s\n", nvram_safe_get( "lan_ipaddr" ) );
    }
    if (nvram_match( "NC_BridgeLAN", "br1") )
    {
            fprintf( fp, "InternalDevice\t%s\n", nvram_safe_get( "lan1_ifname" ));
            fprintf( fp, "GatewayAddr\t%s\n", nvram_safe_get( "lan1_ipaddr" ) );
    }
    if (nvram_match( "NC_BridgeLAN", "br2") )
    {
            fprintf( fp, "InternalDevice\t%s\n", nvram_safe_get( "lan2_ifname" ));
            fprintf( fp, "GatewayAddr\t%s\n", nvram_safe_get( "lan2_ipaddr" ) );
    }
    if (nvram_match( "NC_BridgeLAN", "br3") )
    {
            fprintf( fp, "InternalDevice\t%s\n", nvram_safe_get( "lan3_ifname" ));
            fprintf( fp, "GatewayAddr\t%s\n", nvram_safe_get( "lan3_ipaddr" ) );
    }
#else
    fprintf( fp, "InternalDevice\t%s\n", nvram_safe_get( "lan_ifname" ));
    fprintf( fp, "GatewayAddr\t%s\n", nvram_safe_get( "lan_ipaddr" ) );
#endif

    fprintf( fp, "GatewayMAC\t%s\n", nvram_safe_get( "et0macaddr" ) );

    /*
    *These are user defined, eventually via the web page 
    */
    if ((p = nvram_get("NC_Verbosity")) == NULL) p = "2";
    fprintf( fp, "Verbosity\t%s\n", p );

    if ((p = nvram_get("NC_GatewayName")) == NULL) p = "Tomato RAF Portal";
    fprintf( fp, "GatewayName\t%s\n", p );

    if ((p = nvram_get("NC_GatewayPort")) == NULL) p = "5280";
    fprintf( fp, "GatewayPort\t%s\n", p );

    if ((p = nvram_get("NC_Password")) == NULL) p = "";
    fprintf( fp, "GatewayPassword\t%s\n", p );

    if ((p = nvram_get("NC_GatewayMode")) == NULL) p = "Open";
    fprintf( fp, "GatewayMode\t%s\n", p );

    if ((p = nvram_get("NC_DocumentRoot")) == NULL) p = "/tmp/splashd";
    fprintf( fp, "DocumentRoot\t%s\n", p );
    if( nvram_invmatch( "NC_SplashURL", "" ) )
    {
	fprintf( fp, "SplashURL\t%s\n", nvram_safe_get( "NC_SplashURL" ) );
	fprintf( fp, "SplashURLTimeout\t%s\n",
		 nvram_safe_get( "NC_SplashURLTimeout" ) );
    }
    /*
     * do we really need this?
     * Internal register of host IP's logged.. that's all (Victek) 
     */
    fprintf( fp, "LeaseFile\t%s\n", "/tmp/nocat.leases");

    /*
     * Open-mode and common options 
     */
    fprintf( fp, "FirewallPath\t%s\n", "/usr/libexec/nocat/" );
    fprintf( fp, "ExcludePorts\t%s\n", nvram_safe_get( "NC_ExcludePorts" ) );
    fprintf( fp, "IncludePorts\t%s\n", nvram_safe_get( "NC_IncludePorts" ) );
    fprintf( fp, "AllowedWebHosts\t%s %s\n", nvram_safe_get( "lan_ipaddr" ),
	     nvram_safe_get( "NC_AllowedWebHosts" ) );
    /*
     * TJaqua: Added MACWhiteList to ignore given machines or routers on the
     * local net (e.g. routers with an alternate Auth). 
     */
    fprintf( fp, "MACWhiteList\t%s\n", nvram_safe_get( "NC_MACWhiteList" ) );
    /*
     * TJaqua: Added AnyDNS to pass through any client-defined servers. 
     */
    fprintf( fp, "AnyDNS\t%s\n", "1" );

    fprintf( fp, "HomePage\t%s\n", nvram_safe_get( "NC_HomePage" ) );

    fprintf( fp, "PeerCheckTimeout\t%s\n", nvram_safe_get( "NC_PeerChecktimeout" ) );

    if ((p = nvram_get("NC_ForcedRedirect")) == NULL) p = "0";
    fprintf( fp, "ForcedRedirect\t%s\n", p );

    if ((p = nvram_get("NC_IdleTimeout")) == NULL) p = "0";
    fprintf( fp, "IdleTimeout\t%s\n", p );

    if ((p = nvram_get("NC_MaxMissedARP")) == NULL) p = "5";
    fprintf( fp, "MaxMissedARP\t%s\n", p );

    if ((p = nvram_get("NC_LoginTimeout")) == NULL) p = "6400";
    fprintf( fp, "LoginTimeout\t%s\n", p );

    if ((p = nvram_get("NC_RenewTimeout")) == NULL) p = "0";
    fprintf( fp, "RenewTimeout\t%s\n", p );

    fclose( fp );
    /*
     * end BPsmythe 
     */
    fprintf( stderr, "Wrote: %s\n", NOCAT_CONF );

    return 0;
}
Exemplo n.º 25
0
void start_nocat(void)
{
    FILE *fp;
	char splashfile[255];
	char logofile[255];
	char iconfile[255];
	char cpcmd[255];
	char *p;

    stop_nocat();

    if( !nvram_match( "NC_enable", "1" ) )
	return;
/* not needed .. but this is what it's testing depending on kernel.. should be modified in /nocat/src/nocat.conf
#ifdef LINUX26
	syslog(LOG_INFO,"Device using K2.6\n");
	syslog(LOG_INFO,"tested & bypassed modprobe xt_mark\n");
	syslog(LOG_INFO,"tested & bypassed modprobe xt_mac\n");
#else
	syslog(LOG_INFO,"Device using K2.4\n");
	syslog(LOG_INFO,"Tested & bypassed modprobe ipt_mark\n");
	syslog(LOG_INFO,"Tested & bypassed modprobe ipt_mac\n");
#endif
*/
    build_nocat_conf();

	if ((p = nvram_get("NC_DocumentRoot")) == NULL) p = "/tmp/splashd";
	sprintf( splashfile, "%s/splash.html", p );
	sprintf( logofile, "%s/tux.png", p );
	sprintf( iconfile, "%s/favicon.ico", p );
    if (!f_exists(splashfile)) {
        nvram_get_file("NC_SplashFile", splashfile, 8192);
        if (!f_exists(splashfile)) {
            sprintf(cpcmd, "cp /www/splash.html %s", splashfile);
            system(cpcmd);
            sprintf(cpcmd, "cp /www/tux.png  %s", logofile);
            system(cpcmd);
            sprintf(cpcmd, "cp /www/favicon.ico  %s", iconfile);
            system(cpcmd);
        }
    }
	
    	if( !( fp = fopen( "/tmp/start_splashd.sh", "w" ) ) )
	{
	perror( "/tmp/start_splashd.sh" );
	return;
	}
	
//	if ( !pidof("splashd") > 0 && (fp = fopen("/tmp/var/lock/splashd.lock", "r" ) ) )
//	{
//	unlink( "/tmp/var/lock/splashd.lock");
//	}
		
	fprintf( fp, "#!/bin/sh\n" );
	fprintf( fp, "LOGGER=logger\n");
	fprintf( fp, "LOCK_FILE=/tmp/var/lock/splashd.lock\n");
	fprintf( fp, "if [ -f $LOCK_FILE ]; then\n");
	fprintf( fp, "	$LOGGER \"Captive Portal halted (0), other process starting.\" \n");
	fprintf( fp, "	exit\n");
	fprintf( fp, "fi\n");
	fprintf( fp, "echo \"TOMATO_RAF\" > $LOCK_FILE\n");
	fprintf( fp, "sleep 20\n" );
	fprintf( fp, "$LOGGER \"splashd : Captive Portal Splash Daemon successfully started\" \n");
	fprintf( fp, "echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse\n");
	fprintf( fp, "/usr/sbin/splashd >> /tmp/nocat.log 2>&1 &\n" );
	fprintf( fp, "sleep 2\n" );
	fprintf( fp, "echo 0 > /proc/sys/net/ipv4/tcp_tw_reuse\n");
	fprintf( fp, "rm $LOCK_FILE\n");
	fclose( fp );
	chmod( "/tmp/start_splashd.sh", 0700 );
	xstart( "/tmp/start_splashd.sh" );
	return;
}
Exemplo n.º 26
0
void start_chilli(void)
{
	int ret = 0;
	char ssid[128];

	stop_chilli();		//ensure that its stopped

	if (!strlen(nvram_safe_get("chilli_interface")))
		nvram_set("chilli_interface", get_wdev());
	if (!strlen(nvram_safe_get("hotss_interface")))
		nvram_set("hotss_interface", get_wdev());
	main_config();
	
#ifdef HAVE_HOTSPOT

	if (nvram_match("chilli_enable", "1")
	    && nvram_match("chilli_def_enable", "0")
	    && !nvram_match("hotss_enable", "1")) {
		nvram_unset("chilli_def_enable");
		nvram_set("chilli_enable", "0");
		return;
	}

	if (!nvram_match("chilli_enable", "1")
	    && !nvram_match("hotss_enable", "1")) {
		nvram_unset("chilli_def_enable");
		return;
	}

	if (nvram_match("hotss_enable", "1")) {
		stop_cron();
		if (!nvram_match("chilli_enable", "1")) {
			nvram_set("chilli_enable", "1");	// to get care of firewall, network, etc.
			nvram_set("chilli_def_enable", "0");
		}
		if (!nvram_match("hotss_preconfig", "1")) {
			nvram_set("hotss_preconfig", "1");
			sprintf(ssid, "HotSpotSystem.com-%s_%s",
				nvram_get("hotss_operatorid"),
				nvram_get("hotss_locationid"));
			nvram_set("wl0_ssid", ssid);
			nvram_set("time_zone", "+00");
			nvram_set("daylight_time", "1");
		}
		hotspotsys_config();
		start_cron();
	} else if (nvram_match("chilli_enable", "1")) {
		nvram_unset("chilli_def_enable");
		chilli_config();
	}
#else
	if (!nvram_match("chilli_enable", "1"))
		return;

	chilli_config();

#endif

	ret = killall("chilli", SIGTERM);
	ret = killall("chilli", SIGKILL);
	if (f_exists("/tmp/chilli/hotss.conf")) {
		ret = eval("chilli", "-c", "/tmp/chilli/hotss.conf");
		dd_syslog(LOG_INFO,
			  "hotspotsystem : chilli daemon successfully started\n");
	} else {
		ret = eval("chilli", "-c", "/tmp/chilli/chilli.conf");
		dd_syslog(LOG_INFO,
			  "chilli : chilli daemon successfully started\n");
	}
#ifdef HAVE_TIEXTRA1
	start_mchilli();
#endif

	cprintf("done\n");
	return;
}
Exemplo n.º 27
0
void hotspotsys_config(void)
{
	FILE *fp;
	char *next;
	char var[64];
	char *dnslist;
	int i;

	md5_ctx_t MD;

	if (strlen(nvram_safe_get("hotss_remotekey")) != 12) {
		unsigned char hash[32];
		char *et0 = nvram_safe_get("et0macaddr");

		md5_begin(&MD);
		md5_hash(et0, 17, &MD);
		md5_end((unsigned char *)hash, &MD);
		char idkey[16];
		int i;

		for (i = 0; i < 6; i++)
			sprintf(&idkey[2 * i], "%02d",
				(hash[i] + hash[i + 1]) % 100);
		idkey[12] = '\0';
		nvram_set("hotss_remotekey", idkey);
		nvram_commit();
		char sendid[256];
		sprintf(sendid,
			"/usr/bin/wget http://tech.hotspotsystem.com/up.php?mac=`nvram get wl0_hwaddr|sed s/:/-/g`\\&operator=%s\\&location=%s\\&remotekey=%s",
			nvram_get("hotss_operatorid"),
			nvram_get("hotss_locationid"),
			nvram_get("hotss_remotekey"));
		system2(sendid);
	}

	if (!(fp = fopen("/tmp/chilli/hotss.conf", "w"))) {
		perror("/tmp/chilli/hotss.conf");
		return;
	}

	fprintf(fp, "ipup /tmp/chilli/ip-up.sh\n");
	fprintf(fp, "ipdown /tmp/chilli/ip-down.sh\n");
	fprintf(fp, "radiusserver1 radius.hotspotsystem.com\n");
	fprintf(fp, "radiusserver2 radius2.hotspotsystem.com\n");
	fprintf(fp, "radiussecret hotsys123\n");

	fprintf(fp, "dhcpif %s\n", nvram_safe_get("hotss_interface"));
	if (nvram_invmatch("hotss_net", ""))
		fprintf(fp, "net %s\n", nvram_get("hotss_net"));

	char *uamdomain = "customer.hotspotsystem.com";
	if (!nvram_match("hotss_customuam", "")) {
		uamdomain = nvram_safe_get("hotss_customuam");
	}
	fprintf(fp,
		"uamserver %s://%s/customer/hotspotlogin.php\n",
		nvram_default_get("hotss_customuamproto", "https"), uamdomain);

	if (nvram_invmatch("wan_get_dns", "0.0.0.0")
	    && nvram_invmatch("wan_get_dns", "")) {
		dnslist = nvram_safe_get("wan_get_dns");
		i = 1;
		foreach(var, dnslist, next) {
			if (i > 2)
				break;
			fprintf(fp, "dns%d %s\n", i, var);
			i++;
		}
	} else if (nvram_invmatch("wan_dns", "0.0.0.0")
Exemplo n.º 28
0
void chilli_config(void)
{
	FILE *fp;
	int i;

#ifdef HAVE_CHILLILOCAL

	if (!(fp = fopen("/tmp/chilli/fonusers.local", "w"))) {
		perror("/tmp/chilli/fonusers.local");
		return;
	}
	char *users = nvram_safe_get("fon_userlist");
	char *u = (char *)malloc(strlen(users) + 1);
	char *o = u;

	strcpy(u, users);
	char *sep = strsep(&u, "=");

	while (sep != NULL) {
		fprintf(fp, "%s ", sep);
		char *pass = strsep(&u, " ");

		fprintf(fp, "%s \n", pass != NULL ? pass : "");
		sep = strsep(&u, "=");
	}
	free(o);
	fclose(fp);
#endif

	if (!(fp = fopen("/tmp/chilli/chilli.conf", "w"))) {
		perror("/tmp/chilli/chilli.conf");
		return;
	}
	fprintf(fp, "ipup /tmp/chilli/ip-up.sh\n");
	fprintf(fp, "ipdown /tmp/chilli/ip-down.sh\n");
	fprintf(fp, "radiusserver1 %s\n", nvram_get("chilli_radius"));
	fprintf(fp, "radiusserver2 %s\n", nvram_get("chilli_backup"));
	fprintf(fp, "radiussecret %s\n", nvram_get("chilli_pass"));

	fprintf(fp, "dhcpif %s\n", nvram_safe_get("chilli_interface"));

	fprintf(fp, "uamserver %s\n", nvram_get("chilli_url"));
	if (nvram_invmatch("chilli_dns1", "0.0.0.0")
	    && nvram_invmatch("chilli_dns1", "")) {
		fprintf(fp, "dns1 %s\n", nvram_get("chilli_dns1"));
		if (nvram_invmatch("sv_localdns", "0.0.0.0")
		    && nvram_invmatch("sv_localdns", ""))
			fprintf(fp, "dns2 %s\n", nvram_get("sv_localdns"));
	} else if (nvram_invmatch("sv_localdns", "0.0.0.0")
		   && nvram_invmatch("sv_localdns", ""))
		fprintf(fp, "dns1 %s\n", nvram_get("sv_localdns"));

	if (nvram_invmatch("chilli_uamsecret", ""))
		fprintf(fp, "uamsecret %s\n", nvram_get("chilli_uamsecret"));
	if (nvram_invmatch("chilli_uamanydns", "0"))
		fprintf(fp, "uamanydns\n");
	if (nvram_invmatch("chilli_uamallowed", ""))
		fprintf(fp, "uamallowed %s\n", nvram_get("chilli_uamallowed"));
	if (nvram_invmatch("chilli_net", ""))
		fprintf(fp, "net %s\n", nvram_get("chilli_net"));
	if (nvram_match("chilli_macauth", "1"))
		fprintf(fp, "macauth\n");
#ifndef HAVE_FON
	if (nvram_match("fon_enable", "1")) {
#endif
		char hyp[32];

		strcpy(hyp, nvram_safe_get("wl0_hwaddr"));
		for (i = 0; i < strlen(hyp); i++)
			if (hyp[i] == ':')
				hyp[i] = '-';
		if (i > 0)
			fprintf(fp, "radiusnasid %s\n", hyp);
		nvram_set("chilli_radiusnasid", hyp);
		fprintf(fp, "interval 300\n");
#ifndef HAVE_FON
	} else {
		if (nvram_invmatch("chilli_radiusnasid", ""))
			fprintf(fp, "radiusnasid %s\n",
				nvram_get("chilli_radiusnasid"));
	}
#endif

	if (nvram_invmatch("chilli_additional", "")) {
		char *add = nvram_safe_get("chilli_additional");

		i = 0;
		do {
			if (add[i] != 0x0D)
				fprintf(fp, "%c", add[i]);
		}
		while (add[++i]);
		i = 0;
		int a = 0;
		char *filter = strdup(add);

		do {
			if (add[i] != 0x0D)
				filter[a++] = add[i];
		}
		while (add[++i]);

		filter[a] = 0;
		if (strcmp(filter, add)) {
			nvram_set("chilli_additional", filter);
			nvram_commit();
		}
		free(filter);
	}
	fflush(fp);
	fclose(fp);

	return;
}
Exemplo n.º 29
0
int main(int argc,char* argv[])
{
    int makedaemon = 1;
    char conffile[256];

    int c;

    signal(SIGINT,onsignal);
    signal(SIGHUP,onsignal);
    signal(SIGTERM,onsignal);

    //strcpy(s.authserver,DEFAULT_AUTHSERVER);
    strcpy(s.authserver,nvram_get("wan_bigpond_auth"));
    //strcpy(s.authdomain,DEFAULT_AUTHDOMAIN);
    strcpy(s.authdomain,nvram_get("wan_bigpond_server"));
    s.authport = DEFAULT_AUTHPORT;
    //strcpy(s.username,"");
    strcpy(s.username,nvram_get("wan_bigpond_username"));
    //strcpy(s.password,"");
    strcpy(s.password,nvram_get("wan_bigpond_password"));
    strcpy(s.connectedprog,"");
    strcpy(s.disconnectedprog,"");
    strcpy(conffile,DEFAULT_CONFFILE);
    strcpy(s.localaddress,"");
    s.localport = 0;
    s.minheartbeat = 60;
    s.maxheartbeat = 420;
#if 0
    while( (c = getopt( argc, argv, "c:d:l:D" )) > -1 ) {
        switch( c ) {
        case 'c':
            strncpy( conffile, optarg, MAXCONFFILE);
            break;
        case '?':
            usage();
            exit(1);
            break;
        }
    }

    if(!parse_parms(&s,conffile)) {
        printf( "bpalogin: Could not read configuration file (%s)\n\n",
                conffile );
        usage();
        exit(1);
    }

    optind = 1;
    while( (c = getopt( argc, argv, "c:d:l:D" )) > -1 ) {
        switch( c ) {
        case 'D':
            makedaemon = 0;
            break;
        case 'c':
            break;
        case 'd':
            debug_level = atoi(optarg);
            break;
	case 'l':
	    if( strcasecmp( optarg, "stdout" ) == 0 )
	      	dosyslog = 0;
	    else
		dosyslog = 1;
	    break;
        case '?':
            break;
        case ':':
            break;
        }
    }
#endif
    if(makedaemon) {
      /**
       * Original code did not perform the setsid() or second fork(), and
       * hence did not correctly make itself a daemon.  There is a library
       * call in FreeBSD (daemon) that does the actions below, but the
       * portability is unknown.
       */
      switch( fork() ) {
        case 0:
          break;
          
        case -1:
          perror("Could not run BPALogin in the background");
          exit(1);
          break;
          
        default:
          exit(0);
          break;
      }

      if( setsid() < 0 ) {
        perror("Could not run BPALogin in the background");
        exit(1);
      }

      /**
       * while not strictly necessary, the second fork ensures we stay
       * detached from a terminal by preventing the program using its
       * status as session leader to regain a terminal.
       */
      switch( fork() ) {
        case 0:
          break;

        case -1:
          perror("Could not run BPALogin in the background");
          exit(1);
          break;

        default:
          exit(0);
          break;
      }
    }
    

    openlog("bpalogin",LOG_PID,LOG_DAEMON);

    if(dosyslog)    
        syslog( LOG_INFO, BPALOGIN_BANNER "\n" );
    else
        printf( BPALOGIN_BANNER "\n");

    if(!strcmp(s.username,""))
    {
        critical("Username has not been set");
        exit(1);
    }
    if(!strcmp(s.password,""))
    {
        critical("Password has not been set");
        exit(1);
    }
    s.debug = debug;
    s.critical = critical;
    s.noncritical = noncritical;
    s.onconnected = onconnected;
    s.ondisconnected = ondisconnected;

    while(mainloop(&s));
    s.ondisconnected(0);

    exit(0);
}
Exemplo n.º 30
0
void start_pptpd(void)
{
	int ret = 0, mss = 0;
	char *lpTemp;
	FILE *fp;

	if (!nvram_invmatch("pptpd_enable", "0")) {
		stop_pptpd();
		return;
	}
#ifdef HAVE_PPTP_ACCEL
	insmod("pptp");
#endif
	// cprintf("stop vpn modules\n");
	// stop_vpn_modules ();

	//	copy existing peer data to /tmp
	if (nvram_default_match("sys_enable_jffs2", "1", "0"))
		system("/bin/cp /jffs/etc/pptp_peer.db /tmp/");

	// Create directory for use by pptpd daemon and its supporting files
	mkdir("/tmp/pptpd", 0744);
	cprintf("open options file\n");
	// Create options file that will be unique to pptpd to avoid interference 
	// with pppoe and pptp
	fp = fopen("/tmp/pptpd/options.pptpd", "w");
	cprintf("adding radius plugin\n");
	if (nvram_match("pptpd_radius", "1"))
		fprintf(fp, "plugin radius.so\nplugin radattr.so\n"
			"radius-config-file /tmp/pptpd/radius/radiusclient.conf\n");
	cprintf("check if wan_wins = zero\n");
	int nowins = 0;

	if (nvram_match("wan_wins", "0.0.0.0")) {
		nvram_set("wan_wins", "");
		nowins = 1;
	}
	if (strlen(nvram_safe_get("wan_wins")) == 0)
		nowins = 1;

	cprintf("write config\n");
	fprintf(fp, "lock\n"
		"name *\n"
		"nobsdcomp\n"
		"nodeflate\n"
		"auth\n"
		"refuse-pap\n"
		"refuse-eap\n"
		"refuse-chap\n" 
		"refuse-mschap\n" 
		"require-mschap-v2\n");
	if (nvram_match("pptpd_forcemppe", "1"))
		fprintf(fp, "mppe required,stateless,no40,no56\n");
	else
		fprintf(fp, "mppe stateless\n");
	fprintf(fp, "mppc\n" 	//enable compression
		"debug\n" "logfd 2\n"
		"ms-ignore-domain\n"
		"chap-secrets /tmp/pptpd/chap-secrets\n"
		"ip-up-script /tmp/pptpd/ip-up\n"
		"ip-down-script /tmp/pptpd/ip-down\n"
		"proxyarp\n"
		"ipcp-accept-local\n"
		"ipcp-accept-remote\n"
		"lcp-echo-failure 15\n"
		"lcp-echo-interval 4\n"
//		"lcp-echo-adaptive"	//disable interval
		"mtu %s\n" "mru %s\n",
		nvram_safe_get("pptpd_mtu"),
		nvram_safe_get("pptpd_mru"));
	if (!nowins) {
		fprintf(fp, "ms-wins %s\n", nvram_safe_get("wan_wins"));
	}
	if (strlen(nvram_safe_get("pptpd_wins1"))) {
		fprintf(fp, "ms-wins %s\n", nvram_safe_get("pptpd_wins1"));
	}
	if (strlen(nvram_safe_get("pptpd_wins2"))) {
		fprintf(fp, "ms-wins %s\n", nvram_safe_get("pptpd_wins2"));
	}

	struct dns_lists *dns_list = get_dns_list();

	if (nvram_match("dnsmasq_enable", "1")) {
		if (nvram_invmatch("lan_ipaddr", ""))
			fprintf(fp, "ms-dns %s\n",
				nvram_safe_get("lan_ipaddr"));
	} else if (nvram_match("local_dns", "1")) {
		if (dns_list && (nvram_invmatch("lan_ipaddr", "")
				 || strlen(dns_list->dns_server[0]) > 0
				 || strlen(dns_list->dns_server[1]) > 0
				 || strlen(dns_list->dns_server[2]) > 0)) {

			if (nvram_invmatch("lan_ipaddr", ""))
				fprintf(fp, "ms-dns %s\n",
					nvram_safe_get("lan_ipaddr"));
			if (strlen(dns_list->dns_server[0]) > 0)
				fprintf(fp, "ms-dns %s\n",
					dns_list->dns_server[0]);
			if (strlen(dns_list->dns_server[1]) > 0)
				fprintf(fp, "ms-dns %s\n",
					dns_list->dns_server[1]);
			if (strlen(dns_list->dns_server[2]) > 0)
				fprintf(fp, "ms-dns %s\n",
					dns_list->dns_server[2]);
		}
	} else {
		if (dns_list
		    && (strlen(dns_list->dns_server[0]) > 0
			|| strlen(dns_list->dns_server[1]) > 0
			|| strlen(dns_list->dns_server[2]) > 0)) {
			if (strlen(dns_list->dns_server[0]) > 0)
				fprintf(fp, "ms-dns  %s\n",
					dns_list->dns_server[0]);
			if (strlen(dns_list->dns_server[1]) > 0)
				fprintf(fp, "ms-dns  %s\n",
					dns_list->dns_server[1]);
			if (strlen(dns_list->dns_server[2]) > 0)
				fprintf(fp, "ms-dns  %s\n",
					dns_list->dns_server[2]);
		}
	}
	if (dns_list)
		free(dns_list);
	if (strlen(nvram_safe_get("pptpd_dns1"))) {
		fprintf(fp, "ms-dns %s\n", nvram_safe_get("pptpd_dns1"));
	}
	if (strlen(nvram_safe_get("pptpd_dns2"))) {
		fprintf(fp, "ms-dns %s\n", nvram_safe_get("pptpd_dns2"));
	}
	// Following is all crude and need to be revisited once testing confirms
	// that it does work
	// Should be enough for testing..
	if (nvram_match("pptpd_radius", "1")) {
		if (nvram_get("pptpd_radserver") != NULL
		    && nvram_get("pptpd_radpass") != NULL) {

			fclose(fp);

			mkdir("/tmp/pptpd/radius", 0744);

			fp = fopen("/tmp/pptpd/radius/radiusclient.conf", "w");
			fprintf(fp, "auth_order radius\n"
				"login_tries 4\n"
				"login_timeout 60\n"
				"radius_timeout 10\n"
				"nologin /etc/nologin\n"
				"servers /tmp/pptpd/radius/servers\n"
				"dictionary /etc/dictionary\n"
				"seqfile /var/run/radius.seq\n"
				"mapfile /etc/port-id-map\n"
				"radius_retries 3\n"
				"authserver %s:%s\n",
				nvram_get("pptpd_radserver"),
				nvram_get("pptpd_radport") ?
				nvram_get("pptpd_radport") : "radius");

			if (nvram_get("pptpd_radserver") != NULL
			    && nvram_get("pptpd_acctport") != NULL)
				fprintf(fp, "acctserver %s:%s\n",
					nvram_get("pptpd_radserver"),
					nvram_get("pptpd_acctport") ?
					nvram_get("pptpd_acctport") :
					"radacct");
			fclose(fp);

			fp = fopen("/tmp/pptpd/radius/servers", "w");
			fprintf(fp, "%s\t%s\n", nvram_get("pptpd_radserver"),
				nvram_get("pptpd_radpass"));
			fclose(fp);

		} else
			fclose(fp);
	} else
		fclose(fp);

	// Create pptpd.conf options file for pptpd daemon
	fp = fopen("/tmp/pptpd/pptpd.conf", "w");
	if (nvram_match("pptpd_bcrelay", "1"))
		fprintf(fp, "bcrelay %s\n", nvram_safe_get("lan_ifname"));
	fprintf(fp, "connections %s\nlocalip %s\n"
		"remoteip %s\n", nvram_safe_get("pptpd_conn"),nvram_safe_get("pptpd_lip"),
		nvram_safe_get("pptpd_rip"));
	fclose(fp);

	// Create ip-up and ip-down scripts that are unique to pptpd to avoid
	// interference with pppoe and pptp
	/*
	 * adjust for tunneling overhead (mtu - 40 byte IP - 108 byte tunnel
	 * overhead) 
	 */
	if (nvram_match("mtu_enable", "1"))
		mss = atoi(nvram_safe_get("wan_mtu")) - 40 - 108;
	else
		mss = 1500 - 40 - 108;
	char bcast[32];

	strcpy(bcast, nvram_safe_get("lan_ipaddr"));
	get_broadcast(bcast, nvram_safe_get("lan_netmask"));

	fp = fopen("/tmp/pptpd/ip-up", "w");
	fprintf(fp, "#!/bin/sh\n" "startservice set_routes\n"	// reinitialize 
		"echo $PPPD_PID $1 $5 $6 $PEERNAME >> /tmp/pptp_connected\n"
		"iptables -I INPUT -i $1 -j ACCEPT\n"
		"iptables -I FORWARD -i $1 -j ACCEPT\n"	//
		"iptables -I FORWARD -i $1 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu\n"
		"iptables -t nat -I PREROUTING -i $1 -p udp -m udp --sport 9 -j DNAT --to-destination %s\n"	// rule for wake on lan over pptp tunnel
		"%s\n", bcast,
		nvram_get("pptpd_ipdown_script") ?
		nvram_get("pptpd_ipdown_script") : "");
		//	per peer shaping		
	if (nvram_match("pptpd_radius", "1")) 
		fprintf(fp, "IN=`grep -i RP-Upstream-Speed-Limit /var/run/radattr.$1 | awk '{print $2}'`\n"
		"OUT=`grep -i RP-Downstream-Speed-Limit /var/run/radattr.$1 | awk '{print $2}'`\n"
		"if [ ! -z $IN ] && [ $IN -gt 0 ]\n"	//Speed limit !0 and !empty
		"then	tc qdisc del root dev $1\n"
		"\t tc qdisc add dev $1 handle ffff: ingress\n"
		"\t tc filter add dev $1 parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate \"$IN\"kbit burst \"$IN\"kbit drop flowid :1\n"
		"fi\n"
		"if [ ! -z $OUT ] && [ $OUT -gt 0 ]\n"
		"then tc qdisc del dev $1 ingress\n"
		"\t tc qdisc add dev $1 root tbf rate \"$OUT\"kbit latency 50ms burst \"$OUT\"kbit\n"
		"fi\n");
	fclose(fp);
	fp = fopen("/tmp/pptpd/ip-down", "w");
	fprintf(fp, "#!/bin/sh\n" "grep -v $PPPD_PID /tmp/pptp_connected > /tmp/pptp_connected.tmp\n"
		"mv /tmp/pptp_connected.tmp /tmp/pptp_connected\n"
		//	calc connected time and volume per peer
		"CONTIME=$(($CONNECT_TIME+`grep $PEERNAME /tmp/pptp_peer.db | awk '{print $3}'`))\n"
		"SENT=$(($BYTES_SENT+`grep $PEERNAME /tmp/pptp_peer.db | awk '{print $4}'`))\n"
		"RCVD=$(($BYTES_RCVD+`grep $PEERNAME /tmp/pptp_peer.db | awk '{print $5}'`))\n"
		"grep -v $PEERNAME /tmp/ppp_peer.db > /tmp/pptp_peer.db.tmp\n"
		"mv /tmp/pptp_peer.db.tmp /tmp/pptp_peer.db\n"
		"echo \"$PEERNAME $CONTIME $SENT $RCVD\" >> /tmp/pptp_peer.db\n"
		"iptables -D FORWARD -i $1 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu\n"
		"iptables -D INPUT -i $1 -j ACCEPT\n" "iptables -D FORWARD -i $1 -j ACCEPT\n"
		"iptables -t nat -D PREROUTING -i $1 -p udp -m udp --sport 9 -j DNAT --to-destination %s\n"	// rule for wake on lan over pptp tunnel
		"%s\n", bcast,
		nvram_get("pptpd_ipdown_script") ?
		nvram_get("pptpd_ipdown_script") : "");
	if (nvram_match("pptpd_radius", "1")) 
		fprintf(fp, "tc qdisc del root dev $1\n"
		"tc qdisc del ingress dev $1\n");
	fclose(fp);
	chmod("/tmp/pptpd/ip-up", 0744);
	chmod("/tmp/pptpd/ip-down", 0744);

	// Exctract chap-secrets from nvram and add the default account with
	// routers password
	lpTemp = nvram_safe_get("pptpd_auth");
	fp = fopen("/tmp/pptpd/chap-secrets", "w");
	// fprintf (fp, "root\t*\t%s\t*\n", nvram_safe_get ("http_passwd"));
	if (strlen(lpTemp) != 0)
		fprintf(fp, "%s\n", lpTemp);
	fclose(fp);

	chmod("/tmp/pptpd/chap-secrets", 0600);

	// Execute pptpd daemon
	ret =
	    eval("pptpd", "-c", "/tmp/pptpd/pptpd.conf", "-o",
		 "/tmp/pptpd/options.pptpd");

	dd_syslog(LOG_INFO, "pptpd : pptp daemon successfully started\n");
	return;
}