From f6bda83c782a51e77fb86e647547eb8176c90e7d Mon Sep 17 00:00:00 2001 From: jim-p Date: Fri, 13 Apr 2012 15:00:40 -0400 Subject: Show delegated prefixes on the DHCPv6 Leases display. --- usr/local/www/status_dhcpv6_leases.php | 192 +++++++++++++++++++++++---------- 1 file changed, 138 insertions(+), 54 deletions(-) (limited to 'usr/local/www') diff --git a/usr/local/www/status_dhcpv6_leases.php b/usr/local/www/status_dhcpv6_leases.php index 2f2696d..fc77f27 100644 --- a/usr/local/www/status_dhcpv6_leases.php +++ b/usr/local/www/status_dhcpv6_leases.php @@ -96,22 +96,22 @@ function leasecmp($a, $b) { } function adjust_gmt($dt) { - global $config; + global $config; $dhcpdv6 = $config['dhcpdv6']; foreach ($dhcpdv6 as $dhcpv6leaseinlocaltime) { $dhcpv6leaseinlocaltime = $dhcpv6leaseinlocaltime['dhcpv6leaseinlocaltime']; - if ($dhcpv6leaseinlocaltime == "yes") + if ($dhcpv6leaseinlocaltime == "yes") break; } - $timezone = $config['system']['timezone']; + $timezone = $config['system']['timezone']; $ts = strtotime($dt . " GMT"); if ($dhcpv6leaseinlocaltime == "yes") { - $this_tz = new DateTimeZone($timezone); - $dhcp_lt = new DateTime(strftime("%I:%M:%S%p", $ts), $this_tz); + $this_tz = new DateTimeZone($timezone); + $dhcp_lt = new DateTime(strftime("%I:%M:%S%p", $ts), $this_tz); $offset = $this_tz->getOffset($dhcp_lt); $ts = $ts + $offset; return strftime("%Y/%m/%d %I:%M:%S%p", $ts); - } + } else return strftime("%Y/%m/%d %H:%M:%S", $ts); } @@ -154,7 +154,7 @@ $cleanpattern = "'{ gsub(\"^#.*\", \"\");} { gsub(\"^server-duid.*\", \"\");} { $splitpattern = "'BEGIN { RS=\"}\";} {for (i=1; i<=NF; i++) printf \"%s \", \$i; printf \"}\\n\";}'"; /* stuff the leases file in a proper format into a array by line */ -exec("/bin/cat {$leasesfile} | {$awk} {$cleanpattern} | {$awk} {$splitpattern} | /usr/bin/grep '^ia-na'", $leases_content); +exec("/bin/cat {$leasesfile} | {$awk} {$cleanpattern} | {$awk} {$splitpattern} | /usr/bin/grep '^ia-.. '", $leases_content); $leases_count = count($leases_content); exec("/usr/sbin/ndp -an", $rawdata); $ndpdata = array(); @@ -171,19 +171,22 @@ foreach ($rawdata as $line) { $pools = array(); $leases = array(); +$prefixes = array(); +$mappings = array(); $i = 0; $l = 0; $p = 0; // Put everything together again while($i < $leases_count) { + $entry = array(); /* split the line by space */ $duid_split = array(); - preg_match('/ia-na "(.*)" { (.*)/ ', $leases_content[$i], $duid_split); + preg_match('/ia-.. "(.*)" { (.*)/ ', $leases_content[$i], $duid_split); if (!empty($duid_split[1])) { $iaid_duid = parse_duid($duid_split[1]); - $leases[$l]['iaid'] = hexdec(implode("", array_reverse($iaid_duid[0]))); - $leases[$l]['duid'] = implode(":", $iaid_duid[1]); + $entry['iaid'] = hexdec(implode("", array_reverse($iaid_duid[0]))); + $entry['duid'] = implode(":", $iaid_duid[1]); $data = explode(" ", $duid_split[2]); } else { $data = explode(" ", $leases_content[$i]); @@ -209,7 +212,11 @@ while($i < $leases_count) { $p++; $i++; continue 3; + case "ia-pd": + $is_prefix = true; case "ia-na": + $entry['iaid'] = $tmp_iaid; + $entry['duid'] = $tmp_duid; if ($data[$f+1][0] == '"') { $duid = ""; /* FIXME: This needs a safety belt to prevent an infinite loop */ @@ -217,31 +224,37 @@ while($i < $leases_count) { $duid .= " " . $data[$f+1]; $f++; } - $leases[$l]['duid'] = $duid; + $entry['duid'] = $duid; } else { - $leases[$l]['duid'] = $data[$f+1]; + $entry['duid'] = $data[$f+1]; } - $leases[$l]['type'] = "dynamic"; + $entry['type'] = "dynamic"; $f = $f+2; break; case "iaaddr": - $leases[$l]['ip'] = $data[$f+1]; - $leases[$l]['type'] = "dynamic"; - if (in_array($leases[$l]['ip'], array_keys($ndpdata))) { - $leases[$l]['online'] = 'online'; + $entry['ip'] = $data[$f+1]; + $entry['type'] = "dynamic"; + if (in_array($entry['ip'], array_keys($ndpdata))) { + $entry['online'] = 'online'; } else { - $leases[$l]['online'] = 'offline'; + $entry['online'] = 'offline'; } $f = $f+2; break; + case "iaprefix": + $is_prefix = true; + $entry['prefix'] = $data[$f+1]; + $entry['type'] = "dynamic"; + $f = $f+2; + break; case "starts": - $leases[$l]['start'] = $data[$f+2]; - $leases[$l]['start'] .= " " . $data[$f+3]; + $entry['start'] = $data[$f+2]; + $entry['start'] .= " " . $data[$f+3]; $f = $f+3; break; case "ends": - $leases[$l]['end'] = $data[$f+2]; - $leases[$l]['end'] .= " " . $data[$f+3]; + $entry['end'] = $data[$f+2]; + $entry['end'] .= " " . $data[$f+3]; $f = $f+3; break; case "tstp": @@ -254,23 +267,26 @@ while($i < $leases_count) { $f = $f+3; break; case "cltt": - $leases[$l]['start'] = $data[$f+2]; - $leases[$l]['start'] .= " " . $data[$f+3]; + $entry['start'] = $data[$f+2]; + $entry['start'] .= " " . $data[$f+3]; $f = $f+3; break; case "binding": switch($data[$f+2]) { case "active": - $leases[$l]['act'] = "active"; + $entry['act'] = "active"; break; case "free": - $leases[$l]['act'] = "expired"; - $leases[$l]['online'] = "offline"; + $entry['act'] = "expired"; + $entry['online'] = "offline"; break; case "backup": - $leases[$l]['act'] = "reserved"; - $leases[$l]['online'] = "offline"; + $entry['act'] = "reserved"; + $entry['online'] = "offline"; break; + case "released": + $entry['act'] = "released"; + $entry['online'] = "offline"; } $f = $f+1; break; @@ -283,11 +299,11 @@ while($i < $leases_count) { break; case "client-hostname": if($data[$f+1] <> "") { - $leases[$l]['hostname'] = preg_replace('/"/','',$data[$f+1]); + $entry['hostname'] = preg_replace('/"/','',$data[$f+1]); } else { - $hostname = gethostbyaddr($leases[$l]['ip']); + $hostname = gethostbyaddr($entry['ip']); if($hostname <> "") { - $leases[$l]['hostname'] = $hostname; + $entry['hostname'] = $hostname; } } $f = $f+1; @@ -298,21 +314,32 @@ while($i < $leases_count) { } $f++; } + if ($is_prefix) { + $prefixes[] = $entry; + } else { + $leases[] = $entry; + $mappings[$entry['iaid'] . $entry['duid']] = $entry['ip']; + } $l++; $i++; + $is_prefix = false; } if(count($leases) > 0) { $leases = remove_duplicate($leases,"ip"); } +if(count($prefixes) > 0) { + $prefixes = remove_duplicate($prefixes,"prefix"); +} + if(count($pools) > 0) { $pools = remove_duplicate($pools,"name"); asort($pools); } foreach($config['interfaces'] as $ifname => $ifarr) { - if (is_array($config['dhcpdv6'][$ifname]) && + if (is_array($config['dhcpdv6'][$ifname]) && is_array($config['dhcpdv6'][$ifname]['staticmap'])) { foreach($config['dhcpdv6'][$ifname]['staticmap'] as $static) { $slease = array(); @@ -341,13 +368,13 @@ if ($_GET['order']) if(count($pools) > 0) { ?> - - - - - - - + + + + + + + \n"; @@ -408,9 +435,9 @@ foreach ($leases as $data) { } } else { $data['if'] = convert_real_interface_to_friendly_interface_name(guess_interface_from_ip($data['ip'])); - } + } echo "\n"; - echo "\n"; + echo "\n"; echo "\n"; echo "\n"; echo "\n"; - if ($data['type'] != "static") { - echo "\n"; - echo "\n"; - } else { - echo "\n"; - echo "\n"; - } - echo "\n"; - echo "\n"; - + if ($data['type'] != "static") { + echo "\n"; + echo "\n"; + } else { + echo "\n"; + echo "\n"; + } + echo "\n"; + echo "\n"; + if ($data['type'] == "dynamic") { echo "\n"; } else { - echo "\n"; } @@ -442,10 +469,67 @@ foreach ($leases as $data) { echo "\n"; } - echo "\n"; + echo "\n"; } } +?> +
{$fspans}{$data['ip']}{$fspane} {$fspans}{$data['ip']}{$fspane} {$fspans}{$data['iaid']}{$fspane} {$fspans}{$data['duid']}{$fspane} {$fspans}"; @@ -419,21 +446,21 @@ foreach ($leases as $data) { } echo htmlentities($ndpdata[$data['ip']]['mac']); echo "{$fspane} {$fspans}" . adjust_gmt($data['start']) . "{$fspane} {$fspans}" . adjust_gmt($data['end']) . "{$fspane} {$fspans} n/a {$fspane} {$fspans} n/a {$fspane} {$fspans}{$data['online']}{$fspane} {$fspans}{$data['act']}{$fspane} {$fspans}" . adjust_gmt($data['start']) . "{$fspane} {$fspans}" . adjust_gmt($data['end']) . "{$fspane} {$fspans} n/a {$fspane} {$fspans} n/a {$fspane} {$fspans}{$data['online']}{$fspane} {$fspans}{$data['act']}{$fspane} "; echo ""; + echo ""; echo ""; echo "
+

