DB Error, unknown database type"; exit; } if (!$result) { echo "
Collecting data...
"; exit; } ?>
Subnet Filter:
No such sensor\n"; exit(0); } // Print Title if (isset($limit)) echo "

Top $limit - $sensor_name

"; else echo "

All Records - $sensor_name

"; if(isset($last)) echo "Last connection: " . $last . "
\n"; // Sqlize the incomming variables if($dbtype == DB_PGSQL) { $sql_subnet = "and ip <<= '$subnet'"; } else if($dbtype == DB_MYSQL) { $p = parse_addr($subnet); if($p["mask"] == ip2long("255.255.255.255")) { $sql_subnet = "and ip = " .sprintf("%u", $p["ip"]); } else if($p["mask"] == 0) { $sql_subnet = ""; } else { $net = $p["ip"] & $p["mask"]; $bcast = $net | ~$p["mask"]; $sql_subnet = "and ip between ".sprintf("%u", $net)." and ".sprintf("%u",$bcast); } } // Sql Statement $pg_sql = "select tx.ip, rx.scale as rxscale, tx.scale as txscale, tx.total+rx.total as total, tx.total as sent, rx.total as received, tx.tcp+rx.tcp as tcp, tx.udp+rx.udp as udp, tx.icmp+rx.icmp as icmp, tx.http+rx.http as http, tx.p2p+rx.p2p as p2p, tx.ftp+rx.ftp as ftp from (SELECT ip, max(total/sample_duration)*8 as scale, sum(total) as total, sum(tcp) as tcp, sum(udp) as udp, sum(icmp) as icmp, sum(http) as http, sum(p2p) as p2p, sum(ftp) as ftp from bd_tx_log where sensor_id = $sensor_id $sql_subnet and timestamp > $timestamp::abstime and timestamp < ".($timestamp+$interval)."::abstime group by ip) as tx, (SELECT ip, max(total/sample_duration)*8 as scale, sum(total) as total, sum(tcp) as tcp, sum(udp) as udp, sum(icmp) as icmp, sum(http) as http, sum(p2p) as p2p, sum(ftp) as ftp from bd_rx_log where sensor_id = $sensor_id $sql_subnet and timestamp > $timestamp::abstime and timestamp < ".($timestamp+$interval)."::abstime group by ip) as rx where tx.ip = rx.ip order by total desc;"; $my_sql = "select inet_ntoa(tx.ip) as ip, rx.scale as rxscale, tx.scale as txscale, tx.total+rx.total as total, tx.total as sent, rx.total as received, tx.tcp+rx.tcp as tcp, tx.udp+rx.udp as udp, tx.icmp+rx.icmp as icmp, tx.http+rx.http as http, tx.p2p+rx.p2p as p2p, tx.ftp+rx.ftp as ftp from (SELECT ip, max(total/sample_duration)*8 as scale, sum(total) as total, sum(tcp) as tcp, sum(udp) as udp, sum(icmp) as icmp, sum(http) as http, sum(p2p) as p2p, sum(ftp) as ftp from bd_tx_log where sensor_id = $sensor_id $sql_subnet and unix_timestamp(timestamp) > $timestamp and unix_timestamp(timestamp) < ".($timestamp+$interval)." group by ip) as tx, (SELECT ip, max(total/sample_duration)*8 as scale, sum(total) as total, sum(tcp) as tcp, sum(udp) as udp, sum(icmp) as icmp, sum(http) as http, sum(p2p) as p2p, sum(ftp) as ftp from bd_rx_log where sensor_id = $sensor_id $sql_subnet and unix_timestamp(timestamp) > $timestamp and unix_timestamp(timestamp) < ".($timestamp+$interval)." group by ip) as rx where tx.ip = rx.ip order by total desc"; //echo "
$my_sql
"; exit(0); if($dbtype == DB_PGSQL) { pg_query("SET sort_mem TO 30000;"); $result = pg_query($pg_sql); } else if($dbtype == DB_MYSQL) $result = mysql_query($my_sql); if($dbtype == DB_PGSQL) pg_query("set sort_mem to default;"); if ($limit == "all") { if($dbtype == DB_PGSQL) $limit = pg_num_rows($result); else if($dbtype == DB_MYSQL) $limit = mysql_num_rows($result); } echo "
IpNameTotalSentReceivedtcpudpicmphttpp2pftp"; if (!isset($subnet)) // Set this now for total graphs $subnet = "0.0.0.0/0"; // Output Total Line echo "
Total$subnet"; foreach (array("total", "sent", "received", "tcp", "udp", "icmp", "http", "p2p", "ftp") as $key) { if($dbtype == DB_PGSQL) { for($Counter=0, $Total = 0; $Counter < pg_num_rows($result); $Counter++) { $r = pg_fetch_array($result, $Counter); $Total += $r[$key]; } } else if($dbtype == DB_MYSQL) { if(mysql_num_rows($result) > 0) mysql_data_seek($result, 0); for($Counter = 0, $Total = 0; $Counter < mysql_num_rows($result); $Counter++) { $r = mysql_fetch_array($result); $Total += $r[$key]; } } echo fmtb($Total); } echo "\n"; // Output Other Lines if($dbtype == DB_PGSQL) { for($Counter=0; $Counter < pg_num_rows($result) && $Counter < $limit; $Counter++) { $r = pg_fetch_array($result, $Counter); echo "
"; echo $r['ip']."".gethostbyaddr($r['ip']); echo ""; echo fmtb($r['total']).fmtb($r['sent']).fmtb($r['received']). fmtb($r['tcp']).fmtb($r['udp']).fmtb($r['icmp']).fmtb($r['http']). fmtb($r['p2p']).fmtb($r['ftp'])."\n"; } } else if($dbtype == DB_MYSQL) { if(mysql_num_rows($result) > 0) mysql_data_seek($result, 0); for($Counter=0; $Counter < mysql_num_rows($result) && $Counter < $limit; $Counter++) { $r = mysql_fetch_array($result); echo "
"; echo $r['ip']."".gethostbyaddr($r['ip']); echo ""; echo fmtb($r['total']).fmtb($r['sent']).fmtb($r['received']). fmtb($r['tcp']).fmtb($r['udp']).fmtb($r['icmp']).fmtb($r['http']). fmtb($r['p2p']).fmtb($r['ftp'])."\n"; } } echo "
"; // Output Total Graph //$scale = 0; //if($dbtype == DB_PGSQL) { // for($Counter=0; $Counter < pg_num_rows($result); $Counter++) { // $r = pg_fetch_array($result, $Counter); // $scale = max($r['txscale'], $scale); // $scale = max($r['rxscale'], $scale); // } //} else if($dbtype == DB_MYSQL) { // if(mysql_num_rows($result) > 0) // mysql_data_seek($result, 0); // for($Counter = 0; $Counter < mysql_num_rows($result); $Counter++) { // $r = mysql_fetch_array($result); // $scale = max($r['txscale'], $scale); // $scale = max($r['rxscale'], $scale); // } //} if ($subnet == "0.0.0.0/0") $total_table = "bd_tx_total_log"; else $total_table = "bd_tx_log"; echo "

