pandorafms/pandora_console/include/class/OrderInterpreter.class.php

476 lines
14 KiB
PHP
Raw Normal View History

2019-12-03 13:59:03 +01:00
<?php
/**
* Welcome to Pandora FMS feature.
*
* @category Class
* @package Pandora FMS
* @subpackage Order Interpreter
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
2020-11-27 13:52:35 +01:00
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
2019-12-03 13:59:03 +01:00
* Please see http://pandorafms.org for full contribution list
* 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.
* ============================================================================
*/
// Begin.
global $config;
require_once $config['homedir'].'/godmode/wizards/Wizard.main.php';
2019-12-12 16:27:11 +01:00
ui_require_css_file('order_interpreter');
2019-12-03 13:59:03 +01:00
/**
* Class OrderInterpreter.
*/
class OrderInterpreter extends Wizard
{
/**
* Allowed methods to be called using AJAX request.
*
* @var array
*/
public $AJAXMethods = ['getResult'];
/**
* Url of controller.
*
* @var string
*/
public $ajaxController;
/**
* Generates a JSON error.
*
* @param string $msg Error message.
*
* @return void
*/
public function error($msg)
{
echo json_encode(
['error' => $msg]
);
}
/**
* Checks if target method is available to be called using AJAX.
*
* @param string $method Target method.
*
* @return boolean True allowed, false not.
*/
public function ajaxMethod($method)
{
global $config;
// Check access.
check_login();
return in_array($method, $this->AJAXMethods);
}
/**
* Constructor.
*
2019-12-04 17:28:03 +01:00
* @param string $ajax_controller Controller.
2019-12-03 13:59:03 +01:00
*
* @return object
* @throws Exception On error.
*/
public function __construct(
$ajax_controller='include/ajax/order_interpreter'
) {
2019-12-19 14:10:43 +01:00
global $config;
2019-12-03 13:59:03 +01:00
$this->ajaxController = $ajax_controller;
2019-12-05 16:10:31 +01:00
2019-12-12 17:16:09 +01:00
$this->pages_menu = [
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('Tactical View'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/monitoring.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=view&sec2=operation/agentes/tactical'
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
'AR'
) || check_acl(
$config['id_user'],
0,
'AW'
),
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('Agent Management'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/resources.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente'
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
'AW'
) && check_acl(
$config['id_user'],
0,
'AD'
),
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('General Setup'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/settings.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=general&sec2=godmode/setup/setup&section=general'
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
'PM'
) || is_user_admin(
$config['id_user']
),
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('Manage Policies'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/configuration.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=gmodules&sec2=enterprise/godmode/policies/policies'
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
'AW'
),
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('List Alerts'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/alerts.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=galertas&sec2=godmode/alerts/alert_list'
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
'LW'
)
|| check_acl(
$config['id_user'],
0,
'AD'
)
|| check_acl(
$config['id_user'],
0,
'LM'
),
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('View Events'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/events.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=eventos&sec2=operation/events/events'
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
'ER'
) ||
check_acl(
$config['id_user'],
0,
'EW'
) ||
check_acl(
$config['id_user'],
0,
'EM'
),
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('Dashboard'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/reporting.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
2020-03-26 12:29:38 +01:00
'index.php?sec=reporting&sec2=operation/dashboard/dashboard'
2019-12-12 17:16:09 +01:00
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
'RR'
),
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('Visual Console'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/network.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=network&sec2=godmode/reporting/map_builder'
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
2019-12-26 10:29:26 +01:00
'VR'
2019-12-19 14:10:43 +01:00
),
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('Manage Servers'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/servers.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/modificar_server'
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
'AW'
),
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('Edit User'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/users.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=workspace&sec2=operation/users/user_edit'
),
2019-12-19 14:10:43 +01:00
'acl' => true,
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-13 14:25:33 +01:00
'name' => __('Tree View'),
2019-12-12 17:16:09 +01:00
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/monitoring.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=view&sec2=operation/tree'
),
2019-12-19 14:10:43 +01:00
'acl' => true,
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('Network Component'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/configuration.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=gmodules&sec2=godmode/modules/manage_network_components'
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
'PM'
),
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2019-12-12 17:16:09 +01:00
'name' => __('Task List'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/discovery.menu.png'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=discovery&sec2=godmode/servers/discovery&wiz=tasklist'
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
'AR'
)
|| check_acl(
$config['id_user'],
0,
'AW'
)
|| check_acl(
$config['id_user'],
0,
'AM'
)
|| check_acl(
$config['id_user'],
0,
'RR'
)
|| check_acl(
$config['id_user'],
0,
'RW'
)
|| check_acl(
$config['id_user'],
0,
'RM'
)
|| check_acl(
$config['id_user'],
0,
'PM'
),
2019-12-12 17:16:09 +01:00
],
2019-12-13 14:43:30 +01:00
[
2022-06-10 12:57:45 +02:00
'name' => __('Warp Update'),
2019-12-12 17:16:09 +01:00
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/um_messages.svg'
2019-12-12 17:16:09 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=messages&sec2=godmode/update_manager/update_manager&tab=setup'
),
2019-12-19 14:10:43 +01:00
'acl' => check_acl(
$config['id_user'],
0,
'PM'
) && is_user_admin($config['id_user']),
],
[
'name' => __('Manage Agent Groups'),
'icon' => ui_get_full_url(
2023-02-16 15:03:45 +01:00
'images/menu/users.svg'
2019-12-19 14:10:43 +01:00
),
'url' => ui_get_full_url(
'index.php?sec=gagente&sec2=godmode/groups/group_list&tab=groups'
),
'acl' => check_acl(
$config['id_user'],
0,
'PM'
),
2019-12-12 17:16:09 +01:00
],
2019-12-05 16:10:31 +01:00
2019-12-03 13:59:03 +01:00
];
}
/**
* Method to print order interpreted on header search input.
*
2019-12-03 18:31:13 +01:00
* @return void
2019-12-03 13:59:03 +01:00
*/
2019-12-03 18:19:32 +01:00
public function getResult()
2019-12-03 13:59:03 +01:00
{
2019-12-19 14:10:43 +01:00
global $config;
2019-12-03 13:59:03 +01:00
// Take value from input search.
$text = get_parameter('text', '');
2020-12-02 15:49:13 +01:00
$enterprise = (bool) get_parameter('enterprise', false);
2019-12-05 16:10:31 +01:00
$iterator = 0;
$more_results = 0;
2019-12-03 18:31:13 +01:00
if ($text !== '') {
2019-12-19 16:53:45 +01:00
echo '<div class="show_result_interpreter">';
2019-12-13 14:08:44 +01:00
echo '<ul id="result_items">';
2019-12-04 17:28:03 +01:00
2019-12-12 17:16:09 +01:00
foreach ($this->pages_menu as $key => $value) {
2019-12-05 16:10:31 +01:00
if (preg_match(
'/.*'.io_safe_output($text).'.*/i',
2019-12-12 17:16:09 +01:00
__('GO TO '.$value['name'])
2019-12-19 14:10:43 +01:00
) && $value['acl']
2019-12-05 16:10:31 +01:00
) {
2020-12-02 15:49:13 +01:00
if ($iterator <= 9 && $this->canShowItem($enterprise, $this->pages_menu[$key]['url'])) {
2019-12-13 14:08:44 +01:00
echo '<li class="list_found" name="'.$iterator.'" id="'.$iterator.'">';
2019-12-05 16:10:31 +01:00
echo '
2021-06-04 13:03:35 +02:00
<span class="invert_filter"> Go to </span> &nbsp;
2019-12-12 17:16:09 +01:00
<img src="'.$this->pages_menu[$key]['icon'].'">';
2019-12-04 17:28:03 +01:00
echo '&nbsp;
2019-12-12 17:16:09 +01:00
<a href="'.$this->pages_menu[$key]['url'].'">
'.$value['name'].'</a><br>';
2019-12-05 16:10:31 +01:00
}
$iterator++;
2019-12-05 16:10:31 +01:00
if ($iterator > 10) {
$more_results++;
2019-12-04 17:28:03 +01:00
}
2019-12-03 18:31:13 +01:00
}
2019-12-03 13:59:03 +01:00
}
2019-12-05 16:10:31 +01:00
if ($iterator > 9) {
2019-12-13 14:08:44 +01:00
echo '</li>';
2019-12-05 16:10:31 +01:00
}
2019-12-13 14:08:44 +01:00
echo $this->loadJS();
2019-12-13 14:22:50 +01:00
echo '</ul>';
if ($iterator > 10) {
2021-06-04 13:03:35 +02:00
echo '<div class="more_results"><span class="invert_filter">
+ '.$more_results.' '.__('results found').'</span></div>';
2019-12-13 14:22:50 +01:00
}
2019-12-03 13:59:03 +01:00
2019-12-19 14:20:31 +01:00
if ($iterator === 0) {
2021-06-04 13:03:35 +02:00
echo '<span class="invert_filter">'.__('Press enter to search').'</span>';
2019-12-19 14:20:31 +01:00
}
2019-12-13 14:43:30 +01:00
echo '</div>';
2019-12-13 14:22:50 +01:00
}
2019-12-03 13:59:03 +01:00
}
2020-12-02 15:49:13 +01:00
/**
* Determines if the element must be shown or not.
*
* @param boolean $isEnterprise Define if the console is Enterprise.
* @param string $url Url of the element for select.
*
* @return boolean
*/
private function canShowItem(bool $isEnterprise, string $url)
{
$canShow = false;
$hasEnterpriseLocation = strpos($url, '&sec2=enterprise') !== false;
if (($isEnterprise === false && $hasEnterpriseLocation === false) || $isEnterprise === true) {
$canShow = true;
}
return $canShow;
}
2019-12-03 13:59:03 +01:00
/**
* Load JS content.
2019-12-05 16:10:31 +01:00
* function to create JS actions.
2019-12-03 13:59:03 +01:00
*
* @return string HTML code for javascript functionality.
*/
public function loadJS()
{
ob_start();
?>
<script type="text/javascript">
2019-12-13 14:08:44 +01:00
2019-12-03 13:59:03 +01:00
</script>
<?php
return ob_get_clean();
}
}