diff --git a/hook.php b/hook.php index 41ab57f..51d6be3 100644 --- a/hook.php +++ b/hook.php @@ -1,124 +1,125 @@ . - -------------------------------------------------------------------------- -*/ +------------------------------------------------------------------------- +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 . +-------------------------------------------------------------------------- + */ function plugin_remotesupport_install() { - global $DB; + global $DB; - Toolbox::logInFile("remotsupport","Installing plugin"); - $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]; + Toolbox::logInFile("remotsupport", "Installing plugin"); + $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 - ); + $ret = $DB->insert( + 'glpi_states', $state_online + ); - $state_offline = $state_online; - $state_offline["name"] = 'Offline'; - $state_offline["completename"] = 'Offline'; + $state_offline = $state_online; + $state_offline["name"] = 'Offline'; + $state_offline["completename"] = 'Offline'; - $ret = $DB->insert( - 'glpi_states', $state_offline - ); + $ret = $DB->insert( + 'glpi_states', $state_offline + ); - return true; + return true; } -function plugin_remotesupport_uninstall(){ - global $DB; +function plugin_remotesupport_uninstall() +{ + global $DB; - Toolbox::logInFile("remotsupport","Uninstalling plugin"); - CronTask::Unregister('remotesupport'); + 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']; + $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; + return true; } -function plugin_remotesupport_postinit() { - global $CFG_GLPI, $DB; +function plugin_remotesupport_postinit() +{ + global $CFG_GLPI, $DB; - 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; - - $req = $DB->request(['FROM' => 'glpi_tickets_users', 'WHERE' => ['tickets_id' => $id, 'type' => 1]]); - //NB: Estraggo unicamente il primo richiedente - $row = $req->next(); - $requester = $row['users_id']; - // select id, name, users_id from glpi_computers where users_id = 178; - - if ($row['users_id'] != 0) { - $req2 = $DB->request(['FROM' => 'glpi_computers', 'WHERE' => ['users_id' => $requester, 'is_deleted' => 0]]); - $url = ""; + if (isset($_GET['id']) && $_GET['id'] != 0 && isset($_GET['_itemtype']) && $_GET['_itemtype'] == "Ticket") { + $id = $_GET['id']; - while ($row2 = $req2->next()){ - //$url .= "
  • " . $row2['name'] . "
  • "; - } + //mysql> select * from glpi_tickets_users where tickets_id = 2 and type = 1; - if ($url != ""){ - echo "
    "; - } - } - } + $req = $DB->request(['FROM' => 'glpi_tickets_users', 'WHERE' => ['tickets_id' => $id, 'type' => 1]]); + //NB: Estraggo unicamente il primo richiedente + $row = $req->next(); + $requester = $row['users_id']; + // select id, name, users_id from glpi_computers where users_id = 178; + + if ($row['users_id'] != 0) { + $req2 = $DB->request(['FROM' => 'glpi_computers', 'WHERE' => ['users_id' => $requester, 'is_deleted' => 0]]); + $url = ""; + + while ($row2 = $req2->next()) { + //$url .= "
  • " . $row2['name'] . "
  • "; + } + + if ($url != "") { + echo "
    "; + } + } + } } -?> diff --git a/inc/remote_status.php b/inc/remote_status.php index 768bbe9..e973b2b 100644 --- a/inc/remote_status.php +++ b/inc/remote_status.php @@ -1,81 +1,39 @@ hasAutomaticInventory($a["computers_id"]); - 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 . - - ------------------------------------------------------------------------ - - @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 = []; - $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()); - } + $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( - 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 + 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__.'/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,27 +62,24 @@ $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 ] - ); - echo $comp->fields["contact"]."\n"; + $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"; } -// print_r($a_computerextend); +// print_r($a_computerextend); exit(0); diff --git a/inc/remotesupport.class.php b/inc/remotesupport.class.php index 6b7eef1..9f2443a 100644 --- a/inc/remotesupport.class.php +++ b/inc/remotesupport.class.php @@ -1,140 +1,141 @@ hasAutomaticInventory($item->getID()); + if (empty($a_computerextend)) { + return true; + } - // Manage locks pictures - PluginFusioninventoryLock::showLockIcon('Computer'); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
    ' . __('Remote Support') . '
    '; - $pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer(); - $a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($item->getID()); - if (empty($a_computerextend)) { - return true; - } + $url = "
  • " . $a_computerextend['remote_addr'] . "
  • "; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
    '.__('Remote Support').'
    '; - - $url = "
  • " . $a_computerextend['remote_addr'] . "
  • "; - - if ($url != ""){ + if ($url != "") { echo "

      VNC connect :

      "; echo $url; echo "
    "; - } - echo '
    '; + } + echo '
    '; - } + } - static function getStatesIds() { - global $DB; + public static function getStatesIds() + { + global $DB; - $states_ids = []; + $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']; - $ret = $req->next(); - $states_ids[$ret['name']] = $ret['id']; - - return $states_ids; - } + $ret = $req->next(); + $states_ids[$ret['name']] = $ret['id']; + $ret = $req->next(); + $states_ids[$ret['name']] = $ret['id']; - static function cronRemotesupport($task) { - global $DB; + return $states_ids; + } - Toolbox::logInFile("remotsupport","Starting search of agents\n"); + public static function cronRemotesupport($task) + { + global $DB; + Toolbox::logInFile("remotsupport", "Starting search of agents\n"); $check_arr = []; $comps = []; $pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer(); foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) { - $check = []; - $a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($a["computers_id"]); + $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["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()); - } + $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 - ); + $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'); + $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: - // 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 + 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]); + fwrite($pipes[0], json_encode($check_arr)); + fclose($pipes[0]); - $checked = json_decode(stream_get_contents($pipes[1])); - fclose($pipes[1]); + $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); + // 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("remotsupport","command returned $return_value\n"); - } + Toolbox::logInFile("remotsupport", "command returned $return_value\n"); + } - $stids = self::getStatesIds(); + $stids = self::getStatesIds(); - $DB->update("glpi_computers", [ - 'states_id' => $stids["Offline"] ] , - [ '1' => '1' ] - ); + $DB->update("glpi_computers", [ + 'states_id' => $stids["Offline"]], + ['1' => '1'] + ); + foreach ($checked as $s) { - 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] + ); + Toolbox::logInFile("remotsupport", $s->computers_id . " " . $comp->fields["contact"] . "\n"); - $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 ] - ); - Toolbox::logInFile("remotsupport",$s->computers_id." ".$comp->fields["contact"]."\n"); + } - } + return 0; + } - return 0; - } - - static function cronInfo($name) { - return [ + public static function cronInfo($name) + { + return [ 'description' => "Agent search remotesupport"]; - } + } } diff --git a/setup.php b/setup.php index febf9f6..9c9e7f0 100644 --- a/setup.php +++ b/setup.php @@ -1,25 +1,25 @@ . - -------------------------------------------------------------------------- -*/ +------------------------------------------------------------------------- +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 . +-------------------------------------------------------------------------- + */ define('PLUGIN_REMOTESUPPORT_VERSION', '0.0.1'); define('PLUGIN_REMOTESUPPORT_MIN_GLPI', '9.5.0'); @@ -28,48 +28,38 @@ define("PLUGIN_REMOTESUPPORT_DIR", GLPI_ROOT . "/plugins/remotesupport"); function plugin_init_remotesupport() { - global $PLUGIN_HOOKS; - $PLUGIN_HOOKS['csrf_compliant']['remotesupport'] = true; + global $PLUGIN_HOOKS; + $PLUGIN_HOOKS['csrf_compliant']['remotesupport'] = true; - if (Plugin::isPluginActive('remotesupport')) { - -// $PLUGIN_HOOKS['add_javascript']['remotesupport'][] = 'js/support.js'; + if (Plugin::isPluginActive('remotesupport')) { - $PLUGIN_HOOKS['autoinventory_information']['remotesupport'] = array( - 'Computer' => array('PluginRemotesupportRemotesupport', 'showInfo') - ); + $PLUGIN_HOOKS['autoinventory_information']['remotesupport'] = array( + 'Computer' => array('PluginRemotesupportRemotesupport', 'showInfo'), + ); - CronTask::Register('PluginRemotesupportRemotesupport', 'remotesupport', 300, - ['mode'=>2, 'allowmode'=>3, 'logs_lifetime'=>30, - 'comment'=> 'Remotesupport crontab search agents']); + CronTask::Register('PluginRemotesupportRemotesupport', 'remotesupport', 300, + ['mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, + 'comment' => 'Remotesupport crontab search agents']); + $PLUGIN_HOOKS['menu']['remotesupport'] = true; + $PLUGIN_HOOKS['post_init']['remotesupport'] = 'plugin_remotesupport_postinit'; - // 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'; - - - } + } } function plugin_version_remotesupport() { - return [ - 'name' => __('Remote Support Input', 'remotesupport'), - 'version' => PLUGIN_REMOTESUPPORT_VERSION, - 'author' => 'Alessandro Carloni', - 'license' => 'GPLv2', - 'homepage' =>'https://github.com/Kaya84/', - 'requirements' => [ - 'glpi' => [ - 'min' => PLUGIN_REMOTESUPPORT_MIN_GLPI, - 'max' => PLUGIN_REMOTESUPPORT_MAX_GLPI - ] - ] - ]; + return [ + 'name' => __('Remote Support Input', 'remotesupport'), + 'version' => PLUGIN_REMOTESUPPORT_VERSION, + 'author' => 'Alessandro Carloni', + 'license' => 'GPLv2', + 'homepage' => 'https://github.com/Kaya84/', + 'requirements' => [ + 'glpi' => [ + 'min' => PLUGIN_REMOTESUPPORT_MIN_GLPI, + 'max' => PLUGIN_REMOTESUPPORT_MAX_GLPI, + ], + ], + ]; } -