not entirely sure, think its all the messaging components
[glcas.git] / plugins / hosts.php
index eb93989..ef63bbb 100644 (file)
@@ -5,8 +5,8 @@ error_log("hosts loaded");
 global $URL_HANDLERS;
 $URL_HANDLERS["hosts.*"] = "GLCASHosts";
 global $BASE_URL, $MENU_ITEMS;
-$MENU_ITEMS["30hosts"]["name"] = "Known Machines";
-$MENU_ITEMS["30hosts"]["link"] = "$BASE_URL/hosts";
+$MENU_ITEMS["10hosts"]["name"] = "Known Machines";
+$MENU_ITEMS["10hosts"]["link"] = "$BASE_URL/hosts";
 
 class GLCASHosts {
        function __construct($config)
@@ -28,10 +28,6 @@ class GLCASHosts {
                                        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;
@@ -39,6 +35,7 @@ class GLCASHosts {
                                        GLCASpageBuilder($this, "deleteGroup");
                                        return;
                                case "dooperation":
+                                       error_log("in do operation");
                                        GLCASpageBuilder($this, "doOperation");
                                        return;
                        }
@@ -61,8 +58,10 @@ class GLCASHosts {
                $nogroup = false;
                $hosts_to_do = null;
                $nhosts = 0;
-               $groups_to_do = null;
+               $group_to_do = null;
                $ngroups = 0;
+               $ping_host = null;
+               $nping = 0;
                
                // first check if nogroup is selected
                if(isset($_REQUEST["nonegroup-selected"])) {
@@ -70,7 +69,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;
@@ -86,7 +85,7 @@ class GLCASHosts {
                        $hip = $val["name"];
                        $hg = $val["val"];
                        
-                       echo "<br>Checking $hname, $hip, $hg<br>";
+                       //echo "<br>Checking $hname, $hip, $hg<br>";
                        
                        // check if no group is on
                        if($nogroup && $hg == "") {
@@ -112,11 +111,32 @@ class GLCASHosts {
                                        $this->config->addData("hosts", "$hname", "$hip", "$groupop");
                                }
                                if($operation == "delete") {
+                                       $this->config->delData("ping", "$hip");
+                                       $this->config->delData("lastseen", "$hip");
                                        $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);
@@ -173,14 +193,6 @@ class GLCASHosts {
                
        }
        
-       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"];
@@ -247,6 +259,7 @@ class GLCASHosts {
                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>";
@@ -265,13 +278,29 @@ class GLCASHosts {
                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>Host Group</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></tr>";
                foreach($hosts as $key => $val) {
                        $hname = $val["category"];
                        $hip = $val["name"];
                        $hg = $val["val"];
                        if($hg == "") $hg = "-";
-                       if($hg=="-") echo "<tr><td><input type=\"checkbox\" name=\"$hname-selecthost\"></td><td>$hname</td><td>$hip</td><td>$hg</td><td>...</td><td><a href=\"?action=deletehost&hostname=$hname\">Delete</a></tr>";
+                       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>$lastping</td></tr>";
+                       }
                }
                echo "</table>";
                echo "</td>";
@@ -282,13 +311,30 @@ class GLCASHosts {
                                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>Host Group</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></tr>";
                                if($hosts != false) foreach($hosts as $key => $val) {
                                        $hname = $val["category"];
                                        $hip = $val["name"];
                                        $hg = $val["val"];
                                        if($hg == "") $hg = "-";
-                                       if($hg==$grpname) echo "<tr><td><input type=\"checkbox\" name=\"$hname-selecthost\"></td><td>$hname</td><td>$hip</td><td>$hg</td><td>...</td><td><a href=\"?action=deletehost&hostname=$hname\">Delete</a></tr>";
+                                       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>$lastping</td></tr>";
+                                       }
                                }
                                echo "</table>";
                                echo "</td>";