From: paulr Date: Tue, 9 Aug 2011 14:42:23 +0000 (+1000) Subject: not sure what i did, but you can bet it was AWESOME X-Git-Url: http://git.pjr.cc/?p=glcas.git;a=commitdiff_plain;h=e842b9e98acbc69ea55e655130b68df06f25b3cd not sure what i did, but you can bet it was AWESOME --- diff --git a/bin/pinghelper.php b/bin/pinghelper.php new file mode 100644 index 0000000..d1e8533 --- /dev/null +++ b/bin/pinghelper.php @@ -0,0 +1,56 @@ +loadConfig($configpath); + + +$range = ""; +if(isset($argv[1])) { + $range = $argv[1]; +} else { + echo "Need at least one ip address\n"; +} + +for($i=1; $i < $argc; $i++) { + echo "pinging ".$argv[$i]."\n"; + $ip = $argv[$i]; + $res = exec("/bin/ping -c 1 $ip 2>&1", $arr, $returned); + + if($returned != 0) { + $glconfig->delData("ping", "$ip"); + $glconfig->addData("ping", "$ip", time(), "failed"); + } else { + $res_v = preg_split("/[\/ ]+/",$res); + $rettime = $res_v[7]; + print_r($res_v); + $glconfig->delData("ping", "$ip"); + $glconfig->addData("ping", "$ip", time(), $rettime); + } +} + +?> \ No newline at end of file diff --git a/libglcas/config.php b/libglcas/config.php index 3f4588e..96345b2 100644 --- a/libglcas/config.php +++ b/libglcas/config.php @@ -57,7 +57,7 @@ class GLCASConfig { { $sql = "insert into datatable values (NULL, '$configType', '$configCat', '$configName', '$configVal')"; $this->dbobject->query($sql); - error_log("CONFIG: adddata as $sql"); + //error_log("CONFIG: adddata as $sql"); } function saveConfig() @@ -81,7 +81,7 @@ class GLCASConfig { } $sql = "select data_category,data_name,data_val from datatable $wheredata"; - error_log("CONFIG: get via $sql"); + //error_log("CONFIG: get via $sql"); $res = $this->dbobject->query($sql); @@ -108,7 +108,7 @@ class GLCASConfig { $sql = "delete from datatable where data_type='$configType' and data_category='$configCat' $extrawhere"; $this->dbobject->query($sql); - error_log("del all data was $sql"); + //error_log("del all data was $sql"); } function delAllDAta($configType, $configCat) @@ -116,7 +116,7 @@ class GLCASConfig { $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"); + //error_log("del all data was $sql"); } function setupTables() diff --git a/libglcas/web.php b/libglcas/web.php index 4f26a9b..e2f7627 100644 --- a/libglcas/web.php +++ b/libglcas/web.php @@ -167,7 +167,17 @@ function glcas_getLastSeen($ip, $data) if($last == "never") return $last; - $tdiff = time()-$last; + $last = glcas_tdiffToAgo(time()-$last); + + error_log("last for $ip set to $last"); + + return $last; + +} + +function glcas_tdiffToAgo($time_in_sec) +{ + $tdiff = $time_in_sec; $tdiff_min = (int)($tdiff/60); $tdiff_hour = (int)($tdiff/3600); $tdiff_days = (int)($tdiff/86400); @@ -177,10 +187,7 @@ function glcas_getLastSeen($ip, $data) if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago"; if($tdiff >= 86400) $last = "$tdiff_days days ago"; - error_log("last for $ip set to $last"); - return $last; - } function glcas_isRemoteDir($url) diff --git a/plugins/hosts.php b/plugins/hosts.php index 5b521cf..d2222b6 100644 --- a/plugins/hosts.php +++ b/plugins/hosts.php @@ -63,6 +63,8 @@ class GLCASHosts { $nhosts = 0; $group_to_do = null; $ngroups = 0; + $ping_host = null; + $nping = 0; // first check if nogroup is selected if(isset($_REQUEST["nonegroup-selected"])) { @@ -70,7 +72,7 @@ class GLCASHosts { $nogroup = true; } - foreach($groups as $key=>$val) { + if($groups !== false) foreach($groups as $key=>$val) { $grpname = $val["category"]; if(isset($_REQUEST["$grpname-selectgroup"])) { $group_to_do[$ngroups++] = $grpname; @@ -114,9 +116,28 @@ class GLCASHosts { if($operation == "delete") { $this->config->delData("hosts", "$hname", "$hip", "$hg"); } + if($operation == "ping") { + $ping_host[$nping++] = $hip; + } } } + if($operation == "ping") { + foreach($ping_host as $lip) { + $ips .= " $lip"; + } + + error_log("ping helper is going with $ips"); + + 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/pinghelper.php $ips > /tmp/ping 2>&1 &"; + system($scall); + } else { + error_log("cant find download helper... dieing"); + } + + } /*echo "total to do:
";
 		print_r($hosts_to_do);
 		print_r($_REQUEST);
@@ -247,6 +268,7 @@ class GLCASHosts {
 		echo "Selected hosts operation: ";
 		echo "Group HostIPLast SeenControl";
+		echo "";
 		foreach($hosts as $key => $val) {
 			$hname = $val["category"];
 			$hip = $val["name"];
 			$hg = $val["val"];
 			if($hg == "") $hg = "-";
 			if($hg=="-") {
+				$lastping_v = $this->config->getData("ping", $hip);
+				$lastping_o = $lastping_v[0];
+				if(!$lastping_v) $lastping = "None";
+				else {
+					if($lastping_o["val"] == "failed") {
+						$lastp_time = glcas_tdiffToAgo(time()-$lastping_o["name"]);
+						$lastping = "$lastp_time - Failed";
+					} else {
+						$lastp_time = glcas_tdiffToAgo(time()-$lastping_o["name"]);
+						$lping_delay = $lastping_o["val"];
+						$lastping = "$lastp_time - $lping_delay ms";
+					}
+				}
 				$lastseen = glcas_getLastSeen($hip, $this->config->getData("lastseen", "$hip"));
-				echo "";
+				echo "";
 			}
 		}
 		echo "
HostIPLast SeenLast PingControl
$hname$hip$lastseenDelete
$hname$hip$lastseen$lastpingDelete
"; @@ -285,15 +320,29 @@ class GLCASHosts { echo ""; $grpname = $val["category"]; echo "

Host Group: $grpname Delete


"; - echo ""; + echo "
HostIPLast SeenControl
"; if($hosts != false) foreach($hosts as $key => $val) { $hname = $val["category"]; $hip = $val["name"]; $hg = $val["val"]; if($hg == "") $hg = "-"; if($hg==$grpname) { + $lastping_v = $this->config->getData("ping", $hip); + $lastping_o = $lastping_v[0]; + if(!$lastping_v) $lastping = "None"; + else { + if($lastping_o["val"] == "failed") { + $lastp_time = glcas_tdiffToAgo(time()-$lastping_o["name"]); + $lastping = "$lastp_time - Failed"; + } else { + $lastp_time = glcas_tdiffToAgo(time()-$lastping_o["name"]); + $lping_delay = $lastping_o["val"]; + $lastping = "$lastp_time - $lping_delay ms"; + } + } + $lastseen = glcas_getLastSeen($hip, $this->config->getData("lastseen", "$hip")); - echo ""; + echo ""; } } echo "
HostIPLast SeenLast PingControl
$hname$hip$lastseenDelete
$hname$hip$lastseen$lastpingDelete
";