示例#1
0
文件: upnp.c 项目: AllardJ/Tomato
void asp_upnpinfo(int argc, char **argv)
{
	if (nvram_get_int("upnp_enable")) {
		f_write_string("/etc/upnp/info", "", 0, 0);
		if (killall("miniupnpd", SIGUSR2) == 0) {
			f_wait_notexists("/etc/upnp/info", 5);
		}
	
		web_puts("\nmupnp_data = '");
		web_putfile("/etc/upnp/data.info", WOF_JAVASCRIPT);
		web_puts("';\n");
	}
}
示例#2
0
文件: upnp.c 项目: AllardJ/Tomato
void wo_upnp(char *url)
{
	char s[256];
	const char *proto;
	const char *eport;

	if (nvram_get_int("upnp_enable")) {
		if (((proto = webcgi_get("remove_proto")) != NULL) && (*proto) &&
			((eport = webcgi_get("remove_eport")) != NULL) && (*eport)) {
			sprintf(s, "%3s %6s\n", proto, eport);
			f_write_string("/etc/upnp/delete", s, 0, 0);
			if (killall("miniupnpd", SIGUSR2) == 0) {
				f_wait_notexists("/etc/upnp/delete", 5);
			}
		}
	}
	common_redirect();
}
示例#3
0
void asp_devlist(int argc, char **argv)
{
	char *p;
	FILE *f;
	char buf[1024];
	char comma;

	// must be here for easier call via update.cgi. arg is ignored
	asp_arplist(0, NULL);
	asp_wlnoise(0, NULL);

	//

	p = js_string(nvram_safe_get("dhcpd_static"));
	web_printf("dhcpd_static = '%s'.split('>');\n", p ? p : "");
	free(p);

	//

	web_puts("wldev = [");
	comma = ' ';
	foreach_wif(1, &comma, get_wl_clients);
	web_puts("];\n");

	//

	unsigned long expires;
	char mac[32];
	char ip[32];
	char hostname[256];
	char *host;

	web_puts("dhcpd_lease = [");
#ifdef TCONFIG_VLAN
	if ((nvram_match("lan_proto", "dhcp")) || (nvram_match("lan1_proto", "dhcp")) || (nvram_match("lan2_proto", "dhcp")) || (nvram_match("lan3_proto", "dhcp")) ) {
#else
	if (nvram_match("lan_proto", "dhcp")) {
#endif
		f_write("/var/tmp/dhcp/leases.!", NULL, 0, 0, 0666);

		// dump the leases to a file
		if (killall("dnsmasq", SIGUSR2) == 0) {
			// helper in dnsmasq will remove this when it's done
			f_wait_notexists("/var/tmp/dhcp/leases.!", 5);
		}

		if ((f = fopen("/var/tmp/dhcp/leases", "r")) != NULL) {
			comma = ' ';
			while (fgets(buf, sizeof(buf), f)) {
				if (sscanf(buf, "%lu %17s %15s %255s", &expires, mac, ip, hostname) != 4) continue;
				host = js_string((hostname[0] == '*') ? "" : hostname);
				web_printf("%c['%s','%s','%s','%s']", comma,
						(host ? host : ""), ip, mac, ((expires == 0) ? "non-expiring" : reltime(buf, expires)));
				free(host);
				comma = ',';
			}
			fclose(f);
		}
		unlink("/var/tmp/dhcp/leases");
	}
	web_puts("];");
}