From 46533a511551e2d0f41434adbcaff4d2f057a0ab Mon Sep 17 00:00:00 2001 From: paulr Date: Mon, 13 Sep 2010 01:57:52 +1000 Subject: [PATCH] getting towards base functionality --- lib/db.php | 25 +++++++++ lib/ip.php | 98 +++++++++++++++++++++++++++++++----- lib/www.php | 129 +++++++++++++++++++++++++++++++++++++++++++++++- unittest/ip6tolong.php | 19 +++++++ 4 files changed, 256 insertions(+), 15 deletions(-) create mode 100644 unittest/ip6tolong.php diff --git a/lib/db.php b/lib/db.php index e7afc6e..05216dc 100644 --- a/lib/db.php +++ b/lib/db.php @@ -33,6 +33,31 @@ class db { } public $dbobject = ""; + + function dump() { + $sql = "select * from supernet"; + $res = $this->dbobject->query($sql); + + foreach($res as $row) { + echo "sn:".$row["sn_id"].":".$row["sn_name"].":".$row["sn_ip"].":".$row["sn_mask"].":".$row["sn_desc"]."\n"; + } + $sql = "select * from subnet"; + $res = $this->dbobject->query($sql); + + foreach($res as $row) { + echo "sbn:".$row["sn_id"].":".$row["snid_id"].":".$row["sn_name"].":".$row["sn_ip"].":".$row["sn_mask"].":".$row["sn_desc"]."\n"; + } + $sql = "select * from hosts"; + $res = $this->dbobject->query($sql); + + foreach($res as $row) { + echo "hst:".$row["ho_id"].":".$row["ho_sn_id"].":".$row["ho_ip"].":".$row["ho_name"].":".$row["ho_desc"]."\n"; + } + } + + function restore($restorefile) { + + } } diff --git a/lib/ip.php b/lib/ip.php index 6775fba..a0287f3 100644 --- a/lib/ip.php +++ b/lib/ip.php @@ -1,15 +1,70 @@ dbobject->query($sql); + return true; + } } - function isConflicting($subnet) + function isSubnet($subnet, $mask, $superid) { - + return true; + } + + // this function returns true if it is NOT conflicting + function isConflicting($subnet, $mask, $superid) + { + return true; } public $supers = ""; diff --git a/lib/www.php b/lib/www.php index 70274f5..f9648b9 100644 --- a/lib/www.php +++ b/lib/www.php @@ -3,8 +3,12 @@ $actionRegister["addsuper"] = "www_ip_addSuperRange"; $actionRegister["allocate"] = "www_ip_allocateRange"; $actionRegister["allocatesub"] = "www_ip_allocateSubRange"; +$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"; class www { function Go() { @@ -72,10 +76,25 @@ Description //echo "
";
 		//	print_r($row);
 		//	echo "

"; - echo ""; + echo "
".$row["sn_name"]."".$row["sn_ip"]."/".$row["sn_mask"]."".$row["sn_desc"]."
"; echo ""; echo ""; + echo ""; // now we search for sub's + $res2 = $db->dbobject->query("select * from subnet where snid_id='".$row["sn_id"]."'"); + foreach($res2 as $row2) { + // ("sn_id" INTEGER PRIMARY KEY AUTOINCREMENT,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);'; + $name = $row2["sn_name"]; + $subid = $row2["sn_id"]; + $subnet = $row2["sn_ip"]; + $mask = $row2["sn_mask"]; + $desc = $row2["sn_desc"]; + echo ""; + echo ""; + echo ""; + //echo ""; + echo ""; + } echo "
".$row["sn_name"]."".$row["sn_ip"]."::0/".$row["sn_mask"]."".$row["sn_desc"]."Allocate SubnetDelete Supernet
  • $name
  • $subnet::0/$mask$descDelete SubnetAdd Host

    "; } @@ -184,8 +203,116 @@ function www_ip_allocateSubRange() } } +function www_ip_modifySubnet() +{ + 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 = "select sn_name,sn_desc,sn_ip from subnet where sn_id=='$id'"; + $res = $db->dbobject->query($sql); + + foreach($res as $row) { + $sn_name = $row["sn_name"]; + $sn_desc = $row["sn_desc"]; + $sn_ip = $row["sn_ip"]; + } + + $wwwConnector->header(); + $wwwConnector->printError(); + + // ("ho_id" INTEGER PRIMARY KEY AUTOINCREMENT,"ho_sn_id" INTEGER,"ho_ip" TEXT,"ho_name" TEXT,"ho_desc" TEXT) + ?> +
    +Subnet Name: +Subnet Description: + +
    + +
    +

    Add Host

    +Hostname +IP Address "> +Description + +
    + + + + + +dbobject->query($sql); + + foreach($res as $row) { + $name = $row["ho_name"]; + $desc = $row["ho_desc"]; + $ip = $row["ho_ip"]; + $hid = $row["ho_id"]; + echo ""; + } +?> +
    Host IPHostnameDescription
    $ip$name$descDelete
    + + +Back +footer(); +} + +function www_ip_deletehost() +{ + global $db, $wwwConnector; + + $id = $_REQUEST["hostid"]; + $sid = $_REQUEST["snid"]; + + $sql = "delete from hosts where ho_id=='$id'"; + $db->dbobject->query($sql); + + header("Location: ?action=modsubnet&id=$sid"); +} + +function www_ip_addhost() +{ + global $db, $wwwConnector; + + $id = $_REQUEST["id"]; + $hn = $_REQUEST["hostname"]; + $hip = $_REQUEST["hostip"]; + $desc = $_REQUEST["hostdesc"]; + + $sql = "insert into hosts values (NULL, '$id', '$hip', '$hn', '$desc')"; + $db->dbobject->query($sql); + + header("Location: ?action=modsubnet&id=$id"); +} + +function www_ip_changesubdetails() +{ + global $db, $wwwConnector; + + $id = $_REQUEST["id"]; + $name = $_REQUEST["subname"]; + $desc = $_REQUEST["subdesc"]; + + $sql = "update subnet set sn_name='$name', sn_desc='$desc' where sn_id=='$id'"; + $db->dbobject->query($sql); + + header("Location: ?action=modsubnet&id=$id"); +} + function www_db_dumpdb() { + global $db; + + $datestamp = strftime("%d-%m-%Y-%H.%M.%S"); + $name = "ipmandbdump-$datestamp.db"; + header("Content-type: application/octet-stream;\n"); + header("Content-Disposition: attachment; filename=\"$name\";\n\n"); + $db->dump(); } function www_db_restoredb() diff --git a/unittest/ip6tolong.php b/unittest/ip6tolong.php new file mode 100644 index 0000000..d5ee6c8 --- /dev/null +++ b/unittest/ip6tolong.php @@ -0,0 +1,19 @@ + \ No newline at end of file -- 1.7.0.4