summaryrefslogtreecommitdiffstats
path: root/usr
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2015-06-12 16:37:53 +0545
committerPhil Davis <phil.davis@inf.org>2015-06-12 16:37:53 +0545
commita7a064f4e523cc94d8570075e8b3b9a9220da3a3 (patch)
tree010927f027608cbe303c766e9206b2e5ac710296 /usr
parent71f29f4424060c68f22b383d6d80f2fd3d21f466 (diff)
downloadpfsense-a7a064f4e523cc94d8570075e8b3b9a9220da3a3.zip
pfsense-a7a064f4e523cc94d8570075e8b3b9a9220da3a3.tar.gz
Add description as a display option on Traffic Graph
This is handy at sites where lots of the LAN clients have static-mapped DHCP IP addresses. Depending on the site host naming conventions, host names can be a bit obtuse - may not tell you where the client device might actually be in the building. We put other useful stuff in the description - "Jane Doe - Reception". This enhancement allows the user of Traffic Graph to select "Description" in the "Display" dropdown. Then, for IP addresses that are static mapped, the description from the config is shown, rather than the host name. When a client device is noticed hogging bandwidth, it is easy to go straight to "Jane Doe - Reception" and ask why they are doing some huge download. Might be useful for for others?
Diffstat (limited to 'usr')
-rwxr-xr-xusr/local/www/bandwidth_by_ip.php42
-rw-r--r--usr/local/www/status_graph.php1
2 files changed, 27 insertions, 16 deletions
diff --git a/usr/local/www/bandwidth_by_ip.php b/usr/local/www/bandwidth_by_ip.php
index c9e8e93..772423f 100755
--- a/usr/local/www/bandwidth_by_ip.php
+++ b/usr/local/www/bandwidth_by_ip.php
@@ -57,16 +57,18 @@ if ($sort == "out") {
// 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 != "") && ((!isset($config['dnsmasq']['enable']) || !isset($config['dnsmasq']['regdhcpstatic'])) ||
- (!isset($config['unbound']['enable']) || !isset($config['unbound']['regdhcpstatic'])))) {
+// If hostname, description or FQDN is requested then load the DHCP static mappings into an array keyed by IP address.
+if ($hostipformat != "") {
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'];
+ if ($hostipformat == "descr") {
+ $iplookup[$hostent['ipaddr']] = $hostent['descr'];
+ } else {
+ $iplookup[$hostent['ipaddr']] = $hostent['hostname'];
+ }
}
}
}
@@ -89,20 +91,28 @@ for ($x=2; $x<12; $x++) {
(($filter == "local") && (ip_in_subnet($infoarray[0], $intsubnet))) ||
(($filter == "remote") && (!ip_in_subnet($infoarray[0], $intsubnet)))) {
if ($hostipformat == "") {
+ // pass back just the raw IP address
$addrdata = $infoarray[0];
} else {
- // $hostipformat is "hostname" or "fqdn"
- $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]];
- }
+ // $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.
+ $addrdata = $iplookup[$infoarray[0]];
} else {
- if ($hostipformat == "hostname") {
- // Only pass back the first part of the name, not the FQDN.
- $name_array = explode(".", $addrdata);
- $addrdata = $name_array[0];
+ // 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 {
+ // 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.
+ $name_array = explode(".", $addrdata);
+ $addrdata = $name_array[0];
+ }
}
}
}
diff --git a/usr/local/www/status_graph.php b/usr/local/www/status_graph.php
index 28d13c1..d5d5253 100644
--- a/usr/local/www/status_graph.php
+++ b/usr/local/www/status_graph.php
@@ -233,6 +233,7 @@ if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enabl
<select id="hostipformat" name="hostipformat" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
<option value="">IP Address</option>
<option value="hostname"<?php if ($curhostipformat == "hostname") echo " selected";?>>Host Name</option>
+ <option value="descr"<?php if ($curhostipformat == "descr") echo " selected=\"selected\"";?>>Description</option>
<option value="fqdn"<?php if ($curhostipformat == "fqdn") echo " selected=\"selected\"";?>>FQDN</option>
</select>
</form>
OpenPOWER on IntegriCloud