--- /dev/null
+<?php
+
+
+
+$WEB_ROOT_FS = realpath(dirname(__FILE__));
+$BASE_URL = dirname($_SERVER["PHP_SELF"]);
+
+global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+
+// add libglcas as if it were a path in ../libglcas
+if(file_exists("../libglcas")) {
+ $path = realpath($WEB_ROOT_FS."/../");
+ error_log("added glcas path as $path");
+ set_include_path(get_include_path().PATH_SEPARATOR.$path);
+}
+
+// include the based library
+require_once("libglcas/lib.php");
+
+// load plugins
+glcas_pluginLoader();
+
+// find our config
+$configpath = "";
+
+// TODO: do this better
+$configpath = glcas_getWebConfigPath();
+$glconfig = new GLCASConfig();
+$glconfig->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
{
$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()
}
$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);
$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)
$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()
$nhosts = 0;
$group_to_do = null;
$ngroups = 0;
+ $ping_host = null;
+ $nping = 0;
// first check if nogroup is selected
if(isset($_REQUEST["nonegroup-selected"])) {
$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;
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:<br><pre>";
print_r($hosts_to_do);
print_r($_REQUEST);
echo "Selected hosts operation: <select name=\"operation\">";
echo "<option value=\"move\">Move To</option>";
echo "<option value=\"delete\">Delete</option>";
+ echo "<option value=\"ping\">Ping</option>";
echo "</select>";
echo "Group <select name=\"groupop\">";
echo "<option value=\"\">None</option>";
echo "<tr valign=\"top\">";
echo "<td>";
echo "<h3>Ungrouped Hosts</h3><br>";
- echo "<table border=\"1\"><tr><th><input type=\"checkbox\" name=\"nonegroup-selected\"></th><th>Host</th><th>IP</th><th>Last Seen</th><th>Control</th></tr>";
+ echo "<table border=\"1\"><tr><th><input type=\"checkbox\" name=\"nonegroup-selected\"></th><th>Host</th><th>IP</th><th>Last Seen</th><th>Last Ping</th><th>Control</th></tr>";
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 - <font color=\"red\">Failed</font>";
+ } else {
+ $lastp_time = glcas_tdiffToAgo(time()-$lastping_o["name"]);
+ $lping_delay = $lastping_o["val"];
+ $lastping = "$lastp_time - <font color=\"green\">$lping_delay ms</font>";
+ }
+ }
$lastseen = glcas_getLastSeen($hip, $this->config->getData("lastseen", "$hip"));
- echo "<tr><td><input type=\"checkbox\" name=\"$hname-selecthost\"></td><td>$hname</td><td>$hip</td><td>$lastseen</td><td><a href=\"?action=deletehost&hostname=$hname\">Delete</a></tr>";
+ echo "<tr><td><input type=\"checkbox\" name=\"$hname-selecthost\"></td><td>$hname</td><td>$hip</td><td>$lastseen</td><td>$lastping</td><td><a href=\"?action=deletehost&hostname=$hname\">Delete</a></tr>";
}
}
echo "</table>";
echo "<td>";
$grpname = $val["category"];
echo "<h3>Host Group: $grpname <a href=\"?action=delgroup&grpname=$grpname\">Delete</a></h3><br>";
- echo "<table border=\"1\"><tr><th><input type=\"checkbox\" name=\"$grpname-selectgroup\"></th><th>Host</th><th>IP</th><th>Last Seen</th><th>Control</th></tr>";
+ echo "<table border=\"1\"><tr><th><input type=\"checkbox\" name=\"$grpname-selectgroup\"></th><th>Host</th><th>IP</th><th>Last Seen</th><th>Last Ping</th><th>Control</th></tr>";
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 - <font color=\"red\">Failed</font>";
+ } else {
+ $lastp_time = glcas_tdiffToAgo(time()-$lastping_o["name"]);
+ $lping_delay = $lastping_o["val"];
+ $lastping = "$lastp_time - <font color=\"green\">$lping_delay ms</font>";
+ }
+ }
+
$lastseen = glcas_getLastSeen($hip, $this->config->getData("lastseen", "$hip"));
- echo "<tr><td><input type=\"checkbox\" name=\"$hname-selecthost\"></td><td>$hname</td><td>$hip</td><td>$lastseen</td><td><a href=\"?action=deletehost&hostname=$hname\">Delete</a></tr>";
+ echo "<tr><td><input type=\"checkbox\" name=\"$hname-selecthost\"></td><td>$hname</td><td>$hip</td><td>$lastseen</td><td>$lastping</td><td><a href=\"?action=deletehost&hostname=$hname\">Delete</a></tr>";
}
}
echo "</table>";