%PDF- %PDF-
Direktori : /var/www_old/ |
Current File : //var/www_old/nfdb.php__b81eaf3 |
<?php ob_start(); 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); } $my_ips = array("77.93.194.60", "77.93.194.61", "77.93.194.62", "77.93.194.63", "77.93.194.64", "77.93.194.65", "77.93.194.66", "77.93.194.67", "2a01:430:12b::2"); $tzac = getmicrotime(); //$gi = geoip_open("/usr/share/GeoIP/GeoIP.dat",GEOIP_STANDARD); // Nacteni DNS cache $dns = array(); /*if(file_exists("dnscache.csv")) { $f = fopen("dnscache.csv", "r"); while(!feof($f)) { $line = fgets($f); list($ip, $hostname) = explode(';', trim($line)); $dns[$ip] = $hostname; } fclose($f); }*/ $spojeni = mysql_connect("localhost", "waritko", "blade666"); mysql_select_db("waritko_utils", $spojeni); $res = mysql_query("select ip, hostname from dnscache order by ip"); while($r = mysql_fetch_array($res)) { $dns[$r[0]] = $r[1]; } $filter = ""; if($_GET['what'] == 'TS') { $filter = "\"port 8767 or port 9987 or port 9988 or port 9989\""; } if($_GET['what'] == 'Mumble') { $filter = "\"port 7300 or port 7301 or port 7302\""; } if($_GET['what'] == 'Minecraft') { $filter = "\"port 25565\""; } if($_GET['what'] == 'WoW') { $filter = "\"port 3724 or port 8085\""; } if($_GET['what'] == 'Mail') { $filter = "\"port 143 or port 25\""; } if(isset($_GET['filter'])) { $filter = "\"".$_GET['filter']."\""; } $vys = array(); $zeme = array(); $datepart = date("Y/m/d/"); $f = popen("nfdump -R /home/waritko/nfdevbox/$datepart -o csv -s ip/bytes -n 0 $filter", "r"); $i = 0; // Preskoceni radku co nechceme cist while(!feof($f)) { $line = fgets($f); if(trim($line) == "") break; // Konec dat if($i > 0 || isset($_GET['filter'])) { $res = explode(',', $line); $vys[$i][0] = $res[4]; 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]; $nip = $vys[$i][0]; $nhost = $vys[$i][1]; mysql_query("insert into dnscache(`ip`, `hostname`) values('$nip', '$nhost')"); } } $vys[$i][2] = geoip_country_name_by_name($vys[$i][0]); $vys[$i][3] = geoip_country_name_by_name($vys[$i][0]); $vys[$i][4] = fsize($res[9]); $vys[$i][5] = $line; $zeme[$vys[$i][3]] += $res[9]; } $i++; } fclose($f); // Vypis DNS cache /*$f = fopen("dnscache.csv", "w"); reset($dns); while(list($ip, $hostname) = each($dns)) { fputs($f, "$ip;$hostname\n"); } fclose($f);*/ mysql_close($spojeni); $tkon = getmicrotime(); $time = $tkon-$tzac; $time = sprintf("%01.4f", $time); echo "Cas potrebny na zpracovani: $time sekund\n\n"; ?> <html> <head> <title>Traffic analysis</title> </head> <body> <h1>Data by host</h1> <table style="min-width: 900px; max-width: 1800px;" 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++; $my = ""; if(in_array($v[0], $my_ips)) $my = "style=\"font-weight: bold; background-color: green;\""; $barva = $i % 2 ? "#FFF8DC" : "#FFA07A"; echo " <tr bgcolor=\"$barva\" $my> <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> <!-- $v[5] --> </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); $i = 0; while(list($country, $data) = each($zeme)) { $data = fsize($data); $i++; $barva = $i % 2 ? "#FFF8DC" : "#FFA07A"; echo " <tr bgcolor=\"$barva\"> <td width=\"60%\">$country</td> <td width=\"40%\">$data</td> </tr>\n"; } ?> </table> </body> </html> <?php $ret = ob_get_clean(); // Gzip/Deflate/Bzip2 compression if(stristr($_SERVER["HTTP_ACCEPT_ENCODING"], "bzip2")) { $ret = bzcompress($ret, 9); header("Content-Encoding: bzip2"); } elseif(stristr($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip")) { $ret = gzencode($ret, 9); header("Content-Encoding: gzip"); } elseif (stristr($_SERVER["HTTP_ACCEPT_ENCODING"], "deflate")) { $ret = gzdeflate($ret, 9); header("Content-Encoding: deflate"); } header("Content-length: ".strlen($ret)); echo $ret;