"Fossies" - the Fresh Open Source Software Archive

Member "bandwidthd-2.0.1/phphtdocs/index.php" (8 Jan 2005, 6550 Bytes) of package /linux/privat/old/bandwidthd-2.0.1.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "index.php" see the Fossies "Dox" file reference documentation.

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