"; echo "Total - Total of $subnet

"; echo ""; echo "Send:

"; echo "
\n"; if ($subnet == "0.0.0.0/0" || $subnet == "0/0") $total_table = "bd_rx_total_log"; else $total_table = "bd_rx_log"; echo "Receive:

"; echo "
\n"; // Output Other Graphs if($dbtype == DB_PGSQL) { for($Counter=0; $Counter < pg_num_rows($result) && $Counter < $limit; $Counter++) { $r = pg_fetch_array($result, $Counter); echo "

"; if ($r['ip'] == "0.0.0.0") echo "Total - Total of all subnets

"; else echo $r['ip']." - ".gethostbyaddr($r['ip']).""; echo ""; echo "Send:

"; echo "
\n"; echo "Receive:

"; echo "
\n"; } } else if($dbtype == DB_MYSQL) { if(mysql_num_rows($result) > 0) mysql_data_seek($result, 0); for($Counter=0; $Counter < mysql_num_rows($result) && $Counter < $limit; $Counter++) { $r = mysql_fetch_array($result); echo "

"; if ($r['ip'] == "0.0.0.0") echo "Total - Total of all subnets

"; else echo $r['ip']." - ".gethostbyaddr($r['ip']).""; echo ""; echo "Send:

"; echo "
\n"; echo "Receive:

"; echo "
\n"; } } include('footer.php'); ?>