diff options
author | Scott Ullrich <sullrich@sullrich-MacBookPro.geekgod.com> | 2009-06-15 19:06:29 -0400 |
---|---|---|
committer | Scott Ullrich <sullrich@sullrich-MacBookPro.geekgod.com> | 2009-06-15 19:06:53 -0400 |
commit | f0a3b883e64692edea9f8332ee6ba361e28b66f8 (patch) | |
tree | 5940d43866f81cf2e6c0a060d556a18a90937056 /usr/local | |
parent | 2f3446dba97007c6446f6fe8e079c5ef3874fef1 (diff) | |
download | pfsense-f0a3b883e64692edea9f8332ee6ba361e28b66f8.zip pfsense-f0a3b883e64692edea9f8332ee6ba361e28b66f8.tar.gz |
Adding Scott Dale's rate package to system -> traffic graphs. Cool stuff!
Diffstat (limited to 'usr/local')
-rwxr-xr-x | usr/local/www/bandwidth_by_ip.php | 77 | ||||
-rwxr-xr-x | usr/local/www/status_graph.php | 206 |
2 files changed, 275 insertions, 8 deletions
diff --git a/usr/local/www/bandwidth_by_ip.php b/usr/local/www/bandwidth_by_ip.php new file mode 100755 index 0000000..3fd01a6 --- /dev/null +++ b/usr/local/www/bandwidth_by_ip.php @@ -0,0 +1,77 @@ +<?php +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + * + * + * + * + * + */ + +require_once('guiconfig.inc'); +require_once('interfaces.inc'); +require_once('pfsense-utils.inc'); +require_once('util.inc'); + +$listedIPs = ""; + +//get interface IP and break up into an array +$interface = $_GET['if']; +$real_interface = convert_friendly_interface_to_real_interface_name($interface); +$intip = find_interface_ip($real_interface); +$intip = explode (".", $intip); + +//use class A subnet to make sure we capture all traffic on specified interface +$intsubnet = $intip[0] . ".0.0.0/8"; + +exec("rate -i {$real_interface} -nlq 1 -A -c {$intsubnet}", $listedIPs); + +unset($bandwidthinfo); +unset($receivebytesarray); +unset($transmitbytesarray); + +$someinfo = false; +for ($x=2; $x<12; $x++){ + + $bandwidthinfo = $listedIPs[$x]; + + // echo $bandwidthinfo; + $emptyinfocounter = 1; + if ($bandwidthinfo != "") { + $splitinfo = explode ("|",$bandwidthinfo); + $receivebytesarray = explode(" ",$splitinfo[0]); + //print IP of host; + echo $receivebytesarray[0] . ";"; + + //skip empty array elements until first element found with data + while ($receivebytesarray[$emptyinfocounter] == "") + { + $emptyinfocounter++; + } + //print received bytes for host + echo $receivebytesarray[$emptyinfocounter] . ";"; + + $transmitbytesarray = explode(" ",$splitinfo[1]); + + $emptyinfocounter = 1; + + //skip empty array elements until first element found with data + while ($transmitbytesarray[$emptyinfocounter] == "") + { + $emptyinfocounter++; + } + //print transmitted bytes for host + echo $transmitbytesarray[$emptyinfocounter] . "|"; + + //mark that we collected information + $someinfo = true; + } +} + + +//no bandwidth usage found +if ($someinfo == false) + echo "no info"; + +?> diff --git a/usr/local/www/status_graph.php b/usr/local/www/status_graph.php index 2b58bad..12a9fd3 100755 --- a/usr/local/www/status_graph.php +++ b/usr/local/www/status_graph.php @@ -40,17 +40,18 @@ ##|-PRIV + require("guiconfig.inc"); if ($_POST['width']) $width = $_POST['width']; else - $width = "550"; + $width = "100%"; if ($_POST['height']) $height = $_POST['height']; else - $height = "275"; + $height = "200"; if ($_GET['if']) @@ -59,14 +60,104 @@ else $curif = "wan"; $pgtitle = array("Status","Traffic Graph"); + include("head.inc"); ?> <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> + +<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script> +<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script> +<script language="javascript" type="text/javascript"> + +function updateBandwidth(){ + var hostinterface = "<?php echo $curif; ?>"; + bandwidthAjax(hostinterface); +} + +function bandwidthAjax(hostinterface) { + uri = "bandwidth_by_ip.php?if=" + hostinterface; + var opt = { + // Use GET + method: 'get', + asynchronous: true, + // Handle 404 + on404: function(t) { + alert('Error 404: location "' + t.statusText + '" was not found.'); + }, + // Handle other errors + onFailure: function(t) { + alert('Error ' + t.status + ' -- ' + t.statusText); + }, + onSuccess: function(t) { + updateBandwidthHosts(t.responseText); + } + } + new Ajax.Request(uri, opt); +} + +function updateBandwidthHosts(data){ + var hosts_split = data.split("|"); + d = document; + //parse top ten bandwidth abuser hosts + for (var y=0; y<10; y++){ + if (hosts_split[y] != "" && hosts_split[y] != "no info"){ + if (hosts_split[y]) { + hostinfo = hosts_split[y].split(";"); + + //update host ip info + var HostIpID = "hostip" + y; + var hostip = d.getElementById(HostIpID); + hostip.innerHTML = hostinfo[0]; + + //update bandwidth inbound to host + var hostbandwidthInID = "bandwidthin" + y; + var hostbandwidthin = d.getElementById(hostbandwidthInID); + hostbandwidthin.innerHTML = hostinfo[1] + " Bytes/sec"; + + //update bandwidth outbound from host + var hostbandwidthOutID = "bandwidthout" + y; + var hostbandwidthOut = d.getElementById(hostbandwidthOutID); + hostbandwidthOut.innerHTML = hostinfo[2] + " Bytes/sec"; + + //make the row appear if hidden + var rowid = "host" + y; + textlink = d.getElementById(rowid); + if (textlink.style.display == "none"){ + //hide rows that contain no data + Effect.Appear(rowid, {duration:1}); + } + } + } + else + { + var rowid = "host" + y; + textlink = d.getElementById(rowid); + if (textlink.style.display != "none"){ + //hide rows that contain no data + Effect.Fade(rowid, {duration:2}); + } + } + } + + setTimeout('updateBandwidth()', 3000); +} + + +</script> + <?php include("fbegin.inc"); ?> <?php -$ifdescrs = get_configured_interface_with_descr(); +$ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN'); + +for($j = 1; isset($config['interfaces']['opt' . $j]); $j++) { + if(isset($config['interfaces']['opt' . $j]['enable'])) + $ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr']; +} +if((isset($config['ipsec']['enable'])) || (isset($config['ipsec']['mobileclients']['enable']))) { + $ifdescrs['ipsec'] = "IPSEC"; +} /* link the ipsec interface magically */ if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable'])) @@ -89,13 +180,112 @@ foreach ($ifdescrs as $ifn => $ifd) { <p><form method="post" action="status_graph.php"> </form> <p> -<div align="center"> - <object data="graph.php?ifnum=<?=$curif;?>&ifname=<?=rawurlencode($ifdescrs[$curif]);?>" type="image/svg+xml" width="550" height="275"> - <param name="src" value="graph.php?ifnum=<?=$curif;?>&ifname=<?=rawurlencode($ifdescrs[$curif]);?>" /> - Your browser does not support the type SVG! You need to either use Firefox or download the Adobe SVG plugin. - </object> +<div> + <div class="widgetdiv" style="padding: 5px; float:left; width:46%"> + <object data="graph.php?ifnum=<?=$curif;?>&ifname=<?=rawurlencode($ifdescrs[$curif]);?>" type="image/svg+xml" width="<?=$width;?>" height="<?=$height;?>"> + <param name="src" value="graph.php?ifnum=<?=$curif;?>&ifname=<?=rawurlencode($ifdescrs[$curif]);?>" /> + Your browser does not support the type SVG! You need to either use Firefox or download the Adobe SVG plugin. + </object> + </div> + <div class="widgetdiv" style="padding: 5px; float:right; width:48%"> + <table width="100%" border="0" cellspacing="0" cellpadding="0"> + <tr> + <td class="listtopic" valign="top">Host IP</td> + <td class="listtopic" valign="top">Bandwidth In</td> + <td class="listtopic" valign="top">Bandwidth Out</td> + </tr> + <tr id="host0" style="display:none"> + <td id="hostip0" class="vncell"> + </td> + <td id="bandwidthin0" class="listr"> + </td> + <td id="bandwidthout0" class="listr"> + </td> + </tr> + <tr id="host1" style="display:none"> + <td id="hostip1" class="vncell"> + </td> + <td id="bandwidthin1" class="listr"> + </td> + <td id="bandwidthout1" class="listr"> + </td> + </tr> + <tr id="host2" style="display:none"> + <td id="hostip2" class="vncell"> + </td> + <td id="bandwidthin2" class="listr"> + </td> + <td id="bandwidthout2" class="listr"> + </td> + </tr> + <tr id="host3" style="display:none"> + <td id="hostip3" class="vncell"> + </td> + <td id="bandwidthin3" class="listr"> + </td> + <td id="bandwidthout3" class="listr"> + </td> + </tr> + <tr id="host4" style="display:none"> + <td id="hostip4" class="vncell"> + </td> + <td id="bandwidthin4" class="listr"> + </td> + <td id="bandwidthout4" class="listr"> + </td> + </tr> + <tr id="host5" style="display:none"> + <td id="hostip5" class="vncell"> + </td> + <td id="bandwidthin5" class="listr"> + </td> + <td id="bandwidthout5" class="listr"> + </td> + </tr> + <tr id="host6" style="display:none"> + <td id="hostip6" class="vncell"> + </td> + <td id="bandwidthin6" class="listr"> + </td> + <td id="bandwidthout6" class="listr"> + </td> + </tr> + <tr id="host7" style="display:none"> + <td id="hostip7" class="vncell"> + </td> + <td id="bandwidthin7" class="listr"> + </td> + <td id="bandwidthout7" class="listr"> + </td> + </tr> + <tr id="host8" style="display:none"> + <td id="hostip8" class="vncell"> + </td> + <td id="bandwidthin8" class="listr"> + </td> + <td id="bandwidthout8" class="listr"> + </td> + </tr> + <tr id="host9" style="display:none"> + <td id="hostip9" class="vncell"> + </td> + <td id="bandwidthin9" class="listr"> + </td> + <td id="bandwidthout9" class="listr"> + </td> + </tr> + </table> + </div> </div> <?php include("fend.inc"); ?> + +<script type="text/javascript"> +window.onload = function(in_event) + { + updateBandwidth(); + } + +</script> </body> </html> |