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 if(file_exists("style.css")) echo '<link href="style.css" rel="stylesheet" type="text/css" />';
139 <body><h1><?php echo $title ?></h1>
148 //print_r($_REQUEST);
158 function doInstaller()
160 header("Location: install.php");
164 function www_ip_scansub()
166 global $db, $wwwConnector;
168 $id = $_REQUEST["id"];
170 $res = $db->dbobject->query("select * from subnet where sn_id=='$id'");
172 foreach($res as $row) {
173 $snip = $row["sn_ip"];
174 $snmask = $row["sn_mask"];
175 $snname = $row["sn_name"];
177 $wwwConnector->header();
178 $wwwConnector->printError();
181 You are about to scan the subnet <?php echo "$snname ($snip/$snmask)" ?> how would you like entries added:<br>
182 <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)
183 <li> <a href="index.php?action=scansubreal&id=<?php echo $id?>&method=2">Replace</a> all entries where hosts are UP (reply to ping)
184 <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
185 <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
186 <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
189 $wwwConnector->footer();
192 function www_ip_scansubReal()
194 global $db, $wwwConnector;
196 $id = $_REQUEST["id"];
198 system("/usr/bin/php ../lib/runscan.php $id > /tmp/out.phpipman 2>&1 &");
199 error_log("would exec... nmap -sP -oX $fname $sn/$sm");
201 header("Location: index.php?notice=Scan Initiated");
204 function www_ip_addSuperRange()
208 $name = $_REQUEST["name"];
209 $sn = $_REQUEST["subnet"];
210 $mask = $_REQUEST["mask"];
211 $desc = $_REQUEST["desc"];
215 if($myip->addSupernet($name, $sn, $mask, $desc)) {
216 header("Location: index.php?notice=range added");
218 header("Location: index.php?error=invalid ipaddress");
222 function www_ip_allocateRange()
224 global $db, $wwwConnector;
226 $id = $_REQUEST["id"];
228 $res = $db->dbobject->query("select * from supernet where sn_id=='$id'");
230 foreach($res as $row) {
233 $wwwConnector->header();
234 $wwwConnector->printError();
236 <form method="post" action="?action=allocatesub&id=<?php echo $id ?>">
237 <input type="hidden" name="superid" value="<?php echo $id ?>">
239 <tr><td>Subnet Name</td><td><input type="text" name="subname"></td></tr>
240 <tr><td>Subnet IP</td><td><input type="text" name="subip" value="<?php echo $sn?>"></td></tr>
241 <tr><td>Subnet Mask</td><td><input type="text" name="submask"></td></tr>
242 <tr><td>Description</td><td><input type="text" name="subdesc"></td></tr>
243 <tr><td><input type="submit" name="add" value="Add"></td></tr>
248 $wwwConnector->footer();
251 function www_ip_deleteSubRange()
253 global $db, $wwwConnector;
255 $id = $_REQUEST["id"];
256 //("sn_id" INTEGER PRIMARY KEY AUTOINCREMENT,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);';
257 $sql = "delete from subnet where sn_id=='$id'";
258 $res = $db->dbobject->query($sql);
260 header("Location: index.php?notice=Deleted\n");
263 function www_ip_allocateSubRange()
265 global $db, $wwwConnector;
267 $superid = $_REQUEST["superid"];
268 $name = $_REQUEST["subname"];
269 $subip = $_REQUEST["subip"];
270 $mask = $_REQUEST["submask"];
271 $desc = $_REQUEST["subdesc"];
274 $err = $myip->addSubnet($name, $subip, $mask, $desc, $superid);
276 header("Location: index.php?notice=range added");
278 header("Location: index.php?error=$err");
282 function www_ip_modifySubnet()
284 global $db, $wwwConnector;
286 $id = $_REQUEST["id"];
287 //("sn_id" INTEGER PRIMARY KEY AUTOINCREMENT,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);';
288 $sql = "select sn_name,sn_desc,sn_ip from subnet where sn_id=='$id'";
289 $res = $db->dbobject->query($sql);
291 foreach($res as $row) {
292 $sn_name = $row["sn_name"];
293 $sn_desc = $row["sn_desc"];
294 $sn_ip = $row["sn_ip"];
297 $wwwConnector->header();
298 $wwwConnector->printError();
300 // ("ho_id" INTEGER PRIMARY KEY AUTOINCREMENT,"ho_sn_id" INTEGER,"ho_ip" TEXT,"ho_name" TEXT,"ho_desc" TEXT)
302 <form method="post" action="?action=changesubdetails&id=<?php echo $id ?>">
303 Subnet Name: <input type="text" name="subname" value="<?php echo $sn_name?>">
304 Subnet Description: <input type="text" name="subdesc" value="<?php echo $sn_desc?>">
305 <input type="submit" name="change" value="Update">
308 <form method="post" action="?action=addhosts&id=<?php echo $id ?>">
310 Hostname <input type="text" name="hostname">
311 IP Address <input type="text" name="hostip" value="<?php echo $sn_ip?>">
312 Description <input type="text" name="hostdesc" >
313 <input type="submit" name="change" value="Add">
319 <tr><th>Host IP</th><th>Hostname</th><th>Description</th></tr>
321 $sql = "select * from hosts where ho_sn_id='$id'";
322 $res = $db->dbobject->query($sql);
324 foreach($res as $row) {
325 $name = $row["ho_name"];
326 $desc = $row["ho_desc"];
328 $hid = $row["ho_id"];
329 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>";
335 <a href="index.php">Back</a>
338 $wwwConnector->footer();
341 function www_ip_updatehost()
343 global $db, $wwwConnector;
345 $hname = $_REQUEST["hostname"];
346 $hip = $_REQUEST["hostip"];
347 $hdesc = $_REQUEST["hostdesc"];
348 $sid = $_REQUEST["superid"];
349 $hid = $_REQUEST["hid"];
351 // ("ho_id" INTEGER PRIMARY KEY AUTOINCREMENT,"ho_sn_id" INTEGER,"ho_ip" TEXT,"ho_name" TEXT,"ho_desc" TEXT)
352 $sql = "update hosts set ho_name='$hname',ho_ip='$hip',ho_desc='$hdesc' where ho_id='$hid'";
353 $db->dbobject->query($sql);
355 header("Location: ?action=modsubnet&id=$sid");
358 function www_ip_modifyhost()
360 global $db, $wwwConnector;
362 $id = $_REQUEST["hid"];
364 $res = $db->dbobject->query("select * from hosts where ho_id=='$id'");
366 foreach($res as $row) {
367 $hname = $row["ho_name"];
368 $hip = $row["ho_ip"];
369 $sid = $row["ho_sn_id"];
370 $hdesc = $row["ho_desc"];
373 $wwwConnector->header();
374 $wwwConnector->printError();
376 <form method="post" action="?action=updatehost&hid=<?php echo $id ?>">
377 <input type="hidden" name="superid" value="<?php echo $sid ?>">
379 <tr><td>Host Name</td><td><input type="text" name="hostname" value="<?php echo $hname?>"></td></tr>
380 <tr><td>Host IP</td><td><input type="text" name="hostip" value="<?php echo $hip?>"></td></tr>
381 <tr><td>Description</td><td><input type="text" name="hostdesc" value="<?php echo $hdesc?>"></td></tr>
382 <tr><td><input type="submit" name="add" value="Update"></td></tr>
385 <a href="<?php echo $_SERVER["HTTP_REFERER"]?>">Back</a>
388 $wwwConnector->footer();
391 function www_ip_deletehost()
393 global $db, $wwwConnector;
395 $id = $_REQUEST["hostid"];
396 $sid = $_REQUEST["snid"];
398 $sql = "delete from hosts where ho_id=='$id'";
399 $db->dbobject->query($sql);
401 header("Location: ?action=modsubnet&id=$sid");
404 function www_ip_addhost()
406 global $db, $wwwConnector;
408 $id = $_REQUEST["id"];
409 $hn = $_REQUEST["hostname"];
410 $hip = $_REQUEST["hostip"];
411 $desc = $_REQUEST["hostdesc"];
413 $sql = "insert into hosts values (NULL, '$id', '$hip', '$hn', '$desc')";
414 $db->dbobject->query($sql);
416 header("Location: ?action=modsubnet&id=$id");
419 function www_ip_changesubdetails()
421 global $db, $wwwConnector;
423 $id = $_REQUEST["id"];
424 $name = $_REQUEST["subname"];
425 $desc = $_REQUEST["subdesc"];
427 $sql = "update subnet set sn_name='$name', sn_desc='$desc' where sn_id=='$id'";
428 $db->dbobject->query($sql);
430 header("Location: ?action=modsubnet&id=$id");
433 function www_db_dumpdb()
437 $datestamp = strftime("%d-%m-%Y-%H.%M.%S");
438 $name = "ipmandbdump-$datestamp.db";
439 header("Content-type: application/octet-stream;\n");
440 header("Content-Disposition: attachment; filename=\"$name\";\n\n");
444 function www_db_restoredb()