3 $actionRegister["addsuper"] = "www_ip_addSuperRange";
4 $actionRegister["allocate"] = "www_ip_allocateRange";
5 $actionRegister["allocatesub"] = "www_ip_allocateSubRange";
6 $actionRegister["deletesub"] = "www_ip_deleteSubRange";
7 $actionRegister["modsubnet"] = "www_ip_modifySubnet";
8 $actionRegister["dumpdb"] = "www_db_dumpdb";
9 $actionRegister["restoredb"] = "www_db_restoredb";
10 $actionRegister["changesubdetails"] = "www_ip_changesubdetails";
11 $actionRegister["addhosts"] = "www_ip_addhost";
12 $actionRegister["deletehost"] = "www_ip_deletehost";
13 $actionRegister["modifyhost"] = "www_ip_modifyhost";
14 $actionRegister["updatehost"] = "www_ip_updatehost";
15 $actionRegister["scansub"] = "www_ip_scansub";
16 $actionRegister["scansubreal"] = "www_ip_scansubReal";
20 // this is the web page entry function.
24 //if($db->connect()!=0) {
25 //$this->doInstaller();
29 // its up to auth as to wether "this" url requires auth.
30 $authThis = new auth();
33 if(isset($_REQUEST["action"])) {
34 $this->doAction($_REQUEST["action"]);
40 function doAction($actionName)
42 global $actionRegister;
45 if(isset($actionRegister[$actionName])) {
46 $func = $actionRegister[$actionName];
47 error_log("im here 2");
50 error_log("im here 3");
57 // we build a frame of framey's
69 <form method="post" action="?action=addsuper">
70 Create Supernet: name <input type="text" name="name"></input>
71 Subnet Address <input type="text" name="subnet"></input>
72 Mask <input type="text" name="mask"></input>
73 Description <input type="text" name="desc"></input>
74 <input type="submit" name="go" Value="Create"></input>
78 // now print the super nets
79 $res = $db->dbobject->query("select * from supernet");
80 foreach($res as $row) {
84 if(ipversion($row["sn_ip"]) == 6) $ip6trans = "::0";
86 echo "<table border=\"1\"><tr><th align=\"left\">".$row["sn_name"]."</th><td>".$row["sn_ip"]."$ip6trans/".$row["sn_mask"]."</td><td>".$row["sn_desc"]."</td>";
87 echo "<td><a href=\"?action=allocate&id=".$row["sn_id"]."\">Allocate Subnet</a></td>";
88 echo "<td><a href=\"?action=delete&id=".$row["sn_id"]."\">Delete Supernet</a></td>";
90 // now we search for sub's
91 $res2 = $db->dbobject->query("select * from subnet where snid_id='".$row["sn_id"]."'");
92 foreach($res2 as $row2) {
93 // ("sn_id" INTEGER PRIMARY KEY AUTOINCREMENT,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);';
94 $name = $row2["sn_name"];
95 $subid = $row2["sn_id"];
96 $subnet = $row2["sn_ip"];
97 $mask = $row2["sn_mask"];
98 $desc = $row2["sn_desc"];
100 if(ipversion($row2["sn_ip"]) == 6) $ip6trans = "::0";
104 echo "<td><li> <i><a href=\"?action=modsubnet&id=".$row2["sn_id"]."\">$name</a></i></td><td>$subnet$ip6trans/$mask</td><td>$desc</td>";
105 echo "<td><a href=\"?action=deletesub&id=".$row2["sn_id"]."\">Delete Subnet</a></td>";
106 //echo "<td><a href=\"?action=addhost&id=".$row["sn_id"]."\">Add Host</a></td>";
107 if(ipversion($row2["sn_ip"]) == 4) echo "<td><a href=\"?action=scansub&id=".$row2["sn_id"]."\">Scan Subnet</a></td>";
113 echo "<a href=\"?action=dumpdb\">dump database</a> <a href=\"?action=restoredb\">restore database</a>";
116 function printError()
118 if(isset($_REQUEST["error"]))
120 echo "<font color=\"red\">".$_REQUEST["error"]."</font>";
122 if(isset($_REQUEST["notice"]))
124 echo "<font color=\"green\">".$_REQUEST["notice"]."</font>";
129 function header($title = "Welcome to PHP IP Manager")
133 <head><title><?php echo $title ?></title>
135 <body><h1><?php echo $title ?></h1>
144 //print_r($_REQUEST);
154 function doInstaller()
156 header("Location: install.php");
160 function www_ip_scansub()
162 global $db, $wwwConnector;
164 $id = $_REQUEST["id"];
166 $res = $db->dbobject->query("select * from subnet where sn_id=='$id'");
168 foreach($res as $row) {
169 $snip = $row["sn_ip"];
170 $snmask = $row["sn_mask"];
171 $snname = $row["sn_name"];
173 $wwwConnector->header();
174 $wwwConnector->printError();
177 You are about to scan the subnet <?php echo "$snname ($snip/$snmask)" ?> how would you like entries added:<br>
178 <li> <a href="index.php?action=scansubreal&id=<?php echo $id?>&method=1">Replace</a> all default entries (i.e. where the name and the ip address are the same) where hosts are UP (reply to ping)
179 <li> <a href="index.php?action=scansubreal&id=<?php echo $id?>&method=2">Replace</a> all entries where hosts are UP (reply to ping)
180 <li> <a href="index.php?action=scansubreal&id=<?php echo $id?>&method=3">Add</a> any entries where hosts are UP (reply to ping) and an entry does not already exist in the database
181 <li> <a href="index.php?action=scansubreal&id=<?php echo $id?>&method=4">Add</a> any entries where hosts are UP or Down and an entry does not already exist in the database, but the IP has a reverse hostname entry
182 <li> <a href="index.php?action=scansubreal&id=<?php echo $id?>&method=5">Delete</a> all entries and replace with hosts that are Up or Down and have reverse hostname entries
185 $wwwConnector->footer();
188 function www_ip_scansubReal()
190 global $db, $wwwConnector;
192 $id = $_REQUEST["id"];
194 system("/usr/bin/php ../lib/runscan.php $id > /tmp/out.phpipman 2>&1 &");
195 error_log("would exec... nmap -sP -oX $fname $sn/$sm");
197 header("Location: index.php");
200 function www_ip_addSuperRange()
204 $name = $_REQUEST["name"];
205 $sn = $_REQUEST["subnet"];
206 $mask = $_REQUEST["mask"];
207 $desc = $_REQUEST["desc"];
211 if($myip->addSupernet($name, $sn, $mask, $desc)) {
212 header("Location: index.php?notice=range added");
214 header("Location: index.php?error=invalid ipaddress");
218 function www_ip_allocateRange()
220 global $db, $wwwConnector;
222 $id = $_REQUEST["id"];
224 $res = $db->dbobject->query("select * from supernet where sn_id=='$id'");
226 foreach($res as $row) {
229 $wwwConnector->header();
230 $wwwConnector->printError();
232 <form method="post" action="?action=allocatesub&id=<?php echo $id ?>">
233 <input type="hidden" name="superid" value="<?php echo $id ?>">
235 <tr><td>Subnet Name</td><td><input type="text" name="subname"></td></tr>
236 <tr><td>Subnet IP</td><td><input type="text" name="subip" value="<?php echo $sn?>"></td></tr>
237 <tr><td>Subnet Mask</td><td><input type="text" name="submask"></td></tr>
238 <tr><td>Description</td><td><input type="text" name="subdesc"></td></tr>
239 <tr><td><input type="submit" name="add" value="Add"></td></tr>
244 $wwwConnector->footer();
247 function www_ip_deleteSubRange()
249 global $db, $wwwConnector;
251 $id = $_REQUEST["id"];
252 //("sn_id" INTEGER PRIMARY KEY AUTOINCREMENT,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);';
253 $sql = "delete from subnet where sn_id=='$id'";
254 $res = $db->dbobject->query($sql);
256 header("Location: index.php?notice=Deleted\n");
259 function www_ip_allocateSubRange()
261 global $db, $wwwConnector;
263 $superid = $_REQUEST["superid"];
264 $name = $_REQUEST["subname"];
265 $subip = $_REQUEST["subip"];
266 $mask = $_REQUEST["submask"];
267 $desc = $_REQUEST["subdesc"];
270 if($myip->addSubnet($name, $subip, $mask, $desc, $superid)) {
271 header("Location: index.php?notice=range added");
273 header("Location: index.php?error=invalid ipaddress");
277 function www_ip_modifySubnet()
279 global $db, $wwwConnector;
281 $id = $_REQUEST["id"];
282 //("sn_id" INTEGER PRIMARY KEY AUTOINCREMENT,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);';
283 $sql = "select sn_name,sn_desc,sn_ip from subnet where sn_id=='$id'";
284 $res = $db->dbobject->query($sql);
286 foreach($res as $row) {
287 $sn_name = $row["sn_name"];
288 $sn_desc = $row["sn_desc"];
289 $sn_ip = $row["sn_ip"];
292 $wwwConnector->header();
293 $wwwConnector->printError();
295 // ("ho_id" INTEGER PRIMARY KEY AUTOINCREMENT,"ho_sn_id" INTEGER,"ho_ip" TEXT,"ho_name" TEXT,"ho_desc" TEXT)
297 <form method="post" action="?action=changesubdetails&id=<?php echo $id ?>">
298 Subnet Name: <input type="text" name="subname" value="<?php echo $sn_name?>">
299 Subnet Description: <input type="text" name="subdesc" value="<?php echo $sn_desc?>">
300 <input type="submit" name="change" value="Update">
303 <form method="post" action="?action=addhosts&id=<?php echo $id ?>">
305 Hostname <input type="text" name="hostname">
306 IP Address <input type="text" name="hostip" value="<?php echo $sn_ip?>">
307 Description <input type="text" name="hostdesc" >
308 <input type="submit" name="change" value="Add">
314 <tr><th>Host IP</th><th>Hostname</th><th>Description</th></tr>
316 $sql = "select * from hosts where ho_sn_id='$id'";
317 $res = $db->dbobject->query($sql);
319 foreach($res as $row) {
320 $name = $row["ho_name"];
321 $desc = $row["ho_desc"];
323 $hid = $row["ho_id"];
324 echo "<tr><td><a href=\"?action=modifyhost&hid=$hid\">$ip</a></td><td>$name</td><td>$desc</td><td><a href=\"?action=deletehost&hostid=$hid&snid=$id\">Delete</a></td></tr>";
330 <a href="index.php">Back</a>
333 $wwwConnector->footer();
336 function www_ip_updatehost()
338 global $db, $wwwConnector;
340 $hname = $_REQUEST["hostname"];
341 $hip = $_REQUEST["hostip"];
342 $hdesc = $_REQUEST["hostdesc"];
343 $sid = $_REQUEST["superid"];
344 $hid = $_REQUEST["hid"];
346 // ("ho_id" INTEGER PRIMARY KEY AUTOINCREMENT,"ho_sn_id" INTEGER,"ho_ip" TEXT,"ho_name" TEXT,"ho_desc" TEXT)
347 $sql = "update hosts set ho_name='$hname',ho_ip='$hip',ho_desc='$hdesc' where ho_id='$hid'";
348 $db->dbobject->query($sql);
350 header("Location: ?action=modsubnet&id=$sid");
353 function www_ip_modifyhost()
355 global $db, $wwwConnector;
357 $id = $_REQUEST["hid"];
359 $res = $db->dbobject->query("select * from hosts where ho_id=='$id'");
361 foreach($res as $row) {
362 $hname = $row["ho_name"];
363 $hip = $row["ho_ip"];
364 $sid = $row["ho_sn_id"];
365 $hdesc = $row["ho_desc"];
368 $wwwConnector->header();
369 $wwwConnector->printError();
371 <form method="post" action="?action=updatehost&hid=<?php echo $id ?>">
372 <input type="hidden" name="superid" value="<?php echo $sid ?>">
374 <tr><td>Host Name</td><td><input type="text" name="hostname" value="<?php echo $hname?>"></td></tr>
375 <tr><td>Host IP</td><td><input type="text" name="hostip" value="<?php echo $hip?>"></td></tr>
376 <tr><td>Description</td><td><input type="text" name="hostdesc" value="<?php echo $hdesc?>"></td></tr>
377 <tr><td><input type="submit" name="add" value="Update"></td></tr>
380 <a href="<?php echo $_SERVER["HTTP_REFERER"]?>">Back</a>
383 $wwwConnector->footer();
386 function www_ip_deletehost()
388 global $db, $wwwConnector;
390 $id = $_REQUEST["hostid"];
391 $sid = $_REQUEST["snid"];
393 $sql = "delete from hosts where ho_id=='$id'";
394 $db->dbobject->query($sql);
396 header("Location: ?action=modsubnet&id=$sid");
399 function www_ip_addhost()
401 global $db, $wwwConnector;
403 $id = $_REQUEST["id"];
404 $hn = $_REQUEST["hostname"];
405 $hip = $_REQUEST["hostip"];
406 $desc = $_REQUEST["hostdesc"];
408 $sql = "insert into hosts values (NULL, '$id', '$hip', '$hn', '$desc')";
409 $db->dbobject->query($sql);
411 header("Location: ?action=modsubnet&id=$id");
414 function www_ip_changesubdetails()
416 global $db, $wwwConnector;
418 $id = $_REQUEST["id"];
419 $name = $_REQUEST["subname"];
420 $desc = $_REQUEST["subdesc"];
422 $sql = "update subnet set sn_name='$name', sn_desc='$desc' where sn_id=='$id'";
423 $db->dbobject->query($sql);
425 header("Location: ?action=modsubnet&id=$id");
428 function www_db_dumpdb()
432 $datestamp = strftime("%d-%m-%Y-%H.%M.%S");
433 $name = "ipmandbdump-$datestamp.db";
434 header("Content-type: application/octet-stream;\n");
435 header("Content-Disposition: attachment; filename=\"$name\";\n\n");
439 function www_db_restoredb()