--- /dev/null
+<?php
+
+require_once("lib.php");
+
+$db->connect();
+
+$fname = "/var/tmp/.phpipman.".time();
+
+if($argc != 2) {
+ echo "usage: ".$argv[0]." subnet-id";
+}
+
+$res = $db->dbobject->query("select * from subnet where sn_id='".$argv[1]."'");
+$id = $argv[1];
+
+foreach($res as $row) {
+ //("sn_id" INTEGER PRIMARY KEY AUTOINCREMENT,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);
+ $sn_ip = $row["sn_ip"];
+ $sn_mask = $row["sn_mask"];
+}
+
+if(ipversion($sn_ip)!=4) return;
+
+system("/usr/bin/nmap -oX $fname -sP $sn_ip/$sn_mask > /dev/null 2>&1");
+
+//$fname = "/var/tmp/.phpipman.1284344553";
+echo "Output in $fname\n";
+
+$sml = simplexml_load_file("$fname");
+
+foreach($sml as $row => $key) {
+ //echo "row: $row\n";
+ if($row == "host") {
+ //print_r($key);
+ $status = $key->status["state"];
+ $ha = $key->address["addr"];
+ //echo "host address: $ha\n";
+ $hname = "";
+ if(isset($key->hostnames->hostname["name"])) {
+ //echo "was set: ".$key->hostnames->hostname["name"]."\n";
+ //exit(0);
+ $hname = $key->hostnames->hostname["name"];
+ }
+
+ //"hosts" ("ho_id" INTEGER PRIMARY KEY AUTOINCREMENT,"ho_sn_id" INTEGER,"ho_ip" TEXT,"ho_name" TEXT,"ho_desc" TEXT);';
+ $doadd = false;
+ if($status == "up") {
+ $doadd = true;
+ if($hname == "") $hname = $ha;
+ echo "up: $ha, $hname\n";
+ } else {
+ if($hname != "") {
+ $doadd = true;
+ echo "down: $ha, $hname\n";
+ }
+ }
+
+ if($doadd) {
+ $sql = "delete from hosts where ho_ip=='$ha'";
+ $db->dbobject->query($sql);
+ $sql = "insert into hosts values (NULL, '$id', '$ha', '$hname', '')";
+ $db->dbobject->query($sql);
+ echo "added, $ha, $hname\n";
+ }
+ }
+
+}
+unlink($fname);
+
+?>
\ No newline at end of file
$actionRegister["addsuper"] = "www_ip_addSuperRange";
$actionRegister["allocate"] = "www_ip_allocateRange";
$actionRegister["allocatesub"] = "www_ip_allocateSubRange";
+$actionRegister["deletesub"] = "www_ip_deleteSubRange";
$actionRegister["modsubnet"] = "www_ip_modifySubnet";
$actionRegister["dumpdb"] = "www_db_dumpdb";
$actionRegister["restoredb"] = "www_db_restoredb";
$actionRegister["changesubdetails"] = "www_ip_changesubdetails";
$actionRegister["addhosts"] = "www_ip_addhost";
$actionRegister["deletehost"] = "www_ip_deletehost";
+$actionRegister["modifyhost"] = "www_ip_modifyhost";
+$actionRegister["updatehost"] = "www_ip_updatehost";
+$actionRegister["scansub"] = "www_ip_scansub";
+$actionRegister["scansubreal"] = "www_ip_scansubReal";
class www {
function Go() {
$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 align=\"left\">".$row["sn_name"]."</th><td>".$row["sn_ip"]."::0/".$row["sn_mask"]."</td><td>".$row["sn_desc"]."</td>";
+ // print_r($row);
+ // echo "</pre><hr>";
+ if(ipversion($row["sn_ip"]) == 6) $ip6trans = "::0";
+ else $ip6trans = "";
+ 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>";
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>";
echo "</tr>";
$subnet = $row2["sn_ip"];
$mask = $row2["sn_mask"];
$desc = $row2["sn_desc"];
+
+ if(ipversion($row2["sn_ip"]) == 6) $ip6trans = "::0";
+ else $ip6trans = "";
+
echo "<tr>";
- echo "<td><li> <i><a href=\"?action=modsubnet&id=".$row2["sn_id"]."\">$name</a></i></td><td>$subnet::0/$mask</td><td>$desc</td>";
+ echo "<td><li> <i><a href=\"?action=modsubnet&id=".$row2["sn_id"]."\">$name</a></i></td><td>$subnet$ip6trans/$mask</td><td>$desc</td>";
echo "<td><a href=\"?action=deletesub&id=".$row2["sn_id"]."\">Delete Subnet</a></td>";
//echo "<td><a href=\"?action=addhost&id=".$row["sn_id"]."\">Add Host</a></td>";
+ if(ipversion($row2["sn_ip"]) == 4) echo "<td><a href=\"?action=scansub&id=".$row2["sn_id"]."\">Scan Subnet</a></td>";
echo "</tr>";
}
echo "</table><br>";
function footer()
{
+ echo "<pre>";
+ //print_r($_SERVER);
+
+ //print_r($_REQUEST);
+
+ //print_r($GLOBALS);
+ echo "</pre>";
?>
</body></html>
<?php
}
}
+function www_ip_scansub()
+{
+ global $db, $wwwConnector;
+
+ $id = $_REQUEST["id"];
+
+ $res = $db->dbobject->query("select * from subnet where sn_id=='$id'");
+
+ foreach($res as $row) {
+ $snip = $row["sn_ip"];
+ $snmask = $row["sn_mask"];
+ $snname = $row["sn_name"];
+ }
+ $wwwConnector->header();
+ $wwwConnector->printError();
+
+?>
+You are about to scan the subnet <?php echo "$snname ($snip/$snmask)" ?> how would you like entries added:<br>
+<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)
+<li> <a href="index.php?action=scansubreal&id=<?php echo $id?>&method=2">Replace</a> all entries where hosts are UP (reply to ping)
+<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
+<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
+<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
+<?php
+
+ $wwwConnector->footer();
+}
+
+function www_ip_scansubReal()
+{
+ global $db, $wwwConnector;
+
+ $id = $_REQUEST["id"];
+
+ system("/usr/bin/php ../lib/runscan.php $id > /tmp/out.phpipman 2>&1 &");
+ error_log("would exec... nmap -sP -oX $fname $sn/$sm");
+
+ header("Location: index.php");
+}
+
function www_ip_addSuperRange()
{
global $db;
$wwwConnector->footer();
}
+function www_ip_deleteSubRange()
+{
+ global $db, $wwwConnector;
+
+ $id = $_REQUEST["id"];
+ //("sn_id" INTEGER PRIMARY KEY AUTOINCREMENT,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);';
+ $sql = "delete from subnet where sn_id=='$id'";
+ $res = $db->dbobject->query($sql);
+
+ header("Location: index.php?notice=Deleted\n");
+}
+
function www_ip_allocateSubRange()
{
global $db, $wwwConnector;
<form method="post" action="?action=addhosts&id=<?php echo $id ?>">
<h3>Add Host</h3>
Hostname <input type="text" name="hostname">
-IP Address <input type="text" name="hostip" value="<?php echo $sn_ip.":"?>">
+IP Address <input type="text" name="hostip" value="<?php echo $sn_ip?>">
Description <input type="text" name="hostdesc" >
<input type="submit" name="change" value="Add">
</form>
$desc = $row["ho_desc"];
$ip = $row["ho_ip"];
$hid = $row["ho_id"];
- echo "<tr><td>$ip</td><td>$name</td><td>$desc</td><td><a href=\"?action=deletehost&hostid=$hid&snid=$id\">Delete</a></td></tr>";
+ 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>";
}
?>
</table>
$wwwConnector->footer();
}
+function www_ip_updatehost()
+{
+ global $db, $wwwConnector;
+
+ $hname = $_REQUEST["hostname"];
+ $hip = $_REQUEST["hostip"];
+ $hdesc = $_REQUEST["hostdesc"];
+ $sid = $_REQUEST["superid"];
+ $hid = $_REQUEST["hid"];
+
+ // ("ho_id" INTEGER PRIMARY KEY AUTOINCREMENT,"ho_sn_id" INTEGER,"ho_ip" TEXT,"ho_name" TEXT,"ho_desc" TEXT)
+ $sql = "update hosts set ho_name='$hname',ho_ip='$hip',ho_desc='$hdesc' where ho_id='$hid'";
+ $db->dbobject->query($sql);
+
+ header("Location: ?action=modsubnet&id=$sid");
+}
+
+function www_ip_modifyhost()
+{
+ global $db, $wwwConnector;
+
+ $id = $_REQUEST["hid"];
+
+ $res = $db->dbobject->query("select * from hosts where ho_id=='$id'");
+
+ foreach($res as $row) {
+ $hname = $row["ho_name"];
+ $hip = $row["ho_ip"];
+ $sid = $row["ho_sn_id"];
+ $hdesc = $row["ho_desc"];
+ }
+
+ $wwwConnector->header();
+ $wwwConnector->printError();
+ ?>
+<form method="post" action="?action=updatehost&hid=<?php echo $id ?>">
+<input type="hidden" name="superid" value="<?php echo $sid ?>">
+<table>
+<tr><td>Host Name</td><td><input type="text" name="hostname" value="<?php echo $hname?>"></td></tr>
+<tr><td>Host IP</td><td><input type="text" name="hostip" value="<?php echo $hip?>"></td></tr>
+<tr><td>Description</td><td><input type="text" name="hostdesc" value="<?php echo $hdesc?>"></td></tr>
+<tr><td><input type="submit" name="add" value="Update"></td></tr>
+</table>
+</form>
+<a href="<?php echo $_SERVER["HTTP_REFERER"]?>">Back</a>
+<?php
+
+ $wwwConnector->footer();
+}
+
function www_ip_deletehost()
{
global $db, $wwwConnector;