Merge remote-tracking branch 'origin/develop' into ent-3611-Vista-Creación-Edición-de-Agente
Former-commit-id: b60c4d8c438d79f20cc9dcdfac856bbaf0a4ada5
This commit is contained in:
commit
9f3c586b55
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, AIX version
|
||||
# Version 7.0NG.734, AIX version
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2010 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, FreeBSD Version
|
||||
# Version 7.0NG.734, FreeBSD Version
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2010 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, HP-UX Version
|
||||
# Version 7.0NG.734, HP-UX Version
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, GNU/Linux
|
||||
# Version 7.0NG.734, GNU/Linux
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, GNU/Linux
|
||||
# Version 7.0NG.734, GNU/Linux
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, Solaris Version
|
||||
# Version 7.0NG.734, Solaris Version
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Base config file for Pandora FMS Windows Agent
|
||||
# (c) 2006-2010 Artica Soluciones Tecnologicas
|
||||
# Version 7.0NG.733
|
||||
# Version 7.0NG.734
|
||||
|
||||
# This program is Free Software, you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public Licence as published by the Free Software
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Fichero de configuracion base de agentes de Pandora
|
||||
# Base config file for Pandora agents
|
||||
# Version 7.0NG.733, AIX version
|
||||
# Version 7.0NG.734, AIX version
|
||||
|
||||
# General Parameters
|
||||
# ==================
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Fichero de configuracion base de agentes de Pandora
|
||||
# Base config file for Pandora agents
|
||||
# Version 7.0NG.733
|
||||
# Version 7.0NG.734
|
||||
# FreeBSD/IPSO version
|
||||
# Licenced under GPL licence, 2003-2007 Sancho Lerena
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Fichero de configuracion base de agentes de Pandora
|
||||
# Base config file for Pandora agents
|
||||
# Version 7.0NG.733, HPUX Version
|
||||
# Version 7.0NG.734, HPUX Version
|
||||
|
||||
# General Parameters
|
||||
# ==================
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733
|
||||
# Version 7.0NG.734
|
||||
# Licensed under GPL license v2,
|
||||
# (c) 2003-2010 Artica Soluciones Tecnologicas
|
||||
# please visit http://pandora.sourceforge.net
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733
|
||||
# Version 7.0NG.734
|
||||
# Licensed under GPL license v2,
|
||||
# (c) 2003-2009 Artica Soluciones Tecnologicas
|
||||
# please visit http://pandora.sourceforge.net
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733
|
||||
# Version 7.0NG.734
|
||||
# Licensed under GPL license v2,
|
||||
# please visit http://pandora.sourceforge.net
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Fichero de configuracion base de agentes de Pandora
|
||||
# Base config file for Pandora agents
|
||||
# Version 7.0NG.733, Solaris version
|
||||
# Version 7.0NG.734, Solaris version
|
||||
|
||||
# General Parameters
|
||||
# ==================
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, AIX version
|
||||
# Version 7.0NG.734, AIX version
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2010 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package: pandorafms-agent-unix
|
||||
Version: 7.0NG.733-190417
|
||||
Version: 7.0NG.734-190503
|
||||
Architecture: all
|
||||
Priority: optional
|
||||
Section: admin
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
pandora_version="7.0NG.733-190417"
|
||||
pandora_version="7.0NG.734-190503"
|
||||
|
||||
echo "Test if you has the tools for to make the packages."
|
||||
whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, GNU/Linux
|
||||
# Version 7.0NG.734, GNU/Linux
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2012 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, FreeBSD Version
|
||||
# Version 7.0NG.734, FreeBSD Version
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2016 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, HP-UX Version
|
||||
# Version 7.0NG.734, HP-UX Version
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, GNU/Linux
|
||||
# Version 7.0NG.734, GNU/Linux
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2014 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, GNU/Linux
|
||||
# Version 7.0NG.734, GNU/Linux
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, NetBSD Version
|
||||
# Version 7.0NG.734, NetBSD Version
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2010 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Base config file for Pandora FMS agents
|
||||
# Version 7.0NG.733, Solaris Version
|
||||
# Version 7.0NG.734, Solaris Version
|
||||
# Licensed under GPL license v2,
|
||||
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
|
||||
# http://www.pandorafms.com
|
||||
|
|
|
@ -41,8 +41,8 @@ my $Sem = undef;
|
|||
# Semaphore used to control the number of threads
|
||||
my $ThreadSem = undef;
|
||||
|
||||
use constant AGENT_VERSION => '7.0NG.733';
|
||||
use constant AGENT_BUILD => '190417';
|
||||
use constant AGENT_VERSION => '7.0NG.734';
|
||||
use constant AGENT_BUILD => '190503';
|
||||
|
||||
# Agent log default file size maximum and instances
|
||||
use constant DEFAULT_MAX_LOG_SIZE => 600000;
|
||||
|
@ -1075,6 +1075,10 @@ sub send_buffered_xml_files ($;$) {
|
|||
unlink ("$temporal_file/$xml_file");
|
||||
}
|
||||
}
|
||||
# Do not get stuck trying to send buffered XML files to a secondary server.
|
||||
elsif ($flag_always == 2) {
|
||||
last;
|
||||
}
|
||||
}
|
||||
if (defined($flag_always) && ($flag_always == 2)){
|
||||
swap_servers ();
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#Pandora FMS Linux Agent
|
||||
#
|
||||
%define name pandorafms_agent_unix
|
||||
%define version 7.0NG.733
|
||||
%define release 190417
|
||||
%define version 7.0NG.734
|
||||
%define release 190503
|
||||
|
||||
Summary: Pandora FMS Linux agent, PERL version
|
||||
Name: %{name}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#Pandora FMS Linux Agent
|
||||
#
|
||||
%define name pandorafms_agent_unix
|
||||
%define version 7.0NG.733
|
||||
%define release 190417
|
||||
%define version 7.0NG.734
|
||||
%define release 190503
|
||||
|
||||
Summary: Pandora FMS Linux agent, PERL version
|
||||
Name: %{name}
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
# Please see http://www.pandorafms.org. This code is licensed under GPL 2.0 license.
|
||||
# **********************************************************************
|
||||
|
||||
PI_VERSION="7.0NG.733"
|
||||
PI_BUILD="190417"
|
||||
PI_VERSION="7.0NG.734"
|
||||
PI_BUILD="190503"
|
||||
OS_NAME=`uname -s`
|
||||
|
||||
FORCE=0
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Base config file for Pandora FMS Windows Agent
|
||||
# (c) 2006-2017 Artica Soluciones Tecnologicas
|
||||
# Version 7.0NG.733
|
||||
# Version 7.0NG.734
|
||||
|
||||
# This program is Free Software, you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public Licence as published by the Free Software
|
||||
|
|
|
@ -3,7 +3,7 @@ AllowLanguageSelection
|
|||
{Yes}
|
||||
|
||||
AppName
|
||||
{Pandora FMS Windows Agent v7.0NG.733}
|
||||
{Pandora FMS Windows Agent v7.0NG.734}
|
||||
|
||||
ApplicationID
|
||||
{17E3D2CF-CA02-406B-8A80-9D31C17BD08F}
|
||||
|
@ -186,7 +186,7 @@ UpgradeApplicationID
|
|||
{}
|
||||
|
||||
Version
|
||||
{190417}
|
||||
{190503}
|
||||
|
||||
ViewReadme
|
||||
{Yes}
|
||||
|
|
|
@ -30,7 +30,7 @@ using namespace Pandora;
|
|||
using namespace Pandora_Strutils;
|
||||
|
||||
#define PATH_SIZE _MAX_PATH+1
|
||||
#define PANDORA_VERSION ("7.0NG.733(Build 190417)")
|
||||
#define PANDORA_VERSION ("7.0NG.734(Build 190503)")
|
||||
|
||||
string pandora_path;
|
||||
string pandora_dir;
|
||||
|
|
|
@ -11,7 +11,7 @@ BEGIN
|
|||
VALUE "LegalCopyright", "Artica ST"
|
||||
VALUE "OriginalFilename", "PandoraAgent.exe"
|
||||
VALUE "ProductName", "Pandora FMS Windows Agent"
|
||||
VALUE "ProductVersion", "(7.0NG.733(Build 190417))"
|
||||
VALUE "ProductVersion", "(7.0NG.734(Build 190503))"
|
||||
VALUE "FileVersion", "1.0.0.0"
|
||||
END
|
||||
END
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package: pandorafms-console
|
||||
Version: 7.0NG.733-190417
|
||||
Version: 7.0NG.734-190503
|
||||
Architecture: all
|
||||
Priority: optional
|
||||
Section: admin
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
pandora_version="7.0NG.733-190417"
|
||||
pandora_version="7.0NG.734-190503"
|
||||
|
||||
package_pear=0
|
||||
package_pandora=1
|
||||
|
|
|
@ -10,5 +10,16 @@
|
|||
"require": {
|
||||
"mpdf/mpdf": "^7.1",
|
||||
"swiftmailer/swiftmailer": "^6.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Models\\": "include/rest-api/models",
|
||||
"Enterprise\\Models\\": "enterprise/include/rest-api/models"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ function dbmgr_extension_main()
|
|||
echo "<div style='overflow: auto;'>";
|
||||
$table = new stdClass();
|
||||
$table->width = '100%';
|
||||
$table->class = 'databox data';
|
||||
$table->class = 'info_table';
|
||||
$table->head = array_keys($result[0]);
|
||||
|
||||
$table->data = $result;
|
||||
|
|
|
@ -39,4 +39,16 @@ ALTER TABLE `treport_content_template` ADD COLUMN `unknown_checks` TINYINT(1) DE
|
|||
ALTER TABLE `treport_content_template` ADD COLUMN `agent_max_value` TINYINT(1) DEFAULT '1';
|
||||
ALTER TABLE `treport_content_template` ADD COLUMN `agent_min_value` TINYINT(1) DEFAULT '1';
|
||||
|
||||
ALTER TABLE `trecon_script` ADD COLUMN `type` int NOT NULL default 0;
|
||||
ALTER TABLE `trecon_task` ADD COLUMN `type` int NOT NULL default 0;
|
||||
|
||||
UPDATE `trecon_script` SET `type` = 1 WHERE `name`="Discovery.Application.VMware";
|
||||
UPDATE `trecon_script` SET `type` = 2 WHERE `name`="Discovery.Cloud";
|
||||
UPDATE `trecon_script` SET `type` = 3 WHERE `name` LIKE "IPAM%Recon";
|
||||
UPDATE `trecon_script` SET `type` = 4 WHERE `name` LIKE "IPMI%Recon";
|
||||
|
||||
UPDATE `trecon_task` SET `type`=3 WHERE `description`="Discovery.Application.VMware";
|
||||
UPDATE `trecon_task` SET `type`=2 WHERE `description`="Discovery.Cloud";
|
||||
UPDATE `trecon_task` SET `type`=7 WHERE `description`="Discovery.Cloud.RDS";
|
||||
|
||||
COMMIT;
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
// 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
|
||||
// Load global vars.
|
||||
global $config;
|
||||
|
||||
enterprise_include('godmode/agentes/configurar_agente.php');
|
||||
|
@ -23,10 +23,10 @@ ui_require_javascript_file('encode_decode_base64');
|
|||
|
||||
check_login();
|
||||
|
||||
// Get tab parameter to check ACL in each tabs
|
||||
// Get tab parameter to check ACL in each tabs.
|
||||
$tab = get_parameter('tab', 'main');
|
||||
|
||||
// See if id_agente is set (either POST or GET, otherwise -1
|
||||
// See if id_agente is set (either POST or GET, otherwise -1.
|
||||
$id_agente = (int) get_parameter('id_agente');
|
||||
$group = 0;
|
||||
$all_groups = [$group];
|
||||
|
@ -46,6 +46,7 @@ if (!check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
|
|||
break;
|
||||
|
||||
default:
|
||||
// Default.
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -63,11 +64,11 @@ require_once 'include/functions_modules.php';
|
|||
require_once 'include/functions_alerts.php';
|
||||
require_once 'include/functions_reporting.php';
|
||||
|
||||
// Get passed variables
|
||||
// Get passed variables.
|
||||
$alerttype = get_parameter('alerttype');
|
||||
$id_agent_module = (int) get_parameter('id_agent_module');
|
||||
|
||||
// Init vars
|
||||
// Init vars.
|
||||
$descripcion = '';
|
||||
$comentarios = '';
|
||||
$campo_1 = '';
|
||||
|
@ -137,7 +138,7 @@ $alert_priority = 0;
|
|||
$server_name = '';
|
||||
$grupo = 0;
|
||||
$id_os = 9;
|
||||
// Windows
|
||||
// Windows.
|
||||
$custom_id = '';
|
||||
$cascade_protection = 0;
|
||||
$cascade_protection_modules = 0;
|
||||
|
@ -156,7 +157,7 @@ $cps = 0;
|
|||
$create_agent = (bool) get_parameter('create_agent');
|
||||
$module_macros = [];
|
||||
|
||||
// Create agent
|
||||
// Create agent.
|
||||
if ($create_agent) {
|
||||
$mssg_warning = 0;
|
||||
$alias_safe_output = io_safe_output(get_parameter('alias', ''));
|
||||
|
@ -165,14 +166,14 @@ if ($create_agent) {
|
|||
$direccion_agente = (string) get_parameter_post('direccion', '');
|
||||
$unique_ip = (int) get_parameter_post('unique_ip', 0);
|
||||
|
||||
// safe_output only validate ip
|
||||
// Safe_output only validate ip.
|
||||
$direccion_agente = trim(io_safe_output($direccion_agente));
|
||||
|
||||
if (!validate_address($direccion_agente)) {
|
||||
$mssg_warning = 1;
|
||||
}
|
||||
|
||||
// safe-input before validate ip
|
||||
// Safe-input before validate ip.
|
||||
$direccion_agente = io_safe_input($direccion_agente);
|
||||
|
||||
$nombre_agente = hash('sha256', $alias.'|'.$direccion_agente.'|'.time().'|'.sprintf('%04d', rand(0, 10000)));
|
||||
|
@ -208,7 +209,7 @@ if ($create_agent) {
|
|||
$field_values[$field['id_field']] = (string) get_parameter_post('customvalue_'.$field['id_field'], '');
|
||||
}
|
||||
|
||||
// Check if agent exists (BUG WC-50518-2)
|
||||
// Check if agent exists (BUG WC-50518-2).
|
||||
if ($alias == '') {
|
||||
$agent_creation_error = __('No agent alias specified');
|
||||
$agent_created_ok = 0;
|
||||
|
@ -256,7 +257,7 @@ if ($create_agent) {
|
|||
}
|
||||
|
||||
if ($id_agente !== false) {
|
||||
// Create custom fields for this agent
|
||||
// Create custom fields for this agent.
|
||||
foreach ($field_values as $key => $value) {
|
||||
$update_custom = db_process_sql_insert(
|
||||
'tagent_custom_data',
|
||||
|
@ -268,7 +269,7 @@ if ($create_agent) {
|
|||
);
|
||||
}
|
||||
|
||||
// Create address for this agent in taddress
|
||||
// Create address for this agent in taddress.
|
||||
if ($direccion_agente != '') {
|
||||
agents_add_address($id_agente, $direccion_agente);
|
||||
}
|
||||
|
@ -311,7 +312,7 @@ if ($create_agent) {
|
|||
"Quiet":"'.(int) $quiet.'",
|
||||
"Cps":"'.(int) $cps.'"}';
|
||||
|
||||
// Create the secondary groups
|
||||
// Create the secondary groups.
|
||||
enterprise_hook(
|
||||
'agents_update_secondary_groups',
|
||||
[
|
||||
|
@ -341,14 +342,14 @@ if ($create_agent) {
|
|||
}
|
||||
}
|
||||
|
||||
// Show tabs
|
||||
// Show tabs.
|
||||
$img_style = [
|
||||
'class' => 'top',
|
||||
'width' => 16,
|
||||
];
|
||||
|
||||
if ($id_agente) {
|
||||
// View tab
|
||||
// View tab.
|
||||
$viewtab['text'] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'">'.html_print_image('images/operation.png', true, ['title' => __('View')]).'</a>';
|
||||
|
||||
if ($tab == 'view') {
|
||||
|
@ -359,7 +360,7 @@ if ($id_agente) {
|
|||
|
||||
$viewtab['operation'] = 1;
|
||||
|
||||
// Main tab
|
||||
// Main tab.
|
||||
$maintab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=main&id_agente='.$id_agente.'">'.html_print_image('images/gm_setup.png', true, ['title' => __('Setup')]).'</a>';
|
||||
if ($tab == 'main') {
|
||||
$maintab['active'] = true;
|
||||
|
@ -367,7 +368,7 @@ if ($id_agente) {
|
|||
$maintab['active'] = false;
|
||||
}
|
||||
|
||||
// Module tab
|
||||
// Module tab.
|
||||
$moduletab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=module&id_agente='.$id_agente.'">'.html_print_image('images/gm_modules.png', true, ['title' => __('Modules')]).'</a>';
|
||||
|
||||
if ($tab == 'module') {
|
||||
|
@ -376,7 +377,7 @@ if ($id_agente) {
|
|||
$moduletab['active'] = false;
|
||||
}
|
||||
|
||||
// Alert tab
|
||||
// Alert tab.
|
||||
$alerttab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente='.$id_agente.'">'.html_print_image('images/gm_alerts.png', true, ['title' => __('Alerts')]).'</a>';
|
||||
|
||||
if ($tab == 'alert') {
|
||||
|
@ -385,7 +386,7 @@ if ($id_agente) {
|
|||
$alerttab['active'] = false;
|
||||
}
|
||||
|
||||
// Template tab
|
||||
// Template tab.
|
||||
$templatetab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=template&id_agente='.$id_agente.'">'.html_print_image('images/templates.png', true, ['title' => __('Module templates')]).'</a>';
|
||||
|
||||
if ($tab == 'template') {
|
||||
|
@ -395,7 +396,7 @@ if ($id_agente) {
|
|||
}
|
||||
|
||||
|
||||
// Inventory
|
||||
// Inventory.
|
||||
$inventorytab = enterprise_hook('inventory_tab');
|
||||
|
||||
if ($inventorytab == -1) {
|
||||
|
@ -412,7 +413,7 @@ if ($id_agente) {
|
|||
}
|
||||
|
||||
if ($has_remote_conf === true) {
|
||||
// Plugins
|
||||
// Plugins.
|
||||
$pluginstab = enterprise_hook('plugins_tab');
|
||||
if ($pluginstab == -1) {
|
||||
$pluginstab = '';
|
||||
|
@ -421,21 +422,21 @@ if ($id_agente) {
|
|||
$pluginstab = '';
|
||||
}
|
||||
|
||||
// Collection
|
||||
// Collection.
|
||||
$collectiontab = enterprise_hook('collection_tab');
|
||||
|
||||
if ($collectiontab == -1) {
|
||||
$collectiontab = '';
|
||||
}
|
||||
|
||||
// Group tab
|
||||
// Group tab.
|
||||
$grouptab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&ag_group='.$group.'">'.html_print_image('images/group.png', true, [ 'title' => __('Group')]).'</a>';
|
||||
|
||||
$grouptab['active'] = false;
|
||||
|
||||
$gistab = [];
|
||||
|
||||
// GIS tab
|
||||
// GIS tab.
|
||||
if ($config['activate_gis']) {
|
||||
$gistab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=gis&id_agente='.$id_agente.'">'.html_print_image('images/gm_gis.png', true, [ 'title' => __('GIS data')]).'</a>';
|
||||
|
||||
|
@ -446,10 +447,10 @@ if ($id_agente) {
|
|||
}
|
||||
}
|
||||
|
||||
// Agent wizard tab
|
||||
// Agent wizard tab.
|
||||
$agent_wizard['text'] = '<a href="javascript:" class="agent_wizard_tab">'.html_print_image('images/wand_agent.png', true, [ 'title' => __('Agent wizard')]).'</a>';
|
||||
|
||||
// Hidden subtab layer
|
||||
// Hidden subtab layer.
|
||||
$agent_wizard['sub_menu'] = '<ul class="mn subsubmenu" style="display:none; float:none;">';
|
||||
$agent_wizard['sub_menu'] .= '<li class="nomn tab_godmode" style="text-align: center;">';
|
||||
$agent_wizard['sub_menu'] .= '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=snmp_explorer&id_agente='.$id_agente.'">'.html_print_image('images/wand_snmp.png', true, [ 'title' => __('SNMP Wizard')]).'</a>';
|
||||
|
@ -471,7 +472,7 @@ if ($id_agente) {
|
|||
|
||||
$total_incidents = agents_get_count_incidents($id_agente);
|
||||
|
||||
// Incident tab
|
||||
// Incident tab.
|
||||
if ($total_incidents > 0) {
|
||||
$incidenttab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=incident&id_agente='.$id_agente.'">'.html_print_image('images/book_edit.png', true, ['title' => __('Incidents')]).'</a>';
|
||||
|
||||
|
@ -532,7 +533,7 @@ if ($id_agente) {
|
|||
];
|
||||
}
|
||||
|
||||
// Only if the agent has incidents associated show incidents tab
|
||||
// Only if the agent has incidents associated show incidents tab.
|
||||
if ($total_incidents) {
|
||||
$onheader['incident'] = $incidenttab;
|
||||
}
|
||||
|
@ -545,7 +546,7 @@ if ($id_agente) {
|
|||
];
|
||||
}
|
||||
|
||||
// Extensions tabs
|
||||
// Extensions tabs.
|
||||
foreach ($config['extensions'] as $extension) {
|
||||
if (isset($extension['extension_god_tab'])) {
|
||||
if (check_acl($config['id_user'], $group, $extension['extension_god_tab']['acl'])) {
|
||||
|
@ -574,7 +575,7 @@ if ($id_agente) {
|
|||
}
|
||||
|
||||
$help_header = '';
|
||||
// This add information to the header
|
||||
// This add information to the header.
|
||||
switch ($tab) {
|
||||
case 'main':
|
||||
$tab_description = '- '.__('Setup');
|
||||
|
@ -639,6 +640,10 @@ if ($id_agente) {
|
|||
case 'wmi_explorer':
|
||||
$tab_description = '- '.__('WMI Wizard');
|
||||
break;
|
||||
|
||||
default:
|
||||
// Default.
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -649,10 +654,15 @@ if ($id_agente) {
|
|||
$tab_description = '- '.__('SNMP explorer');
|
||||
$help_header = 'snmp_explorer';
|
||||
break;
|
||||
|
||||
default:
|
||||
// Default.
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Default.
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -668,7 +678,7 @@ if ($id_agente) {
|
|||
$config['item_title_size_text']
|
||||
);
|
||||
} else {
|
||||
// Create agent
|
||||
// Create agent.
|
||||
ui_print_page_header(
|
||||
__('Agent manager'),
|
||||
'images/bricks.png',
|
||||
|
@ -682,12 +692,12 @@ $delete_conf_file = (bool) get_parameter('delete_conf_file');
|
|||
|
||||
if ($delete_conf_file) {
|
||||
$correct = false;
|
||||
// Delete remote configuration
|
||||
// Delete remote configuration.
|
||||
if (isset($config['remote_config'])) {
|
||||
$agent_md5 = md5(io_safe_output(agents_get_name($id_agente, 'none')), false);
|
||||
|
||||
if (file_exists($config['remote_config'].'/md5/'.$agent_md5.'.md5')) {
|
||||
// Agent remote configuration editor
|
||||
// Agent remote configuration editor.
|
||||
$file_name = $config['remote_config'].'/conf/'.$agent_md5.'.conf';
|
||||
$correct = @unlink($file_name);
|
||||
|
||||
|
@ -703,7 +713,7 @@ if ($delete_conf_file) {
|
|||
);
|
||||
}
|
||||
|
||||
// Show agent creation results
|
||||
// Show agent creation results.
|
||||
if ($create_agent) {
|
||||
if (!isset($agent_creation_error)) {
|
||||
$agent_creation_error = __('Could not be created');
|
||||
|
@ -720,17 +730,17 @@ if ($create_agent) {
|
|||
}
|
||||
}
|
||||
|
||||
// Fix / Normalize module data
|
||||
// Fix / Normalize module data.
|
||||
if (isset($_GET['fix_module'])) {
|
||||
$id_module = get_parameter_get('fix_module', 0);
|
||||
// get info about this module
|
||||
// Get info about this module.
|
||||
$media = reporting_get_agentmodule_data_average($id_module, 30758400);
|
||||
// Get average over the year
|
||||
// Get average over the year.
|
||||
$media *= 1.3;
|
||||
$error = '';
|
||||
$result = true;
|
||||
|
||||
// If the value of media is 0 or something went wrong, don't delete
|
||||
// If the value of media is 0 or something went wrong, don't delete.
|
||||
if (!empty($media)) {
|
||||
$where = [
|
||||
'datos' => '>'.$media,
|
||||
|
@ -759,9 +769,9 @@ if (isset($_GET['fix_module'])) {
|
|||
|
||||
$update_agent = (bool) get_parameter('update_agent');
|
||||
|
||||
// Update AGENT
|
||||
// Update AGENT.
|
||||
if ($update_agent) {
|
||||
// if modified some agent paramenter
|
||||
// If modified some agent paramenter.
|
||||
$mssg_warning = 0;
|
||||
$id_agente = (int) get_parameter_post('id_agente');
|
||||
$nombre_agente = str_replace('`', '‘', (string) get_parameter_post('agente', ''));
|
||||
|
@ -770,14 +780,14 @@ if ($update_agent) {
|
|||
$alias_as_name = (int) get_parameter_post('alias_as_name', 0);
|
||||
$direccion_agente = (string) get_parameter_post('direccion', '');
|
||||
$unique_ip = (int) get_parameter_post('unique_ip', 0);
|
||||
// safe_output only validate ip
|
||||
// Safe_output only validate ip.
|
||||
$direccion_agente = trim(io_safe_output($direccion_agente));
|
||||
|
||||
if (!validate_address($direccion_agente)) {
|
||||
$mssg_warning = 1;
|
||||
}
|
||||
|
||||
// safe-input before validate ip
|
||||
// Safe-input before validate ip.
|
||||
$direccion_agente = io_safe_input($direccion_agente);
|
||||
|
||||
$address_list = (string) get_parameter_post('address_list', '');
|
||||
|
@ -786,10 +796,13 @@ if ($update_agent) {
|
|||
&& $direccion_agente == agents_get_address($id_agente)
|
||||
&& $address_list != agents_get_address($id_agente)
|
||||
) {
|
||||
// If we selected another IP in the drop down list to be 'primary':
|
||||
// a) field is not the same as selectbox
|
||||
// b) field has not changed from current IP
|
||||
// c) selectbox is not the current IP
|
||||
/*
|
||||
* If we selected another IP in the drop down list to be 'primary':
|
||||
* a) field is not the same as selectbox
|
||||
* b) field has not changed from current IP
|
||||
* c) selectbox is not the current IP.
|
||||
*/
|
||||
|
||||
if (!empty($address_list)) {
|
||||
$direccion_agente = $address_list;
|
||||
}
|
||||
|
@ -799,7 +812,7 @@ if ($update_agent) {
|
|||
$intervalo = (int) get_parameter_post('intervalo', SECONDS_5MINUTES);
|
||||
$comentarios = str_replace('`', '‘', (string) get_parameter_post('comentarios', ''));
|
||||
$modo = (int) get_parameter_post('modo', 0);
|
||||
// Mode: Learning, Normal or Autodisabled
|
||||
// Mode: Learning, Normal or Autodisabled.
|
||||
$id_os = (int) get_parameter_post('id_os');
|
||||
$disabled = (bool) get_parameter_post('disabled');
|
||||
$server_name = (string) get_parameter_post('server_name', '');
|
||||
|
@ -837,7 +850,7 @@ if ($update_agent) {
|
|||
);
|
||||
|
||||
if ($old_value === false) {
|
||||
// Create custom field if not exist
|
||||
// Create custom field if not exist.
|
||||
$update_custom = db_process_sql_insert(
|
||||
'tagent_custom_data',
|
||||
[
|
||||
|
@ -866,10 +879,10 @@ if ($update_agent) {
|
|||
ui_print_warning_message(__('The ip or dns name entered cannot be resolved'));
|
||||
}
|
||||
|
||||
// Verify if there is another agent with the same name but different ID
|
||||
// Verify if there is another agent with the same name but different ID.
|
||||
if ($alias == '') {
|
||||
ui_print_error_message(__('No agent alias specified'));
|
||||
// If there is an agent with the same name, but a different ID
|
||||
// If there is an agent with the same name, but a different ID.
|
||||
}
|
||||
|
||||
if ($unique_ip && $direccion_agente != '') {
|
||||
|
@ -882,7 +895,7 @@ if ($update_agent) {
|
|||
} else if ($exists_ip) {
|
||||
ui_print_error_message(__('Duplicate main IP address'));
|
||||
} else {
|
||||
// If different IP is specified than previous, add the IP
|
||||
// If different IP is specified than previous, add the IP.
|
||||
if ($direccion_agente != ''
|
||||
&& $direccion_agente != agents_get_address($id_agente)
|
||||
) {
|
||||
|
@ -890,7 +903,7 @@ if ($update_agent) {
|
|||
}
|
||||
|
||||
$action_delete_ip = (bool) get_parameter('delete_ip', false);
|
||||
// If IP is set for deletion, delete first
|
||||
// If IP is set for deletion, delete first.
|
||||
if ($action_delete_ip) {
|
||||
$delete_ip = get_parameter_post('address_list');
|
||||
|
||||
|
@ -939,11 +952,11 @@ if ($update_agent) {
|
|||
__('There was a problem updating the agent')
|
||||
);
|
||||
} else {
|
||||
// Update the agent from the metaconsole cache
|
||||
// Update the agent from the metaconsole cache.
|
||||
enterprise_include_once('include/functions_agents.php');
|
||||
enterprise_hook('agent_update_from_cache', [$id_agente, $values, $server_name]);
|
||||
|
||||
// Update the configuration files
|
||||
// Update the configuration files.
|
||||
if ($old_values['intervalo'] != $intervalo) {
|
||||
enterprise_hook(
|
||||
'config_agents_update_config_token',
|
||||
|
@ -1057,9 +1070,9 @@ if ($update_agent) {
|
|||
}
|
||||
|
||||
// Read agent data
|
||||
// This should be at the end of all operation checks, to read the changes - $id_agente doesn't have to be retrieved
|
||||
// This should be at the end of all operation checks, to read the changes - $id_agente doesn't have to be retrieved.
|
||||
if ($id_agente) {
|
||||
// This has been done in the beginning of the page, but if an agent was created, this id might change
|
||||
// This has been done in the beginning of the page, but if an agent was created, this id might change.
|
||||
$id_grupo = agents_get_agent_group($id_agente);
|
||||
if (!check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') && !check_acl_one_of_groups($config['id_user'], $all_groups, 'AD')) {
|
||||
db_pandora_audit('ACL Violation', 'Trying to admin an agent without access');
|
||||
|
@ -1069,13 +1082,13 @@ if ($id_agente) {
|
|||
|
||||
$agent = db_get_row('tagente', 'id_agente', $id_agente);
|
||||
if (empty($agent)) {
|
||||
// Close out the page
|
||||
// Close out the page.
|
||||
ui_print_error_message(__('There was a problem loading the agent'));
|
||||
return;
|
||||
}
|
||||
|
||||
$intervalo = $agent['intervalo'];
|
||||
// Define interval in seconds
|
||||
// Define interval in seconds.
|
||||
$nombre_agente = $agent['nombre'];
|
||||
if (empty($alias)) {
|
||||
$alias = $agent['alias'];
|
||||
|
@ -1111,11 +1124,11 @@ $create_module = (bool) get_parameter('create_module');
|
|||
$delete_module = (bool) get_parameter('delete_module');
|
||||
$enable_module = (int) get_parameter('enable_module');
|
||||
$disable_module = (int) get_parameter('disable_module');
|
||||
// It is the id_agent_module to duplicate
|
||||
// It is the id_agent_module to duplicate.
|
||||
$duplicate_module = (int) get_parameter('duplicate_module');
|
||||
$edit_module = (bool) get_parameter('edit_module');
|
||||
|
||||
// GET DATA for MODULE UPDATE OR MODULE INSERT
|
||||
// GET DATA for MODULE UPDATE OR MODULE INSERT.
|
||||
if ($update_module || $create_module) {
|
||||
$id_grupo = agents_get_agent_group($id_agente);
|
||||
$all_groups = agents_get_all_groups_agent($id_agente, $id_grupo);
|
||||
|
@ -1136,9 +1149,12 @@ if ($update_module || $create_module) {
|
|||
$id_module_group = (int) get_parameter('id_module_group');
|
||||
$flag = (bool) get_parameter('flag');
|
||||
|
||||
// Don't read as (float) because it lost it's decimals when put into MySQL
|
||||
// where are very big and PHP uses scientific notation, p.e:
|
||||
// 1.23E-10 is 0.000000000123
|
||||
/*
|
||||
* Don't read as (float) because it lost it's decimals when put into MySQL
|
||||
* where are very big and PHP uses scientific notation, p.e:
|
||||
* 1.23E-10 is 0.000000000123.
|
||||
*/
|
||||
|
||||
$post_process = (string) get_parameter('post_process', 0.0);
|
||||
if (get_parameter('prediction_module')) {
|
||||
$prediction_module = 1;
|
||||
|
@ -1160,7 +1176,7 @@ if ($update_module || $create_module) {
|
|||
$tcp_send = (string) get_parameter('tcp_send');
|
||||
$tcp_rcv = (string) get_parameter('tcp_rcv');
|
||||
$tcp_port = (int) get_parameter('tcp_port');
|
||||
// Correction in order to not insert 0 as port
|
||||
// Correction in order to not insert 0 as port.
|
||||
$is_port_empty = get_parameter('tcp_port', '');
|
||||
if ($is_port_empty === '') {
|
||||
$tcp_port = null;
|
||||
|
@ -1186,7 +1202,7 @@ if ($update_module || $create_module) {
|
|||
}
|
||||
|
||||
if ($id_module_type == 25) {
|
||||
// web analysis, from MODULE_WUX
|
||||
// web analysis, from MODULE_WUX.
|
||||
$custom_string_1 = base64_encode((string) get_parameter('custom_string_1', $custom_string_1_default));
|
||||
$custom_integer_1 = (int) get_parameter('custom_integer_1', $custom_integer_1_default);
|
||||
} else {
|
||||
|
@ -1198,7 +1214,7 @@ if ($update_module || $create_module) {
|
|||
$custom_string_3 = (string) get_parameter('custom_string_3', $custom_string_3_default);
|
||||
$custom_integer_2 = (int) get_parameter('custom_integer_2', 0);
|
||||
|
||||
// Get macros
|
||||
// Get macros.
|
||||
$macros = (string) get_parameter('macros');
|
||||
|
||||
if (!empty($macros)) {
|
||||
|
@ -1225,7 +1241,8 @@ if ($update_module || $create_module) {
|
|||
if (preg_match('/^module_name\s*(.*)/', $line, $match)) {
|
||||
$new_configuration_data .= 'module_name '.io_safe_output($name)."\n";
|
||||
}
|
||||
// We delete from conf all the module macros starting with _field
|
||||
|
||||
// We delete from conf all the module macros starting with _field.
|
||||
else if (!preg_match('/^module_macro_field.*/', $line, $match)) {
|
||||
$new_configuration_data .= "$line\n";
|
||||
}
|
||||
|
@ -1243,14 +1260,6 @@ if ($update_module || $create_module) {
|
|||
$new_configuration_data = str_replace('module_end', $macros_for_data.'module_end', $new_configuration_data);
|
||||
}
|
||||
|
||||
/*
|
||||
$macros_for_data = enterprise_hook('config_agents_get_macros_data_conf', array($_POST));
|
||||
|
||||
if ($macros_for_data !== ENTERPRISE_NOT_HOOK && $macros_for_data != '') {
|
||||
// Add macros to configuration file
|
||||
$new_configuration_data = str_replace('module_end', $macros_for_data."module_end", $new_configuration_data);
|
||||
}
|
||||
*/
|
||||
$configuration_data = str_replace(
|
||||
'\\',
|
||||
'\',
|
||||
|
@ -1269,16 +1278,16 @@ if ($update_module || $create_module) {
|
|||
|
||||
$snmp_community = (string) get_parameter('snmp_community');
|
||||
$snmp_oid = (string) get_parameter('snmp_oid');
|
||||
// Change double quotes by single
|
||||
// Change double quotes by single.
|
||||
$snmp_oid = preg_replace('/"/', ''', $snmp_oid);
|
||||
|
||||
if (empty($snmp_oid)) {
|
||||
// The user did not set any OID manually but did a SNMP walk
|
||||
// The user did not set any OID manually but did a SNMP walk.
|
||||
$snmp_oid = (string) get_parameter('select_snmp_oid');
|
||||
}
|
||||
|
||||
if ($id_module_type >= 15 && $id_module_type <= 18) {
|
||||
// New support for snmp v3
|
||||
// New support for snmp v3.
|
||||
$tcp_send = (string) get_parameter('snmp_version');
|
||||
$plugin_user = (string) get_parameter('snmp3_auth_user');
|
||||
$plugin_pass = io_input_password((string) get_parameter('snmp3_auth_pass'));
|
||||
|
@ -1410,15 +1419,25 @@ if ($update_module || $create_module) {
|
|||
$module_macro_values = (array) get_parameter('module_macro_values', []);
|
||||
$module_macros = modules_get_module_macros_json($module_macro_names, $module_macro_values);
|
||||
|
||||
// Make changes in the conf file if necessary
|
||||
// Make changes in the conf file if necessary.
|
||||
enterprise_include_once('include/functions_config_agents.php');
|
||||
|
||||
$module_in_policy = enterprise_hook('policies_is_module_in_policy', [$id_agent_module]);
|
||||
$module_linked = enterprise_hook('policies_is_module_linked', [$id_agent_module]);
|
||||
|
||||
if ((!$module_in_policy && !$module_linked )
|
||||
|| ( $module_in_policy && !$module_linked )
|
||||
if ((!$module_in_policy && !$module_linked && $update_module)
|
||||
|| ( $module_in_policy && !$module_linked && $update_module)
|
||||
) {
|
||||
enterprise_hook(
|
||||
'config_agents_update_module_in_conf',
|
||||
[
|
||||
$id_agente,
|
||||
io_safe_output($old_configuration_data),
|
||||
io_safe_output($configuration_data),
|
||||
$disabled,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
enterprise_hook(
|
||||
'config_agents_write_module_in_conf',
|
||||
[
|
||||
|
@ -1431,7 +1450,7 @@ if ($update_module || $create_module) {
|
|||
}
|
||||
}
|
||||
|
||||
// MODULE UPDATE
|
||||
// MODULE UPDATE.
|
||||
if ($update_module) {
|
||||
$id_agent_module = (int) get_parameter('id_agent_module');
|
||||
|
||||
|
@ -1517,7 +1536,7 @@ if ($update_module) {
|
|||
}
|
||||
}
|
||||
|
||||
// In local modules, the interval is updated by agent
|
||||
// In local modules, the interval is updated by agent.
|
||||
$module_kind = (int) get_parameter('moduletype');
|
||||
if ($module_kind == MODULE_DATA) {
|
||||
unset($values['module_interval']);
|
||||
|
@ -1586,7 +1605,7 @@ if ($update_module) {
|
|||
);
|
||||
}
|
||||
|
||||
// Update the module interval
|
||||
// Update the module interval.
|
||||
cron_update_module_interval($id_agent_module, $cron_interval);
|
||||
|
||||
ui_print_success_message(__('Module successfully updated'));
|
||||
|
@ -1605,8 +1624,7 @@ if ($update_module) {
|
|||
}
|
||||
}
|
||||
|
||||
// MODULE INSERT
|
||||
// =================
|
||||
// MODULE INSERT.
|
||||
if ($create_module) {
|
||||
if (isset($_POST['combo_snmp_oid'])) {
|
||||
$combo_snmp_oid = get_parameter_post('combo_snmp_oid');
|
||||
|
@ -1630,6 +1648,10 @@ if ($create_module) {
|
|||
$description = ' ';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Default.
|
||||
break;
|
||||
}
|
||||
|
||||
$values = [
|
||||
|
@ -1755,7 +1777,7 @@ if ($create_module) {
|
|||
enterprise_hook('modules_create_synthetic_operations', [$id_agent_module, $serialize_ops]);
|
||||
}
|
||||
|
||||
// Update the module interval
|
||||
// Update the module interval.
|
||||
cron_update_module_interval($id_agent_module, $cron_interval);
|
||||
|
||||
ui_print_success_message(__('Module added successfully'));
|
||||
|
@ -1776,7 +1798,7 @@ if ($create_module) {
|
|||
}
|
||||
|
||||
// MODULE DELETION
|
||||
// =================
|
||||
// =================.
|
||||
if ($delete_module) {
|
||||
// DELETE agent module !
|
||||
$id_borrar_modulo = (int) get_parameter_get('delete_module', 0);
|
||||
|
@ -1812,7 +1834,7 @@ if ($delete_module) {
|
|||
enterprise_include_once('include/functions_config_agents.php');
|
||||
enterprise_hook('config_agents_delete_module_in_conf', [modules_get_agentmodule_agent($id_borrar_modulo), modules_get_agentmodule_name($id_borrar_modulo)]);
|
||||
|
||||
// Init transaction
|
||||
// Init transaction.
|
||||
$error = 0;
|
||||
|
||||
// First delete from tagente_modulo -> if not successful, increment
|
||||
|
@ -1831,7 +1853,7 @@ if ($delete_module) {
|
|||
if ($result === false) {
|
||||
$error++;
|
||||
} else {
|
||||
// Set flag to update module status count
|
||||
// Set flag to update module status count.
|
||||
db_process_sql(
|
||||
'UPDATE tagente
|
||||
SET update_module_count = 1, update_alert_count = 1
|
||||
|
@ -1873,7 +1895,7 @@ if ($delete_module) {
|
|||
}
|
||||
|
||||
// Trick to detect if we are deleting a synthetic module (avg or arithmetic)
|
||||
// If result is empty then module doesn't have this type of submodules
|
||||
// If result is empty then module doesn't have this type of submodules.
|
||||
$ops_json = enterprise_hook('modules_get_synthetic_operations', [$id_borrar_modulo]);
|
||||
$result_ops_synthetic = json_decode($ops_json);
|
||||
if (!empty($result_ops_synthetic)) {
|
||||
|
@ -1881,18 +1903,17 @@ if ($delete_module) {
|
|||
if ($result === false) {
|
||||
$error++;
|
||||
}
|
||||
} //end if
|
||||
else {
|
||||
} else {
|
||||
$result_components = enterprise_hook('modules_get_synthetic_components', [$id_borrar_modulo]);
|
||||
$count_components = 1;
|
||||
if (!empty($result_components)) {
|
||||
// Get number of components pending to delete to know when it's needed to update orders
|
||||
// Get number of components pending to delete to know when it's needed to update orders.
|
||||
$num_components = count($result_components);
|
||||
$last_target_module = 0;
|
||||
foreach ($result_components as $id_target_module) {
|
||||
// Detects change of component or last component to update orders
|
||||
// Detects change of component or last component to update orders.
|
||||
if (($count_components == $num_components)
|
||||
or ($last_target_module != $id_target_module)
|
||||
|| ($last_target_module != $id_target_module)
|
||||
) {
|
||||
$update_orders = true;
|
||||
} else {
|
||||
|
@ -1911,7 +1932,7 @@ if ($delete_module) {
|
|||
}
|
||||
}
|
||||
|
||||
// Check for errors
|
||||
// Check for errors.
|
||||
if ($error != 0) {
|
||||
ui_print_error_message(__('There was a problem deleting the module'));
|
||||
} else {
|
||||
|
@ -1929,7 +1950,7 @@ if ($delete_module) {
|
|||
}
|
||||
|
||||
// MODULE DUPLICATION
|
||||
// ==================
|
||||
// ==================.
|
||||
if (!empty($duplicate_module)) {
|
||||
// DUPLICATE agent module !
|
||||
$id_duplicate_module = $duplicate_module;
|
||||
|
@ -1976,7 +1997,7 @@ if (!empty($duplicate_module)) {
|
|||
}
|
||||
|
||||
// MODULE ENABLE/DISABLE
|
||||
// =====================
|
||||
// =====================.
|
||||
if ($enable_module) {
|
||||
$result = modules_change_disabled($enable_module, 0);
|
||||
$modulo_nombre = db_get_row_sql('SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = '.$enable_module.'');
|
||||
|
@ -2016,7 +2037,7 @@ if ($disable_module) {
|
|||
}
|
||||
|
||||
// UPDATE GIS
|
||||
// ==========
|
||||
// ==========.
|
||||
$updateGIS = get_parameter('update_gis', 0);
|
||||
if ($updateGIS) {
|
||||
$updateGisData = get_parameter('update_gis_data');
|
||||
|
@ -2104,9 +2125,8 @@ switch ($tab) {
|
|||
break;
|
||||
|
||||
case 'alert':
|
||||
/*
|
||||
Because $id_agente is set, it will show only agent alerts */
|
||||
// This var is for not display create button on alert list
|
||||
// Because $id_agente is set, it will show only agent alerts.
|
||||
// This var is for not display create button on alert list.
|
||||
$dont_display_alert_create_bttn = true;
|
||||
include 'godmode/alerts/alert_list.php';
|
||||
break;
|
||||
|
@ -2155,7 +2175,7 @@ switch ($tab) {
|
|||
default:
|
||||
if (enterprise_hook('switch_agent_tab', [$tab])) {
|
||||
// This will make sure that blank pages will have at least some
|
||||
// debug info in them - do not translate debug
|
||||
// debug info in them - do not translate debug.
|
||||
ui_print_error_message(__('Invalid tab specified'));
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1090,10 +1090,11 @@ function readFields() {
|
|||
var text = tinymce.get("text-label").getContent();
|
||||
values["label"] = text;
|
||||
|
||||
values["percentile_label_color"] = $(
|
||||
"input[name=percentile_label_color]"
|
||||
).val();
|
||||
|
||||
if ($("input[name=percentile_label]").val().length > 0) {
|
||||
values["percentile_label_color"] = $(
|
||||
"input[name=percentile_label_color]"
|
||||
).val();
|
||||
values["label"] =
|
||||
"<span style='color:" +
|
||||
values["percentile_label_color"] +
|
||||
|
|
|
@ -1205,4 +1205,6 @@ ui_require_javascript_file('pandora_modules');
|
|||
$('.command_macro').click(macros_click_locked_event);
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
|
|
@ -70,10 +70,6 @@ $values[SECONDS_5MINUTES] = human_time_description_raw(SECONDS_5MINUTES);
|
|||
$values[SECONDS_10MINUTES] = human_time_description_raw(SECONDS_10MINUTES);
|
||||
$values[SECONDS_30MINUTES] = human_time_description_raw(SECONDS_30MINUTES);
|
||||
|
||||
$table_behaviour->data[$row][0] = __('Default interval for refresh on Visual Console').ui_print_help_tip(__('This interval will affect to Visual Console pages'), true);
|
||||
$table_behaviour->data[$row][1] = html_print_select($values, 'vc_refr', $config['vc_refr'], '', 'N/A', 0, true, false, false);
|
||||
$row++;
|
||||
|
||||
$table_behaviour->data[$row][0] = __('Paginated module view');
|
||||
$table_behaviour->data[$row][1] = html_print_checkbox_switch(
|
||||
'paginate_module',
|
||||
|
@ -908,6 +904,24 @@ $row++;
|
|||
$table_vc->size[0] = '50%';
|
||||
$table_vc->data = [];
|
||||
|
||||
// Remove when the new view reaches rock solid stability.
|
||||
$table_vc->data[$row][0] = __('Legacy Visual Console View');
|
||||
$table_vc->data[$row][0] .= ui_print_help_tip(
|
||||
__('To use the old view when using the Visual Console visor'),
|
||||
true
|
||||
);
|
||||
$table_vc->data[$row][1] = html_print_checkbox_switch(
|
||||
'legacy_vc',
|
||||
1,
|
||||
(bool) $config['legacy_vc'],
|
||||
true
|
||||
);
|
||||
$row++;
|
||||
|
||||
$table_vc->data[$row][0] = __('Default interval for refresh on Visual Console').ui_print_help_tip(__('This interval will affect to Visual Console pages'), true);
|
||||
$table_vc->data[$row][1] = html_print_select($values, 'vc_refr', (int) $config['vc_refr'], '', 'N/A', 0, true, false, false);
|
||||
$row++;
|
||||
|
||||
$vc_favourite_view_array[0] = __('Classic view');
|
||||
$vc_favourite_view_array[1] = __('View of favorites');
|
||||
$table_vc->data[$row][0] = __('Type of view of visual consoles').ui_print_help_tip(__('Allows you to directly display the list of favorite visual consoles'), true);
|
||||
|
@ -918,12 +932,8 @@ $row++;
|
|||
$table_vc->data[$row][1] = "<input type ='number' value=".$config['vc_menu_items']." size='5' name='vc_menu_items' min='0' max='25'>";
|
||||
$row++;
|
||||
|
||||
if (empty($config['vc_line_thickness'])) {
|
||||
$config['vc_line_thickness'] = 2;
|
||||
}
|
||||
|
||||
$table_vc->data[$row][0] = __('Default line thickness for the Visual Console').ui_print_help_tip(__('This interval will affect to the lines between elements on the Visual Console'), true);
|
||||
$table_vc->data[$row][1] = html_print_input_text('vc_line_thickness', $config['vc_line_thickness'], '', 5, 5, true);
|
||||
$table_vc->data[$row][1] = html_print_input_text('vc_line_thickness', (int) $config['vc_line_thickness'], '', 5, 5, true);
|
||||
|
||||
|
||||
echo '<fieldset>';
|
||||
|
|
|
@ -96,8 +96,20 @@ class DiscoveryTaskList extends Wizard
|
|||
]
|
||||
);
|
||||
|
||||
// Header
|
||||
ui_print_page_header(__('Task list'), '', false, '', true, '', false, '', GENERIC_SIZE_TEXT, '', $this->printHeader(true));
|
||||
// Header.
|
||||
ui_print_page_header(
|
||||
__('Task list'),
|
||||
'',
|
||||
false,
|
||||
'',
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
'',
|
||||
GENERIC_SIZE_TEXT,
|
||||
'',
|
||||
$this->printHeader(true)
|
||||
);
|
||||
|
||||
// Show redirected messages from discovery.php.
|
||||
if ($status === 0) {
|
||||
|
@ -404,15 +416,30 @@ class DiscoveryTaskList extends Wizard
|
|||
// Exceptions: IPAM.
|
||||
$ipam = false;
|
||||
if ($task['id_recon_script'] != null) {
|
||||
$recon_script_name = db_get_value('name', 'trecon_script', 'id_recon_script', $task['id_recon_script']);
|
||||
if (io_safe_output($recon_script_name) == 'IPAM Recon'
|
||||
&& enterprise_installed()
|
||||
) {
|
||||
$subnet_obj = json_decode($task['macros'], true);
|
||||
$subnet = $subnet_obj['1']['value'];
|
||||
$tipam_task_id = db_get_value('id', 'tipam_network', 'id_recon_task', $task['id_rt']);
|
||||
$ipam = true;
|
||||
$recon_script_data = db_get_row(
|
||||
'trecon_script',
|
||||
'id_recon_script',
|
||||
$task['id_recon_script']
|
||||
);
|
||||
if ($recon_script_data !== false) {
|
||||
$recon_script_name = $recon_script_data['name'];
|
||||
if (io_safe_output($recon_script_name) == 'IPAM Recon'
|
||||
&& enterprise_installed()
|
||||
) {
|
||||
$subnet_obj = json_decode($task['macros'], true);
|
||||
$subnet = $subnet_obj['1']['value'];
|
||||
$tipam_task_id = db_get_value(
|
||||
'id',
|
||||
'tipam_network',
|
||||
'id_recon_task',
|
||||
$task['id_rt']
|
||||
);
|
||||
$ipam = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$recon_script_data = false;
|
||||
$recon_script_name = false;
|
||||
}
|
||||
|
||||
if ($task['disabled'] == 0 && $server_name !== '') {
|
||||
|
@ -464,15 +491,56 @@ class DiscoveryTaskList extends Wizard
|
|||
}
|
||||
|
||||
if ($task['id_recon_script'] == 0) {
|
||||
// Discovery NetScan.
|
||||
$data[6] = html_print_image(
|
||||
'images/network.png',
|
||||
true,
|
||||
['title' => __('Discovery NetScan')]
|
||||
).' ';
|
||||
$data[6] .= network_profiles_get_name(
|
||||
$task['id_network_profile']
|
||||
);
|
||||
// Internal discovery task.
|
||||
switch ($task['type']) {
|
||||
case DISCOVERY_CLOUD_AWS_RDS:
|
||||
// Discovery Applications MySQL.
|
||||
$data[6] = html_print_image(
|
||||
'images/network.png',
|
||||
true,
|
||||
['title' => __('Discovery Cloud RDS')]
|
||||
).' ';
|
||||
$data[6] .= __('Discovery.Cloud.Aws.RDS');
|
||||
break;
|
||||
|
||||
case DISCOVERY_APP_MYSQL:
|
||||
// Discovery Applications MySQL.
|
||||
$data[6] = html_print_image(
|
||||
'images/network.png',
|
||||
true,
|
||||
['title' => __('Discovery Applications MySQL')]
|
||||
).' ';
|
||||
$data[6] .= __('Discovery.App.MySQL');
|
||||
break;
|
||||
|
||||
case DISCOVERY_APP_ORACLE:
|
||||
// Discovery Applications Oracle.
|
||||
$data[6] = html_print_image(
|
||||
'images/network.png',
|
||||
true,
|
||||
['title' => __('Discovery Applications Oracle')]
|
||||
).' ';
|
||||
$data[6] .= __('Discovery.App.Oracle');
|
||||
break;
|
||||
|
||||
case DISCOVERY_HOSTDEVICES:
|
||||
default:
|
||||
// Discovery NetScan.
|
||||
$data[6] = html_print_image(
|
||||
'images/network.png',
|
||||
true,
|
||||
['title' => __('Discovery NetScan')]
|
||||
).' ';
|
||||
$str = network_profiles_get_name(
|
||||
$task['id_network_profile']
|
||||
);
|
||||
if (!empty($str)) {
|
||||
$data[6] .= $str;
|
||||
} else {
|
||||
$data[6] .= __('Discovery.NetScan');
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// APP recon task.
|
||||
$data[6] = html_print_image(
|
||||
|
@ -512,7 +580,11 @@ class DiscoveryTaskList extends Wizard
|
|||
$data[9] .= '</a>';
|
||||
}
|
||||
|
||||
if ($task['disabled'] != 2 && $task['utimestamp'] > 0) {
|
||||
if ($task['disabled'] != 2 && $task['utimestamp'] > 0
|
||||
&& $task['type'] != DISCOVERY_APP_MYSQL
|
||||
&& $task['type'] != DISCOVERY_APP_ORACLE
|
||||
&& $task['type'] != DISCOVERY_CLOUD_AWS_RDS
|
||||
) {
|
||||
$data[9] .= '<a href="#" onclick="show_map('.$task['id_rt'].',\''.$task['name'].'\')">';
|
||||
$data[9] .= html_print_image(
|
||||
'images/dynamic_network_icon.png',
|
||||
|
@ -548,7 +620,7 @@ class DiscoveryTaskList extends Wizard
|
|||
$data[9] .= '<a href="'.ui_get_full_url(
|
||||
sprintf(
|
||||
'index.php?sec=gservers&sec2=godmode/servers/discovery&%s&task=%d',
|
||||
$this->getTargetWiz($task),
|
||||
$this->getTargetWiz($task, $recon_script_data),
|
||||
$task['id_rt']
|
||||
)
|
||||
).'">'.html_print_image(
|
||||
|
@ -608,28 +680,49 @@ class DiscoveryTaskList extends Wizard
|
|||
/**
|
||||
* Return target url sub-string to edit target task.
|
||||
*
|
||||
* @param array $task With all data.
|
||||
* @param array $task With all data.
|
||||
* @param array $script With all script data or false if undefined.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTargetWiz($task)
|
||||
public function getTargetWiz($task, $script=false)
|
||||
{
|
||||
// TODO: Do not use description. Use recon_script ID instead.
|
||||
switch ($task['description']) {
|
||||
case 'Discovery.Application.VMware':
|
||||
return 'wiz=app&mode=vmware&page=0';
|
||||
if ($script !== false) {
|
||||
switch ($script['type']) {
|
||||
case DISCOVERY_SCRIPT_CLOUD_AWS:
|
||||
return 'wiz=cloud&mode=amazonws&page=1';
|
||||
|
||||
case CLOUDWIZARD_AWS_DESCRIPTION:
|
||||
case DISCOVERY_SCRIPT_APP_VMWARE:
|
||||
return 'wiz=app&mode=vmware&page=0';
|
||||
|
||||
case DISCOVERY_SCRIPT_IPAM_RECON:
|
||||
return '';
|
||||
|
||||
case DISCOVERY_SCRIPT_IPMI_RECON:
|
||||
default:
|
||||
return 'wiz=hd&mode=customnetscan';
|
||||
}
|
||||
}
|
||||
|
||||
switch ($task['type']) {
|
||||
case DISCOVERY_APP_MYSQL:
|
||||
return 'wiz=app&mode=mysql&page=0';
|
||||
|
||||
case DISCOVERY_APP_ORACLE:
|
||||
return 'wiz=app&mode=oracle&page=0';
|
||||
|
||||
case DISCOVERY_CLOUD_AWS:
|
||||
case DISCOVERY_CLOUD_AWS_EC2:
|
||||
return 'wiz=cloud&mode=amazonws&page=1';
|
||||
|
||||
case 'console_task':
|
||||
return 'wiz=ctask';
|
||||
case DISCOVERY_CLOUD_AWS_RDS:
|
||||
return 'wiz=cloud&mode=amazonws&sub=rds&page=0';
|
||||
|
||||
default:
|
||||
if ($task['id_recon_script'] === null) {
|
||||
return 'wiz=hd&mode=netscan';
|
||||
if ($task['description'] == 'console_task') {
|
||||
return 'wiz=ctask';
|
||||
} else {
|
||||
return 'wiz=hd&mode=customnetscan';
|
||||
return 'wiz=hd&mode=netscan';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -149,7 +149,8 @@ class HostDevices extends Wizard
|
|||
),
|
||||
'label' => __('Discovery'),
|
||||
],
|
||||
]
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
ui_print_page_header(__('Host & devices'), '', false, '', true, '', false, '', GENERIC_SIZE_TEXT, '', $this->printHeader(true));
|
||||
|
@ -533,7 +534,19 @@ class HostDevices extends Wizard
|
|||
if ($this->page < $this->maxPagesNetScan) {
|
||||
// Avoid to print header out of wizard.
|
||||
$this->prepareBreadcrum($breadcrum);
|
||||
ui_print_page_header(__('NetScan'), '', false, '', true, '', false, '', GENERIC_SIZE_TEXT, '', $this->printHeader(true));
|
||||
ui_print_page_header(
|
||||
__('NetScan'),
|
||||
'',
|
||||
false,
|
||||
'',
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
'',
|
||||
GENERIC_SIZE_TEXT,
|
||||
'',
|
||||
$this->printHeader(true)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->page) === true
|
||||
|
@ -581,113 +594,83 @@ class HostDevices extends Wizard
|
|||
if (isset($this->page) === false
|
||||
|| $this->page == 0
|
||||
) {
|
||||
$form = [];
|
||||
|
||||
// Input task name.
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Task name').'</b>',
|
||||
'arguments' => [
|
||||
// Comment input
|
||||
$comment_input ='<div class="label_select"><label>'.__('Comment').':</label></div>';
|
||||
|
||||
$comment_input .= $this->printInput([
|
||||
'name' => 'comment',
|
||||
'rows' => 1,
|
||||
'columns' => 1,
|
||||
'value' => $this->task['description'],
|
||||
'type' => 'textarea',
|
||||
'size' => 25,
|
||||
'class' => 'discovery_textarea_input',
|
||||
'return' => true
|
||||
]);
|
||||
|
||||
// Task input
|
||||
$taskname_input_label = '<div class="label_select"><label>'.__('Task name').':</label></div>';
|
||||
|
||||
$taskname_input = $this->printInput([
|
||||
'name' => 'taskname',
|
||||
'value' => $this->task['name'],
|
||||
'type' => 'text',
|
||||
'size' => 25,
|
||||
],
|
||||
];
|
||||
'class' => 'discovery_full_width_input'
|
||||
]);
|
||||
|
||||
if (isset($this->task['id_rt']) === true) {
|
||||
// Propagate id.
|
||||
$form['inputs'][] = [
|
||||
'arguments' => [
|
||||
'name' => 'task',
|
||||
'value' => $this->task['id_rt'],
|
||||
'type' => 'hidden',
|
||||
],
|
||||
];
|
||||
}
|
||||
// Network input
|
||||
$network_input_label .= '<div class="label_select discovery_label_hint"><label>'.__('Network').':</label>'.ui_print_help_tip(__('You can specify several networks, separated by commas, for example: 192.168.50.0/24,192.168.60.0/24'), true).'</div>';
|
||||
|
||||
// Input task name.
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Comment').'</b>',
|
||||
'arguments' => [
|
||||
'name' => 'comment',
|
||||
'value' => $this->task['description'],
|
||||
'type' => 'text',
|
||||
'size' => 25,
|
||||
],
|
||||
];
|
||||
|
||||
// Input Discovery Server.
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Discovery server').'</b>'.ui_print_help_tip(
|
||||
__('You must select a Discovery Server to run the Task, otherwise the Recon Task will never run'),
|
||||
true
|
||||
),
|
||||
'arguments' => [
|
||||
'type' => 'select_from_sql',
|
||||
'sql' => sprintf(
|
||||
'SELECT id_server, name
|
||||
FROM tserver
|
||||
WHERE server_type = %d
|
||||
ORDER BY name',
|
||||
SERVER_TYPE_DISCOVERY
|
||||
),
|
||||
'name' => 'id_recon_server',
|
||||
'selected' => $this->task['id_recon_server'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Input Network.
|
||||
$form['inputs'][] = [
|
||||
|
||||
'label' => '<b>'.__('Network').'</b>'.ui_print_help_tip(
|
||||
__('You can specify several networks, separated by commas, for example: 192.168.50.0/24,192.168.60.0/24'),
|
||||
true
|
||||
),
|
||||
'arguments' => [
|
||||
$network_input = $this->printInput([
|
||||
'name' => 'network',
|
||||
'value' => $this->task['subnet'],
|
||||
'type' => 'text',
|
||||
'size' => 25,
|
||||
],
|
||||
];
|
||||
'class' => 'discovery_full_width_input',
|
||||
]);
|
||||
|
||||
// Input Group.
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Group').'</b>',
|
||||
'arguments' => [
|
||||
'name' => 'id_group',
|
||||
'returnAllGroup' => false,
|
||||
'privilege' => 'PM',
|
||||
'type' => 'select_groups',
|
||||
'selected' => $this->task['id_group'],
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Interval and schedules.
|
||||
// Discovery server input
|
||||
$discovery_server_select_label = '<div class="label_select discovery_label_hint"><label>'.__('Discovery server').':</label>'.ui_print_help_tip(__('You must select a Discovery Server to run the Task, otherwise the Recon Task will never run'), true).'</div>';
|
||||
|
||||
$discovery_server_select = $this->printInput([
|
||||
'type' => 'select_from_sql',
|
||||
'sql' => sprintf(
|
||||
'SELECT id_server, name
|
||||
FROM tserver
|
||||
WHERE server_type = %d
|
||||
ORDER BY name',
|
||||
SERVER_TYPE_DISCOVERY
|
||||
),
|
||||
'name' => 'id_recon_server',
|
||||
'selected' => $this->task['id_recon_server'],
|
||||
'return' => true,
|
||||
'style' => 'width: 100%',
|
||||
]);
|
||||
|
||||
// Interval input
|
||||
$interv_manual = 0;
|
||||
if ((int) $this->task['interval_sweep'] == 0) {
|
||||
$interv_manual = 1;
|
||||
}
|
||||
|
||||
// Schedule.
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Interval').'</b>'.ui_print_help_tip(
|
||||
__('Manual interval means that it will be executed only On-demand'),
|
||||
true
|
||||
),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'selected' => $interv_manual,
|
||||
'fields' => [
|
||||
0 => __('Defined'),
|
||||
1 => __('Manual'),
|
||||
],
|
||||
'name' => 'interval_manual_defined',
|
||||
'return' => true,
|
||||
$interval_input_label = '<div class="label_select discovery_label_hint" style="padding-top: 6px;"><label>'.__('Interval').':</label>'.ui_print_help_tip(__('Manual interval means that it will run only on demand.'), true).'</div>';
|
||||
|
||||
$interval_input = $this->printInput([
|
||||
'type' => 'select',
|
||||
'selected' => $interv_manual,
|
||||
'fields' => [
|
||||
0 => __('Defined'),
|
||||
1 => __('Manual'),
|
||||
],
|
||||
'extra' => '<span id="interval_manual_container">'.html_print_extended_select_for_time(
|
||||
'name' => 'interval_manual_defined',
|
||||
'return' => true,
|
||||
'style' => 'float: right;'
|
||||
]);
|
||||
|
||||
$interval_input_extra = '<span id="interval_manual_container">'.html_print_extended_select_for_time(
|
||||
'interval',
|
||||
$this->task['interval_sweep'],
|
||||
'',
|
||||
|
@ -700,36 +683,38 @@ class HostDevices extends Wizard
|
|||
).ui_print_help_tip(
|
||||
__('The minimum recomended interval for Recon Task is 5 minutes'),
|
||||
true
|
||||
).'</span>',
|
||||
];
|
||||
).'</span>';
|
||||
|
||||
$str = __('Next');
|
||||
|
||||
if (isset($this->task['id_rt']) === true) {
|
||||
$str = __('Update and continue');
|
||||
// Group select
|
||||
$group_select = '<div class="label_select"><label>'.__('Group').':</label></div>';
|
||||
|
||||
$group_select .= $this->printInput([
|
||||
'name' => 'id_group',
|
||||
'returnAllGroup' => false,
|
||||
'privilege' => 'PM',
|
||||
'type' => 'select_groups',
|
||||
'selected' => $this->task['id_group'],
|
||||
'return' => true,
|
||||
'class' => 'discovery_list_input',
|
||||
'size' => 9,
|
||||
'simple_multiple_options' => true,
|
||||
]);
|
||||
|
||||
if (isset($this->task['id_rt']) === true) {
|
||||
//Propagate ID
|
||||
$task_hidden = $this->printInput([
|
||||
'name' => 'task',
|
||||
'value' => $this->task['id_rt'],
|
||||
'type' => 'hidden'
|
||||
]);
|
||||
}
|
||||
|
||||
// Submit button.
|
||||
$form['inputs'][] = [
|
||||
'arguments' => [
|
||||
'name' => 'submit',
|
||||
'label' => $str,
|
||||
'type' => 'submit',
|
||||
'attributes' => 'class="sub next"',
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$task_url = '';
|
||||
if (isset($this->task['id_rt'])) {
|
||||
$task_url = '&task='.$this->task['id_rt'];
|
||||
}
|
||||
|
||||
$form['form'] = [
|
||||
'method' => 'POST',
|
||||
'action' => $this->url.'&mode=netscan&page='.($this->page + 1).$task_url,
|
||||
];
|
||||
|
||||
// Default.
|
||||
$interval = 600;
|
||||
$unit = 60;
|
||||
|
@ -738,24 +723,62 @@ class HostDevices extends Wizard
|
|||
$unit = $this->getTimeUnit($interval);
|
||||
}
|
||||
|
||||
$form['js'] = '
|
||||
$("select#interval_manual_defined").change(function() {
|
||||
if ($("#interval_manual_defined").val() == 1) {
|
||||
$("#interval_manual_container").hide();
|
||||
$("#text-interval_text").val(0);
|
||||
$("#hidden-interval").val(0);
|
||||
}
|
||||
else {
|
||||
$("#interval_manual_container").show();
|
||||
$("#text-interval_text").val(10);
|
||||
$("#hidden-interval").val('.$interval.');
|
||||
$("#interval_units").val('.$unit.');
|
||||
}
|
||||
}).change();';
|
||||
|
||||
// XXX: Could be improved validating inputs before continue (JS)
|
||||
// Print NetScan page 0.
|
||||
$this->printForm($form);
|
||||
//$this->printForm($form);
|
||||
|
||||
echo '<form action="'.$this->url.'&mode=netscan&page='.($this->page + 1).$task_url.'" method="POST">';
|
||||
echo $task_hidden;
|
||||
|
||||
echo '<div class="white_box">
|
||||
<div class="edit_discovery_info" style="margin-bottom: 15px;">
|
||||
<div style="width: 25%; padding: 9px;">'
|
||||
.'<div style="height: 50%; margin-bottom: 35px;">'.html_print_image ("images/wizard/netscan_green.png", true, array ("title" => __('Close'), "style" => 'width: 60%;'), false).'</div>'
|
||||
.'<div class="edit_discovery_input"><div style="display: flex;">'.$interval_input_label.'<div style="margin-left: 15 px; width: 50%;">'.$interval_input.'</div></div>'.$interval_input_extra.'</div>'
|
||||
.'</div>
|
||||
|
||||
<div style="width: 40%; padding-left: 5%; padding-right: 12%;">
|
||||
<div class="edit_discovery_input">'.$taskname_input_label.'<div class="discovery_text_input">'.$taskname_input.'</div></div>'
|
||||
.'<div class="edit_discovery_input discovery_select_input">'.$discovery_server_select_label.$discovery_server_select.'<div class="discovery_hint"></div></div>'
|
||||
.'<div class="edit_discovery_input">'.$network_input_label.'<div class="discovery_text_input">'.$network_input.'</div></div>'
|
||||
.'</div>'
|
||||
.'<div style="width: 35%;">'.$group_select.'</div>'
|
||||
.'</div>'
|
||||
|
||||
.'<div class="edit_discovery_info">
|
||||
<div style="width: 100%;">
|
||||
'.$comment_input.'
|
||||
</div>
|
||||
</div>'
|
||||
.'</div>';
|
||||
|
||||
$str = __('Next');
|
||||
|
||||
if (isset($this->task['id_rt']) === true) {
|
||||
$str = __('Update and continue');
|
||||
}
|
||||
|
||||
echo '<div class="action-buttons" style="width: 100%; margin-top: 10px;">'.html_print_submit_button($str, 'submit', false, 'class="sub next"', true).'</div>';
|
||||
echo '</form>';
|
||||
|
||||
echo '<script>
|
||||
|
||||
$("select#interval_manual_defined").change(function() {
|
||||
if ($("#interval_manual_defined").val() == 1) {
|
||||
$("#interval_manual_container").hide();
|
||||
$("#text-interval_text").val(0);
|
||||
$("#hidden-interval").val(0);
|
||||
}
|
||||
else {
|
||||
$("#interval_manual_container").show();
|
||||
$("#text-interval_text").val(10);
|
||||
$("#hidden-interval").val('.$interval.');
|
||||
$("#interval_units").val('.$unit.');
|
||||
}
|
||||
}).change();
|
||||
|
||||
</script>';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -783,7 +806,7 @@ $("select#interval_manual_defined").change(function() {
|
|||
];
|
||||
|
||||
$form['inputs'][] = [
|
||||
'extra' => '<p>Please, configure task <b>'.io_safe_output($this->task['name']).'</b></p>',
|
||||
'extra' => '<p><h3>Please, configure task <b>'.io_safe_output($this->task['name']).'</b></h3></p>',
|
||||
];
|
||||
|
||||
// Input: Module template.
|
||||
|
@ -799,7 +822,6 @@ $("select#interval_manual_defined").change(function() {
|
|||
'selected' => $this->task['id_network_profile'],
|
||||
'nothing_value' => 0,
|
||||
'nothing' => __('None'),
|
||||
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -850,7 +872,7 @@ $("select#interval_manual_defined").change(function() {
|
|||
'action' => $this->url.'&mode=netscan&page='.($this->page + 1).'&task='.$this->task['id_rt'],
|
||||
];
|
||||
|
||||
$this->printForm($form);
|
||||
$this->printForm($form, false, true);
|
||||
}
|
||||
|
||||
if ($this->page == 2) {
|
||||
|
|
|
@ -191,21 +191,19 @@ class Wizard
|
|||
* Builder for breadcrum
|
||||
*
|
||||
* @param array $urls Array of urls to be stored in breadcrum.
|
||||
* @param boolean $add True if breadcrum should be added instead of
|
||||
* overwrite it.
|
||||
* @param boolean $add True if breadcrum should be added
|
||||
* instead of overwrite it.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepareBreadcrum(array $urls, bool $add=false, bool $separator_beginning=false)
|
||||
{
|
||||
public function prepareBreadcrum(
|
||||
array $urls,
|
||||
bool $add=false
|
||||
) {
|
||||
$bc = [];
|
||||
$i = 0;
|
||||
$count = 0;
|
||||
$array_size = count($urls);
|
||||
|
||||
foreach ($urls as $url) {
|
||||
$count++;
|
||||
|
||||
if ($url['selected'] == 1) {
|
||||
$class = 'selected';
|
||||
} else {
|
||||
|
@ -213,20 +211,10 @@ class Wizard
|
|||
}
|
||||
|
||||
$bc[$i] = '';
|
||||
|
||||
if ($separator_beginning === true) {
|
||||
$bc[$i] .= '<span class="breadcrumb_link"> / </span>';
|
||||
}
|
||||
|
||||
$bc[$i] .= '<span><a class="breadcrumb_link '.$class.'" href="'.$url['link'].'">';
|
||||
$bc[$i] .= $url['label'];
|
||||
$bc[$i] .= '</a>';
|
||||
if ($count < $array_size) {
|
||||
$bc[$i] .= '<span class="breadcrumb_link"> / </span>';
|
||||
}
|
||||
|
||||
$bc[$i] .= '<span><a class="breadcrumb_link '.$class.'" href="'.$url['link'].'">';
|
||||
$bc[$i] .= $url['label'];
|
||||
$bc[$i] .= '</a>';
|
||||
$bc[$i] .= '</span>';
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
@ -235,7 +223,6 @@ class Wizard
|
|||
} else {
|
||||
$this->setBreadcrum($bc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -275,7 +262,10 @@ class Wizard
|
|||
*/
|
||||
public function printBreadcrum()
|
||||
{
|
||||
return implode('', $this->breadcrum);
|
||||
return implode(
|
||||
'<span class="breadcrumb_link"> / </span>',
|
||||
$this->breadcrum
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
@ -483,7 +473,9 @@ class Wizard
|
|||
((isset($data['keys_field']) === true) ? $data['keys_field'] : 'id_grupo'),
|
||||
((isset($data['strict_user']) === true) ? $data['strict_user'] : false),
|
||||
((isset($data['delete_groups']) === true) ? $data['delete_groups'] : false),
|
||||
((isset($data['include_groups']) === true) ? $data['include_groups'] : false)
|
||||
((isset($data['include_groups']) === true) ? $data['include_groups'] : false),
|
||||
((isset($data['size']) === true) ? $data['size'] : false),
|
||||
((isset($data['simple_multiple_options']) === true) ? $data['simple_multiple_options'] : false)
|
||||
);
|
||||
|
||||
case 'submit':
|
||||
|
@ -640,7 +632,7 @@ class Wizard
|
|||
*
|
||||
* @return string HTML code.
|
||||
*/
|
||||
public function printForm(array $data, bool $return=false)
|
||||
public function printForm(array $data, bool $return=false, bool $print_white_box=false)
|
||||
{
|
||||
$form = $data['form'];
|
||||
$inputs = $data['inputs'];
|
||||
|
@ -666,13 +658,27 @@ class Wizard
|
|||
error_log('Error executing wizard callback: ', $e->getMessage());
|
||||
}
|
||||
|
||||
$output = '<ul class="wizard">';
|
||||
$output_submit = '';
|
||||
$output = '';
|
||||
|
||||
if ($print_white_box === true)
|
||||
$output .= '<div class="white_box">';
|
||||
|
||||
$output .= '<ul class="wizard">';
|
||||
|
||||
foreach ($inputs as $input) {
|
||||
$output .= $this->printBlock($input, true);
|
||||
if ($input['arguments']['type']!='submit')
|
||||
$output .= $this->printBlock($input, true);
|
||||
else
|
||||
$output_submit .= $this->printBlock($input, true);
|
||||
}
|
||||
|
||||
$output .= '</ul>';
|
||||
|
||||
if ($print_white_box === true)
|
||||
$output .= '</div>';
|
||||
|
||||
$output .= '<ul class="wizard">'.$output_submit.'</ul>';
|
||||
$output .= '</form>';
|
||||
$output .= '<script>'.$js.'</script>';
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
|
@ -1,17 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* Extension to manage a list of gateways and the node address where they should
|
||||
* point to.
|
||||
*
|
||||
* @category Custom fields View
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
if (check_login()) {
|
||||
// Pandora FMS- http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// 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 Lesser General Public License
|
||||
// as published by the Free Software Foundation; 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.
|
||||
global $config;
|
||||
|
||||
include_once $config['homedir'].'/include/functions_agents.php';
|
||||
|
@ -21,9 +37,18 @@ if (check_login()) {
|
|||
enterprise_include_once('include/functions_metaconsole.php');
|
||||
|
||||
$get_custom_fields_data = (bool) get_parameter('get_custom_fields_data', 0);
|
||||
$build_table_custom_fields = (bool) get_parameter('build_table_custom_fields', 0);
|
||||
$build_table_child_custom_fields = (bool) get_parameter('build_table_child_custom_fields', 0);
|
||||
$build_table_save_filter = (bool) get_parameter('build_table_save_filter', 0);
|
||||
$build_table_custom_fields = (bool) get_parameter(
|
||||
'build_table_custom_fields',
|
||||
0
|
||||
);
|
||||
$build_table_child_custom_fields = (bool) get_parameter(
|
||||
'build_table_child_custom_fields',
|
||||
0
|
||||
);
|
||||
$build_table_save_filter = (bool) get_parameter(
|
||||
'build_table_save_filter',
|
||||
0
|
||||
);
|
||||
$append_tab_filter = (bool) get_parameter('append_tab_filter', 0);
|
||||
$create_filter_cf = (bool) get_parameter('create_filter_cf', 0);
|
||||
$update_filter_cf = (bool) get_parameter('update_filter_cf', 0);
|
||||
|
@ -43,9 +68,16 @@ if (check_login()) {
|
|||
$start = get_parameter('start', 0);
|
||||
$draw = get_parameter('draw', 0);
|
||||
$search = get_parameter('search', '');
|
||||
$indexed_descriptions = json_decode(io_safe_output(get_parameter('indexed_descriptions', '')), true);
|
||||
$indexed_descriptions = json_decode(
|
||||
io_safe_output(
|
||||
get_parameter('indexed_descriptions', '')
|
||||
),
|
||||
true
|
||||
);
|
||||
$module_status = get_parameter('module_status');
|
||||
$id_status = get_parameter('id_status');
|
||||
|
||||
// order query
|
||||
// Order query.
|
||||
$order_column = $order[0]['column'];
|
||||
$type_order = $order[0]['dir'];
|
||||
switch ($order_column) {
|
||||
|
@ -66,27 +98,34 @@ if (check_login()) {
|
|||
break;
|
||||
}
|
||||
|
||||
// table temporary for save array in table by order and search custom_field data
|
||||
// Table temporary for save array in table
|
||||
// by order and search custom_field data.
|
||||
$table_temporary = 'CREATE TEMPORARY TABLE temp_custom_fields (
|
||||
id_server int(10),
|
||||
id_agent int(10),
|
||||
name_custom_fields varchar(2048),
|
||||
critical_count int,
|
||||
warning_count int,
|
||||
unknown_count int,
|
||||
notinit_count int,
|
||||
normal_count int,
|
||||
total_count int,
|
||||
`status` int(2),
|
||||
KEY `data_index_temp_1` (`id_server`, `id_agent`)
|
||||
)';
|
||||
db_process_sql($table_temporary);
|
||||
|
||||
// insert values array in table temporary
|
||||
// Insert values array in table temporary.
|
||||
$values_insert = [];
|
||||
foreach ($indexed_descriptions as $key => $value) {
|
||||
$values_insert[] = '('.$value['id_server'].', '.$value['id_agente'].", '".$value['description']."', ".$value['status'].')';
|
||||
$values_insert[] = '('.$value['id_server'].', '.$value['id_agente'].", '".$value['description']."', '".$value['critical_count']."', '".$value['warning_count']."', '".$value['unknown_count']."', '".$value['notinit_count']."', '".$value['normal_count']."', '".$value['total_count']."', ".$value['status'].')';
|
||||
}
|
||||
|
||||
$values_insert_implode = implode(',', $values_insert);
|
||||
$query_insert = 'INSERT INTO temp_custom_fields VALUES '.$values_insert_implode;
|
||||
db_process_sql($query_insert);
|
||||
|
||||
// search table for alias, custom field data, server_name, direction
|
||||
// Search table for alias, custom field data, server_name, direction.
|
||||
$search_query = '';
|
||||
if ($search['value'] != '') {
|
||||
$search_query = ' AND (tma.alias LIKE "%'.$search['value'].'%"';
|
||||
|
@ -95,7 +134,61 @@ if (check_login()) {
|
|||
$search_query .= ' OR temp.name_custom_fields LIKE "%'.$search['value'].'%" ) ';
|
||||
}
|
||||
|
||||
// query all fields result
|
||||
// Search for status module.
|
||||
$status_agent_search = '';
|
||||
if (isset($id_status) === true && is_array($id_status) === true) {
|
||||
if (in_array(-1, $id_status) === false) {
|
||||
if (in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $id_status) === false) {
|
||||
$status_agent_search = ' AND temp.status IN ('.implode(',', $id_status).')';
|
||||
} else {
|
||||
// Not normal statuses.
|
||||
$status_agent_search = ' AND temp.status IN (1,2,3,4,5)';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search for status module.
|
||||
$status_module_search = '';
|
||||
if (isset($module_status) === true && is_array($module_status) === true) {
|
||||
if (in_array(-1, $module_status) === false) {
|
||||
if (in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $module_status) === false) {
|
||||
if (count($module_status) > 0) {
|
||||
$status_module_search = ' AND ( ';
|
||||
foreach ($module_status as $key => $value) {
|
||||
$status_module_search .= ($key != 0) ? ' OR (' : ' (';
|
||||
switch ($value) {
|
||||
default:
|
||||
case AGENT_STATUS_NORMAL:
|
||||
$status_module_search .= ' temp.normal_count > 0) ';
|
||||
break;
|
||||
case AGENT_STATUS_CRITICAL:
|
||||
$status_module_search .= ' temp.critical_count > 0) ';
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_WARNING:
|
||||
$status_module_search .= ' temp.warning_count > 0) ';
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_UNKNOWN:
|
||||
$status_module_search .= ' temp.unknown_count > 0) ';
|
||||
break;
|
||||
|
||||
case AGENT_STATUS_NOT_INIT:
|
||||
$status_module_search .= ' temp.notinit_count > 0) ';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$status_module_search .= ' ) ';
|
||||
}
|
||||
} else {
|
||||
// Not normal.
|
||||
$status_module_search = ' AND ( temp.critical_count > 0 OR temp.warning_count > 0 OR temp.unknown_count > 0 AND temp.notinit_count > 0 )';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Query all fields result.
|
||||
$query = sprintf(
|
||||
'SELECT
|
||||
tma.id_agente,
|
||||
|
@ -112,10 +205,14 @@ if (check_login()) {
|
|||
AND temp.id_server = tma.id_tmetaconsole_setup
|
||||
WHERE tma.disabled = 0
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
LIMIT %d OFFSET %d
|
||||
',
|
||||
$search_query,
|
||||
$status_agent_search,
|
||||
$status_module_search,
|
||||
$order_by,
|
||||
$length,
|
||||
$start
|
||||
|
@ -123,23 +220,27 @@ if (check_login()) {
|
|||
|
||||
$result = db_get_all_rows_sql($query);
|
||||
|
||||
// query count
|
||||
// Query count.
|
||||
$query_count = sprintf(
|
||||
'SELECT
|
||||
COUNT(tma.id_agente) AS `count`
|
||||
FROM tmetaconsole_agent tma
|
||||
INNER JOIN temp_custom_fields temp
|
||||
ON temp.id_agent = tma.id_tagente
|
||||
AND temp.id_server = tma.id_tmetaconsole_setup
|
||||
WHERE tma.disabled = 0
|
||||
%s
|
||||
',
|
||||
$search_query
|
||||
FROM tmetaconsole_agent tma
|
||||
INNER JOIN temp_custom_fields temp
|
||||
ON temp.id_agent = tma.id_tagente
|
||||
AND temp.id_server = tma.id_tmetaconsole_setup
|
||||
WHERE tma.disabled = 0
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
',
|
||||
$search_query,
|
||||
$status_agent_search,
|
||||
$status_module_search
|
||||
);
|
||||
|
||||
$count = db_get_sql($query_count);
|
||||
|
||||
// for link nodes.
|
||||
// For link nodes.
|
||||
$array_nodes = metaconsole_get_connections();
|
||||
if (isset($array_nodes) && is_array($array_nodes)) {
|
||||
$hash_array_nodes = [];
|
||||
|
@ -158,20 +259,20 @@ if (check_login()) {
|
|||
$user_rot13 = str_rot13($config['id_user']);
|
||||
$hashdata = $user.$pwd;
|
||||
$hashdata = md5($hashdata);
|
||||
$url_hash = '&'.'loginhash=auto&'.'loginhash_data='.$hashdata.'&'.'loginhash_user='.$user_rot13;
|
||||
$url_hash = '&loginhash=auto&loginhash_data='.$hashdata.'&loginhash_user='.$user_rot13;
|
||||
|
||||
$hash_array_nodes[$server['id']]['hashurl'] = $url_hash;
|
||||
$hash_array_nodes[$server['id']]['server_url'] = $server['server_url'];
|
||||
}
|
||||
}
|
||||
|
||||
// prepare rows for table dinamic
|
||||
// Prepare rows for table dinamic.
|
||||
$data = [];
|
||||
foreach ($result as $values) {
|
||||
$image_status = agents_get_image_status($values['status']);
|
||||
|
||||
// link nodes
|
||||
$agent_link = '<a href="'.$hash_array_nodes[$values['id_tmetaconsole_setup']]['server_url'].'/'.'index.php?'.'sec=estado&'.'sec2=operation/agentes/ver_agente&'.'id_agente='.$values['id_tagente'].$hash_array_nodes[$values['id_tmetaconsole_setup']]['hashurl'].'">';
|
||||
// Link nodes.
|
||||
$agent_link = '<a href="'.$hash_array_nodes[$values['id_tmetaconsole_setup']]['server_url'].'/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$values['id_tagente'].$hash_array_nodes[$values['id_tmetaconsole_setup']]['hashurl'].'">';
|
||||
|
||||
$agent_alias = ui_print_truncate_text(
|
||||
$values['alias'],
|
||||
|
@ -225,7 +326,7 @@ if (check_login()) {
|
|||
$name_where = " AND tam.nombre LIKE '%".$module_search."%'";
|
||||
}
|
||||
|
||||
// filter by status module
|
||||
// Filter by status module.
|
||||
$and_module_status = '';
|
||||
if (is_array($module_status)) {
|
||||
if (!in_array(-1, $module_status)) {
|
||||
|
@ -260,7 +361,7 @@ if (check_login()) {
|
|||
$and_module_status .= ' ) ';
|
||||
}
|
||||
} else {
|
||||
// not normal
|
||||
// Not normal.
|
||||
$and_module_status = 'AND tae.estado <> 0 AND tae.estado <> 300 ';
|
||||
}
|
||||
}
|
||||
|
@ -314,7 +415,12 @@ if (check_login()) {
|
|||
&& $value['id_tipo_modulo'] != 23
|
||||
&& $value['id_tipo_modulo'] != 33
|
||||
) {
|
||||
$table_modules->data[$key][1] = remove_right_zeros(number_format($value['datos'], $config['graph_precision']));
|
||||
$table_modules->data[$key][1] = remove_right_zeros(
|
||||
number_format(
|
||||
$value['datos'],
|
||||
$config['graph_precision']
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$table_modules->data[$key][1] = $value['datos'];
|
||||
}
|
||||
|
@ -329,7 +435,10 @@ if (check_login()) {
|
|||
);
|
||||
|
||||
$table_modules->data[$key][3] = $value['current_interval'];
|
||||
$table_modules->data[$key][4] = ui_print_timestamp($value['utimestamp'], true);
|
||||
$table_modules->data[$key][4] = ui_print_timestamp(
|
||||
$value['utimestamp'],
|
||||
true
|
||||
);
|
||||
switch ($value['estado']) {
|
||||
case 0:
|
||||
case 300:
|
||||
|
@ -398,7 +507,7 @@ if (check_login()) {
|
|||
}
|
||||
}
|
||||
|
||||
// status agents from tagente
|
||||
// Status agents from tagente.
|
||||
$sql_info_agents = 'SELECT * fROM tagente WHERE id_agente ='.$id_agent;
|
||||
$info_agents = db_get_row_sql($sql_info_agents);
|
||||
$status_agent = agents_get_status_from_counts($info_agents);
|
||||
|
@ -463,7 +572,13 @@ if (check_login()) {
|
|||
false
|
||||
);
|
||||
|
||||
$table->data[0][3] = html_print_submit_button(__('Load filter'), 'load_filter', false, 'class="sub upd"', true);
|
||||
$table->data[0][3] = html_print_submit_button(
|
||||
__('Load filter'),
|
||||
'load_filter',
|
||||
false,
|
||||
'class="sub upd"',
|
||||
true
|
||||
);
|
||||
|
||||
echo "<form action='' method='post'>";
|
||||
html_print_table($table);
|
||||
|
@ -474,7 +589,12 @@ if (check_login()) {
|
|||
}
|
||||
|
||||
if ($append_tab_filter) {
|
||||
$filters = json_decode(io_safe_output(get_parameter('filters', '')), true);
|
||||
$filters = json_decode(
|
||||
io_safe_output(
|
||||
get_parameter('filters', '')
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$table = new StdClass;
|
||||
$table->id = 'save_filter_form';
|
||||
|
@ -485,7 +605,14 @@ if (check_login()) {
|
|||
if ($filters['id'] == 'extended_create_filter') {
|
||||
echo "<div id='msg_error_create'></div>";
|
||||
$table->data[0][0] = __('Filter name');
|
||||
$table->data[0][1] = html_print_input_text('id_name', '', '', 15, 255, true);
|
||||
$table->data[0][1] = html_print_input_text(
|
||||
'id_name',
|
||||
'',
|
||||
'',
|
||||
15,
|
||||
255,
|
||||
true
|
||||
);
|
||||
|
||||
$table->data[1][0] = __('Group');
|
||||
$table->data[1][1] = html_print_select_groups(
|
||||
|
@ -510,7 +637,13 @@ if (check_login()) {
|
|||
);
|
||||
|
||||
$table->rowspan[0][2] = 2;
|
||||
$table->data[0][2] = html_print_submit_button(__('Create filter'), 'create_filter', false, 'class="sub upd"', true);
|
||||
$table->data[0][2] = html_print_submit_button(
|
||||
__('Create filter'),
|
||||
'create_filter',
|
||||
false,
|
||||
'class="sub upd"',
|
||||
true
|
||||
);
|
||||
} else {
|
||||
echo "<div id='msg_error_update'></div>";
|
||||
echo "<div id='msg_error_delete'></div>";
|
||||
|
@ -552,8 +685,20 @@ if (check_login()) {
|
|||
false
|
||||
);
|
||||
|
||||
$table->data[0][2] = html_print_submit_button(__('Delete filter'), 'delete_filter', false, 'class="sub upd"', true);
|
||||
$table->data[1][2] = html_print_submit_button(__('Update filter'), 'update_filter', false, 'class="sub upd"', true);
|
||||
$table->data[0][2] = html_print_submit_button(
|
||||
__('Delete filter'),
|
||||
'delete_filter',
|
||||
false,
|
||||
'class="sub upd"',
|
||||
true
|
||||
);
|
||||
$table->data[1][2] = html_print_submit_button(
|
||||
__('Update filter'),
|
||||
'update_filter',
|
||||
false,
|
||||
'class="sub upd"',
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
html_print_table($table);
|
||||
|
@ -561,17 +706,20 @@ if (check_login()) {
|
|||
}
|
||||
|
||||
if ($create_filter_cf) {
|
||||
// initialize result
|
||||
// Initialize result.
|
||||
$result_array = [];
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = '';
|
||||
|
||||
// initialize vars
|
||||
$filters = json_decode(io_safe_output(get_parameter('filters', '')), true);
|
||||
// Initialize vars.
|
||||
$filters = json_decode(
|
||||
io_safe_output(get_parameter('filters', '')),
|
||||
true
|
||||
);
|
||||
$name_filter = get_parameter('name_filter', '');
|
||||
$group_search = get_parameter('group_search', 0);
|
||||
|
||||
// check that the name is not empty
|
||||
// Check that the name is not empty.
|
||||
if ($name_filter == '') {
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
|
@ -596,7 +744,7 @@ if (check_login()) {
|
|||
return;
|
||||
}
|
||||
|
||||
// check custom field is not empty
|
||||
// Check custom field is not empty.
|
||||
if ($filters['id_custom_fields'] == '') {
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
|
@ -608,13 +756,15 @@ if (check_login()) {
|
|||
return;
|
||||
}
|
||||
|
||||
// insert
|
||||
// Insert.
|
||||
$values = [];
|
||||
$values['name'] = $name_filter;
|
||||
$values['group_search'] = $group_search;
|
||||
$values['id_group'] = $filters['group'];
|
||||
$values['id_custom_field'] = $filters['id_custom_fields'];
|
||||
$values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']);
|
||||
$values['id_custom_fields_data'] = json_encode(
|
||||
$filters['id_custom_fields_data']
|
||||
);
|
||||
$values['id_status'] = json_encode($filters['id_status']);
|
||||
$values['module_search'] = $filters['module_search'];
|
||||
$values['module_status'] = json_encode($filters['module_status']);
|
||||
|
@ -622,7 +772,7 @@ if (check_login()) {
|
|||
|
||||
$insert = db_process_sql_insert('tagent_custom_fields_filter', $values);
|
||||
|
||||
// check error insert
|
||||
// Check error insert.
|
||||
if ($insert) {
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = ui_print_success_message(
|
||||
|
@ -644,17 +794,17 @@ if (check_login()) {
|
|||
}
|
||||
|
||||
if ($update_filter_cf) {
|
||||
// initialize result
|
||||
// Initialize result.
|
||||
$result_array = [];
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = '';
|
||||
|
||||
// initialize vars
|
||||
// Initialize vars.
|
||||
$filters = json_decode(io_safe_output(get_parameter('filters', '')), true);
|
||||
$id_filter = get_parameter('id_filter', '');
|
||||
$group_search = get_parameter('group_search', 0);
|
||||
|
||||
// check selected filter
|
||||
// Check selected filter.
|
||||
if ($id_filter == -1) {
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
|
@ -666,11 +816,11 @@ if (check_login()) {
|
|||
return;
|
||||
}
|
||||
|
||||
// array condition update
|
||||
// Array condition update.
|
||||
$condition = [];
|
||||
$condition['id'] = $id_filter;
|
||||
|
||||
// check selected custom fields
|
||||
// Check selected custom fields.
|
||||
if ($filters['id_custom_fields'] == '') {
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
|
@ -682,7 +832,7 @@ if (check_login()) {
|
|||
return;
|
||||
}
|
||||
|
||||
// array values update
|
||||
// Array values update.
|
||||
$values = [];
|
||||
$values['id_group'] = $filters['group'];
|
||||
$values['group_search'] = $group_search;
|
||||
|
@ -693,10 +843,10 @@ if (check_login()) {
|
|||
$values['module_status'] = json_encode($filters['module_status']);
|
||||
$values['recursion'] = $filters['recursion'];
|
||||
|
||||
// update
|
||||
// Update.
|
||||
$update = db_process_sql_update('tagent_custom_fields_filter', $values, $condition);
|
||||
|
||||
// check error insert
|
||||
// Check error insert.
|
||||
if ($update) {
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = ui_print_success_message(
|
||||
|
@ -718,16 +868,16 @@ if (check_login()) {
|
|||
}
|
||||
|
||||
if ($delete_filter_cf) {
|
||||
// Initialize result
|
||||
// Initialize result.
|
||||
$result_array = [];
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = '';
|
||||
|
||||
// Initialize vars
|
||||
// Initialize vars.
|
||||
$filters = json_decode(io_safe_output(get_parameter('filters', '')), true);
|
||||
$id_filter = get_parameter('id_filter', '');
|
||||
|
||||
// Check selected filter
|
||||
// Check selected filter.
|
||||
if ($id_filter == -1) {
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
|
@ -739,14 +889,14 @@ if (check_login()) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Array condition update
|
||||
// Array condition update.
|
||||
$condition = [];
|
||||
$condition['id'] = $id_filter;
|
||||
|
||||
// Delete
|
||||
// Delete.
|
||||
$delete = db_process_sql_delete('tagent_custom_fields_filter', $condition);
|
||||
|
||||
// Check error insert
|
||||
// Check error insert.
|
||||
if ($delete) {
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = ui_print_success_message(
|
||||
|
|
|
@ -45,23 +45,25 @@ if ($progress_task_discovery) {
|
|||
|
||||
$result = '<div id = progress_task_'.$id_task.'>';
|
||||
if ($task['utimestamp']) {
|
||||
$result .= '<ul class="progress_task_discovery">';
|
||||
$result .= '<li><h1>'._('Overall Progress').'</h1></li>';
|
||||
$result .= '<li>';
|
||||
$result .= d3_progress_bar(
|
||||
$result .= '<div style="display: flex;">';
|
||||
$result .= '<div style="width: 100%; text-align: center; margin-top: 40px;">';
|
||||
$result .= '<span style="font-size: 1.9em; font-family: "lato-bolder", "Open Sans", sans-serif !important;">'._('Overall Progress').'</span>';
|
||||
|
||||
$result .= '<div style="margin-top: 25px;">';
|
||||
$result .= progress_circular_bar(
|
||||
$id_task,
|
||||
($global_progress < 0) ? 100 : $global_progress,
|
||||
460,
|
||||
30,
|
||||
'#EA5434',
|
||||
200,
|
||||
200,
|
||||
'#7eb641',
|
||||
'%',
|
||||
'',
|
||||
'#FFFFFF',
|
||||
0,
|
||||
0,
|
||||
'#3A3A3A',
|
||||
0
|
||||
);
|
||||
|
||||
$result .= '</div>';
|
||||
|
||||
if ($global_progress > 0) {
|
||||
switch ($summary['step']) {
|
||||
case STEP_SCANNING:
|
||||
|
@ -85,28 +87,28 @@ if ($progress_task_discovery) {
|
|||
break;
|
||||
}
|
||||
|
||||
$result .= '</li>';
|
||||
$result .= '<li><h1>'.$str.' ';
|
||||
$result .= '</div>';
|
||||
$result .= '<div style="width: 100%; text-align: center; margin-top: 40px;">';
|
||||
$result .= '<span style="font-size: 1.9em; font-family: "lato-bolder", "Open Sans", sans-serif !important;">'.$str.' ';
|
||||
$result .= $summary['c_network_name'];
|
||||
$result .= '</h1></li>';
|
||||
$result .= '<li>';
|
||||
$result .= d3_progress_bar(
|
||||
$result .= '</span>';
|
||||
|
||||
$result .= '<div style="margin-top: 25px;">';
|
||||
$result .= progress_circular_bar(
|
||||
$id_task.'_detail',
|
||||
$summary['c_network_percent'],
|
||||
460,
|
||||
30,
|
||||
'#2751E1',
|
||||
200,
|
||||
200,
|
||||
'#7eb641',
|
||||
'%',
|
||||
'',
|
||||
'#FFFFFF',
|
||||
0,
|
||||
0,
|
||||
'#3A3A3A',
|
||||
0
|
||||
);
|
||||
$result .= '</li>';
|
||||
$result .= '</div></div>';
|
||||
}
|
||||
|
||||
$result .= '</ul>';
|
||||
$result .= '</div></div>';
|
||||
|
||||
$i = 0;
|
||||
$table = new StdClasS();
|
||||
|
@ -142,6 +144,7 @@ if ($progress_task_discovery) {
|
|||
$table->data[$i][1] .= $summary['summary']['WMI'];
|
||||
$table->data[$i++][1] .= '</span>';
|
||||
|
||||
$result .= '<div style="margin-top: 40px; text-align: center;"><span style="font-size: 1.9em; font-family: "lato-bolder", "Open Sans", sans-serif !important;">'.__('Summary').'</span></div>';
|
||||
$result .= html_print_table($table, true).'</div>';
|
||||
} else {
|
||||
$global_progress = -1;
|
||||
|
|
|
@ -37,13 +37,10 @@ $api_password = get_parameter('apipass', '');
|
|||
$password = get_parameter('pass', '');
|
||||
$user = get_parameter('user', '');
|
||||
$info = get_parameter('info', '');
|
||||
|
||||
$other = parseOtherParameter($otherSerialize, $otherMode);
|
||||
|
||||
$apiPassword = io_output_password(db_get_value_filter('value', 'tconfig', ['token' => 'api_password']));
|
||||
|
||||
$correctLogin = false;
|
||||
$user_in_db = null;
|
||||
$no_login_msg = '';
|
||||
|
||||
// Clean unwanted output
|
||||
|
@ -107,7 +104,6 @@ if ($correctLogin) {
|
|||
if ($op == 'set' && $id) {
|
||||
switch ($op2) {
|
||||
case 'update_agent':
|
||||
|
||||
case 'add_module_in_conf':
|
||||
case 'update_module_in_conf':
|
||||
case 'delete_module_in_conf':
|
||||
|
@ -149,8 +145,45 @@ if ($correctLogin) {
|
|||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
case 'delete_user_permission':
|
||||
|
||||
if ($user_db === '') {
|
||||
returnError(__('User or group not specified'), __('User, group not specified'));
|
||||
return;
|
||||
}
|
||||
|
||||
$id_os = api_set_delete_user_profiles($thrash1, $thrash2, $other, $returnType);
|
||||
|
||||
if ($id_os != 100) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($id_os == false) {
|
||||
returnError('not_allowed_operation_cluster', $returnType);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'add_permission_user_to_group':
|
||||
|
||||
if ($user_db == null || $group_db == null || $id_up == null) {
|
||||
returnError(__('User, group or profile not specified'), __('User, group or profile status not specified'));
|
||||
return;
|
||||
}
|
||||
|
||||
$id_os = api_set_add_permission_user_to_group($thrash1, $thrash2, $other, $returnType);
|
||||
|
||||
if ($id_os != 100) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($id_os == false) {
|
||||
returnError('not_allowed_operation_cluster', $returnType);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -438,7 +438,7 @@ class CustomNetScan extends Wizard
|
|||
|
||||
// Input task name.
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Task name').'</b>',
|
||||
'label' => __('Task name'),
|
||||
'arguments' => [
|
||||
'name' => 'taskname',
|
||||
'value' => $this->task['name'],
|
||||
|
@ -460,7 +460,7 @@ class CustomNetScan extends Wizard
|
|||
|
||||
// Input task description.
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Comment').'</b>',
|
||||
'label' => __('Comment'),
|
||||
'arguments' => [
|
||||
'name' => 'comment',
|
||||
'value' => $this->task['description'],
|
||||
|
@ -471,7 +471,7 @@ class CustomNetScan extends Wizard
|
|||
|
||||
// Input Discovery Server.
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Discovery server').'</b>'.ui_print_help_tip(
|
||||
'label' => __('Discovery server').ui_print_help_tip(
|
||||
__('You must select a Discovery Server to run the Task, otherwise the Recon Task will never run'),
|
||||
true
|
||||
),
|
||||
|
@ -492,7 +492,7 @@ class CustomNetScan extends Wizard
|
|||
|
||||
// Input Group.
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Group').'</b>',
|
||||
'label' => __('Group'),
|
||||
'arguments' => [
|
||||
'name' => 'id_group',
|
||||
'returnAllGroup' => false,
|
||||
|
@ -511,7 +511,7 @@ class CustomNetScan extends Wizard
|
|||
|
||||
// Schedule.
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Interval').'</b>'.ui_print_help_tip(
|
||||
'label' => __('Interval').ui_print_help_tip(
|
||||
__('Manual interval means that it will be executed only On-demand'),
|
||||
true
|
||||
),
|
||||
|
@ -594,7 +594,7 @@ class CustomNetScan extends Wizard
|
|||
|
||||
// XXX: Could be improved validating inputs before continue (JS)
|
||||
// Print NetScan page 0.
|
||||
$this->printForm($form);
|
||||
$this->printForm($form, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -602,7 +602,7 @@ class CustomNetScan extends Wizard
|
|||
$name_ipam = 'IPAM Recon';
|
||||
// Recon script.
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Recon script').'</b>',
|
||||
'label' => __('Recon script'),
|
||||
'arguments' => [
|
||||
'type' => 'select_from_sql',
|
||||
'sql' => sprintf(
|
||||
|
@ -643,7 +643,7 @@ class CustomNetScan extends Wizard
|
|||
);
|
||||
|
||||
$form['inputs'][] = [
|
||||
'label' => '<b>'.__('Explanation').'</b><span id="spinner_recon_script" style="display: none;">'.html_print_image('images/spinner.gif', true).'</span>',
|
||||
'label' => __('Explanation').'<span id="spinner_recon_script" style="display: none;">'.html_print_image('images/spinner.gif', true).'</span>',
|
||||
'arguments' => [
|
||||
'type' => 'textarea',
|
||||
'rows' => 4,
|
||||
|
@ -652,6 +652,7 @@ class CustomNetScan extends Wizard
|
|||
'value' => $explanation,
|
||||
'return' => true,
|
||||
'attributes' => 'style="width: 388px;"',
|
||||
'class' => 'discovery_textarea_input'
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -663,8 +664,9 @@ class CustomNetScan extends Wizard
|
|||
'name' => 'macro_name',
|
||||
'value' => 'macro_value',
|
||||
'type' => 'text',
|
||||
'size' => 100,
|
||||
'size' => 50,
|
||||
'return' => true,
|
||||
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -740,7 +742,7 @@ class CustomNetScan extends Wizard
|
|||
get_explanation_recon_script($(this).val(), "'.$id_task.'", "'.$url_ajax.'");
|
||||
})'.$change;
|
||||
|
||||
$this->printForm($form);
|
||||
$this->printForm($form, false, true);
|
||||
}
|
||||
|
||||
if (isset($this->page) === true && $this->page === 2) {
|
||||
|
|
|
@ -34,9 +34,9 @@ enterprise_include_once('include/functions_networkmap.php');
|
|||
enterprise_include_once('include/functions_discovery.php');
|
||||
|
||||
// Avoid node overlapping.
|
||||
define('GRAPHVIZ_RADIUS_CONVERSION_FACTOR', 20);
|
||||
define('MAP_X_CORRECTION', 600);
|
||||
define('MAP_Y_CORRECTION', 150);
|
||||
define('GRAPHVIZ_CONVERSION_FACTOR', 30);
|
||||
define('MAP_X_CORRECTION', 0);
|
||||
define('MAP_Y_CORRECTION', 0);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -191,6 +191,20 @@ class NetworkMap
|
|||
*/
|
||||
public $relations;
|
||||
|
||||
/**
|
||||
* Private nodes converted to JS.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $nodesJS;
|
||||
|
||||
/**
|
||||
* Private relations converted to JS.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $relationsJS;
|
||||
|
||||
/**
|
||||
* Include a Pandora (or vendor) node or not.
|
||||
*
|
||||
|
@ -319,6 +333,8 @@ class NetworkMap
|
|||
// Default mapOptions values.
|
||||
// Defines the command to generate positions.
|
||||
$this->mapOptions['generation_method'] = LAYOUT_SPRING1;
|
||||
// Use fixed positions defined (X,Y) per node.
|
||||
$this->mapOptions['fixed_positions'] = 0;
|
||||
$this->mapOptions['width'] = $config['networkmap_max_width'];
|
||||
$this->mapOptions['height'] = $config['networkmap_max_width'];
|
||||
$this->mapOptions['simple'] = 0;
|
||||
|
@ -999,23 +1015,25 @@ class NetworkMap
|
|||
case NODE_GENERIC:
|
||||
// Handmade ones.
|
||||
// Add also parent relationship.
|
||||
$parent_id = $node['id_parent'];
|
||||
if (isset($node['id_parent'])) {
|
||||
$parent_id = $node['id_parent'];
|
||||
|
||||
if ((int) $parent_id > 0) {
|
||||
$parent_node = $this->getNodeData(
|
||||
(int) $parent_id,
|
||||
'id_node'
|
||||
);
|
||||
}
|
||||
if ((int) $parent_id >= 0) {
|
||||
$parent_node = $this->getNodeData(
|
||||
(int) $parent_id,
|
||||
'id_node'
|
||||
);
|
||||
}
|
||||
|
||||
// Store relationship.
|
||||
if ($parent_node) {
|
||||
$relations[] = [
|
||||
'id_parent' => $parent_node,
|
||||
'parent_type' => NODE_GENERIC,
|
||||
'id_child' => $node['id_node'],
|
||||
'child_type' => NODE_GENERIC,
|
||||
];
|
||||
// Store relationship.
|
||||
if ($parent_node !== null) {
|
||||
$relations[] = [
|
||||
'id_parent' => $parent_node,
|
||||
'parent_type' => NODE_GENERIC,
|
||||
'id_child' => $node['id_node'],
|
||||
'child_type' => NODE_GENERIC,
|
||||
];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1224,6 +1242,11 @@ class NetworkMap
|
|||
return '';
|
||||
}
|
||||
|
||||
if ($this->mapOptions['fixed_positions']) {
|
||||
// Ignore.
|
||||
return;
|
||||
}
|
||||
|
||||
$dot_str = '';
|
||||
|
||||
// Color is being printed by D3, not graphviz.
|
||||
|
@ -1233,8 +1256,22 @@ class NetworkMap
|
|||
$url = 'none';
|
||||
$parent = $data['parent'];
|
||||
$font_size = $this->mapOptions['font_size'];
|
||||
$radius = $this->mapOptions['map_filter']['node_radius'];
|
||||
$radius /= GRAPHVIZ_RADIUS_CONVERSION_FACTOR;
|
||||
if (isset($data['radius'])) {
|
||||
$radius = $data['radius'];
|
||||
} else {
|
||||
$radius = $this->mapOptions['map_filter']['node_radius'];
|
||||
}
|
||||
|
||||
$radius /= GRAPHVIZ_CONVERSION_FACTOR;
|
||||
|
||||
if (is_array($label)) {
|
||||
$label = array_reduce(
|
||||
function ($carry, $item) {
|
||||
$carry .= $item;
|
||||
return $carry;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (strlen($label) > 16) {
|
||||
$label = ui_print_truncate_text($label, 16, false, true, false);
|
||||
|
@ -1593,6 +1630,21 @@ class NetworkMap
|
|||
|
||||
if (is_array($node['style']) === false) {
|
||||
$node['style'] = json_decode($node['style'], true);
|
||||
|
||||
// Add styles.
|
||||
if (isset($source_data['style']) === true
|
||||
&& is_array($source_data['style']) === true
|
||||
) {
|
||||
$node['style'] = array_merge(
|
||||
$node['style'],
|
||||
$source_data['style']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Propagate styles.
|
||||
foreach ($node['style'] as $k => $v) {
|
||||
$item[$k] = $v;
|
||||
}
|
||||
|
||||
$item['type'] = $node['type'];
|
||||
|
@ -1632,9 +1684,20 @@ class NetworkMap
|
|||
$node[$k] = $v;
|
||||
}
|
||||
|
||||
$node['style']['label'] = $node['name'];
|
||||
if (!empty($node['text'])) {
|
||||
$node['style']['label'] = $node['text'];
|
||||
} else {
|
||||
$node['style']['label'] = $node['name'];
|
||||
}
|
||||
|
||||
$node['style']['shape'] = 'circle';
|
||||
$item['color'] = self::getColorByStatus($node['status']);
|
||||
if (isset($source_data['color'])) {
|
||||
$item['color'] = $source_data['color'];
|
||||
} else {
|
||||
$item['color'] = self::getColorByStatus(
|
||||
$node['status']
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1679,6 +1742,7 @@ class NetworkMap
|
|||
$item['text'] = io_safe_output($node['style']['label']);
|
||||
$item['shape'] = $node['style']['shape'];
|
||||
$item['map_id'] = $node['id_map'];
|
||||
|
||||
if (!isset($node['style']['id_networkmap'])
|
||||
|| $node['style']['id_networkmap'] == ''
|
||||
|| $node['style']['id_networkmap'] == 0
|
||||
|
@ -1694,8 +1758,6 @@ class NetworkMap
|
|||
$item['image'] = $item['image_url'];
|
||||
$item['image_height'] = 52;
|
||||
$item['image_width'] = 52;
|
||||
$item['width'] = $this->mapOptions['map_filter']['node_radius'];
|
||||
$item['height'] = $this->mapOptions['map_filter']['node_radius'];
|
||||
}
|
||||
|
||||
$return[] = $item;
|
||||
|
@ -2036,6 +2098,10 @@ class NetworkMap
|
|||
'id_source' => $id_source,
|
||||
'label' => $label,
|
||||
'image' => null,
|
||||
'radius' => max(
|
||||
$node['width'],
|
||||
$node['height']
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -2148,8 +2214,8 @@ class NetworkMap
|
|||
if (preg_match('/^graph.*$/', $line) != 0) {
|
||||
// Graph definition.
|
||||
$fields = explode(' ', $line);
|
||||
$this->map['width'] = ($fields[2] * 10 * GRAPHVIZ_RADIUS_CONVERSION_FACTOR);
|
||||
$this->map['height'] = ($fields[3] * 10 * GRAPHVIZ_RADIUS_CONVERSION_FACTOR);
|
||||
$this->map['width'] = ($fields[2] * GRAPHVIZ_CONVERSION_FACTOR);
|
||||
$this->map['height'] = ($fields[3] * GRAPHVIZ_CONVERSION_FACTOR);
|
||||
|
||||
if ($this->map['width'] > $config['networkmap_max_width']) {
|
||||
$this->map['width'] = $config['networkmap_max_width'];
|
||||
|
@ -2162,8 +2228,8 @@ class NetworkMap
|
|||
// Node.
|
||||
$fields = explode(' ', $line);
|
||||
$id = $fields[1];
|
||||
$nodes[$id]['x'] = (($fields[2] * $this->mapOptions['map_filter']['node_radius']) - $this->mapOptions['map_filter']['rank_sep'] * GRAPHVIZ_RADIUS_CONVERSION_FACTOR);
|
||||
$nodes[$id]['y'] = (($fields[3] * $this->mapOptions['map_filter']['node_radius']) - $this->mapOptions['map_filter']['rank_sep'] * GRAPHVIZ_RADIUS_CONVERSION_FACTOR);
|
||||
$nodes[$id]['x'] = ($fields[2] * GRAPHVIZ_CONVERSION_FACTOR);
|
||||
$nodes[$id]['y'] = ($fields[3] * GRAPHVIZ_CONVERSION_FACTOR);
|
||||
} else if (preg_match('/^edge.*$/', $line) != 0
|
||||
&& empty($this->relations) === true
|
||||
) {
|
||||
|
@ -2401,7 +2467,17 @@ class NetworkMap
|
|||
* Calculate X,Y positions.
|
||||
*/
|
||||
|
||||
$graph = $this->calculateCoords();
|
||||
if (!$this->mapOptions['fixed_positions']) {
|
||||
$graph = $this->calculateCoords();
|
||||
} else {
|
||||
// Set by user.
|
||||
$graph['nodes'] = $this->rawNodes;
|
||||
$graph['relations'] = $this->relations;
|
||||
$this->map['width'] = $this->mapOptions['width'];
|
||||
$this->map['height'] = $this->mapOptions['height'];
|
||||
}
|
||||
|
||||
$this->map['filter']['z_dash'] = $this->mapOptions['z_dash'];
|
||||
|
||||
if (is_array($graph) === true) {
|
||||
$nodes = $graph['nodes'];
|
||||
|
@ -2501,6 +2577,10 @@ class NetworkMap
|
|||
$style['image'] = $node_tmp['image'];
|
||||
$style['width'] = $node_tmp['width'];
|
||||
$style['height'] = $node_tmp['height'];
|
||||
$style['radius'] = max(
|
||||
$style['width'],
|
||||
$style['height']
|
||||
);
|
||||
$style['label'] = $node_tmp['text'];
|
||||
|
||||
$node_tmp['style'] = json_encode($style);
|
||||
|
@ -2658,6 +2738,10 @@ class NetworkMap
|
|||
$output .= "var z_dash = null;\n";
|
||||
}
|
||||
|
||||
if (empty($networkmap['filter']['node_radius']) === true) {
|
||||
$networkmap['filter']['node_radius'] = $this->mapOptions['map_filter']['node_radius'];
|
||||
}
|
||||
|
||||
$output .= 'var networkmap_refresh_time = 1000 * '.$networkmap['source_period'].";\n";
|
||||
$output .= 'var networkmap_center = [ '.$networkmap['center_x'].', '.$networkmap['center_y']."];\n";
|
||||
$output .= 'var networkmap_dimensions = [ '.$networkmap['width'].', '.$networkmap['height']."];\n";
|
||||
|
@ -2676,8 +2760,14 @@ class NetworkMap
|
|||
$nodes = [];
|
||||
}
|
||||
|
||||
$nodes_js = $this->nodesToJS($nodes);
|
||||
$output .= 'networkmap.nodes = ('.json_encode($nodes_js).");\n";
|
||||
$this->nodesJS = $this->nodesToJS($nodes);
|
||||
|
||||
$output .= 'networkmap.nodes = ('.json_encode($this->nodesJS).");\n";
|
||||
|
||||
// Clean.
|
||||
unset($this->nodes);
|
||||
unset($this->rawNodes);
|
||||
unset($this->nodeMapping);
|
||||
|
||||
// Translate edges to js links.
|
||||
$relations = $this->graph['relations'];
|
||||
|
@ -2685,8 +2775,11 @@ class NetworkMap
|
|||
$relations = [];
|
||||
}
|
||||
|
||||
$links_js = $this->edgeToJS($relations);
|
||||
$output .= 'networkmap.links = ('.json_encode($links_js).");\n";
|
||||
$this->relationsJS = $this->edgeToJS($relations);
|
||||
$output .= 'networkmap.links = ('.json_encode($this->relationsJS).");\n";
|
||||
|
||||
// Clean.
|
||||
unset($this->relations);
|
||||
|
||||
$output .= '
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -3221,16 +3314,21 @@ class NetworkMap
|
|||
&& $this->useTooltipster
|
||||
) {
|
||||
$output .= '<script type="text/javascript">
|
||||
var nodes = networkmap.nodes;
|
||||
var arrows = networkmap.links;
|
||||
var width = networkmap_dimensions[0];
|
||||
var height = networkmap_dimensions[1];
|
||||
var font_size = '.$this->mapOptions['font_size'].';
|
||||
var custom_params = '.json_encode($this->tooltipParams).';
|
||||
var controller = null;
|
||||
var homedir = "'.ui_get_full_url(false).'"
|
||||
$(function() {
|
||||
controller = new SimpleMapController("#simple_map");
|
||||
controller = new SimpleMapController({
|
||||
map_width: '.$this->map['width'].',
|
||||
map_height: '.$this->map['height'].',
|
||||
id: "'.$this->idMap.'",
|
||||
target: "#simple_map",
|
||||
nodes: '.json_encode($this->nodesJS).',
|
||||
arrows: '.json_encode($this->relationsJS).',
|
||||
center_x: '.$this->map['center_x'].',
|
||||
center_y: '.$this->map['center_y'].',
|
||||
z_dash: '.$this->map['filter']['z_dash'].',
|
||||
font_size: '.$this->mapOptions['font_size'].',
|
||||
homedir: "'.ui_get_full_url(false).'",
|
||||
custom_params: '.json_encode($this->tooltipParams).'
|
||||
});
|
||||
controller.init_map();
|
||||
});
|
||||
</script>';
|
||||
|
@ -3315,9 +3413,17 @@ class NetworkMap
|
|||
|
||||
$output .= '<div id="simple_map" data-id="'.$this->idMap.'" ';
|
||||
$output .= 'style="border: 1px #ddd solid;';
|
||||
$output .= ' width:'.$this->mapOptions['width'];
|
||||
$output .= ' ;height:'.$this->mapOptions['height'].'">';
|
||||
$output .= '<svg id="svg'.$this->idMap.'" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" pointer-events="all" width="'.$this->mapOptions['width'].'" height="'.$this->mapOptions['height'].'px">';
|
||||
|
||||
if ($this->fullSize) {
|
||||
$output .= ' width:100%';
|
||||
$output .= ' ;height: 100%">';
|
||||
$output .= '<svg id="svg'.$this->idMap.'" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" pointer-events="all" width="100%" height="100%">';
|
||||
} else {
|
||||
$output .= ' width:'.$this->mapOptions['width'].'px';
|
||||
$output .= ' ;height:'.$this->mapOptions['height'].'px">';
|
||||
$output .= '<svg id="svg'.$this->idMap.'" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" pointer-events="all" width="'.$this->mapOptions['width'].'" height="'.$this->mapOptions['height'].'px">';
|
||||
}
|
||||
|
||||
$output .= '</svg>';
|
||||
$output .= '</div>';
|
||||
} else {
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
/**
|
||||
* Pandora build version and version
|
||||
*/
|
||||
$build_version = 'PC190417';
|
||||
$pandora_version = 'v7.0NG.733';
|
||||
$build_version = 'PC190503';
|
||||
$pandora_version = 'v7.0NG.734';
|
||||
|
||||
// Do not overwrite default timezone set if defined.
|
||||
$script_tz = @date_default_timezone_get();
|
||||
|
|
|
@ -583,8 +583,22 @@ define('NETWORKMAP_DEFAULT_HEIGHT', 800);
|
|||
// Discovery task types.
|
||||
define('DISCOVERY_HOSTDEVICES', 0);
|
||||
define('DISCOVERY_HOSTDEVICES_CUSTOM', 1);
|
||||
define('DISCOVERY_CLOUD_AWS', 10);
|
||||
define('DISCOVERY_APP_VMWARE', 100);
|
||||
define('DISCOVERY_CLOUD_AWS', 2);
|
||||
define('DISCOVERY_APP_VMWARE', 3);
|
||||
define('DISCOVERY_APP_MYSQL', 4);
|
||||
define('DISCOVERY_APP_ORACLE', 5);
|
||||
define('DISCOVERY_CLOUD_AWS_EC2', 6);
|
||||
define('DISCOVERY_CLOUD_AWS_RDS', 7);
|
||||
|
||||
|
||||
// Discovery types matching definition.
|
||||
define('DISCOVERY_SCRIPT_HOSTDEVICES_CUSTOM', 0);
|
||||
// Standard applications.
|
||||
define('DISCOVERY_SCRIPT_APP_VMWARE', 1);
|
||||
// Cloud environments.
|
||||
define('DISCOVERY_SCRIPT_CLOUD_AWS', 2);
|
||||
define('DISCOVERY_SCRIPT_IPAM_RECON', 3);
|
||||
define('DISCOVERY_SCRIPT_IPMI_RECON', 4);
|
||||
|
||||
// Discovery task descriptions.
|
||||
define('CLOUDWIZARD_AWS_DESCRIPTION', 'Discovery.Cloud.AWS.EC2');
|
||||
|
|
|
@ -328,14 +328,21 @@ function agents_get_alerts_simple($id_agent=false, $filter='', $options=false, $
|
|||
*
|
||||
* By default, it will return all the agents where the user has reading access.
|
||||
*
|
||||
* @param array filter options in an indexed array. See
|
||||
* db_format_array_where_clause_sql()
|
||||
* @param array Fields to get.
|
||||
* @param string Access needed in the agents groups.
|
||||
* @param array $order The order of agents, by default is upward for field nombre.
|
||||
* @param boolean $return Whether to return array with agents or false, or sql string statement
|
||||
* @param array $filter Filter options in an indexed array.
|
||||
* See db_format_array_where_clause_sql().
|
||||
* @param array $fields DB fields to get.
|
||||
* @param string $access ACL level needed in the agents groups.
|
||||
* @param array $order The order of agents, by default is upward
|
||||
* for field nombre.
|
||||
* @param boolean $return Whether to return array with agents or
|
||||
* the sql string statement.
|
||||
* @param boolean $disabled_agent Whether to return only the enabled agents
|
||||
* or not.
|
||||
* @param boolean $use_meta_table Whether to use the regular or the meta table
|
||||
* to retrieve the agents.
|
||||
*
|
||||
* @return mixed An array with all alerts defined for an agent or false in case no allowed groups are specified.
|
||||
* @return mixed An array with all alerts defined for an agent
|
||||
* or false in case no allowed groups are specified.
|
||||
*/
|
||||
function agents_get_agents(
|
||||
$filter=false,
|
||||
|
@ -346,7 +353,8 @@ function agents_get_agents(
|
|||
'order' => 'ASC',
|
||||
],
|
||||
$return=false,
|
||||
$disabled_agent=0
|
||||
$disabled_agent=0,
|
||||
$use_meta_table=false
|
||||
) {
|
||||
global $config;
|
||||
|
||||
|
@ -563,11 +571,15 @@ function agents_get_agents(
|
|||
);
|
||||
}
|
||||
|
||||
$table_name = ($use_meta_table === true) ? 'tmetaconsole_agent' : 'tagente';
|
||||
$sql = sprintf(
|
||||
'SELECT DISTINCT %s
|
||||
FROM tagente LEFT JOIN tagent_secondary_group ON tagent_secondary_group.id_agent=tagente.id_agente
|
||||
FROM `%s` tagente
|
||||
LEFT JOIN tagent_secondary_group
|
||||
ON tagent_secondary_group.id_agent=tagente.id_agente
|
||||
WHERE %s %s',
|
||||
implode(',', $fields),
|
||||
$table_name,
|
||||
$where,
|
||||
$order
|
||||
);
|
||||
|
|
|
@ -559,7 +559,6 @@ $module_field_column_mampping = [
|
|||
'module_critical_inverse' => 'critical_inverse as module_critical_inverse',
|
||||
'module_warning_inverse' => 'warning_inverse as module_warning_inverse',
|
||||
];
|
||||
|
||||
// module related field mappings 2/2 (output field => column for 'tagente_estado')
|
||||
// module_id_agent_modulo is not in this list
|
||||
$estado_fields_to_columns_mapping = [
|
||||
|
@ -14729,3 +14728,365 @@ function api_set_reset_agent_counts($id, $thrash1, $thrash2, $thrash3)
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Functions por get all user to new feature for Carrefour
|
||||
* It depends of returnType, the method will return csv or json data
|
||||
*
|
||||
* @param string $thrash1 don't use
|
||||
* @param string $thrash2 don't use
|
||||
* @param array $other don't use
|
||||
* *@param string $returnType
|
||||
* Example:
|
||||
* api.php?op=get&op2=list_all_user&return_type=json&apipass=1234&user=admin&pass=pandora
|
||||
* @return
|
||||
*/
|
||||
|
||||
|
||||
function api_get_list_all_user($thrash1, $thrash2, $other, $returnType)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!check_acl($config['id_user'], 0, 'AR')) {
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'SELECT
|
||||
tup.id_usuario AS user_id,
|
||||
tu.fullname AS fullname,
|
||||
tp.id_perfil AS profile_id,
|
||||
tup.id_up AS id_up,
|
||||
tp.name AS profile_name,
|
||||
tup.id_grupo AS group_id,
|
||||
tgp.nombre AS group_name
|
||||
FROM tperfil tp
|
||||
INNER JOIN tusuario_perfil tup
|
||||
ON tp.id_perfil = tup.id_perfil
|
||||
LEFT OUTER JOIN tgrupo tgp
|
||||
ON tup.id_grupo = tgp.id_grupo
|
||||
LEFT OUTER JOIN tusuario tu
|
||||
ON tu.id_user = tup.id_usuario';
|
||||
|
||||
$users = db_get_all_rows_sql($sql);
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($users as $up) {
|
||||
$group_name = $up['group_name'];
|
||||
if ($up['group_name'] === null) {
|
||||
$group_name = 'All';
|
||||
}
|
||||
|
||||
$values[$i] = [
|
||||
'id_usuario' => $up['user_id'],
|
||||
'fullname' => $up['fullname'],
|
||||
'id_up' => $up['id_up'],
|
||||
'id_perfil' => $up['profile_id'],
|
||||
'perfil_name' => $up['profile_name'],
|
||||
'id_grupo' => $up['group_id'],
|
||||
'group_name' => $group_name,
|
||||
];
|
||||
$i += 1;
|
||||
}
|
||||
|
||||
if ($values === false) {
|
||||
returnError('Error_user', __('Users could not be found.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 'array',
|
||||
'data' => $values,
|
||||
];
|
||||
|
||||
returnData($returnType, $data, ';');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Funtion for get all info user to new feature for Carrefour
|
||||
* It depends of returnType, the method will return csv or json data
|
||||
*
|
||||
* @param string $thrash1 don't use
|
||||
* @param string $thrash2 don't use
|
||||
* @param array $other other[0] = user database
|
||||
* @param string $returnType
|
||||
* Example
|
||||
* api.php?op=get&op2=info_user_name&return_type=json&other=admin&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
|
||||
function api_get_info_user_name($thrash1, $thrash2, $other, $returnType)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!check_acl($config['id_user'], 0, 'AR')) {
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT tup.id_usuario AS user_id,
|
||||
tu.fullname AS fullname,
|
||||
tup.id_up AS id_up,
|
||||
tp.id_perfil AS profile_id,
|
||||
tp.name AS profile_name,
|
||||
tup.id_grupo AS group_id,
|
||||
tg.nombre AS group_name
|
||||
FROM tperfil tp
|
||||
INNER JOIN tusuario_perfil tup
|
||||
ON tp.id_perfil = tup.id_perfil
|
||||
LEFT OUTER JOIN tgrupo tg
|
||||
ON tup.id_grupo = tg.id_grupo
|
||||
LEFT OUTER JOIN tusuario tu
|
||||
ON tu.id_user = tup.id_usuario
|
||||
WHERE tup.id_usuario = "%s"',
|
||||
io_safe_output($other['data'][0])
|
||||
);
|
||||
|
||||
$user_profile = db_get_all_rows_sql($sql);
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($user_profile as $up) {
|
||||
$group_name = $up['group_name'];
|
||||
if ($up['group_name'] === null) {
|
||||
$group_name = 'All';
|
||||
}
|
||||
|
||||
$values[$i] = [
|
||||
'id_usuario' => $up['user_id'],
|
||||
'fullname' => $up['fullname'],
|
||||
'id_up' => $up['id_up'],
|
||||
'id_perfil' => $up['profile_id'],
|
||||
'perfil_name' => $up['profile_name'],
|
||||
'id_grupo' => $up['group_id'],
|
||||
'group_name' => $group_name,
|
||||
];
|
||||
$i += 1;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 'array',
|
||||
'data' => $values,
|
||||
];
|
||||
|
||||
returnData($returnType, $data, ';');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function for get user from a group to new feature for Carrefour.
|
||||
* It depends of returnType, the method will return csv or json data.
|
||||
*
|
||||
* @param string $thrash1 don't use
|
||||
* @param string $thrash2 don't use
|
||||
* @param array $other
|
||||
* $other[0] = id group
|
||||
* $other[1] = is disabled or not
|
||||
* @param string $returnType
|
||||
* Example
|
||||
* api.php?op=get&op2=filter_user_group&return_type=json&other=0|0&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
|
||||
function api_get_filter_user_group($thrash1, $thrash2, $other, $returnType)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!check_acl($config['id_user'], 0, 'AR')) {
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
$filter = '';
|
||||
|
||||
if ($other['data'][0] !== '' && $other['data'][1] !== '') {
|
||||
$filter = 'WHERE tup.id_grupo = '.$other['data'][0].' AND tu.disabled = '.$other['data'][1].'';
|
||||
} else if ($other['data'][0] !== '') {
|
||||
$filter = 'WHERE tup.id_grupo = '.$other['data'][0].'';
|
||||
} else if ($other['data'][1] !== '') {
|
||||
$filter = 'WHERE tu.disabled = '.$other['data'][1].'';
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT DISTINCT
|
||||
tup.id_usuario AS user_id,
|
||||
tu.fullname AS fullname,
|
||||
tup.id_up AS id_up,
|
||||
tp.id_perfil AS profile_id,
|
||||
tp.name AS profile_name,
|
||||
tup.id_grupo AS group_id,
|
||||
tg.nombre AS group_name
|
||||
FROM tperfil tp
|
||||
INNER JOIN tusuario_perfil tup
|
||||
ON tp.id_perfil = tup.id_perfil
|
||||
LEFT OUTER JOIN tgrupo tg
|
||||
ON tup.id_grupo = tg.id_grupo
|
||||
LEFT OUTER JOIN tusuario tu
|
||||
ON tu.id_user = tup.id_usuario
|
||||
'.$filter.''
|
||||
);
|
||||
|
||||
$filter_user = db_get_all_rows_sql($sql);
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($filter_user as $up) {
|
||||
$group_name = $up['group_name'];
|
||||
if ($up['group_name'] === null) {
|
||||
$group_name = 'All';
|
||||
}
|
||||
|
||||
$values[$i] = [
|
||||
'id_usuario' => $up['user_id'],
|
||||
'fullname' => $up['fullname'],
|
||||
'id_up' => $up['id_up'],
|
||||
'id_perfil' => $up['profile_id'],
|
||||
'perfil_name' => $up['profile_name'],
|
||||
'id_grupo' => $up['group_id'],
|
||||
'group_name' => $group_name,
|
||||
];
|
||||
$i += 1;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 'array',
|
||||
'data' => $values,
|
||||
];
|
||||
|
||||
returnData($returnType, $data, ';');
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function for delete an user permission for Carrefour new feature
|
||||
* The return of this function its only a message
|
||||
*
|
||||
* @param string $thrash1 don't use
|
||||
* @param string $thrash2 don't use
|
||||
* @param array $other
|
||||
* $other[0] = id up
|
||||
* @param string $returnType
|
||||
* Example
|
||||
* api.php?op=set&op2=delete_user_permission&return_type=json&other=user|2&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
|
||||
function api_set_delete_user_permission($thrash1, $thrash2, $other, $returnType)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!check_acl($config['id_user'], 0, 'AW')) {
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
if ($other['data'][0] != '') {
|
||||
$values = [
|
||||
'id_up' => io_safe_output($other['data'][0]),
|
||||
];
|
||||
} else {
|
||||
returnError('Error_delete', __('User profile could not be deleted.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$deleted_permission = db_process_sql_delete('tusuario_perfil', $values);
|
||||
|
||||
if ($deleted_permission == false) {
|
||||
returnError('Error_delete', __('User profile could not be deleted.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 'string',
|
||||
'data' => $deleted_permission,
|
||||
];
|
||||
|
||||
returnData('string', ['type' => 'string', 'data' => $data]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function for add permission a user to a group for Carrefour new feature
|
||||
* It depends of returnType, the method will return csv or json data
|
||||
*
|
||||
* @param string $thrash1 don't use
|
||||
* @param string $thrash2 don't use
|
||||
* @param array $other other[0] = user database
|
||||
* other[1] = id group
|
||||
* other[2] = id profile
|
||||
* other[3] = no_hierarchy ( 0 or 1, if empty = 0)
|
||||
* other[4] = id from tusuario_perfil table (optional)
|
||||
* * @param string $returnType
|
||||
* Example
|
||||
* api.php?op=set&op2=add_permission_user_to_group&return_type=json&other=admin|0|1|1|20&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
|
||||
function api_set_add_permission_user_to_group($thrash1, $thrash2, $other, $returnType)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!check_acl($config['id_user'], 0, 'AW')) {
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'SELECT id_up
|
||||
FROM tusuario_perfil
|
||||
WHERE id_up = '.$other['data'][4].'';
|
||||
|
||||
$exist_profile = db_get_value_sql($sql);
|
||||
|
||||
if ($other['data'][3] < 0 || $other['data'][3] > 1) {
|
||||
returnError('Error_insert', __('User profile could not be available.'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($other['data'][3] == null) {
|
||||
$other['data'][3] = 0;
|
||||
}
|
||||
|
||||
$values = [
|
||||
'id_usuario' => $other['data'][0],
|
||||
'id_perfil' => $other['data'][2],
|
||||
'id_grupo' => $other['data'][1],
|
||||
'no_hierarchy' => $other['data'][3],
|
||||
'assigned_by' => $config['id_user'],
|
||||
'id_policy' => 0,
|
||||
'tags' => '',
|
||||
|
||||
];
|
||||
|
||||
$where_id_up = ['id_up' => $other['data'][4]];
|
||||
if ($exist_profile === $other['data'][4] && $where_id_up !== null) {
|
||||
$sucessfull_insert = db_process_sql_update('tusuario_perfil', $values, $where_id_up);
|
||||
} else {
|
||||
$sucessfull_insert = db_process_sql_insert('tusuario_perfil', $values);
|
||||
}
|
||||
|
||||
if ($sucessfull_insert == false) {
|
||||
returnError('Error_insert', __('User profile could not be available.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 'array',
|
||||
'data' => $values,
|
||||
];
|
||||
|
||||
returnData($returnType, $data, ';');
|
||||
|
||||
}
|
||||
|
|
|
@ -980,7 +980,11 @@ function config_update_config()
|
|||
$error_update[] = __('Custom support url');
|
||||
}
|
||||
|
||||
if (!config_update_value('vc_refr', get_parameter('vc_refr'))) {
|
||||
if (!config_update_value('legacy_vc', (int) get_parameter('legacy_vc'))) {
|
||||
$error_update[] = __('Use the legacy Visual Console');
|
||||
}
|
||||
|
||||
if (!config_update_value('vc_refr', (int) get_parameter('vc_refr'))) {
|
||||
$error_update[] = __('Default interval for refresh on Visual Console');
|
||||
}
|
||||
|
||||
|
@ -2415,10 +2419,18 @@ function config_process_config()
|
|||
config_update_value('dbtype', 'mysql');
|
||||
}
|
||||
|
||||
if (!isset($config['legacy_vc'])) {
|
||||
config_update_value('legacy_vc', 1);
|
||||
}
|
||||
|
||||
if (!isset($config['vc_refr'])) {
|
||||
config_update_value('vc_refr', 300);
|
||||
}
|
||||
|
||||
if (!isset($config['vc_line_thickness'])) {
|
||||
config_update_value('vc_line_thickness', 2);
|
||||
}
|
||||
|
||||
if (!isset($config['agent_size_text_small'])) {
|
||||
config_update_value('agent_size_text_small', 18);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,31 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// 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 Lesser General Public License
|
||||
// as published by the Free Software Foundation; 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.
|
||||
/**
|
||||
* Extension to manage a list of gateways and the node address where they should
|
||||
* point to.
|
||||
*
|
||||
* @category Custom fields View
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
|
@ -56,14 +71,14 @@ function get_custom_fields($custom_field_id=false, $select=true, $display_on_fro
|
|||
}
|
||||
} else {
|
||||
$metaconsole_connections = metaconsole_get_connection_names();
|
||||
// For all nodes
|
||||
// For all nodes.
|
||||
if (isset($metaconsole_connections) && is_array($metaconsole_connections)) {
|
||||
$result_meta = [];
|
||||
foreach ($metaconsole_connections as $metaconsole) {
|
||||
// Get server connection data
|
||||
// Get server connection data.
|
||||
$server_data = metaconsole_get_connection($metaconsole);
|
||||
|
||||
// Establishes connection
|
||||
// Establishes connection.
|
||||
if (metaconsole_load_external_db($server_data) !== NOERR) {
|
||||
continue;
|
||||
}
|
||||
|
@ -82,7 +97,7 @@ function get_custom_fields($custom_field_id=false, $select=true, $display_on_fro
|
|||
|
||||
$result[] = db_get_all_rows_sql($sql);
|
||||
|
||||
// Restore connection to root node
|
||||
// Restore connection to root node.
|
||||
metaconsole_restore_db();
|
||||
|
||||
if (isset($result) && is_array($result)) {
|
||||
|
@ -109,7 +124,7 @@ function get_custom_fields($custom_field_id=false, $select=true, $display_on_fro
|
|||
/**
|
||||
* Returns custom field data.
|
||||
*
|
||||
* @param integer custom_field_id id.
|
||||
* @param integer $custom_field_name Custom_field_id id.
|
||||
*
|
||||
* @return array custom fields data.
|
||||
*/
|
||||
|
@ -141,14 +156,14 @@ function get_custom_fields_data($custom_field_name)
|
|||
}
|
||||
} else {
|
||||
$metaconsole_connections = metaconsole_get_connection_names();
|
||||
// For all nodes
|
||||
// For all nodes.
|
||||
if (isset($metaconsole_connections) && is_array($metaconsole_connections)) {
|
||||
$result_meta = [];
|
||||
foreach ($metaconsole_connections as $metaconsole) {
|
||||
// Get server connection data
|
||||
// Get server connection data.
|
||||
$server_data = metaconsole_get_connection($metaconsole);
|
||||
|
||||
// Establishes connection
|
||||
// Establishes connection.
|
||||
if (metaconsole_load_external_db($server_data) !== NOERR) {
|
||||
continue;
|
||||
}
|
||||
|
@ -168,7 +183,7 @@ function get_custom_fields_data($custom_field_name)
|
|||
|
||||
$result_meta[] = db_get_all_rows_sql($sql);
|
||||
|
||||
// Restore connection to root node
|
||||
// Restore connection to root node.
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
|
@ -189,9 +204,15 @@ function get_custom_fields_data($custom_field_name)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function for custom field view return all conter for agents
|
||||
*
|
||||
* @param array $filters Params for search.
|
||||
* @return void False or array.
|
||||
*/
|
||||
function agent_counters_custom_fields($filters)
|
||||
{
|
||||
// filter by status agent
|
||||
// Filter by status agent.
|
||||
$and_status = '';
|
||||
|
||||
$agent_state_normal = 0;
|
||||
|
@ -262,7 +283,7 @@ function agent_counters_custom_fields($filters)
|
|||
}
|
||||
}
|
||||
|
||||
// filter by status module
|
||||
// Filter by status module.
|
||||
$empty_agents_count = "UNION ALL
|
||||
SELECT ta.id_agente,
|
||||
0 AS c_m_total,
|
||||
|
@ -314,20 +335,20 @@ function agent_counters_custom_fields($filters)
|
|||
$and_module_status .= ' ) ';
|
||||
}
|
||||
} else {
|
||||
// not normal
|
||||
// Not normal.
|
||||
$and_module_status = 'AND tae.estado <> 0 AND tae.estado <> 300 ';
|
||||
$empty_agents_count = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// filters module
|
||||
// Filters module.
|
||||
if ($filters['module_search']) {
|
||||
$and_module_search = 'AND tam.nombre LIKE "%'.$filters['module_search'].'%"';
|
||||
$empty_agents_count = '';
|
||||
}
|
||||
|
||||
// filter group and check ACL groups
|
||||
// Filter group and check ACL groups.
|
||||
$groups_and = '';
|
||||
if (!users_can_manage_group_all('AR')) {
|
||||
if ($filters['group']) {
|
||||
|
@ -338,7 +359,7 @@ function agent_counters_custom_fields($filters)
|
|||
}
|
||||
|
||||
if ($filters['group']) {
|
||||
// recursion check acl
|
||||
// Recursion check acl.
|
||||
if ($filters['recursion']) {
|
||||
$recursion_groups = groups_get_id_recursive($filters['group'], true);
|
||||
if (!users_can_manage_group_all('AR')) {
|
||||
|
@ -362,26 +383,26 @@ function agent_counters_custom_fields($filters)
|
|||
}
|
||||
}
|
||||
|
||||
// filter custom data
|
||||
// Filter custom data.
|
||||
$custom_data_and = '';
|
||||
if (!in_array(-1, $filters['id_custom_fields_data'])) {
|
||||
$custom_data_array = implode("', '", $filters['id_custom_fields_data']);
|
||||
$custom_data_and = "AND tcd.description IN ('".$custom_data_array."')";
|
||||
}
|
||||
|
||||
// filter custom name
|
||||
// Filter custom name.
|
||||
$custom_field_name = $filters['id_custom_fields'];
|
||||
|
||||
if (is_metaconsole()) {
|
||||
$metaconsole_connections = metaconsole_get_connection_names();
|
||||
// For all nodes
|
||||
// For all nodes.
|
||||
if (isset($metaconsole_connections) && is_array($metaconsole_connections)) {
|
||||
$result_meta = [];
|
||||
$data = [];
|
||||
foreach ($metaconsole_connections as $metaconsole) {
|
||||
// Get server connection data
|
||||
// Get server connection data.
|
||||
$server_data = metaconsole_get_connection($metaconsole);
|
||||
// Establishes connection
|
||||
// Establishes connection.
|
||||
if (metaconsole_load_external_db($server_data) !== NOERR) {
|
||||
continue;
|
||||
}
|
||||
|
@ -470,7 +491,13 @@ function agent_counters_custom_fields($filters)
|
|||
WHEN ta.total_count = ta.notinit_count
|
||||
THEN 5
|
||||
ELSE 0
|
||||
END) AS `status`
|
||||
END) AS `status`,
|
||||
ta.critical_count,
|
||||
ta.warning_count,
|
||||
ta.unknown_count,
|
||||
ta.notinit_count,
|
||||
ta.normal_count,
|
||||
ta.total_count
|
||||
FROM tagente ta
|
||||
LEFT JOIN tagent_secondary_group tasg
|
||||
ON ta.id_agente = tasg.id_agent
|
||||
|
@ -510,7 +537,7 @@ function agent_counters_custom_fields($filters)
|
|||
}
|
||||
|
||||
$data = array_merge($data, $node_result);
|
||||
// Restore connection to root node
|
||||
// Restore connection to root node.
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
}
|
||||
|
@ -519,7 +546,7 @@ function agent_counters_custom_fields($filters)
|
|||
$array_data = [];
|
||||
|
||||
if (isset($result_meta) && is_array($result_meta)) {
|
||||
// initialize counters
|
||||
// Initialize counters.
|
||||
$final_result['counters_total'] = [
|
||||
't_m_normal' => 0,
|
||||
't_m_critical' => 0,
|
||||
|
@ -538,7 +565,7 @@ function agent_counters_custom_fields($filters)
|
|||
foreach ($result_meta as $k => $nodo) {
|
||||
if (isset($nodo) && is_array($nodo)) {
|
||||
foreach ($nodo as $key => $value) {
|
||||
// Sum counters total
|
||||
// Sum counters total.
|
||||
$final_result['counters_total']['t_m_normal'] += $value['m_normal'];
|
||||
$final_result['counters_total']['t_m_critical'] += $value['m_critical'];
|
||||
$final_result['counters_total']['t_m_warning'] += $value['m_warning'];
|
||||
|
@ -553,7 +580,7 @@ function agent_counters_custom_fields($filters)
|
|||
$final_result['counters_total']['t_a_not_init'] += $value['a_not_init'];
|
||||
$final_result['counters_total']['t_a_agents'] += $value['a_agents'];
|
||||
|
||||
// Sum counters for data
|
||||
// Sum counters for data.
|
||||
$array_data[$value['name_data']]['m_normal'] += $value['m_normal'];
|
||||
$array_data[$value['name_data']]['m_critical'] += $value['m_critical'];
|
||||
$array_data[$value['name_data']]['m_warning'] += $value['m_warning'];
|
||||
|
@ -576,7 +603,7 @@ function agent_counters_custom_fields($filters)
|
|||
|
||||
$final_result['indexed_descriptions'] = $data;
|
||||
} else {
|
||||
// TODO
|
||||
// TODO.
|
||||
$final_result = false;
|
||||
}
|
||||
|
||||
|
@ -586,7 +613,7 @@ function agent_counters_custom_fields($filters)
|
|||
|
||||
function get_filters_custom_fields_view($id=0, $for_select=false, $name='')
|
||||
{
|
||||
// filter group and check ACL groups
|
||||
// Filter group and check ACL groups.
|
||||
$groups_and = '';
|
||||
if (!users_can_manage_group_all()) {
|
||||
$user_groups = array_keys(users_get_groups(false, 'AR', false));
|
||||
|
@ -631,3 +658,38 @@ function get_group_filter_custom_field_view($id)
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function for print counters agents or modules.
|
||||
*
|
||||
* @param array $status_array Array need value, image, title, color, counter.
|
||||
* @param string $id_form Id form default value ''.
|
||||
* @param string $id_input Id input default value ''.
|
||||
*
|
||||
* @return array Return html print div container counters.
|
||||
*/
|
||||
function print_counters_cfv(
|
||||
array $status_array,
|
||||
string $id_form='',
|
||||
string $id_input=''
|
||||
) {
|
||||
$html_result = '<form class = "cfv_status_agent" id="'.$id_form.'">';
|
||||
foreach ($status_array as $key => $value) {
|
||||
$checked = ($value['checked'] === 1) ? 'checked=true' : '';
|
||||
$disabled = ($value['counter'] === 0) ? 'disabled=true' : '';
|
||||
|
||||
$html_result .= '<input id="lists_'.$id_input.'['.$key.']" '.$checked.' '.$disabled.' type="checkbox" name="lists_'.$id_input.'['.$key.']" />';
|
||||
$html_result .= '<label for="lists_'.$id_input.'['.$key.']" style="background-color:'.$value['color'].';">';
|
||||
$html_result .= html_print_image(
|
||||
$value['image'],
|
||||
true,
|
||||
['title' => $value['title']]
|
||||
);
|
||||
$html_result .= $value['counter'];
|
||||
$html_result .= '</label>';
|
||||
}
|
||||
|
||||
$html_result .= '</form>';
|
||||
return $html_result;
|
||||
}
|
||||
|
|
|
@ -609,7 +609,7 @@ function filemanager_file_explorer(
|
|||
|
||||
if (defined('METACONSOLE')) {
|
||||
$table->class = 'databox_tactical';
|
||||
$table->title = '<span>'.__('Index of images').'</span>';
|
||||
$table->title = '<span>'.__('Index of %s', $relative_directory).'</span>';
|
||||
}
|
||||
|
||||
$table->colspan = [];
|
||||
|
@ -773,46 +773,42 @@ function filemanager_file_explorer(
|
|||
if (!$readOnly) {
|
||||
if (is_writable($real_directory)) {
|
||||
// The buttons to make actions
|
||||
if (defined('METACONSOLE')) {
|
||||
echo "<div style='text-align: left; width: ".$table->width.";'>";
|
||||
} else {
|
||||
$tabs_dialog = '<ul id="file_table_modal">
|
||||
<li class="create_folder">
|
||||
<a href="javascript: show_form_create_folder();">'.html_print_image(
|
||||
'images/create_directory.png',
|
||||
true,
|
||||
['title' => __('Create directory')]
|
||||
).'<span>'.__('Create a Directory').'</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="create_text_file">
|
||||
<a href="javascript: show_create_text_file();">'.html_print_image(
|
||||
'images/create_file.png',
|
||||
true,
|
||||
['title' => __('Create a Text')]
|
||||
).'<span>'.__('Create a Text').'</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="upload_file">
|
||||
<a href="javascript: show_upload_file();">'.html_print_image(
|
||||
'images/upload_file.png',
|
||||
true,
|
||||
['title' => __('Upload Files')]
|
||||
).'<span>'.__('Upload Files').'</span>
|
||||
</a>
|
||||
</li></ul>';
|
||||
$tabs_dialog = '<ul id="file_table_modal">
|
||||
<li class="create_folder">
|
||||
<a href="javascript: show_form_create_folder();">'.html_print_image(
|
||||
'images/create_directory.png',
|
||||
true,
|
||||
['title' => __('Create directory')]
|
||||
).'<span>'.__('Create a Directory').'</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="create_text_file">
|
||||
<a href="javascript: show_create_text_file();">'.html_print_image(
|
||||
'images/create_file.png',
|
||||
true,
|
||||
['title' => __('Create a Text')]
|
||||
).'<span>'.__('Create a Text').'</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="upload_file">
|
||||
<a href="javascript: show_upload_file();">'.html_print_image(
|
||||
'images/upload_file.png',
|
||||
true,
|
||||
['title' => __('Upload Files')]
|
||||
).'<span>'.__('Upload Files').'</span>
|
||||
</a>
|
||||
</li></ul>';
|
||||
|
||||
echo '<div id="create_folder" style="display: none;">'.$tabs_dialog.'
|
||||
<form method="post" action="'.$url.'">'.html_print_input_text('dirname', '', '', 30, 255, true).html_print_submit_button(__('Create'), 'crt', false, 'class="sub next"', true).html_print_input_hidden('directory', $relative_directory, true).html_print_input_hidden('create_dir', 1, true).html_print_input_hidden('hash', md5($relative_directory.$config['dbpass']), true).html_print_input_hidden('hash2', md5($relative_directory.$config['dbpass']), true).'</form></div>';
|
||||
echo '<div id="create_folder" style="display: none;">'.$tabs_dialog.'
|
||||
<form method="post" action="'.$url.'">'.html_print_input_text('dirname', '', '', 30, 255, true).html_print_submit_button(__('Create'), 'crt', false, 'class="sub next"', true).html_print_input_hidden('directory', $relative_directory, true).html_print_input_hidden('create_dir', 1, true).html_print_input_hidden('hash', md5($relative_directory.$config['dbpass']), true).html_print_input_hidden('hash2', md5($relative_directory.$config['dbpass']), true).'</form></div>';
|
||||
|
||||
echo '<div id="upload_file" style="display: none;"> '.$tabs_dialog.'
|
||||
<form method="post" action="'.$url.'" enctype="multipart/form-data">'.ui_print_help_tip(__('The zip upload in this dir, easy to upload multiple files.'), true).html_print_input_file('file', true, false).html_print_input_hidden('umask', $umask, true).html_print_checkbox('decompress', 1, false, true).__('Decompress').html_print_submit_button(__('Go'), 'go', false, 'class="sub next"', true).html_print_input_hidden('real_directory', $real_directory, true).html_print_input_hidden('directory', $relative_directory, true).html_print_input_hidden('hash', md5($real_directory.$relative_directory.$config['dbpass']), true).html_print_input_hidden('hash2', md5($relative_directory.$config['dbpass']), true).html_print_input_hidden('upload_file_or_zip', 1, true).'</form></div>';
|
||||
echo '<div id="upload_file" style="display: none;"> '.$tabs_dialog.'
|
||||
<form method="post" action="'.$url.'" enctype="multipart/form-data">'.ui_print_help_tip(__('The zip upload in this dir, easy to upload multiple files.'), true).html_print_input_file('file', true, false).html_print_input_hidden('umask', $umask, true).html_print_checkbox('decompress', 1, false, true).__('Decompress').html_print_submit_button(__('Go'), 'go', false, 'class="sub next"', true).html_print_input_hidden('real_directory', $real_directory, true).html_print_input_hidden('directory', $relative_directory, true).html_print_input_hidden('hash', md5($real_directory.$relative_directory.$config['dbpass']), true).html_print_input_hidden('hash2', md5($relative_directory.$config['dbpass']), true).html_print_input_hidden('upload_file_or_zip', 1, true).'</form></div>';
|
||||
|
||||
echo ' <div id="create_text_file" style="display: none;">'.$tabs_dialog.'
|
||||
<form method="post" action="'.$url.'">'.html_print_input_text('name_file', '', '', 30, 50, true).html_print_submit_button(__('Create'), 'create', false, 'class="sub next"', true).html_print_input_hidden('real_directory', $real_directory, true).html_print_input_hidden('directory', $relative_directory, true).html_print_input_hidden('hash', md5($real_directory.$relative_directory.$config['dbpass']), true).html_print_input_hidden('umask', $umask, true).html_print_input_hidden('create_text_file', 1, true).'</form></div>';
|
||||
echo ' <div id="create_text_file" style="display: none;">'.$tabs_dialog.'
|
||||
<form method="post" action="'.$url.'">'.html_print_input_text('name_file', '', '', 30, 50, true).html_print_submit_button(__('Create'), 'create', false, 'class="sub next"', true).html_print_input_hidden('real_directory', $real_directory, true).html_print_input_hidden('directory', $relative_directory, true).html_print_input_hidden('hash', md5($real_directory.$relative_directory.$config['dbpass']), true).html_print_input_hidden('umask', $umask, true).html_print_input_hidden('create_text_file', 1, true).'</form></div>';
|
||||
|
||||
echo "<div style='width: ".$table->width.";' class='file_table_buttons'>";
|
||||
}
|
||||
echo "<div style='width: ".$table->width.";' class='file_table_buttons'>";
|
||||
|
||||
echo "<a href='javascript: show_form_create_folder();'>";
|
||||
echo html_print_image(
|
||||
|
|
|
@ -436,7 +436,9 @@ function html_print_select_groups(
|
|||
$keys_field='id_grupo',
|
||||
$strict_user=false,
|
||||
$delete_groups=false,
|
||||
$include_groups=false
|
||||
$include_groups=false,
|
||||
$size=false,
|
||||
$simple_multiple_options=false
|
||||
) {
|
||||
global $config;
|
||||
|
||||
|
@ -481,7 +483,12 @@ function html_print_select_groups(
|
|||
$class,
|
||||
$disabled,
|
||||
$style,
|
||||
$option_style
|
||||
$option_style,
|
||||
$size,
|
||||
false,
|
||||
'',
|
||||
false,
|
||||
$simple_multiple_options
|
||||
);
|
||||
|
||||
if ($return) {
|
||||
|
@ -529,7 +536,8 @@ function html_print_select(
|
|||
$size=false,
|
||||
$modal=false,
|
||||
$message='',
|
||||
$select_all=false
|
||||
$select_all=false,
|
||||
$simple_multiple_options=false
|
||||
) {
|
||||
$output = "\n";
|
||||
|
||||
|
@ -557,6 +565,14 @@ function html_print_select(
|
|||
}
|
||||
}
|
||||
|
||||
if ($simple_multiple_options === true) {
|
||||
if ($size !== false) {
|
||||
$attributes .= ' size="'.$size.'"';
|
||||
} else {
|
||||
$attributes .= ' size="10"';
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($class)) {
|
||||
$attributes .= ' class="'.$class.'"';
|
||||
}
|
||||
|
@ -1774,7 +1790,8 @@ function html_print_button($label='OK', $name='', $disabled=false, $script='', $
|
|||
*/
|
||||
function html_print_textarea($name, $rows, $columns, $value='', $attributes='', $return=false, $class='')
|
||||
{
|
||||
$output = '<textarea id="textarea_'.$name.'" name="'.$name.'" cols="'.$columns.'" rows="'.$rows.'" '.$attributes.'" '.$class.'>';
|
||||
|
||||
$output = '<textarea id="textarea_'.$name.'" name="'.$name.'" cols="'.$columns.'" rows="'.$rows.'" '.$attributes.'" class="'.$class.'">';
|
||||
// $output .= io_safe_input ($value);
|
||||
$output .= ($value);
|
||||
$output .= '</textarea>';
|
||||
|
|
|
@ -50,7 +50,7 @@ function reporting_xml_get_report($report, $filename, $return=false)
|
|||
}
|
||||
|
||||
// Download if marked to download.
|
||||
if ($filename === false) {
|
||||
if ($filename !== false) {
|
||||
header('Content-Type: application/xml; charset=UTF-8');
|
||||
header('Content-Disposition: attachment; filename="'.$filename.'.xml"');
|
||||
}
|
||||
|
|
|
@ -54,10 +54,15 @@ function snmp_browser_print_tree(
|
|||
$last=0,
|
||||
$last_array=[],
|
||||
$sufix=false,
|
||||
$checked=[]
|
||||
$checked=[],
|
||||
$return=false,
|
||||
$descriptive_ids=false,
|
||||
$previous_id=''
|
||||
) {
|
||||
static $url = false;
|
||||
|
||||
$output = '';
|
||||
|
||||
// Get the base URL for images.
|
||||
if ($url === false) {
|
||||
$url = ui_get_full_url('operation/tree', false, false, false);
|
||||
|
@ -73,9 +78,9 @@ function snmp_browser_print_tree(
|
|||
$last_array[$depth] = $last;
|
||||
|
||||
if ($depth > 0) {
|
||||
echo "<ul id='ul_$id' style='margin: 0; padding: 0; display: none'>\n";
|
||||
$output .= "<ul id='ul_$id' style='margin: 0; padding: 0; display: none'>\n";
|
||||
} else {
|
||||
echo "<ul id='ul_$id' style='margin: 0; padding: 0;'>\n";
|
||||
$output .= "<ul id='ul_$id' style='margin: 0; padding: 0;'>\n";
|
||||
}
|
||||
|
||||
foreach ($tree['__LEAVES__'] as $level => $sub_level) {
|
||||
|
@ -83,73 +88,97 @@ function snmp_browser_print_tree(
|
|||
$sub_id = time().rand(0, getrandmax());
|
||||
|
||||
// Display the branch.
|
||||
echo "<li id='li_$sub_id' style='margin: 0; padding: 0;'>";
|
||||
$output .= "<li id='li_$sub_id' style='margin: 0; padding: 0;'>";
|
||||
|
||||
// Indent sub branches.
|
||||
for ($i = 1; $i <= $depth; $i++) {
|
||||
if ($last_array[$i] == 1) {
|
||||
echo '<img src="'.$url.'/no_branch.png" style="vertical-align: middle;">';
|
||||
$output .= '<img src="'.$url.'/no_branch.png" style="vertical-align: middle;">';
|
||||
} else {
|
||||
echo '<img src="'.$url.'/branch.png" style="vertical-align: middle;">';
|
||||
$output .= '<img src="'.$url.'/branch.png" style="vertical-align: middle;">';
|
||||
}
|
||||
}
|
||||
|
||||
// Branch.
|
||||
if (! empty($sub_level['__LEAVES__'])) {
|
||||
echo "<a id='anchor_$sub_id' onfocus='javascript: this.blur();' href='javascript: toggleTreeNode(\"$sub_id\", \"$id\");'>";
|
||||
$output .= "<a id='anchor_$sub_id' onfocus='javascript: this.blur();' href='javascript: toggleTreeNode(\"$sub_id\", \"$id\");'>";
|
||||
if ($depth == 0 && $count == 0) {
|
||||
if ($count == $total) {
|
||||
echo '<img src="'.$url.'/one_closed.png" style="vertical-align: middle;">';
|
||||
$output .= '<img src="'.$url.'/one_closed.png" style="vertical-align: middle;">';
|
||||
} else {
|
||||
echo '<img src="'.$url.'/first_closed.png" style="vertical-align: middle;">';
|
||||
$output .= '<img src="'.$url.'/first_closed.png" style="vertical-align: middle;">';
|
||||
}
|
||||
} else if ($count == $total) {
|
||||
echo '<img src="'.$url.'/last_closed.png" style="vertical-align: middle;">';
|
||||
$output .= '<img src="'.$url.'/last_closed.png" style="vertical-align: middle;">';
|
||||
} else {
|
||||
echo '<img src="'.$url.'/closed.png" style="vertical-align: middle;">';
|
||||
$output .= '<img src="'.$url.'/closed.png" style="vertical-align: middle;">';
|
||||
}
|
||||
|
||||
echo '</a>';
|
||||
$output .= '</a>';
|
||||
}
|
||||
|
||||
// Leave.
|
||||
else {
|
||||
if ($depth == 0 && $count == 0) {
|
||||
if ($count == $total) {
|
||||
echo '<img src="'.$url.'/no_branch.png" style="vertical-align: middle;">';
|
||||
$output .= '<img src="'.$url.'/no_branch.png" style="vertical-align: middle;">';
|
||||
} else {
|
||||
echo '<img src="'.$url.'/first_leaf.png" style="vertical-align: middle;">';
|
||||
$output .= '<img src="'.$url.'/first_leaf.png" style="vertical-align: middle;">';
|
||||
}
|
||||
} else if ($count == $total) {
|
||||
echo '<img src="'.$url.'/last_leaf.png" style="vertical-align: middle;">';
|
||||
$output .= '<img src="'.$url.'/last_leaf.png" style="vertical-align: middle;">';
|
||||
} else {
|
||||
echo '<img src="'.$url.'/leaf.png" style="vertical-align: middle;">';
|
||||
$output .= '<img src="'.$url.'/leaf.png" style="vertical-align: middle;">';
|
||||
}
|
||||
}
|
||||
|
||||
// Branch or leave with branches!
|
||||
if (isset($sub_level['__OID__'])) {
|
||||
echo "<a onfocus='javascript: this.blur();' href='javascript: snmpGet(\"".addslashes($sub_level['__OID__'])."\");'>";
|
||||
echo '<img src="'.$url.'/../../images/eye.png" style="vertical-align: middle;">';
|
||||
echo '</a>';
|
||||
$output .= "<a onfocus='javascript: this.blur();' href='javascript: snmpGet(\"".addslashes($sub_level['__OID__'])."\");'>";
|
||||
$output .= '<img src="'.$url.'/../../images/eye.png" style="vertical-align: middle;">';
|
||||
$output .= '</a>';
|
||||
}
|
||||
|
||||
$checkbox_name_sufix = ($sufix === true) ? '_'.$level : '';
|
||||
$checkbox_name = 'create_'.$sub_id.$checkbox_name_sufix;
|
||||
$status = (!empty($checked) && isset($checked[$level]));
|
||||
echo html_print_checkbox($checkbox_name, 0, $status, true, false, '').' <span>'.$level.'</span>';
|
||||
if (isset($sub_level['__VALUE__'])) {
|
||||
echo '<span class="value" style="display: none;"> = '.$sub_level['__VALUE__'].'</span>';
|
||||
if ($descriptive_ids === true) {
|
||||
$checkbox_name = 'create_'.$sub_id.$previous_id.$checkbox_name_sufix;
|
||||
} else {
|
||||
$checkbox_name = 'create_'.$sub_id.$checkbox_name_sufix;
|
||||
}
|
||||
|
||||
echo '</li>';
|
||||
$previous_id = $checkbox_name_sufix;
|
||||
$status = (!empty($checked) && isset($checked[$level]));
|
||||
$output .= html_print_checkbox($checkbox_name, 0, $status, true, false, '').' <span>'.$level.'</span>';
|
||||
if (isset($sub_level['__VALUE__'])) {
|
||||
$output .= '<span class="value" style="display: none;"> = '.$sub_level['__VALUE__'].'</span>';
|
||||
}
|
||||
|
||||
$output .= '</li>';
|
||||
|
||||
// Recursively print sub levels.
|
||||
snmp_browser_print_tree($sub_level, $sub_id, ($depth + 1), ($count == $total ? 1 : 0), $last_array, $sufix, $checked);
|
||||
$output .= snmp_browser_print_tree(
|
||||
$sub_level,
|
||||
$sub_id,
|
||||
($depth + 1),
|
||||
($count == $total ? 1 : 0),
|
||||
$last_array,
|
||||
$sufix,
|
||||
$checked,
|
||||
$return,
|
||||
$descriptive_ids,
|
||||
$previous_id
|
||||
);
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
$output .= '</ul>';
|
||||
|
||||
if ($return == false) {
|
||||
echo $output;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1988,10 +1988,10 @@ function ui_pagination(
|
|||
$script_modified
|
||||
);
|
||||
|
||||
$output .= "<a class='offset_$offset_page'
|
||||
$output .= "<a class='pagination $other_class offset_$offset_page'
|
||||
href='javascript: $script_modified;'>";
|
||||
} else {
|
||||
$output .= "<a class='offset_$offset_page' href='$url&$offset_name=$offset_page'>";
|
||||
$output .= "<a class='pagination $other_class offset_$offset_page' href='$url&$offset_name=$offset_page'>";
|
||||
}
|
||||
|
||||
$output .= $iterator;
|
||||
|
|
|
@ -3961,38 +3961,54 @@ function visual_map_translate_module_status($module_status)
|
|||
* layouts), and makes an AND operation to be sure that all the items
|
||||
* are OK. If any of them is down, then result is down (0)
|
||||
*
|
||||
* @param int Id of the layout
|
||||
* @param array Information about the status calculation of the item
|
||||
* @param int Depth (for recursion control)
|
||||
* @param integer $layout_id Id of the layout.
|
||||
* @param array $status_data Information about the status calculation of the
|
||||
* item.
|
||||
* @param integer $depth Depth (for recursion control).
|
||||
*
|
||||
* @return boolean The status of the given layout. True if it's OK, false if not.
|
||||
* @return integer The status of the given layout.
|
||||
*/
|
||||
function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
|
||||
{
|
||||
global $config;
|
||||
|
||||
// TODO: Implement this limit into the setup
|
||||
// TODO: Implement this limit into the setup.
|
||||
if ($depth > 10) {
|
||||
return VISUAL_MAP_STATUS_UNKNOWN;
|
||||
}
|
||||
|
||||
$layout_items = db_get_all_rows_filter('tlayout_data', ['id_layout' => $layout_id]);
|
||||
$layout_items = db_get_all_rows_filter(
|
||||
'tlayout_data',
|
||||
['id_layout' => $layout_id]
|
||||
);
|
||||
|
||||
if ($layout_items === false) {
|
||||
return VISUAL_MAP_STATUS_UNKNOWN;
|
||||
}
|
||||
|
||||
// Check for valid items to retrieve the status for
|
||||
// Check for valid items to retrieve the status for.
|
||||
$valid_layout_items = [];
|
||||
foreach ($layout_items as $layout_item_data) {
|
||||
if (($layout_item_data['type'] == GROUP_ITEM
|
||||
&& !empty($layout_item_data['id_group'])
|
||||
&& check_acl($config['id_user'], $layout_item_data['id_group'], 'VR')
|
||||
&& check_acl($config['id_user'], $layout_item_data['element_group'], 'VR'))
|
||||
&& check_acl(
|
||||
$config['id_user'],
|
||||
$layout_item_data['id_group'],
|
||||
'VR'
|
||||
)
|
||||
&& check_acl(
|
||||
$config['id_user'],
|
||||
$layout_item_data['element_group'],
|
||||
'VR'
|
||||
))
|
||||
|| ((!empty($layout_item_data['id_layout_linked'])
|
||||
|| !empty($layout_item_data['id_agente_modulo'])
|
||||
|| !empty($layout_item_data['id_agent']))
|
||||
&& check_acl($config['id_user'], $layout_item_data['element_group'], 'VR'))
|
||||
&& check_acl(
|
||||
$config['id_user'],
|
||||
$layout_item_data['element_group'],
|
||||
'VR'
|
||||
))
|
||||
) {
|
||||
$valid_layout_items[] = $layout_item_data;
|
||||
}
|
||||
|
@ -4002,7 +4018,7 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
|
|||
return VISUAL_MAP_STATUS_UNKNOWN;
|
||||
}
|
||||
|
||||
// Sort by node id to reduce the number of connections
|
||||
// Sort by node id to reduce the number of connections.
|
||||
if (is_metaconsole()) {
|
||||
sort_by_column($valid_layout_items, 'id_metaconsole');
|
||||
}
|
||||
|
@ -4021,14 +4037,14 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
|
|||
|
||||
if (empty($node_id) && $meta_connected_to) {
|
||||
metaconsole_restore_db();
|
||||
// Restore db connection
|
||||
// Restore db connection.
|
||||
$meta_connected_to = null;
|
||||
} else if (!empty($node_id) && ( empty($meta_connected_to)
|
||||
|| $meta_connected_to != $node_id)
|
||||
} else if (!empty($node_id)
|
||||
&& (empty($meta_connected_to) || $meta_connected_to != $node_id)
|
||||
) {
|
||||
if (!empty($meta_connected_to)) {
|
||||
metaconsole_restore_db();
|
||||
// Restore db connection
|
||||
// Restore db connection.
|
||||
}
|
||||
|
||||
$connection = metaconsole_get_connection_by_id($node_id);
|
||||
|
@ -4042,64 +4058,80 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
|
|||
|
||||
$status = VISUAL_MAP_STATUS_NORMAL;
|
||||
|
||||
$ent_element_status = enterprise_hook('enterprise_visual_map_get_status_element', [$layoutData]);
|
||||
$ent_element_status = enterprise_hook(
|
||||
'enterprise_visual_map_get_status_element',
|
||||
[$layoutData]
|
||||
);
|
||||
if ($ent_element_status === ENTERPRISE_NOT_HOOK) {
|
||||
$ent_element_status = false;
|
||||
}
|
||||
|
||||
// Enterprise element
|
||||
if ($ent_element_status !== false) {
|
||||
// Enterprise element.
|
||||
$status = $ent_element_status;
|
||||
}
|
||||
// Other
|
||||
else {
|
||||
} else {
|
||||
// Other.
|
||||
switch ($layout_item_data['type']) {
|
||||
case STATIC_GRAPH:
|
||||
case PERCENTILE_BAR:
|
||||
case PERCENTILE_BUBBLE:
|
||||
case CIRCULAR_PROGRESS_BAR:
|
||||
case CIRCULAR_INTERIOR_PROGRESS_BAR:
|
||||
// Linked layout
|
||||
if (!empty($layout_item_data['id_layout_linked'])) {
|
||||
$status = visual_map_get_layout_status($layout_item_data['id_layout_linked'], $layout_item_data, ($depth + 1));
|
||||
}
|
||||
// Module
|
||||
else if (!empty($layout_item_data['id_agente_modulo'])) {
|
||||
$module_status = modules_get_agentmodule_status($layout_item_data['id_agente_modulo']);
|
||||
$status = visual_map_translate_module_status($module_status);
|
||||
}
|
||||
// Agent
|
||||
else if (!empty($layout_item_data['id_agent'])) {
|
||||
$agent_status = agents_get_status($layout_item_data['id_agent'], true);
|
||||
$status = visual_map_translate_agent_status($agent_status);
|
||||
}
|
||||
// Unknown
|
||||
else {
|
||||
// Linked layout.
|
||||
$status = visual_map_get_layout_status(
|
||||
$layout_item_data['id_layout_linked'],
|
||||
$layout_item_data,
|
||||
($depth + 1)
|
||||
);
|
||||
} else if (!empty($layout_item_data['id_agente_modulo'])) {
|
||||
// Module.
|
||||
$module_status = modules_get_agentmodule_status(
|
||||
$layout_item_data['id_agente_modulo']
|
||||
);
|
||||
$status = visual_map_translate_module_status(
|
||||
$module_status
|
||||
);
|
||||
} else if (!empty($layout_item_data['id_agent'])) {
|
||||
// Agent.
|
||||
$agent_status = agents_get_status(
|
||||
$layout_item_data['id_agent'],
|
||||
true
|
||||
);
|
||||
$status = visual_map_translate_agent_status(
|
||||
$agent_status
|
||||
);
|
||||
} else {
|
||||
// Unknown.
|
||||
$status = VISUAL_MAP_STATUS_UNKNOWN;
|
||||
}
|
||||
break;
|
||||
|
||||
case GROUP_ITEM:
|
||||
$group_status = groups_get_status($layout_item_data['id_group']);
|
||||
$group_status = groups_get_status(
|
||||
$layout_item_data['id_group']
|
||||
);
|
||||
$status = visual_map_translate_agent_status($group_status);
|
||||
break;
|
||||
|
||||
default:
|
||||
// If it's a graph, a progress bar or a data tag, ALWAYS report status OK
|
||||
// (=0) to avoid confussions here.
|
||||
// If it's a graph, a progress bar or a data tag,
|
||||
// ALWAYS report status OK (=0) to avoid confussions here.
|
||||
$status = VISUAL_MAP_STATUS_NORMAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// When the status calculation type is 'default', only one critical element is required to
|
||||
// set the layout status as critical, so we can return the critical status right now.
|
||||
if ($status_data['linked_layout_status_type'] === 'default' && ( $status == VISUAL_MAP_STATUS_CRITICAL_BAD
|
||||
// When the status calculation type is 'default', only one critical
|
||||
// element is required to set the layout status as critical, so we can
|
||||
// return the critical status right now.
|
||||
if ($status_data['linked_layout_status_type'] === 'default'
|
||||
&& ($status == VISUAL_MAP_STATUS_CRITICAL_BAD
|
||||
|| $status == VISUAL_MAP_STATUS_CRITICAL_ALERT)
|
||||
) {
|
||||
if (is_metaconsole() && $meta_connected_to) {
|
||||
// Restore db connection.
|
||||
metaconsole_restore_db();
|
||||
// Restore db connection
|
||||
}
|
||||
|
||||
return $status;
|
||||
|
@ -4113,11 +4145,11 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
|
|||
}
|
||||
|
||||
if (is_metaconsole() && $meta_connected_to) {
|
||||
// Restore db connection.
|
||||
metaconsole_restore_db();
|
||||
// Restore db connection
|
||||
}
|
||||
|
||||
// Status calculation
|
||||
// Status calculation.
|
||||
switch ($status_data['linked_layout_status_type']) {
|
||||
default:
|
||||
case 'default':
|
||||
|
@ -4149,7 +4181,7 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
|
|||
if ($num_items_critical > 0
|
||||
&& ((($num_items_critical_alert + $num_items_critical) * 100) / $num_items) >= $weight
|
||||
) {
|
||||
return $num_items_critical_alert > 0 ? VISUAL_MAP_STATUS_CRITICAL_ALERT : VISUAL_MAP_STATUS_CRITICAL_BAD;
|
||||
return ($num_items_critical_alert > 0) ? VISUAL_MAP_STATUS_CRITICAL_ALERT : VISUAL_MAP_STATUS_CRITICAL_BAD;
|
||||
} else if ($num_items_warning > 0
|
||||
&& (($num_items_warning * 100) / $num_items) >= $weight
|
||||
) {
|
||||
|
@ -4525,3 +4557,43 @@ function visual_map_get_color_cloud_element($data)
|
|||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the Visual Console Client files (js & css).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function visual_map_load_client_resources()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$baseUrl = ui_get_full_url(false, false, false, false);
|
||||
$vcClientPath = 'include/visual-console-client';
|
||||
$dir = $config['homedir'].'/'.$vcClientPath;
|
||||
if (is_dir($dir)) {
|
||||
$dh = opendir($dir);
|
||||
if ($dh) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file === '.' || $file === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
preg_match('/.*.js$/', $file, $match, PREG_OFFSET_CAPTURE);
|
||||
if (empty($match) === false) {
|
||||
$url = $baseUrl.$vcClientPath.'/'.$match[0][0];
|
||||
echo '<script type="text/javascript" src="'.$url.'"></script>';
|
||||
continue;
|
||||
}
|
||||
|
||||
preg_match('/.*.css$/', $file, $match, PREG_OFFSET_CAPTURE);
|
||||
if (empty($match) === false) {
|
||||
$url = $baseUrl.$vcClientPath.'/'.$match[0][0];
|
||||
echo '<link type="text/css" rel="stylesheet" href="'.$url.'" />';
|
||||
}
|
||||
}
|
||||
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -688,7 +688,7 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background)
|
|||
'percentile_item',
|
||||
'datos',
|
||||
];
|
||||
$form_items['percentile_item_row_6']['html'] = '<td align="left">'.__('Label color').'</td>
|
||||
$form_items['percentile_item_row_6']['html'] = '<td align="left">'.__('Value color').'</td>
|
||||
<td align="left">'.html_print_input_text_extended(
|
||||
'percentile_label_color',
|
||||
'#ffffff',
|
||||
|
|
|
@ -2133,7 +2133,7 @@ function pandoraFlotArea(
|
|||
var plot = $.plot($("#" + graph_id), datas, options);
|
||||
|
||||
// Re-calculate the graph height with the legend height
|
||||
if (dashboard || vconsole) {
|
||||
if (dashboard) {
|
||||
$acum = 0;
|
||||
if (dashboard) $acum = 35;
|
||||
var hDiff =
|
||||
|
|
|
@ -415,7 +415,7 @@ function d3_progress_bubble($id, $percentile, $width, $height, $color, $unit='%'
|
|||
}
|
||||
|
||||
|
||||
function progress_circular_bar($id, $percentile, $width, $height, $color, $unit='%', $text='', $fill_color='#FFFFFF')
|
||||
function progress_circular_bar($id, $percentile, $width, $height, $color, $unit='%', $text='', $fill_color='#FFFFFF', $transition=1)
|
||||
{
|
||||
global $config;
|
||||
|
||||
|
@ -427,7 +427,7 @@ function progress_circular_bar($id, $percentile, $width, $height, $color, $unit=
|
|||
$output .= '<div id='.$recipient_name." style='overflow: hidden;'></div>";
|
||||
$output .= include_javascript_d3(true);
|
||||
$output .= "<script language=\"javascript\" type=\"text/javascript\">
|
||||
print_circular_progress_bar('".$recipient_name_to_js."', ".(int) $percentile.', '.(int) $width.', '.(int) $height.", '".$color."', '".$unit."', '".$text."', '".$fill_color."');
|
||||
print_circular_progress_bar('".$recipient_name_to_js."', ".(int) $percentile.', '.(int) $width.', '.(int) $height.", '".$color."', '".$unit."', '".$text."', '".$fill_color."', '".$transition."');
|
||||
</script>";
|
||||
|
||||
return $output;
|
||||
|
|
|
@ -1980,7 +1980,8 @@ function print_circular_progress_bar(
|
|||
color,
|
||||
unit,
|
||||
label,
|
||||
label_color
|
||||
label_color,
|
||||
transition
|
||||
) {
|
||||
var twoPi = Math.PI * 2;
|
||||
var radius = width / 2;
|
||||
|
@ -2112,15 +2113,19 @@ function print_circular_progress_bar(
|
|||
|
||||
var progress = startPercent;
|
||||
|
||||
(function loops() {
|
||||
updateProgress(progress);
|
||||
if (transition == 0)
|
||||
updateProgress(endPercent);
|
||||
else {
|
||||
(function loops() {
|
||||
updateProgress(progress);
|
||||
|
||||
if (count > 0) {
|
||||
count--;
|
||||
progress += step;
|
||||
setTimeout(loops, 30);
|
||||
}
|
||||
})();
|
||||
if (count > 0) {
|
||||
count--;
|
||||
progress += step;
|
||||
setTimeout(loops, 30);
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
function print_interior_circular_progress_bar(
|
||||
|
|
|
@ -1748,7 +1748,9 @@ function round_with_decimals(value, multiplier) {
|
|||
if (typeof multiplier === "undefined") multiplier = 1;
|
||||
|
||||
// Return non numeric types without modification
|
||||
if (typeof value !== "number") return value;
|
||||
if (typeof value !== "number" || Number.isNaN(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value * multiplier == 0) return 0;
|
||||
if (Math.abs(value) * multiplier >= 1) {
|
||||
|
|
|
@ -1,3 +1,268 @@
|
|||
// TODO: Add Artica ST header.
|
||||
/* globals jQuery, VisualConsole */
|
||||
|
||||
/*
|
||||
* *********************
|
||||
* * New VC functions. *
|
||||
* *********************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generate a Visual Console client.
|
||||
* @param {HTMLElement} container Node which will be used to contain the VC.
|
||||
* @param {object} props VC container properties.
|
||||
* @param {object[]} items List of item definitions.
|
||||
* @param {string | null} baseUrl Base URL to perform API requests.
|
||||
* @param {number | null} updateInterval Time in milliseconds between VC updates.
|
||||
* @param {function | null} onUpdate Callback which will be execuded when the Visual Console.
|
||||
* is updated. It will receive two arguments with the old and the new Visual Console's
|
||||
* data structure.
|
||||
* @return {VisualConsole | null} The Visual Console instance or a null value.
|
||||
*/
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function createVisualConsole(
|
||||
container,
|
||||
props,
|
||||
items,
|
||||
baseUrl,
|
||||
updateInterval,
|
||||
onUpdate
|
||||
) {
|
||||
var visualConsole = null;
|
||||
var linkedVCRequest = null;
|
||||
var updateVCRequest = null;
|
||||
|
||||
if (container == null || props == null || items == null) return null;
|
||||
if (baseUrl == null) baseUrl = "";
|
||||
|
||||
// Code which will be executed between intervals.
|
||||
var intervalRef = null;
|
||||
var stopInterval = function() {
|
||||
if (intervalRef !== null) window.clearInterval(intervalRef);
|
||||
};
|
||||
var startInterval = function() {
|
||||
if (updateInterval == null || updateInterval <= 0) return;
|
||||
stopInterval();
|
||||
|
||||
intervalRef = window.setInterval(function() {
|
||||
if (updateVCRequest !== null) updateVCRequest.abort();
|
||||
updateVCRequest = loadVisualConsoleData(
|
||||
baseUrl,
|
||||
visualConsole.props.id,
|
||||
function(error, data) {
|
||||
if (error) {
|
||||
console.log(
|
||||
"[ERROR]",
|
||||
"[VISUAL-CONSOLE-CLIENT]",
|
||||
"[API]",
|
||||
error.message
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace Visual Console.
|
||||
if (data != null && data.props != null && data.items != null) {
|
||||
try {
|
||||
var props =
|
||||
typeof data.props === "string"
|
||||
? JSON.parse(data.props)
|
||||
: data.props;
|
||||
var items =
|
||||
typeof data.items === "string"
|
||||
? JSON.parse(data.items)
|
||||
: data.items;
|
||||
|
||||
var prevProps = visualConsole.props;
|
||||
// Update the data structure.
|
||||
visualConsole.props = props;
|
||||
// Update the items.
|
||||
visualConsole.updateElements(items);
|
||||
// Emit the VC update event.
|
||||
if (onUpdate) onUpdate(prevProps, visualConsole.props);
|
||||
} catch (ignored) {} // eslint-disable-line no-empty
|
||||
}
|
||||
}
|
||||
);
|
||||
}, updateInterval);
|
||||
};
|
||||
|
||||
// Initialize the Visual Console.
|
||||
try {
|
||||
visualConsole = new VisualConsole(container, props, items);
|
||||
// VC Item clicked.
|
||||
visualConsole.onClick(function(e) {
|
||||
// Override the link to another VC if it isn't on remote console.
|
||||
if (
|
||||
e.data &&
|
||||
e.data.linkedLayoutId != null &&
|
||||
e.data.linkedLayoutId > 0 &&
|
||||
e.data.link != null &&
|
||||
e.data.link.length > 0 &&
|
||||
(e.data.linkedLayoutAgentId == null || e.data.linkedLayoutAgentId === 0)
|
||||
) {
|
||||
// Stop the current link behavior.
|
||||
e.nativeEvent.preventDefault();
|
||||
|
||||
// Fetch and update the old VC with the new.
|
||||
if (linkedVCRequest !== null) linkedVCRequest.abort();
|
||||
linkedVCRequest = loadVisualConsoleData(
|
||||
baseUrl,
|
||||
e.data.linkedLayoutId,
|
||||
function(error, data) {
|
||||
if (error) {
|
||||
console.log(
|
||||
"[ERROR]",
|
||||
"[VISUAL-CONSOLE-CLIENT]",
|
||||
"[API]",
|
||||
error.message
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace Visual Console.
|
||||
if (data != null && data.props != null && data.items != null) {
|
||||
// Cancel the old VC updates.
|
||||
stopInterval();
|
||||
|
||||
try {
|
||||
var props =
|
||||
typeof data.props === "string"
|
||||
? JSON.parse(data.props)
|
||||
: data.props;
|
||||
var items =
|
||||
typeof data.items === "string"
|
||||
? JSON.parse(data.items)
|
||||
: data.items;
|
||||
|
||||
if (updateVCRequest !== null) updateVCRequest.abort();
|
||||
// Save the old props.
|
||||
var prevProps = visualConsole.props;
|
||||
// Update the data structure.
|
||||
visualConsole.props = props;
|
||||
// Update the items.
|
||||
visualConsole.updateElements(items);
|
||||
// Emit the VC update event.
|
||||
if (onUpdate) onUpdate(prevProps, visualConsole.props);
|
||||
} catch (ignored) {} // eslint-disable-line no-empty
|
||||
|
||||
// Restart the updates.
|
||||
startInterval();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Start an interval to update the Visual Console.
|
||||
startInterval();
|
||||
} catch (error) {
|
||||
console.log("[ERROR]", "[VISUAL-CONSOLE-CLIENT]", error.message);
|
||||
}
|
||||
|
||||
return visualConsole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a Visual Console's structure and its items.
|
||||
* @param {string} baseUrl Base URL to build the API path.
|
||||
* @param {number} vcId Identifier of the Visual Console.
|
||||
* @param {function} callback Function to be executed on request success or fail.
|
||||
* On success, the function will receive an object with the next properties:
|
||||
* - `props`: object with the Visual Console's data structure.
|
||||
* - `items`: array of data structures of the Visual Console's items.
|
||||
* @return {Object} Cancellable. Object which include and .abort([statusText]) function.
|
||||
*/
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function loadVisualConsoleData(baseUrl, vcId, callback) {
|
||||
// var apiPath = baseUrl + "/include/rest-api";
|
||||
var apiPath = baseUrl + "/ajax.php";
|
||||
var vcJqXHR = null;
|
||||
var itemsJqXHR = null;
|
||||
|
||||
// Initialize the final result.
|
||||
var result = {
|
||||
props: null,
|
||||
items: null
|
||||
};
|
||||
|
||||
// Cancel the ajax requests.
|
||||
var abort = function(textStatus) {
|
||||
if (textStatus == null) textStatus = "abort";
|
||||
|
||||
// -- XMLHttpRequest.readyState --
|
||||
// Value State Description
|
||||
// 0 UNSENT Client has been created. open() not called yet.
|
||||
// 4 DONE The operation is complete.
|
||||
|
||||
if (vcJqXHR.readyState !== 0 && vcJqXHR.readyState !== 4)
|
||||
vcJqXHR.abort(textStatus);
|
||||
if (itemsJqXHR.readyState !== 0 && itemsJqXHR.readyState !== 4)
|
||||
itemsJqXHR.abort(textStatus);
|
||||
};
|
||||
|
||||
// Check if the required data is complete.
|
||||
var checkResult = function() {
|
||||
return result.props !== null && result.items !== null;
|
||||
};
|
||||
|
||||
// Failed request handler.
|
||||
var handleFail = function(jqXHR, textStatus, errorThrown) {
|
||||
abort();
|
||||
// Manually aborted or not.
|
||||
if (textStatus === "abort") {
|
||||
callback();
|
||||
} else {
|
||||
var error = new Error(errorThrown);
|
||||
error.request = jqXHR;
|
||||
callback(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Curried function which handle success.
|
||||
var handleSuccess = function(key) {
|
||||
// Actual request handler.
|
||||
return function(data) {
|
||||
result[key] = data;
|
||||
if (checkResult()) callback(null, result);
|
||||
};
|
||||
};
|
||||
|
||||
// Visual Console container request.
|
||||
vcJqXHR = jQuery
|
||||
// .get(apiPath + "/visual-consoles/" + vcId, null, "json")
|
||||
.get(
|
||||
apiPath,
|
||||
{
|
||||
page: "include/rest-api/index",
|
||||
getVisualConsole: 1,
|
||||
visualConsoleId: vcId
|
||||
},
|
||||
"json"
|
||||
)
|
||||
.done(handleSuccess("props"))
|
||||
.fail(handleFail);
|
||||
// Visual Console items request.
|
||||
itemsJqXHR = jQuery
|
||||
// .get(apiPath + "/visual-consoles/" + vcId + "/items", null, "json")
|
||||
.get(
|
||||
apiPath,
|
||||
{
|
||||
page: "include/rest-api/index",
|
||||
getVisualConsoleItems: 1,
|
||||
visualConsoleId: vcId
|
||||
},
|
||||
"json"
|
||||
)
|
||||
.done(handleSuccess("items"))
|
||||
.fail(handleFail);
|
||||
|
||||
// Abortable.
|
||||
return {
|
||||
abort: abort
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Delete the functions below when you can.
|
||||
/**************************************
|
||||
These functions require jQuery library
|
||||
**************************************/
|
||||
|
|
|
@ -36481,8 +36481,8 @@ msgstr ""
|
|||
#: ../../enterprise/load_enterprise.php:584
|
||||
#, php-format
|
||||
msgid ""
|
||||
"<strong style=\"font-size: 11pt\">License out of limits</strong> <br><br> "
|
||||
"This node has a metaconsole license and it allows %d agents and you have %d "
|
||||
"<strong style=\"font-size: 11pt\">Out of license limits</strong> <br><br> "
|
||||
"This node has a Metaconsole license that allows %d agents, and you have %d "
|
||||
"agents cached."
|
||||
msgstr ""
|
||||
"<strong style=\"font-size: 11pt\">License expired</strong> <br><br> This "
|
||||
|
@ -36492,20 +36492,21 @@ msgstr ""
|
|||
#: ../../enterprise/load_enterprise.php:592
|
||||
#, php-format
|
||||
msgid ""
|
||||
"<strong style=\"font-size: 11pt\">License out of limits</strong> <br><br> "
|
||||
"This license allows %d agents and you have %d agents configured."
|
||||
"<strong style=\"font-size: 11pt\">Out of license limits</strong> <br><br> "
|
||||
"This node has a Metaconsole license that allows %d agents, and you have %d "
|
||||
"agents configured."
|
||||
msgstr ""
|
||||
"<strong style=\"font-size: 11pt\">License expired</strong> <br><br> This "
|
||||
"license allows %d agents and you have %d agents configured."
|
||||
"license allows %d agents, and you have %d agents configured."
|
||||
|
||||
#: ../../enterprise/load_enterprise.php:597
|
||||
#, php-format
|
||||
msgid ""
|
||||
"<strong style=\"font-size: 11pt\">License out of limits</strong> <br><br> "
|
||||
"<strong style=\"font-size: 11pt\">Out of license limits</strong> <br><br> "
|
||||
"This license allows %d modules and you have %d modules configured."
|
||||
msgstr ""
|
||||
"<strong style=\"font-size: 11pt\">License expired</strong> <br><br> This "
|
||||
"license allows %d modules and you have %d modules configured."
|
||||
"<strong style=\"font-size: 11pt\">Out of license limits</strong> <br><br> This "
|
||||
"license allows %d modules, and you have %d modules configured."
|
||||
|
||||
#: ../../enterprise/load_enterprise.php:604
|
||||
msgid ""
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
global $config;
|
||||
|
||||
if (!is_ajax()) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once $config['homedir'].'/vendor/autoload.php';
|
||||
|
||||
use Models\VisualConsole\Container as VisualConsole;
|
||||
|
||||
$visualConsoleId = (int) get_parameter('visualConsoleId');
|
||||
$getVisualConsole = (bool) get_parameter('getVisualConsole');
|
||||
$getVisualConsoleItems = (bool) get_parameter('getVisualConsoleItems');
|
||||
|
||||
// Check groups can access user.
|
||||
$aclUserGroups = [];
|
||||
if (!users_can_manage_group_all('AR')) {
|
||||
$aclUserGroups = array_keys(users_get_groups(false, 'AR'));
|
||||
}
|
||||
|
||||
ob_clean();
|
||||
|
||||
if ($getVisualConsole === true) {
|
||||
$visualConsole = VisualConsole::fromDB(['id' => $visualConsoleId]);
|
||||
$visualConsoleData = $visualConsole->toArray();
|
||||
$groupId = $visualConsoleData['groupId'];
|
||||
|
||||
// ACL.
|
||||
$aclRead = check_acl($config['id_user'], $groupId, 'VR');
|
||||
$aclWrite = check_acl($config['id_user'], $groupId, 'VW');
|
||||
$aclManage = check_acl($config['id_user'], $groupId, 'VM');
|
||||
|
||||
if (!$aclRead && !$aclWrite && !$aclManage) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access visual console without group access'
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo $visualConsole;
|
||||
} else if ($getVisualConsoleItems === true) {
|
||||
$vcItems = VisualConsole::getItemsFromDB($visualConsoleId, $aclUserGroups);
|
||||
echo '['.implode($vcItems, ',').']';
|
||||
}
|
||||
|
||||
exit;
|
|
@ -0,0 +1,231 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models;
|
||||
|
||||
/**
|
||||
* This class should be extended to add functionalities to
|
||||
* fetch, validate, transform and represent data entities.
|
||||
*/
|
||||
abstract class Model
|
||||
{
|
||||
|
||||
/**
|
||||
* Internal data of the model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $data;
|
||||
|
||||
|
||||
/**
|
||||
* Validate the received data structure to ensure if we can extract the
|
||||
* values required to build the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException If any input value is considered
|
||||
* invalid.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract protected function validateData(array $data): void;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract protected function decode(array $data): array;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor of the model. It won't be public. The instances
|
||||
* will be created through factories which start with from*.
|
||||
*
|
||||
* @param array $unknownData Input data structure.
|
||||
*/
|
||||
protected function __construct(array $unknownData)
|
||||
{
|
||||
$this->validateData($unknownData);
|
||||
$this->data = $this->decode($unknownData);
|
||||
// Sort alphabetically.
|
||||
ksort($this->data, (SORT_NATURAL | SORT_FLAG_CASE));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instance the class with the unknown input data.
|
||||
*
|
||||
* @param array $data Unknown data structure.
|
||||
*
|
||||
* @return self Instance of the model.
|
||||
*/
|
||||
public static function fromArray(array $data)
|
||||
{
|
||||
// The reserved word static refers to the invoked class at runtime.
|
||||
return new static($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Obtain a data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter to retrieve the modeled element.
|
||||
*
|
||||
* @return array The modeled element data structure stored into the DB.
|
||||
* @throws \Exception When the data cannot be retrieved from the DB.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract protected static function fetchDataFromDB(array $filter);
|
||||
|
||||
|
||||
/**
|
||||
* Obtain a model's instance from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter to retrieve the modeled element.
|
||||
*
|
||||
* @return self A modeled element's instance.
|
||||
*/
|
||||
public static function fromDB(array $filter): self
|
||||
{
|
||||
// The reserved word static refers to the invoked class at runtime.
|
||||
return static::fromArray(static::fetchDataFromDB($filter));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* JSON representation of the model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* JSON representation of the model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toJson(): string
|
||||
{
|
||||
return \json_encode($this->data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Text representation of the model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->toJson();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* -------------
|
||||
* - UTILITIES -
|
||||
* -------------
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* From a unknown value, it will try to extract a valid boolean value.
|
||||
*
|
||||
* @param mixed $value Unknown input.
|
||||
*
|
||||
* @return boolean Valid boolean value.
|
||||
*/
|
||||
protected static function parseBool($value): bool
|
||||
{
|
||||
if (\is_bool($value) === true) {
|
||||
return $value;
|
||||
} else if (\is_numeric($value) === true) {
|
||||
return $value > 0;
|
||||
} else if (\is_string($value) === true) {
|
||||
return $value === '1' || $value === 'true';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a not empty string or a default value from a unknown value.
|
||||
*
|
||||
* @param mixed $val Input value.
|
||||
* @param mixed $def Default value.
|
||||
*
|
||||
* @return mixed A valid string (not empty) extracted from the input
|
||||
* or the default value.
|
||||
*/
|
||||
protected static function notEmptyStringOr($val, $def)
|
||||
{
|
||||
return (\is_string($val) === true && strlen($val) > 0) ? $val : $def;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a valid integer or a default value from a unknown value.
|
||||
*
|
||||
* @param mixed $val Input value.
|
||||
* @param mixed $def Default value.
|
||||
*
|
||||
* @return mixed A valid int extracted from the input or the default value.
|
||||
*/
|
||||
protected static function parseIntOr($val, $def)
|
||||
{
|
||||
return (is_numeric($val) === true) ? (int) $val : $def;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a valid float or a default value from a unknown value.
|
||||
*
|
||||
* @param mixed $val Input value.
|
||||
* @param mixed $def Default value.
|
||||
*
|
||||
* @return mixed A valid float extracted from the input or the
|
||||
* default value.
|
||||
*/
|
||||
protected static function parseFloatOr($val, $def)
|
||||
{
|
||||
return (is_numeric($val) === true) ? (float) $val : $def;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a value from a dictionary from a possible pool of keys.
|
||||
*
|
||||
* @param array $dict Input array.
|
||||
* @param array $keys Possible keys.
|
||||
*
|
||||
* @return mixed The first value found with the pool of keys or null.
|
||||
*/
|
||||
protected static function issetInArray(array $dict, array $keys)
|
||||
{
|
||||
foreach ($keys as $key => $value) {
|
||||
if (isset($dict[$value]) === true) {
|
||||
return $dict[$value];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,376 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole;
|
||||
use Models\Model;
|
||||
|
||||
/**
|
||||
* Model of a Visual Console.
|
||||
*/
|
||||
final class Container extends Model
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Validate the received data structure to ensure if we can extract the
|
||||
* values required to build the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException If any input value is considered
|
||||
* invalid.
|
||||
*
|
||||
* @overrides Model::validateData.
|
||||
*/
|
||||
protected function validateData(array $data): void
|
||||
{
|
||||
if (isset($data['id']) === false
|
||||
|| \is_numeric($data['id']) === false
|
||||
) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the Id property is required and should be integer'
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($data['name']) === false
|
||||
|| \is_string($data['name']) === false
|
||||
|| empty($data['name']) === true
|
||||
) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the name property is required and should be string'
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($data['width']) === false
|
||||
|| \is_numeric($data['width']) === false
|
||||
|| $data['width'] <= 0
|
||||
) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the width property is required and should greater than 0'
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($data['height']) === false
|
||||
|| \is_numeric($data['height']) === false
|
||||
|| $data['height'] <= 0
|
||||
) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the height property is required and should greater than 0'
|
||||
);
|
||||
}
|
||||
|
||||
static::extractGroupId($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Model::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) $data['id'],
|
||||
'name' => $data['name'],
|
||||
'groupId' => static::extractGroupId($data),
|
||||
'backgroundImage' => static::extractBackgroundImage($data),
|
||||
'backgroundColor' => static::extractBackgroundColor($data),
|
||||
'isFavorite' => static::extractFavorite($data),
|
||||
'width' => (int) $data['width'],
|
||||
'height' => (int) $data['height'],
|
||||
'backgroundURL' => static::extractBackgroundUrl($data),
|
||||
'relationLineWidth' => (int) $data['relationLineWidth'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a group Id value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return integer Valid identifier of a group.
|
||||
*
|
||||
* @throws \InvalidArgumentException When a valid group Id can't be found.
|
||||
*/
|
||||
private static function extractGroupId(array $data): int
|
||||
{
|
||||
$groupId = static::parseIntOr(
|
||||
static::issetInArray($data, ['id_group', 'groupId']),
|
||||
null
|
||||
);
|
||||
|
||||
if ($groupId === null || $groupId < 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the group Id property is required and should be integer'
|
||||
);
|
||||
}
|
||||
|
||||
return $groupId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a image name value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the image name (not empty) or null.
|
||||
*/
|
||||
private static function extractBackgroundImage(array $data)
|
||||
{
|
||||
$backgroundImage = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['background', 'backgroundURL']),
|
||||
null
|
||||
);
|
||||
|
||||
return ($backgroundImage === 'None.png') ? null : $backgroundImage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a image url value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the image url (not empty) or null.
|
||||
*/
|
||||
private static function extractBackgroundUrl(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['backgroundURL']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a background color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the color (not empty) or null.
|
||||
*/
|
||||
private static function extractBackgroundColor(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray(
|
||||
$data,
|
||||
[
|
||||
'backgroundColor',
|
||||
'background_color',
|
||||
]
|
||||
),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the "is favorite" switch value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return boolean If the item is favorite or not.
|
||||
*/
|
||||
private static function extractFavorite(array $data): bool
|
||||
{
|
||||
return static::parseBool(
|
||||
static::issetInArray($data, ['is_favourite', 'isFavorite'])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Obtain a container data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console.
|
||||
*
|
||||
* @return self A Visual Console Container instance.
|
||||
* @throws \Exception When the data cannot be retrieved from the DB.
|
||||
*
|
||||
* @override Model::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter)
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$row = \db_get_row_filter('tlayout', $filter);
|
||||
|
||||
if ($row === false) {
|
||||
throw new \Exception('error fetching the data from the DB');
|
||||
}
|
||||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_io.php';
|
||||
include_once $config['homedir'].'/include/functions_ui.php';
|
||||
|
||||
// Clean HTML entities.
|
||||
$row = \io_safe_output($row);
|
||||
|
||||
$row['relationLineWidth'] = (int) $config['vc_line_thickness'];
|
||||
|
||||
$backgroundUrl = static::extractBackgroundUrl($row);
|
||||
$backgroundImage = static::extractBackgroundImage($row);
|
||||
|
||||
if ($backgroundUrl === null && $backgroundImage !== null) {
|
||||
$row['backgroundURL'] = ui_get_full_url(
|
||||
'images/console/background/'.$backgroundImage,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
return \io_safe_output($row);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Obtain a item's class.
|
||||
*
|
||||
* @param integer $type Type of the item of the Visual Console.
|
||||
*
|
||||
* @return mixed A reference to the item's class.
|
||||
*/
|
||||
public static function getItemClass(int $type)
|
||||
{
|
||||
switch ($type) {
|
||||
case STATIC_GRAPH:
|
||||
return Items\StaticGraph::class;
|
||||
|
||||
case MODULE_GRAPH:
|
||||
return Items\ModuleGraph::class;
|
||||
|
||||
case SIMPLE_VALUE:
|
||||
case SIMPLE_VALUE_MAX:
|
||||
case SIMPLE_VALUE_MIN:
|
||||
case SIMPLE_VALUE_AVG:
|
||||
return Items\SimpleValue::class;
|
||||
|
||||
case PERCENTILE_BAR:
|
||||
case PERCENTILE_BUBBLE:
|
||||
case CIRCULAR_PROGRESS_BAR:
|
||||
case CIRCULAR_INTERIOR_PROGRESS_BAR:
|
||||
return Items\Percentile::class;
|
||||
|
||||
case LABEL:
|
||||
return Items\Label::class;
|
||||
|
||||
case ICON:
|
||||
return Items\Icon::class;
|
||||
|
||||
// Enterprise item. It may not exist.
|
||||
case SERVICE:
|
||||
return \class_exists('\Enterprise\Models\VisualConsole\Items\Service') ? \Enterprise\Models\VisualConsole\Items\Service::class : Item::class;
|
||||
|
||||
case GROUP_ITEM:
|
||||
return Items\Group::class;
|
||||
|
||||
case BOX_ITEM:
|
||||
return Items\Box::class;
|
||||
|
||||
case LINE_ITEM:
|
||||
return Items\Line::class;
|
||||
|
||||
case AUTO_SLA_GRAPH:
|
||||
return Items\EventsHistory::class;
|
||||
|
||||
case DONUT_GRAPH:
|
||||
return Items\DonutGraph::class;
|
||||
|
||||
case BARS_GRAPH:
|
||||
return Items\BarsGraph::class;
|
||||
|
||||
case CLOCK:
|
||||
return Items\Clock::class;
|
||||
|
||||
case COLOR_CLOUD:
|
||||
return Items\ColorCloud::class;
|
||||
|
||||
default:
|
||||
return Item::class;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Obtain a list of items which belong to the Visual Console.
|
||||
*
|
||||
* @param integer $layoutId Identifier of the Visual Console.
|
||||
* @param array $groupsFilter Groups can access user.
|
||||
*
|
||||
* @return array A list of items.
|
||||
* @throws \Exception When the data cannot be retrieved from the DB.
|
||||
*/
|
||||
public static function getItemsFromDB(
|
||||
int $layoutId,
|
||||
array $groupsFilter=[]
|
||||
): array {
|
||||
// Default filter.
|
||||
$filter = ['id_layout' => $layoutId];
|
||||
$fields = [
|
||||
'id',
|
||||
'type',
|
||||
];
|
||||
|
||||
// Override the filter if the groups filter is not empty.
|
||||
if (count($groupsFilter) > 0) {
|
||||
// Filter group for elements groups.
|
||||
$filter = [];
|
||||
$filter[] = \db_format_array_where_clause_sql(
|
||||
[
|
||||
'id_layout' => $layoutId,
|
||||
'element_group' => $groupsFilter,
|
||||
]
|
||||
);
|
||||
|
||||
// Filter groups for type groups.
|
||||
// Only true condition if type is GROUP_ITEM.
|
||||
$filter[] = '('.\db_format_array_where_clause_sql(
|
||||
[
|
||||
'type' => GROUP_ITEM,
|
||||
'id_group' => $groupsFilter,
|
||||
]
|
||||
).')';
|
||||
}
|
||||
|
||||
$rows = \db_get_all_rows_filter(
|
||||
'tlayout_data',
|
||||
$filter,
|
||||
$fields,
|
||||
'OR'
|
||||
);
|
||||
|
||||
if ($rows === false) {
|
||||
$rows = [];
|
||||
}
|
||||
|
||||
$items = [];
|
||||
|
||||
foreach ($rows as $data) {
|
||||
$itemId = (int) $data['id'];
|
||||
$itemType = (int) $data['type'];
|
||||
$class = static::getItemClass($itemType);
|
||||
|
||||
try {
|
||||
array_push($items, $class::fromDB(['id' => $itemId]));
|
||||
} catch (\Throwable $e) {
|
||||
// TODO: Log this?
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,346 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a bars graph item of the Visual Console.
|
||||
*/
|
||||
final class BarsGraph extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked module.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedModule = true;
|
||||
|
||||
/**
|
||||
* Used to enable validation, extraction and encodeing of the HTML output.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useHtmlOutput = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = BARS_GRAPH;
|
||||
$return['gridColor'] = $this->extractGridColor($data);
|
||||
$return['backgroundColor'] = $this->extractBackgroundColor($data);
|
||||
$return['typeGraph'] = $this->extractTypeGraph($data);
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a grid color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the grid color (not empty) or null.
|
||||
*/
|
||||
private function extractGridColor(array $data): string
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['gridColor', 'border_color']),
|
||||
'#000000'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a background color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string One of 'white', 'black' or 'transparent'.
|
||||
* 'white' by default.
|
||||
*/
|
||||
private function extractBackgroundColor(array $data): string
|
||||
{
|
||||
$backgroundColor = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['backgroundColor', 'image']),
|
||||
null
|
||||
);
|
||||
|
||||
switch ($backgroundColor) {
|
||||
case 'black':
|
||||
case 'transparent':
|
||||
return $backgroundColor;
|
||||
|
||||
default:
|
||||
return 'white';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a type graph value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string One of 'vertical' or 'horizontal'. 'vertical' by default.
|
||||
*/
|
||||
private function extractTypeGraph(array $data): string
|
||||
{
|
||||
$typeGraph = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['typeGraph', 'type_graph']),
|
||||
null
|
||||
);
|
||||
|
||||
switch ($typeGraph) {
|
||||
case 'horizontal':
|
||||
return 'horizontal';
|
||||
|
||||
default:
|
||||
return 'vertical';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console Item data structure stored into the DB.
|
||||
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
||||
*
|
||||
* @override Item::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$data = parent::fetchDataFromDB($filter);
|
||||
|
||||
/*
|
||||
* Retrieve extra data.
|
||||
*/
|
||||
|
||||
// Load config.
|
||||
global $config;
|
||||
|
||||
// Load side libraries.
|
||||
include_once $config['homedir'].'/include/functions_ui.php';
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
include_once $config['homedir'].'/include/graphs/fgraph.php';
|
||||
|
||||
if (is_metaconsole()) {
|
||||
\enterprise_include_once('include/functions_metaconsole.php');
|
||||
}
|
||||
|
||||
// Extract needed properties.
|
||||
$gridColor = static::extractGridColor($data);
|
||||
$backGroundColor = static::extractBackgroundColor($data);
|
||||
$typeGraph = static::extractTypeGraph($data);
|
||||
|
||||
// Get the linked agent and module Ids.
|
||||
$linkedModule = static::extractLinkedModule($data);
|
||||
$agentId = $linkedModule['agentId'];
|
||||
$moduleId = $linkedModule['moduleId'];
|
||||
$metaconsoleId = $linkedModule['metaconsoleId'];
|
||||
|
||||
if ($agentId === null) {
|
||||
throw new \InvalidArgumentException('missing agent Id');
|
||||
}
|
||||
|
||||
if ($moduleId === null) {
|
||||
throw new \InvalidArgumentException('missing module Id');
|
||||
}
|
||||
|
||||
// Add colors that will use the graphics.
|
||||
$color = [];
|
||||
|
||||
$color[0] = [
|
||||
'border' => '#000000',
|
||||
'color' => $config['graph_color1'],
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[1] = [
|
||||
'border' => '#000000',
|
||||
'color' => $config['graph_color2'],
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[2] = [
|
||||
'border' => '#000000',
|
||||
'color' => $config['graph_color3'],
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[3] = [
|
||||
'border' => '#000000',
|
||||
'color' => $config['graph_color4'],
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[4] = [
|
||||
'border' => '#000000',
|
||||
'color' => $config['graph_color5'],
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[5] = [
|
||||
'border' => '#000000',
|
||||
'color' => $config['graph_color6'],
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[6] = [
|
||||
'border' => '#000000',
|
||||
'color' => $config['graph_color7'],
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[7] = [
|
||||
'border' => '#000000',
|
||||
'color' => $config['graph_color8'],
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[8] = [
|
||||
'border' => '#000000',
|
||||
'color' => $config['graph_color9'],
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[9] = [
|
||||
'border' => '#000000',
|
||||
'color' => $config['graph_color10'],
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[11] = [
|
||||
'border' => '#000000',
|
||||
'color' => COL_GRAPH9,
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[12] = [
|
||||
'border' => '#000000',
|
||||
'color' => COL_GRAPH10,
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[13] = [
|
||||
'border' => '#000000',
|
||||
'color' => COL_GRAPH11,
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[14] = [
|
||||
'border' => '#000000',
|
||||
'color' => COL_GRAPH12,
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
$color[15] = [
|
||||
'border' => '#000000',
|
||||
'color' => COL_GRAPH13,
|
||||
'alpha' => CHART_DEFAULT_ALPHA,
|
||||
];
|
||||
|
||||
// Maybe connect to node.
|
||||
$nodeConnected = false;
|
||||
if (\is_metaconsole() === true && $metaconsoleId !== null) {
|
||||
$nodeConnected = \metaconsole_connect(
|
||||
null,
|
||||
$metaconsoleId
|
||||
) === NOERR;
|
||||
|
||||
if ($nodeConnected === false) {
|
||||
throw new \InvalidArgumentException(
|
||||
'error connecting to the node'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$moduleData = \get_bars_module_data($moduleId);
|
||||
|
||||
$waterMark = [
|
||||
'file' => $config['homedir'].'/images/logo_vertical_water.png',
|
||||
'url' => \ui_get_full_url(
|
||||
'images/logo_vertical_water.png',
|
||||
false,
|
||||
false,
|
||||
false
|
||||
),
|
||||
];
|
||||
|
||||
if ((int) $data['width'] === 0 || (int) $data['height'] === 0) {
|
||||
$width = 400;
|
||||
$height = 400;
|
||||
} else {
|
||||
$width = (int) $data['width'];
|
||||
$height = (int) $data['height'];
|
||||
}
|
||||
|
||||
if ($typeGraph === 'horizontal') {
|
||||
$graph = \hbar_graph(
|
||||
$moduleData,
|
||||
$width,
|
||||
$height,
|
||||
$color,
|
||||
[],
|
||||
[],
|
||||
\ui_get_full_url(
|
||||
'images/image_problem_area.png',
|
||||
false,
|
||||
false,
|
||||
false
|
||||
),
|
||||
'',
|
||||
'',
|
||||
$waterMark,
|
||||
$config['fontpath'],
|
||||
6,
|
||||
'',
|
||||
0,
|
||||
$config['homeurl'],
|
||||
$backGroundColor,
|
||||
$gridColor
|
||||
);
|
||||
} else {
|
||||
$graph = \vbar_graph(
|
||||
$moduleData,
|
||||
$width,
|
||||
$height,
|
||||
$color,
|
||||
[],
|
||||
[],
|
||||
\ui_get_full_url(
|
||||
'images/image_problem_area.png',
|
||||
false,
|
||||
false,
|
||||
false
|
||||
),
|
||||
'',
|
||||
'',
|
||||
$waterMark,
|
||||
$config['fontpath'],
|
||||
6,
|
||||
'',
|
||||
0,
|
||||
$config['homeurl'],
|
||||
$backGroundColor,
|
||||
true,
|
||||
false,
|
||||
$gridColor
|
||||
);
|
||||
}
|
||||
|
||||
// Restore connection.
|
||||
if ($nodeConnected === true) {
|
||||
\metaconsole_restore_db();
|
||||
}
|
||||
|
||||
$data['html'] = $graph;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a Box item of the Visual Console.
|
||||
*/
|
||||
final class Box extends Item
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$boxData = parent::decode($data);
|
||||
$boxData['type'] = BOX_ITEM;
|
||||
$boxData['parentId'] = null;
|
||||
$boxData['aclGroupId'] = null;
|
||||
$boxData['borderWidth'] = $this->extractBorderWidth($data);
|
||||
$boxData['borderColor'] = $this->extractBorderColor($data);
|
||||
$boxData['fillColor'] = $this->extractFillColor($data);
|
||||
return $boxData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a border width value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return integer Valid border width. 0 by default.
|
||||
*/
|
||||
private function extractBorderWidth(array $data): int
|
||||
{
|
||||
return static::parseIntOr(
|
||||
static::issetInArray($data, ['borderWidth', 'border_width']),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a border color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the border color (not empty) or null.
|
||||
*/
|
||||
private function extractBorderColor(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['borderColor', 'border_color']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a fill color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the fill color (not empty) or null.
|
||||
*/
|
||||
private function extractFillColor(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['fillColor', 'fill_color']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a clock item of the Visual Console.
|
||||
*/
|
||||
final class Clock extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
* @throws \InvalidArgumentException When there is a problem with
|
||||
* the time management.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$clockData = parent::decode($data);
|
||||
$clockData['type'] = CLOCK;
|
||||
$clockData['clockType'] = static::extractClockType($data);
|
||||
$clockData['clockFormat'] = static::extractClockFormat($data);
|
||||
$clockData['clockTimezone'] = static::extractClockTimezone($data);
|
||||
|
||||
try {
|
||||
$timezone = new \DateTimeZone($clockData['clockTimezone']);
|
||||
$timezoneUTC = new \DateTimeZone('UTC');
|
||||
$dateTimeUtc = new \DateTime('now', $timezoneUTC);
|
||||
$clockData['clockTimezoneOffset'] = $timezone->getOffset(
|
||||
$dateTimeUtc
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
throw new \InvalidArgumentException($e->getMessage());
|
||||
}
|
||||
|
||||
// $clockData['showClockTimezone'] = static::parseBool(
|
||||
// static::issetInArray($data, ['showClockTimezone'])
|
||||
// );
|
||||
// TODO: Remove the true by default when added into the editor.
|
||||
$clockData['showClockTimezone'] = true;
|
||||
$clockData['color'] = static::extractColor($data);
|
||||
return $clockData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a clock type value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string One of 'digital' or 'analogic'. 'analogic' by default.
|
||||
*/
|
||||
private static function extractClockType(array $data): string
|
||||
{
|
||||
$clockType = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['clockType', 'clock_animation']),
|
||||
null
|
||||
);
|
||||
|
||||
switch ($clockType) {
|
||||
case 'digital':
|
||||
case 'digital_1':
|
||||
return 'digital';
|
||||
|
||||
default:
|
||||
return 'analogic';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a clock format value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string One of 'time' or 'datetime'. 'datetime' by default.
|
||||
*/
|
||||
private static function extractClockFormat(array $data): string
|
||||
{
|
||||
$clockFormat = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['clockFormat', 'time_format']),
|
||||
null
|
||||
);
|
||||
|
||||
switch ($clockFormat) {
|
||||
case 'time':
|
||||
return 'time';
|
||||
|
||||
default:
|
||||
return 'datetime';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a clock timezone value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string
|
||||
* @throws \InvalidArgumentException When a valid clock timezone cannot be
|
||||
* extracted.
|
||||
*/
|
||||
private static function extractClockTimezone(array $data): string
|
||||
{
|
||||
$clockTimezone = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['clockTimezone', 'timezone']),
|
||||
null
|
||||
);
|
||||
|
||||
if ($clockTimezone === null) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the clockTimezone property is required and should be string'
|
||||
);
|
||||
}
|
||||
|
||||
return $clockTimezone;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed returns a color or null.
|
||||
*/
|
||||
private static function extractColor(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['color', 'fill_color']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,281 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a color cloud item of the Visual Console.
|
||||
*/
|
||||
final class ColorCloud extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked module.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedModule = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item->decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$decodedData = parent::decode($data);
|
||||
$decodedData['type'] = COLOR_CLOUD;
|
||||
$decodedData['label'] = null;
|
||||
$decodedData['defaultColor'] = static::extractDefaultColor($data);
|
||||
$decodedData['colorRanges'] = static::extractColorRanges($data);
|
||||
$decodedData['color'] = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['color']),
|
||||
null
|
||||
);
|
||||
|
||||
return $decodedData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the default color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string Default color.
|
||||
* @throws \InvalidArgumentException If the default color cannot be
|
||||
* extracted.
|
||||
*/
|
||||
private static function extractDefaultColor(array $data): string
|
||||
{
|
||||
if (isset($data['defaultColor'])) {
|
||||
$defaultColor = static::notEmptyStringOr(
|
||||
$data['defaultColor'],
|
||||
null
|
||||
);
|
||||
|
||||
if ($defaultColor === null) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the default color property is required and should be a not empty string'
|
||||
);
|
||||
}
|
||||
|
||||
return $defaultColor;
|
||||
} else {
|
||||
$dynamicData = static::extractDynamicData($data);
|
||||
return $dynamicData['defaultColor'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a list of color ranges.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return array Color ranges list.
|
||||
* @throws \InvalidArgumentException If any of the color ranges is invalid.
|
||||
*/
|
||||
private static function extractColorRanges(array $data): array
|
||||
{
|
||||
if (isset($data['colorRanges']) && \is_array($data['colorRanges'])) {
|
||||
// Validate the color ranges.
|
||||
foreach ($data['colorRanges'] as $colorRange) {
|
||||
if (\is_numeric($colorRange['fromValue']) === false
|
||||
|| \is_numeric($colorRange['toValue']) === false
|
||||
|| static::notEmptyStringOr($colorRange['color'], null) === null
|
||||
) {
|
||||
throw new \InvalidArgumentException('invalid color range');
|
||||
}
|
||||
}
|
||||
|
||||
return $data['colorRanges'];
|
||||
} else if (isset($data['label']) === true) {
|
||||
$dynamicData = static::extractDynamicData($data);
|
||||
return $dynamicData['colorRanges'];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a dynamic data structure from the 'label' field.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return array Dynamic data structure.
|
||||
* @throws \InvalidArgumentException If the structure cannot be built.
|
||||
*
|
||||
* @example [
|
||||
* 'defaultColor' => '#FFF',
|
||||
* 'colorRanges' => [
|
||||
* [
|
||||
* 'fromValue' => 50.0,
|
||||
* 'toValue' => 150.5,
|
||||
* 'color' => '#000',
|
||||
* ],
|
||||
* [
|
||||
* 'fromValue' => 200.0,
|
||||
* 'toValue' => 300.5,
|
||||
* 'color' => '#F0F0F0',
|
||||
* ],
|
||||
* ]
|
||||
* ]
|
||||
*/
|
||||
private static function extractDynamicData(array $data): array
|
||||
{
|
||||
$dynamicDataEncoded = static::notEmptyStringOr($data['label'], null);
|
||||
|
||||
if ($dynamicDataEncoded === null) {
|
||||
throw new \InvalidArgumentException('dynamic data not found');
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
try {
|
||||
$dynamicData = \json_decode($dynamicDataEncoded, true);
|
||||
|
||||
$result['defaultColor'] = $dynamicData['default_color'];
|
||||
$result['colorRanges'] = [];
|
||||
|
||||
if (\is_array($dynamicData['color_ranges']) === true) {
|
||||
foreach ($dynamicData['color_ranges'] as $colorRange) {
|
||||
if (\is_numeric($colorRange['from_value']) === true
|
||||
&& \is_numeric($colorRange['to_value']) === true
|
||||
&& static::notEmptyStringOr(
|
||||
$colorRange['color'],
|
||||
null
|
||||
) !== null
|
||||
) {
|
||||
$result['colorRanges'][] = [
|
||||
'color' => $colorRange['color'],
|
||||
'fromValue' => (float) $colorRange['from_value'],
|
||||
'toValue' => (float) $colorRange['to_value'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
throw new \InvalidArgumentException('invalid dynamic data');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console Item data structure stored into the DB.
|
||||
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
||||
*
|
||||
* @override Item::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$data = parent::fetchDataFromDB($filter);
|
||||
|
||||
/*
|
||||
* Retrieve extra data.
|
||||
*/
|
||||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_modules.php';
|
||||
if (is_metaconsole()) {
|
||||
\enterprise_include_once('include/functions_metaconsole.php');
|
||||
}
|
||||
|
||||
// Get the linked module Id.
|
||||
$linkedModule = static::extractLinkedModule($data);
|
||||
$moduleId = $linkedModule['moduleId'];
|
||||
$metaconsoleId = $linkedModule['metaconsoleId'];
|
||||
|
||||
if ($moduleId === null) {
|
||||
throw new \InvalidArgumentException('missing module Id');
|
||||
}
|
||||
|
||||
$dynamicData = static::extractDynamicData($data);
|
||||
// Set the initial color.
|
||||
$data['color'] = $dynamicData['defaultColor'];
|
||||
|
||||
// Search for a matching color range.
|
||||
if (empty($dynamicData['colorRanges']) === false) {
|
||||
// Connect to node.
|
||||
$nodeConnected = false;
|
||||
if (\is_metaconsole() === true && $metaconsoleId !== null) {
|
||||
$nodeConnected = \metaconsole_connect(
|
||||
null,
|
||||
$metaconsoleId
|
||||
) === NOERR;
|
||||
|
||||
if ($nodeConnected === false) {
|
||||
throw new \InvalidArgumentException(
|
||||
'error connecting to the node'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch module value.
|
||||
$value = false;
|
||||
if ($metaconsoleId === null
|
||||
|| ($metaconsoleId !== null && $nodeConnected)
|
||||
) {
|
||||
$value = \modules_get_last_value($moduleId);
|
||||
}
|
||||
|
||||
// Restore connection.
|
||||
if ($nodeConnected === true) {
|
||||
\metaconsole_restore_db();
|
||||
}
|
||||
|
||||
// Value found.
|
||||
if ($value !== false) {
|
||||
/*
|
||||
* TODO: It would be ok to give support to string values in the
|
||||
* future?
|
||||
*
|
||||
* It can be done by matching the range value with the value
|
||||
* if it is a string. I think the function to retrieve the value
|
||||
* only supports numeric values.
|
||||
*/
|
||||
|
||||
$value = (float) $value;
|
||||
foreach ($dynamicData['colorRanges'] as $colorRange) {
|
||||
if ($colorRange['fromValue'] <= $value
|
||||
&& $colorRange['toValue'] >= $value
|
||||
) {
|
||||
// Range matched. Use the range color.
|
||||
$data['color'] = $colorRange['color'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a Donut Graph item of the Visual Console.
|
||||
*/
|
||||
final class DonutGraph extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked module.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedModule = true;
|
||||
|
||||
/**
|
||||
* Used to enable validation, extraction and encodeing of the HTML output.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useHtmlOutput = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = DONUT_GRAPH;
|
||||
$return['legendBackgroundColor'] = static::extractLegendBackgroundColor(
|
||||
$data
|
||||
);
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a border color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the border color (not empty) or null.
|
||||
*/
|
||||
private static function extractLegendBackgroundColor(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray(
|
||||
$data,
|
||||
[
|
||||
'legendBackgroundColor',
|
||||
'border_color',
|
||||
]
|
||||
),
|
||||
'#000000'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console Item data structure stored into the DB.
|
||||
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
||||
*
|
||||
* @override Item::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$data = parent::fetchDataFromDB($filter);
|
||||
|
||||
/*
|
||||
* Retrieve extra data.
|
||||
*/
|
||||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
include_once $config['homedir'].'/include/graphs/functions_d3.php';
|
||||
if (is_metaconsole()) {
|
||||
\enterprise_include_once('include/functions_metaconsole.php');
|
||||
}
|
||||
|
||||
// Extract needed properties.
|
||||
$legendBackGroundColor = static::extractLegendBackgroundColor($data);
|
||||
// Get the linked agent and module Ids.
|
||||
$linkedModule = static::extractLinkedModule($data);
|
||||
$agentId = $linkedModule['agentId'];
|
||||
$moduleId = $linkedModule['moduleId'];
|
||||
$metaconsoleId = $linkedModule['metaconsoleId'];
|
||||
|
||||
if ($agentId === null) {
|
||||
throw new \InvalidArgumentException('missing agent Id');
|
||||
}
|
||||
|
||||
if ($moduleId === null) {
|
||||
throw new \InvalidArgumentException('missing module Id');
|
||||
}
|
||||
|
||||
// Maybe connect to node.
|
||||
$nodeConnected = false;
|
||||
if (\is_metaconsole() === true && $metaconsoleId !== null) {
|
||||
$nodeConnected = \metaconsole_connect(
|
||||
null,
|
||||
$metaconsoleId
|
||||
) === NOERR;
|
||||
|
||||
if ($nodeConnected === false) {
|
||||
throw new \InvalidArgumentException(
|
||||
'error connecting to the node'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT COUNT(tam.id_agente_modulo)
|
||||
FROM tagente_modulo tam
|
||||
INNER JOIN ttipo_modulo ttm
|
||||
ON tam.id_tipo_modulo = ttm.id_tipo
|
||||
WHERE tam.id_agente = %d
|
||||
AND tam.id_agente_modulo = %d
|
||||
AND ttm.nombre LIKE \'%%_string\'',
|
||||
$agentId,
|
||||
$moduleId
|
||||
);
|
||||
$isString = (bool) \db_get_value_sql($sql);
|
||||
|
||||
// Restore connection.
|
||||
if ($nodeConnected === true) {
|
||||
\metaconsole_restore_db();
|
||||
}
|
||||
|
||||
if ($isString === true) {
|
||||
$graphData = \get_donut_module_data($moduleId);
|
||||
|
||||
$width = (int) $data['width'];
|
||||
$height = (int) $data['height'];
|
||||
|
||||
// Default width.
|
||||
if ($width <= 0) {
|
||||
$width = 300;
|
||||
}
|
||||
|
||||
// Default height.
|
||||
if ($height <= 0) {
|
||||
$height = 300;
|
||||
}
|
||||
|
||||
$data['html'] = \d3_donut_graph(
|
||||
(int) $data['id'],
|
||||
$width,
|
||||
$height,
|
||||
$graphData,
|
||||
$legendBackGroundColor
|
||||
);
|
||||
} else {
|
||||
$src = 'images/console/signes/wrong_donut_graph.png';
|
||||
if (\is_metaconsole() === true && $metaconsoleId !== null) {
|
||||
$src = '../../'.$src;
|
||||
}
|
||||
|
||||
$data['html'] = '<img src="'.$src.'">';
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a events history item of the Visual Console.
|
||||
*/
|
||||
final class EventsHistory extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked module.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedModule = true;
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
/**
|
||||
* Used to enable validation, extraction and encodeing of the HTML output.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useHtmlOutput = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = AUTO_SLA_GRAPH;
|
||||
$return['maxTime'] = static::extractMaxTime($data);
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a graph period value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed The time in seconds of the graph period or null.
|
||||
*/
|
||||
private static function extractMaxTime(array $data)
|
||||
{
|
||||
return static::parseIntOr(
|
||||
static::issetInArray($data, ['maxTime', 'period']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console Item data structure stored into the DB.
|
||||
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
||||
*
|
||||
* @override Item::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$data = parent::fetchDataFromDB($filter);
|
||||
|
||||
/*
|
||||
* Retrieve extra data.
|
||||
*/
|
||||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_graph.php';
|
||||
|
||||
// Get the linked agent and module Ids.
|
||||
$linkedModule = static::extractLinkedModule($data);
|
||||
$agentId = static::parseIntOr($linkedModule['agentId'], null);
|
||||
$moduleId = static::parseIntOr($linkedModule['moduleId'], null);
|
||||
|
||||
if ($agentId === null) {
|
||||
throw new \InvalidArgumentException('missing agent Id');
|
||||
}
|
||||
|
||||
// Default size.
|
||||
if ($data['width'] == 0 || $data['height'] == 0) {
|
||||
$data['width'] = 500;
|
||||
$data['height'] = 50;
|
||||
}
|
||||
|
||||
// Use the same HTML output as the old VC.
|
||||
$html = \graph_graphic_moduleevents(
|
||||
$agentId,
|
||||
$moduleId,
|
||||
(int) $data['width'],
|
||||
(int) $data['height'],
|
||||
static::extractMaxTime($data),
|
||||
'',
|
||||
true
|
||||
);
|
||||
|
||||
$data['html'] = $html;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,455 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a group item of the Visual Console.
|
||||
*/
|
||||
final class Group extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
/**
|
||||
* Enable the validation, extraction and encoding of HTML output.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useHtmlOutput = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = GROUP_ITEM;
|
||||
$return['groupId'] = static::extractGroupId($data);
|
||||
$return['imageSrc'] = static::extractImageSrc($data);
|
||||
$return['statusImageSrc'] = static::extractStatusImageSrc($data);
|
||||
$return['showStatistics'] = static::extractShowStatistics($data);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a group Id value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return integer Valid identifier of a group.
|
||||
*
|
||||
* @throws \InvalidArgumentException When a valid group Id can't be found.
|
||||
*/
|
||||
private static function extractGroupId(array $data): int
|
||||
{
|
||||
$groupId = static::parseIntOr(
|
||||
static::issetInArray($data, ['groupId', 'id_group']),
|
||||
null
|
||||
);
|
||||
|
||||
if ($groupId === null || $groupId < 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the group Id property is required and should be integer'
|
||||
);
|
||||
}
|
||||
|
||||
return $groupId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a image src value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the image url (not empty) or null.
|
||||
*/
|
||||
private static function extractImageSrc(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['imageSrc', 'image']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a status image src value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the status image url (not empty)
|
||||
* or null.
|
||||
*/
|
||||
private static function extractStatusImageSrc(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['statusImageSrc']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the "show statistics" switch value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return boolean If the statistics should be shown or not.
|
||||
*/
|
||||
private static function extractShowStatistics(array $data): bool
|
||||
{
|
||||
return static::parseBool(
|
||||
static::issetInArray($data, ['showStatistics', 'show_statistics'])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console Item data structure stored into the DB.
|
||||
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
||||
*
|
||||
* @override Item::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$data = parent::fetchDataFromDB($filter);
|
||||
|
||||
/*
|
||||
* Retrieve extra data.
|
||||
*/
|
||||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_groups.php';
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
include_once $config['homedir'].'/include/functions_ui.php';
|
||||
include_once $config['homedir'].'/include/functions_agents.php';
|
||||
include_once $config['homedir'].'/include/functions_users.php';
|
||||
if (is_metaconsole()) {
|
||||
\enterprise_include_once('include/functions_metaconsole.php');
|
||||
}
|
||||
|
||||
$groupId = static::extractGroupId($data);
|
||||
$showStatistics = static::extractShowStatistics($data);
|
||||
|
||||
if ($showStatistics === true) {
|
||||
$isMetaconsole = \is_metaconsole();
|
||||
// Retrieve the agent stats.
|
||||
$agentsCritical = \agents_get_agents(
|
||||
[
|
||||
'id_grupo' => $groupId,
|
||||
'status' => AGENT_STATUS_CRITICAL,
|
||||
],
|
||||
['COUNT(*) AS total'],
|
||||
'AR',
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
$isMetaconsole
|
||||
);
|
||||
$numCritical = $agentsCritical[0]['total'];
|
||||
$agentsWarning = \agents_get_agents(
|
||||
[
|
||||
'id_grupo' => $groupId,
|
||||
'status' => AGENT_STATUS_WARNING,
|
||||
],
|
||||
['COUNT(*) AS total'],
|
||||
'AR',
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
$isMetaconsole
|
||||
);
|
||||
$numWarning = $agentsWarning[0]['total'];
|
||||
$agentsUnknown = \agents_get_agents(
|
||||
[
|
||||
'id_grupo' => $groupId,
|
||||
'status' => AGENT_STATUS_UNKNOWN,
|
||||
],
|
||||
['COUNT(*) AS total'],
|
||||
'AR',
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
$isMetaconsole
|
||||
);
|
||||
$numUnknown = $agentsUnknown[0]['total'];
|
||||
$agentsOk = \agents_get_agents(
|
||||
[
|
||||
'id_grupo' => $groupId,
|
||||
'status' => AGENT_STATUS_OK,
|
||||
],
|
||||
['COUNT(*) AS total'],
|
||||
'AR',
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
$isMetaconsole
|
||||
);
|
||||
$numNormal = $agentsOk[0]['total'];
|
||||
|
||||
$numTotal = ($numCritical + $numWarning + $numUnknown + $numNormal);
|
||||
$agentStats = [
|
||||
'critical' => ($numCritical / $numTotal * 100),
|
||||
'warning' => ($numWarning / $numTotal * 100),
|
||||
'normal' => ($numNormal / $numTotal * 100),
|
||||
'unknown' => ($numUnknown / $numTotal * 100),
|
||||
];
|
||||
|
||||
$groupName = \groups_get_name($groupId, true);
|
||||
$data['html'] = static::printStatsTable(
|
||||
$groupName,
|
||||
$agentStats,
|
||||
(int) $data['width'],
|
||||
(int) $data['height']
|
||||
);
|
||||
} else {
|
||||
if (\is_metaconsole()) {
|
||||
$groupFilter = $groupId;
|
||||
if ($groupId === 0) {
|
||||
$groupFilter = implode(
|
||||
',',
|
||||
array_keys(\users_get_groups())
|
||||
);
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT
|
||||
SUM(fired_count) AS fired,
|
||||
SUM(critical_count) AS critical,
|
||||
SUM(warning_count) AS warning,
|
||||
SUM(unknown_count) AS unknown
|
||||
FROM tmetaconsole_agent
|
||||
LEFT JOIN tmetaconsole_agent_secondary_group tasg
|
||||
ON id_agente = tasg.id_agent
|
||||
WHERE id_grupo IN (%s)
|
||||
OR tasg.id_group IN (%s)',
|
||||
$groupFilter,
|
||||
$groupFilter
|
||||
);
|
||||
|
||||
$countStatus = \db_get_row_sql($sql);
|
||||
|
||||
if ($countStatus['fired'] > 0) {
|
||||
$status = AGENT_STATUS_ALERT_FIRED;
|
||||
} else if ($countStatus['critical'] > 0) {
|
||||
$status = AGENT_STATUS_CRITICAL;
|
||||
} else if ($countStatus['warning'] > 0) {
|
||||
$status = AGENT_STATUS_WARNING;
|
||||
} else if ($countStatus['unknown'] > 0) {
|
||||
$status = AGENT_STATUS_UNKNOWN;
|
||||
} else {
|
||||
$status = AGENT_STATUS_NORMAL;
|
||||
}
|
||||
} else {
|
||||
// Get the status img src.
|
||||
$status = \groups_get_status($groupId);
|
||||
}
|
||||
|
||||
$imagePath = \visual_map_get_image_status_element($data, $status);
|
||||
$data['statusImageSrc'] = \ui_get_full_url(
|
||||
$imagePath,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
// If the width or the height are equal to 0 we will extract them
|
||||
// from the real image size.
|
||||
$width = (int) $data['width'];
|
||||
$height = (int) $data['height'];
|
||||
if ($width === 0 || $height === 0) {
|
||||
// TODO: This will be the default behaviour after we finish the
|
||||
// builder. Don't delete this code.
|
||||
// $sizeImage = getimagesize($config['homedir'].'/'.$imagePath);
|
||||
// $data['width'] = $sizeImage[0];
|
||||
// $data['height'] = $sizeImage[1];
|
||||
$sizeImage = getimagesize($config['homedir'].'/'.$imagePath);
|
||||
$imageHeight = $sizeImage[1];
|
||||
|
||||
if ($width === 0) {
|
||||
$data['width'] = 70;
|
||||
}
|
||||
|
||||
if ($height === 0) {
|
||||
$data['height'] = ($imageHeight > 70) ? 70 : $imageHeight;
|
||||
}
|
||||
}
|
||||
|
||||
$data['html'] = '<img src="'.$data['statusImageSrc'].'">';
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* HTML representation for the agent stats of a group.
|
||||
*
|
||||
* @param string $groupName Group name.
|
||||
* @param array $agentStats Data structure with the agent statistics.
|
||||
* @param integer $width Width.
|
||||
* @param integer $height Height.
|
||||
*
|
||||
* @return string HTML representation.
|
||||
*/
|
||||
private static function printStatsTable(
|
||||
string $groupName,
|
||||
array $agentStats,
|
||||
int $width=520,
|
||||
int $height=80
|
||||
): string {
|
||||
$width = ($width > 0) ? $width : 520;
|
||||
$height = ($height > 0) ? $height : 80;
|
||||
|
||||
$tableStyle = \join(
|
||||
[
|
||||
'width:'.$width.'px;',
|
||||
'height:'.$height.'px;',
|
||||
'text-align:center;',
|
||||
]
|
||||
);
|
||||
$headStyle = \join(
|
||||
[
|
||||
'text-align:center;',
|
||||
'background-color:#9d9ea0;',
|
||||
'color:black;',
|
||||
'font-weight:bold;',
|
||||
]
|
||||
);
|
||||
$valueStyle = \join(
|
||||
[
|
||||
'margin-left: 2%;',
|
||||
'color: #FFF;',
|
||||
'font-size: 12px;',
|
||||
'display: inline;',
|
||||
'background-color: #FC4444;',
|
||||
'position: relative;',
|
||||
'height: 80%;',
|
||||
'width: 9.4%;',
|
||||
'height: 80%;',
|
||||
'border-radius: 2px;',
|
||||
'text-align: center;',
|
||||
'padding: 5px;',
|
||||
]
|
||||
);
|
||||
$nameStyle = \join(
|
||||
[
|
||||
'background-color: white;',
|
||||
'color: black;',
|
||||
'font-size: 12px;',
|
||||
'display: inline;',
|
||||
'display: inline;',
|
||||
'position:relative;',
|
||||
'width: 9.4%;',
|
||||
'height: 80%;',
|
||||
'border-radius: 2px;',
|
||||
'text-align: center;',
|
||||
'padding: 5px;',
|
||||
]
|
||||
);
|
||||
|
||||
$html = '<table class="databox" style="'.$tableStyle.'">';
|
||||
$html .= '<tr style="height:10%;">';
|
||||
$html .= '<th style="'.$headStyle.'">'.$groupName.'</th>';
|
||||
$html .= '</tr>';
|
||||
$html .= '<tr style="background-color:whitesmoke;height:90%;">';
|
||||
$html .= '<td>';
|
||||
|
||||
// Critical.
|
||||
$html .= '<div style="'.$valueStyle.'background-color: #FC4444;">';
|
||||
$html .= \number_format($agentStats['critical']).'%';
|
||||
$html .= '</div>';
|
||||
$html .= '<div style="'.$nameStyle.'">'.__('Critical').'</div>';
|
||||
// Warning.
|
||||
$html .= '<div style="'.$valueStyle.'background-color: #f8db3f;">';
|
||||
$html .= \number_format($agentStats['warning']).'%';
|
||||
$html .= '</div>';
|
||||
$html .= '<div style="'.$nameStyle.'">'.__('Warning').'</div>';
|
||||
// Normal.
|
||||
$html .= '<div style="'.$valueStyle.'background-color: #84b83c;">';
|
||||
$html .= \number_format($agentStats['normal']).'%';
|
||||
$html .= '</div>';
|
||||
$html .= '<div style="'.$nameStyle.'">'.__('Normal').'</div>';
|
||||
// Unknown.
|
||||
$html .= '<div style="'.$valueStyle.'background-color: #9d9ea0;">';
|
||||
$html .= \number_format($agentStats['unknown']).'%';
|
||||
$html .= '</div>';
|
||||
$html .= '<div style="'.$nameStyle.'">'.__('Unknown').'</div>';
|
||||
|
||||
$html .= '</td>';
|
||||
$html .= '</tr>';
|
||||
$html .= '</table>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a link to something related with the item.
|
||||
*
|
||||
* @param array $data Visual Console Item's data structure.
|
||||
*
|
||||
* @return mixed The link or a null value.
|
||||
*
|
||||
* @override Item::buildLink.
|
||||
*/
|
||||
protected static function buildLink(array $data)
|
||||
{
|
||||
// This will return the link to a linked VC if this item has one.
|
||||
$link = parent::buildLink($data);
|
||||
if ($link !== null) {
|
||||
return $link;
|
||||
}
|
||||
|
||||
global $config;
|
||||
|
||||
$groupId = static::extractGroupId($data);
|
||||
$baseUrl = $config['homeurl'].'index.php';
|
||||
|
||||
if (\is_metaconsole()) {
|
||||
return $baseUrl.'?'.http_build_query(
|
||||
[
|
||||
'sec' => 'monitoring',
|
||||
'sec2' => 'operation/tree',
|
||||
'group_id' => $groupId,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return $baseUrl.'?'.http_build_query(
|
||||
[
|
||||
'sec' => 'estado',
|
||||
'sec2' => 'operation/agentes/estado_agente',
|
||||
'group_id' => $groupId,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a group item of the Visual Console.
|
||||
*/
|
||||
final class Icon extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = ICON;
|
||||
$return['image'] = static::extractImage($data);
|
||||
$return['imageSrc'] = static::extractImageSrc($data);
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a image value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the image url (not empty) or null.
|
||||
*
|
||||
* @throws \InvalidArgumentException When a valid image can't be found.
|
||||
*/
|
||||
private static function extractImage(array $data)
|
||||
{
|
||||
$image = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['image']),
|
||||
null
|
||||
);
|
||||
|
||||
if ($image === null) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the image property is required and should be a non empty string'
|
||||
);
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a image src value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the image url (not empty) or null.
|
||||
*
|
||||
* @throws \InvalidArgumentException When a valid image src can't be found.
|
||||
*/
|
||||
private static function extractImageSrc(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['imageSrc']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// 'images/console/icons/'.$imageSrc.'.png'
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console Item data structure stored into the DB.
|
||||
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
||||
*
|
||||
* @override Item::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$data = parent::fetchDataFromDB($filter);
|
||||
|
||||
/*
|
||||
* Retrieve extra data.
|
||||
*/
|
||||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_ui.php';
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
|
||||
// Get the img src.
|
||||
$imagePath = \visual_map_get_image_status_element($data);
|
||||
$data['imageSrc'] = \ui_get_full_url($imagePath, false, false, false);
|
||||
|
||||
// If the width or the height are equal to 0 we will extract them
|
||||
// from the real image size.
|
||||
$width = (int) $data['width'];
|
||||
$height = (int) $data['height'];
|
||||
if ($width === 0 || $height === 0) {
|
||||
// TODO: This will be the default behaviour after we finish the
|
||||
// builder. Don't delete this code.
|
||||
// $sizeImage = getimagesize($config['homedir'].'/'.$imagePath);
|
||||
// $data['width'] = $sizeImage[0];
|
||||
// $data['height'] = $sizeImage[1];
|
||||
$sizeImage = getimagesize($config['homedir'].'/'.$imagePath);
|
||||
$imageHeight = $sizeImage[1];
|
||||
|
||||
if ($width === 0) {
|
||||
$data['width'] = 70;
|
||||
}
|
||||
|
||||
if ($height === 0) {
|
||||
$data['height'] = ($imageHeight > 70) ? 70 : $imageHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a label item of the Visual Console.
|
||||
*/
|
||||
final class Label extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
|
||||
/**
|
||||
* Validate the received data structure to ensure if we can extract the
|
||||
* values required to build the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException If any input value is considered
|
||||
* invalid.
|
||||
*
|
||||
* @overrides Item->validateData.
|
||||
*/
|
||||
protected function validateData(array $data): void
|
||||
{
|
||||
parent::validateData($data);
|
||||
if (static::notEmptyStringOr(static::issetInArray($data, ['label']), null) === null) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the label property is required and should be a not empty string'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item->decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = LABEL;
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\Model;
|
||||
|
||||
/**
|
||||
* Model of a line item of the Visual Console.
|
||||
*/
|
||||
final class Line extends Model
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Validate the received data structure to ensure if we can extract the
|
||||
* values required to build the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return void
|
||||
* @throws \InvalidArgumentException If any input value is considered
|
||||
* invalid.
|
||||
*
|
||||
* @overrides Model->validateData.
|
||||
*/
|
||||
protected function validateData(array $data): void
|
||||
{
|
||||
if (isset($data['id']) === false
|
||||
|| \is_numeric($data['id']) === false
|
||||
) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the Id property is required and should be integer'
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($data['type']) === false
|
||||
|| \is_numeric($data['type']) === false
|
||||
) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the Id property is required and should be integer'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Model->decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) $data['id'],
|
||||
'type' => LINE_ITEM,
|
||||
'startX' => static::extractStartX($data),
|
||||
'startY' => static::extractStartY($data),
|
||||
'endX' => static::extractEndX($data),
|
||||
'endY' => static::extractEndY($data),
|
||||
'isOnTop' => static::extractIsOnTop($data),
|
||||
'borderWidth' => static::extractBorderWidth($data),
|
||||
'borderColor' => static::extractBorderColor($data),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a x axis value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return integer Valid x axis of the start position of the line.
|
||||
*/
|
||||
private static function extractStartX(array $data): int
|
||||
{
|
||||
return static::parseIntOr(
|
||||
static::issetInArray($data, ['startX', 'pos_x']),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a y axis value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return integer Valid y axis of the start position of the line.
|
||||
*/
|
||||
private static function extractStartY(array $data): int
|
||||
{
|
||||
return static::parseIntOr(
|
||||
static::issetInArray($data, ['startY', 'pos_y']),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a x axis value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return integer Valid x axis of the end position of the line.
|
||||
*/
|
||||
private static function extractEndX(array $data): int
|
||||
{
|
||||
return static::parseIntOr(
|
||||
static::issetInArray($data, ['endX', 'width']),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a y axis value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return integer Valid y axis of the end position of the line.
|
||||
*/
|
||||
private static function extractEndY(array $data): int
|
||||
{
|
||||
return static::parseIntOr(
|
||||
static::issetInArray($data, ['endY', 'height']),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a conditional value which tells if the item has visual priority.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return boolean If the item is on top or not.
|
||||
*/
|
||||
private static function extractIsOnTop(array $data): bool
|
||||
{
|
||||
return static::parseBool(
|
||||
static::issetInArray($data, ['isOnTop', 'show_on_top'])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a border width value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return integer Valid border width. 0 by default and minimum value.
|
||||
*/
|
||||
private static function extractBorderWidth(array $data): int
|
||||
{
|
||||
$borderWidth = static::parseIntOr(
|
||||
static::issetInArray($data, ['borderWidth', 'border_width']),
|
||||
0
|
||||
);
|
||||
|
||||
return ($borderWidth >= 0) ? $borderWidth : 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a border color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the border color (not empty) or null.
|
||||
*/
|
||||
private static function extractBorderColor(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['borderColor', 'border_color']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Obtain a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console line data structure stored into the DB.
|
||||
* @throws \Exception When the data cannot be retrieved from the DB.
|
||||
*
|
||||
* @override Model::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$row = \db_get_row_filter('tlayout_data', $filter);
|
||||
|
||||
if ($row === false) {
|
||||
throw new \Exception('error fetching the data from the DB');
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,274 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a module graph item of the Visual Console.
|
||||
*/
|
||||
final class ModuleGraph extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked module.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedModule = true;
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
/**
|
||||
* Used to enable validation, extraction and encodeing of the HTML output.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useHtmlOutput = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = MODULE_GRAPH;
|
||||
$return['backgroundType'] = static::extractBackgroundType($data);
|
||||
$return['period'] = static::extractPeriod($data);
|
||||
|
||||
$customGraphId = static::extractCustomGraphId($data);
|
||||
|
||||
if (empty($customGraphId) === false) {
|
||||
$return['customGraphId'] = $customGraphId;
|
||||
} else {
|
||||
$return['graphType'] = static::extractGraphType($data);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a background type value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string 'transparent', 'white' or 'black'. 'transparent' by default.
|
||||
*/
|
||||
private static function extractBackgroundType(array $data): string
|
||||
{
|
||||
$value = static::issetInArray($data, ['backgroundType', 'image']);
|
||||
|
||||
switch ($value) {
|
||||
case 'transparent':
|
||||
case 'white':
|
||||
case 'black':
|
||||
return $value;
|
||||
|
||||
default:
|
||||
return 'transparent';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a graph period value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed The time in seconds of the graph period or null.
|
||||
*/
|
||||
private static function extractPeriod(array $data)
|
||||
{
|
||||
return static::parseIntOr(
|
||||
static::issetInArray($data, ['period']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a custom graph Id value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed The custom graph Id (int) or null.
|
||||
*/
|
||||
private static function extractCustomGraphId(array $data)
|
||||
{
|
||||
return static::parseIntOr(
|
||||
static::issetInArray($data, ['customGraphId', 'id_custom_graph']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a graph type value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string 'line' or 'area'. 'line' by default.
|
||||
*/
|
||||
private static function extractGraphType(array $data): string
|
||||
{
|
||||
$value = static::issetInArray($data, ['graphType', 'type_graph']);
|
||||
|
||||
switch ($value) {
|
||||
case 'line':
|
||||
case 'area':
|
||||
return $value;
|
||||
|
||||
default:
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console Item data structure stored into the DB.
|
||||
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
||||
*
|
||||
* @override Item::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$data = parent::fetchDataFromDB($filter);
|
||||
|
||||
/*
|
||||
* Retrieve extra data.
|
||||
*/
|
||||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_graph.php';
|
||||
include_once $config['homedir'].'/include/functions_modules.php';
|
||||
if (is_metaconsole()) {
|
||||
\enterprise_include_once('include/functions_metaconsole.php');
|
||||
}
|
||||
|
||||
$imageOnly = false;
|
||||
|
||||
$backgroundType = static::extractBackgroundType($data);
|
||||
$period = static::extractPeriod($data);
|
||||
$customGraphId = static::extractCustomGraphId($data);
|
||||
$graphType = static::extractGraphType($data);
|
||||
$linkedModule = static::extractLinkedModule($data);
|
||||
$moduleId = $linkedModule['moduleId'];
|
||||
$metaconsoleId = $linkedModule['metaconsoleId'];
|
||||
|
||||
// Maybe connect to node.
|
||||
$nodeConnected = false;
|
||||
if (\is_metaconsole() === true && $metaconsoleId !== null) {
|
||||
$nodeConnected = \metaconsole_connect(
|
||||
null,
|
||||
$metaconsoleId
|
||||
) === NOERR;
|
||||
|
||||
if ($nodeConnected === false) {
|
||||
throw new \InvalidArgumentException(
|
||||
'error connecting to the node'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* About the 30 substraction to the graph height:
|
||||
* The function which generates the graph doesn't respect the
|
||||
* required height. It uses it for the canvas (the graph itself and
|
||||
* their axes), but then it adds the legend. One item of the legend
|
||||
* (one dataset) is about 30px, so we need to substract that height
|
||||
* from the canvas to try to fit the element's height.
|
||||
*
|
||||
* PD: The custom graphs can have more datasets, but we only substract
|
||||
* the height of one of it to replicate the legacy functionality.
|
||||
*/
|
||||
|
||||
// Custom graph.
|
||||
if (empty($customGraphId) === false) {
|
||||
$customGraph = \db_get_row_filter(
|
||||
'tgraph',
|
||||
'id_graph',
|
||||
$customGraphId
|
||||
);
|
||||
|
||||
$params = [
|
||||
'period' => $period,
|
||||
'width' => $data['width'],
|
||||
'height' => ($data['height'] - 30),
|
||||
'title' => '',
|
||||
'unit_name' => null,
|
||||
'show_alerts' => false,
|
||||
'only_image' => $imageOnly,
|
||||
'vconsole' => true,
|
||||
'backgroundColor' => $backgroundType,
|
||||
];
|
||||
|
||||
$paramsCombined = [
|
||||
'id_graph' => $customGraphId,
|
||||
'stacked' => $customGraph['stacked'],
|
||||
'summatory' => $customGraph['summatory_series'],
|
||||
'average' => $customGraph['average_series'],
|
||||
'modules_series' => $customGraph['modules_series'],
|
||||
];
|
||||
|
||||
$data['html'] = \graphic_combined_module(
|
||||
false,
|
||||
$params,
|
||||
$paramsCombined
|
||||
);
|
||||
} else {
|
||||
// Module graph.
|
||||
if ($moduleId === null) {
|
||||
throw new \InvalidArgumentException('missing module Id');
|
||||
}
|
||||
|
||||
$params = [
|
||||
'agent_module_id' => $moduleId,
|
||||
'period' => $period,
|
||||
'show_events' => false,
|
||||
'width' => $data['width'],
|
||||
'height' => ($data['height'] - 30),
|
||||
'title' => \modules_get_agentmodule_name($moduleId),
|
||||
'unit' => \modules_get_unit($moduleId),
|
||||
'only_image' => $imageOnly,
|
||||
'menu' => false,
|
||||
'backgroundColor' => $backgroundType,
|
||||
'type_graph' => $graphType,
|
||||
'vconsole' => true,
|
||||
];
|
||||
|
||||
$data['html'] = \grafico_modulo_sparse($params);
|
||||
}
|
||||
|
||||
// Restore connection.
|
||||
if ($nodeConnected === true) {
|
||||
\metaconsole_restore_db();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,249 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a percentile item of the Visual Console.
|
||||
*/
|
||||
final class Percentile extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked module.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedModule = true;
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = PERCENTILE_BAR;
|
||||
$return['percentileType'] = static::extractPercentileType($data);
|
||||
$return['valueType'] = static::extractValueType($data);
|
||||
// TODO: Add min value to the database.
|
||||
$return['minValue'] = static::parseFloatOr(
|
||||
static::issetInArray($data, ['minValue']),
|
||||
null
|
||||
);
|
||||
$return['maxValue'] = static::parseFloatOr(
|
||||
static::issetInArray($data, ['maxValue', 'height']),
|
||||
null
|
||||
);
|
||||
$return['color'] = static::extractColor($data);
|
||||
$return['labelColor'] = static::extractLabelColor($data);
|
||||
$return['value'] = static::parseFloatOr(
|
||||
static::issetInArray($data, ['value']),
|
||||
null
|
||||
);
|
||||
$return['unit'] = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['unit']),
|
||||
null
|
||||
);
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a percentile type value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string 'progress-bar', 'bubble', 'circular-progress-bar'
|
||||
* or 'circular-progress-bar-alt'. 'progress-bar' by default.
|
||||
*/
|
||||
private static function extractPercentileType(array $data): string
|
||||
{
|
||||
if (isset($data['percentileType']) === true) {
|
||||
switch ($data['percentileType']) {
|
||||
case 'progress-bar':
|
||||
case 'bubble':
|
||||
case 'circular-progress-bar':
|
||||
case 'circular-progress-bar-alt':
|
||||
return $data['percentileType'];
|
||||
|
||||
default:
|
||||
return 'progress-bar';
|
||||
}
|
||||
}
|
||||
|
||||
switch ($data['type']) {
|
||||
case PERCENTILE_BUBBLE:
|
||||
return 'bubble';
|
||||
|
||||
case CIRCULAR_PROGRESS_BAR:
|
||||
return 'circular-progress-bar';
|
||||
|
||||
case CIRCULAR_INTERIOR_PROGRESS_BAR:
|
||||
return 'circular-progress-bar-alt';
|
||||
|
||||
default:
|
||||
case PERCENTILE_BAR:
|
||||
return 'progress-bar';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a value type value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string 'percent' or 'value'. 'percent' by default.
|
||||
*/
|
||||
private static function extractValueType(array $data): string
|
||||
{
|
||||
$rawValueType = static::issetInArray($data, ['valueType', 'image']);
|
||||
|
||||
switch ($rawValueType) {
|
||||
case 'percent':
|
||||
case 'value':
|
||||
return $rawValueType;
|
||||
|
||||
default:
|
||||
return 'percent';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed The color or null.
|
||||
*/
|
||||
private static function extractColor(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['color', 'border_color']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a label color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed The label color or null.
|
||||
*/
|
||||
private static function extractLabelColor(array $data)
|
||||
{
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['labelColor', 'fill_color']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console Item data structure stored into the DB.
|
||||
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
||||
*
|
||||
* @override Item::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$data = parent::fetchDataFromDB($filter);
|
||||
|
||||
/*
|
||||
* Retrieve extra data.
|
||||
*/
|
||||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_graph.php';
|
||||
include_once $config['homedir'].'/include/functions_modules.php';
|
||||
include_once $config['homedir'].'/include/functions_io.php';
|
||||
if (is_metaconsole()) {
|
||||
\enterprise_include_once('include/functions_metaconsole.php');
|
||||
}
|
||||
|
||||
// Get the linked module Id.
|
||||
$linkedModule = static::extractLinkedModule($data);
|
||||
$moduleId = static::parseIntOr($linkedModule['moduleId'], null);
|
||||
$metaconsoleId = static::parseIntOr(
|
||||
$linkedModule['metaconsoleId'],
|
||||
null
|
||||
);
|
||||
|
||||
// Get the value type.
|
||||
$valueType = static::extractValueType($data);
|
||||
|
||||
if ($moduleId === null) {
|
||||
throw new \InvalidArgumentException('missing module Id');
|
||||
}
|
||||
|
||||
// Maybe connect to node.
|
||||
$nodeConnected = false;
|
||||
if (\is_metaconsole() === true && $metaconsoleId !== null) {
|
||||
$nodeConnected = \metaconsole_connect(
|
||||
null,
|
||||
$metaconsoleId
|
||||
) === NOERR;
|
||||
|
||||
if ($nodeConnected === false) {
|
||||
throw new \InvalidArgumentException(
|
||||
'error connecting to the node'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$moduleValue = \modules_get_last_value($moduleId);
|
||||
if ($moduleValue === false) {
|
||||
throw new \InvalidArgumentException(
|
||||
'error fetching the module value'
|
||||
);
|
||||
}
|
||||
|
||||
// Cast to float.
|
||||
$moduleValue = (float) $moduleValue;
|
||||
|
||||
// Store the module value.
|
||||
$data['value'] = $moduleValue;
|
||||
|
||||
$unit = \modules_get_unit($moduleId);
|
||||
if (empty($unit) === false) {
|
||||
$data['unit'] = \io_safe_output($unit);
|
||||
}
|
||||
|
||||
// Restore connection.
|
||||
if ($nodeConnected === true) {
|
||||
\metaconsole_restore_db();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,239 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a simple value item of the Visual Console.
|
||||
*/
|
||||
final class SimpleValue extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked module.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedModule = true;
|
||||
|
||||
|
||||
/**
|
||||
* Validate the received data structure to ensure if we can extract the
|
||||
* values required to build the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException If any input value is considered
|
||||
* invalid.
|
||||
*
|
||||
* @overrides Item->validateData.
|
||||
*/
|
||||
protected function validateData(array $data): void
|
||||
{
|
||||
parent::validateData($data);
|
||||
if (isset($data['value']) === false) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the value property is required and should be string'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item->decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = SIMPLE_VALUE;
|
||||
$return['processValue'] = static::extractProcessValue($data);
|
||||
$return['valueType'] = static::extractValueType($data);
|
||||
$return['value'] = $data['value'];
|
||||
|
||||
if ($return['processValue'] !== 'none') {
|
||||
$return['period'] = static::extractPeriod($data);
|
||||
}
|
||||
|
||||
// Clear the size, as this element always have a dynamic size.
|
||||
$return['width'] = 0;
|
||||
$return['height'] = 0;
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a process value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string One of 'none', 'avg', 'max' or 'min'. 'none' by default.
|
||||
*/
|
||||
private static function extractProcessValue(array $data): string
|
||||
{
|
||||
if (isset($data['processValue'])) {
|
||||
switch ($data['processValue']) {
|
||||
case 'none':
|
||||
case 'avg':
|
||||
case 'max':
|
||||
case 'min':
|
||||
return $data['processValue'];
|
||||
|
||||
default:
|
||||
return 'none';
|
||||
}
|
||||
} else {
|
||||
switch ($data['type']) {
|
||||
case SIMPLE_VALUE_MAX:
|
||||
return 'max';
|
||||
|
||||
case SIMPLE_VALUE_MIN:
|
||||
return 'min';
|
||||
|
||||
case SIMPLE_VALUE_AVG:
|
||||
return 'avg';
|
||||
|
||||
default:
|
||||
return 'none';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the value of period.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return integer The period in seconds. 0 is the minimum value.
|
||||
*/
|
||||
private static function extractPeriod(array $data): int
|
||||
{
|
||||
$period = static::parseIntOr(
|
||||
static::issetInArray($data, ['period']),
|
||||
0
|
||||
);
|
||||
return ($period >= 0) ? $period : 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a value type.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string One of 'string' or 'image'. 'string' by default.
|
||||
*/
|
||||
private static function extractValueType(array $data): string
|
||||
{
|
||||
switch ($data['valueType']) {
|
||||
case 'string':
|
||||
case 'image':
|
||||
return $data['valueType'];
|
||||
|
||||
default:
|
||||
return 'string';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console Item data structure stored into the DB.
|
||||
* @throws \InvalidArgumentException When a module Id cannot be found.
|
||||
*
|
||||
* @override Item::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$data = parent::fetchDataFromDB($filter);
|
||||
|
||||
/*
|
||||
* Retrieve extra data.
|
||||
*/
|
||||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
if (is_metaconsole()) {
|
||||
\enterprise_include_once('include/functions_metaconsole.php');
|
||||
}
|
||||
|
||||
// Get the linked module Id.
|
||||
$linkedModule = static::extractLinkedModule($data);
|
||||
$moduleId = static::parseIntOr($linkedModule['moduleId'], null);
|
||||
$metaconsoleId = static::parseIntOr(
|
||||
$linkedModule['metaconsoleId'],
|
||||
null
|
||||
);
|
||||
|
||||
if ($moduleId === null) {
|
||||
throw new \InvalidArgumentException('missing module Id');
|
||||
}
|
||||
|
||||
// Maybe connect to node.
|
||||
$nodeConnected = false;
|
||||
if (\is_metaconsole() === true && $metaconsoleId !== null) {
|
||||
$nodeConnected = \metaconsole_connect(
|
||||
null,
|
||||
$metaconsoleId
|
||||
) === NOERR;
|
||||
|
||||
if ($nodeConnected === false) {
|
||||
throw new \InvalidArgumentException(
|
||||
'error connecting to the node'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the formatted value.
|
||||
$value = \visual_map_get_simple_value(
|
||||
$data['type'],
|
||||
$moduleId,
|
||||
static::extractPeriod($data)
|
||||
);
|
||||
|
||||
// Restore connection.
|
||||
if ($nodeConnected === true) {
|
||||
\metaconsole_restore_db();
|
||||
}
|
||||
|
||||
// Some modules are image based. Extract the base64 image if needed.
|
||||
$matches = [];
|
||||
if (\preg_match('/src=\"(data:image.*)"/', $value, $matches) === 1) {
|
||||
$data['valueType'] = 'image';
|
||||
$data['value'] = $matches[1];
|
||||
} else {
|
||||
$data['valueType'] = 'string';
|
||||
$data['value'] = $value;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,256 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
|
||||
/**
|
||||
* Model of a static graph item of the Visual Console.
|
||||
*/
|
||||
final class StaticGraph extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked module.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedModule = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item->decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = STATIC_GRAPH;
|
||||
$return['imageSrc'] = static::extractImageSrc($data);
|
||||
$return['showLastValueTooltip'] = static::extractShowLastValueTooltip(
|
||||
$data
|
||||
);
|
||||
$return['statusImageSrc'] = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['statusImageSrc']),
|
||||
null
|
||||
);
|
||||
$return['lastValue'] = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['lastValue']),
|
||||
null
|
||||
);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a image src value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the image url (not empty) or null.
|
||||
*
|
||||
* @throws \InvalidArgumentException When a valid image src can't be found.
|
||||
*/
|
||||
private static function extractImageSrc(array $data): string
|
||||
{
|
||||
$imageSrc = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['imageSrc', 'image']),
|
||||
null
|
||||
);
|
||||
|
||||
if ($imageSrc === null) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the image src property is required and should be a non empty string'
|
||||
);
|
||||
}
|
||||
|
||||
return $imageSrc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the value of showLastValueTooltip and
|
||||
* return 'default', 'enabled' or 'disabled'.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function extractShowLastValueTooltip(array $data): string
|
||||
{
|
||||
$showLastValueTooltip = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['showLastValueTooltip']),
|
||||
null
|
||||
);
|
||||
|
||||
if ($showLastValueTooltip === null) {
|
||||
$showLastValueTooltip = static::parseIntOr(
|
||||
static::issetInArray($data, ['show_last_value']),
|
||||
null
|
||||
);
|
||||
switch ($showLastValueTooltip) {
|
||||
case 1:
|
||||
return 'enabled';
|
||||
|
||||
case 2:
|
||||
return 'disabled';
|
||||
|
||||
default:
|
||||
return 'default';
|
||||
}
|
||||
} else {
|
||||
switch ($showLastValueTooltip) {
|
||||
case 'enabled':
|
||||
return 'enabled';
|
||||
|
||||
case 'disabled':
|
||||
return 'disabled';
|
||||
|
||||
default:
|
||||
return 'default';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console Item data structure stored into the DB.
|
||||
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
||||
*
|
||||
* @override Item::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$data = parent::fetchDataFromDB($filter);
|
||||
|
||||
/*
|
||||
* Retrieve extra data.
|
||||
*/
|
||||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_ui.php';
|
||||
include_once $config['homedir'].'/include/functions_io.php';
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
include_once $config['homedir'].'/include/functions_modules.php';
|
||||
if (is_metaconsole()) {
|
||||
\enterprise_include_once('include/functions_metaconsole.php');
|
||||
}
|
||||
|
||||
// Get the linked module Id.
|
||||
$linkedModule = static::extractLinkedModule($data);
|
||||
$moduleId = $linkedModule['moduleId'];
|
||||
$metaconsoleId = $linkedModule['metaconsoleId'];
|
||||
|
||||
if ($moduleId === null) {
|
||||
throw new \InvalidArgumentException('missing module Id');
|
||||
}
|
||||
|
||||
// Get the img src.
|
||||
// There's no need to connect to the metaconsole before searching for
|
||||
// the image status cause the function itself does that for us.
|
||||
$imagePath = \visual_map_get_image_status_element($data);
|
||||
$data['statusImageSrc'] = \ui_get_full_url(
|
||||
$imagePath,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
// If the width or the height are equal to 0 we will extract them
|
||||
// from the real image size.
|
||||
$width = (int) $data['width'];
|
||||
$height = (int) $data['height'];
|
||||
if ($width === 0 || $height === 0) {
|
||||
// TODO: This will be the default behaviour after we finish the
|
||||
// builder. Don't delete this code.
|
||||
// $sizeImage = getimagesize($config['homedir'].'/'.$imagePath);
|
||||
// $data['width'] = $sizeImage[0];
|
||||
// $data['height'] = $sizeImage[1];
|
||||
// Default value. Will be replaced by a dynamic image size
|
||||
// calculation after the phase 3.
|
||||
$sizeImage = getimagesize($config['homedir'].'/'.$imagePath);
|
||||
$imageHeight = $sizeImage[1];
|
||||
|
||||
if ($width === 0) {
|
||||
$data['width'] = 70;
|
||||
}
|
||||
|
||||
if ($height === 0) {
|
||||
$data['height'] = ($imageHeight > 70) ? 70 : $imageHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// Get last value.
|
||||
$showLastValueTooltip = static::extractShowLastValueTooltip($data);
|
||||
if ($showLastValueTooltip !== 'disabled' && $moduleId > 0) {
|
||||
// Maybe connect to node.
|
||||
$nodeConnected = false;
|
||||
if (\is_metaconsole() === true && $metaconsoleId !== null) {
|
||||
$nodeConnected = \metaconsole_connect(
|
||||
null,
|
||||
$metaconsoleId
|
||||
) === NOERR;
|
||||
|
||||
if ($nodeConnected === false) {
|
||||
throw new \InvalidArgumentException(
|
||||
'error connecting to the node'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$imgTitle = '';
|
||||
|
||||
$unit = \trim(\io_safe_output(\modules_get_unit($moduleId)));
|
||||
$value = \modules_get_last_value($moduleId);
|
||||
|
||||
$isBooleanModule = \modules_is_boolean($moduleId);
|
||||
if (!$isBooleanModule
|
||||
|| ($isBooleanModule && $showLastValueTooltip !== 'default')
|
||||
) {
|
||||
if (is_numeric($value)) {
|
||||
$imgTitle .= __('Last value: ').\remove_right_zeros($value);
|
||||
} else {
|
||||
$imgTitle .= __('Last value: ').$value;
|
||||
}
|
||||
|
||||
if (empty($unit) === false && empty($imgTitle) === false) {
|
||||
$imgTitle .= ' '.$unit;
|
||||
}
|
||||
|
||||
$data['lastValue'] = $imgTitle;
|
||||
}
|
||||
|
||||
// Restore connection.
|
||||
if ($nodeConnected === true) {
|
||||
\metaconsole_restore_db();
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -156,11 +156,118 @@ span.breadcrumb_link {
|
|||
color: #95b750;
|
||||
}
|
||||
|
||||
.form_grid_items {
|
||||
overflow: hidden;
|
||||
/*
|
||||
* Discovery forms structure
|
||||
*/
|
||||
|
||||
.edit_discovery_info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-top: 25px;
|
||||
}
|
||||
.form_grid_items .form_grid_item {
|
||||
float: left;
|
||||
|
||||
.edit_discovery_input {
|
||||
align-items: center;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
/*
|
||||
* Discovery text inputs
|
||||
*/
|
||||
|
||||
.discovery_label_hint {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
label {
|
||||
color: #343434 !important;
|
||||
font-size: 1.5em;
|
||||
font-family: "lato-bolder", "Open Sans", sans-serif !important;
|
||||
font-weight: bold;
|
||||
margin: 0px 0px 5px 0px;
|
||||
}
|
||||
|
||||
.discovery_full_width_input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
select {
|
||||
font-family: "lato-bolder", "Open Sans", sans-serif !important;
|
||||
font-size: 1.6em !important;
|
||||
color: #686868;
|
||||
}
|
||||
|
||||
select > option {
|
||||
font-family: "lato-bolder", "Open Sans", sans-serif !important;
|
||||
font-size: 1em !important;
|
||||
}
|
||||
|
||||
li > input[type=text], li > input[type=password], .discovery_text_input > input[type=password], .discovery_text_input > input[type=text], #interval_manual > input[type=text] {
|
||||
background-color: transparent !important;
|
||||
border: none;
|
||||
border-radius: 0 !important;
|
||||
border-bottom: 1px solid #343434;
|
||||
padding: 0px 0px 2px 0px;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 4px;
|
||||
font-family: "lato-bolder", "Open Sans", sans-serif !important;
|
||||
font-size: 1.6em;
|
||||
}
|
||||
|
||||
li > input[type=text]:focus, li > input[type=password]:focus, .discovery_text_input > input[type=password]:focus, .discovery_text_input > input[type=text]:focus, #interval_manual > input[type=text]:focus {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#interval_manual > input[type=text] {
|
||||
width: 50px;
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.discovery_list_input {
|
||||
font-family: "lato-bolder", "Open Sans", sans-serif !important;
|
||||
font-size: 1.6em !important;
|
||||
color: #686868;
|
||||
width: 100%;
|
||||
height: 240px;
|
||||
border: 1px solid #CBCBCB;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.discovery_list_input option {
|
||||
font-family: "lato-bolder", "Open Sans", sans-serif !important;
|
||||
font-size: 1.1em !important;
|
||||
padding-left: 30%;
|
||||
}
|
||||
|
||||
.discovery_list_input option:checked {
|
||||
background: #1aab8e -webkit-linear-gradient(bottom, #7db742 0%, #7db742 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.discovery_textarea_input {
|
||||
background-color: #fbfbfb !important;
|
||||
padding-left: 10px;
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
max-height: 100px;
|
||||
max-width: 100%;
|
||||
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
|
||||
-moz-box-sizing: border-box; /* Firefox, other Gecko */
|
||||
box-sizing: border-box;
|
||||
padding: 10px;
|
||||
resize: none;
|
||||
font-family: "lato-bolder", "Open Sans", sans-serif !important;
|
||||
font-size: 1.4em !important;
|
||||
}
|
||||
|
||||
a.tip {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.inline_switch > label {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.discovery_interval_select_width {
|
||||
width: 90%;
|
||||
}
|
|
@ -16,8 +16,10 @@ ul.wizard li > label:not(.p-switch) {
|
|||
}
|
||||
|
||||
ul.wizard li > textarea {
|
||||
width: 250px;
|
||||
width: 600px;
|
||||
height: 15em;
|
||||
display: inline-block;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,90 @@
|
|||
#visual-console-container {
|
||||
margin: 0px auto;
|
||||
position: relative;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 100% 100%;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
.visual-console-item {
|
||||
position: absolute;
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
-webkit-box-orient: initial;
|
||||
-webkit-box-direction: initial;
|
||||
-ms-flex-direction: initial;
|
||||
flex-direction: initial;
|
||||
justify-items: center;
|
||||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
-webkit-user-select: text;
|
||||
-moz-user-select: text;
|
||||
-ms-user-select: text;
|
||||
user-select: text;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Alarm Clock;
|
||||
src: url(alarm-clock.ttf);
|
||||
}
|
||||
|
||||
/* Digital clock */
|
||||
|
||||
.visual-console-item .digital-clock {
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-box-direction: normal;
|
||||
-ms-flex-direction: column;
|
||||
flex-direction: column;
|
||||
-webkit-box-pack: center;
|
||||
-ms-flex-pack: center;
|
||||
justify-content: center;
|
||||
justify-items: center;
|
||||
-ms-flex-line-pack: center;
|
||||
align-content: center;
|
||||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.visual-console-item .digital-clock > span {
|
||||
font-family: "Alarm Clock", "Courier New", Courier, monospace;
|
||||
font-size: 50px;
|
||||
|
||||
/* To improve legibility */
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
text-rendering: optimizeLegibility;
|
||||
text-shadow: rgba(0, 0, 0, 0.01) 0 0 1px;
|
||||
}
|
||||
|
||||
.visual-console-item .digital-clock > span.date {
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
.visual-console-item .digital-clock > span.timezone {
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
/* Analog clock */
|
||||
|
||||
.visual-console-item .analogic-clock .hour-hand {
|
||||
-webkit-animation: rotate-hour 43200s infinite linear;
|
||||
animation: rotate-hour 43200s infinite linear;
|
||||
}
|
||||
|
||||
.visual-console-item .analogic-clock .minute-hand {
|
||||
-webkit-animation: rotate-minute 3600s infinite linear;
|
||||
animation: rotate-minute 3600s infinite linear;
|
||||
}
|
||||
|
||||
.visual-console-item .analogic-clock .second-hand {
|
||||
-webkit-animation: rotate-second 60s infinite linear;
|
||||
animation: rotate-second 60s infinite linear;
|
||||
}
|
||||
|
||||
/*# sourceMappingURL=vc.main.css.map*/
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["webpack:///main.css","webpack:///styles.css"],"names":[],"mappings":"AAAA;EACE,gBAAgB;EAChB,kBAAkB;EAClB,4BAA4B;EAC5B,0BAA0B;EAC1B,2BAA2B;AAC7B;;AAEA;EACE,kBAAkB;EAClB,oBAAa;EAAb,oBAAa;EAAb,aAAa;EACb,2BAAuB;EAAvB,8BAAuB;MAAvB,2BAAuB;UAAvB,uBAAuB;EACvB,qBAAqB;EACrB,yBAAmB;MAAnB,sBAAmB;UAAnB,mBAAmB;EACnB,yBAAiB;KAAjB,sBAAiB;MAAjB,qBAAiB;UAAjB,iBAAiB;AACnB;;ACfA;EACE,wBAAwB;EACxB,0BAA2B;AAC7B;;AAEA,kBAAkB;;AAElB;EACE,oBAAa;EAAb,oBAAa;EAAb,aAAa;EACb,4BAAsB;EAAtB,6BAAsB;MAAtB,0BAAsB;UAAtB,sBAAsB;EACtB,wBAAuB;MAAvB,qBAAuB;UAAvB,uBAAuB;EACvB,qBAAqB;EACrB,0BAAqB;MAArB,qBAAqB;EACrB,yBAAmB;MAAnB,sBAAmB;UAAnB,mBAAmB;AACrB;;AAEA;EACE,6DAA6D;EAC7D,eAAe;;EAEf,0BAA0B;EAC1B,mCAAmC;EACnC,kCAAkC;EAClC,kCAAkC;EAClC,wCAAwC;AAC1C;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,eAAe;AACjB;;AAEA,iBAAiB;;AAEjB;EACE,qDAA6C;UAA7C,6CAA6C;AAC/C;;AAEA;EACE,sDAA8C;UAA9C,8CAA8C;AAChD;;AAEA;EACE,oDAA4C;UAA5C,4CAA4C;AAC9C","file":"vc.main.css","sourcesContent":["#visual-console-container {\n margin: 0px auto;\n position: relative;\n background-repeat: no-repeat;\n background-size: 100% 100%;\n background-position: center;\n}\n\n.visual-console-item {\n position: absolute;\n display: flex;\n flex-direction: initial;\n justify-items: center;\n align-items: center;\n user-select: text;\n}\n","@font-face {\n font-family: Alarm Clock;\n src: url(./alarm-clock.ttf);\n}\n\n/* Digital clock */\n\n.visual-console-item .digital-clock {\n display: flex;\n flex-direction: column;\n justify-content: center;\n justify-items: center;\n align-content: center;\n align-items: center;\n}\n\n.visual-console-item .digital-clock > span {\n font-family: \"Alarm Clock\", \"Courier New\", Courier, monospace;\n font-size: 50px;\n\n /* To improve legibility */\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n text-rendering: optimizeLegibility;\n text-shadow: rgba(0, 0, 0, 0.01) 0 0 1px;\n}\n\n.visual-console-item .digital-clock > span.date {\n font-size: 25px;\n}\n\n.visual-console-item .digital-clock > span.timezone {\n font-size: 25px;\n}\n\n/* Analog clock */\n\n.visual-console-item .analogic-clock .hour-hand {\n animation: rotate-hour 43200s infinite linear;\n}\n\n.visual-console-item .analogic-clock .minute-hand {\n animation: rotate-minute 3600s infinite linear;\n}\n\n.visual-console-item .analogic-clock .second-hand {\n animation: rotate-second 60s infinite linear;\n}\n"],"sourceRoot":""}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -128,8 +128,8 @@
|
|||
</div>
|
||||
<div style='height: 10px'>
|
||||
<?php
|
||||
$version = '7.0NG.733';
|
||||
$build = '190417';
|
||||
$version = '7.0NG.734';
|
||||
$build = '190503';
|
||||
$banner = "v$version Build $build";
|
||||
|
||||
error_reporting(0);
|
||||
|
|
|
@ -497,6 +497,7 @@ if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) {
|
|||
if (!is_metaconsole()) {
|
||||
$table->size[7] = '5%';
|
||||
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'LW') || check_acl_one_of_groups($config['id_user'], $all_groups, 'LM')) {
|
||||
$table->head[8] = __('Validate');
|
||||
$table->align[8] = 'left';
|
||||
$table->size[8] = '5%';
|
||||
}
|
||||
|
@ -532,6 +533,7 @@ if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) {
|
|||
if (!is_metaconsole()) {
|
||||
$table->size[7] = '5%';
|
||||
if (check_acl($config['id_user'], $id_group, 'LW') || check_acl($config['id_user'], $id_group, 'LM')) {
|
||||
$table->head[8] = __('Validate');
|
||||
$table->align[8] = 'left';
|
||||
$table->size[8] = '5%';
|
||||
}
|
||||
|
@ -563,6 +565,7 @@ if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) {
|
|||
if (!is_metaconsole()) {
|
||||
$table->size[6] = '5%';
|
||||
if (check_acl($config['id_user'], $id_group, 'LW') || check_acl($config['id_user'], $id_group, 'LM')) {
|
||||
$table->head[7] = __('Validate');
|
||||
$table->align[7] = 'left';
|
||||
$table->size[7] = '5%';
|
||||
}
|
||||
|
|
|
@ -91,18 +91,20 @@ if ($id_group > 0 && in_array($id_group, array_keys($groups))) {
|
|||
$childrens_str = implode(',', $childrens_ids);
|
||||
$sql_post .= " AND (id_grupo IN ($childrens_str)";
|
||||
|
||||
if ($is_using_secondary_group === 1)
|
||||
if ($is_using_secondary_group === 1) {
|
||||
$sql_post .= " OR id_group IN ($childrens_str)";
|
||||
}
|
||||
|
||||
$sql_post .= ")";
|
||||
$sql_post .= ')';
|
||||
} else {
|
||||
// If a group is selected and it's in the groups allowed.
|
||||
$sql_post .= " AND (id_grupo = $id_group";
|
||||
|
||||
if ($is_using_secondary_group === 1)
|
||||
if ($is_using_secondary_group === 1) {
|
||||
$sql_post .= " OR id_group = $id_group";
|
||||
}
|
||||
|
||||
$sql_post .= ")";
|
||||
$sql_post .= ')';
|
||||
}
|
||||
} else {
|
||||
if (!users_is_admin() && !users_can_manage_group_all('ER')) {
|
||||
|
@ -112,13 +114,12 @@ if ($id_group > 0 && in_array($id_group, array_keys($groups))) {
|
|||
implode(',', array_keys($groups)),
|
||||
implode(',', array_keys($groups))
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sql_post .= sprintf(
|
||||
' AND (id_grupo IN (%s)) ',
|
||||
implode(',', array_keys($groups))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -492,12 +492,6 @@ if (is_array($config['extensions'])) {
|
|||
$sub['godmode/agentes/planned_downtime.list']['id'] = 'Scheduled downtime';
|
||||
}
|
||||
|
||||
if (check_acl($config['id_user'], 0, 'AW')) {
|
||||
$sub['operation/servers/recon_view']['text'] = __('Recon view');
|
||||
$sub['operation/servers/recon_view']['id'] = 'Recon view';
|
||||
$sub['operation/servers/recon_view']['refr'] = 0;
|
||||
}
|
||||
|
||||
foreach ($config['extensions'] as $extension) {
|
||||
// If no operation_menu is a godmode extension.
|
||||
if ($extension['operation_menu'] == '') {
|
||||
|
|
|
@ -0,0 +1,265 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 20012 Artica Soluciones Tecnologicas
|
||||
// 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.
|
||||
// Don't start a session before this import.
|
||||
// The session is configured and started inside the config process.
|
||||
require_once '../../include/config.php';
|
||||
|
||||
// Set root on homedir, as defined in setup
|
||||
chdir($config['homedir']);
|
||||
|
||||
ob_start();
|
||||
// Enterprise support
|
||||
if (file_exists(ENTERPRISE_DIR.'/load_enterprise.php')) {
|
||||
include_once ENTERPRISE_DIR.'/load_enterprise.php';
|
||||
}
|
||||
|
||||
if (file_exists(ENTERPRISE_DIR.'/include/functions_login.php')) {
|
||||
include_once ENTERPRISE_DIR.'/include/functions_login.php';
|
||||
}
|
||||
|
||||
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
|
||||
echo '<html xmlns="http://www.w3.org/1999/xhtml">'."\n";
|
||||
echo '<head>';
|
||||
|
||||
global $vc_public_view;
|
||||
$vc_public_view = true;
|
||||
// This starts the page head. In the call back function,
|
||||
// things from $page['head'] array will be processed into the head
|
||||
ob_start('ui_process_page_head');
|
||||
// Enterprise main
|
||||
enterprise_include('index.php');
|
||||
|
||||
require_once 'include/functions_visual_map.php';
|
||||
|
||||
$hash = get_parameter('hash');
|
||||
$id_layout = (int) get_parameter('id_layout');
|
||||
$graph_javascript = (bool) get_parameter('graph_javascript');
|
||||
$config['id_user'] = get_parameter('id_user');
|
||||
|
||||
$myhash = md5($config['dbpass'].$id_layout.$config['id_user']);
|
||||
|
||||
// Check input hash
|
||||
if ($myhash != $hash) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$refr = (int) get_parameter('refr', 0);
|
||||
$layout = db_get_row('tlayout', 'id', $id_layout);
|
||||
|
||||
if (! $layout) {
|
||||
db_pandora_audit('ACL Violation', 'Trying to access visual console without id layout');
|
||||
include $config['homedir'].'/general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($config['pure'])) {
|
||||
$config['pure'] = 0;
|
||||
}
|
||||
|
||||
// ~ $xhr = (bool) get_parameter('xhr');
|
||||
if ($layout) {
|
||||
$id_group = $layout['id_group'];
|
||||
$layout_name = $layout['name'];
|
||||
$background = $layout['background'];
|
||||
$bwidth = $layout['width'];
|
||||
$bheight = $layout['height'];
|
||||
// ~ $width = (int) get_parameter('width');
|
||||
// ~ if ($width <= 0) $width = null;
|
||||
// ~ $height = (int) get_parameter('height');
|
||||
// ~ if ($height <= 0) $height = null;
|
||||
// ~ ob_start();
|
||||
// ~ // Render map
|
||||
visual_map_print_visual_map(
|
||||
$id_layout,
|
||||
true,
|
||||
true,
|
||||
$width,
|
||||
$height,
|
||||
'../../',
|
||||
true,
|
||||
true,
|
||||
true
|
||||
);
|
||||
// ~ return;
|
||||
} else {
|
||||
echo '<div id="vc-container"></div>';
|
||||
}
|
||||
|
||||
// Floating menu - Start
|
||||
echo '<div id="vc-controls" style="z-index:300;">';
|
||||
|
||||
echo '<div id="menu_tab">';
|
||||
echo '<ul class="mn">';
|
||||
|
||||
// QR code
|
||||
echo '<li class="nomn">';
|
||||
echo '<a href="javascript: show_dialog_qrcode();">';
|
||||
echo '<img class="vc-qr" src="../../images/qrcode_icon_2.jpg"/>';
|
||||
echo '</a>';
|
||||
echo '</li>';
|
||||
|
||||
// Countdown
|
||||
echo '<li class="nomn">';
|
||||
echo '<div class="vc-refr">';
|
||||
echo '<div class="vc-countdown"></div>';
|
||||
echo '<div id="vc-refr-form">';
|
||||
echo __('Refresh').':';
|
||||
echo html_print_select(get_refresh_time_array(), 'refr', $refr, '', '', 0, true, false, false);
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
echo '</li>';
|
||||
|
||||
// Console name
|
||||
echo '<li class="nomn">';
|
||||
echo '<div class="vc-title">'.$layout_name.'</div>';
|
||||
echo '</li>';
|
||||
|
||||
echo '</ul>';
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
// Floating menu - End
|
||||
// QR code dialog
|
||||
echo '<div style="display: none;" id="qrcode_container" title="'.__('QR code of the page').'">';
|
||||
echo '<div id="qrcode_container_image"></div>';
|
||||
echo '</div>';
|
||||
|
||||
ui_require_jquery_file('countdown');
|
||||
ui_require_javascript_file('wz_jsgraphics');
|
||||
ui_require_javascript_file('pandora_visual_console');
|
||||
$ignored_params['refr'] = '';
|
||||
?>
|
||||
|
||||
<style type="text/css">
|
||||
svg {
|
||||
stroke: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
var refr = <?php echo (int) $refr; ?>;
|
||||
var href = "<?php echo ui_get_url_refresh($ignored_params); ?>";
|
||||
|
||||
var startCountDown = function (duration, cb) {
|
||||
$('div.vc-countdown').countdown('destroy');
|
||||
if (!duration) return;
|
||||
var t = new Date();
|
||||
t.setTime(t.getTime() + duration * 1000);
|
||||
$('div.vc-countdown').countdown({
|
||||
until: t,
|
||||
format: 'MS',
|
||||
layout: '(%M%nn%M:%S%nn%S <?php echo __('Until refresh'); ?>) ',
|
||||
alwaysExpire: true,
|
||||
onExpiry: function () {
|
||||
$('div.vc-countdown').countdown('destroy');
|
||||
//~ cb();
|
||||
url = js_html_entity_decode( href ) + duration;
|
||||
$(document).attr ("location", url);
|
||||
}
|
||||
});
|
||||
}
|
||||
startCountDown(refr, false);
|
||||
// Auto hide controls
|
||||
var controls = document.getElementById('vc-controls');
|
||||
autoHideElement(controls, 1000);
|
||||
|
||||
$('select#refr').change(function (event) {
|
||||
refr = Number.parseInt(event.target.value, 10);
|
||||
startCountDown(refr, false);
|
||||
});
|
||||
|
||||
|
||||
$('body').css('background-color','<?php echo $layout['background_color']; ?>');
|
||||
$('body').css('margin','0');
|
||||
$('body').css('height','100%');
|
||||
$('body').css('overflow','hidden');
|
||||
$(".module_graph .menu_graph").css('display','none');
|
||||
|
||||
$(".parent_graph").each(function(){
|
||||
|
||||
if($(this).css('background-color') != 'rgb(255, 255, 255)'){
|
||||
$(this).css('color', '#999');
|
||||
}
|
||||
});
|
||||
|
||||
$(".overlay").removeClass("overlay").addClass("overlaydisabled");
|
||||
|
||||
// Start the map fetch
|
||||
//~ fetchMap();
|
||||
});
|
||||
|
||||
$(window).on('load', function () {
|
||||
$('.item:not(.icon) img:not(.b64img)').each( function() {
|
||||
if ($(this).css('float')=='left' || $(this).css('float')=='right') {
|
||||
if( $(this).parent()[0].tagName == 'DIV'){
|
||||
$(this).css('margin-top',(parseInt($(this).parent().css('height'))/2-parseInt($(this).css('height'))/2)+'px');
|
||||
}
|
||||
else if ( $(this).parent()[0].tagName == 'A') {
|
||||
$(this).css('margin-top',(parseInt($(this).parent().parent().css('height'))/2-parseInt($(this).css('height'))/2)+'px');
|
||||
}
|
||||
$(this).css('margin-left','');
|
||||
}
|
||||
else {
|
||||
if(parseInt($(this).parent().parent().css('width'))/2-parseInt($(this).css('width'))/2 < 0){
|
||||
$(this).css('margin-left','');
|
||||
$(this).css('margin-top','');
|
||||
} else {
|
||||
if( $(this).parent()[0].tagName == 'DIV'){
|
||||
$(this).css('margin-left',(parseInt($(this).parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
|
||||
}
|
||||
else if ( $(this).parent()[0].tagName == 'A') {
|
||||
$(this).css('margin-left',(parseInt($(this).parent().parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
|
||||
}
|
||||
$(this).css('margin-top','');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('.item > div').each( function() {
|
||||
if ($(this).css('float')=='left' || $(this).css('float')=='right') {
|
||||
if($(this).attr('id').indexOf('clock') || $(this).attr('id').indexOf('overlay')){
|
||||
$(this).css('margin-top',(parseInt($(this).parent().css('height'))/2-parseInt($(this).css('height'))/2)+'px');
|
||||
}
|
||||
else{
|
||||
$(this).css('margin-top',(parseInt($(this).parent().css('height'))/2-parseInt($(this).css('height'))/2-15)+'px');
|
||||
}
|
||||
$(this).css('margin-left','');
|
||||
}
|
||||
else {
|
||||
$(this).css('margin-left',(parseInt($(this).parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
|
||||
$(this).css('margin-top','');
|
||||
}
|
||||
});
|
||||
|
||||
$('.item > a > div').each( function() {
|
||||
if ($(this).css('float')=='left' || $(this).css('float')=='right') {
|
||||
$(this).css('margin-top',(parseInt($(this).parent().parent().css('height'))/2-parseInt($(this).css('height'))/2-5)+'px');
|
||||
$(this).css('margin-left','');
|
||||
}
|
||||
else {
|
||||
$(this).css('margin-left',(parseInt($(this).parent().parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
|
||||
$(this).css('margin-top','');
|
||||
}
|
||||
});
|
||||
|
||||
$(".graph:not([class~='noresizevc'])").each(function(){
|
||||
height = parseInt($(this).css("height")) - 30;
|
||||
$(this).css('height', height);
|
||||
});
|
||||
|
||||
// Start the map fetch
|
||||
//~ fetchMap();
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,386 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
|
||||
// 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.
|
||||
global $config;
|
||||
|
||||
// Login check
|
||||
require_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
|
||||
check_login();
|
||||
|
||||
if (!defined('METACONSOLE')) {
|
||||
$id_layout = (int) get_parameter('id');
|
||||
} else {
|
||||
$id_layout = (int) get_parameter('id_visualmap');
|
||||
}
|
||||
|
||||
if ($id_layout) {
|
||||
$default_action = 'edit';
|
||||
} else {
|
||||
$default_action = 'new';
|
||||
}
|
||||
|
||||
if (!defined('METACONSOLE')) {
|
||||
$action = get_parameterBetweenListValues(
|
||||
'action',
|
||||
[
|
||||
'new',
|
||||
'save',
|
||||
'edit',
|
||||
'update',
|
||||
'delete',
|
||||
],
|
||||
$default_action
|
||||
);
|
||||
} else {
|
||||
$action = get_parameterBetweenListValues(
|
||||
'action2',
|
||||
[
|
||||
'new',
|
||||
'save',
|
||||
'edit',
|
||||
'update',
|
||||
'delete',
|
||||
],
|
||||
$default_action
|
||||
);
|
||||
}
|
||||
|
||||
$refr = (int) get_parameter('refr', $config['vc_refr']);
|
||||
$graph_javascript = (bool) get_parameter('graph_javascript', true);
|
||||
$vc_refr = false;
|
||||
|
||||
if (isset($config['vc_refr']) and $config['vc_refr'] != 0) {
|
||||
$view_refresh = $config['vc_refr'];
|
||||
} else {
|
||||
$view_refresh = '300';
|
||||
}
|
||||
|
||||
// Get input parameter for layout id
|
||||
if (! $id_layout) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access visual console without id layout'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
$layout = db_get_row('tlayout', 'id', $id_layout);
|
||||
|
||||
if (! $layout) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access visual console without id layout'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
$id_group = $layout['id_group'];
|
||||
$layout_name = $layout['name'];
|
||||
$background = $layout['background'];
|
||||
$bwidth = $layout['width'];
|
||||
$bheight = $layout['height'];
|
||||
|
||||
$pure_url = '&pure='.$config['pure'];
|
||||
|
||||
// ACL
|
||||
$vconsole_read = check_acl($config['id_user'], $id_group, 'VR');
|
||||
$vconsole_write = check_acl($config['id_user'], $id_group, 'VW');
|
||||
$vconsole_manage = check_acl($config['id_user'], $id_group, 'VM');
|
||||
|
||||
if (! $vconsole_read && !$vconsole_write && !$vconsole_manage) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access visual console without group access'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
// Render map
|
||||
$options = [];
|
||||
|
||||
$options['consoles_list']['text'] = '<a href="index.php?sec=network&sec2=godmode/reporting/map_builder&refr='.$refr.'">'.html_print_image(
|
||||
'images/visual_console.png',
|
||||
true,
|
||||
['title' => __('Visual consoles list')]
|
||||
).'</a>';
|
||||
|
||||
if ($vconsole_write || $vconsole_manage) {
|
||||
$url_base = 'index.php?sec=network&sec2=godmode/reporting/visual_console_builder&action=';
|
||||
|
||||
$hash = md5($config['dbpass'].$id_layout.$config['id_user']);
|
||||
|
||||
$options['public_link']['text'] = '<a href="'.ui_get_full_url(
|
||||
'operation/visual_console/public_console.php?hash='.$hash.'&id_layout='.$id_layout.'&id_user='.$config['id_user']
|
||||
).'" target="_blank">'.html_print_image(
|
||||
'images/camera_mc.png',
|
||||
true,
|
||||
['title' => __('Show link to public Visual Console')]
|
||||
).'</a>';
|
||||
$options['public_link']['active'] = false;
|
||||
|
||||
$options['data']['text'] = '<a href="'.$url_base.$action.'&tab=data&id_visual_console='.$id_layout.'">'.html_print_image(
|
||||
'images/op_reporting.png',
|
||||
true,
|
||||
['title' => __('Main data')]
|
||||
).'</a>';
|
||||
$options['list_elements']['text'] = '<a href="'.$url_base.$action.'&tab=list_elements&id_visual_console='.$id_layout.'">'.html_print_image(
|
||||
'images/list.png',
|
||||
true,
|
||||
['title' => __('List elements')]
|
||||
).'</a>';
|
||||
|
||||
if (enterprise_installed()) {
|
||||
$options['wizard_services']['text'] = '<a href="'.$url_base.$action.'&tab=wizard_services&id_visual_console='.$id_layout.'">'.html_print_image(
|
||||
'images/wand_services.png',
|
||||
true,
|
||||
['title' => __('Services wizard')]
|
||||
).'</a>';
|
||||
}
|
||||
|
||||
$options['wizard']['text'] = '<a href="'.$url_base.$action.'&tab=wizard&id_visual_console='.$id_layout.'">'.html_print_image(
|
||||
'images/wand.png',
|
||||
true,
|
||||
['title' => __('Wizard')]
|
||||
).'</a>';
|
||||
$options['editor']['text'] = '<a href="'.$url_base.$action.'&tab=editor&id_visual_console='.$id_layout.'">'.html_print_image(
|
||||
'images/builder.png',
|
||||
true,
|
||||
['title' => __('Builder')]
|
||||
).'</a>';
|
||||
}
|
||||
|
||||
$options['view']['text'] = '<a href="index.php?sec=network&sec2=operation/visual_console/render_view&id='.$id_layout.'&refr='.$view_refresh.'">'.html_print_image('images/operation.png', true, ['title' => __('View')]).'</a>';
|
||||
$options['view']['active'] = true;
|
||||
|
||||
if (!is_metaconsole()) {
|
||||
if (!$config['pure']) {
|
||||
$options['pure']['text'] = '<a href="index.php?sec=network&sec2=operation/visual_console/render_view&id='.$id_layout.'&refr='.$refr.'&pure=1">'.html_print_image('images/full_screen.png', true, ['title' => __('Full screen mode')]).'</a>';
|
||||
ui_print_page_header($layout_name, 'images/visual_console.png', false, '', false, $options);
|
||||
}
|
||||
|
||||
// Set the hidden value for the javascript
|
||||
html_print_input_hidden('metaconsole', 0);
|
||||
} else {
|
||||
// Set the hidden value for the javascript
|
||||
html_print_input_hidden('metaconsole', 1);
|
||||
}
|
||||
|
||||
if ($config['pure']) {
|
||||
// Container of the visual map (ajax loaded)
|
||||
echo '<div id="vc-container">'.visual_map_print_visual_map(
|
||||
$id_layout,
|
||||
true,
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
'',
|
||||
false,
|
||||
true
|
||||
).'</div>';
|
||||
|
||||
// Floating menu - Start
|
||||
echo '<div id="vc-controls" style="z-index: 999">';
|
||||
|
||||
echo '<div id="menu_tab">';
|
||||
echo '<ul class="mn">';
|
||||
|
||||
// Quit fullscreen
|
||||
echo '<li class="nomn">';
|
||||
echo '<a href="index.php?sec=network&sec2=operation/visual_console/render_view&id='.$id_layout.'&refr='.$refr.'">';
|
||||
echo html_print_image('images/normal_screen.png', true, ['title' => __('Back to normal mode')]);
|
||||
echo '</a>';
|
||||
echo '</li>';
|
||||
|
||||
// Countdown
|
||||
echo '<li class="nomn">';
|
||||
echo '<div class="vc-refr">';
|
||||
echo '<div class="vc-countdown"></div>';
|
||||
echo '<div id="vc-refr-form">';
|
||||
echo __('Refresh').':';
|
||||
echo html_print_select(get_refresh_time_array(), 'refr', $refr, '', '', 0, true, false, false);
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
echo '</li>';
|
||||
|
||||
// Console name
|
||||
echo '<li class="nomn">';
|
||||
echo '<div class="vc-title">'.$layout_name.'</div>';
|
||||
echo '</li>';
|
||||
|
||||
echo '</ul>';
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
// Floating menu - End
|
||||
ui_require_jquery_file('countdown');
|
||||
|
||||
?>
|
||||
<style type="text/css">
|
||||
/* Avoid the main_pure container 1000px height */
|
||||
body.pure {
|
||||
min-height: 100px;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
<?php
|
||||
echo 'background-color: '.$layout['background_color'].';';
|
||||
?>
|
||||
}
|
||||
div#main_pure {
|
||||
height: 100%;
|
||||
margin: 0px;
|
||||
<?php
|
||||
echo 'background-color: '.$layout['background_color'].';';
|
||||
?>
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
} else {
|
||||
visual_map_print_visual_map($id_layout, true, true, null, null, '', false, true, true);
|
||||
}
|
||||
|
||||
ui_require_javascript_file('wz_jsgraphics');
|
||||
ui_require_javascript_file('pandora_visual_console');
|
||||
$ignored_params['refr'] = '';
|
||||
?>
|
||||
|
||||
<style type="text/css">
|
||||
svg {
|
||||
stroke: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
$(document).ready (function () {
|
||||
var refr = <?php echo (int) $refr; ?>;
|
||||
var pure = <?php echo (int) $config['pure']; ?>;
|
||||
var href = "<?php echo ui_get_url_refresh($ignored_params); ?>";
|
||||
if (pure) {
|
||||
var startCountDown = function (duration, cb) {
|
||||
$('div.vc-countdown').countdown('destroy');
|
||||
if (!duration) return;
|
||||
var t = new Date();
|
||||
t.setTime(t.getTime() + duration * 1000);
|
||||
$('div.vc-countdown').countdown({
|
||||
until: t,
|
||||
format: 'MS',
|
||||
layout: '(%M%nn%M:%S%nn%S <?php echo __('Until refresh'); ?>) ',
|
||||
alwaysExpire: true,
|
||||
onExpiry: function () {
|
||||
$('div.vc-countdown').countdown('destroy');
|
||||
//cb();
|
||||
url = js_html_entity_decode( href ) + duration;
|
||||
$(document).attr ("location", url);
|
||||
/*$.post(window.location.href.replace("refr=300","refr="+new_count), function(respuestaSolicitud){
|
||||
$('#background_<?php echo $id_layout; ?>').html(respuestaSolicitud);
|
||||
});
|
||||
*/
|
||||
$("#main_pure").css('background-color','<?php echo $layout['background_color']; ?>');
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
startCountDown(refr, false);
|
||||
|
||||
var controls = document.getElementById('vc-controls');
|
||||
autoHideElement(controls, 1000);
|
||||
|
||||
$('select#refr').change(function (event) {
|
||||
refr = Number.parseInt(event.target.value, 10);
|
||||
new_count = event.target.value;
|
||||
startCountDown(refr, false);
|
||||
});
|
||||
}
|
||||
else {
|
||||
$('#refr').change(function () {
|
||||
$('#hidden-vc_refr').val($('#refr option:selected').val());
|
||||
});
|
||||
}
|
||||
|
||||
$(".module_graph .menu_graph").css('display','none');
|
||||
|
||||
$(".parent_graph").each( function() {
|
||||
if ($(this).css('background-color') != 'rgb(255, 255, 255)')
|
||||
$(this).css('color', '#999');
|
||||
});
|
||||
|
||||
$(".overlay").removeClass("overlay").addClass("overlaydisabled");
|
||||
|
||||
});
|
||||
|
||||
$(window).on('load', function () {
|
||||
$('.item:not(.icon) img:not(.b64img)').each( function() {
|
||||
if ($(this).css('float')=='left' || $(this).css('float')=='right') {
|
||||
if( $(this).parent()[0].tagName == 'DIV'){
|
||||
$(this).css('margin-top',(parseInt($(this).parent().css('height'))/2-parseInt($(this).css('height'))/2)+'px');
|
||||
}
|
||||
else if ( $(this).parent()[0].tagName == 'A') {
|
||||
$(this).css('margin-top',(parseInt($(this).parent().parent().css('height'))/2-parseInt($(this).css('height'))/2)+'px');
|
||||
}
|
||||
$(this).css('margin-left','');
|
||||
}
|
||||
else {
|
||||
if(parseInt($(this).parent().parent().css('width'))/2-parseInt($(this).css('width'))/2 < 0){
|
||||
$(this).css('margin-left','');
|
||||
$(this).css('margin-top','');
|
||||
} else {
|
||||
if( $(this).parent()[0].tagName == 'DIV'){
|
||||
$(this).css('margin-left',(parseInt($(this).parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
|
||||
}
|
||||
else if ( $(this).parent()[0].tagName == 'A') {
|
||||
$(this).css('margin-left',(parseInt($(this).parent().parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
|
||||
}
|
||||
$(this).css('margin-top','');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('.item > div').each( function() {
|
||||
if ($(this).css('float')=='left' || $(this).css('float')=='right') {
|
||||
if($(this).attr('id').indexOf('clock') || $(this).attr('id').indexOf('overlay')){
|
||||
$(this).css('margin-top',(parseInt($(this).parent().css('height'))/2-parseInt($(this).css('height'))/2)+'px');
|
||||
}
|
||||
else{
|
||||
$(this).css('margin-top',(parseInt($(this).parent().css('height'))/2-parseInt($(this).css('height'))/2-15)+'px');
|
||||
}
|
||||
$(this).css('margin-left','');
|
||||
}
|
||||
else {
|
||||
$(this).css('margin-left',(parseInt($(this).parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
|
||||
$(this).css('margin-top','');
|
||||
}
|
||||
});
|
||||
|
||||
$('.item > a > div').each( function() {
|
||||
if ($(this).css('float')=='left' || $(this).css('float')=='right') {
|
||||
$(this).css('margin-top',(parseInt($(this).parent().parent().css('height'))/2-parseInt($(this).css('height'))/2-5)+'px');
|
||||
$(this).css('margin-left','');
|
||||
}
|
||||
else {
|
||||
$(this).css('margin-left',(parseInt($(this).parent().parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
|
||||
$(this).css('margin-top','');
|
||||
}
|
||||
});
|
||||
|
||||
$(".graph:not([class~='noresizevc'])").each(function(){
|
||||
height = parseInt($(this).css("height")) - 30;
|
||||
$(this).css('height', height);
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue