diff options
Diffstat (limited to 'usr/local/sbin')
-rw-r--r-- | usr/local/sbin/prefixes.php | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/usr/local/sbin/prefixes.php b/usr/local/sbin/prefixes.php index 7c924c8..85cb496 100644 --- a/usr/local/sbin/prefixes.php +++ b/usr/local/sbin/prefixes.php @@ -5,10 +5,12 @@ if(!file_exists($leases_file)) { exit(1); } +$fd = fopen($leases_file, 'r'); + $duid_arr = array(); -foreach(file($leases_file) as $line) { +while (( $line = fgets($fd, 4096)) !== false) { // echo "$line"; - if(preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i ", $line, $duidmatch)) { + if(preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i", $line, $duidmatch)) { $type = $duidmatch[1]; $duid = $duidmatch[2]; continue; @@ -31,7 +33,7 @@ foreach(file($leases_file) as $line) { } /* closing bracket */ - if(preg_match("/^}/i ", $line)) { + if(preg_match("/^}/i", $line)) { switch($type) { case "ia-na": $duid_arr[$duid][$type] = $ia_na; @@ -48,13 +50,13 @@ foreach(file($leases_file) as $line) { continue; } } +fclose($fd); $routes = array(); foreach ($duid_arr as $entry) { - if($entry['ia-pd'] <> "") { + if(!empty($entry['ia-pd'])) { $routes[$entry['ia-na']] = $entry['ia-pd']; } - array_shift($duid_arr); } // echo "add routes\n"; @@ -66,28 +68,24 @@ if(count($routes) > 0) { /* get clog from dhcpd */ $dhcpdlogfile = "/var/log/dhcpd.log"; -$clog = array(); -if(file_exists($dhcpdlogfile)) - exec("clog $dhcpdlogfile", $clog, $ret); - -if($ret > 0) - $clog = array(); - $expires = array(); -foreach($clog as $line) { - if(preg_match("/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i", $line, $expire)) { - if(in_array($expire[1], $routes)) - continue; - $expires[$expire[1]] = $expire[1]; +if(file_exists($dhcpdlogfile)) { + $fd = popen("clog $dhcpdlogfile", 'r'); + while (($line = fgets($fd)) !== false) { + //echo $line; + if(preg_match("/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i", $line, $expire)) { + if(in_array($expire[1], $routes)) + continue; + $expires[$expire[1]] = $expire[1]; + } } - array_shift($clog); + pclose($fd); } // echo "remove routes\n"; if(count($expires) > 0) { foreach ($expires as $prefix) { echo "/sbin/route delete -inet6 {$prefix['prefix']}\n"; - array_shift($expires); } } |