%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www_old/
Upload File :
Create Path :
Current File : //var/www_old/jabber_net.php__b81eaf3

<?php
	function int2ip($val)
	{
		$ret = $val % 256;
		$val /= 256;
		$ret = ($val % 256).".$ret";
		$val /= 256;
		$ret = ($val % 256).".$ret";
		$val /= 256;
		$ret = ($val % 256).".$ret";
		return $ret;
	}

	function fsize($size)
	{
		$jedn = array("bytes", "Kbytes", "Mbytes", "Gbytes", "Tbytes", "Pbytes");
		//$size = filesize($name);
		$i = 0;
		while($size > 1023)
		{
			$size /= 1024;
			$i++;
		}
		return sprintf("%0.2f %s", $size, $jedn[$i]);
	}

	function getmicrotime() 
	{
		list($usec,$sec)=explode(" ",microtime()); 
		return ((float)$usec+(float)$sec);
	}

	$tzac = getmicrotime();
	//$gi = geoip_open("/usr/share/GeoIP/GeoIP.dat",GEOIP_STANDARD);

	// Nacteni DNS cache
	$dns = array();
	if(file_exists("dnscache_jabb.csv"))
	{
		$f = fopen("dnscache_jabb.csv", "r");
		while(!feof($f))
		{
			$line = fgets($f);
			list($ip, $hostname) = explode(';', trim($line));
			$dns[$ip] = $hostname;
		}
		fclose($f);
	}

	$fname = date("Y/m");
	//echo $fname;
	//die;
	if(isset($_GET['all'])) $fname = "";
	echo "<!-- nfdump -R /var/log/netflows/$fname -o pipe -s ip/bytes -n 0 \"port 5222 and proto tcp\" -->";
	$f = popen("nfdump -R /var/log/netflows/$fname -o pipe -s ip/bytes -n 0 \"port 5222 and proto tcp\"", "r");
	$vys = array();
	$zeme = array();
	$i = 0; // Preskoceni radku co nechceme cist
	while(!feof($f))
	{
		$line = fgets($f);
		if(trim($line) == "") break; // Konec dat
		if($i > 0)
		{
			$res = explode('|', $line);
			$vys[$i][0] = int2ip($res[9]);
			if($i <= 100)
			{
				if(isset($dns[$vys[$i][0]]))
				{
					$vys[$i][1] = $dns[$vys[$i][0]];
				}
				else
				{
					$vys[$i][1] = gethostbyaddr($vys[$i][0]);
					$dns[$vys[$i][0]] = $vys[$i][1];
				}
			}
			$vys[$i][2] = geoip_country_name_by_name($vys[$i][0]);
			$vys[$i][3] = geoip_country_name_by_name($vys[$i][0]);
			if(trim($vys[$i][2]) == "")
			{
				if(preg_match("/\\.cz$/", $vys[$i][1]))
				{
					$vys[$i][2] = "CZ";
					$vys[$i][3] = "Czech Republic";
				}
			}
			$vys[$i][4] = fsize($res[12]);
			$zeme[$vys[$i][3]] += $res[12];
			if(strstr($vys[$i][1], 'vodafone.cz'))
			{
				$vys[0][1] = 'cust.vodafone.cz';
				$vys[0][2] = "CZ";
				$vys[0][3] = "Czech Republic";
				$vys[0][4] += $res[12];
				$i--;
			}
		}
		$i++;
	}
	fclose($f);
	$vys[0][4] = fsize($vys[0][4]);
	ksort($vys);

	$f = popen("nfdump -R /var/log/netflows/$fname -o pipe -s ip/bytes -n 0 \"port 5269 and proto tcp\"", "r");
	$vys2 = array();
	$i = 0; // Preskoceni radku co nechceme cist
	while(!feof($f))
	{
		$line = fgets($f);
		if(trim($line) == "") break; // Konec dat
		if($i > 0)
		{
			$res = explode('|', $line);
			$vys2[$i][0] = int2ip($res[9]);
			if($i <= 100)
			{
				if(isset($dns[$vys2[$i][0]]))
				{
					$vys2[$i][1] = $dns[$vys2[$i][0]];
				}
				else
				{
					$vys2[$i][1] = gethostbyaddr($vys2[$i][0]);
					$dns[$vys2[$i][0]] = $vys2[$i][1];
				}
			}
			$vys2[$i][2] = geoip_country_name_by_name($vys2[$i][0]);
			$vys2[$i][3] = geoip_country_name_by_name($vys2[$i][0]);
			if(trim($vys2[$i][2]) == "")
			{
				if(preg_match("/\\.cz$/", $vys2[$i][1]))
				{
					$vys2[$i][2] = "CZ";
					$vys2[$i][3] = "Czech Republic";
				}
			}
			$vys2[$i][4] = fsize($res[12]);
			$zeme[$vys2[$i][3]] += $res[12];
		}
		$i++;
	}
	fclose($f);

	// Vypis DNS cache
	$f = fopen("dnscache_jabb.csv", "w");
	reset($dns);
	while(list($ip, $hostname) = each($dns))
	{
		fputs($f, "$ip;$hostname\n");
	}
	fclose($f);

	$tkon = getmicrotime();
        $time = $tkon-$tzac;
	$time = sprintf("%01.4f", $time);
?>
<html>
	<head>
		<title>Traffic analysis</title>
	</head>
	<body>
		<p><?php echo "Cas potrebny na zpracovani: $time sekund\n\n"; ?></p>
		<h1>Client2Server data by host</h1>
		<table width="900" border="1">
			<tr>
				<th width="10%">#</th>
				<th width="20%">IP</th>
				<th width="35%">Domain name</th>
				<th width="15%">Data</th>
				<th width="20%">Country</th>
			</tr>
<?php
	$i = 0;
	foreach($vys as $v)
	{
		$i++;
		echo "			<tr>
				<td width=\"10%\">$i</td>
				<td width=\"20%\">$v[0]</td>
				<td width=\"35%\">$v[1]</td>
				<td width=\"15%\">$v[4]</td>
				<td width=\"20%\">$v[3]</td>
				</tr>\n";
		if($i == 100) break;
	}
?>
		</table>
		<br /><br /><br />
		<h1>Server2Server data by host</h1>
		<table width="900" border="1">
			<tr>
				<th width="10%">#</th>
				<th width="20%">IP</th>
				<th width="35%">Domain name</th>
				<th width="15%">Data</th>
				<th width="20%">Country</th>
			</tr>
<?php
	$i = 0;
	foreach($vys2 as $v)
	{
		$i++;
		echo "			<tr>
				<td width=\"10%\">$i</td>
				<td width=\"20%\">$v[0]</td>
				<td width=\"35%\">$v[1]</td>
				<td width=\"15%\">$v[4]</td>
				<td width=\"20%\">$v[3]</td>
				</tr>\n";
		if($i == 100) break;
	}
?>
		</table>
		<br /><br /><br />
		<h1>Data by country</h1>
		<table width="400" border="1">
			<tr>
				<th width="60%">Country</th>
				<th width="40%">Data</th>
			</tr>
<?php
	arsort($zeme);
	while(list($country, $data) = each($zeme))
	{
		$data = fsize($data);
		echo "			<tr>
				<td width=\"60%\">$country</td>
				<td width=\"40%\">$data</td>
			</tr>\n";
	}
?>
		</table>
	</body>
</html>

Zerion Mini Shell 1.0