index.php (6184B)
1 <?php 2 include("include.php"); 3 ?> 4 <html> 5 <center> 6 <img src=logo.gif> 7 <?php 8 9 $sensor_name = 'default'; 10 11 // Get variables from url 12 13 if (isset($_GET['interval']) && $_GET['interval'] != "none") 14 $interval = $_GET['interval']; 15 16 if (isset($_GET['timestamp']) && $_GET['timestamp'] != "none") 17 $timestamp = $_GET['timestamp']; 18 19 if (isset($_GET['subnet']) && $_GET['subnet'] != "none") 20 $subnet = $_GET['subnet']; 21 22 if (isset($_GET['limit']) && $_GET['limit'] != "none") 23 $limit = $_GET['limit']; 24 25 26 $db = ConnectDb(); 27 ?> 28 <FORM name="navigation" method="get"> 29 <table width=100% cellspacing=0 cellpadding=5 border=1> 30 <tr> 31 <td><SELECT name="interval"> 32 <OPTION value="none">--Select An Interval-- 33 <OPTION value=<?php echo INT_DAILY?> <?php echo $interval==INT_DAILY?"SELECTED":""?>>Daily 34 <OPTION value=<?php echo INT_WEEKLY?> <?php echo $interval==INT_WEEKLY?"SELECTED":""?>>Weekly 35 <OPTION value=<?php echo INT_MONTHLY?> <?php echo $interval==INT_MONTHLY?"SELECTED":""?>>Monthly 36 <OPTION value=<?php echo INT_YEARLY?> <?php echo $interval==INT_YEARLY?"SELECTED":""?>>Yearly 37 <OPTION value=<?php echo 24*60*60?> <?php echo $interval==24*60*60?"SELECTED":""?>>24hrs 38 <OPTION value=<?php echo 30*24*60*60?> <?php echo $interval==30*24*60*60?"SELECTED":""?>>30days 39 </select> 40 41 <td><SELECT name="limit"> 42 <OPTION value="none">--How Many Results-- 43 <OPTION value=20 <?php echo $limit==20?"SELECTED":""?>>20 44 <OPTION value=50 <?php echo $limit==50?"SELECTED":""?>>50 45 <OPTION value=100 <?php echo $limit==100?"SELECTED":""?>>100 46 <OPTION value=all <?php echo $limit=="all"?"SELECTED":""?>>All 47 </select> 48 49 <td>Subnet Filter:<input name=subnet value="<?php echo isset($subnet)?$subnet:"0.0.0.0/0"?>"> 50 <input type=submit value="Go"> 51 </table> 52 </FORM> 53 <?php 54 // Set defaults 55 if (!isset($interval)) 56 $interval = DFLT_INTERVAL; 57 58 if (!isset($timestamp)) 59 $timestamp = time() - $interval + (0.05*$interval); 60 61 if (!isset($limit)) 62 $limit = 20; 63 64 // Validation 65 if (!isset($sensor_name)) 66 exit(0); 67 68 // Print Title 69 70 if (isset($limit)) 71 echo "<h2>Top $limit - $sensor_name</h2>"; 72 else 73 echo "<h2>All Records - $sensor_name</h2>"; 74 75 // Sqlize the incomming variables 76 if (isset($subnet)) { 77 $sql_subnet = prepare_sql_subnet($subnet); 78 } 79 80 // Sql Statement 81 $sql = "select tx.ip, rx.scale as rxscale, tx.scale as txscale, tx.total+rx.total as total, tx.total as sent, 82 rx.total as received, tx.tcp+rx.tcp as tcp, tx.udp+rx.udp as udp, 83 tx.icmp+rx.icmp as icmp, tx.http+rx.http as http, 84 tx.p2p+rx.p2p as p2p, tx.ftp+rx.ftp as ftp 85 from 86 87 (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, 88 sum(http) as http, sum(p2p) as p2p, sum(ftp) as ftp 89 from sensors, bd_tx_log 90 where sensor_name = '$sensor_name' 91 and sensors.sensor_id = bd_tx_log.sensor_id 92 $sql_subnet 93 and timestamp > $timestamp and timestamp < ".($timestamp+$interval)." 94 group by ip) as tx, 95 96 (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, 97 sum(http) as http, sum(p2p) as p2p, sum(ftp) as ftp 98 from sensors, bd_rx_log 99 where sensor_name = '$sensor_name' 100 and sensors.sensor_id = bd_rx_log.sensor_id 101 $sql_subnet 102 and timestamp > $timestamp and timestamp < ".($timestamp+$interval)." 103 group by ip) as rx 104 105 where tx.ip = rx.ip 106 order by total desc;"; 107 108 //echo "</center><pre>$sql</pre><center>"; error_log($sql); 109 $pdoResult = $db->query($sql); 110 $result = $pdoResult->fetchAll(); 111 $db = NULL; 112 $num_rows = count($result); 113 if ($limit == "all") 114 $limit = $num_rows; 115 116 echo "<table width=100% border=1 cellspacing=0><tr><td>Ip<td>Name<td>Total<td>Sent<td>Received<td>tcp<td>udp<td>icmp<td>http<td>smtp<td>ftp"; 117 118 if (!isset($subnet)) // Set this now for total graphs 119 $subnet = "0.0.0.0/0"; 120 121 // Output Total Line 122 echo "<TR><TD><a href=Total>Total</a><TD>$subnet"; 123 foreach (array("total", "sent", "received", "tcp", "udp", "icmp", "http", "p2p", "ftp") as $key) 124 { 125 for($Counter=0, $Total = 0; $Counter < $num_rows; $Counter++) 126 { 127 $r = $result[$Counter]; 128 $Total += $r[$key]; 129 } 130 echo fmtb($Total); 131 } 132 echo "\n"; 133 134 // Output Other Lines 135 for($Counter=0; $Counter < $num_rows && $Counter < $limit; $Counter++) 136 { 137 $r = $result[$Counter]; 138 $r['ip'] = long2ip($r['ip']); 139 echo "<tr><td><a href=#".$r['ip'].">"; 140 echo $r['ip']."<td>".gethostbyaddr($r['ip']); 141 echo "</a>"; 142 echo fmtb($r['total']).fmtb($r['sent']).fmtb($r['received']). 143 fmtb($r['tcp']).fmtb($r['udp']).fmtb($r['icmp']).fmtb($r['http']). 144 fmtb($r['p2p']).fmtb($r['ftp'])."\n"; 145 } 146 echo "</table></center>"; 147 148 // Output Total Graph 149 for($Counter=0, $Total = 0; $Counter < $num_rows; $Counter++) 150 { 151 $r = $result[$Counter]; 152 $scale = max($r['txscale'], $scale); 153 $scale = max($r['rxscale'], $scale); 154 } 155 156 if ($subnet == "0.0.0.0/0") 157 $total_table = "bd_tx_total_log"; 158 else 159 $total_table = "bd_tx_log"; 160 echo "<a name=Total><h3><a href=details.php?sensor_name=$sensor_name&ip=$subnet>"; 161 echo "Total - Total of $subnet</h3>"; 162 echo "</a>"; 163 echo "Send:<br><img src=graph.php?ip=$subnet&interval=$interval&sensor_name=".$sensor_name."&table=$total_table><br>"; 164 echo "<img src=legend.gif><br>\n"; 165 if ($subnet == "0.0.0.0/0") 166 $total_table = "bd_rx_total_log"; 167 else 168 $total_table = "bd_rx_log"; 169 echo "Receive:<br><img src=graph.php?ip=$subnet&interval=$interval&sensor_name=".$sensor_name."&table=$total_table><br>"; 170 echo "<img src=legend.gif><br>\n"; 171 172 173 // Output Other Graphs 174 for($Counter=0; $Counter < $num_rows && $Counter < $limit; $Counter++) 175 { 176 $r = $result[$Counter]; 177 $r['ip'] = long2ip($r['ip']); 178 echo "<a name=".$r['ip']."><h3><a href=details.php?sensor_name=$sensor_name&ip=".$r['ip'].">"; 179 if ($r['ip'] == "0.0.0.0") 180 echo "Total - Total of all subnets</h3>"; 181 else 182 echo $r['ip']." - ".gethostbyaddr($r['ip'])."</h3>"; 183 echo "</a>"; 184 echo "Send:<br><img src=graph.php?ip=".$r['ip']."&interval=$interval&sensor_name=".$sensor_name."&table=bd_tx_log&yscale=".(max($r['txscale'], $r['rxscale']))."><br>"; 185 echo "<img src=legend.gif><br>\n"; 186 echo "Receive:<br><img src=graph.php?ip=".$r['ip']."&interval=$interval&sensor_name=".$sensor_name."&table=bd_rx_log&yscale=".(max($r['txscale'], $r['rxscale']))."><br>"; 187 echo "<img src=legend.gif><br>\n"; 188 } 189 190 include('footer.php');