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