示例#1
0
static void run_engine()
{
	if(!f_exists("/dev/detector") || !f_exists("/dev/idpfw")){
		run_dpi_engine_service();
	}

	if(!f_exists("/tmp/bwdpi/bwdpi.app.db")){
		stop_dpi_engine_service(1);
	}
}
示例#2
0
static char *getPhyDev()
{
	if (f_exists("/proc/switch/eth0/enable"))
		return "eth0";

	if (f_exists("/proc/switch/eth1/enable"))
		return "eth1";

	if (f_exists("/proc/switch/eth2/enable"))
		return "eth2";

	return "eth0";
}
示例#3
0
static int _f_wait_exists(const char *name, int max, int invert)
{
	while (max-- > 0) {
		if (f_exists(name) ^ invert) return 1;
		sleep(1);
	}
	return 0;
}
示例#4
0
static void prep(void)
{
	if (!f_exists("/jffs/etc/freeradius/radiusd.conf")) {
		//prepare files
		mkdir("/jffs/etc", 0700);
		mkdir("/jffs/etc/freeradius", 0700);
		system("cp -r /etc/freeradius /jffs/etc");
	}

}
示例#5
0
文件: common.c 项目: smx-smx/dsl-n55u
long fappend_file(const char *path, const char *fname)
{
	FILE *f;
	int r = -1;

	if (f_exists(fname) && (f = fopen(path, "a")) != NULL) {
		r = fappend(f, fname);
		fclose(f);
	}
	return r;
}
示例#6
0
void stop_siproxd(void)
{
	unsigned int i;

	i = 0;
	syslog(LOG_INFO,"Siproxd - killing daemon\n");
	if ((i = pidof (siproxd_process)) > 3) {
		killall_tk(siproxd_process);
			if (f_exists(siproxdpid)) {
			unlink(siproxdpid);
			}
	}
}
示例#7
0
文件: nocat.c 项目: NieHao/Tomato-RAF
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;
}
示例#8
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;
}
示例#9
0
int main(int argc, char **argv)
{
	char *base;
	int f;

	/*
		Make sure std* are valid since several functions attempt to close these
		handles. If nvram_*() runs first, nvram=0, nvram gets closed. - zzz
	*/

	if ((f = open("/dev/null", O_RDWR)) < 0) {
	}
	else if(f < 3) {
		dup(f);
		dup(f);
	}
	else {
		close(f);
	}

	base = strrchr(argv[0], '/');
	base = base ? base + 1 : argv[0];

#if 0
	if (strcmp(base, "rc") == 0) {
		if (argc < 2) return 1;
		if (strcmp(argv[1], "start") == 0) return kill(1, SIGUSR2);
		if (strcmp(argv[1], "stop") == 0) return kill(1, SIGINT);
		if (strcmp(argv[1], "restart") == 0) return kill(1, SIGHUP);
		++argv;
		--argc;
		base = argv[0];
	}
#endif

#ifdef RTCONFIG_RALINK
    if(getpid() != 1)
    {
#endif

#if defined(DEBUG_NOISY)
	if (nvram_match("debug_logrc", "1")) {
		int i;

		cprintf("[rc %d] ", getpid());
		for (i = 0; i < argc; ++i) {
			cprintf("%s ", argv[i]);
		}
		cprintf("\n");

	}
#endif

#if defined(DEBUG_NOISY)
	if (nvram_match("debug_ovrc", "1")) {
		char tmp[256];
		char *a[32];

		realpath(argv[0], tmp);
		if ((strncmp(tmp, "/tmp/", 5) != 0) && (argc < 32)) {
			sprintf(tmp, "%s%s", "/tmp/", base);
			if (f_exists(tmp)) {
				cprintf("[rc] override: %s\n", tmp);
				memcpy(a, argv, argc * sizeof(a[0]));
				a[argc] = 0;
				a[0] = tmp;
				execvp(tmp, a);
				exit(0);
			}
		}
	}
#endif
#ifdef RTCONFIG_RALINK
    }
#endif
	const applets_t *a;
	for (a = applets; a->name; ++a) {
		if (strcmp(base, a->name) == 0) {
			openlog(base, LOG_PID, LOG_USER);
			return a->main(argc, argv);
		}
	}


	if(!strcmp(base, "restart_wireless")){
		printf("restart wireless...\n");
		restart_wireless();
		return 0;
	}
        else if(!strcmp(base, "nvram_erase")){
                erase_nvram();
                return 0;
        }
#ifdef RTCONFIG_USB
	else if(!strcmp(base, "get_apps_name")){
		if(argc != 2){
			printf("Usage: get_apps_name [File name]\n");
			return 0;
		}

		return get_apps_name(argv[1]);
	}
	else if(!strcmp(base, "asus_sd")){
		if(argc != 3){
			printf("Usage: asus_sd [device_name] [action]\n");
			return 0;
		}

		return asus_sd(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_lp")){
		if(argc != 3){
			printf("Usage: asus_lp [device_name] [action]\n");
			return 0;
		}

		return asus_lp(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_sg")){
		if(argc != 3){
			printf("Usage: asus_sg [device_name] [action]\n");
			return 0;
		}

		return asus_sg(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_sr")){
		if(argc != 3){
			printf("Usage: asus_sr [device_name] [action]\n");
			return 0;
		}

		return asus_sr(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_tty")){
		if(argc != 3){
			printf("Usage: asus_tty [device_name] [action]\n");
			return 0;
		}

		return asus_tty(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_usbbcm")){
		if(argc != 3){
			printf("Usage: asus_usbbcm [device_name] [action]\n");
			return 0;
		}

		return asus_usbbcm(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_usb_interface")){
		if(argc != 3){
			printf("Usage: asus_usb_interface [device_name] [action]\n");
			return 0;
		}

		return asus_usb_interface(argv[1], argv[2]);
	}
	else if (!strcmp(base, "usb_notify")) {
#if defined(RTCONFIG_APP_PREINSTALLED) || defined(RTCONFIG_APP_NETINSTALLED)
		usb_notify();
#endif

		return 0;
	}
#if defined(RTCONFIG_APP_PREINSTALLED) || defined(RTCONFIG_APP_NETINSTALLED)
	else if(!strcmp(base, "run_app_script")){
		if(argc != 3){
			printf("Usage: run_app_script [Package name | allpkg] [APP action]\n");
			return 0;
		}

		if(!strcmp(argv[1], "allpkg"))
			return run_app_script(NULL, argv[2]);
		else
			return run_app_script(argv[1], argv[2]);
	}
	else if (!strcmp(base, "chk_app_state")) {
#define PID_FILE "/var/run/chk_app_state.pid"
		FILE *fp;
		char chk_value[4];

		if(f_read_string(PID_FILE, chk_value, 4) > 0
				&& atoi(chk_value) != getpid()){
			_dprintf("Already running!\n");
			return 0;
		}

		if((fp = fopen(PID_FILE, "w")) == NULL){
			_dprintf("Can't open the pid file!\n");
			return 0;
		}

		fprintf(fp, "%d", getpid());
		fclose(fp);

		memset(chk_value, 0, 4);
		strncpy(chk_value, nvram_safe_get("apps_state_switch"), 4);
		if(strcmp(chk_value, "")){
			if(atoi(chk_value) != APPS_SWITCH_FINISHED && !pids("app_switch.sh")){
				_dprintf("Don't have the switch script.\n");
				nvram_set("apps_state_switch", "");
			}

			unlink(PID_FILE);
			return 0;
		}

		memset(chk_value, 0, 4);
		strncpy(chk_value, nvram_safe_get("apps_state_install"), 4);
		if(strcmp(chk_value, "")){
			if(atoi(chk_value) != APPS_INSTALL_FINISHED && !pids("app_install.sh")){
				_dprintf("Don't have the install script.\n");
				nvram_set("apps_state_install", "");
			}

			unlink(PID_FILE);
			return 0;
		}

		memset(chk_value, 0, 4);
		strncpy(chk_value, nvram_safe_get("apps_state_upgrade"), 4);
		if(strcmp(chk_value, "")){
			if(atoi(chk_value) != APPS_UPGRADE_FINISHED && !pids("app_upgrade.sh")){
				_dprintf("Don't have the upgrade script.\n");
				nvram_set("apps_state_upgrade", "");
			}

			unlink(PID_FILE);
			return 0;
		}

		memset(chk_value, 0, 4);
		strncpy(chk_value, nvram_safe_get("apps_state_enable"), 4);
		if(strcmp(chk_value, "")){
			if(atoi(chk_value) != APPS_ENABLE_FINISHED && !pids("app_set_enabled.sh")){
				_dprintf("Don't have the enable script.\n");
				nvram_set("apps_state_enable", "");
			}

			unlink(PID_FILE);
			return 0;
		}

		unlink(PID_FILE);
		return 0;
	}
#endif
#endif
	else if(!strcmp(base, "ATE")) {
		if( argc == 2 || argc == 3 || argc == 4) {
			asus_ate_command(argv[1], argv[2], argv[3]);
		}
		else
			printf("ATE_ERROR\n");
                return 0;
	}
#if defined(RTCONFIG_RALINK)
	else if (!strcmp(base, "FWRITE")) {
		if (argc == 3)
			return FWRITE(argv[1], argv[2]);
		else
		return 0;
	}
	else if (!strcmp(base, "FREAD")) {
		if (argc == 3)
		{
			unsigned int addr;
			int len;
			addr = strtoul(argv[1], NULL, 16);
			if(argv[2][0] == '0' && argv[2][1] == 'x')
				len  = (int) strtoul(argv[2], NULL, 16);
			else
				len  = (int) strtoul(argv[2], NULL, 10);

			if(len > 0)
				return FREAD(addr, len);
		}
		printf("ATE_ERROR\n");
		return 0;
	}
	else if (!strcmp(base, "asuscfe_5g")) {
		if (argc == 2)
			return asuscfe(argv[1], WIF_5G);
		else
			return EINVAL;
	}
	else if (!strcmp(base, "asuscfe_2g")) {
		if (argc == 2)
			return asuscfe(argv[1], WIF_2G);
		else
			return EINVAL;
	}
	else if (!strcmp(base, "stainfo_2g")) {
		return stainfo(0);
	}
	else if (!strcmp(base, "stainfo_5g")) {
		return stainfo(1);
	}
#ifdef RTCONFIG_DSL
	else if(!strcmp(base, "gen_ralink_config")){
		if(argc != 3){
			printf("Usage: gen_ralink_config [band] [is_iNIC]\n");
			return 0;
		}
		return gen_ralink_config(atoi(argv[1]), atoi(argv[2]));
	}
#endif
#endif
	else if(!strcmp(base, "run_telnetd")) {
		run_telnetd();
		return 0;
	}
#if defined(RTCONFIG_PPTPD) || defined(RTCONFIG_ACCEL_PPTPD)
	else if(!strcmp(base, "run_pptpd")) {
		start_pptpd();
		return 0;
	}
#endif
#ifdef RTCONFIG_PARENTALCTRL
	else if(!strcmp(base, "pc")) {
		pc_main(argc, argv);
		return 0;
	}
#endif
#ifdef CONFIG_BCMWL5
	else if (!strcmp(base, "wlcscan")) {
		return wlcscan_main();
	}
#endif
#ifdef RTCONFIG_WIRELESSREPEATER
	else if (!strcmp(base, "wlcconnect")) {
		return wlcconnect_main();
	}
	else if (!strcmp(base, "setup_dnsmq")) {
		if(argc != 2)
			return 0;

		return setup_dnsmq(atoi(argv[1]));
	}
#endif
	else if (!strcmp(base, "add_multi_routes")) {
		return add_multi_routes();
	}
	else if (!strcmp(base, "led_ctrl")) {
		if (argc != 3)
			return 0;

		return(led_control(atoi(argv[1]), atoi(argv[2])));
	}
#ifdef RTCONFIG_BCMARM
        /* mtd-erase2 [device] */
        else if (!strcmp(base, "mtd-erase2")) {
                if (argv[1] && ((!strcmp(argv[1], "boot")) ||
                        (!strcmp(argv[1], "linux")) ||
                        (!strcmp(argv[1], "linux2")) ||
                        (!strcmp(argv[1], "rootfs")) ||
                        (!strcmp(argv[1], "rootfs2")) ||
                        (!strcmp(argv[1], "nvram")))) {

                        return mtd_erase(argv[1]);
                } else {
                        fprintf(stderr, "usage: mtd-erase2 [device]\n");
                        return EINVAL;
                }
        }
        /* mtd-write2 [path] [device] */
        else if (!strcmp(base, "mtd-write2")) {
                if (argc >= 3)
                        return mtd_write(argv[1], argv[2]);
                else {
                        fprintf(stderr, "usage: mtd-write2 [path] [device]\n");
                        return EINVAL;
                }
        }
#endif
	else if (!strcmp(base, "free_caches")) {
		int c;
		unsigned int test_num;
		char *set_value = NULL;
		int clean_time = 1;
		int threshold = 0;

		if(argc){
			while((c = getopt(argc, argv, "c:w:t:")) != -1){
				switch(c){
					case 'c': // set the clean-cache mode: 0~3.
						test_num = strtol(optarg, NULL, 10);
        		if(test_num == LONG_MIN || test_num == LONG_MAX){
        			_dprintf("ERROR: unknown value %s...\n", optarg);
							return 0;
						}

						if(test_num < 0 || test_num > 3){
							_dprintf("ERROR: the value %s was over the range...\n", optarg);
							return 0;
						}

						set_value = optarg;

						break;
					case 'w': // set the waited time for cleaning.
						test_num = strtol(optarg, NULL, 10);
        		if(test_num < 0 || test_num == LONG_MIN || test_num == LONG_MAX){
        			_dprintf("ERROR: unknown value %s...\n", optarg);
							return 0;
						}

						clean_time = test_num;

						break;
					case 't': // set the waited time for cleaning.
						test_num = strtol(optarg, NULL, 10);
        		if(test_num < 0 || test_num == LONG_MIN || test_num == LONG_MAX){
        			_dprintf("ERROR: unknown value %s...\n", optarg);
							return 0;
						}

						threshold = test_num;

						break;
					default:
						fprintf(stderr, "Usage: free_caches [ -c clean_mode ] [ -w clean_time ] [ -t threshold ]\n");
						break;
				}
			}
		}

		if(!set_value)
			set_value = FREE_MEM_PAGE;

		free_caches(set_value, clean_time, threshold);

		return 0;
	}
	printf("Unknown applet: %s\n", base);
	return 0;
}
示例#10
0
文件: shell.c 项目: vicky98/class2
int main()
{
	//--------------------------------------------
	// FUNCTION: main
	// The main body of the program
	// PARAMETERS:
	// cmdline1    - input
	// cmdline     - const input
	// token       - the split input
	// args_array  - the array with arguments
	// pid         - process ID
	// status      - status
	// file_exist  - the value returned by f_exists()
	// file_access - the value returned by f_access()
	//----------------------------------------------

	while(1)
	{
		char* cmdline1 = NULL;
		size_t size = 0;
		getline(&cmdline1, &size, stdin);
		strtok(cmdline1, " \n");
		const char* cmdline = cmdline1;
		char* const* args_array = parse_cmdline(cmdline);
		const char* filename = args_array[0];

		int file_exist = f_exists(filename);
		int file_access = f_access(filename);

		if (file_exist == 0)
			perror(filename);
		
		if (file_exist == 1 && file_access == 1)
			perror(filename);

		pid_t pid = fork();
		int status;

		if (file_exist == 1 && file_access == 0)
		{
			if (pid < 0)
				printf("Forking failed\n");

			if (pid == 0)  // in the child process
			{
				int e_value = execv(filename, args_array); 

				if (e_value < 0)
					printf("Execv error\n");		    	 
			}
	
			if (pid > 0)  // in the parent process
			{
				int w_value = waitpid(pid, &status, 0);

				if (w_value < 0)
					printf("Waitpid error\n");
			}
		}
	}

    return 0;
}
示例#11
0
int ssl_server_init(char* ca_file, char *crt_file, char *key_file, char *dhp_file, char *ssl_cipher_list)
{
	static const char *ssl_ctx_id = "httpd";
	long ssl_options;

	if (!crt_file || !f_exists(crt_file)) {
		httpd_log("%s: Server certificate (%s) is not found!", SYSLOG_ID_SSL, crt_file);
		httpd_log("Please manual build the certificate via \"%s\" script.", "https-cert.sh");
		return -1;
	}

	if (!key_file || !f_exists(key_file)) {
		httpd_log("%s: Server private key (%s) is not found!", SYSLOG_ID_SSL, key_file);
		httpd_log("Please manual build the certificate via \"%s\" script.", "https-cert.sh");
		return -1;
	}

	SSL_load_error_strings();
	SSL_library_init();

	ssl_ctx = SSL_CTX_new(SSLv23_server_method());
	if (!ssl_ctx) {
		httpd_log("%s: Unable to create SSL context!", SYSLOG_ID_SSL);
		return -1;
	}

	ssl_options = SSL_OP_ALL | SSL_OP_NO_COMPRESSION | SSL_OP_NO_SSLv2 |
			SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION;

	SSL_CTX_set_options(ssl_ctx, ssl_options);
	SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_NONE, NULL);

	if (ssl_cipher_list && strlen(ssl_cipher_list) > 2) {
		if (SSL_CTX_set_cipher_list(ssl_ctx, ssl_cipher_list) != 1) {
			httpd_log("%s: Cannot set SSL cipher list (%s)!", SYSLOG_ID_SSL, ssl_cipher_list);
		} else {
			SSL_CTX_set_options(ssl_ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
		}
	}

	if (ca_file && f_exists(ca_file)) {
		if (SSL_CTX_load_verify_locations(ssl_ctx, ca_file, NULL) != 1) {
			httpd_log("%s: Cannot load CA certificate (%s)!", SYSLOG_ID_SSL, ca_file);
		}
	}

	if (SSL_CTX_use_certificate_file(ssl_ctx, crt_file, SSL_FILETYPE_PEM) != 1) {
		httpd_log("%s: Cannot load server certificate (%s)!", SYSLOG_ID_SSL, crt_file);
		ssl_server_uninit();
		return 1;
	}

	if (SSL_CTX_use_PrivateKey_file(ssl_ctx, key_file, SSL_FILETYPE_PEM) != 1) {
		httpd_log("%s: Cannot load server private key (%s)!", SYSLOG_ID_SSL, key_file);
		ssl_server_uninit();
		return 1;
	}

	if (SSL_CTX_check_private_key(ssl_ctx) != 1) {
		httpd_log("%s: Private key does not match the certificate!", SYSLOG_ID_SSL);
		ssl_server_uninit();
		return 1;
	}

	if (dhp_file && f_exists(dhp_file)) {
		/* DH parameters from file */
		BIO *bio = BIO_new_file(dhp_file, "r");
		if (bio) {
			DH *dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
			BIO_free(bio);
			if (dh) {
				SSL_CTX_set_tmp_dh(ssl_ctx, dh);
				SSL_CTX_set_options(ssl_ctx, SSL_OP_SINGLE_DH_USE);
				DH_free(dh);
			} else {
				httpd_log("%s: Cannot load DH parameters (%s)!", SYSLOG_ID_SSL, dhp_file);
			}
		}
	} else {
		/* Default DH parameters from RFC5114 */
		DH *dh = DH_new();
		if (dh) {
			dh->p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), NULL);
			dh->g = BN_bin2bn(dh1024_g, sizeof(dh1024_g), NULL);
			dh->length = 160;
			if (dh->p && dh->g) {
				SSL_CTX_set_tmp_dh(ssl_ctx, dh);
				SSL_CTX_set_options(ssl_ctx, SSL_OP_SINGLE_DH_USE);
			}
			DH_free(dh);
		}
	}

	SSL_CTX_set_default_read_ahead(ssl_ctx, 1);

	SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_SERVER);
	SSL_CTX_set_session_id_context(ssl_ctx, (unsigned char *)ssl_ctx_id, strlen(ssl_ctx_id));
	SSL_CTX_sess_set_cache_size(ssl_ctx, 10);

	SSL_CTX_set_info_callback(ssl_ctx, http_ssl_info_cb);

	return 0;
}
示例#12
0
int main(int argc, char **argv)
{
	char *base;
	int f;

	/*
		Make sure std* are valid since several functions attempt to close these
		handles. If nvram_*() runs first, nvram=0, nvram gets closed. - zzz
	*/
	if ((f = open("/dev/null", O_RDWR)) < 3) {
		dup(f);
		dup(f);
	}
	else {
		close(f);
	}

	base = strrchr(argv[0], '/');
	base = base ? base + 1 : argv[0];

#if 0
	if (strcmp(base, "rc") == 0) {
		if (argc < 2) return 1;
		if (strcmp(argv[1], "start") == 0) return kill(1, SIGUSR2);
		if (strcmp(argv[1], "stop") == 0) return kill(1, SIGINT);
		if (strcmp(argv[1], "restart") == 0) return kill(1, SIGHUP);
		++argv;
		--argc;
		base = argv[0];
	}
#endif

#if defined(DEBUG_NOISY)
	if (nvram_match("debug_logrc", "1")) {
		int i;

		cprintf("[rc %d] ", getpid());
		for (i = 0; i < argc; ++i) {
			cprintf("%s ", argv[i]);
		}
		cprintf("\n");

	}
#endif

#if defined(DEBUG_NOISY)
	if (nvram_match("debug_ovrc", "1")) {
		char tmp[256];
		char *a[32];

		realpath(argv[0], tmp);
		if ((strncmp(tmp, "/tmp/", 5) != 0) && (argc < 32)) {
			sprintf(tmp, "%s%s", "/tmp/", base);
			if (f_exists(tmp)) {
				cprintf("[rc] override: %s\n", tmp);
				memcpy(a, argv, argc * sizeof(a[0]));
				a[argc] = 0;
				a[0] = tmp;
				execvp(tmp, a);
				exit(0);
			}
		}
	}
#endif

	const applets_t *a;
	for (a = applets; a->name; ++a) {
		if (strcmp(base, a->name) == 0) {
			openlog(base, LOG_PID, LOG_USER);
			return a->main(argc, argv);
		}
	}


	if(!strcmp(base, "restart_wireless")){
		printf("restart wireless...\n");
		restart_wireless();
		return 0;
	}
#ifdef RTCONFIG_USB
	else if(!strcmp(base, "get_apps_name")){
		if(argc != 2){
			printf("Usage: get_apps_name [File name]\n");
			return 0;
		}

		return get_apps_name(argv[1]);
	}
	else if(!strcmp(base, "asus_sd")){
		if(argc != 3){
			printf("Usage: asus_sd [device_name] [action]\n");
			return 0;
		}

		return asus_sd(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_lp")){
		if(argc != 3){
			printf("Usage: asus_lp [device_name] [action]\n");
			return 0;
		}

		return asus_lp(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_sg")){
		if(argc != 3){
			printf("Usage: asus_sg [device_name] [action]\n");
			return 0;
		}

		return asus_sg(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_sr")){
		if(argc != 3){
			printf("Usage: asus_sr [device_name] [action]\n");
			return 0;
		}

		return asus_sr(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_tty")){
		if(argc != 3){
			printf("Usage: asus_tty [device_name] [action]\n");
			return 0;
		}

		return asus_tty(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_usbbcm")){
		if(argc != 3){
			printf("Usage: asus_usbbcm [device_name] [action]\n");
			return 0;
		}

		return asus_usbbcm(argv[1], argv[2]);
	}
	else if(!strcmp(base, "asus_usb_interface")){
		if(argc != 3){
			printf("Usage: asus_usb_interface [device_name] [action]\n");
			return 0;
		}

		return asus_usb_interface(argv[1], argv[2]);
	}
#endif
	else if(!strcmp(base, "run_app_script")){
		if(argc != 3){
			printf("Usage: run_app_script [Package name | allpkg] [APP action]\n");
			return 0;
		}

		if(!strcmp(argv[1], "allpkg"))
			return run_app_script(NULL, argv[2]);
		else
			return run_app_script(argv[1], argv[2]);
	}
	else if(!strcmp(base, "ATE")) {
		if( argc == 2 || argc == 3 || argc == 4) {
			asus_ate_command(argv[1], argv[2], argv[3]);
		}
		else
			printf("ATE_ERROR\n");
                return 0;
	}
#ifdef RTCONFIG_DSL
	else if(!strcmp(base, "gen_ralink_config")){
		if(argc != 3){
			printf("Usage: gen_ralink_config [band] [is_iNIC]\n");
			return 0;
		}
		return gen_ralink_config(atoi(argv[1]), atoi(argv[2]));
	}
#endif
	else if(!strcmp(base, "run_telnetd")) {
		run_telnetd();
		return 0;
	}
#if defined(RTCONFIG_PPTPD) || defined(RTCONFIG_ACCEL_PPTPD)
	else if(!strcmp(base, "run_pptpd")) {
		start_pptpd();
		return 0;
	}
#endif
#ifdef RTCONFIG_PARENTALCTRL
	else if(!strcmp(base, "pc")) {
		pc_main(argc, argv);
		return 0;
	}
#endif
#ifdef RTCONFIG_WIRELESSREPEATER
	else if (!strcmp(base, "wlcscan")) {
		return wlcscan_main();
	}
	else if (!strcmp(base, "wlcconnect")) {
		return wlcconnect_main();
	}
	else if (!strcmp(base, "setup_dnsmq")) {
		if(argc != 2)
			return 0;

		return setup_dnsmq(atoi(argv[1]));
	}
#endif
#ifdef RTCONFIG_BCMWL6
#ifdef ACS_ONCE
        else if (!strcmp(base, "acsd_restart_wl")) {
		restart_wireless_acsd();
		return 0;
        }
#endif
#endif
	else if (!strcmp(base, "add_multi_routes")) {
		return add_multi_routes();
	}
#ifndef OVERWRITE_DNS
	else if (!strcmp(base, "add_ns")) {
		return add_ns(argv[1]);
	}
	else if (!strcmp(base, "del_ns")) {
		return del_ns(argv[1]);
	}
#endif
	else if (!strcmp(base, "led_ctrl")) {
		return(led_control(atoi(argv[1]), atoi(argv[2])));
	}
	else if (!strcmp(base, "free_caches")) {
		int c;
		unsigned int test_num;
		char *set_value = NULL;
		int clean_time = 1;
		int threshold = 0;

		if(argc){
			while((c = getopt(argc, argv, "c:w:t:")) != -1){
				switch(c){
					case 'c': // set the clean-cache mode: 0~3.
						test_num = strtol(optarg, NULL, 10);
        		if(test_num == LONG_MIN || test_num == LONG_MAX){
        			_dprintf("ERROR: unknown value %s...\n", optarg);
							return 0;
						}

						if(test_num < 0 || test_num > 3){
							_dprintf("ERROR: the value %s was over the range...\n", optarg);
							return 0;
						}

						set_value = optarg;

						break;
					case 'w': // set the waited time for cleaning.
						test_num = strtol(optarg, NULL, 10);
        		if(test_num <= 0 || test_num == LONG_MIN || test_num == LONG_MAX){
        			_dprintf("ERROR: unknown value %s...\n", optarg);
							return 0;
						}

						clean_time = test_num;

						break;
					case 't': // set the waited time for cleaning.
						test_num = strtol(optarg, NULL, 10);
        		if(test_num < 0 || test_num == LONG_MIN || test_num == LONG_MAX){
        			_dprintf("ERROR: unknown value %s...\n", optarg);
							return 0;
						}

						threshold = test_num;

						break;
					default:
						fprintf(stderr, "Usage: free_caches [ -c clean_mode ] [ -w clean_time ] [ -t threshold ]\n");
						break;
				}
			}
		}

		if(!set_value)
			set_value = FREE_MEM_PAGE;

		free_caches(set_value, clean_time, threshold);

		return 0;
	}
	printf("Unknown applet: %s\n", base);
	return 0;
}
示例#13
0
int main(int argc, char **argv)
{
	char *base;
	int f;

	/*
		Make sure std* are valid since several functions attempt to close these
		handles. If nvram_*() runs first, nvram=0, nvram gets closed. - zzz
	*/
	if ((f = open("/dev/null", O_RDWR)) < 3) {
		dup(f);
		dup(f);
	}
	else {
		close(f);
	}

	base = strrchr(argv[0], '/');
	base = base ? base + 1 : argv[0];

#if 1
	if (strcmp(base, "rc") == 0) {
		if (argc < 2) return 1;
		if (strcmp(argv[1], "start") == 0) return kill(1, SIGUSR2);
		if (strcmp(argv[1], "stop") == 0) return kill(1, SIGINT);
		if (strcmp(argv[1], "restart") == 0) return kill(1, SIGHUP);
		++argv;
		--argc;
		base = argv[0];
	}
#endif

#if defined(DEBUG_NOISY)
	if (nvram_match("debug_logrc", "1")) {
		int i;

		cprintf("[rc %d] ", getpid());
		for (i = 0; i < argc; ++i) {
			cprintf("%s ", argv[i]);
		}
		cprintf("\n");

	}
#endif

#if defined(DEBUG_NOISY)
	if (nvram_match("debug_ovrc", "1")) {
		char tmp[256];
		char *a[32];

		realpath(argv[0], tmp);
		if ((strncmp(tmp, "/tmp/", 5) != 0) && (argc < 32)) {
			sprintf(tmp, "%s%s", "/tmp/", base);
			if (f_exists(tmp)) {
				cprintf("[rc] override: %s\n", tmp);
				memcpy(a, argv, argc * sizeof(a[0]));
				a[argc] = 0;
				a[0] = tmp;
				execvp(tmp, a);
				exit(0);
			}
		}
	}
#endif

	const applets_t *a;
	for (a = applets; a->name; ++a) {
		if (strcmp(base, a->name) == 0) {
			openlog(base, LOG_PID, LOG_USER);
			return a->main(argc, argv);
		}
	}

	printf("Unknown applet: %s\n", base);
	return 0;
}
示例#14
0
void start_chilli(void)
{
	int ret = 0;
	char ssid[128];

if ((nvram_match("usb_enable", "1")
	&& nvram_match("usb_storage", "1")
	&& nvram_match("usb_automnt", "1")
	&& nvram_match("usb_mntpoint", "jffs"))
	|| (nvram_match("enable_jffs2", "1")
	&& nvram_match("jffs_mounted", "1")
	&& nvram_match("sys_enable_jffs2", "1")))
		jffs = 1;

	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")) {
#ifdef HAVE_COOVA_CHILLI
		putenv("CHILLISTATEDIR=/var/run/chilli1");
		mkdir("/var/run/chilli1", 0700);
		ret = eval("chilli", "--statedir=/var/run/chilli1",
			"--pidfile=/var/run/chilli1/chilli.pid",
			"-c", "/tmp/chilli/hotss.conf");
#else
		ret = eval("chilli", "-c", "/tmp/chilli/hotss.conf");
#endif
		dd_syslog(LOG_INFO, "hotspotsystem : chilli daemon successfully started\n");
	} else {
#ifdef HAVE_COOVA_CHILLI
		putenv("CHILLISTATEDIR=/var/run/chilli1");
		mkdir("/var/run/chilli1", 0700);
		ret = eval("chilli", "--statedir=/var/run/chilli1",
			"--pidfile=/var/run/chilli1/chilli.pid",
			"-c", "/tmp/chilli/chilli.conf");
#else
		ret = eval("chilli", "-c", "/tmp/chilli/chilli.conf");
#endif
		dd_syslog(LOG_INFO, "chilli : chilli daemon successfully started\n");
	}
#ifdef HAVE_TIEXTRA1
	start_mchilli();
#endif

	cprintf("done\n");
	return;
}
示例#15
0
void start_freeradius(void)
{
	int ret = 0;
	pid_t pid;

	char *radiusd_argv[] = { "radiusd", "-d", "/jffs/etc/freeradius", NULL };
	FILE *fp = NULL;
	stop_freeradius();
	nvram_default_get("radius_country", "DE");
	nvram_default_get("radius_state", "Saxony");
	nvram_default_get("radius_locality", "none");
	nvram_default_get("radius_expiration", "365");
	nvram_default_get("radius_passphrase", "changeme");
	nvram_default_get("radius_organisation", "DD-WRT");
	nvram_default_get("radius_email", "*****@*****.**");
	nvram_default_get("radius_common", "DD-WRT FreeRadius Certificate");

	nvram_default_get("radius_port", "1812");
	nvram_default_get("radius_enabled", "0");
	if (!nvram_match("radius_enabled", "1"))
		return;

#ifndef HAVE_OPENRISC
#ifndef HAVE_VENTANA
#if !defined(HAVE_RB600) || defined(HAVE_WDR4900)
#ifdef HAVE_X86
	system("mount --bind /usr/local /jffs");
#else
	if (!nvram_match("jffs_mounted", "1"))
		return;		//jffs is a requirement for radius and must be mounted at this point here
#endif
#endif
#endif
#endif
	prep();
	sysprintf("sed \"s/port = 0/port = %s/g\" /etc/freeradius/radiusd.conf > /jffs/etc/freeradius/radiusd.conf", nvram_safe_get("radius_port"));
	sysprintf("sed \"s/private_key_password = whatever/private_key_password = %s/g\" /etc/freeradius/eap.conf > /jffs/etc/freeradius/eap.conf", nvram_safe_get("radius_passphrase"));

	if (!f_exists("/jffs/etc/freeradius/certs/server.pem")) {
		//prepare certificates
		start_gen_radius_cert();
	}

	int i;

	/* generate clients */
	{
		struct radiusclientdb *db = loadradiusclientdb();
		if (db) {
			fp = fopen("/jffs/etc/freeradius/clients.conf", "wb");
			system("touch /jffs/etc/freeradius/clients.manual");
			fprintf(fp, "$INCLUDE clients.manual\n");

			for (i = 0; i < db->usercount; i++) {
				if (!db->users[i].clientsize)
					continue;
				if (!db->users[i].client || !strlen(db->users[i].client))
					continue;
				fprintf(fp, "client %s {\n" "\tsecret = %s\n" "\tshortname = DD-WRT-RADIUS\n}\n", db->users[i].client, db->users[i].passwd);
			}

			fclose(fp);
			freeradiusclientdb(db);
		}
	}

	/* now generate users */
	{
		struct radiusdb *db = loadradiusdb();
		if (db) {
			fp = fopen("/jffs/etc/freeradius/users", "wb");
			system("touch /jffs/etc/freeradius/users.manual");
			fprintf(fp, "$INCLUDE users.manual\n");
			fprintf(fp, "DEFAULT FreeRADIUS-Proxied-To == 127.0.0.1\n" "\tSession-Timeout := 3600,\n" "\tUser-Name := \"%%{User-Name}\",\n" "\tAcct-Interim-Interval := 300,\n" "\tFall-Through = Yes\n\n");
			time_t tm;
			struct tm tm_time;
			for (i = 0; i < db->usercount; i++) {
				if (!db->users[i].usersize)
					continue;
				if (!db->users[i].user || !strlen(db->users[i].user))
					continue;
				if (!db->users[i].enabled)
					continue;
				fprintf(fp, "%s        Cleartext-Password := \"%s\"", db->users[i].user, db->users[i].passwd);
				if (db->users[i].expiration) {
					tm = db->users[i].expiration * 24 * 60 * 60;
					memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
					char datebuf[128];
					strftime(datebuf, sizeof(datebuf), "%d %b %Y", &tm_time);
					fprintf(fp, ", Expiration == \"%s\"\n", datebuf);
				} else
					fprintf(fp, "\n");
				if (db->users[i].downstream) {
					fprintf(fp, "\tWISPr-Bandwidth-Max-Down := %d,\n", db->users[i].downstream * 1024);
					fprintf(fp, "\tRP-Downstream-Speed-Limit := %d", db->users[i].downstream);
				}
				if (db->users[i].upstream) {
					if (db->users[i].downstream)
						fprintf(fp, ",\n");
					fprintf(fp, "\tWISPr-Bandwidth-Max-Up := %d,\n", db->users[i].upstream * 1024);
					fprintf(fp, "\tRP-Upstream-Speed-Limit := %d", db->users[i].upstream);
				}
				fprintf(fp, "\n");
			}
			fclose(fp);
			freeradiusdb(db);
		}
	}
	ret = _evalpid(radiusd_argv, NULL, 0, &pid);

	dd_syslog(LOG_INFO, "radiusd : FreeRadius daemon successfully started\n");

	return;
}
示例#16
0
文件: file.c 项目: pudquick/vcp
struct file *f_get(char *fname)
{
	struct file *new_item;
	struct stat filestat;
	
	/* check existance */
	if (!f_exists(fname)) {
		return NULL;
	}
	
	/* create new item */
	new_item = malloc(sizeof(struct file));
	if (new_item == NULL) {
		return NULL;
	}
	new_item->dst = NULL;
	new_item->size = 0;
	new_item->uid = 0;
	new_item->gid = 0;
	new_item->mode = 0;
    new_item->done = 0;
	
	/* set source names */
	new_item->src = fname;
	new_item->fname = basename(fname);

    /* determine file type, collect attributes */
    if (lstat(fname, &filestat) != 0) {
        free(new_item);
        return NULL;
    }
    if (S_ISLNK(filestat.st_mode)) {
        /* symlink */
        new_item->type = SLINK;
        new_item->dst = new_item->src;
        new_item->src = malloc(filestat.st_size + 1);
        if (readlink(fname, new_item->src, filestat.st_size) !=
                        filestat.st_size) {
            free(new_item);
            return NULL;
        }
        new_item->src[filestat.st_size] = '\0';
    } else {
        /* POSIX: uid, modes etc. not defined by lstat(), use stat()    */
        if (stat(fname, &filestat) != 0) {
            free(new_item);
            return NULL;
        }
        new_item->uid = filestat.st_uid;
        new_item->gid = filestat.st_gid;
        new_item->mode = filestat.st_mode;
        new_item->times.actime = filestat.st_atime;
        new_item->times.modtime = filestat.st_mtime;
        if (S_ISREG(filestat.st_mode)) {
            /* regular file */
            new_item->type = RFILE;
            new_item->size = filestat.st_size;
        } else if (S_ISDIR(filestat.st_mode)) {
            /* directory */
            new_item->type = RDIR;
        } else {
            /* unknown object, abort */
            free(new_item);
            return NULL;
        }
    }
	
	return new_item;
}