예제 #1
0
파일: Report.cpp 프로젝트: GUI2BCD/Agent
/**
 * Converts stored data into POST compatible data
 * @return string containing POST data
 */
std::string Report::toPost() {

	std::string data = "&";

	data += "localip=";
	data += getLocalIp();
	data += "&wifi=";
	data += getWifi();
	data += "&traceroute=";
	data += getTraceroute();

	return data;
}
예제 #2
0
int main(int argc, char **argv)
{
	char *dev;
	int oldMonitor, newMonitor;
	u_char packet[4096];
	int pktlen;
	wiviz_cfg cfg;
	int i;
	int defaultHopSeq[] = { 1, 3, 6, 8, 11 };
	int s, one;
	memset(&cfg, 0, sizeof(cfg));
#ifdef HAVE_RT2880
	wl_dev = "ra0";
#elif HAVE_MADWIFI
	wl_dev = nvram_safe_get("wifi_display");
#else
	char tmp[32];
	sprintf(tmp, "%s_ifname", nvram_safe_get("wifi_display"));
	wl_dev = nvram_safe_get(tmp);
#endif
	if (argc > 1)
		if (!strcmp(argv[1], "terminate")) {
#ifdef HAVE_MADWIFI
			// return to original channel
#ifdef HAVE_ATH9K
			if (!is_ath9k(wl_dev))
#endif
			{
				sysprintf("iwconfig %s channel %sM", get_monitor(), nvram_nget("%s_channel", nvram_safe_get("wifi_display")));
				sleep(1);
				sysprintf("ifconfig %s down", get_monitor());
				if (is_ar5008(nvram_safe_get("wifi_display"))) {
					sysprintf("80211n_wlanconfig %s destroy", get_monitor());
				} else {
					sysprintf("wlanconfig %s destroy", get_monitor());
				}
			}
#elif HAVE_RT2880
			nvram_set("wl0_mode", nvram_safe_get("wl0_oldmode"));
			sysprintf("startservice configurewifi");
			if (nvram_match("wl0_mode", "sta") || nvram_match("wl0_mode", "apsta")) {
				sysprintf("startstop wan");
			}
#else
			oldMonitor = 0;
			wl_ioctl(wl_dev, WLC_SET_MONITOR, &oldMonitor, 4);
#endif
			return 0;
		}

	global_cfg = &cfg;
	signal(SIGUSR1, &signal_handler);
	signal(SIGUSR2, &signal_handler);

	printf("Wi-Viz 2 infogathering daemon by Nathan True\n");
	printf("http://wiviz.natetrue.com\n");

	memset(&cfg, 0, sizeof(wiviz_cfg));
	cfg.numHosts = 0;
	cfg.lastKeepAlive = time(NULL);
	cfg.channelHopping = 0;
	cfg.channelDwellTime = 1000;
	cfg.channelHopSeqLen = 5;
	memcpy(cfg.channelHopSeq, defaultHopSeq, sizeof(defaultHopSeq));

#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880)
	wl_ioctl(wl_dev, WLC_GET_MAGIC, &i, 4);
	if (i != WLC_IOCTL_MAGIC) {
		printf("Wireless magic not correct, not querying wl for info %X!=%X\n", i, WLC_IOCTL_MAGIC);
		cfg.readFromWl = 0;
	} else {
		cfg.readFromWl = 1;
		wl_ioctl(wl_dev, WLC_GET_MONITOR, &oldMonitor, 4);
		newMonitor = 1;
		wl_ioctl(wl_dev, WLC_SET_MONITOR, &newMonitor, 4);
	}

#elif HAVE_RT2880
	nvram_set("wl0_oldmode", nvram_safe_get("wl0_mode"));
	nvram_set("wl0_mode", "sta");
	if (!nvram_match("wl0_oldmode", "sta"))
		sysprintf("startservice configurewifi");
	sysprintf("iwconfig ra0 mode monitor");
	cfg.readFromWl = 1;
#else
#ifdef HAVE_ATH9K
	if (!is_ath9k(nvram_safe_get("wifi_display")))
#endif
	{
		if (is_ar5008(nvram_safe_get("wifi_display"))) {
			sysprintf("80211n_wlanconfig %s create wlandev %s wlanmode monitor", get_monitor(), getWifi(nvram_safe_get("wifi_display")));
		} else {
			sysprintf("wlanconfig %s create wlandev %s wlanmode monitor", get_monitor(), getWifi(nvram_safe_get("wifi_display")));
		}
		sysprintf("ifconfig %s up", get_monitor());
	}
	cfg.readFromWl = 1;
#endif
	reloadConfig();

#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880)
	s = openMonitorSocket(get_monitor());	// for testing we use ath0
#else

	if (nvram_match("wifi_display", "wl1"))
		s = openMonitorSocket("prism1");
	else
		s = openMonitorSocket("prism0");
#endif
	if (s == -1)
		return;
	one = 1;
	ioctl(s, FIONBIO, (char *)&one);

	if (cfg.readFromWl) {
		readWL(&cfg);
	}
#ifdef WIVIZ_GPS
	gps_init(&cfg);
#endif

	while (!stop) {
#ifdef WIVIZ_GPS
		gps_tick();
#else
		if (time(NULL) - cfg.lastKeepAlive > 30)
			stop = 1;
#endif
		pktlen = recv(s, packet, 4096, 0);
		if (pktlen <= 0)
			continue;
		dealWithPacket(&cfg, pktlen, packet);
	}

	signal_handler(SIGUSR1);

	if (cfg.channelHopperPID)
		kill(cfg.channelHopperPID, SIGKILL);

#ifndef WIVIZ_GPS
	for (i = 0; i < MAX_HOSTS; i++) {
		print_host(stderr, cfg.hosts + i);
		if (cfg.hosts[i].occupied)
			printf("\n");
		if (cfg.hosts[i].apInfo)
			free(cfg.hosts[i].apInfo);
		if (cfg.hosts[i].staInfo)
			free(cfg.hosts[i].staInfo);
	}
#endif
	close(s);
	return 0;
}