moved some functionality into the ip class
authorpaulr <me@pjr.cc>
Sat, 11 Sep 2010 19:21:11 +0000 (05:21 +1000)
committerpaulr <me@pjr.cc>
Sat, 11 Sep 2010 19:21:11 +0000 (05:21 +1000)
lib/ip.php
lib/www.php

index a1c6a8a..91d7013 100644 (file)
@@ -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)
index 79409a8..2ec7c73 100644 (file)
@@ -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");