added some db functionality
[PHPIPManager.git] / lib / www.php
index 1b8085d..70274f5 100644 (file)
@@ -1,6 +1,10 @@
 <?php
 // The www class file.
 $actionRegister["addsuper"] = "www_ip_addSuperRange";
+$actionRegister["allocate"] = "www_ip_allocateRange";
+$actionRegister["allocatesub"] = "www_ip_allocateSubRange";
+$actionRegister["dumpdb"] = "www_db_dumpdb";
+$actionRegister["restoredb"] = "www_db_restoredb";
 
 class www {
        function Go() {
@@ -69,11 +73,13 @@ Description <input type="text" name="desc"></input>
                //      print_r($row);
                //      echo "</pre><hr>";
                        echo "<table border=\"1\"><tr><th>".$row["sn_name"]."</th><td>".$row["sn_ip"]."/".$row["sn_mask"]."</td><td>".$row["sn_desc"]."</td>";
-                       echo "<td><a href=\"?action=allocate\">Allocate Subnet</a></td>";
-                       echo "<td><a href=\"?action=delete\">Delete Supernet</a></td>";
+                       echo "<td><a href=\"?action=allocate&id=".$row["sn_id"]."\">Allocate Subnet</a></td>";
+                       echo "<td><a href=\"?action=delete&id=".$row["sn_id"]."\">Delete Supernet</a></td>";
                        // now we search for sub's
                        echo "</table><br>";
                }
+               
+               echo "<a href=\"?action=dumpdb\">dump database</a> <a href=\"?action=restoredb\">restore database</a>";  
        }
        
        function printError()
@@ -122,15 +128,68 @@ 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");
+       }
+}
+
+function www_ip_allocateRange()
+{
+       global $db, $wwwConnector;
+
+       $id = $_REQUEST["id"];
+       
+       $res = $db->dbobject->query("select * from supernet where sn_id=='$id'");
+       
+       foreach($res as $row) {
+               $sn = $row["sn_ip"];
+       }
+       $wwwConnector->header();
+       $wwwConnector->printError();
+       ?>
+<form method="post" action="?action=allocatesub&id=<?php echo $id ?>">
+<input type="hidden" name="superid" value="<?php echo $id ?>">
+<table>
+<tr><td>Subnet Name</td><td><input type="text" name="subname"></td></tr>
+<tr><td>Subnet IP</td><td><input type="text" name="subip" value="<?php echo $sn?>"></td></tr>
+<tr><td>Subnet Mask</td><td><input type="text" name="submask"></td></tr>
+<tr><td>Description</td><td><input type="text" name="subdesc"></td></tr>
+<tr><td><input type="submit" name="add" value="Add"></td></tr>
+</table>
+</form>
+<?php
+
+       $wwwConnector->footer();
+}
+
+function www_ip_allocateSubRange()
+{
+       global $db, $wwwConnector;
+       
+       $superid = $_REQUEST["superid"];
+       $name = $_REQUEST["subname"];
+       $subip = $_REQUEST["subip"];
+       $mask = $_REQUEST["submask"];
+       $desc = $_REQUEST["subdesc"];
+       
+       $myip = new ip();
+       if($myip->addSubnet($name, $subip, $mask, $desc, $superid)) {
                header("Location: index.php?notice=range added");
        } else {
                header("Location: index.php?error=invalid ipaddress");
        }
+}
+
+function www_db_dumpdb()
+{
+}
 
+function www_db_restoredb()
+{
 }
 
 ?>
\ No newline at end of file