Compare commits
20 Commits
6aee52c717
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 9436fe7c60 | |||
| b84ca3e4e4 | |||
| 79a944c0e3 | |||
| a1e314b00c | |||
| e169c19bd0 | |||
| d43842790a | |||
|
|
5d3bfbc491 | ||
| 72fe3d8335 | |||
| 3c461d4570 | |||
|
|
07678cacd4 | ||
| 625c246ba9 | |||
| 8aaf241075 | |||
| 68e726fae3 | |||
|
|
1dc3c4a557 | ||
|
|
cffcb3ea64 | ||
|
|
a8e21ef76c | ||
|
|
f868d991b1 | ||
|
|
a8e4ddb2e0 | ||
|
|
8ac143be27 | ||
|
|
f0399c9c9d |
@@ -1,5 +1,5 @@
|
|||||||
# RemoteSupport
|
# RemoteSupport
|
||||||
GLPI Plugin for direct VNC connection from browser inside computer from server
|
GLPI Plugin for direct VNC connection from browser inside computer from server and update status of online computers, it checks computer with go program in glpi cron and with fusion inventory agent...
|
||||||
|
|
||||||
This Plugin add a simple button inside computer:
|
This Plugin add a simple button inside computer:
|
||||||
|
|
||||||
|
|||||||
BIN
bin/check_status
BIN
bin/check_status
Binary file not shown.
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -116,8 +117,15 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
// str_debug := os.Getenv("debug")
|
||||||
|
str_threads := os.Getenv("threads")
|
||||||
|
|
||||||
|
threads, _ := strconv.Atoi(str_threads)
|
||||||
|
// debug, _ := strconv.ParseBool(str_debug)
|
||||||
|
|
||||||
//startTime := time.Now()
|
//startTime := time.Now()
|
||||||
results := boundedParallelGet(checks, 100)
|
results := boundedParallelGet(checks, threads)
|
||||||
//seconds := time.Since(startTime).Seconds()
|
//seconds := time.Since(startTime).Seconds()
|
||||||
//tmplate := "requests: %d/%d in %v"
|
//tmplate := "requests: %d/%d in %v"
|
||||||
|
|
||||||
|
|||||||
15
hook.php
15
hook.php
@@ -25,7 +25,17 @@ function plugin_remotesupport_install()
|
|||||||
{
|
{
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
Toolbox::logInFile("remotsupport", "Installing plugin");
|
$config = new Config();
|
||||||
|
$config->setConfigurationValues('plugin:Remotesupport',
|
||||||
|
['run_mode' => 'None',
|
||||||
|
'threads' => 100,
|
||||||
|
'show_in_tickets' => true,
|
||||||
|
'show_in_computers' => true,
|
||||||
|
'easy_novnc' => true,
|
||||||
|
'fusion' => true]
|
||||||
|
);
|
||||||
|
|
||||||
|
Toolbox::logInFile("remotesupport", "Installing plugin");
|
||||||
$state_online = [
|
$state_online = [
|
||||||
'name' => 'Online',
|
'name' => 'Online',
|
||||||
'entities_id' => 0,
|
'entities_id' => 0,
|
||||||
@@ -94,8 +104,9 @@ function plugin_remotesupport_uninstall()
|
|||||||
function plugin_remotesupport_postinit()
|
function plugin_remotesupport_postinit()
|
||||||
{
|
{
|
||||||
global $CFG_GLPI, $DB;
|
global $CFG_GLPI, $DB;
|
||||||
|
$config = Config::getConfigurationValues('plugin:Remotesupport');
|
||||||
|
|
||||||
if (isset($_GET['id']) && $_GET['id'] != 0 && isset($_GET['_itemtype']) && $_GET['_itemtype'] == "Ticket") {
|
if (isset($_GET['id']) && $_GET['id'] != 0 && isset($_GET['_itemtype']) && $_GET['_itemtype'] == "Ticket" && $config["show_in_tickets"]) {
|
||||||
$id = $_GET['id'];
|
$id = $_GET['id'];
|
||||||
|
|
||||||
//mysql> select * from glpi_tickets_users where tickets_id = 2 and type = 1;
|
//mysql> select * from glpi_tickets_users where tickets_id = 2 and type = 1;
|
||||||
|
|||||||
112
inc/config.class.php
Normal file
112
inc/config.class.php
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* @version $Id$
|
||||||
|
-------------------------------------------------------------------------
|
||||||
|
GLPI - Gestionnaire Libre de Parc Informatique
|
||||||
|
Copyright (C) 2003-2011 by the INDEPNET Development Team.
|
||||||
|
http://indepnet.net/ http://glpi-project.org
|
||||||
|
-------------------------------------------------------------------------
|
||||||
|
LICENSE
|
||||||
|
This file is part of GLPI.
|
||||||
|
GLPI is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
GLPI is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PluginRemotesupportConfig extends CommonDBTM {
|
||||||
|
|
||||||
|
static protected $notable = true;
|
||||||
|
|
||||||
|
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
|
||||||
|
|
||||||
|
if (!$withtemplate) {
|
||||||
|
if ($item->getType() == 'Config') {
|
||||||
|
return __('Remote Support plugin');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
static function configUpdate($input) {
|
||||||
|
$input['configuration'] = 1 - $input['configuration'];
|
||||||
|
return $input;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showFormRemotesupport() {
|
||||||
|
global $CFG_GLPI;
|
||||||
|
|
||||||
|
if (!Session::haveRight("config", UPDATE)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$my_config = Config::getConfigurationValues('plugin:Remotesupport');
|
||||||
|
|
||||||
|
echo "<form name='form' action=\"".Toolbox::getItemTypeFormURL('Config')."\" method='post'>";
|
||||||
|
echo "<div class='center' id='tabsbody'>";
|
||||||
|
echo "<table class='tab_cadre_fixe'>";
|
||||||
|
echo "<input type='hidden' name='config_class' value='".__CLASS__."'>";
|
||||||
|
echo "<input type='hidden' name='config_context' value='plugin:Remotesupport'>";
|
||||||
|
echo "<tr><th colspan='4'>" . __('Remote support setup') . "</th></tr>";
|
||||||
|
echo "<tr>";
|
||||||
|
echo "<td >" . __('Run Mode:') . "</td>";
|
||||||
|
echo "<td>";
|
||||||
|
Dropdown::showFromArray('run_mode', array('None' => __('None'),'Serial'=>__('Serial'),'Parallel' => __('Parallel')), array('value' => $my_config['run_mode']));
|
||||||
|
echo "</td>";
|
||||||
|
echo "<td >" . __('EasyNoVNC Installed:') . "</td>";
|
||||||
|
echo "<td>";
|
||||||
|
Dropdown::showYesNo("easy_novnc", $my_config['easy_novnc']);
|
||||||
|
echo "</td></tr>";
|
||||||
|
echo "<tr>";
|
||||||
|
echo "<td >" . __('Show in Computers:') . "</td>";
|
||||||
|
echo "<td>";
|
||||||
|
Dropdown::showYesNo("show_in_computers", $my_config['show_in_computers']);
|
||||||
|
echo "</td>";
|
||||||
|
echo "<td >" . __('Show in Tickets:') . "</td>";
|
||||||
|
echo "<td>";
|
||||||
|
Dropdown::showYesNo("show_in_tickets", $my_config['show_in_tickets']);
|
||||||
|
echo "</td>";
|
||||||
|
echo "</tr>";
|
||||||
|
|
||||||
|
echo "<tr>";
|
||||||
|
echo "<td >" . __('Threads:') . "</td>";
|
||||||
|
echo "<td>";
|
||||||
|
Dropdown::showNumber("threads",
|
||||||
|
[
|
||||||
|
'value' => 100,
|
||||||
|
'min' => 1,
|
||||||
|
'max' => 100
|
||||||
|
]);
|
||||||
|
echo "</td>";
|
||||||
|
echo "<td >" . __('Fusion inventory:') . "</td>";
|
||||||
|
echo "<td>";
|
||||||
|
Dropdown::showYesNo("fusion", $my_config['fusion']);
|
||||||
|
echo "</td>";
|
||||||
|
|
||||||
|
echo "</tr>";
|
||||||
|
|
||||||
|
echo "<tr class='tab_bg_2'>";
|
||||||
|
echo "<td colspan='4' class='center'>";
|
||||||
|
echo "<input type='submit' name='update' class='submit' value=\""._sx('button', 'Save')."\">";
|
||||||
|
echo "</td></tr>";
|
||||||
|
|
||||||
|
echo "</table></div>";
|
||||||
|
Html::closeForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
|
||||||
|
|
||||||
|
if ($item->getType() == 'Config') {
|
||||||
|
$config = new self();
|
||||||
|
$config->showFormRemotesupport();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,13 +8,19 @@ global $DB, $agents;
|
|||||||
|
|
||||||
$check_arr = [];
|
$check_arr = [];
|
||||||
$comps = [];
|
$comps = [];
|
||||||
|
|
||||||
|
$rs_path = Plugin::getPhpDir('remotesupport');
|
||||||
|
|
||||||
|
$pfConfig = new PluginFusioninventoryConfig();
|
||||||
|
$port = $pfConfig->getValue('agent_port');
|
||||||
|
|
||||||
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
|
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
|
||||||
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
|
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
|
||||||
|
|
||||||
$check = [];
|
$check = [];
|
||||||
$a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($a["computers_id"]);
|
$a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($a["computers_id"]);
|
||||||
|
|
||||||
$check["url"] = "http://" . $a_computerextend["remote_addr"] . ":62354/status";
|
$check["url"] = "http://" . $a_computerextend["remote_addr"] . ":" . $port . "/status";
|
||||||
$check["id"] = $a["id"];
|
$check["id"] = $a["id"];
|
||||||
$check["computers_id"] = $a["computers_id"];
|
$check["computers_id"] = $a["computers_id"];
|
||||||
$check["status"] = "unknown";
|
$check["status"] = "unknown";
|
||||||
@@ -31,9 +37,9 @@ $descriptorspec = array(
|
|||||||
);
|
);
|
||||||
|
|
||||||
$cwd = '/tmp';
|
$cwd = '/tmp';
|
||||||
$env = array('debug' => 'false');
|
$env = array('debug' => 'false', 'threads' => 100);
|
||||||
|
|
||||||
$process = proc_open(__DIR__ . '/check_status', $descriptorspec, $pipes, $cwd, $env);
|
$process = proc_open($rs_path . '/bin/check_status', $descriptorspec, $pipes, $cwd, $env);
|
||||||
|
|
||||||
if (is_resource($process)) {
|
if (is_resource($process)) {
|
||||||
// $pipes now looks like this:
|
// $pipes now looks like this:
|
||||||
@@ -62,24 +68,21 @@ $ret = $req->next();
|
|||||||
$states_ids[$ret['name']] = $ret['id'];
|
$states_ids[$ret['name']] = $ret['id'];
|
||||||
print_r($states_ids);
|
print_r($states_ids);
|
||||||
|
|
||||||
$DB->update("glpi_computers", [
|
$DB->update("glpi_computers", [
|
||||||
'states_id' => $states_ids["Offline"]],
|
'states_id' => $states_ids["Offline"] ] ,
|
||||||
['1' => '1']
|
[ '1' => '1' ]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$ids = [];
|
||||||
foreach ($checked as $s) {
|
foreach ($checked as $s) {
|
||||||
echo $s->computers_id . " ";
|
echo $s->computers_id."\n";
|
||||||
|
$ids[] = $s->computers_id;
|
||||||
$comp = new Computer();
|
|
||||||
$comp->getFromDB($s->computers_id);
|
|
||||||
$comp->fields["states_id"] = $states_ids["Online"];
|
|
||||||
$DB->update("glpi_computers", [
|
|
||||||
'states_id' => $comp->fields["states_id"]],
|
|
||||||
['id' => $s->computers_id]
|
|
||||||
);
|
|
||||||
echo $comp->fields["contact"] . "\n";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$DB->update("glpi_computers", [
|
||||||
|
'states_id' => $states_ids["Online"] ],
|
||||||
|
[ 'id' => $ids ]
|
||||||
|
);
|
||||||
|
|
||||||
// print_r($a_computerextend);
|
// print_r($a_computerextend);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|||||||
@@ -9,17 +9,27 @@ class PluginRemotesupportRemotesupport extends CommonDBTM
|
|||||||
public static function showInfo($item)
|
public static function showInfo($item)
|
||||||
{
|
{
|
||||||
|
|
||||||
$fi_path = Plugin::getWebDir('fusioninventory');
|
$config = Config::getConfigurationValues('plugin:Remotesupport');
|
||||||
|
|
||||||
// Manage locks pictures
|
if ($config["show_in_computers"] == false) {
|
||||||
PluginFusioninventoryLock::showLockIcon('Computer');
|
|
||||||
|
|
||||||
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
|
|
||||||
$a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($item->getID());
|
|
||||||
if (empty($a_computerextend)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$statusids = self::getStatusArray();
|
||||||
|
|
||||||
|
if ($config["fusion"] == true && $config["easy_novnc"] == true) {
|
||||||
|
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
|
||||||
|
$a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($item->getID());
|
||||||
|
if (empty($a_computerextend)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$href = "https://" . $_SERVER['SERVER_NAME'] . "/vnc.html?path=vnc%2F" . $a_computerextend['remote_addr'] . "&autoconnect=true&resize=scale&reconnect=true&show_dot=true";
|
||||||
|
$name = $a_computerextend['remote_addr'];
|
||||||
|
} else {
|
||||||
|
$href = "vnc://" . $item->fields["name"];
|
||||||
|
$name = $item->fields["name"];
|
||||||
|
}
|
||||||
echo '<table class="tab_glpi" width="100%">';
|
echo '<table class="tab_glpi" width="100%">';
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
echo '<th>' . __('Remote Support') . '</th>';
|
echo '<th>' . __('Remote Support') . '</th>';
|
||||||
@@ -27,7 +37,8 @@ class PluginRemotesupportRemotesupport extends CommonDBTM
|
|||||||
echo '<tr class="tab_bg_1">';
|
echo '<tr class="tab_bg_1">';
|
||||||
echo '<td>';
|
echo '<td>';
|
||||||
|
|
||||||
$url = "<a target=\"_blank\" href=\"https://" . $_SERVER['SERVER_ADDR'] . "/vnc.html?path=vnc%2F" . $a_computerextend['remote_addr'] . "&autoconnect=true&resize=scale&reconnect=true&show_dot=true\"><li class=\"document\"><i class=\"fa fa-laptop-medical\"></i>" . $a_computerextend['remote_addr'] . "</li></a>";
|
$style = $statusids[$item->getID()] == "Offline" ? "style=\"background-color: red\"" : "";
|
||||||
|
$url = "<a target=\"_blank\" href=\"" . $href . "\"><li class=\"document\" ". $style ."><i class=\"fa fa-laptop-medical\"></i>" . $name . "</li></a>";
|
||||||
|
|
||||||
if ($url != "") {
|
if ($url != "") {
|
||||||
echo "<div><ul class=\"timeline_choices\"><h2>VNC connect : </h2>";
|
echo "<div><ul class=\"timeline_choices\"><h2>VNC connect : </h2>";
|
||||||
@@ -56,58 +67,125 @@ class PluginRemotesupportRemotesupport extends CommonDBTM
|
|||||||
return $states_ids;
|
return $states_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getContactArray()
|
||||||
|
{
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$req = $DB->request('glpi_computers', ['FIELDS' => ['glpi_computers' => ['id', 'contact']]]);
|
||||||
|
|
||||||
|
$contactids = [];
|
||||||
|
while ($ret = $req->next()) {
|
||||||
|
$contactids[$ret["id"]] = $ret["contact"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $contactids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getStatusArray()
|
||||||
|
{
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$st = self::getStatesIds();
|
||||||
|
|
||||||
|
$req = $DB->request('glpi_computers', ['FIELDS' => ['glpi_computers' => ['id', 'states_id']]]);
|
||||||
|
|
||||||
|
$statusids = [];
|
||||||
|
while ($ret = $req->next()) {
|
||||||
|
$statusids[$ret["id"]] = $ret["states_id"] == $st["Offline"] ? "Offline" : "Online";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $statusids;
|
||||||
|
}
|
||||||
|
|
||||||
public static function cronRemotesupport($task)
|
public static function cronRemotesupport($task)
|
||||||
{
|
{
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
Toolbox::logInFile("remotsupport", "Starting search of agents\n");
|
$config = Config::getConfigurationValues('plugin:Remotesupport');
|
||||||
|
|
||||||
$check_arr = [];
|
if ($config["fusion"] == false || $config["run_mode"] == "None") {
|
||||||
$comps = [];
|
return 0;
|
||||||
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
|
|
||||||
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
|
|
||||||
|
|
||||||
$check = [];
|
|
||||||
$a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($a["computers_id"]);
|
|
||||||
|
|
||||||
$check["url"] = "http://" . $a_computerextend["remote_addr"] . ":62354/status";
|
|
||||||
$check["id"] = $a["id"];
|
|
||||||
$check["computers_id"] = $a["computers_id"];
|
|
||||||
$check["status"] = "unknown";
|
|
||||||
|
|
||||||
$check_arr[] = $check;
|
|
||||||
$comps[$a["computers_id"]] = $check;
|
|
||||||
//print_r($agent->getAgentStatusURLs());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$descriptorspec = array(
|
Toolbox::logInFile("remotesupport", "Starting search of agents\n");
|
||||||
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
|
|
||||||
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
|
|
||||||
2 => array("file", "/tmp/error-output.txt", "a"), // stderr is a file to write to
|
|
||||||
);
|
|
||||||
|
|
||||||
$cwd = '/tmp';
|
if ($config["run_mode"] == "Parallel") {
|
||||||
$env = array('debug' => 'false');
|
$pfConfig = new PluginFusioninventoryConfig();
|
||||||
|
$port = $pfConfig->getValue('agent_port');
|
||||||
|
$rs_path = Plugin::getPhpDir('remotesupport');
|
||||||
|
|
||||||
$process = proc_open(__DIR__ . '/../bin/check_status', $descriptorspec, $pipes, $cwd, $env);
|
$check_arr = [];
|
||||||
|
$comps = [];
|
||||||
|
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
|
||||||
|
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
|
||||||
|
|
||||||
if (is_resource($process)) {
|
$check = [];
|
||||||
// $pipes now looks like this:
|
$a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($a["computers_id"]);
|
||||||
// 0 => writeable handle connected to child stdin
|
|
||||||
// 1 => readable handle connected to child stdout
|
|
||||||
// Any error output will be appended to /tmp/error-output.txt
|
|
||||||
|
|
||||||
fwrite($pipes[0], json_encode($check_arr));
|
$check["url"] = "http://" . $a_computerextend["remote_addr"] . ":" . $port . "/status";
|
||||||
fclose($pipes[0]);
|
$check["id"] = $a["id"];
|
||||||
|
$check["computers_id"] = $a["computers_id"];
|
||||||
|
$check["status"] = "unknown";
|
||||||
|
|
||||||
$checked = json_decode(stream_get_contents($pipes[1]));
|
$check_arr[] = $check;
|
||||||
fclose($pipes[1]);
|
$comps[$a["computers_id"]] = $check;
|
||||||
|
//print_r($agent->getAgentStatusURLs());
|
||||||
|
}
|
||||||
|
|
||||||
// It is important that you close any pipes before calling
|
$descriptorspec = array(
|
||||||
// proc_close in order to avoid a deadlock
|
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
|
||||||
$return_value = proc_close($process);
|
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
|
||||||
|
2 => array("file", "/tmp/error-output.txt", "a"), // stderr is a file to write to
|
||||||
|
);
|
||||||
|
|
||||||
|
$cwd = '/tmp';
|
||||||
|
$env = array('debug' => 'false', 'threads' => $config["threads"]);
|
||||||
|
|
||||||
|
$process = proc_open($rs_path . '/bin/check_status', $descriptorspec, $pipes, $cwd, $env);
|
||||||
|
|
||||||
|
if (is_resource($process)) {
|
||||||
|
// $pipes now looks like this:
|
||||||
|
// 0 => writeable handle connected to child stdin
|
||||||
|
// 1 => readable handle connected to child stdout
|
||||||
|
// Any error output will be appended to /tmp/error-output.txt
|
||||||
|
|
||||||
|
fwrite($pipes[0], json_encode($check_arr));
|
||||||
|
fclose($pipes[0]);
|
||||||
|
|
||||||
|
$checked = json_decode(stream_get_contents($pipes[1]));
|
||||||
|
fclose($pipes[1]);
|
||||||
|
|
||||||
|
// It is important that you close any pipes before calling
|
||||||
|
// proc_close in order to avoid a deadlock
|
||||||
|
$return_value = proc_close($process);
|
||||||
|
|
||||||
|
Toolbox::logInFile("remotesupport", "command returned $return_value\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$agents = [];
|
||||||
|
$data_set = [];
|
||||||
|
$checked = [];
|
||||||
|
|
||||||
|
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
|
||||||
|
|
||||||
|
$data_set[] = $a["id"];
|
||||||
|
$agents[$a["id"]] = $a;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($data_set as $id) {
|
||||||
|
$agent = new PluginFusioninventoryAgent;
|
||||||
|
$agent->getFromDB((int) $id);
|
||||||
|
$st = $agent->getStatus();
|
||||||
|
|
||||||
|
if ($st["message"] != "noanswer") {
|
||||||
|
$check = new stdClass();
|
||||||
|
$check->computers_id = $agents[$id]["computers_id"];
|
||||||
|
$checked[] = $check;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Toolbox::logInFile("remotsupport", "command returned $return_value\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$stids = self::getStatesIds();
|
$stids = self::getStatesIds();
|
||||||
@@ -117,25 +195,28 @@ class PluginRemotesupportRemotesupport extends CommonDBTM
|
|||||||
['1' => '1']
|
['1' => '1']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$ids = [];
|
||||||
|
$cids = self::getContactArray();
|
||||||
|
|
||||||
foreach ($checked as $s) {
|
foreach ($checked as $s) {
|
||||||
|
|
||||||
$comp = new Computer();
|
$comp = new Computer();
|
||||||
$comp->getFromDB($s->computers_id);
|
$comp->getFromDB($s->computers_id);
|
||||||
$comp->fields["states_id"] = $stids["Online"];
|
Toolbox::logInFile("remotesupport", $s->computers_id . " " . $cids[$s->computers_id] . "\n");
|
||||||
$DB->update("glpi_computers", [
|
$ids[] = $s->computers_id;
|
||||||
'states_id' => $comp->fields["states_id"]],
|
|
||||||
['id' => $s->computers_id]
|
|
||||||
);
|
|
||||||
Toolbox::logInFile("remotsupport", $s->computers_id . " " . $comp->fields["contact"] . "\n");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$DB->update("glpi_computers", [
|
||||||
|
'states_id' => $stids["Online"]],
|
||||||
|
['id' => $ids]
|
||||||
|
);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function cronInfo($name)
|
public static function cronInfo($name)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'description' => "Agent search remotesupport"];
|
'description' => __('Agent search remotesupport')];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
170
inc/test.php
170
inc/test.php
@@ -1,170 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
------------------------------------------------------------------------
|
|
||||||
FusionInventory
|
|
||||||
Copyright (C) 2010-2011 by the FusionInventory Development Team.
|
|
||||||
|
|
||||||
http://www.fusioninventory.org/ http://forge.fusioninventory.org/
|
|
||||||
------------------------------------------------------------------------
|
|
||||||
|
|
||||||
LICENSE
|
|
||||||
|
|
||||||
This file is part of FusionInventory project.
|
|
||||||
|
|
||||||
FusionInventory is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
FusionInventory is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with FusionInventory. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
|
||||||
|
|
||||||
@package FusionInventory
|
|
||||||
@author Walid Nouh
|
|
||||||
@co-author
|
|
||||||
@copyright Copyright (c) 2010-2011 FusionInventory team
|
|
||||||
@license AGPL License 3.0 or (at your option) any later version
|
|
||||||
http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
|
||||||
@link http://www.fusioninventory.org/
|
|
||||||
@link http://forge.fusioninventory.org/projects/fusioninventory-for-glpi/
|
|
||||||
@since 2010
|
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
include ("../../../inc/includes.php");
|
|
||||||
|
|
||||||
declare(ticks=1);
|
|
||||||
|
|
||||||
|
|
||||||
$state_online = [
|
|
||||||
'name' => 'Online',
|
|
||||||
'entities_id' => 0,
|
|
||||||
'is_recursive' => 0,
|
|
||||||
'comment' => '',
|
|
||||||
'states_id' => 0,
|
|
||||||
'completename' => 'Online',
|
|
||||||
'level' => 1,
|
|
||||||
'ancestors_cache' => '[]',
|
|
||||||
'sons_cache' => 'NULL',
|
|
||||||
'is_visible_computer' => 1,
|
|
||||||
'is_visible_monitor' => 0,
|
|
||||||
'is_visible_networkequipment' => 0,
|
|
||||||
'is_visible_peripheral' => 0,
|
|
||||||
'is_visible_phone' => 0,
|
|
||||||
'is_visible_printer' => 0,
|
|
||||||
'is_visible_softwareversion' => 0,
|
|
||||||
'is_visible_softwarelicense' => 0,
|
|
||||||
'is_visible_line' => 0,
|
|
||||||
'is_visible_certificate' => 0,
|
|
||||||
'is_visible_rack' => 0,
|
|
||||||
'is_visible_passivedcequipment' => 0,
|
|
||||||
'is_visible_enclosure' => 0,
|
|
||||||
'is_visible_pdu' => 0,
|
|
||||||
'is_visible_cluster' => 0,
|
|
||||||
'is_visible_contract' => 0,
|
|
||||||
'is_visible_appliance' => 0];
|
|
||||||
/*
|
|
||||||
$ret = $DB->insert(
|
|
||||||
'glpi_states', $state_online
|
|
||||||
);
|
|
||||||
|
|
||||||
$state_offline = $state_online;
|
|
||||||
$state_offline["name"] = 'Offline';
|
|
||||||
$state_offline["completename"] = 'Offline';
|
|
||||||
|
|
||||||
$ret = $DB->insert(
|
|
||||||
'glpi_states', $state_offline
|
|
||||||
);
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
$req = $DB->request('glpi_states', ['FIELDS' => ['glpi_states' => ['id', 'name']]], [ 'OR' => [ 'name' => 'Online', 'name' => 'Offline']]);
|
|
||||||
|
|
||||||
$ret = $req->next();
|
|
||||||
$states_ids[$ret['name']] = $ret['id'];
|
|
||||||
$ret = $req->next();
|
|
||||||
$states_ids[$ret['name']] = $ret['id'];
|
|
||||||
print_r($states_ids);
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
|
|
||||||
global $DB,$agents;
|
|
||||||
|
|
||||||
$check_arr = [];
|
|
||||||
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
|
|
||||||
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
|
|
||||||
|
|
||||||
$check = [];
|
|
||||||
$a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($a["computers_id"]);
|
|
||||||
|
|
||||||
$check["url"] = "http://".$a_computerextend["remote_addr"].":62354/status";
|
|
||||||
$check["id"] = $a["id"];
|
|
||||||
$check["computers_id"] = $a["computers_id"];
|
|
||||||
$check["status"] = "unknown";
|
|
||||||
|
|
||||||
$check_arr[] = $check;
|
|
||||||
//print_r($agent->getAgentStatusURLs());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$descriptorspec = array(
|
|
||||||
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
|
|
||||||
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
|
|
||||||
2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
|
|
||||||
);
|
|
||||||
|
|
||||||
$cwd = '/tmp';
|
|
||||||
$env = array('debug' => 'false');
|
|
||||||
|
|
||||||
$process = proc_open(__DIR__.'/bench_urls', $descriptorspec, $pipes, $cwd, $env);
|
|
||||||
|
|
||||||
if (is_resource($process)) {
|
|
||||||
// $pipes now looks like this:
|
|
||||||
// 0 => writeable handle connected to child stdin
|
|
||||||
// 1 => readable handle connected to child stdout
|
|
||||||
// Any error output will be appended to /tmp/error-output.txt
|
|
||||||
|
|
||||||
fwrite($pipes[0], json_encode($check_arr));
|
|
||||||
fclose($pipes[0]);
|
|
||||||
|
|
||||||
$checked = json_decode(stream_get_contents($pipes[1]));
|
|
||||||
fclose($pipes[1]);
|
|
||||||
|
|
||||||
// It is important that you close any pipes before calling
|
|
||||||
// proc_close in order to avoid a deadlock
|
|
||||||
$return_value = proc_close($process);
|
|
||||||
|
|
||||||
echo "command returned $return_value\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$DB->update("glpi_computers", [
|
|
||||||
'states_id' => NULL ] ,
|
|
||||||
[ '1' => '1' ]
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($checked as $s) {
|
|
||||||
echo $s->computers_id." ";
|
|
||||||
|
|
||||||
$comp = new Computer();
|
|
||||||
$comp->getFromDB($s->computers_id);
|
|
||||||
$comp->fields["states_id"] = 2;
|
|
||||||
$DB->update("glpi_computers", [
|
|
||||||
'states_id' => $comp->fields["states_id"] ],
|
|
||||||
[ 'id' => $s->computers_id ]
|
|
||||||
);
|
|
||||||
echo $comp->fields["contact"]."\n";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// print_r($a_computerextend);
|
|
||||||
exit(0);
|
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
</authors>
|
</authors>
|
||||||
<versions>
|
<versions>
|
||||||
<version>
|
<version>
|
||||||
<num>0.0.1</num>
|
<num>0.0.2</num>
|
||||||
<compatibility>~9.5.0</compatibility>
|
<compatibility>~9.5.0</compatibility>
|
||||||
</version>
|
</version>
|
||||||
</versions>
|
</versions>
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ function plugin_init_remotesupport()
|
|||||||
'Computer' => array('PluginRemotesupportRemotesupport', 'showInfo'),
|
'Computer' => array('PluginRemotesupportRemotesupport', 'showInfo'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Plugin::registerClass('PluginRemotesupportConfig', ['addtabon' => 'Config']);
|
||||||
|
|
||||||
CronTask::Register('PluginRemotesupportRemotesupport', 'remotesupport', 300,
|
CronTask::Register('PluginRemotesupportRemotesupport', 'remotesupport', 300,
|
||||||
['mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30,
|
['mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30,
|
||||||
'comment' => 'Remotesupport crontab search agents']);
|
'comment' => 'Remotesupport crontab search agents']);
|
||||||
|
|||||||
Reference in New Issue
Block a user