X-Git-Url: http://git.pjr.cc/?p=glcas.git;a=blobdiff_plain;f=plugins%2Fhosts.php;h=eb93989795df1cc96125aa20f833eb41ea0ff652;hp=a5709a56569040d54c60692f9b09a6e5d1f6e06e;hb=e45207eb04184d0ee4c7f7b77bbe74b599c1a003;hpb=486854e1f39db5dd0fe2f317d2a586dd6ac39124
diff --git a/plugins/hosts.php b/plugins/hosts.php
index a5709a5..eb93989 100644
--- a/plugins/hosts.php
+++ b/plugins/hosts.php
@@ -20,13 +20,26 @@ class GLCASHosts {
{
if(isset($_REQUEST["action"])) {
switch($_REQUEST["action"]) {
- case "addpackage":
+ case "addhost":
error_log("in updaterepo");
- GLCASpageBuilder($this,"addPackage");
+ GLCASpageBuilder($this,"addHost");
return;
- case "deletepkg":
- error_log("in delete pkg");
- GLCASpageBuilder($this, "delPackage");
+ case "addgroup":
+ error_log("in add group");
+ GLCASpageBuilder($this, "addGroup");
+ return;
+ case "deletehost":
+ error_log("in add group");
+ GLCASpageBuilder($this, "deleteHost");
+ return;
+ case "scanrange":
+ GLCASpageBuilder($this, "scanIPRange");
+ return;
+ case "delgroup":
+ GLCASpageBuilder($this, "deleteGroup");
+ return;
+ case "dooperation":
+ GLCASpageBuilder($this, "doOperation");
return;
}
}
@@ -36,9 +49,308 @@ class GLCASHosts {
}
+
+ // TODO: this whole function wont work correctly
+ // once we move to hosts being in multiple groups..
+ function doOperation($url)
+ {
+ $operation = $_REQUEST["operation"];
+ $groupop = $_REQUEST["groupop"];
+ $hosts = $this->config->getData("hosts");
+ $groups = $this->config->getData("hostgroups");
+ $nogroup = false;
+ $hosts_to_do = null;
+ $nhosts = 0;
+ $groups_to_do = null;
+ $ngroups = 0;
+
+ // first check if nogroup is selected
+ if(isset($_REQUEST["nonegroup-selected"])) {
+ //echo "nonegroup operation
";
+ $nogroup = true;
+ }
+
+ foreach($groups as $key=>$val) {
+ $grpname = $val["category"];
+ if(isset($_REQUEST["$grpname-selectgroup"])) {
+ $group_to_do[$ngroups++] = $grpname;
+
+ }
+ }
+
+ foreach($hosts as $key=>$val) {
+ $dohost = false;
+ $hname = $val["category"];
+ // this bits annoying TODO: find out why this happens
+ $thname = preg_replace("/\./", "_", $hname);
+ $hip = $val["name"];
+ $hg = $val["val"];
+
+ echo "
Checking $hname, $hip, $hg
";
+
+ // check if no group is on
+ if($nogroup && $hg == "") {
+ //echo "Set doing true on nogroup
";
+ $dohost = true;
+ }
+
+ // check if host was in a group selected
+ if($group_to_do !== null) foreach($group_to_do as $dothese) {
+ if($hg == $dothese) $dohost = true;
+ }
+
+ // directly selected hosts
+ if(isset($_REQUEST["$thname-selecthost"])) {
+ //echo "add host $hname
";
+ $dohost = true;
+ }
+
+ // now do the op
+ if($dohost) {
+ if($operation == "move") {
+ $this->config->delData("hosts", "$hname", "$hip", "$hg");
+ $this->config->addData("hosts", "$hname", "$hip", "$groupop");
+ }
+ if($operation == "delete") {
+ $this->config->delData("hosts", "$hname", "$hip", "$hg");
+ }
+ }
+ }
+
+ /*echo "total to do:
"; + print_r($hosts_to_do); + print_r($_REQUEST); + echo "";*/ + + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + header("Location: $BASE_URL/hosts"); + + + } + + function deleteGroup($url) + { + $grpname = $_REQUEST["grpname"]; + $this->config->delData("hostgroups", "$grpname"); + $hosts = $this->config->getData("hosts"); + foreach($hosts as $key=>$val) { + $hname = $val["category"]; + $hip = $val["name"]; + $hg = $val["val"]; + + if($hg == $grpname) { + $this->config->delData("hosts", "$hname", "$hip", "$hg"); + $this->config->addData("hosts", "$hname", "$hip", ""); + } + } + + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + header("Location: $BASE_URL/hosts"); + + } + + function scanIPRange($url) + { + $iprange = $_REQUEST["scanip"]; + $hostgroup = ""; + if(isset($_REQUEST["hostgroup"])) { + $hostgroup = $_REQUEST["hostgroup"]; + } + + // we just assume class c atm + error_log("background scanner, start"); + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + if(file_exists("$WEB_ROOT_FS/../bin/scanhelper.php")) { + $scall = "/usr/bin/php $WEB_ROOT_FS/../bin/scanhelper.php '$iprange' '$hostgroup' > /tmp/scanlog 2>&1 &"; + system($scall); + } else { + error_log("cant find download helper... dieing"); + } + + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + header("Location: $BASE_URL/hosts"); + + + } + + function deleteHost($url) + { + $hostname = $_REQUEST["hostname"]; + $this->config->delData("hosts", "$hostname"); + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + header("Location: $BASE_URL/hosts"); + } + + function addHost($url) + { + $hg = $_REQUEST["hostgroup"]; + $hostname = $_REQUEST["hostname"]; + $ip = $_REQUEST["ipaddr"]; + + if($hostname == "" && $ip == "") { + echo "Error: must have either ip or hostname\n"; + return 0; + } + + if($hostname == "") { + // try to lookup hostname from ip + $hostname = gethostbyaddr($ip); + } + + if($ip == "") { + // try to lookup ip from hostname + $ip = gethostbyname($hostname); + } + + $hosts = $this->config->getData("hosts"); + foreach($hosts as $key => $val) { + if($val["category"] == $hostname && $val["name"] == $ip) { + echo "Error: host already exists
";
+
+ // the add hosts dialog
+ echo "Add Host"; + echo ""; + + echo " | ";
+
+ // the add groups dialog
+ echo "Add Group"; + echo ""; + + echo " | ";
+ //scan ip range via dns
+ echo "Scan Range"; + echo ""; + + echo " |