3 $actionRegister["addsuper"] = "www_ip_addSuperRange";
4 $actionRegister["allocate"] = "www_ip_allocateRange";
5 $actionRegister["allocatesub"] = "www_ip_allocateSubRange";
6 $actionRegister["modsubnet"] = "www_ip_modifySubnet";
7 $actionRegister["dumpdb"] = "www_db_dumpdb";
8 $actionRegister["restoredb"] = "www_db_restoredb";
9 $actionRegister["changesubdetails"] = "www_ip_changesubdetails";
10 $actionRegister["addhosts"] = "www_ip_addhost";
11 $actionRegister["deletehost"] = "www_ip_deletehost";
15 // this is the web page entry function.
19 //if($db->connect()!=0) {
20 //$this->doInstaller();
24 // its up to auth as to wether "this" url requires auth.
25 $authThis = new auth();
28 if(isset($_REQUEST["action"])) {
29 $this->doAction($_REQUEST["action"]);
35 function doAction($actionName)
37 global $actionRegister;
40 if(isset($actionRegister[$actionName])) {
41 $func = $actionRegister[$actionName];
42 error_log("im here 2");
45 error_log("im here 3");
52 // we build a frame of framey's
64 <form method="post" action="?action=addsuper">
65 Create Supernet: name <input type="text" name="name"></input>
66 Subnet Address <input type="text" name="subnet"></input>
67 Mask <input type="text" name="mask"></input>
68 Description <input type="text" name="desc"></input>
69 <input type="submit" name="go" Value="Create"></input>
73 // now print the super nets
74 $res = $db->dbobject->query("select * from supernet");
75 foreach($res as $row) {
79 echo "<table border=\"1\"><tr><th align=\"left\">".$row["sn_name"]."</th><td>".$row["sn_ip"]."::0/".$row["sn_mask"]."</td><td>".$row["sn_desc"]."</td>";
80 echo "<td><a href=\"?action=allocate&id=".$row["sn_id"]."\">Allocate Subnet</a></td>";
81 echo "<td><a href=\"?action=delete&id=".$row["sn_id"]."\">Delete Supernet</a></td>";
83 // now we search for sub's
84 $res2 = $db->dbobject->query("select * from subnet where snid_id='".$row["sn_id"]."'");
85 foreach($res2 as $row2) {
86 // ("sn_id" INTEGER PRIMARY KEY AUTOINCREMENT,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);';
87 $name = $row2["sn_name"];
88 $subid = $row2["sn_id"];
89 $subnet = $row2["sn_ip"];
90 $mask = $row2["sn_mask"];
91 $desc = $row2["sn_desc"];
93 echo "<td><li> <i><a href=\"?action=modsubnet&id=".$row2["sn_id"]."\">$name</a></i></td><td>$subnet::0/$mask</td><td>$desc</td>";
94 echo "<td><a href=\"?action=deletesub&id=".$row2["sn_id"]."\">Delete Subnet</a></td>";
95 //echo "<td><a href=\"?action=addhost&id=".$row["sn_id"]."\">Add Host</a></td>";
101 echo "<a href=\"?action=dumpdb\">dump database</a> <a href=\"?action=restoredb\">restore database</a>";
104 function printError()
106 if(isset($_REQUEST["error"]))
108 echo "<font color=\"red\">".$_REQUEST["error"]."</font>";
110 if(isset($_REQUEST["notice"]))
112 echo "<font color=\"green\">".$_REQUEST["notice"]."</font>";
117 function header($title = "Welcome to PHP IP Manager")
121 <head><title><?php echo $title ?></title>
123 <body><h1><?php echo $title ?></h1>
135 function doInstaller()
137 header("Location: install.php");
141 function www_ip_addSuperRange()
145 $name = $_REQUEST["name"];
146 $sn = $_REQUEST["subnet"];
147 $mask = $_REQUEST["mask"];
148 $desc = $_REQUEST["desc"];
152 if($myip->addSupernet($name, $sn, $mask, $desc)) {
153 header("Location: index.php?notice=range added");
155 header("Location: index.php?error=invalid ipaddress");
159 function www_ip_allocateRange()
161 global $db, $wwwConnector;
163 $id = $_REQUEST["id"];
165 $res = $db->dbobject->query("select * from supernet where sn_id=='$id'");
167 foreach($res as $row) {
170 $wwwConnector->header();
171 $wwwConnector->printError();
173 <form method="post" action="?action=allocatesub&id=<?php echo $id ?>">
174 <input type="hidden" name="superid" value="<?php echo $id ?>">
176 <tr><td>Subnet Name</td><td><input type="text" name="subname"></td></tr>
177 <tr><td>Subnet IP</td><td><input type="text" name="subip" value="<?php echo $sn?>"></td></tr>
178 <tr><td>Subnet Mask</td><td><input type="text" name="submask"></td></tr>
179 <tr><td>Description</td><td><input type="text" name="subdesc"></td></tr>
180 <tr><td><input type="submit" name="add" value="Add"></td></tr>
185 $wwwConnector->footer();
188 function www_ip_allocateSubRange()
190 global $db, $wwwConnector;
192 $superid = $_REQUEST["superid"];
193 $name = $_REQUEST["subname"];
194 $subip = $_REQUEST["subip"];
195 $mask = $_REQUEST["submask"];
196 $desc = $_REQUEST["subdesc"];
199 if($myip->addSubnet($name, $subip, $mask, $desc, $superid)) {
200 header("Location: index.php?notice=range added");
202 header("Location: index.php?error=invalid ipaddress");
206 function www_ip_modifySubnet()
208 global $db, $wwwConnector;
210 $id = $_REQUEST["id"];
211 //("sn_id" INTEGER PRIMARY KEY AUTOINCREMENT,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);';
212 $sql = "select sn_name,sn_desc,sn_ip from subnet where sn_id=='$id'";
213 $res = $db->dbobject->query($sql);
215 foreach($res as $row) {
216 $sn_name = $row["sn_name"];
217 $sn_desc = $row["sn_desc"];
218 $sn_ip = $row["sn_ip"];
221 $wwwConnector->header();
222 $wwwConnector->printError();
224 // ("ho_id" INTEGER PRIMARY KEY AUTOINCREMENT,"ho_sn_id" INTEGER,"ho_ip" TEXT,"ho_name" TEXT,"ho_desc" TEXT)
226 <form method="post" action="?action=changesubdetails&id=<?php echo $id ?>">
227 Subnet Name: <input type="text" name="subname" value="<?php echo $sn_name?>">
228 Subnet Description: <input type="text" name="subdesc" value="<?php echo $sn_desc?>">
229 <input type="submit" name="change" value="Update">
232 <form method="post" action="?action=addhosts&id=<?php echo $id ?>">
234 Hostname <input type="text" name="hostname">
235 IP Address <input type="text" name="hostip" value="<?php echo $sn_ip.":"?>">
236 Description <input type="text" name="hostdesc" >
237 <input type="submit" name="change" value="Add">
243 <tr><th>Host IP</th><th>Hostname</th><th>Description</th></tr>
245 $sql = "select * from hosts where ho_sn_id='$id'";
246 $res = $db->dbobject->query($sql);
248 foreach($res as $row) {
249 $name = $row["ho_name"];
250 $desc = $row["ho_desc"];
252 $hid = $row["ho_id"];
253 echo "<tr><td>$ip</td><td>$name</td><td>$desc</td><td><a href=\"?action=deletehost&hostid=$hid&snid=$id\">Delete</a></td></tr>";
259 <a href="index.php">Back</a>
262 $wwwConnector->footer();
265 function www_ip_deletehost()
267 global $db, $wwwConnector;
269 $id = $_REQUEST["hostid"];
270 $sid = $_REQUEST["snid"];
272 $sql = "delete from hosts where ho_id=='$id'";
273 $db->dbobject->query($sql);
275 header("Location: ?action=modsubnet&id=$sid");
278 function www_ip_addhost()
280 global $db, $wwwConnector;
282 $id = $_REQUEST["id"];
283 $hn = $_REQUEST["hostname"];
284 $hip = $_REQUEST["hostip"];
285 $desc = $_REQUEST["hostdesc"];
287 $sql = "insert into hosts values (NULL, '$id', '$hip', '$hn', '$desc')";
288 $db->dbobject->query($sql);
290 header("Location: ?action=modsubnet&id=$id");
293 function www_ip_changesubdetails()
295 global $db, $wwwConnector;
297 $id = $_REQUEST["id"];
298 $name = $_REQUEST["subname"];
299 $desc = $_REQUEST["subdesc"];
301 $sql = "update subnet set sn_name='$name', sn_desc='$desc' where sn_id=='$id'";
302 $db->dbobject->query($sql);
304 header("Location: ?action=modsubnet&id=$id");
307 function www_db_dumpdb()
311 $datestamp = strftime("%d-%m-%Y-%H.%M.%S");
312 $name = "ipmandbdump-$datestamp.db";
313 header("Content-type: application/octet-stream;\n");
314 header("Content-Disposition: attachment; filename=\"$name\";\n\n");
318 function www_db_restoredb()