+

Delegated Prefixes

+ + + + + + + + + +"; + $fspane = ""; + } else { + $fspans = $fspane = ""; + } + if ($data['act'] == "static") { + foreach ($config['dhcpdv6'] as $dhcpif => $dhcpifconf) { + if(is_array($dhcpifconf['staticmap'])) { + foreach ($dhcpifconf['staticmap'] as $staticent) { + if ($data['ip'] == $staticent['ipaddr']) { + $data['if'] = $dhcpif; + break; + } + } + } + /* exit as soon as we have an interface */ + if ($data['if'] != "") + break; + } + } else { + $data['if'] = convert_real_interface_to_friendly_interface_name(guess_interface_from_ip($data['ip'])); + } + echo "\n"; + if ($mappings[$data['iaid'] . $data['duid']]) { + $dip = "
Routed To: {$mappings[$data['iaid'] . $data['duid']]}"; + } + echo "\n"; + echo "\n"; + echo "\n"; + if ($data['type'] != "static") { + echo "\n"; + echo "\n"; + } else { + echo "\n"; + echo "\n"; + } + echo "\n"; + echo "\n"; + } +} ?>
{$fspans}{$data['prefix']}{$dip}{$fspane} {$fspans}{$data['iaid']}{$fspane} {$fspans}{$data['duid']}{$fspane} {$fspans}" . adjust_gmt($data['start']) . "{$fspane} {$fspans}" . adjust_gmt($data['end']) . "{$fspane} {$fspans} n/a {$fspane} {$fspans} n/a {$fspane} {$fspans}{$data['act']}{$fspane} 

-- cgit v1.1