You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
6.6 KiB

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