mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 00:04:37 +02:00
Added a new agent tab to launch the eHorus Client
(cherry picked from commit 8fa87e7e1e0aa4b5ff3c4b165f9d638fc06d4de0)
This commit is contained in:
parent
5191f8658a
commit
d990d11970
185
pandora_console/operation/agentes/ehorus.php
Normal file
185
pandora_console/operation/agentes/ehorus.php
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Pandora FMS- http://pandorafms.com
|
||||||
|
* ==================================================
|
||||||
|
* Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||||
|
*
|
||||||
|
* This program 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 for version 2.
|
||||||
|
* This program 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Load global vars
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
check_login ();
|
||||||
|
|
||||||
|
if (! check_acl ($config['id_user'], 0, "AR") && ! is_user_admin ($config['id_user'])) {
|
||||||
|
db_pandora_audit("ACL Violation", "Trying to access eHorus");
|
||||||
|
require ("general/noaccess.php");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once($config['homedir'] . '/include/functions_ui.php');
|
||||||
|
require_once($config['homedir'] . '/include/functions_agents.php');
|
||||||
|
|
||||||
|
if (!$config['ehorus_enabled']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the parameters */
|
||||||
|
$agent_id = (int) get_parameter('id_agente');
|
||||||
|
|
||||||
|
if (empty($agent_id)) {
|
||||||
|
ui_print_error_message(__('Missing agent id'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ehorus_agent_id = agents_get_agent_custom_field($agent_id, 'eHorus ID');
|
||||||
|
|
||||||
|
if (empty($ehorus_agent_id)) {
|
||||||
|
ui_print_error_message(__('Missing ehorus agent id'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Directory data
|
||||||
|
$hostname = $config['ehorus_hostname'];
|
||||||
|
$port = $config['ehorus_port'];
|
||||||
|
$user = $config['ehorus_user'];
|
||||||
|
$password = io_output_password($config['ehorus_pass']);
|
||||||
|
$curl_timeout = $config['ehorus_req_timeout'];
|
||||||
|
|
||||||
|
// Get the agent auth token
|
||||||
|
$token_path = '/agents/' . $ehorus_agent_id . '/token';
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, 'https://' . $hostname . ':' . $port . $token_path);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $curl_timeout);
|
||||||
|
curl_setopt($ch, CURLOPT_USERPWD, $user . ':' . $password);
|
||||||
|
|
||||||
|
$result_token = curl_exec($ch);
|
||||||
|
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$error = false;
|
||||||
|
if ($result_token === false) {
|
||||||
|
$error = curl_error($ch);
|
||||||
|
}
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($error !== false || $http_status !== 200) {
|
||||||
|
if ($error !== false) {
|
||||||
|
// echo $error;
|
||||||
|
ui_print_error_message(__('There was an error retrieving an authorization token'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui_print_error_message($http_status . ' ' . $result_token);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response_auth = array();
|
||||||
|
try {
|
||||||
|
$response_auth = json_decode($result_token, true);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
ui_print_error_message(__('There was an error processing the response'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get agent info
|
||||||
|
$agent_path = '/agents/' . $ehorus_agent_id;
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, 'https://' . $hostname . ':' . $port . $agent_path);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $curl_timeout);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: JWT ' . $response_auth['token']));
|
||||||
|
|
||||||
|
$result_agent = curl_exec($ch);
|
||||||
|
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$error = false;
|
||||||
|
if ($result_agent === false) {
|
||||||
|
$error = curl_error($ch);
|
||||||
|
}
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($error !== false || $http_status !== 200) {
|
||||||
|
if ($error !== false) {
|
||||||
|
// echo $error;
|
||||||
|
ui_print_error_message(__('There was an error retrieving the agent data'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui_print_error_message($http_status . ' ' . $result_agent);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$agent_data = array();
|
||||||
|
try {
|
||||||
|
$agent_data = json_decode($result_agent, true);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
ui_print_error_message(__('There was an error processing the response'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invalid permision
|
||||||
|
// return;
|
||||||
|
|
||||||
|
echo '<table id="ehorus-client-run-info" class="databox" style="width: 100%;"><tr>';
|
||||||
|
echo '<td>';
|
||||||
|
echo __('Remote management of this agent with eHorus');
|
||||||
|
echo '</td><td>';
|
||||||
|
echo '<input type="button" id="run-ehorus-client" class="sub next" value="' . __('Launch') . '" />';
|
||||||
|
echo '</td>';
|
||||||
|
echo '</tr></table>';
|
||||||
|
|
||||||
|
echo '<div id="ehorus-client"></div>';
|
||||||
|
|
||||||
|
ui_require_css_file('bootstrap.min', 'include/ehorus/css/');
|
||||||
|
ui_require_css_file('style', 'include/ehorus/css/');
|
||||||
|
ui_require_javascript_file('bundle.min', 'include/ehorus/');
|
||||||
|
?>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function () {
|
||||||
|
var runClient = function () {
|
||||||
|
var agentID = '<?php echo $ehorus_agent_id; ?>';
|
||||||
|
var protocol = 'wss';
|
||||||
|
var hostname = '<?php echo $agent_data['serverAddress']; ?>';
|
||||||
|
var port = <?php echo $agent_data['serverPort']; ?>;
|
||||||
|
var token = '<?php echo $response_auth['token']; ?>';
|
||||||
|
var isBusy = <?php echo json_encode($agent_data['isBusy']); ?>;
|
||||||
|
var lastConnection = <?php echo json_encode($agent_data['lastConnection']); ?>;
|
||||||
|
|
||||||
|
var eHorusProps = {
|
||||||
|
url: {
|
||||||
|
protocol,
|
||||||
|
hostname,
|
||||||
|
port,
|
||||||
|
slashes: true,
|
||||||
|
pathname: '',
|
||||||
|
search: 'auth=' + token
|
||||||
|
},
|
||||||
|
agentID: agentID,
|
||||||
|
agentLastContact: lastConnection,
|
||||||
|
agentIsBusy: isBusy,
|
||||||
|
header: false,
|
||||||
|
section: 'terminal',
|
||||||
|
handleDisconnect: function () {
|
||||||
|
console.log('Disconnect callback');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var eHorus = new EHorus(eHorusProps);
|
||||||
|
eHorus.renderIn(document.getElementById('ehorus-client'));
|
||||||
|
}
|
||||||
|
$('input#run-ehorus-client').click(function () {
|
||||||
|
$('table#ehorus-client-run-info').remove();
|
||||||
|
runClient();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
@ -924,6 +924,33 @@ if (enterprise_installed() && $config['log_collector']) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* eHorus tab */
|
||||||
|
if ($config['ehorus_enabled']) {
|
||||||
|
$ehorus_tab['text'] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&tab=ehorus&id_agente='.$id_agente.'" class="ehorus_tab">'
|
||||||
|
. html_print_image ('images/operation.png', true, array ( 'title' => __('eHorus')))
|
||||||
|
. '</a>';
|
||||||
|
|
||||||
|
// Hidden subtab layer
|
||||||
|
// $ehorus_tab['sub_menu'] = '<ul class="mn subsubmenu" style="display:none; float:none;">';
|
||||||
|
// $ehorus_tab['sub_menu'] .= '<li class="nomn tab_godmode" style="text-align: center;">';
|
||||||
|
// $ehorus_tab['sub_menu'] .= '<a href="javascript:;">'
|
||||||
|
// . html_print_image ("images/wand_snmp.png", true, array ( "title" => __('SNMP Wizard')))
|
||||||
|
// . '</a>';
|
||||||
|
// $ehorus_tab['sub_menu'] .= '</li>';
|
||||||
|
// $ehorus_tab['sub_menu'] .= '<li class="nomn tab_godmode" style="text-align: center;">';
|
||||||
|
// $ehorus_tab['sub_menu'] .= '<a href="javascript:;">'
|
||||||
|
// . html_print_image ("images/wand_interfaces.png", true, array ( "title" => __('SNMP Interfaces wizard')))
|
||||||
|
// . '</a>';
|
||||||
|
// $ehorus_tab['sub_menu'] .= '</li>';
|
||||||
|
// $ehorus_tab['sub_menu'] .= '<li class="nomn tab_godmode" style="text-align: center;">';
|
||||||
|
// $ehorus_tab['sub_menu'] .= '<a href="javascript:;">'
|
||||||
|
// . html_print_image ("images/wand_wmi.png", true, array ( "title" => __('WMI Wizard')))
|
||||||
|
// . '</a>';
|
||||||
|
// $ehorus_tab['sub_menu'] .= '</li>';
|
||||||
|
// $ehorus_tab['sub_menu'] .= '</ul>';
|
||||||
|
|
||||||
|
$ehorus_tab['active'] = $tab == 'ehorus';
|
||||||
|
}
|
||||||
|
|
||||||
$onheader = array('manage' => $managetab,
|
$onheader = array('manage' => $managetab,
|
||||||
'main' => $maintab,
|
'main' => $maintab,
|
||||||
@ -947,6 +974,10 @@ if ($agent['url_address'] != '') {
|
|||||||
if (isset($log_viewer_tab) && !empty($log_viewer_tab)) {
|
if (isset($log_viewer_tab) && !empty($log_viewer_tab)) {
|
||||||
$onheader['log_viewer'] = $log_viewer_tab;
|
$onheader['log_viewer'] = $log_viewer_tab;
|
||||||
}
|
}
|
||||||
|
// If the ehorus id exists
|
||||||
|
if ($config['ehorus_enabled']) {
|
||||||
|
$onheader['ehorus'] = $ehorus_tab;
|
||||||
|
}
|
||||||
|
|
||||||
//Tabs for extensions
|
//Tabs for extensions
|
||||||
foreach ($config['extensions'] as $extension) {
|
foreach ($config['extensions'] as $extension) {
|
||||||
@ -1039,6 +1070,9 @@ switch($tab) {
|
|||||||
case "url_address":
|
case "url_address":
|
||||||
$header_description = ' - ' . __('Url address');
|
$header_description = ' - ' . __('Url address');
|
||||||
break;
|
break;
|
||||||
|
case "ehorus":
|
||||||
|
$header_description = ' - ' . __('eHorus');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_print_page_header(agents_get_name($id_agente) .
|
ui_print_page_header(agents_get_name($id_agente) .
|
||||||
@ -1092,6 +1126,9 @@ switch ($tab) {
|
|||||||
$embebed_into_agent_view = true;
|
$embebed_into_agent_view = true;
|
||||||
enterprise_include ("operation/log/log_viewer.php");
|
enterprise_include ("operation/log/log_viewer.php");
|
||||||
break;
|
break;
|
||||||
|
case "ehorus":
|
||||||
|
require("operation/agentes/ehorus.php");
|
||||||
|
break;
|
||||||
case "extension":
|
case "extension":
|
||||||
$found = false;
|
$found = false;
|
||||||
foreach($config['extensions'] as $extension) {
|
foreach($config['extensions'] as $extension) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user