diff options
author | Phil Davis <phil.davis@inf.org> | 2015-06-22 13:05:35 +0545 |
---|---|---|
committer | Phil Davis <phil.davis@inf.org> | 2015-06-22 13:05:35 +0545 |
commit | be253f60af60127f9a1888838cb275be3db90e2a (patch) | |
tree | 605e00308d8c0f0471ef34186ddc2a953b9d3406 /usr/local | |
parent | a7a064f4e523cc94d8570075e8b3b9a9220da3a3 (diff) | |
download | pfsense-be253f60af60127f9a1888838cb275be3db90e2a.zip pfsense-be253f60af60127f9a1888838cb275be3db90e2a.tar.gz |
Add DNS host override descriptions
since we can sometimes provide a useful description from that config
data also.
Fill the $iplookup array with host or FQDN data if description is blank
or host or FQDN was requested. Then we can use $iplookup in all cases
where we have local data. It simplifies some logic a bit.
Diffstat (limited to 'usr/local')
-rwxr-xr-x | usr/local/www/bandwidth_by_ip.php | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/usr/local/www/bandwidth_by_ip.php b/usr/local/www/bandwidth_by_ip.php index 772423f..d50b9e4 100755 --- a/usr/local/www/bandwidth_by_ip.php +++ b/usr/local/www/bandwidth_by_ip.php @@ -1,8 +1,6 @@ <?php /* - * To change this template, choose Tools | Templates - * and open the template in the editor. - * + bandwidth_by_ip.php */ /* @@ -57,17 +55,40 @@ if ($sort == "out") { // get the desired format for displaying the host name or IP $hostipformat = $_GET['hostipformat']; $iplookup = array(); -// If hostname, description or FQDN is requested then load the DHCP static mappings into an array keyed by IP address. +// If hostname, description or FQDN is requested then load the locally-known IP address - host/description mappings into an array keyed by IP address. if ($hostipformat != "") { if (is_array($config['dhcpd'])) { + // Build an array of static-mapped DHCP entries keyed by IP address. foreach ($config['dhcpd'] as $ifdata) { if (is_array($ifdata['staticmap'])) { foreach ($ifdata['staticmap'] as $hostent) { if (($hostent['ipaddr'] != "") && ($hostent['hostname'] != "")) { - if ($hostipformat == "descr") { + if ($hostipformat == "descr" && $hostent['descr'] != "") { $iplookup[$hostent['ipaddr']] = $hostent['descr']; } else { $iplookup[$hostent['ipaddr']] = $hostent['hostname']; + if ($hostipformat == "fqdn") { + $iplookup[$hostent['ipaddr']] .= "." . $config['system']['domain']; + } + } + } + } + } + } + } + // Add any DNS host override data keyed by IP address. + foreach (array('dnsmasq', 'unbound') as $dns_type) { + if (isset($config[$dns_type]['enable'])) { + if (is_array($config[$dns_type]['hosts'])) { + foreach ($config[$dns_type]['hosts'] as $hostent) { + if (($hostent['ip'] != "") && ($hostent['host'] != "")) { + if ($hostipformat == "descr" && $hostent['descr'] != "") { + $iplookup[$hostent['ip']] = $hostent['descr']; + } else { + $iplookup[$hostent['ip']] = $hostent['host']; + if ($hostipformat == "fqdn") { + $iplookup[$hostent['ip']] .= "." . $hostent['domain']; + } } } } @@ -94,19 +115,14 @@ for ($x=2; $x<12; $x++) { // pass back just the raw IP address $addrdata = $infoarray[0]; } else { - // $hostipformat is one of "hostname", "descr" or "fqdn" - we want a name if we can get it. - if ((($hostipformat == "hostname") || ($hostipformat == "descr")) && ($iplookup[$infoarray[0]] != "")) { - // User asked for hostname or description and we have a static mapping entry, so use it. + // $hostipformat is one of "hostname", "descr" or "fqdn" - we want a text representation if we can get it. + if ($iplookup[$infoarray[0]] != "") { + // We have a local entry, so use it. $addrdata = $iplookup[$infoarray[0]]; } else { // Try to reverse lookup the IP address. $addrdata = gethostbyaddr($infoarray[0]); - if ($addrdata == $infoarray[0]) { - // Reverse lookup did not find a name, last gasp try the static mapping array - if ($iplookup[$infoarray[0]] != "") { - $addrdata = $iplookup[$infoarray[0]]; - } - } else { + if ($addrdata != $infoarray[0]) { // Reverse lookup returned something other than the IP address (FQDN, we hope!) if ($hostipformat != "fqdn") { // The user does not want the whole FQDN, so only pass back the first part of the name. |