<?php
// The www class file.
$actionRegister["addsuper"] = "www_ip_addSuperRange";
+$actionRegister["allocate"] = "www_ip_allocateSubRange";
class www {
function Go() {
{
// we build a frame of framey's
$this->header();
+ $this->printError();
$this->mainPage();
$this->footer();
}
{
global $db;
- echo "<h1>Welcome to PHPIPManager</h1>";
?>
<form method="post" action="?action=addsuper">
Create Supernet: name <input type="text" name="name"></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&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>";
+ }
+ }
+
+ 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
}
$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");
+ }
+}
+
+function www_ip_allocateSubRange()
+{
+ 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();
+ ?>
+sql is <?php echo "select * from supernet where sn_id=='$id" ?><br>
+<form method="post" action="?action=allocatesub&id=<?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="subip"></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
- header("Location: index.php");
+ $wwwConnector->footer();
}
?>
\ No newline at end of file