X-Git-Url: http://git.pjr.cc/?p=glcas.git;a=blobdiff_plain;f=plugins%2Fhosts.php;h=f2e8e44b26c9c92efda261e1dae2ade0b0c408c0;hp=76e3e59fb5fe68f98417260df95984d3d6872e5b;hb=28961382f5b6b9d0b97408af8bcce52fe214db22;hpb=f3baa0c9da025f9460610472f5fc8f5e37910d28 diff --git a/plugins/hosts.php b/plugins/hosts.php index 76e3e59..f2e8e44 100644 --- a/plugins/hosts.php +++ b/plugins/hosts.php @@ -22,11 +22,24 @@ class GLCASHosts { switch($_REQUEST["action"]) { case "addhost": error_log("in updaterepo"); - GLCASpageBuilder($this,"addPackage"); + GLCASpageBuilder($this,"addHost"); return; - case "delhost": - 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,276 @@ class GLCASHosts { } + function doOperation($url) + { + $operation = $_REQUEST["operation"]; + $groupop = $_REQUEST["groupop"]; + $hosts = $this->config->getData("hosts"); + $groups = $this->config->getData("hostgroups"); + + // first check if nogroup is selected + if(isset($_REQUEST["nonegroup-selected"])) { + echo "nonegroup operation
"; + } + + foreach($hosts as $key=>$val) { + $hname = $val["category"]; + $hip = $val["name"]; + $hg = $val["val"]; + if(isset($_REQUEST["$hname-selecthost"])) { + echo "Select host, $hname true
"; + } + } + + foreach($groups as $key=>$val) { + $grpname = $val["category"]; + if(isset($_REQUEST["$grpname-selectgroup"])) { + echo "Select group, $grpname true
"; + } + } + + } + + 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 + $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"); + + + } + } + echo "Finished"; + } + + 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
"; + return 0; + } + } + + $this->config->addData("hosts", "$hostname", "$ip", "$hg"); + + + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + header("Location: $BASE_URL/hosts"); + + } + + function addGroup($url) + { + $grpname = $_REQUEST["groupname"]; + $groups = $this->config->getData("hostgroups"); + + foreach($groups as $key => $val) { + if($val["category"] == $grpname) { + echo "Error: gorup already exists"; + return 0; + } + } + + $this->config->adddata("hostgroups", "$grpname", "", ""); + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + header("Location: $BASE_URL/hosts"); + + } + function mainBody($url) { - echo "I am a hosts thingy"; + $hosts = $this->config->getData("hosts"); + $groups = $this->config->getData("hostgroups"); + + $gs = 0; + echo "

Hosts and Groups

"; + echo "
"; + echo "Selected hosts operation: "; + echo "Group "; + echo ""; + + + echo ""; + + $gs++; + // fist print ungrouped + echo ""; + echo ""; + + if($groups) { + foreach($groups as $key=>$val) { + $gs++; + echo ""; + if(($gs%4)==0) echo ""; + } + } + + + 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 "
"; + $grpname = $val["category"]; + echo "

Host Group: $grpname Delete


"; + echo ""; + 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 "
"; + echo "
"; + + 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;