X-Git-Url: http://git.pjr.cc/?p=glcas.git;a=blobdiff_plain;f=plugins%2Fhosts.php;h=eb93989795df1cc96125aa20f833eb41ea0ff652;hp=3634682eb4d1f4de9e86da7c6a4d5b5635887539;hb=e45207eb04184d0ee4c7f7b77bbe74b599c1a003;hpb=155c0a1bc81dff4fc1bb4bcebb754c961e457499 diff --git a/plugins/hosts.php b/plugins/hosts.php index 3634682..eb93989 100644 --- a/plugins/hosts.php +++ b/plugins/hosts.php @@ -35,6 +35,12 @@ class GLCASHosts { case "scanrange": GLCASpageBuilder($this, "scanIPRange"); return; + case "delgroup": + GLCASpageBuilder($this, "deleteGroup"); + return; + case "dooperation": + GLCASpageBuilder($this, "doOperation"); + return; } } @@ -43,6 +49,106 @@ 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"]; @@ -52,37 +158,19 @@ class GLCASHosts { } // we just assume class c atm - $ips_v = explode(".", $iprange); - - $ips = $ips_v[0].".".$ips_v[1].".".$ips_v[2]; - - for($i = 1; $i < 32; $i++) { - $hostname = ""; - $ips_me = "$ips.$i"; - echo "Scanning $ips_me
"; - error_log("Scanning $ips_me
"); - flush(); - $hostname = gethostbyaddr($ips_me); - if($hostname != $ips_me) { - echo "Found host on $ips_me as $hostname
"; - error_log("Found host on $ips_me as $hostname"); - flush(); - $hosts = $this->config->getData("hosts"); - $exists = false; - foreach($hosts as $key => $val) { - if($val["category"] == $hostname && $val["name"] == $ips_me) { - echo "Host in db already
"; - $exists = true; - flush(); - } - - } - if(!$exists) $this->config->addData("hosts", "$hostname", "$ips_me", "$hostgroup"); - - - } + 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"); } - echo "Finished"; + + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + header("Location: $BASE_URL/hosts"); + + } function deleteHost($url) @@ -153,37 +241,69 @@ class GLCASHosts { $hosts = $this->config->getData("hosts"); $groups = $this->config->getData("hostgroups"); - echo "

Hosts

"; - if($hosts) { - echo ""; - 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
"; + $gs = 0; + echo "

Hosts and Groups

"; + echo "
"; + echo "Selected hosts operation: "; + echo "Group "; + echo ""; + - // groups - echo "

Host Groups

"; + echo ""; + + $gs++; + // fist print ungrouped + echo ""; + echo ""; + if($groups) { - echo "
"; + echo "

Ungrouped Hosts


"; + echo ""; + foreach($hosts as $key => $val) { + $hname = $val["category"]; + $hip = $val["name"]; + $hg = $val["val"]; + if($hg == "") $hg = "-"; + if($hg=="-") echo ""; + } + echo "
HostIPHost GroupLast SeenControl
$hname$hip$hg...Delete
"; + echo "
"; foreach($groups as $key=>$val) { + $gs++; + echo ""; + echo "

Host Group: $grpname Delete


"; + echo "
Group Name
"; $grpname = $val["category"]; - echo "
$grpname
"; + if($hosts != false) foreach($hosts as $key => $val) { + $hname = $val["category"]; + $hip = $val["name"]; + $hg = $val["val"]; + if($hg == "") $hg = "-"; + if($hg==$grpname) echo ""; + } + echo "
HostIPHost GroupLast SeenControl
$hname$hip$hg...Delete
"; + echo ""; + if(($gs%4)==0) echo ""; } - echo ""; - } else { - echo "No host groups defined yet
"; } + + + echo ""; + echo "
"; + echo "
"; + echo "
"; // the add hosts dialog