reformatted, cleaned

This commit is contained in:
2021-12-10 11:50:51 +01:00
parent 0cde20881a
commit a4e71a8992
4 changed files with 275 additions and 328 deletions

View File

@@ -1,31 +1,31 @@
<?php
/*
-------------------------------------------------------------------------
Remote Spport (VNC)
Copyright (C) 2021 by Alessandro Carloni
https://github.com/Kaya84/RemoteSupport
-------------------------------------------------------------------------
Remote Spport (VNC)
Copyright (C) 2021 by Alessandro Carloni
https://github.com/Kaya84/RemoteSupport
-------------------------------------------------------------------------
LICENSE
This file is part of Camera Input.
Camera Input 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.
Camera Input 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 Camera Input. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
-------------------------------------------------------------------------
LICENSE
This file is part of Camera Input.
Camera Input 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.
Camera Input 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 Camera Input. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
function plugin_remotesupport_install()
{
global $DB;
Toolbox::logInFile("remotsupport","Installing plugin");
Toolbox::logInFile("remotsupport", "Installing plugin");
$state_online = [
'name' => 'Online',
'entities_id' => 0,
@@ -69,31 +69,33 @@ function plugin_remotesupport_install()
return true;
}
function plugin_remotesupport_uninstall(){
function plugin_remotesupport_uninstall()
{
global $DB;
Toolbox::logInFile("remotsupport","Uninstalling plugin");
Toolbox::logInFile("remotsupport", "Uninstalling plugin");
CronTask::Unregister('remotesupport');
$req = $DB->request('glpi_states', ['FIELDS' => ['glpi_states' => ['id', 'name']]], [ 'OR' => [ 'name' => 'Online', 'name' => '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'];
$DB->query('UPDATE glpi_computers SET states_id=NULL WHERE id='.$states_ids["Offline"]);
$DB->query('UPDATE glpi_computers SET states_id=NULL WHERE id='.$states_ids["Online"]);
$DB->query('DELETE FROM glpi_states WHERE id='.$states_ids["Offline"]);
$DB->query('DELETE FROM glpi_states WHERE id='.$states_ids["Online"]);
$DB->query('UPDATE glpi_computers SET states_id=NULL WHERE id=' . $states_ids["Offline"]);
$DB->query('UPDATE glpi_computers SET states_id=NULL WHERE id=' . $states_ids["Online"]);
$DB->query('DELETE FROM glpi_states WHERE id=' . $states_ids["Offline"]);
$DB->query('DELETE FROM glpi_states WHERE id=' . $states_ids["Online"]);
return true;
}
function plugin_remotesupport_postinit() {
function plugin_remotesupport_postinit()
{
global $CFG_GLPI, $DB;
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") {
$id = $_GET['id'];
//mysql> select * from glpi_tickets_users where tickets_id = 2 and type = 1;
@@ -108,12 +110,12 @@ function plugin_remotesupport_postinit() {
$req2 = $DB->request(['FROM' => 'glpi_computers', 'WHERE' => ['users_id' => $requester, 'is_deleted' => 0]]);
$url = "";
while ($row2 = $req2->next()){
while ($row2 = $req2->next()) {
//$url .= "<li class=\"document\" onclick=\"location.href='vnc://" . $row2['name'] ."'\"$
$url .= "<li class=\"document\" onclick=\"location.href='vnc://" . $row2['name'] ."'\"><i class=\"fa fa-laptop-medical\"></i>" . $row2['name'] . "</li>";
$url .= "<li class=\"document\" onclick=\"location.href='vnc://" . $row2['name'] . "'\"><i class=\"fa fa-laptop-medical\"></i>" . $row2['name'] . "</li>";
}
if ($url != ""){
if ($url != "") {
echo "<div><ul class=\"timeline_choices\"><h2>Remote support : </h2>";
echo $url;
echo "</ul></div>";
@@ -121,4 +123,3 @@ function plugin_remotesupport_postinit() {
}
}
}
?>

View File

@@ -1,61 +1,20 @@
<?php
/*
------------------------------------------------------------------------
FusionInventory
Copyright (C) 2010-2011 by the FusionInventory Development Team.
include "../../../inc/includes.php";
http://www.fusioninventory.org/ http://forge.fusioninventory.org/
------------------------------------------------------------------------
declare (ticks = 1);
LICENSE
global $DB, $agents;
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);
global $DB,$agents;
$check_arr = [];
$comps = [];
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
$check_arr = [];
$comps = [];
$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["url"] = "http://" . $a_computerextend["remote_addr"] . ":62354/status";
$check["id"] = $a["id"];
$check["computers_id"] = $a["computers_id"];
$check["status"] = "unknown";
@@ -63,19 +22,18 @@ global $DB,$agents;
$check_arr[] = $check;
$comps[$a["computers_id"]] = $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
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__.'/check_status', $descriptorspec, $pipes, $cwd, $env);
$process = proc_open(__DIR__ . '/check_status', $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process)) {
// $pipes now looks like this:
@@ -96,7 +54,7 @@ if (is_resource($process)) {
echo "command returned $return_value\n";
}
$req = $DB->request('glpi_states', ['FIELDS' => ['glpi_states' => ['id', 'name']]], [ 'OR' => [ 'name' => 'Online', 'name' => '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'];
@@ -104,25 +62,22 @@ $ret = $req->next();
$states_ids[$ret['name']] = $ret['id'];
print_r($states_ids);
$DB->update("glpi_computers", [
'states_id' => $states_ids["Offline"] ] ,
[ '1' => '1' ]
);
$DB->update("glpi_computers", [
'states_id' => $states_ids["Offline"]],
['1' => '1']
);
foreach ($checked as $s) {
echo $s->computers_id." ";
echo $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 ]
'states_id' => $comp->fields["states_id"]],
['id' => $s->computers_id]
);
echo $comp->fields["contact"]."\n";
echo $comp->fields["contact"] . "\n";
}

View File

@@ -4,10 +4,10 @@ if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
class PluginRemotesupportRemotesupport extends CommonDBTM {
static function showInfo($item) {
class PluginRemotesupportRemotesupport extends CommonDBTM
{
public static function showInfo($item)
{
$fi_path = Plugin::getWebDir('fusioninventory');
@@ -22,14 +22,14 @@ class PluginRemotesupportRemotesupport extends CommonDBTM {
echo '<table class="tab_glpi" width="100%">';
echo '<tr>';
echo '<th>'.__('Remote Support').'</th>';
echo '<th>' . __('Remote Support') . '</th>';
echo '</tr>';
echo '<tr class="tab_bg_1">';
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>";
$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>";
if ($url != ""){
if ($url != "") {
echo "<div><ul class=\"timeline_choices\"><h2>VNC connect : </h2>";
echo $url;
echo "</ul></div>";
@@ -40,12 +40,13 @@ class PluginRemotesupportRemotesupport extends CommonDBTM {
}
static function getStatesIds() {
public static function getStatesIds()
{
global $DB;
$states_ids = [];
$req = $DB->request('glpi_states', ['FIELDS' => ['glpi_states' => ['id', 'name']]], [ 'OR' => [ 'name' => 'Online', 'name' => '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'];
@@ -55,11 +56,11 @@ class PluginRemotesupportRemotesupport extends CommonDBTM {
return $states_ids;
}
static function cronRemotesupport($task) {
public static function cronRemotesupport($task)
{
global $DB;
Toolbox::logInFile("remotsupport","Starting search of agents\n");
Toolbox::logInFile("remotsupport", "Starting search of agents\n");
$check_arr = [];
$comps = [];
@@ -69,7 +70,7 @@ class PluginRemotesupportRemotesupport extends CommonDBTM {
$check = [];
$a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($a["computers_id"]);
$check["url"] = "http://".$a_computerextend["remote_addr"].":62354/status";
$check["url"] = "http://" . $a_computerextend["remote_addr"] . ":62354/status";
$check["id"] = $a["id"];
$check["computers_id"] = $a["computers_id"];
$check["status"] = "unknown";
@@ -82,13 +83,13 @@ class PluginRemotesupportRemotesupport extends CommonDBTM {
$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
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__.'/../bin/check_status', $descriptorspec, $pipes, $cwd, $env);
$process = proc_open(__DIR__ . '/../bin/check_status', $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process)) {
// $pipes now looks like this:
@@ -106,34 +107,34 @@ class PluginRemotesupportRemotesupport extends CommonDBTM {
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
Toolbox::logInFile("remotsupport","command returned $return_value\n");
Toolbox::logInFile("remotsupport", "command returned $return_value\n");
}
$stids = self::getStatesIds();
$DB->update("glpi_computers", [
'states_id' => $stids["Offline"] ] ,
[ '1' => '1' ]
'states_id' => $stids["Offline"]],
['1' => '1']
);
foreach ($checked as $s) {
$comp = new Computer();
$comp->getFromDB($s->computers_id);
$comp->fields["states_id"] = $stids["Online"];
$DB->update("glpi_computers", [
'states_id' => $comp->fields["states_id"] ],
[ 'id' => $s->computers_id ]
'states_id' => $comp->fields["states_id"]],
['id' => $s->computers_id]
);
Toolbox::logInFile("remotsupport",$s->computers_id." ".$comp->fields["contact"]."\n");
Toolbox::logInFile("remotsupport", $s->computers_id . " " . $comp->fields["contact"] . "\n");
}
return 0;
}
static function cronInfo($name) {
public static function cronInfo($name)
{
return [
'description' => "Agent search remotesupport"];
}

View File

@@ -1,25 +1,25 @@
<?php
/*
-------------------------------------------------------------------------
Remote Spport (VNC)
Copyright (C) 2021 by Alessandro Carloni
https://github.com/Kaya84/RemoteSupport
-------------------------------------------------------------------------
Remote Spport (VNC)
Copyright (C) 2021 by Alessandro Carloni
https://github.com/Kaya84/RemoteSupport
-------------------------------------------------------------------------
LICENSE
This file is part of Camera Input.
Camera Input 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.
Camera Input 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 Camera Input. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
-------------------------------------------------------------------------
LICENSE
This file is part of Camera Input.
Camera Input 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.
Camera Input 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 Camera Input. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
define('PLUGIN_REMOTESUPPORT_VERSION', '0.0.1');
define('PLUGIN_REMOTESUPPORT_MIN_GLPI', '9.5.0');
@@ -33,26 +33,17 @@ function plugin_init_remotesupport()
if (Plugin::isPluginActive('remotesupport')) {
// $PLUGIN_HOOKS['add_javascript']['remotesupport'][] = 'js/support.js';
$PLUGIN_HOOKS['autoinventory_information']['remotesupport'] = array(
'Computer' => array('PluginRemotesupportRemotesupport', 'showInfo')
'Computer' => array('PluginRemotesupportRemotesupport', 'showInfo'),
);
CronTask::Register('PluginRemotesupportRemotesupport', 'remotesupport', 300,
['mode'=>2, 'allowmode'=>3, 'logs_lifetime'=>30,
'comment'=> 'Remotesupport crontab search agents']);
['mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30,
'comment' => 'Remotesupport crontab search agents']);
// Add Config Page
// Plugin::registerClass('PluginRemotesupportConfig', ['addtabon' => 'Config']);
// $PLUGIN_HOOKS["menu_toadd"]['remotesupport'] = ['tools' => 'PluginRemotesupportMenu'];
// $PLUGIN_HOOKS['config_page']['remotesupport'] = 'front/index.php';
$PLUGIN_HOOKS['menu']['remotesupport'] = true;
$PLUGIN_HOOKS['post_init']['remotesupport'] = 'plugin_remotesupport_postinit';
}
}
@@ -63,13 +54,12 @@ function plugin_version_remotesupport()
'version' => PLUGIN_REMOTESUPPORT_VERSION,
'author' => 'Alessandro Carloni',
'license' => 'GPLv2',
'homepage' =>'https://github.com/Kaya84/',
'homepage' => 'https://github.com/Kaya84/',
'requirements' => [
'glpi' => [
'min' => PLUGIN_REMOTESUPPORT_MIN_GLPI,
'max' => PLUGIN_REMOTESUPPORT_MAX_GLPI
]
]
'max' => PLUGIN_REMOTESUPPORT_MAX_GLPI,
],
],
];
}