Exemplo n.º 1
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;
}
Exemplo n.º 2
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.º 3
0
void start_dnsmasq(void)
{
	FILE *fp;
	struct dns_lists *dns_list = NULL;
	int ret;
	int i;

	if (nvram_match("dhcp_dnsmasq", "1")
	    && nvram_match("lan_proto", "dhcp")
	    && nvram_match("dnsmasq_enable", "0")) {
		nvram_set("dnsmasq_enable", "1");
		nvram_commit();
	}

	if (!nvram_invmatch("dnsmasq_enable", "0")) {
		stop_dnsmasq();
		return;
	}

	usejffs = 0;

	if (nvram_match("dhcpd_usejffs", "1")) {
		if (!(fp = fopen("/jffs/dnsmasq.leases", "a"))) {
			usejffs = 0;
		} else {
			fclose(fp);
			usejffs = 1;
		}
	}

	/*
	 * Write configuration file based on current information 
	 */
	if (!(fp = fopen("/tmp/dnsmasq.conf", "w"))) {
		perror("/tmp/dnsmasq.conf");
		return;
	}
//    fprintf(fp, "bind-interfaces\n");
	if (nvram_match("chilli_enable", "1")) {
		if (canlan())
			fprintf(fp, "interface=%s", get_wdev());
		else
			fprintf(fp, "interface=%s,", get_wdev());
	} else if (nvram_match("pptpd_enable", "1")) {
		if (canlan())
			fprintf(fp, "listen-address=%s,%s", "127.0.0.1",
				nvram_safe_get("lan_ipaddr"));
		else
			fprintf(fp, "listen-address=%s", "127.0.0.1");
	} else {
		if (canlan())
			fprintf(fp, "interface=%s",
				nvram_safe_get("lan_ifname"));
		else
			fprintf(fp, "interface=");
	}
	int mdhcpcount = 0;

	if (nvram_get("mdhcpd_count") != NULL) {
		mdhcpcount = atoi(nvram_safe_get("mdhcpd_count"));
		for (i = 0; i < mdhcpcount; i++) {
			if (strlen(nvram_nget("%s_ipaddr", getmdhcp(0, i))) == 0
			    || strlen(nvram_nget("%s_netmask", getmdhcp(0, i)))
			    == 0)
				continue;
			if (canlan() || i > 0) {
				if (nvram_match("pptpd_enable", "1"))
					fprintf(fp, ",%s",
						nvram_nget("%s_ipaddr",
							   getmdhcp(0, i)));
				else
					fprintf(fp, ",%s", getmdhcp(0, i));
			} else {
				if (nvram_match("pptpd_enable", "1"))
					fprintf(fp, "%s",
						nvram_nget("%s_ipaddr",
							   getmdhcp(0, i)));
				else
					fprintf(fp, "%s", getmdhcp(0, i));

			}
		}
	}
	fprintf(fp, "\n");

	fprintf(fp, "resolv-file=/tmp/resolv.dnsmasq\n" "all-servers\n"); //

	/*
	 * Domain 
	 */
	if (nvram_match("dhcp_domain", "wan")) {
		if (nvram_invmatch("wan_domain", ""))
			fprintf(fp, "domain=%s\n",
				nvram_safe_get("wan_domain"));
		else if (nvram_invmatch("wan_get_domain", ""))
			fprintf(fp, "domain=%s\n",
				nvram_safe_get("wan_get_domain"));
	} else {
		if (nvram_invmatch("lan_domain", ""))
			fprintf(fp, "domain=%s\n",
				nvram_safe_get("lan_domain"));
	}

	/*
	 * DD-WRT use dnsmasq as DHCP replacement 
	 */

	//bs mod
	if (hasdhcp()) {
		/*
		 * DHCP leasefile 
		 */
		if (nvram_match("dhcpd_usenvram", "1")) {
			fprintf(fp, "leasefile-ro\n");
			fprintf(fp, "dhcp-script=%s\n", "/etc/lease_update.sh");
		} else {
			if (usejffs)
				fprintf(fp,
					"dhcp-leasefile=/jffs/dnsmasq.leases\n");
			else
				fprintf(fp,
					"dhcp-leasefile=/tmp/dnsmasq.leases\n");
		}

		int dhcp_max = 0;

		if (landhcp())
			dhcp_max +=
			    atoi(nvram_safe_get("dhcp_num")) +
			    atoi(nvram_safe_get("static_leasenum"));
		for (i = 0; i < mdhcpcount; i++) {
			if (strlen(nvram_nget("%s_ipaddr", getmdhcp(0, i))) == 0
			    || strlen(nvram_nget("%s_netmask", getmdhcp(0, i)))
			    == 0)
				continue;
			dhcp_max += atoi(getmdhcp(3, i));
		}
		fprintf(fp, "dhcp-lease-max=%d\n", dhcp_max);
		if (landhcp())
			fprintf(fp, "dhcp-option=lan,3,%s\n",
				nvram_safe_get("lan_ipaddr"));
		for (i = 0; i < mdhcpcount; i++) {
			if (strlen(nvram_nget("%s_ipaddr", getmdhcp(0, i))) == 0
			    || strlen(nvram_nget("%s_netmask", getmdhcp(0, i)))
			    == 0)
				continue;
			fprintf(fp, "dhcp-option=%s,3,", getmdhcp(0, i));
			fprintf(fp, "%s\n",
				nvram_nget("%s_ipaddr", getmdhcp(0, i)));
		}
		if (nvram_invmatch("wan_wins", "")
		    && nvram_invmatch("wan_wins", "0.0.0.0"))
			fprintf(fp, "dhcp-option=44,%s\n",
				nvram_safe_get("wan_wins"));

		if (nvram_match("dns_dnsmasq", "0")) {
			dns_list = get_dns_list();

			if (dns_list
			    && (strlen(dns_list->dns_server[0]) > 0
				|| strlen(dns_list->dns_server[1]) > 0
				|| strlen(dns_list->dns_server[2]) > 0)) {

				fprintf(fp, "dhcp-option=6");

				if (strlen(dns_list->dns_server[0]) > 0)
					fprintf(fp, ",%s",
						dns_list->dns_server[0]);

				if (strlen(dns_list->dns_server[1]) > 0)
					fprintf(fp, ",%s",
						dns_list->dns_server[1]);

				if (strlen(dns_list->dns_server[2]) > 0)
					fprintf(fp, ",%s",
						dns_list->dns_server[2]);

				fprintf(fp, "\n");
			}

			if (dns_list)
				free(dns_list);
		}

		if (nvram_match("auth_dnsmasq", "1"))
			fprintf(fp, "dhcp-authoritative\n");
		if (landhcp()) {
			fprintf(fp, "dhcp-range=lan,");
			fprintf(fp, "%d.%d.%d.%s,",
				get_single_ip(nvram_safe_get("lan_ipaddr"), 0),
				get_single_ip(nvram_safe_get("lan_ipaddr"), 1),
				get_single_ip(nvram_safe_get("lan_ipaddr"), 2),
				nvram_safe_get("dhcp_start"));
			if (nvram_match("dhcp_num", "0")) {
				fprintf(fp, "static,");
			} else {
				fprintf(fp, "%d.%d.%d.%d,",
					get_single_ip(nvram_safe_get
						      ("lan_ipaddr"), 0),
					get_single_ip(nvram_safe_get
						      ("lan_ipaddr"), 1),
					get_single_ip(nvram_safe_get
						      ("lan_ipaddr"), 2),
					atoi(nvram_safe_get("dhcp_start")) +
					atoi(nvram_safe_get("dhcp_num")) - 1);
			}
			fprintf(fp, "%s,", nvram_safe_get("lan_netmask"));
			fprintf(fp, "%sm\n", nvram_safe_get("dhcp_lease"));
		}

		for (i = 0; i < mdhcpcount; i++) {
			if (strcmp(getmdhcp(1, i), "On"))
				continue;
			if (strlen(nvram_nget("%s_ipaddr", getmdhcp(0, i))) == 0
			    || strlen(nvram_nget("%s_netmask", getmdhcp(0, i)))
			    == 0)
				continue;
			fprintf(fp, "dhcp-range=%s,", getmdhcp(0, i));
			fprintf(fp, "%d.%d.%d.",
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      0),
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      1),
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      2));
			fprintf(fp, "%s,", getmdhcp(2, i));
			fprintf(fp, "%d.%d.%d.",
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      0),
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      1),
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      2));
			int end = atoi(getmdhcp(2, i));

			end += atoi(getmdhcp(3, i));
			fprintf(fp, "%d,", end);
			fprintf(fp, "%s,",
				nvram_nget("%s_netmask", getmdhcp(0, i)));
			fprintf(fp, "%sm\n", getmdhcp(4, i));
		}

		int leasenum = atoi(nvram_safe_get("static_leasenum"));

		if (leasenum > 0) {
			char *lease = nvram_safe_get("static_leases");
			char *leasebuf = (char *)malloc(strlen(lease) + 1);
			char *cp = leasebuf;

			strcpy(leasebuf, lease);
			for (i = 0; i < leasenum; i++) {
				char *mac = strsep(&leasebuf, "=");
				char *host = strsep(&leasebuf, "=");
				char *ip = strsep(&leasebuf, "=");
				char *time = strsep(&leasebuf, " ");

				if (mac == NULL || host == NULL || ip == NULL)
					continue;
				if (!time || strlen(time) == 0)
					fprintf(fp,
						"dhcp-host=%s,%s,%s,infinite\n",
						mac, host, ip);
				else
					fprintf(fp, "dhcp-host=%s,%s,%s,%sm\n",
						mac, host, ip, time);

				addHost(host, ip);
			}
			free(cp);
		}
	}
	/* stop dns rebinding for private addresses */
	if (nvram_match("dnsmasq_no_dns_rebind", "1")) {
		fprintf(fp, "stop-dns-rebind\n");
	}
	/*
	 * Additional options 
	 */
	if (nvram_invmatch("dnsmasq_options", "")) {
		fwritenvram("dnsmasq_options", fp);
	}
	fclose(fp);

	dns_to_resolv();

	chmod("/etc/lease_update.sh", 0700);
	ret = eval("dnsmasq", "--conf-file=/tmp/dnsmasq.conf");
	dd_syslog(LOG_INFO, "dnsmasq : dnsmasq daemon successfully started\n");

	cprintf("done\n");
	return;
}