1
0

index.php 6.0 KB

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