working a bit
[PHPIPManager.git] / lib / www.php
index c45de8a..1b8085d 100644 (file)
@@ -43,6 +43,7 @@ class www {
        {
                // we build a frame of framey's
                $this->header();
+               $this->printError();
                $this->mainPage();              
                $this->footer();
        }
@@ -51,7 +52,6 @@ class www {
        {
                global $db;
                
-               echo "<h1>Welcome to PHPIPManager</h1>";
                ?>
 <form method="post" action="?action=addsuper">
 Create Supernet: name <input type="text" name="name"></input>
@@ -60,16 +60,42 @@ Mask <input type="text" name="mask"></input>
 Description <input type="text" name="desc"></input>
 <input type="submit" name="go" Value="Create"></input>
 </form>
-               <?php 
+               <?php
+
+               // now print the super nets
+               $res = $db->dbobject->query("select * from supernet");
+               foreach($res as $row) {
+                       //echo "<pre>";
+               //      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>";
+                       // now we search for sub's
+                       echo "</table><br>";
+               }
+       }
+       
+       function printError()
+       {
+               if(isset($_REQUEST["error"]))
+               {
+                       echo "<font color=\"red\">".$_REQUEST["error"]."</font>";
+               }
+               if(isset($_REQUEST["notice"]))
+               {
+                       echo "<font color=\"green\">".$_REQUEST["notice"]."</font>";
+               }
+               
        }
        
-       function header()
+       function header($title = "Welcome to PHP IP Manager")
        {
                ?>
 <html>
-<head>
+<head><title><?php echo $title ?></title>
 </head>
-<body>
+<body><h1><?php echo $title ?></h1>
                <?php
        }
        
@@ -96,10 +122,15 @@ function www_ip_addSuperRange()
        $mask = $_REQUEST["mask"];
        $desc = $_REQUEST["desc"];
        
-       $sql = "insert into supernet values (NULL, '$name', '$sn', '$mask', '$desc')";
-       $db->dbobject->query($sql);
+       if(ip::isValid($sn, $mask)) {
+               $sn = ip::truncateNetwork($sn, $mask);
+               $sql = "insert into supernet values (NULL, '$name', '$sn', '$mask', '$desc')";
+               $db->dbobject->query($sql);
+               header("Location: index.php?notice=range added");
+       } else {
+               header("Location: index.php?error=invalid ipaddress");
+       }
 
-       header("Location: index.php");
 }
 
 ?>
\ No newline at end of file