diff options
author | Phil Davis <phil.davis@world.inf.org> | 2013-03-06 20:47:31 +0545 |
---|---|---|
committer | Phil Davis <phil.davis@world.inf.org> | 2013-03-06 20:47:31 +0545 |
commit | c16f7c5c983a23839d42e00b250da81689848f51 (patch) | |
tree | 2b1cb2aeb338d4bf511362eaeee59b8cf7fa4325 /usr/local/www/bandwidth_by_ip.php | |
parent | 4006a43733a4fcc5fd517670ef4b36eb2db96e7e (diff) | |
download | pfsense-c16f7c5c983a23839d42e00b250da81689848f51.zip pfsense-c16f7c5c983a23839d42e00b250da81689848f51.tar.gz |
Add display by host name to Traffic Graph
Diffstat (limited to 'usr/local/www/bandwidth_by_ip.php')
-rwxr-xr-x | usr/local/www/bandwidth_by_ip.php | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/usr/local/www/bandwidth_by_ip.php b/usr/local/www/bandwidth_by_ip.php index 5c46912..979cffb 100755 --- a/usr/local/www/bandwidth_by_ip.php +++ b/usr/local/www/bandwidth_by_ip.php @@ -35,6 +35,25 @@ if ($sort == "out") else {$sort_method = "-R";} +// get the desired format for displaying the host name or IP +$hostipformat = $_GET['hostipformat']; +$iplookup = array(); +// If hostname display is requested and the DNS forwarder does not already have DHCP static names registered, +// then load the DHCP static mappings into an array keyed by IP address. +if (($hostipformat == "hostname") && (!isset($config['dnsmasq']['regdhcpstatic']))) { + if (is_array($config['dhcpd'])) { + foreach ($config['dhcpd'] as $ifdata) { + if (is_array($ifdata['staticmap'])) { + foreach ($ifdata['staticmap'] as $hostent) { + if (($hostent['ipaddr'] != "") && ($hostent['hostname'] != "")) { + $iplookup[$hostent['ipaddr']] = $hostent['hostname']; + } + } + } + } + } +} + $_grb = exec("/usr/local/bin/rate -i {$real_interface} -nlq 1 -Aba 20 {$sort_method} -c {$intsubnet} | tr \"|\" \" \" | awk '{ printf \"%s:%s:%s:%s:%s\\n\", $1, $2, $4, $6, $8 }'", $listedIPs); $someinfo = false; @@ -46,8 +65,22 @@ for ($x=2; $x<12; $x++){ $emptyinfocounter = 1; if ($bandwidthinfo != "") { $infoarray = explode (":",$bandwidthinfo); - //print IP of host; - echo $infoarray[0] . ";" . $infoarray[1] . ";" . $infoarray[2] . "|"; + if ($hostipformat == "hostname") { + $addrdata = gethostbyaddr($infoarray[0]); + if ($addrdata == $infoarray[0]) { + // gethostbyaddr() gave us back the IP address, so try the static mapping array + if ($iplookup[$infoarray[0]] != "") + $addrdata = $iplookup[$infoarray[0]]; + } else { + // gethostbyaddr() gave an answer. Just pass back the name up to the first "." + $name_array = explode(".", $addrdata); + $addrdata = $name_array[0]; + } + } else { + $addrdata = $infoarray[0]; + } + //print host information; + echo $addrdata . ";" . $infoarray[1] . ";" . $infoarray[2] . "|"; //mark that we collected information $someinfo = true; |