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?notice=Scan Initiated");
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 $err = $myip->addSubnet($name, $subip, $mask, $desc, $superid);
272 header("Location: index.php?notice=range added");
274 header("Location: index.php?error=$err");
278 function www_ip_modifySubnet()
280 global $db, $wwwConnector;
282 $id = $_REQUEST["id"];
283 //("sn_id" INTEGER PRIMARY KEY AUTOINCREMENT,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);';
284 $sql = "select sn_name,sn_desc,sn_ip from subnet where sn_id=='$id'";
285 $res = $db->dbobject->query($sql);
287 foreach($res as $row) {
288 $sn_name = $row["sn_name"];
289 $sn_desc = $row["sn_desc"];
290 $sn_ip = $row["sn_ip"];
293 $wwwConnector->header();
294 $wwwConnector->printError();
296 // ("ho_id" INTEGER PRIMARY KEY AUTOINCREMENT,"ho_sn_id" INTEGER,"ho_ip" TEXT,"ho_name" TEXT,"ho_desc" TEXT)
298 <form method="post" action="?action=changesubdetails&id=<?php echo $id ?>">
299 Subnet Name: <input type="text" name="subname" value="<?php echo $sn_name?>">
300 Subnet Description: <input type="text" name="subdesc" value="<?php echo $sn_desc?>">
301 <input type="submit" name="change" value="Update">
304 <form method="post" action="?action=addhosts&id=<?php echo $id ?>">
306 Hostname <input type="text" name="hostname">
307 IP Address <input type="text" name="hostip" value="<?php echo $sn_ip?>">
308 Description <input type="text" name="hostdesc" >
309 <input type="submit" name="change" value="Add">
315 <tr><th>Host IP</th><th>Hostname</th><th>Description</th></tr>
317 $sql = "select * from hosts where ho_sn_id='$id'";
318 $res = $db->dbobject->query($sql);
320 foreach($res as $row) {
321 $name = $row["ho_name"];
322 $desc = $row["ho_desc"];
324 $hid = $row["ho_id"];
325 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>";
331 <a href="index.php">Back</a>
334 $wwwConnector->footer();
337 function www_ip_updatehost()
339 global $db, $wwwConnector;
341 $hname = $_REQUEST["hostname"];
342 $hip = $_REQUEST["hostip"];
343 $hdesc = $_REQUEST["hostdesc"];
344 $sid = $_REQUEST["superid"];
345 $hid = $_REQUEST["hid"];
347 // ("ho_id" INTEGER PRIMARY KEY AUTOINCREMENT,"ho_sn_id" INTEGER,"ho_ip" TEXT,"ho_name" TEXT,"ho_desc" TEXT)
348 $sql = "update hosts set ho_name='$hname',ho_ip='$hip',ho_desc='$hdesc' where ho_id='$hid'";
349 $db->dbobject->query($sql);
351 header("Location: ?action=modsubnet&id=$sid");
354 function www_ip_modifyhost()
356 global $db, $wwwConnector;
358 $id = $_REQUEST["hid"];
360 $res = $db->dbobject->query("select * from hosts where ho_id=='$id'");
362 foreach($res as $row) {
363 $hname = $row["ho_name"];
364 $hip = $row["ho_ip"];
365 $sid = $row["ho_sn_id"];
366 $hdesc = $row["ho_desc"];
369 $wwwConnector->header();
370 $wwwConnector->printError();
372 <form method="post" action="?action=updatehost&hid=<?php echo $id ?>">
373 <input type="hidden" name="superid" value="<?php echo $sid ?>">
375 <tr><td>Host Name</td><td><input type="text" name="hostname" value="<?php echo $hname?>"></td></tr>
376 <tr><td>Host IP</td><td><input type="text" name="hostip" value="<?php echo $hip?>"></td></tr>
377 <tr><td>Description</td><td><input type="text" name="hostdesc" value="<?php echo $hdesc?>"></td></tr>
378 <tr><td><input type="submit" name="add" value="Update"></td></tr>
381 <a href="<?php echo $_SERVER["HTTP_REFERER"]?>">Back</a>
384 $wwwConnector->footer();
387 function www_ip_deletehost()
389 global $db, $wwwConnector;
391 $id = $_REQUEST["hostid"];
392 $sid = $_REQUEST["snid"];
394 $sql = "delete from hosts where ho_id=='$id'";
395 $db->dbobject->query($sql);
397 header("Location: ?action=modsubnet&id=$sid");
400 function www_ip_addhost()
402 global $db, $wwwConnector;
404 $id = $_REQUEST["id"];
405 $hn = $_REQUEST["hostname"];
406 $hip = $_REQUEST["hostip"];
407 $desc = $_REQUEST["hostdesc"];
409 $sql = "insert into hosts values (NULL, '$id', '$hip', '$hn', '$desc')";
410 $db->dbobject->query($sql);
412 header("Location: ?action=modsubnet&id=$id");
415 function www_ip_changesubdetails()
417 global $db, $wwwConnector;
419 $id = $_REQUEST["id"];
420 $name = $_REQUEST["subname"];
421 $desc = $_REQUEST["subdesc"];
423 $sql = "update subnet set sn_name='$name', sn_desc='$desc' where sn_id=='$id'";
424 $db->dbobject->query($sql);
426 header("Location: ?action=modsubnet&id=$id");
429 function www_db_dumpdb()
433 $datestamp = strftime("%d-%m-%Y-%H.%M.%S");
434 $name = "ipmandbdump-$datestamp.db";
435 header("Content-type: application/octet-stream;\n");
436 header("Content-Disposition: attachment; filename=\"$name\";\n\n");
440 function www_db_restoredb()