From 155c0a1bc81dff4fc1bb4bcebb754c961e457499 Mon Sep 17 00:00:00 2001 From: paulr Date: Tue, 9 Aug 2011 04:44:02 +1000 Subject: [PATCH] hostgroup scanning works. --- libglcas/config.php | 44 +++++++---- libglcas/web.php | 2 +- plugins/adhoc.php | 159 ++++++++++++++++++++++++++++------------ plugins/hosts.php | 202 +++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 338 insertions(+), 69 deletions(-) diff --git a/libglcas/config.php b/libglcas/config.php index 499c97b..3f4588e 100644 --- a/libglcas/config.php +++ b/libglcas/config.php @@ -55,9 +55,9 @@ class GLCASConfig { function addData($configType, $configCat, $configName, $configVal) { - $sql = "insert into datatable values (NULL, '$configType', '$configCat', $configName', '$configVal')"; + $sql = "insert into datatable values (NULL, '$configType', '$configCat', '$configName', '$configVal')"; $this->dbobject->query($sql); - + error_log("CONFIG: adddata as $sql"); } function saveConfig() @@ -70,43 +70,53 @@ class GLCASConfig { $ret = null; $nret = 0; $haveWhere = false; + + $wheredata = "where data_type='$configType'"; if($configCat != "") { - $haveWhere = true; - $wheredata = "where data_category='$configCat'"; + $wheredata .= " and data_category='$configCat'"; } if($configName != "") { - if($haveWhere) { - $wheredata .= " and data_name='$configName'"; - } else { - $wheredata = "where data_name='$configName'"; - } + $wheredata .= " and data_name='$configName'"; } - $sql = "select data_val,data_category,data_name from datatable $wheredata"; + $sql = "select data_category,data_name,data_val from datatable $wheredata"; + error_log("CONFIG: get via $sql"); + $res = $this->dbobject->query($sql); foreach($res as $row) { - $ret[$nret]["val"] = $row[0]; - $ret[$nret]["cat"] = $row[1]; - $ret[$nret]["name"] = $row[2]; + $ret[$nret]["val"] = $row[2]; + $ret[$nret]["category"] = $row[0]; + $ret[$nret]["name"] = $row[1]; $nret++; } + if($nret == 0) return false; return $ret; } - function delData($configType, $configName, $configVal) + function delData($configType, $configCat, $configName="", $configVal="") { - $sql = "delete from datatable where data_type='$configType' and data_name='$configName' and data_val='$configVal')"; + $extrawhere = ""; + if($configName != "") { + $extrawhere = " and data_name='$configName'"; + } + if($configVal != "") { + $extrawhere .= " and data_val='$configVal'"; + } + $sql = "delete from datatable where data_type='$configType' and data_category='$configCat' $extrawhere"; $this->dbobject->query($sql); + + error_log("del all data was $sql"); } function delAllDAta($configType, $configCat) { - $sql = "delete from datatable where data_type='$configType' and data_name='$configName'"; + $sql = "delete from datatable where data_type='$configType' and data_category='$configCat'"; //echo "sql is $sql\n"; $this->dbobject->query($sql); + error_log("del all data was $sql"); } function setupTables() @@ -125,7 +135,7 @@ class GLCASConfig { $sql = 'CREATE TABLE "config" ( "configname" TEXT,"configvar" TEXT);'; $this->dbobject->query($sql); - $sql = 'CREATE TABLE "datatable" ("data_id" INTEGER PRIMARY KEY AUTOINCREMENT,"data_category" TEXT,"data_type" TEXT,"data_name" TEXT,"data_val" TEXT);'; + $sql = 'CREATE TABLE "datatable" ("data_id" INTEGER PRIMARY KEY AUTOINCREMENT,"data_type" TEXT,"data_category" TEXT,"data_name" TEXT,"data_val" TEXT);'; $this->dbobject->query($sql); $sql = 'CREATE TABLE sqlite_sequence(name,seq);'; diff --git a/libglcas/web.php b/libglcas/web.php index 96b787e..6f93f80 100644 --- a/libglcas/web.php +++ b/libglcas/web.php @@ -34,7 +34,7 @@ function GLCASMenuBuilder() { global $BASE_URL, $MENU_ITEMS; - sort($MENU_ITEMS); + ksort($MENU_ITEMS); ?> diff --git a/plugins/adhoc.php b/plugins/adhoc.php index 9bfbb65..7b56ef8 100644 --- a/plugins/adhoc.php +++ b/plugins/adhoc.php @@ -25,6 +25,17 @@ class GLCASAdhoc { function go($url) { + error_log("ADHOC: url is $url in"); + $tags = explode("/", $url); + if(isset($tags[1])) { + error_log("tags 1 is set: \"".$tags[1]."\""); + if($tags[1] != "") { + if($this->doPackageRequest($tags[1])) return 0; + } else { + GLCASpageBuilder($this, "doPackageList"); + return 0; + } + } if(isset($_REQUEST["action"])) { switch($_REQUEST["action"]) { case "addpackage": @@ -43,22 +54,31 @@ class GLCASAdhoc { } + function doPackageList() + { + echo "im a package list\n"; + } + + function doPackageRequest($package) + { + echo "i got a request for $package\n"; + + return true; + } + function delPackage($url) { $repostore = $this->config->getConfig("storagelocation"); $pkgid = $_REQUEST["pkgid"]; + $pkgname = $_REQUEST["pkgname"]; - $pkgs = unserialize($this->config->getConfig("adhocpackages")); - - if(isset($pkgs[$pkgid])) { - unset($pkgs[$pkgid]); - $this->config->setConfig("adhocpackages", serialize($pkgs)); - $this->config->saveConfig(); - } + $this->config->delAllData("adhocpkgdata", $pkgid); + $this->config->delData("adhoc", "pkglist", "$pkgname", "$pkgid"); global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; - header("Location: $BASE_URL/adhoc/"); + header("Location: $BASE_URL/adhoc"); + } @@ -67,10 +87,16 @@ class GLCASAdhoc { $repostore = $this->config->getConfig("storagelocation"); if(!isset($_REQUEST["pkgname"])) { - echo "Error: No package name set
"; + if(isset($_REQUEST["origpkg"])) if($_REQUEST["origpkg"] == -1) { + echo "Error: No package name set
"; + return 0; + } } if($_REQUEST["pkgname"] == "") { - echo "Error: Package name cant be blank
"; + if(isset($_REQUEST["origpkg"])) if($_REQUEST["origpkg"] == -1) { + echo "Error: Package name cant be blank
"; + return 0; + } } @@ -97,50 +123,63 @@ class GLCASAdhoc { if(!$uploaded && !$fileurl) { echo "Error: no uploaded file and no file url, you need one or the other buddy
"; + return 0; } $getfile = ""; if($fileurl) { $getfile = file_get_contents($_REQUEST["fileurl"]); - } + } if($uploaded||$fileurl) { echo "Got a file named $fname, $lname"; } - $pkgs = unserialize($this->config->getConfig("adhocpackages")); + $myname = $_REQUEST["pkgname"]; + $myarch = $_REQUEST["arch"]; + $mytype = $_REQUEST["type"]; + $myfileurl = $ultfileurl; + + if(isset($_REQUEST["origpkg"])) if($_REQUEST["origpkg"] != -1) { + $n = $_REQUEST["origpkg"]; + $this->config->addData("adhocpkgdata", "$n", "arch", $myarch); + $this->config->addData("adhocpkgdata", "$n", "type", $mytype); + $outputfile = "$repostore/adhoc/$n.$myarch.$mytype"; + if($uploaded) { + copy("$fname", "$outputfile"); + } else { + file_put_contents("$outputfile", $getfile); + } + + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + header("Location: $BASE_URL/adhoc"); + return 0; + } - $n = -1; - foreach($pkgs as $key => $var) { - $n = $key; + // assuming add a new + $n = 0; + $pkglist = $this->config->getData("adhoc", "pkglist"); + if($pkglist !== false) foreach($pkglist as $key => $val) { + $n = $val["name"]+1; } - $n++; + + error_log("would add package as $n"); - echo "Would add package as $n"; + $this->config->addData("adhoc", "pkglist", "$myname", $n); + $this->config->addData("adhocpkgdata", "$n", "arch", $myarch); + $this->config->addData("adhocpkgdata", "$n", "type", $mytype); - $pkgs[$n]["name"] = $_REQUEST["pkgname"]; - $pkgs[$n]["arch"] = $_REQUEST["arch"]; - $pkgs[$n]["type"] = $_REQUEST["type"]; - $pkgs[$n]["fileurl"] = $ultfileurl; - + + $outputfile = "$repostore/adhoc/$n.$myarch.$mytype"; if($uploaded) { - copy("$fname", "$repostore/adhoc/$n"); + copy("$fname", "$outputfile"); } else { - file_put_contents("$repostore/adhoc/$n", $fetfile); + file_put_contents("$outputfile", $getfile); } - $this->config->setConfig("adhocpackages", serialize($pkgs)); - $this->config->saveConfig(); - - echo "Done"; - - - echo "
";
-		print_r($_SERVER);
-		print_r($_FILES);
-		print_r($_REQUEST);
-		print_r($pkgs);
-		echo "
"; + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + header("Location: $BASE_URL/adhoc"); + } @@ -148,23 +187,51 @@ class GLCASAdhoc { { echo "

Packages

"; + /* TODO: to new config $pkgs = unserialize($this->config->getConfig("adhocpackages")); - echo "
Menu Home
"; - - foreach($pkgs as $key => $var) { - $name = $var["pkgname"]; - $arch = $var["arch"]; - $type = $var["type"]; - echo ""; + */ + $pkgs = $this->config->getData("adhoc"); + //print_r($pkgs); + if($pkgs !== false) { + echo "
NamePackage TypesArchitectureControl
$name$type$archAdd another arch Delete
"; + + foreach($pkgs as $key => $var) { + $name = $var["name"]; + $id = $var["val"]; + $arch_v = $this->config->getData("adhocpkgdata", $id, "arch"); + $arch = $arch_v[0]["val"]; + $type_v = $this->config->getData("adhocpkgdata", $id, "type"); + $type = $type_v[0]["val"]; + echo ""; + if(count($arch_v) > 1) { + for($i=1; $i < count($arch_v); $i++) { + $arch = $arch_v[$i]["val"]; + $type_v = $this->config->getData("adhocpkgdata", $id, "type"); + $type = $type_v[$i]["val"]; + echo ""; + } + } + } + echo "
NamePackage TypesArchitectureControl
$name$type$archDelete
$type$arch
"; } - echo "
"; - + $kos = getKnownOSList(); echo "
"; echo "

Add a Package


"; echo ""; - echo "Name or Add version of
"; + echo "Name "; + if($pkgs !== false) { + echo "or Add version of
"; + } + else echo "
"; echo "Arch
"; + foreach($hosts as $key => $val) { + $hname = $val["category"]; + $hip = $val["name"]; + $hg = $val["val"]; + if($hg == "") $hg = "-"; + echo ""; + } + echo "
HostIPHost GroupLast SeenControl
$hname$hip$hg...Delete
"; + } else { + echo "No hosts defined yet
"; + } + echo "
"; + + // groups + echo "

Host Groups

"; + if($groups) { + echo ""; + foreach($groups as $key=>$val) { + $grpname = $val["category"]; + echo ""; + } + echo "
Group Name
$grpname
"; + } else { + echo "No host groups defined yet
"; + } + echo "
"; + + + echo "
"; + + // the add hosts dialog + echo "

Add Host

"; + echo ""; + echo "Hostname:
"; + echo "IP Address:
"; + if($groups) { + echo "Host Group:
"; + } + echo ""; + echo ""; + + echo "
"; + + // the add groups dialog + echo "

Add Group

"; + echo "
"; + echo "Groupname:
"; + echo "
"; + echo "
"; + + echo "
"; + //scan ip range via dns + echo "

Scan Range

"; + echo "
"; + echo "Range (i.e. 10.1.2.0):
"; + if($groups) { + echo "Host Group:
"; + } + echo "
"; + echo "
"; + + echo "
"; + } private $config; -- 1.7.0.4