From c48401e7f5fb02123cdaf58035c08534b73d6597 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 2 Mar 2016 07:01:25 +0545 Subject: Add code to handle DHCP leases in multiple pools 1) Add code from RELENG_2_2 https://github.com/pfsense/pfsense/commit/cf3aff59edfa4b101d69ddd694a59fdc580d2299 that checks for leases that are in pools other than the ordinary first pool. This code has been missed from the bootstrap conversion. 2) Make the leases per interface/pool work properly. The counter $dlsc did not get incremented much anyway, because of break statements in the previous code. I have made it key $dhcp_leases_subnet_counter by the interface and starting IP of the pool - this is a unique identifier of each pool, so the counter for it can be reliably incremented as leases are considered in any order. 3) Sort $dhcp_leases_subnet_counter before displaying the counter data - that way the displayed data is always nicely ordered by interface name and then increasing pool start IP, regardless of the order that the leases happened to be found. --- src/usr/local/www/status_dhcp_leases.php | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/usr/local/www/status_dhcp_leases.php') diff --git a/src/usr/local/www/status_dhcp_leases.php b/src/usr/local/www/status_dhcp_leases.php index 4d0a5c0..48d7b33 100644 --- a/src/usr/local/www/status_dhcp_leases.php +++ b/src/usr/local/www/status_dhcp_leases.php @@ -406,21 +406,36 @@ foreach ($leases as $data): } if ($data['act'] != $static_string) { - $dlsc=0; foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) { if (!is_array($dhcpifconf['range'])) { continue; } if (is_inrange_v4($data['ip'], $dhcpifconf['range']['from'], $dhcpifconf['range']['to'])) { $data['if'] = $dhcpif; - $dhcp_leases_subnet_counter[$dlsc]['dhcpif'] = $dhcpif; - $dhcp_leases_subnet_counter[$dlsc]['from'] = $dhcpifconf['range']['from']; - $dhcp_leases_subnet_counter[$dlsc]['to'] = $dhcpifconf['range']['to']; - $dhcp_leases_subnet_counter[$dlsc]['count'] = $dhcp_leases_subnet_counter[$dlsc]['count']+1; + $dlskey = $dhcpif . "-" . $dhcpifconf['range']['from']; + $dhcp_leases_subnet_counter[$dlskey]['dhcpif'] = $dhcpif; + $dhcp_leases_subnet_counter[$dlskey]['from'] = $dhcpifconf['range']['from']; + $dhcp_leases_subnet_counter[$dlskey]['to'] = $dhcpifconf['range']['to']; + $dhcp_leases_subnet_counter[$dlskey]['count'] += 1; break; } - $dlsc++; + // Check if the IP is in the range of any DHCP pools + if (is_array($dhcpifconf['pool'])) { + foreach ($dhcpifconf['pool'] as $dhcppool) { + if (is_array($dhcppool['range'])) { + if (is_inrange_v4($data['ip'], $dhcppool['range']['from'], $dhcppool['range']['to'])) { + $data['if'] = $dhcpif; + $dlskey = $dhcpif . "-" . $dhcppool['range']['from']; + $dhcp_leases_subnet_counter[$dlskey]['dhcpif'] = $dhcpif; + $dhcp_leases_subnet_counter[$dlskey]['from'] = $dhcppool['range']['from']; + $dhcp_leases_subnet_counter[$dlskey]['to'] = $dhcppool['range']['to']; + $dhcp_leases_subnet_counter[$dlskey]['count'] += 1; + break 2; + } + } + } + } } } @@ -483,7 +498,10 @@ foreach ($leases as $data): - + -- cgit v1.1