From 25d958f0efba2469a49a6de196f5a9ba0790ecd1 Mon Sep 17 00:00:00 2001 From: paulr Date: Sun, 12 Sep 2010 05:21:11 +1000 Subject: [PATCH] moved some functionality into the ip class --- lib/ip.php | 12 +++++++++++- lib/www.php | 7 +++---- 2 files changed, 14 insertions(+), 5 deletions(-) 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"); -- 1.7.0.4