From: paulr Date: Sat, 11 Sep 2010 19:21:11 +0000 (+1000) Subject: moved some functionality into the ip class X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=25d958f0efba2469a49a6de196f5a9ba0790ecd1;p=PHPIPManager.git moved some functionality into the ip class --- diff --git a/lib/ip.php b/lib/ip.php index a1c6a8a..91d7013 100644 --- a/lib/ip.php +++ b/lib/ip.php @@ -76,10 +76,12 @@ class ip { $slt = ""; for($i = 0; $i < $sns; $i++) { + if($i!=0) $slt .= ":"; if(strlen($pss[$i]) < 1) { error_log("no 3"); return false; } + $slt .= "".$pss[$i]; } // we are still a valid ipv6 ip address/mask @@ -96,9 +98,17 @@ class ip { } } - function addSupernet($supernet) + function addSupernet($name, $sn, $mask, $desc) { + global $db; + if(ip::isValid($sn, $mask)) { + $sn = ip::truncateNetwork($sn, $mask); + $sql = "insert into supernet values (NULL, '$name', '$sn', '$mask', '$desc')"; + $db->dbobject->query($sql); + return true; + } + return false; } function addSubnet($subnet) diff --git a/lib/www.php b/lib/www.php index 79409a8..2ec7c73 100644 --- a/lib/www.php +++ b/lib/www.php @@ -123,10 +123,9 @@ function www_ip_addSuperRange() $mask = $_REQUEST["mask"]; $desc = $_REQUEST["desc"]; - if(ip::isValid($sn, $mask)) { - $sn = ip::truncateNetwork($sn, $mask); - $sql = "insert into supernet values (NULL, '$name', '$sn', '$mask', '$desc')"; - $db->dbobject->query($sql); + $myip = new ip(); + + if($myip->addSupernet($name, $sn, $mask, $desc)) { header("Location: index.php?notice=range added"); } else { header("Location: index.php?error=invalid ipaddress");