Merge remote-tracking branch 'origin/develop' into ent-4705-encriptado-de-nuevos-tokens

This commit is contained in:
marcos 2020-02-17 16:15:29 +01:00
commit 7564249207
169 changed files with 49531 additions and 27115 deletions

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, AIX version
# Version 7.0NG.743, AIX version
# Licensed under GPL license v2,
# Copyright (c) 2003-2010 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, FreeBSD Version
# Version 7.0NG.743, FreeBSD Version
# Licensed under GPL license v2,
# Copyright (c) 2003-2010 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, HP-UX Version
# Version 7.0NG.743, HP-UX Version
# Licensed under GPL license v2,
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, GNU/Linux
# Version 7.0NG.743, GNU/Linux
# Licensed under GPL license v2,
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, GNU/Linux
# Version 7.0NG.743, GNU/Linux
# Licensed under GPL license v2,
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, Solaris Version
# Version 7.0NG.743, Solaris Version
# Licensed under GPL license v2,
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,6 +1,6 @@
# Base config file for Pandora FMS Windows Agent
# (c) 2006-2010 Artica Soluciones Tecnologicas
# Version 7.0NG.742
# Version 7.0NG.743
# 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

View File

@ -1,6 +1,6 @@
# Fichero de configuracion base de agentes de Pandora
# Base config file for Pandora agents
# Version 7.0NG.742, AIX version
# Version 7.0NG.743, AIX version
# General Parameters
# ==================

View File

@ -1,6 +1,6 @@
# Fichero de configuracion base de agentes de Pandora
# Base config file for Pandora agents
# Version 7.0NG.742
# Version 7.0NG.743
# FreeBSD/IPSO version
# Licenced under GPL licence, 2003-2007 Sancho Lerena

View File

@ -1,6 +1,6 @@
# Fichero de configuracion base de agentes de Pandora
# Base config file for Pandora agents
# Version 7.0NG.742, HPUX Version
# Version 7.0NG.743, HPUX Version
# General Parameters
# ==================

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742
# Version 7.0NG.743
# Licensed under GPL license v2,
# (c) 2003-2010 Artica Soluciones Tecnologicas
# please visit http://pandora.sourceforge.net

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742
# Version 7.0NG.743
# Licensed under GPL license v2,
# (c) 2003-2009 Artica Soluciones Tecnologicas
# please visit http://pandora.sourceforge.net

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742
# Version 7.0NG.743
# Licensed under GPL license v2,
# please visit http://pandora.sourceforge.net

View File

@ -1,6 +1,6 @@
# Fichero de configuracion base de agentes de Pandora
# Base config file for Pandora agents
# Version 7.0NG.742, Solaris version
# Version 7.0NG.743, Solaris version
# General Parameters
# ==================

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, AIX version
# Version 7.0NG.743, AIX version
# Licensed under GPL license v2,
# Copyright (c) 2003-2010 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
package: pandorafms-agent-unix
Version: 7.0NG.742-200128
Version: 7.0NG.743-200217
Architecture: all
Priority: optional
Section: admin

View File

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
pandora_version="7.0NG.742-200128"
pandora_version="7.0NG.743-200217"
echo "Test if you has the tools for to make the packages."
whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, GNU/Linux
# Version 7.0NG.743, GNU/Linux
# Licensed under GPL license v2,
# Copyright (c) 2003-2012 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, FreeBSD Version
# Version 7.0NG.743, FreeBSD Version
# Licensed under GPL license v2,
# Copyright (c) 2003-2016 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, HP-UX Version
# Version 7.0NG.743, HP-UX Version
# Licensed under GPL license v2,
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, GNU/Linux
# Version 7.0NG.743, GNU/Linux
# Licensed under GPL license v2,
# Copyright (c) 2003-2014 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, GNU/Linux
# Version 7.0NG.743, GNU/Linux
# Licensed under GPL license v2,
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, NetBSD Version
# Version 7.0NG.743, NetBSD Version
# Licensed under GPL license v2,
# Copyright (c) 2003-2010 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -1,5 +1,5 @@
# Base config file for Pandora FMS agents
# Version 7.0NG.742, Solaris Version
# Version 7.0NG.743, Solaris Version
# Licensed under GPL license v2,
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
# http://www.pandorafms.com

View File

@ -54,8 +54,8 @@ my $Sem = undef;
# Semaphore used to control the number of threads
my $ThreadSem = undef;
use constant AGENT_VERSION => '7.0NG.742';
use constant AGENT_BUILD => '200128';
use constant AGENT_VERSION => '7.0NG.743';
use constant AGENT_BUILD => '200217';
# Agent log default file size maximum and instances
use constant DEFAULT_MAX_LOG_SIZE => 600000;

View File

@ -2,8 +2,8 @@
#Pandora FMS Linux Agent
#
%define name pandorafms_agent_unix
%define version 7.0NG.742
%define release 200128
%define version 7.0NG.743
%define release 200217
Summary: Pandora FMS Linux agent, PERL version
Name: %{name}

View File

@ -2,8 +2,8 @@
#Pandora FMS Linux Agent
#
%define name pandorafms_agent_unix
%define version 7.0NG.742
%define release 200128
%define version 7.0NG.743
%define release 200217
Summary: Pandora FMS Linux agent, PERL version
Name: %{name}

View File

@ -9,8 +9,8 @@
# Please see http://www.pandorafms.org. This code is licensed under GPL 2.0 license.
# **********************************************************************
PI_VERSION="7.0NG.742"
PI_BUILD="200128"
PI_VERSION="7.0NG.743"
PI_BUILD="200217"
OS_NAME=`uname -s`
FORCE=0

View File

@ -1,6 +1,6 @@
# Base config file for Pandora FMS Windows Agent
# (c) 2006-2017 Artica Soluciones Tecnologicas
# Version 7.0NG.742
# Version 7.0NG.743
# 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

View File

@ -3,7 +3,7 @@ AllowLanguageSelection
{Yes}
AppName
{Pandora FMS Windows Agent v7.0NG.742}
{Pandora FMS Windows Agent v7.0NG.743}
ApplicationID
{17E3D2CF-CA02-406B-8A80-9D31C17BD08F}
@ -186,7 +186,7 @@ UpgradeApplicationID
{}
Version
{200128}
{200217}
ViewReadme
{Yes}

View File

@ -30,7 +30,7 @@ using namespace Pandora;
using namespace Pandora_Strutils;
#define PATH_SIZE _MAX_PATH+1
#define PANDORA_VERSION ("7.0NG.742(Build 200128)")
#define PANDORA_VERSION ("7.0NG.743(Build 200217)")
string pandora_path;
string pandora_dir;

View File

@ -11,7 +11,7 @@ BEGIN
VALUE "LegalCopyright", "Artica ST"
VALUE "OriginalFilename", "PandoraAgent.exe"
VALUE "ProductName", "Pandora FMS Windows Agent"
VALUE "ProductVersion", "(7.0NG.742(Build 200128))"
VALUE "ProductVersion", "(7.0NG.743(Build 200217))"
VALUE "FileVersion", "1.0.0.0"
END
END

View File

@ -0,0 +1,2 @@
# pandora disable listing
Options -Indexes

View File

@ -1,5 +1,5 @@
package: pandorafms-console
Version: 7.0NG.742-200128
Version: 7.0NG.743-200217
Architecture: all
Priority: optional
Section: admin

View File

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
pandora_version="7.0NG.742-200128"
pandora_version="7.0NG.743-200217"
package_pear=0
package_pandora=1

View File

@ -1,3 +1,11 @@
Order deny,allow
Deny from All
#Order deny,allow
#Deny from All
#Allow from localhost
#pandora disable phpexec
<FilesMatch "\.(txt|php)$">
Deny from all
Allow from localhost
</FilesMatch>
php_flag engine off

View File

@ -801,31 +801,37 @@ function mainAgentsModules()
$link = "winopeng('".'operation/agentes/stat_win.php?'."type=$graph_type&".'period='.SECONDS_1DAY.'&'.'id='.$module_id.'&'.'refresh='.SECONDS_10MINUTES."', 'day_".$win_handle."')";
echo '<a href="javascript:'.$link.'">';
$module_last_value = modules_get_last_value($module_id);
if (!is_numeric($module_last_value)) {
$module_last_value = htmlspecialchars($module_last_value);
}
switch ($status) {
case AGENT_MODULE_STATUS_NORMAL:
ui_print_status_image('module_ok.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_ok.png', $module_last_value, false);
break;
case AGENT_MODULE_STATUS_CRITICAL_BAD:
ui_print_status_image('module_critical.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_critical.png', $module_last_value, false);
break;
case AGENT_MODULE_STATUS_WARNING:
ui_print_status_image('module_warning.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_warning.png', $module_last_value, false);
break;
case AGENT_MODULE_STATUS_UNKNOWN:
ui_print_status_image('module_unknown.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_unknown.png', $module_last_value, false);
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
ui_print_status_image('module_alertsfired.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_alertsfired.png', $module_last_value, false);
break;
case 4:
ui_print_status_image('module_no_data.png', modules_get_last_value($module_id), false);
ui_print_status_image('module_no_data.png', $module_last_value, false);
break;
}

View File

@ -1334,7 +1334,7 @@ ALTER TABLE `tmap` MODIFY COLUMN `id_user` varchar(250) NOT NULL DEFAULT '';
INSERT INTO `tconfig` (`token`, `value`) VALUES ('big_operation_step_datos_purge', '100');
INSERT INTO `tconfig` (`token`, `value`) VALUES ('small_operation_step_datos_purge', '1000');
INSERT INTO `tconfig` (`token`, `value`) VALUES ('days_autodisable_deletion', '30');
INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 34);
INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 35);
INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_docs_logo', 'default_docs.png');
INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_support_logo', 'default_support.png');
INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_logo_white_bg_preview', 'pandora_logo_head_white_bg.png');

View File

@ -78,6 +78,23 @@
#opacity{
background:black;opacity:0.1;left:0px;top:0px;width:100%;height:100%;
background:black;
opacity:0.1;
left:0px;
top:0px;
width:100%;
height:100%;
position: fixed;
z-index: 1;
}
img.modalclose {
text-align: right;
float: right;
padding-right: 11px;
padding-top: 11px;
vertical-align: middle;
cursor:pointer;
}
</style>
@ -89,6 +106,7 @@ background:black;opacity:0.1;left:0px;top:0px;width:100%;height:100%;
<span class='modalheadertex'>
<?php echo __('Database error'); ?>
</span>
<img class='modalclose' src='<?php echo $config['homeurl']; ?>images/icono_cerrar.png'>
</div>
<div class='modalconten'>
@ -122,7 +140,7 @@ background:black;opacity:0.1;left:0px;top:0px;width:100%;height:100%;
echo '
<a href="'.ui_get_full_external_url($docs_url).'" target="_blank">
<div class="modalwikibutto cerrar">
<div class="modalwikibutto">
<span class="modalwikibuttontex">'.__('Documentation').'
</span>
</div>
@ -140,3 +158,12 @@ background:black;opacity:0.1;left:0px;top:0px;width:100%;height:100%;
</body>
</html>
<script>
$(".modalclose").click(function(){
$('div#alert_messages_na').toggle();
$('div#opacity').toggle();
});
</script>

View File

@ -830,9 +830,16 @@ foreach ($modules as $module) {
$data[4] .= ui_print_help_tip(__('The policy modules of data type will only update their intervals when policy is applied.'), true);
}
$data[5] = ui_print_truncate_text($module['descripcion'], 'description', false);
$data[6] = ui_print_status_image($status, $title, true);
if ($module['id_modulo'] == MODULE_DATA && $module['id_policy_module'] != 0) {
$module_description = utf8_decode($module['descripcion']);
} else {
$module_description = $module['descripcion'];
}
$data[5] = ui_print_truncate_text($module_description, 'description', false);
$data[6] = ui_print_status_image($status, htmlspecialchars($title), true);
// MAX / MIN values
if ($module['id_tipo_modulo'] != 25) {

View File

@ -320,7 +320,7 @@ if (check_acl($config['id_user'], 0, 'PM')) {
$sub2['godmode/setup/setup&amp;section=websocket_engine']['refr'] = 0;
if ($config['activate_gis']) {
$sub2['godmode/setup/gis']['text'] = __('Map conections GIS');
$sub2['godmode/setup/setup&amp;section=gis']['text'] = __('Map conections GIS');
}
$sub['general']['sub2'] = $sub2;

View File

@ -191,12 +191,8 @@ switch ($action) {
case 'top_n':
case 'exception':
case 'general':
case 'network_interfaces_report':
case 'availability':
case 'event_report_log':
case 'increment':
case 'availability_graph':
case 'agent_module':
$get_data_editor = true;
break;
@ -3857,6 +3853,7 @@ $(document).ready (function () {
case 'historical_data':
case 'agent_configuration':
case 'module_histogram_graph':
case 'event_report_log':
case 'increment':
if ($("#hidden-id_agent").val() == 0) {
dialog_message('#message_no_agent');

View File

@ -455,7 +455,7 @@ foreach ($items as $item) {
if ($item['type'] == 'custom_graph') {
$custom_graph_name = db_get_row_sql('SELECT name FROM tgraph WHERE id_graph = '.$item['id_gs']);
$row[1] = get_report_name($item['type']).' ('.$custom_graph_name['name'].')';
$row[1] = get_report_name($item['type']).' ('.io_safe_output($custom_graph_name['name']).')';
}

View File

@ -203,7 +203,7 @@ foreach ($layoutDatas as $layoutData) {
$table->data[($i + 1)]['icon'] = html_print_image(
'images/auto_sla_graph.png',
true,
['title' => __('Auto SLA Graph')]
['title' => __('Event history graph')]
);
break;

View File

@ -761,7 +761,7 @@ $buttons['consoles_list'] = [
];
$buttons['public_link'] = [
'active' => false,
'text' => '<a href="'.ui_get_full_url('operation/visual_console/public_console.php?hash='.$hash.'&id_layout='.$idVisualConsole.'&id_user='.$config['id_user']).'">'.html_print_image('images/camera_mc.png', true, ['title' => __('Show link to public Visual Console')]).'</a>',
'text' => '<a href="'.ui_get_full_url('operation/visual_console/public_console.php?hash='.$hash.'&refr='.$refr.'&id_layout='.$idVisualConsole.'&id_user='.$config['id_user']).'">'.html_print_image('images/camera_mc.png', true, ['title' => __('Show link to public Visual Console')]).'</a>',
];
$buttons['data'] = [
'active' => false,

View File

@ -28,15 +28,6 @@ require_once 'include/functions_gis.php';
ui_require_javascript_file('openlayers.pandora');
// Header.
ui_print_page_header(
__('Map conections GIS'),
'',
false,
'',
true
);
$action = get_parameter('action');
switch ($action) {
@ -88,7 +79,7 @@ if ($mapsConnections !== false) {
$table->data[] = [
'<a href="index.php?sec=gsetup&sec2=godmode/setup/gis_step_2&amp;action=edit_connection_map&amp;id_connection_map='.$mapsConnection['id_tmap_connection'].'">'.$mapsConnection['conection_name'].'</a>',
ui_print_group_icon($mapsConnection['group_id'], true),
'<a href="index.php?sec=gsetup&sec2=godmode/setup/gis&amp;id_connection_map='.$mapsConnection['id_tmap_connection'].'&amp;action=delete_connection"
'<a href="index.php?sec=gsetup&sec2=godmode/setup/setup&amp;section=gis&amp;id_connection_map='.$mapsConnection['id_tmap_connection'].'&amp;action=delete_connection"
onClick="javascript: if (!confirm(\''.__('Do you wan delete this connection?').'\')) return false;">'.html_print_image('images/cross.png', true).'</a>',
];
$table->cellclass[][2] = 'action_buttons';

View File

@ -26,6 +26,10 @@ if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user
require_once 'include/functions_gis.php';
$buttons['gis'] = [
'text' => '<a href="'.ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup&section=gis').'">'.html_print_image('images/list.png', true, ['title' => __('GIS Maps connections')]).'</a>',
];
$action = get_parameter('action', 'create_connection_map');
if (is_ajax()) {
@ -41,7 +45,8 @@ switch ($action) {
'',
false,
'',
true
true,
$buttons
);
$mapConnection_name = '';
@ -67,7 +72,8 @@ switch ($action) {
'',
false,
'',
true
true,
$buttons
);
$idConnectionMap = get_parameter('id_connection_map');

View File

@ -138,6 +138,13 @@ $buttons['websocket_engine'] = [
'text' => '<a href="'.ui_get_full_url('index.php?sec=gsetup&sec2=godmode/setup/setup&section=websocket_engine').'">'.html_print_image('images/websocket_small.png', true, ['title' => __('Websocket engine')]).'</a>',
];
if ($config['activate_gis']) {
$buttons['gis'] = [
'active' => false,
'text' => '<a href="'.ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup&section=gis').'">'.html_print_image('images/gis_tab.png', true, ['title' => __('GIS Map connection')]).'</a>',
];
}
$help_header = '';
if (enterprise_installed()) {
$subpage = setup_enterprise_add_subsection_main($section, $buttons, $help_header);
@ -183,6 +190,11 @@ switch ($section) {
$help_header = 'setup_integria_tab';
break;
case 'gis':
$buttons['gis']['active'] = true;
$subpage = ' &raquo '.__('Map conections GIS');
break;
case 'notifications':
$buttons['notifications']['active'] = true;
$subpage = ' &raquo '.__('Notifications');
@ -254,6 +266,10 @@ switch ($section) {
include_once $config['homedir'].'/godmode/setup/setup_integria.php';
break;
case 'gis':
include_once $config['homedir'].'/godmode/setup/gis.php';
break;
case 'notifications':
include_once $config['homedir'].'/godmode/setup/setup_notifications.php';
break;

View File

@ -262,9 +262,9 @@ if ($create_user) {
$password_confirm = '';
$new_user = true;
} else {
$have_number = false;
$have_simbols = false;
if ($config['enable_pass_policy']) {
$have_number = true;
$have_simbols = true;
if ($config['pass_needs_numbers']) {
$nums = preg_match('/([[:alpha:]])*(\d)+(\w)*/', $password_confirm);
if ($nums == 0) {
@ -273,8 +273,7 @@ if ($create_user) {
$password_new = '';
$password_confirm = '';
$new_user = true;
} else {
$have_number = true;
$have_number = false;
}
}
@ -286,24 +285,13 @@ if ($create_user) {
$password_new = '';
$password_confirm = '';
$new_user = true;
} else {
$have_simbols = true;
$have_simbols = false;
}
}
if ($config['pass_needs_symbols'] && $config['pass_needs_numbers']) {
if ($have_number && $have_simbols) {
$result = create_user($id, $password_new, $values);
}
} else if ($config['pass_needs_symbols'] && !$config['pass_needs_numbers']) {
if ($have_simbols) {
$result = create_user($id, $password_new, $values);
}
} else if (!$config['pass_needs_symbols'] && $config['pass_needs_numbers']) {
if ($have_number) {
$result = create_user($id, $password_new, $values);
}
}
} else {
$result = create_user($id, $password_new, $values);
}

View File

@ -504,8 +504,8 @@ foreach ($info as $user_id => $user_info) {
foreach ($result as $row) {
$data[4] .= "<div style='float:left;'>";
$data[4] .= profile_get_name($row['id_perfil']);
$data[4] .= '</div>';
$data[4] .= "<div style='float:right; padding-right:10px;'>";
$data[4] .= ' / </div>';
$data[4] .= "<div style='float:left; padding-left:5px;'>";
$data[4] .= groups_get_name($row['id_grupo'], true);
$data[4] .= '</div>';
$data[4] .= '<br />';

View File

@ -0,0 +1,5 @@
#pandora disable phpexec
<Files *.php>
Deny from all
</Files>
php_flag engine off

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B

View File

@ -1004,8 +1004,14 @@ if (check_login()) {
$data[3] .= ' <a class="relations_details" href="ajax.php?page=operation/agentes/estado_monitores&get_relations_tooltip=1&id_agente_modulo='.$module['id_agente_modulo'].'">'.html_print_image('images/link2.png', true, ['id' => 'relations-details-'.$module['id_agente_modulo'], 'class' => 'img_help']).'</a> ';
}
$module_description = '';
if ($module['id_modulo'] == MODULE_DATA && $module['id_policy_module'] != 0) {
$module_description = utf8_decode($module['descripcion']);
} else {
$module_description = $module['descripcion'];
}
$data[4] = ui_print_string_substr($module['descripcion'], 60, true, 8);
$data[4] = ui_print_string_substr($module_description, 60, true, 8);
if ($module['datos'] != strip_tags($module['datos'])) {
@ -1022,7 +1028,7 @@ if (check_login()) {
$title
);
$data[5] = ui_print_status_image($status, $title, true);
$data[5] = ui_print_status_image($status, htmlspecialchars($title), true);
if (!$show_context_help_first_time) {
$show_context_help_first_time = true;

View File

@ -160,16 +160,17 @@ if (file_exists('languages/'.$user_language.'.mo') === true) {
<script language="javascript" type="text/javascript" src="graphs/flot/jquery.flot.axislabels.js"></script>
<script language="javascript" type="text/javascript" src="graphs/flot/pandora.flot.js"></script>
</head>
<body bgcolor="#ffffff" style='background:#ffffff;'>
<body style='background-color: <?php echo $params['backgroundColor']; ?>;'>
<?php
$params['only_image'] = false;
$params['width'] = (int) $_REQUEST['viewport_width'];
$params['menu'] = false;
$params_combined = json_decode($_REQUEST['data_combined'], true);
$module_list = json_decode($_REQUEST['data_module_list'], true);
$type_graph_pdf = $_REQUEST['type_graph_pdf'];
if ($params['vconsole'] === false) {
$params['width'] = (int) $_REQUEST['viewport_width'];
if ((isset($params['width']) === false
|| ($params['width'] <= 0))
) {
@ -183,6 +184,7 @@ if (file_exists('languages/'.$user_language.'.mo') === true) {
$params['height'] = 70;
}
}
}
echo '<div>';
switch ($type_graph_pdf) {
@ -291,7 +293,8 @@ if (file_exists('languages/'.$user_language.'.mo') === true) {
$params['not_interactive'],
$params['ttl'],
$params['widgets'],
$params['show']
$params['show'],
$params['date_to']
);
break;

File diff suppressed because it is too large Load Diff

View File

@ -226,6 +226,13 @@ class NetworkMap
*/
public $tooltipParams;
/**
* Defines if map is widget or not for JS
*
* @var boolean;
*/
public $widget;
/**
* Shows the map using 100% of height and width if is a widget.
*
@ -406,8 +413,10 @@ class NetworkMap
// Initialize as widget?
if (isset($options['widget'])) {
$this->fullSize = (bool) $options['widget'];
$this->widget = true;
} else {
$this->fullSize = true;
$this->widget = false;
}
// Use a custom parser.
@ -2689,6 +2698,7 @@ class NetworkMap
$this->cleanGraphRelations();
// Print some params to handle it in js.
html_print_input_hidden('widget', $this->widget);
html_print_input_hidden('product_name', get_product_name());
html_print_input_hidden('center_logo', ui_get_full_url(ui_get_logo_to_center_networkmap()));

View File

@ -123,7 +123,7 @@ class Tree
return '';
}
return " AND tam.nombre LIKE '%%".$this->filter['searchModule']."%%' ";
return " AND tam.nombre LIKE '%%".str_replace('%', '%%', $this->filter['searchModule'])."%%' ";
}
@ -133,7 +133,7 @@ class Tree
return '';
}
return " AND LOWER(ta.alias) LIKE LOWER('%%".$this->filter['searchAgent']."%%')";
return " AND LOWER(ta.alias) LIKE LOWER('%%".str_replace('%', '%%', $this->filter['searchAgent'])."%%')";
}
@ -331,7 +331,7 @@ class Tree
return '';
}
return " AND tg.nombre LIKE '%%".$this->filter['searchGroup']."%%'";
return " AND tg.nombre LIKE '%%".str_replace('%', '%%', $this->filter['searchGroup'])."%%'";
}
@ -623,7 +623,7 @@ class Tree
}
}
$module['statusImageHTML'] = ui_print_status_image($statusType, $statusTitle, true);
$module['statusImageHTML'] = ui_print_status_image($statusType, htmlspecialchars($statusTitle), true);
// HTML of the server type image
$module['serverTypeHTML'] = servers_show_type($module['server_type']);

View File

@ -154,7 +154,7 @@ class WelcomeWindow extends Wizard
target: $('#welcome_modal_window'),
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
modal: {
title: "<?php echo __('Welcome to Pandora FMS'); ?>",
title: "<?php echo __('Welcome to').' '.io_safe_output(get_product_name()); ?>",
cancel: '<?php echo __('Do not show anymore'); ?>',
ok: '<?php echo __('Close'); ?>'
},

View File

@ -20,8 +20,8 @@
/**
* Pandora build version and version
*/
$build_version = 'PC200128';
$pandora_version = 'v7.0NG.742';
$build_version = 'PC200217';
$pandora_version = 'v7.0NG.743';
// Do not overwrite default timezone set if defined.
$script_tz = @date_default_timezone_get();

View File

@ -102,9 +102,9 @@ define('SECONDS_1MONTH', 2592000);
define('SECONDS_2MONTHS', 5184000);
define('SECONDS_3MONTHS', 7776000);
define('SECONDS_6MONTHS', 15552000);
define('SECONDS_1YEAR', 31104000);
define('SECONDS_2YEARS', 62208000);
define('SECONDS_3YEARS', 93312000);
define('SECONDS_1YEAR', 31536000);
define('SECONDS_2YEARS', 63072000);
define('SECONDS_3YEARS', 94608000);

View File

@ -3874,6 +3874,7 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined=false
$width_img = 500;
if ($params['vconsole'] === false) {
// Set height image.
$height_img = 170;
$params['height'] = 170;
@ -3886,6 +3887,9 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined=false
$width_img = 360;
$height_img = 70;
}
} else {
$height_img = $params['height'];
}
$params_encode_json = urlencode(json_encode($params));
@ -3926,8 +3930,14 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined=false
*/
function get_product_name()
{
global $config;
$stored_name = enterprise_hook('enterprise_get_product_name');
if (empty($stored_name) || $stored_name == ENTERPRISE_NOT_HOOK) {
if ($config['rb_product_name_alt']) {
return $config['rb_product_name_alt'];
}
return 'Pandora FMS';
}

View File

@ -301,11 +301,16 @@ function isInACL($ip)
// example lab.artica.es without '*'
$name = [];
$name = gethostbyname($acl_ip);
if (preg_match('/'.$name.'/', $ip)) {
if (preg_match('/'.$name.'/', $ip, $matches)) {
// This is for false matches, like '' or $.
if (count($matches) == 1 && $matches[0] == '') {
continue;
} else {
return true;
}
}
}
}
return false;
}
@ -12190,7 +12195,7 @@ function api_set_create_event($id, $trash1, $other, $returnType)
$id_agent = $other['data'][2];
if (is_metaconsole()) {
// On metaconsole, connect with the node to check the permissions
$agent_cache = db_get_row('tmetaconsole_agent', 'id_agente', $id_agent);
$agent_cache = db_get_row('tmetaconsole_agent', 'id_tagente', $id_agent);
if ($agent_cache === false) {
returnError('id_not_found', 'string');
return;
@ -12367,7 +12372,7 @@ function api_set_create_event($id, $trash1, $other, $returnType)
$return,
$user_comment,
'Added comment',
defined('METACONSOLE'),
is_metaconsole(),
$config['history_db_enabled']
);
if ($other['data'][13] != '') {
@ -12379,7 +12384,7 @@ function api_set_create_event($id, $trash1, $other, $returnType)
$return,
$owner_user,
true,
defined('METACONSOLE'),
is_metaconsole(),
$config['history_db_enabled']
);
}

View File

@ -2231,7 +2231,7 @@ function events_create_event(
}
$table_events = 'tevento';
if (defined('METACONSOLE')) {
if (is_metaconsole()) {
$table_events = 'tmetaconsole_event';
$sql = sprintf(
@ -3647,7 +3647,7 @@ function events_get_response_target(
$ip = db_get_value_filter('direccion', $agente_table_name, $filter);
// If agent has not an IP, display N/A.
if ($ip === false) {
if ($ip === false || $ip === '') {
$ip = __('N/A');
}
@ -4719,7 +4719,7 @@ function events_page_comments($event, $ajax=false)
foreach ($comm as $c) {
$data[0] = '<b>'.$c['action'].' by '.$c['id_user'].'</b>';
$data[0] .= '<br><br><i>'.date($config['date_format'], $c['utimestamp']).'</i>';
$data[1] = '<p style="word-break: break-word;">'.$c['comment'].'</p>';
$data[1] = '<p style="word-break: break-word;">'.stripslashes(str_replace(['\n', '\r'], '<br/>', $c['comment'])).'</p>';
$table_comments->data[] = $data;
}
break;

View File

@ -195,7 +195,7 @@ function forecast_projection_graph(
$now = time();
// Check that exec time is not greater than half max exec server time
if ($max_exec_time !== false) {
if ($max_exec_time != false) {
if (($begin_time + ($max_exec_time / 2)) < $now) {
return false;
}
@ -214,15 +214,17 @@ function forecast_projection_graph(
// Using this function for prediction_date
if ($prediction_period == false) {
// These statements stop the prediction when interval is greater than 2 years
if (($current_ts - $last_timestamp) >= 94608000) {
if (($current_ts - $last_timestamp) >= 94608000
|| $max_value == $min_value
) {
return false;
}
// Found it
if (($max_value >= $output_data[$idx][0])
if (($max_value >= $output_data[$idx][1])
&& ($min_value <= $output_data[$idx][0])
) {
return $current_ts;
return ($current_ts + ($sum_diff_dates * $agent_interval));
}
} else if ($current_ts > $limit_timestamp) {
$in_range = false;

View File

@ -2840,7 +2840,8 @@ function graph_sla_slicebar(
true,
$ttl,
false,
false
false,
$date
);
}
@ -3904,7 +3905,7 @@ function graph_graphic_agentevents($id_agent, $width, $height, $period=0, $homeu
* @param string homeurl
* @param bool return or echo the result
*/
function graph_graphic_moduleevents($id_agent, $id_module, $width, $height, $period=0, $homeurl, $return=false)
function graph_graphic_moduleevents($id_agent, $id_module, $width, $height, $period=0, $homeurl, $return=false, $ttl=1)
{
global $config;
global $graphic_type;
@ -3980,7 +3981,7 @@ function graph_graphic_moduleevents($id_agent, $id_module, $width, $height, $per
$out = flot_slicesbar_graph(
$data,
$period,
100,
$width,
$height,
$full_legend,
$colors,
@ -3993,7 +3994,8 @@ function graph_graphic_moduleevents($id_agent, $id_module, $width, $height, $per
$id_agent,
[],
true,
1
$ttl,
true
);
if ($return) {

View File

@ -1685,6 +1685,8 @@ function html_print_input_number(array $settings):string
'required',
'pattern',
'autocomplete',
'min',
'max',
];
$output = '';
@ -1904,10 +1906,15 @@ function html_print_input_hidden_extended(
*
* @return string HTML code if return parameter is true.
*/
function html_print_input_color($name, $value, $class=false, $return=false)
function html_print_input_color($name, $value, $id='', $class=false, $return=false)
{
$attr_type = 'type="color"';
if (empty($id) === true) {
$attr_id = 'id="color-'.htmlspecialchars($name, ENT_QUOTES).'"';
} else {
$attr_id = 'id="'.$id.'"';
}
$attr_name = 'name="'.htmlspecialchars($name, ENT_QUOTES).'"';
$attr_value = 'value="'.htmlspecialchars($value, ENT_QUOTES).'"';
$attr_class = 'class="'.($class !== false ? htmlspecialchars($class, ENT_QUOTES) : '').'"';
@ -3380,6 +3387,11 @@ function html_print_input($data, $wrapper='div', $input_only=false)
}
}
if (isset($data['wrapper']) === true) {
$output = '<'.$data['wrapper'].' id="wr_'.$data['name'].'" ';
$output .= ' class="'.$data['input_class'].'">';
}
switch ($data['type']) {
case 'text':
$output .= html_print_input_text(
@ -3490,6 +3502,7 @@ function html_print_input($data, $wrapper='div', $input_only=false)
$output .= html_print_input_color(
$data['name'],
$data['value'],
$data['id'],
((isset($data['class']) === true) ? $data['class'] : false),
((isset($data['return']) === true) ? $data['return'] : false)
);
@ -3663,11 +3676,157 @@ function html_print_input($data, $wrapper='div', $input_only=false)
$output .= html_print_input_multicheck($data);
break;
case 'autocomplete_agent':
$agent_name = '';
if (isset($data['id_agent_hidden']) === true
&& empty($data['id_agent_hidden']) === false
) {
if (is_metaconsole() === true) {
$connection = metaconsole_get_connection_by_id(
$data['server_id_hidden']
);
$agent_name = '';
if (metaconsole_load_external_db($connection) == NOERR) {
$agent_name = db_get_value_filter(
'alias',
'tagente',
['id_agente' => $data['id_agent_hidden']]
);
}
// Append server name.
if (!empty($agent_name)) {
$agent_name .= ' ('.$connection['server_name'].')';
}
// Restore db connection.
metaconsole_restore_db();
} else {
$agent_name = agents_get_alias($data['id_agent_hidden']);
}
}
$params = [];
$params['return'] = $data['return'];
$params['show_helptip'] = false;
$params['input_name'] = $data['name'];
$params['value'] = $agent_name;
$params['javascript_is_function_select'] = true;
if (isset($data['module_input']) === true
&& $data['module_input'] === true
) {
$params['selectbox_id'] = $data['module_name'];
$params['add_none_module'] = $data['module_none'];
}
$params['use_hidden_input_idagent'] = true;
$params['hidden_input_idagent_id'] = 'hidden-'.$data['name_agent_hidden'];
if (is_metaconsole()) {
$params['use_input_id_server'] = true;
$params['input_id_server_id'] = 'hidden-'.$data['name_server_hidden'];
$params['metaconsole_enabled'] = true;
}
$output .= html_print_input_hidden(
$data['name_agent_hidden'],
$data['id_agent_hidden'],
$data['return']
);
$output .= html_print_input_hidden(
$data['name_server_hidden'],
$data['server_id_hidden'],
$data['return']
);
$output .= ui_print_agent_autocomplete_input($params);
break;
case 'autocomplete_module':
// Module.
if (($data['agent_id'] === false
|| empty($data['agent_id']) === true)
&& (isset($data['selected']) === false
|| $data['selected'] === 0)
) {
$fields = [
0 => __('Select an Agent first'),
];
} else {
$sql = sprintf(
'SELECT id_agente_modulo, nombre
FROM tagente_modulo
WHERE id_agente = %d
AND delete_pending = 0',
$data['agent_id']
);
if (is_metaconsole() === true) {
$connection = metaconsole_get_connection_by_id(
$data['metaconsole_id']
);
if (metaconsole_load_external_db($connection) == NOERR) {
$modules_agent = db_get_all_rows_sql($sql);
if ($modules_agent === false) {
$modules_agent = [];
}
}
// Restore db connection.
metaconsole_restore_db();
} else {
$modules_agent = db_get_all_rows_sql($sql);
}
$fields = [];
if (isset($modules_agent) === true
&& is_array($modules_agent) === true
) {
$fields = array_reduce(
$modules_agent,
function ($carry, $item) {
$carry[$item['id_agente_modulo']] = $item['nombre'];
return $carry;
},
[]
);
}
}
$output .= html_print_select(
$fields,
$data['name'],
((isset($data['selected']) === true) ? $data['selected'] : ''),
((isset($data['script']) === true) ? $data['script'] : ''),
((isset($data['nothing']) === true) ? $data['nothing'] : ''),
((isset($data['nothing_value']) === true) ? $data['nothing_value'] : 0),
((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['multiple']) === true) ? $data['multiple'] : false),
((isset($data['sort']) === true) ? $data['sort'] : true),
((isset($data['class']) === true) ? $data['class'] : ''),
((isset($data['disabled']) === true) ? $data['disabled'] : false),
((isset($data['style']) === true) ? $data['style'] : false),
((isset($data['option_style']) === true) ? $data['option_style'] : false),
((isset($data['size']) === true) ? $data['size'] : false),
((isset($data['modal']) === true) ? $data['modal'] : false),
((isset($data['message']) === true) ? $data['message'] : ''),
((isset($data['select_all']) === true) ? $data['select_all'] : false)
);
break;
default:
// Ignore.
break;
}
if (isset($data['wrapper']) === true) {
$output .= '</'.$data['wrapper'].'>';
}
if ($data['label'] && $input_only === false) {
$output .= '</'.$wrapper.'>';
if (!$data['return']) {
@ -3817,3 +3976,25 @@ function html_print_autocomplete_users_from_integria(
echo $output;
}
}
function html_print_tabs(array $tabs)
{
$result = '<div id="html-tabs">';
$result .= '<ul class="">';
foreach ($tabs as $key => $value) {
$result .= "<li><a href='".$value['href']."' id='".$value['id']."'>";
$result .= html_print_image(
'images/'.$value['img'],
true
);
$result .= '<span>'.$value['name'].'</span>';
$result .= '</a></li>';
}
$result .= '</ul>';
$result .= '</div>';
return $result;
}

View File

@ -3679,7 +3679,7 @@ function agents_get_network_interfaces_array(
/**
* reporting alert get fired
*/
function reporting_alert_get_fired($id_agent_module, $id_alert_template_module, $period, $datetime)
function reporting_alert_get_fired($id_agent_module, $id_alert_template_module, $period, $datetime, $return_empty=true)
{
$fired = [];
$firedTimes = get_module_alert_fired(
@ -3709,7 +3709,11 @@ function reporting_alert_get_fired($id_agent_module, $id_alert_template_module,
if ($fireTime['utimestamp'] > $datelimit && $fireTime['utimestamp'] <= $datetime) {
$fired[] = $fireTime['timestamp'];
} else {
if ($return_empty === true) {
$fired[] = $empty;
} else {
continue;
}
}
}
@ -3821,10 +3825,15 @@ function reporting_alert_report_group($report, $content)
foreach ($actions['custom'] as $action) {
$data_action[$naction]['name'] = $action['name'];
$fired = $action['fired'];
if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)) {
$data_action[$naction]['fired'] = '----------------------------';
} else {
if ($fired == 0) {
$data_action[$naction]['fired'] = __('Not triggered');
} else if ($fired > 0) {
if ($fired > $datelimit && $fired < $datetime) {
$data_action[$naction]['fired'] = $fired;
} else {
continue 2;
}
}
$naction++;
@ -3833,10 +3842,15 @@ function reporting_alert_report_group($report, $content)
foreach ($actions['default'] as $action) {
$data_action[$naction]['name'] = $action['name'];
$fired = $action['fired'];
if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)) {
$data_action[$naction]['fired'] = '----------------------------';
} else {
if ($fired == 0) {
$data_action[$naction]['fired'] = __('Not triggered');
} else if ($fired > 0) {
if ($fired > $datelimit && $fired < $datetime) {
$data_action[$naction]['fired'] = $fired;
} else {
continue 2;
}
}
$naction++;
@ -3845,10 +3859,15 @@ function reporting_alert_report_group($report, $content)
foreach ($actions['unavailable'] as $action) {
$data_action[$naction]['name'] = $action['name'];
$fired = $action['fired'];
if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)) {
$data_action[$naction]['fired'] = '----------------------------';
} else {
if ($fired == 0) {
$data_action[$naction]['fired'] = __('Not triggered');
} else if ($fired > 0) {
if ($fired > $datelimit && $fired < $datetime) {
$data_action[$naction]['fired'] = $fired;
} else {
continue 2;
}
}
$naction++;
@ -3862,7 +3881,8 @@ function reporting_alert_report_group($report, $content)
$agent_module['id_agent_module'],
$actions['id'],
(int) $content['period'],
(int) $report['datetime']
(int) $report['datetime'],
false
);
$module_actions['actions'] = $data_action;
@ -7919,6 +7939,7 @@ function reporting_simple_graph(
'server_id' => $id_meta,
'height' => $config['graph_image_height'],
'landscape' => $content['landscape'],
'backgroundColor' => 'transparent',
'return_img_base_64' => true,
];

View File

@ -95,7 +95,7 @@ function treeview_printModuleTable($id_module, $server_data=false, $no_head=fals
$row = [];
$row['title'] = __('Warning status');
$row['data'] = $warning_status_str;
$table->data['watning_status'] = $row;
$table->data['warning_status'] = $row;
// Critical Min/Max
if (modules_is_string_type($module['id_tipo_modulo'])) {
@ -124,9 +124,16 @@ function treeview_printModuleTable($id_module, $server_data=false, $no_head=fals
$table->data['module_group'] = $row;
// Description
$module_description = '';
if ($module['id_modulo'] == MODULE_DATA && $module['id_policy_module'] != 0) {
$module_description = utf8_decode($module['descripcion']);
} else {
$module_description = $module['descripcion'];
}
$row = [];
$row['title'] = __('Description');
$row['data'] = ui_print_truncate_text($module['descripcion'], 'description', true, true, true, '[&hellip;]');
$row['data'] = ui_print_truncate_text($module_description, 'description', true, true, true, '[&hellip;]');
$table->data['description'] = $row;
// Tags

View File

@ -1691,8 +1691,10 @@ function ui_process_page_head($string, $bitfield)
}
}
$text_subtitle = isset($config['rb_product_name_alt']) ? '' : ' - '.__('the Flexible Monitoring System');
$output .= "\n\t";
$output .= '<title>'.get_product_name().' - '.__('the Flexible Monitoring System').'</title>
$output .= '<title>'.get_product_name().$text_subtitle.'</title>
<meta http-equiv="expires" content="never" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
@ -3820,7 +3822,7 @@ function ui_get_url_refresh($params=false, $relative=true, $add_post=true)
$url .= $key.'['.$k.']='.$v.'&';
}
} else {
$url .= $key.'='.$value.'&';
$url .= $key.'='.io_safe_input($value).'&';
}
}

View File

@ -3287,6 +3287,7 @@ function visual_map_get_color_line_status($layoutData)
* Get image of element in the visual console with status.
*
* @param array $layoutData The row of element in DB.
* @param boolean $status Status.
*
* @return string The image with the relative path to pandora console directory.
*/
@ -3294,8 +3295,12 @@ function visual_map_get_image_status_element($layoutData, $status=false)
{
$img = 'images/console/icons/'.$layoutData['image'];
if (empty($layoutData['image'])) {
return false;
}
if ($layoutData['type'] == 5) {
// ICON ELEMENT
// ICON ELEMENT.
$img .= '.png';
} else {
if ($status === false) {
@ -3304,35 +3309,36 @@ function visual_map_get_image_status_element($layoutData, $status=false)
switch ($status) {
case 1:
// Critical (BAD)
// Critical (BAD).
$img .= '_bad.png';
break;
case 4:
// Critical (ALERT)
// Critical (ALERT).
$img = '4'.$img.'_bad.png';
break;
case 0:
// Normal (OK)
// Normal (OK).
$img .= '_ok.png';
break;
case 2:
// Warning
// Warning.
$img .= '_warning.png';
break;
case 10:
// Warning (ALERT)
// Warning (ALERT).
$img = '4'.$img.'_warning.png';
break;
case 3:
// Unknown
// Unknown.
default:
$img .= '.png';
// Default is Grey (Other)
// Default is Grey (Other).
break;
}
}
@ -4260,7 +4266,7 @@ function visual_map_create_internal_name_item($label=null, $type, $image, $agent
case 'auto_sla_graph':
case AUTO_SLA_GRAPH:
$text = __('Auto SLA Graph');
$text = __('Event history graph');
break;
case 'percentile_bar':

View File

@ -56,7 +56,7 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background)
'static_graph' => __('Static Graph'),
'percentile_item' => __('Percentile Item'),
'module_graph' => __('Graph'),
'auto_sla_graph' => __('Auto SLA Graph'),
'auto_sla_graph' => __('Event history graph'),
'simple_value' => __('Simple value').ui_print_help_tip(
__(
"To use 'label'field, you should write
@ -738,13 +738,13 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background)
$form_items['color_cloud_def_color_row'] = [];
$form_items['color_cloud_def_color_row']['items'] = ['color_cloud'];
$form_items['color_cloud_def_color_row']['html'] = '<td align="left">'.__('Default color').'</td>
<td align="left">'.html_print_input_color('default_color', $default_color, false, true).'</td>';
<td align="left">'.html_print_input_color('default_color', $default_color, '', false, true).'</td>';
// Color ranges
$color_range_tip = __('The color of the element will be the one selected in the first range created in which the value of the module is found (with the initial and final values of the range included)').'.';
$form_items['color_cloud_color_ranges_row'] = [];
$form_items['color_cloud_color_ranges_row']['items'] = ['color_cloud'];
$form_items['color_cloud_color_ranges_row']['html'] = '<td align="left">'.__('Ranges').ui_print_help_tip($color_range_tip, true).'</td>'.'<td align="left">'.'<table id="new-color-range" class="databox color-range color-range-creation">'.'<tr>'.'<td>'.__('From value').'</td>'.'<td>'.html_print_input_text('from_value_new', '', '', 5, 255, true).'</td>'.'<td rowspan="4">'.'<a class="color-range-add" href="#">'.html_print_image('images/add.png', true).'</a>'.'</td>'.'</tr>'.'<td>'.__('To value').'</td>'.'<td>'.html_print_input_text('to_value_new', '', '', 5, 255, true).'</td>'.'<td></td>'.'<tr>'.'</tr>'.'<tr>'.'<td>'.__('Color').'</td>'.'<td>'.html_print_input_color('color_new', $default_color, false, true).'</td>'.'<td></td>'.'</tr>'.'</table>'.'</td>';
$form_items['color_cloud_color_ranges_row']['html'] = '<td align="left">'.__('Ranges').ui_print_help_tip($color_range_tip, true).'</td>'.'<td align="left">'.'<table id="new-color-range" class="databox color-range color-range-creation">'.'<tr>'.'<td>'.__('From value').'</td>'.'<td>'.html_print_input_text('from_value_new', '', '', 5, 255, true).'</td>'.'<td rowspan="4">'.'<a class="color-range-add" href="#">'.html_print_image('images/add.png', true).'</a>'.'</td>'.'</tr>'.'<td>'.__('To value').'</td>'.'<td>'.html_print_input_text('to_value_new', '', '', 5, 255, true).'</td>'.'<td></td>'.'<tr>'.'</tr>'.'<tr>'.'<td>'.__('Color').'</td>'.'<td>'.html_print_input_color('color_new', $default_color, '', false, true).'</td>'.'<td></td>'.'</tr>'.'</table>'.'</td>';
// End of Color Cloud rows
$form_items['show_on_top_row'] = [];
@ -1299,7 +1299,7 @@ function visual_map_editor_print_toolbox()
visual_map_print_button_editor('module_graph', __('Module Graph'), 'left', false, 'graph_min', true);
visual_map_print_button_editor('donut_graph', __('Serialized pie graph'), 'left', false, 'donut_graph_min', true);
visual_map_print_button_editor('bars_graph', __('Bars Graph'), 'left', false, 'bars_graph_min', true);
visual_map_print_button_editor('auto_sla_graph', __('Auto SLA Graph'), 'left', false, 'auto_sla_graph_min', true);
visual_map_print_button_editor('auto_sla_graph', __('Event history graph'), 'left', false, 'auto_sla_graph_min', true);
visual_map_print_button_editor('simple_value', __('Simple Value'), 'left', false, 'binary_min', true);
visual_map_print_button_editor('label', __('Label'), 'left', false, 'label_min', true);
visual_map_print_button_editor('icon', __('Icon'), 'left', false, 'icon_min', true);

View File

@ -168,7 +168,8 @@ function vbar_graph(
$backgroundColor='white',
$from_ux=false,
$from_wux=false,
$tick_color='white'
$tick_color='white',
$base64=false
) {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
@ -194,6 +195,7 @@ function vbar_graph(
'from_wux' => $from_wux,
'backgroundColor' => $backgroundColor,
'tick_color' => $tick_color,
'return_img_base_64' => $base64,
];
return generator_chart_to_pdf('vbar', $params);
}
@ -345,11 +347,12 @@ function hbar_graph(
$backgroundColor='white',
$tick_color='white',
$val_min=null,
$val_max=null
$val_max=null,
$base64=false
) {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
if (empty($chart_data)) {
if ($chart_data === false || empty($chart_data) === true) {
return graph_nodata_image($width, $height, 'hbar');
}
@ -365,6 +368,7 @@ function hbar_graph(
'tick_color' => $tick_color,
'val_min' => $val_min,
'val_max' => $val_max,
'return_img_base_64' => $base64,
];
return generator_chart_to_pdf('hbar', $params);
}

View File

@ -1,6 +1,6 @@
/* global $ */
/* exported pandoraFlotPie, pandoraFlotPieCustom */
// eslint-disable-next-line no-unused-vars
function pandoraFlotPie(
graph_id,
values,
@ -73,8 +73,9 @@ function pandoraFlotPie(
case "right":
case "inner":
conf_pie.legend.container = $("#" + graph_id + "_legend");
break;
default:
//TODO FOR TOP OR LEFT OR RIGHT
// TODO FOR TOP OR LEFT OR RIGHT.
break;
}
@ -85,7 +86,7 @@ function pandoraFlotPie(
// Events
$("#" + graph_id).bind("plothover", pieHover);
$("#" + graph_id).bind("plotclick", pieClick);
//$("#" + graph_id).bind("plotclick", pieClick);
$("#" + graph_id).bind("mouseout", resetInteractivity);
$("#" + graph_id).css("margin-left", "auto");
$("#" + graph_id).css("margin-right", "auto");
@ -125,6 +126,7 @@ function pandoraFlotPie(
}
}
// eslint-disable-next-line no-unused-vars
function pandoraFlotPieCustom(
graph_id,
values,
@ -311,11 +313,11 @@ function pandoraFlotPieCustom(
}
}
// eslint-disable-next-line no-unused-vars
function pandoraFlotHBars(
graph_id,
values,
labels,
water_mark,
maxvalue,
water_mark,
separator,
@ -346,7 +348,7 @@ function pandoraFlotHBars(
var serie = values[i].split(separator);
var aux = new Array();
for (j = 0; j < serie.length; j++) {
for (var j = 0; j < serie.length; j++) {
var aux2 = parseFloat(serie[j]);
aux.push([aux2, j]);
datas.push({
@ -358,16 +360,10 @@ function pandoraFlotHBars(
var labels_total = new Array();
labels = labels.split(separator);
i = 0;
for (i = 0; i < labels.length; i++) {
for (var i = 0; i < labels.length; i++) {
labels_total.push([i, labels[i]]);
}
var stack = 0,
bars = true,
lines = false,
steps = false;
var k = 0;
var options = {
series: {
bars: {
@ -428,15 +424,14 @@ function pandoraFlotHBars(
$("#" + graph_id).HUseTooltip();
$("#" + graph_id).css("margin-left", "auto");
$("#" + graph_id).css("margin-right", "auto");
//~ $('#' + graph_id).find('div.legend-tooltip').tooltip({ track: true });
function yFormatter(v, axis) {
format = new Array();
for (i = 0; i < labels_total.length; i++) {
// v, axis;
function yFormatter() {
var format = new Array();
for (var i = 0; i < labels_total.length; i++) {
var label = labels_total[i][1];
// var shortLabel = reduceText(label, 25);
var title = label;
var margin_top = 0;
if (label.length > 30) {
label = reduceText(label, 30);
}
@ -460,9 +455,10 @@ function pandoraFlotHBars(
return format;
}
function xFormatter(v, axis) {
label = parseFloat(v);
text = label.toLocaleString();
// v, axis;
function xFormatter(v) {
var label = parseFloat(v);
var text = label.toLocaleString();
if (label >= 1000000) text = text.substring(0, 4) + "M";
else if (label >= 100000) text = text.substring(0, 3) + "K";
else if (label >= 1000) text = text.substring(0, 2) + "K";
@ -500,7 +496,7 @@ $.fn.HUseTooltip = function() {
$("#tooltip").remove();
var x = item.datapoint[0];
var y = item.datapoint[1];
// var y = item.datapoint[1];
var color = item.series.color;
showTooltip(pos.pageX, pos.pageY, color, "<strong>" + x + "</strong>");
@ -523,7 +519,7 @@ $.fn.VUseTooltip = function() {
$("#tooltip").remove();
var x = item.datapoint[0];
// var x = item.datapoint[0];
var y = item.datapoint[1];
var color = item.series.color;
@ -555,6 +551,7 @@ function showTooltip(x, y, color, contents) {
.fadeIn(200);
}
// eslint-disable-next-line no-unused-vars
function pandoraFlotVBars(
graph_id,
values,
@ -562,7 +559,6 @@ function pandoraFlotVBars(
labels_long,
legend,
colors,
water_mark,
maxvalue,
water_mark,
separator,
@ -590,11 +586,11 @@ function pandoraFlotVBars(
: ["#FFA631", "#e63c52", "#f3b200", "#5BB6E5", "#F2919D", "#82b92e"];
var datas = new Array();
for (i = 0; i < values.length; i++) {
for (var i = 0; i < values.length; i++) {
var serie = values[i].split(separator);
var aux = new Array();
for (j = 0; j < serie.length; j++) {
for (var j = 0; j < serie.length; j++) {
var aux2 = parseFloat(serie[j]);
aux.push([aux2, j]);
if (from_ux) {
@ -618,11 +614,6 @@ function pandoraFlotVBars(
labels_total.push([i, labels[i]]);
}
var stack = 0,
bars = true,
lines = false,
steps = false;
var options = {
series: {
bars: {
@ -650,9 +641,9 @@ function pandoraFlotVBars(
axisLabelFontFamily: font + "Font",
axisLabelPadding: 100,
autoscaleMargin: 0.02,
tickFormatter: function(v, axis) {
label = parseFloat(v);
text = label.toLocaleString();
tickFormatter: function(v) {
var label = parseFloat(v);
var text = label.toLocaleString();
if (label >= 1000000) text = text.substring(0, 4) + "M";
else if (label >= 100000) text = text.substring(0, 3) + "K";
else if (label >= 1000) text = text.substring(0, 2) + "K";
@ -718,7 +709,7 @@ function pandoraFlotVBars(
.css("top", "+0px")
.css("left", "-20px");
// Format functions
function xFormatter(v, axis) {
function xFormatter() {
var format = new Array();
for (i = 0; i < labels_total.length; i++) {
var label = labels_total[i][1];
@ -751,7 +742,8 @@ function pandoraFlotVBars(
return format;
}
function yFormatter(v, axis) {
/*
function yFormatter(v) {
return (
'<div class="' +
font +
@ -768,6 +760,7 @@ function pandoraFlotVBars(
'<div style="font-size:' + font_size + 'pt !important;">' + v + "</div>"
);
}
*/
if (water_mark) {
set_watermark(
@ -778,6 +771,7 @@ function pandoraFlotVBars(
}
}
// eslint-disable-next-line no-unused-vars
function pandoraFlotSlicebar(
graph_id,
values,
@ -802,9 +796,9 @@ function pandoraFlotSlicebar(
full_legend = full_legend.split(separator);
}
var font_size = parseInt(font_size);
font_size = parseInt(font_size);
if (font != undefined)
var font = font
font = font
.split("/")
.pop()
.split(".")
@ -884,7 +878,7 @@ function pandoraFlotSlicebar(
$.plot($("#" + graph_id), datas, options);
if (match == null) {
if (match == null && not_interactive == 0) {
// Events
$("#" + graph_id).bind("plothover", function(event, pos, item) {
if (item) {
@ -919,6 +913,8 @@ function pandoraFlotSlicebar(
//current date
var dateObj = new Date();
var newdate = "";
var newdate2 = "";
if (full_legend != "") {
newdate = full_legend[item.seriesIndex];
newdate2 = full_legend[item.seriesIndex + 1];
@ -968,8 +964,8 @@ function pandoraFlotSlicebar(
}
// Format functions
function xFormatter(v, axis) {
d = new Date(1000 * (v + datelimit));
function xFormatter(v) {
var d = new Date(1000 * (v + datelimit));
var monthNames = [
"Jan",
"Feb",
@ -1000,6 +996,7 @@ function pandoraFlotSlicebar(
}
}
// eslint-disable-next-line no-unused-vars
function pandoraFlotArea(
graph_id,
values,
@ -1036,7 +1033,7 @@ function pandoraFlotArea(
var legend_color = params.legend_color;
var update_legend = {};
var force_integer = 0;
var title = params.title;
// var title = params.title;
var divisor = params.divisor;
if (typeof divisor === "undefined") {

View File

@ -462,7 +462,8 @@ function d3_donut_graph($id, $width, $height, $module_data, $resume_color)
$recipient_name = 'donut_graph_'.$id;
$recipient_name_to_js = '#donut_graph_'.$id;
$output = '<div id='.$recipient_name." style='overflow: hidden;'></div>";
$output = '';
$output .= '<div id='.$recipient_name." style='overflow: hidden;'></div>";
$output .= include_javascript_d3(true);
$output .= '<style type="text/css">
path {
@ -472,6 +473,7 @@ function d3_donut_graph($id, $width, $height, $module_data, $resume_color)
</style>';
$output .= "<script language=\"javascript\" type=\"text/javascript\">
$('".$recipient_name_to_js."').empty();
print_donut_graph('".$recipient_name_to_js."', ".$width.', '.$height.', '.$module_data.", '".$resume_color."');
</script>";

View File

@ -143,7 +143,7 @@ function flot_area_graph(
// Parent layer.
$return = "<div class='parent_graph' style='width: ".($params['width']).';'.$background_style.$padding_vconsole."'>";
if (empty($params['title']) === false) {
if ($params['title'] === true && empty($params['title']) === false) {
$return .= '<p style="text-align:center;">'.$params['title'].'</p>';
}
@ -279,12 +279,6 @@ function flot_area_graph(
// Trick to get translated string from javascript.
$return .= html_print_input_hidden('unknown_text', __('Unknown'), true);
// To use the js document ready event or not. Default true.
$document_ready = true;
if (isset($params['document_ready']) === true) {
$document_ready = $params['document_ready'];
}
$values = json_encode($array_data);
$legend = json_encode($legend);
@ -302,10 +296,6 @@ function flot_area_graph(
$return .= "<script type='text/javascript'>";
if ($document_ready === true) {
$return .= '$(document).ready( function () {';
}
$return .= "pandoraFlotArea(\n";
$return .= "'".$graph_id."', \n";
$return .= $values.", \n";
@ -319,10 +309,6 @@ function flot_area_graph(
$return .= $array_events_alerts."\n";
$return .= ');';
if ($document_ready === true) {
$return .= '});';
}
$return .= '</script>';
// Parent layer.
@ -629,8 +615,7 @@ function flot_hcolumn_chart($graph_data, $width, $height, $water_mark, $font='',
// Javascript code
$return .= "<script type='text/javascript'>";
$return .= "pandoraFlotHBars('$graph_id', '$values', '$labels',
false, $max, '$water_mark', '$separator', '$separator2', '$font', $font_size, '$background_color', '$tick_color', $val_min, $val_max)";
$return .= "pandoraFlotHBars('$graph_id', '$values', '$labels', $max, '$water_mark', '$separator', '$separator2', '$font', $font_size, '$background_color', '$tick_color', $val_min, $val_max)";
$return .= '</script>';
return $return;
@ -722,12 +707,12 @@ function flot_vcolumn_chart($graph_data, $width, $height, $color, $legend, $long
$return .= "<script type='text/javascript'>";
if ($from_ux) {
if ($from_wux) {
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', false, $max, '$water_mark', '$separator', '$separator2','$font',$font_size, true, true, '$background_color', '$tick_color')";
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', $max, '$water_mark', '$separator', '$separator2','$font',$font_size, true, true, '$background_color', '$tick_color')";
} else {
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', false, $max, '$water_mark', '$separator', '$separator2','$font',$font_size, true, false, '$background_color', '$tick_color')";
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', $max, '$water_mark', '$separator', '$separator2','$font',$font_size, true, false, '$background_color', '$tick_color')";
}
} else {
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', false, $max, '$water_mark', '$separator', '$separator2','$font',$font_size, false, false, '$background_color', '$tick_color')";
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', $max, '$water_mark', '$separator', '$separator2','$font',$font_size, false, false, '$background_color', '$tick_color')";
}
$return .= '</script>';
@ -754,7 +739,8 @@ function flot_slicesbar_graph(
$not_interactive=0,
$ttl=1,
$widgets=false,
$show=true
$show=true,
$date_to=false
) {
global $config;
@ -779,6 +765,7 @@ function flot_slicesbar_graph(
'widgets' => $widgets,
'show' => $show,
'return_img_base_64' => true,
'date_to' => $date_to,
];
$graph = '<img src="data:image/jpg;base64,';
@ -791,15 +778,17 @@ function flot_slicesbar_graph(
// Get a unique identifier to graph
$graph_id = uniqid('graph_');
$height = ((int) $height + 15);
// Set some containers to legend, graph, timestamp tooltip, etc.
if ($stat_win) {
$height = ((int) $height + 15);
$return = "<div id='$graph_id' class='noresizevc graph $adapt_key' style='width: ".$width.'%; height: '.$height."px; display: inline-block;'></div>";
} else {
if ($widgets) {
$width = ((int) $width - 10);
$height = ((int) $height - 10);
$return = "<div id='$graph_id' class='noresizevc graph $adapt_key' style='width: ".$width.'px; height: '.$height."px;'></div>";
} else {
$height = ((int) $height + 15);
$return = "<div id='$graph_id' class='noresizevc graph $adapt_key' style='width: ".$width.'%; height: '.$height."px;'></div>";
}
}
@ -873,8 +862,11 @@ function flot_slicesbar_graph(
$full_legend_date = false;
}
$date = get_system_time();
$datelimit = (($date - $period));
if (!$date_to) {
$date_to = get_system_time();
}
$datelimit = (($date_to - $period));
$i = 0;
$values2 = [];

View File

@ -12,6 +12,8 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
/* globals jQuery, d3 */
// The recipient is the selector of the html element
// The elements is an array with the names of the wheel elements
// The matrix must be a 2 dimensional array with a row and a column for each element
@ -2293,6 +2295,7 @@ function print_interior_circular_progress_bar(
})();
}
// eslint-disable-next-line no-unused-vars
function print_donut_graph(
recipient,
width,
@ -2309,40 +2312,13 @@ function print_donut_graph(
svg.append("g").attr("class", "slices");
var radius = 120;
var increment_y = 60;
var increment_y_padding = 25;
var decrement_x_padding = 150;
if (width >= 500) {
radius = 180;
increment_y = 60;
increment_y_padding = 20;
decrement_x_padding = 40;
} else if (width >= 400) {
radius = 140;
increment_y = 40;
increment_y_padding = 20;
decrement_x_padding = 40;
} else if (width >= 300) {
radius = 100;
increment_y = 40;
increment_y_padding = 15;
decrement_x_padding = 40;
} else if (width >= 200) {
radius = 50;
increment_y = 40;
increment_y_padding = 15;
decrement_x_padding = 25;
} else if (width >= 100) {
radius = 20;
increment_y = 20;
increment_y_padding = 8;
decrement_x_padding = 25;
} else {
radius = 10;
increment_y = 10;
increment_y_padding = 3;
decrement_x_padding = 5;
var heightLegend = 25 * module_data.length;
var maxRadius = (height - heightLegend) / 2;
var radius = maxRadius;
if (maxRadius > width / 2) {
radius = width / 2;
}
var arc = d3.svg
@ -2365,37 +2341,22 @@ function print_donut_graph(
svg
.append("g")
.append("rect")
.attr(
"transform",
"translate(" +
(width / 2 - (radius + decrement_x_padding)) +
"," +
(height / 2 - radius - increment_y) +
")"
)
.attr("fill", m_d.color)
.attr("x", -20)
.attr("y", -10)
.attr("width", 20)
.attr("height", 10);
.attr("x", 20)
.attr("y", 20 * (key + 1))
.attr("width", 25)
.attr("height", 15);
svg
.append("g")
.append("text")
.attr("fill", resume_color)
.attr(
"transform",
"translate(" +
(width / 2 - (radius + decrement_x_padding) + 10) +
"," +
(height / 2 - radius - increment_y) +
")"
)
.attr("transform", "translate(" + 40 + "," + 20 * (key + 1) + ")")
.attr("x", 15)
.attr("y", 10)
.text(m_d.tag_name)
.style("font-family", "smallfontFont")
.style("font-size", "7pt");
increment_y -= increment_y_padding;
});
function donutData() {
@ -2425,7 +2386,7 @@ function print_donut_graph(
.attr("class", "slice")
.attr(
"transform",
"translate(" + width / 2 + "," + (height - radius) + ")"
"translate(" + width / 2 + "," + (height + heightLegend) / 2 + ")"
);
slice

View File

@ -738,6 +738,14 @@ function add_new_link(new_link) {
}
function move_to_networkmap(node) {
// Checks if is widget or not
var widget = false;
widget = $("#hidden-widget").val();
if (widget == true) {
var id_cell = $(".widget_content").data("id_cell");
move_to_networkmap_widget(node.networkmap_id, id_cell);
} else {
var params = [];
params.push("get_networkmap_from_fictional=1");
params.push("id=" + node.id_db);
@ -760,6 +768,7 @@ function move_to_networkmap(node) {
}
});
}
}
function edit_node(data_node, dblClick) {
if (enterprise_installed) {
@ -4516,3 +4525,38 @@ function update_fictional_node_popup(id) {
color
);
}
function move_to_networkmap_widget(networkmap_id, id_cell) {
var params = [];
$(".widget_content").each(function(i) {
$("#body_cell").empty();
});
var pathname = window.location.pathname;
var path;
if (
pathname == "/pandora_console/enterprise/dashboard/public_dashboard.php"
) {
path = "../../ajax.php";
} else {
path = "ajax.php";
}
params.push("networkmap=true");
params.push("networkmap_id=" + networkmap_id);
params.push("page=enterprise/include/ajax/map_enterprise.ajax");
jQuery.ajax({
data: params.join("&"),
dataType: "html",
type: "POST",
url: path,
success: function(data) {
$(".widget_content").each(function(i) {
$("#body_cell").append(data);
});
}
});
}

View File

@ -1,4 +1,4 @@
/* global $ */
/* global $ uniqId*/
/* exported load_modal */
/*JS to Show user modals :
- Confirm dialogs.
@ -60,12 +60,19 @@ function logo_preview(icon_name, icon_path, incoming_options) {
}
// Advanced Form control.
// eslint-disable-next-line no-unused-vars
function load_modal(settings) {
var AJAX_RUNNING = 0;
var data = new FormData();
if (settings.extradata) {
settings.extradata.forEach(function(item) {
if (item.value != undefined) data.append(item.name, item.value);
if (item.value != undefined) {
if (item.value instanceof Object || item.value instanceof Array) {
data.append(item.name, JSON.stringify(item.value));
} else {
data.append(item.name, item.value);
}
}
});
}
data.append("page", settings.onshow.page);
@ -99,6 +106,10 @@ function load_modal(settings) {
};
}
if (settings.beforeClose == undefined) {
settings.beforeClose = function() {};
}
settings.target.html("Loading modal...");
settings.target
.dialog({
@ -168,7 +179,6 @@ function load_modal(settings) {
text: settings.modal.ok,
click: function() {
if (AJAX_RUNNING) return;
if (settings.onsubmit != undefined) {
if (settings.onsubmit.preaction != undefined) {
settings.onsubmit.preaction();
@ -189,7 +199,7 @@ function load_modal(settings) {
formdata.append("method", settings.onsubmit.method);
var flagError = false;
if (Array.isArray(settings.form) === false) {
$("#" + settings.form + " :input").each(function() {
if (this.checkValidity() === false) {
$(this).attr("title", this.validationMessage);
@ -237,8 +247,35 @@ function load_modal(settings) {
}
}
});
} else {
settings.form.forEach(function(element) {
$("#" + element + " :input").each(function() {
// TODO VALIDATE ALL INPUTS.
if (this.type == "file") {
if ($(this).prop("files")[0]) {
formdata.append(this.name, $(this).prop("files")[0]);
}
} else {
if ($(this).attr("type") == "checkbox") {
if (this.checked) {
formdata.append(this.name, "on");
}
} else {
formdata.append(this.name, $(this).val());
}
}
});
});
}
if (flagError === false) {
if (
settings.onsubmitClose != undefined &&
settings.onsubmitClose == 1
) {
$(this).dialog("close");
}
$.ajax({
method: "post",
url: settings.url,
@ -289,17 +326,32 @@ function load_modal(settings) {
modal: true,
title: settings.modal.title,
width: width,
minHeight:
settings.onshow.minHeight != undefined
? settings.onshow.minHeight
: "auto",
maxHeight:
settings.onshow.maxHeight != undefined
? settings.onshow.maxHeight
: "auto",
overlay: settings.modal.overlay,
buttons: required_buttons,
closeOnEscape: false,
closeOnEscape: true,
open: function() {
$(".ui-dialog-titlebar-close").hide();
//$(".ui-dialog-titlebar-close").hide();
},
close: function() {
if (id_modal_target != undefined) {
$(id_modal_target).remove();
}
if (settings.cleanup != undefined) {
settings.cleanup();
}
$(this).dialog("destroy");
},
beforeClose: settings.beforeClose()
});
},
error: function(data) {
@ -308,7 +360,9 @@ function load_modal(settings) {
});
}
//Function that shows a dialog box to confirm closures of generic manners. The modal id is random
// Function that shows a dialog box to confirm closures of generic manners.
// The modal id is random.
// eslint-disable-next-line no-unused-vars
function confirmDialog(settings) {
var randomStr = uniqId();
@ -365,6 +419,7 @@ function confirmDialog(settings) {
*
* @return {void}
*/
// eslint-disable-next-line no-unused-vars
function generalShowMsg(data, idMsg) {
var title = data.title[data.error];
var text = data.text[data.error];

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@
global $config;
if (!is_ajax()) {
return;
}
@ -9,57 +10,329 @@ if (!is_ajax()) {
require_once $config['homedir'].'/vendor/autoload.php';
use Models\VisualConsole\Container as VisualConsole;
use Models\VisualConsole\View as Viewer;
use Models\VisualConsole\Item as Item;
$method = get_parameter('method');
if ($method) {
$viewer = new Viewer();
try {
if (method_exists($viewer, $method) === true) {
echo $viewer->{$method}();
}
} catch (Exception $e) {
echo json_encode(['error' => $e->getMessage()]);
return;
}
return;
}
$visualConsoleId = (int) get_parameter('visualConsoleId');
$getVisualConsole = (bool) get_parameter('getVisualConsole');
$getVisualConsoleItems = (bool) get_parameter('getVisualConsoleItems');
$updateVisualConsoleItem = (bool) get_parameter('updateVisualConsoleItem');
$createVisualConsoleItem = (bool) get_parameter('createVisualConsoleItem');
$getVisualConsoleItem = (bool) get_parameter('getVisualConsoleItem');
$removeVisualConsoleItem = (bool) get_parameter('removeVisualConsoleItem');
$copyVisualConsoleItem = (bool) get_parameter('copyVisualConsoleItem');
$getImagesVisualConsole = (bool) get_parameter('getImagesVisualConsole');
$createColorRangeVisualConsole = (bool) get_parameter(
'createColorRangeVisualConsole'
);
$getTimeZoneVisualConsole = (bool) get_parameter('getTimeZoneVisualConsole');
$serviceListVisualConsole = (bool) get_parameter(
'serviceListVisualConsole'
);
// Check groups can access user.
$aclUserGroups = [];
if (!users_can_manage_group_all('AR')) {
$aclUserGroups = array_keys(users_get_groups(false, 'AR'));
}
$loadtabs = (bool) get_parameter('loadtabs');
ob_clean();
if ($getVisualConsole === true) {
if ($visualConsoleId) {
// Retrieve the visual console.
$visualConsole = VisualConsole::fromDB(['id' => $visualConsoleId]);
$visualConsoleData = $visualConsole->toArray();
$groupId = $visualConsoleData['groupId'];
$vcGroupId = $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');
$aclRead = check_acl($config['id_user'], $vcGroupId, 'VR');
$aclWrite = check_acl($config['id_user'], $vcGroupId, 'VW');
$aclManage = check_acl($config['id_user'], $vcGroupId, 'VM');
if (!$aclRead && !$aclWrite && !$aclManage) {
db_pandora_audit(
'ACL Violation',
'Trying to access visual console without group access'
);
exit;
http_response_code(403);
return;
}
}
if ($getVisualConsole === true) {
echo $visualConsole;
return;
} else if ($getVisualConsoleItems === true) {
// Check groups can access user.
$aclUserGroups = [];
if (!users_can_manage_group_all('AR')) {
$aclUserGroups = array_keys(users_get_groups(false, 'AR'));
}
$vcItems = VisualConsole::getItemsFromDB($visualConsoleId, $aclUserGroups);
echo '['.implode($vcItems, ',').']';
return;
} else if ($getVisualConsoleItem === true
|| $updateVisualConsoleItem === true
) {
$itemId = (int) get_parameter('visualConsoleItemId');
try {
$item = VisualConsole::getItemFromDB($itemId);
} catch (Throwable $e) {
// Bad params.
http_response_code(400);
return;
}
$itemData = $item->toArray();
$itemType = $itemData['type'];
$itemAclGroupId = $itemData['aclGroupId'];
// ACL.
$aclRead = check_acl($config['id_user'], $itemAclGroupId, 'VR');
$aclWrite = check_acl($config['id_user'], $itemAclGroupId, 'VW');
$aclManage = check_acl($config['id_user'], $itemAclGroupId, 'VM');
if (!$aclRead && !$aclWrite && !$aclManage) {
db_pandora_audit(
'ACL Violation',
'Trying to access visual console without group access'
);
http_response_code(403);
return;
}
// Check also the group Id for the group item.
if ($itemType === GROUP_ITEM) {
$itemGroupId = $itemData['groupId'];
// ACL.
$aclRead = check_acl($config['id_user'], $itemGroupId, 'VR');
$aclWrite = check_acl($config['id_user'], $itemGroupId, 'VW');
$aclManage = check_acl($config['id_user'], $itemGroupId, 'VM');
if (!$aclRead && !$aclWrite && !$aclManage) {
db_pandora_audit(
'ACL Violation',
'Trying to access visual console without group access'
);
http_response_code(403);
return;
}
}
if ($getVisualConsoleItem === true) {
echo $item;
return;
} else if ($updateVisualConsoleItem === true) {
$visualConsoleId = (integer) get_parameter('visualConsoleId');
$visualConsoleItemId = (integer) get_parameter('visualConsoleItemId');
$data = get_parameter('data');
$class = VisualConsole::getItemClass($data['type']);
$item_data = [];
$item_data['id'] = $visualConsoleItemId;
$item_data['id_layout'] = $visualConsoleId;
$item = $class::fromDB($item_data);
if (isset($data) === true) {
$data['id'] = $itemId;
$data['id_layout'] = $visualConsoleId;
$result = $item->save($data);
echo json_encode($result);
echo $item;
}
return;
}
} else if ($createVisualConsoleItem === true) {
// TODO: ACL.
$data = get_parameter('data');
if ($data) {
// Inserted data in new item.
$class = VisualConsole::getItemClass((int) $data['type']);
try {
// Save the new item.
$data['id_layout'] = $visualConsoleId;
$result = $class::save($data);
} catch (\Throwable $th) {
// There is no item in the database.
echo false;
return;
}
// Extract data new item inserted.
try {
$item = VisualConsole::getItemFromDB($result);
} catch (Throwable $e) {
// Bad params.
http_response_code(400);
return;
}
echo $item;
} else {
echo false;
}
return;
} else if ($removeVisualConsoleItem === true) {
$itemId = (int) get_parameter('visualConsoleItemId');
try {
$item = VisualConsole::getItemFromDB($itemId);
} catch (\Throwable $th) {
// There is no item in the database.
http_response_code(404);
return;
}
$itemData = $item->toArray();
$itemAclGroupId = $itemData['aclGroupId'];
$aclWrite = check_acl($config['id_user'], $itemAclGroupId, 'VW');
$aclManage = check_acl($config['id_user'], $itemAclGroupId, 'VM');
// ACL.
if (!$aclWrite && !$aclManage) {
db_pandora_audit(
'ACL Violation',
'Trying to delete visual console item without group access'
);
http_response_code(403);
return;
}
$data = get_parameter('data');
$result = $item::delete($itemId);
echo $result;
return;
} else if ($copyVisualConsoleItem === true) {
$itemId = (int) get_parameter('visualConsoleItemId');
// Get a copy of the item.
$item = VisualConsole::getItemFromDB($itemId);
$data = $item->toArray();
$data['id_layout'] = $visualConsoleId;
if ($data['type'] === LINE_ITEM) {
$data['endX'] = ($data['endX'] + 20);
$data['endY'] = ($data['endY'] + 20);
$data['startX'] = ($data['startX'] + 20);
$data['startY'] = ($data['startY'] + 20);
} else {
$data['x'] = ($data['x'] + 20);
$data['y'] = ($data['y'] + 20);
}
unset($data['id']);
$class = VisualConsole::getItemClass((int) $data['type']);
try {
// Save the new item.
$result = $class::save($data);
} catch (\Throwable $th) {
// There is no item in the database.
echo false;
return;
}
echo $result;
return;
} else if ($getImagesVisualConsole) {
$img = get_parameter('nameImg', 'appliance');
$only = (bool) get_parameter('only', 0);
$count = Item::imagesElementsVC($img, $only);
echo json_encode($count);
return;
} else if ($createColorRangeVisualConsole) {
$uniqId = \uniqid();
$baseUrl = ui_get_full_url('/', false, false, false);
$from = get_parameter('from', 0);
$to = get_parameter('to', 0);
$color = get_parameter('color', 0);
$rangeFrom = [
'name' => 'rangeFrom[]',
'type' => 'number',
'value' => $from,
'return' => true,
];
$rangeTo = [
'name' => 'rangeTo[]',
'type' => 'number',
'value' => $to,
'return' => true,
];
$rangeColor = [
'wrapper' => 'div',
'name' => 'rangeColor[]',
'type' => 'color',
'value' => $color,
'return' => true,
];
$removeBtn = [
'name' => 'Remove',
'label' => '',
'type' => 'button',
'attributes' => 'class="remove-item-img"',
'return' => true,
'script' => 'removeColorRange(\''.$uniqId.'\')',
];
$classRangeColor = 'interval-color-ranges flex-row flex-start w100p';
$liRangeColor = '<li id="li-'.$uniqId.'" class="'.$classRangeColor.'">';
$liRangeColor .= '<label>'.__('From').'</label>';
$liRangeColor .= html_print_input($rangeFrom);
$liRangeColor .= '<label>'.__('To').'</label>';
$liRangeColor .= html_print_input($rangeTo);
$liRangeColor .= '<label>'.__('Color').'</label>';
$liRangeColor .= '<div>';
$liRangeColor .= html_print_input($rangeColor);
$liRangeColor .= '</div>';
$liRangeColor .= '<label></label>';
$liRangeColor .= html_print_input($removeBtn);
$liRangeColor .= '<li>';
echo $liRangeColor;
return;
} else if ($getTimeZoneVisualConsole) {
$zone = get_parameter('zone', 'Europe');
$zones = Item::zonesVC($zone);
echo json_encode($zones);
return;
} else if ($serviceListVisualConsole) {
if (!enterprise_installed()) {
echo json_encode(false);
return;
}
enterprise_include_once('include/functions_services.php');
// Services list.
$services = [];
$services = enterprise_hook(
'services_get_services',
[
false,
[
'id',
'name',
],
]
);
echo io_safe_output(json_encode($services));
return;
} else if ($loadtabs) {
$viewer = new Viewer();
echo $viewer->loadForm();
return;
}
exit;

View File

@ -76,6 +76,7 @@ abstract class CachedModel extends Model
{
global $config;
// TODO: Remove references to the VC items. This class should be usable with any resource.
if ($filter['cache_expiration'] > 0) {
// Obtain the item's data from cache.
$cachedData = static::fetchCachedData($filter);

View File

@ -71,6 +71,18 @@ abstract class Model
abstract public function save(array $data=[]);
/**
* Delete an item in the database
*
* @param integer $itemId Identifier of the Item.
*
* @return boolean The modeled element data structure stored into the DB.
*
* @abstract
*/
abstract public function delete(int $itemId): bool;
/**
* Constructor of the model. It won't be public. The instances
* will be created through factories which start with from*.
@ -151,7 +163,7 @@ abstract class Model
*/
public function toJson(): string
{
return \json_encode($this->data);
return json_encode($this->data);
}

View File

@ -123,6 +123,21 @@ final class Container extends Model
}
/**
* Delete an item in the database
*
* @param integer $itemId Identifier of the Item.
*
* @return boolean The modeled element data structure stored into the DB.
*
* @overrides Model::delete.
*/
public function delete(int $itemId): bool
{
return true;
}
/**
* Extract a group Id value.
*
@ -254,7 +269,7 @@ final class Container extends Model
$backgroundImage = static::extractBackgroundImage($row);
if ($backgroundUrl === null && $backgroundImage !== null) {
$row['backgroundURL'] = ui_get_full_url(
$row['backgroundURL'] = \ui_get_full_url(
'images/console/background/'.$backgroundImage,
false,
false,
@ -406,4 +421,46 @@ final class Container extends Model
}
/**
* Obtain an item which belong to the Visual Console.
*
* @param integer $itemId Identifier of the Item.
*
* @return Model Item or Line.
* @throws \Exception When the data cannot be retrieved from the DB.
*/
public static function getItemFromDB(int $itemId): Model
{
// Default filter.
$filter = ['id' => $itemId];
$fields = [
'DISTINCT(id) AS id',
'type',
'cache_expiration',
'id_layout',
];
$row = \db_get_row_filter(
'tlayout_data',
$filter,
$fields,
'OR'
);
if ($rows === false) {
return '';
}
$class = static::getItemClass((int) $row['type']);
try {
$item = $class::fromDB($row);
} catch (\Throwable $e) {
// TODO: Log this?
}
return $item;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -27,6 +27,73 @@ final class BarsGraph extends Item
protected static $useHtmlOutput = true;
/**
* Extract a type graph value.
*
* @param array $data Unknown input data structure.
*
* @return string One of 'vertical' or 'horizontal'. 'vertical' by default.
*/
private static function getTypeGraph(array $data)
{
return static::notEmptyStringOr(
static::issetInArray(
$data,
[
'typeGraph',
'type_graph',
'graphType',
]
),
null
);
}
/**
* Return a valid representation of a record in database.
*
* @param array $data Input data.
*
* @return array Data structure representing a record in database.
*
* @overrides Item->encode.
*/
protected function encode(array $data): array
{
$return = parent::encode($data);
$type_graph = static::getTypeGraph($data);
if ($type_graph !== null) {
$return['type_graph'] = $type_graph;
}
return $return;
}
/**
* 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';
}
}
/**
* Returns a valid representation of the model.
*
@ -156,14 +223,6 @@ final class BarsGraph extends Item
$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 = [];
@ -246,9 +305,9 @@ final class BarsGraph extends Item
// Maybe connect to node.
$nodeConnected = false;
if (\is_metaconsole() === true && $metaconsoleId !== null) {
$server = \metaconsole_get_connection_by_id($metaconsoleId);
$nodeConnected = \metaconsole_connect(
null,
$metaconsoleId
$server
) === NOERR;
if ($nodeConnected === false) {
@ -259,6 +318,9 @@ final class BarsGraph extends Item
}
$moduleData = \get_bars_module_data($moduleId);
if ($moduleData !== false && is_array($moduleData) === true) {
array_pop($moduleData);
}
$waterMark = [
'file' => $config['homedir'].'/images/logo_vertical_water.png',
@ -286,22 +348,20 @@ final class BarsGraph extends Item
$color,
[],
[],
\ui_get_full_url(
'images/image_problem_area.png',
false,
false,
false
),
'',
'',
$waterMark,
$config['fontpath'],
6,
$config['fontsize'],
'',
0,
2,
$config['homeurl'],
$backGroundColor,
$gridColor
$gridColor,
null,
null,
true
);
} else {
$graph = \vbar_graph(
@ -321,14 +381,15 @@ final class BarsGraph extends Item
'',
$waterMark,
$config['fontpath'],
6,
$config['fontsize'],
'',
0,
2,
$config['homeurl'],
$backGroundColor,
true,
false,
$gridColor
$gridColor,
true
);
}
@ -337,10 +398,149 @@ final class BarsGraph extends Item
\metaconsole_restore_db();
}
$data['html'] = $graph;
$imgbase64 = 'data:image/jpg;base64,';
$imgbase64 .= $graph;
$data['html'] = $imgbase64;
return $data;
}
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
// Retrieve global - common inputs.
$inputs = Item::getFormInputs($values);
if (is_array($inputs) !== true) {
throw new Exception(
'[BarsGraph]::getFormInputs parent class return is not an array'
);
}
if ($values['tabSelected'] === 'specific') {
// Background color.
$fields = [
'white' => __('White'),
'black' => __('Black'),
'transparent' => __('Transparent'),
];
$inputs[] = [
'label' => __('Background color'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'backgroundColor',
'selected' => $values['backgroundColor'],
'return' => true,
'sort' => false,
],
];
// Graph Type.
$fields = [
'horizontal' => __('Horizontal'),
'vertical' => __('Vertical'),
];
$inputs[] = [
'label' => __('Graph Type'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'typeGraph',
'selected' => $values['typeGraph'],
'return' => true,
],
];
// Grid color.
$inputs[] = [
'label' => __('Grid color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'gridColor',
'type' => 'color',
'value' => $values['gridColor'],
'return' => true,
],
];
// Autocomplete agents.
$inputs[] = [
'label' => __('Agent'),
'arguments' => [
'type' => 'autocomplete_agent',
'name' => 'agentAlias',
'id_agent_hidden' => $values['agentId'],
'name_agent_hidden' => 'agentId',
'server_id_hidden' => $values['metaconsoleId'],
'name_server_hidden' => 'metaconsoleId',
'return' => true,
'module_input' => true,
'module_name' => 'moduleId',
'module_none' => false,
],
];
// Autocomplete module.
$inputs[] = [
'label' => __('Module'),
'arguments' => [
'type' => 'autocomplete_module',
'fields' => $fields,
'name' => 'moduleId',
'selected' => $values['moduleId'],
'return' => true,
'sort' => false,
'agent_id' => $values['agentId'],
'metaconsole_id' => $values['metaconsoleId'],
],
];
}
return $inputs;
}
/**
* Default values.
*
* @param array $values Array values.
*
* @return array Array with default values.
*
* @overrides Item->getDefaultGeneralValues.
*/
public function getDefaultGeneralValues(array $values): array
{
// Retrieve global - common inputs.
$values = parent::getDefaultGeneralValues($values);
// Default values.
if (isset($values['width']) === false) {
$values['width'] = 300;
}
if (isset($values['height']) === false) {
$values['height'] = 180;
}
return $values;
}
}

View File

@ -12,6 +12,89 @@ final class Box extends Item
{
/**
* Extract the "Fill transparent" switch value.
*
* @param array $data Unknown input data structure.
*
* @return mixed If the statistics should be shown or not.
*/
private static function getFillTransparent(array $data)
{
return static::issetInArray(
$data,
[
'fillTransparent',
'show_statistics',
]
);
}
/**
* Extract a fill color value.
*
* @param array $data Unknown input data structure.
*
* @return mixed String representing the fill color (not empty) or null.
*/
protected static function getFillColor(array $data)
{
return static::notEmptyStringOr(
static::issetInArray(
$data,
[
'fillColor',
'fill_color',
'labelColor',
]
),
null
);
}
/**
* Return a valid representation of a record in database.
*
* @param array $data Input data.
*
* @return array Data structure representing a record in database.
*
* @overrides Item->encode.
*/
protected function encode(array $data): array
{
$return = parent::encode($data);
$border_width = parent::getBorderWidth($data);
if ($border_width !== null) {
if ($border_width < 1) {
$border_width = 1;
}
$return['border_width'] = $border_width;
}
$border_color = static::getBorderColor($data);
if ($border_color !== null) {
$return['border_color'] = $border_color;
}
$fill_color = static::getFillColor($data);
if ($fill_color !== null) {
$return['fill_color'] = $fill_color;
}
$fill_transparent = static::getFillTransparent($data);
if ($fill_transparent !== null) {
$return['show_statistics'] = static::parseBool($fill_transparent);
}
return $return;
}
/**
* Returns a valid representation of the model.
*
@ -30,10 +113,26 @@ final class Box extends Item
$boxData['borderWidth'] = $this->extractBorderWidth($data);
$boxData['borderColor'] = $this->extractBorderColor($data);
$boxData['fillColor'] = $this->extractFillColor($data);
$boxData['fillTransparent'] = $this->extractFillTransparent($data);
return $boxData;
}
/**
* Extract the "Fill transparent" switch value.
*
* @param array $data Unknown input data structure.
*
* @return boolean If the statistics should be shown or not.
*/
private static function extractFillTransparent(array $data): bool
{
return static::parseBool(
static::issetInArray($data, ['fillTransparent', 'show_statistics'])
);
}
/**
* Extract a border width value.
*
@ -82,4 +181,196 @@ final class Box extends Item
}
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
if ($values['tabSelected'] === 'general') {
$inputs[] = [
'arguments' => [
'type' => 'hidden',
'name' => 'tabGeneral',
'value' => true,
],
];
// Size.
$inputs[] = [
'block_id' => 'size-item',
'class' => 'flex-row flex-start w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('Size'),
],
[
'label' => __('width'),
'arguments' => [
'name' => 'width',
'type' => 'number',
'value' => $values['width'],
'return' => true,
'min' => 0,
],
],
[
'label' => __('height'),
'arguments' => [
'name' => 'height',
'type' => 'number',
'value' => $values['height'],
'return' => true,
'min' => 0,
],
],
],
];
// Position.
$inputs[] = [
'block_id' => 'position-item',
'class' => 'flex-row flex-start w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('Position'),
],
[
'label' => __('X'),
'arguments' => [
'name' => 'x',
'type' => 'number',
'value' => $values['x'],
'return' => true,
'min' => 0,
],
],
[
'label' => __('Y'),
'arguments' => [
'name' => 'y',
'type' => 'number',
'value' => $values['y'],
'return' => true,
'min' => 0,
],
],
],
];
// Show on top.
$inputs[] = [
'label' => __('Show on top'),
'arguments' => [
'name' => 'isOnTop',
'id' => 'isOnTop',
'type' => 'switch',
'value' => $values['isOnTop'],
],
];
}
// Default specific values.
if (isset($values['borderColor']) === false) {
$values['borderColor'] = '#000000';
}
if (isset($values['borderWidth']) === false) {
$values['borderWidth'] = 1;
}
if (isset($values['fillColor']) === false) {
$values['fillColor'] = '#ffffff';
}
if ($values['tabSelected'] === 'specific') {
// Border color.
$inputs[] = [
'label' => __('Border color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'borderColor',
'type' => 'color',
'value' => $values['borderColor'],
'return' => true,
],
];
// Border Width.
$inputs[] = [
'label' => __('Border Width'),
'arguments' => [
'name' => 'borderWidth',
'type' => 'number',
'value' => $values['borderWidth'],
'return' => true,
'min' => 1,
],
];
// Fill color.
$inputs[] = [
'label' => __('Fill color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'fillColor',
'type' => 'color',
'value' => $values['fillColor'],
'return' => true,
],
];
// Fill transparent.
$inputs[] = [
'label' => __('Fill transparent'),
'arguments' => [
'name' => 'fillTransparent',
'id' => 'fillTransparent',
'type' => 'switch',
'value' => $values['fillTransparent'],
],
];
}
return $inputs;
}
/**
* Default values.
*
* @param array $values Array values.
*
* @return array Array with default values.
*
* @overrides Item->getDefaultGeneralValues.
*/
public function getDefaultGeneralValues(array $values): array
{
// Retrieve global - common inputs.
$values = parent::getDefaultGeneralValues($values);
// Default values.
if (isset($values['width']) === false) {
$values['width'] = 100;
}
if (isset($values['height']) === false) {
$values['height'] = 100;
}
return $values;
}
}

View File

@ -20,6 +20,96 @@ final class Clock extends Item
protected static $useLinkedVisualConsole = true;
/**
* Encode type item.
*
* @param array $data Data for encode.
*
* @return string Return color.
*/
protected function encodeColor(array $data): ?string
{
$color = null;
if (isset($data['color']) === true) {
if (empty($data['color']) === true) {
$color = '#F0F0F0';
} else {
$color = $data['color'];
}
}
return $color;
}
/**
* Return a valid representation of a record in database.
*
* @param array $data Input data.
*
* @return array Data structure representing a record in database.
*
* @overrides Item->encode.
*/
protected function encode(array $data): array
{
$return = parent::encode($data);
$color = static::encodeColor($data);
if ($color !== null) {
$return['fill_color'] = $color;
}
$clock_animation = static::notEmptyStringOr(
static::issetInArray(
$data,
[
'clockType',
'clock_animation',
'clockAnimation',
]
),
null
);
if ($clock_animation !== null) {
$return['clock_animation'] = $clock_animation;
}
$time_format = static::notEmptyStringOr(
static::issetInArray(
$data,
[
'clockFormat',
'time_format',
'timeFormat',
]
),
null
);
if ($time_format !== null) {
$return['time_format'] = $time_format;
}
$timezone = static::notEmptyStringOr(
static::issetInArray(
$data,
[
'timezone',
'timeZone',
'time_zone',
'clockTimezone',
]
),
null
);
if ($timezone !== null) {
$return['timezone'] = $timezone;
}
return $return;
}
/**
* Returns a valid representation of the model.
*
@ -151,4 +241,170 @@ final class Clock extends Item
}
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
// Retrieve global - common inputs.
$inputs = Item::getFormInputs($values);
if (is_array($inputs) !== true) {
throw new Exception(
'[Clock]::getFormInputs parent class return is not an array'
);
}
if ($values['tabSelected'] === 'specific') {
// Time zone.
$baseUrl = ui_get_full_url('/', false, false, false);
$fields = [
'Africa' => __('Africa'),
'America' => __('America'),
'Antarctica' => __('Antarctica'),
'Arctic' => __('Arctic'),
'Asia' => __('Asia'),
'Atlantic' => __('Atlantic'),
'Australia' => __('Australia'),
'Europe' => __('Europe'),
'Indian' => __('Indian'),
'Pacific' => __('Pacific'),
'UTC' => __('UTC'),
];
if (isset($values['clockTimezone']) === false
&& empty($values['clockTimezone']) === true
) {
$values['zone'] = 'Europe';
$values['clockTimezone'] = 'Europe/Amsterdam';
} else {
$zone = explode('/', $values['clockTimezone']);
$values['zone'] = $zone[0];
}
$zones = self::zonesVC($values['zone']);
$inputs[] = [
'block_id' => 'timeZone-item',
'class' => 'flex-row flex-start w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('Time zone'),
],
[
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'zone',
'selected' => $values['zone'],
'script' => 'timeZoneVCChange(\''.$baseUrl.'\',\''.$values['vCId'].'\')',
'return' => true,
],
],
[
'arguments' => [
'type' => 'select',
'fields' => $zones,
'name' => 'clockTimezone',
'selected' => $values['clockTimezone'],
'return' => true,
],
],
],
];
// Clock animation.
$fields = [
'analogic' => __('Simple analogic'),
'digital' => __('Simple digital'),
];
$inputs[] = [
'label' => __('Clock animation'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'clockType',
'selected' => $values['clockType'],
'return' => true,
'sort' => false,
],
];
// Time format.
$fields = [
'time' => __('Only time'),
'datetime' => __('Time and date'),
];
$inputs[] = [
'label' => __('Time format'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'clockFormat',
'selected' => $values['clockFormat'],
'return' => true,
'sort' => false,
],
];
// Element color.
$inputs[] = [
'label' => __('Fill color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'color',
'type' => 'color',
'value' => $values['color'],
'return' => true,
],
];
}
return $inputs;
}
/**
* Default values.
*
* @param array $values Array values.
*
* @return array Array with default values.
*
* @overrides Item->getDefaultGeneralValues.
*/
public function getDefaultGeneralValues(array $values): array
{
if (isset($values['isLinkEnabled']) === false) {
$values['isLinkEnabled'] = false;
}
// Retrieve global - common inputs.
$values = parent::getDefaultGeneralValues($values);
// Default values.
if (isset($values['width']) === false) {
$values['width'] = 100;
}
if (isset($values['height']) === false) {
$values['height'] = 100;
}
return $values;
}
}

View File

@ -28,6 +28,98 @@ final class ColorCloud extends Item
protected static $useLinkedModule = true;
/**
* Encode the ranges color value.
*
* @param array $data Unknown input data structure.
*
* @return array Ranges color.
*/
private static function encodeColorRanges(array $data): array
{
$colorRangeArray = [];
if (isset($data['colorRanges']) === true
&& is_array($data['colorRanges']) === true
) {
if (empty($data['colorRanges']) === false) {
foreach ($data['colorRanges'] as $colorRange) {
if (\is_numeric($colorRange['fromValue']) === true
&& \is_numeric($colorRange['toValue']) === true
&& static::notEmptyStringOr(
$colorRange['color'],
null
) !== null
) {
$colorRangeArray[] = [
'color' => $colorRange['color'],
'from_value' => (float) $colorRange['fromValue'],
'to_value' => (float) $colorRange['toValue'],
];
}
}
} else {
$colorRangeArray = [];
}
}
return $colorRangeArray;
}
/**
* Return a valid representation of a record in database.
*
* @param array $data Input data.
*
* @return array Data structure representing a record in database.
*
* @overrides Item->encode.
*/
protected function encode(array $data): array
{
$return = parent::encode($data);
$colorRanges = null;
$defaultColor = null;
if (isset($data['defaultColor']) === true) {
$defaultColor = static::extractDefaultColor($data);
}
if (isset($data['colorRanges']) === true) {
$colorRanges = static::encodeColorRanges($data);
}
if (empty($data['id']) === true) {
$return['label'] = json_encode(
[
'default_color' => $defaultColor,
'color_ranges' => $colorRanges,
]
);
} else {
$prevData = $this->toArray();
$prevDataDefaultColor = static::extractDefaultColor(
['defaultColor' => $prevData['defaultColor']]
);
$prevDataColorRanges = static::encodeColorRanges(
['colorRanges' => $prevData['colorRanges']]
);
$return['label'] = json_encode(
[
'default_color' => ($defaultColor !== null) ? $defaultColor : $prevDataDefaultColor,
'color_ranges' => ($colorRanges !== null) ? $colorRanges : $prevDataColorRanges,
]
);
}
return $return;
}
/**
* Returns a valid representation of the model.
*
@ -143,10 +235,6 @@ final class ColorCloud extends Item
{
$dynamicDataEncoded = static::notEmptyStringOr($data['label'], null);
if ($dynamicDataEncoded === null) {
throw new \InvalidArgumentException('dynamic data not found');
}
$result = [];
try {
@ -212,10 +300,6 @@ final class ColorCloud extends Item
$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'];
@ -278,4 +362,225 @@ final class ColorCloud extends Item
}
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
// Retrieve global - common inputs.
$inputs = Item::getFormInputs($values);
if (is_array($inputs) !== true) {
throw new Exception(
'[ColorCloud]::getFormInputs parent class return is not an array'
);
}
if ($values['tabSelected'] === 'specific') {
// Autocomplete agents.
$inputs[] = [
'label' => __('Agent'),
'arguments' => [
'type' => 'autocomplete_agent',
'name' => 'agentAlias',
'id_agent_hidden' => $values['agentId'],
'name_agent_hidden' => 'agentId',
'server_id_hidden' => $values['metaconsoleId'],
'name_server_hidden' => 'metaconsoleId',
'return' => true,
'module_input' => true,
'module_name' => 'moduleId',
'module_none' => false,
],
];
// Autocomplete module.
$inputs[] = [
'label' => __('Module'),
'arguments' => [
'type' => 'autocomplete_module',
'fields' => $fields,
'name' => 'moduleId',
'selected' => $values['moduleId'],
'return' => true,
'sort' => false,
'agent_id' => $values['agentId'],
'metaconsole_id' => $values['metaconsoleId'],
],
];
// Default color.
$inputs[] = [
'label' => __('Default color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'defaultColor',
'type' => 'color',
'value' => $values['defaultColor'],
'return' => true,
],
];
// Label.
$inputs[] = [
'label' => __('Add new range').':',
];
$baseUrl = ui_get_full_url('/', false, false, false);
// Default ranges.
$inputs[] = [
'block_id' => 'default-ranges',
'class' => 'flex-row flex-start w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('From'),
'arguments' => [
'id' => 'rangeDefaultFrom',
'name' => 'rangeDefaultFrom',
'type' => 'number',
'value' => 0,
'return' => true,
'min' => 0,
],
],
[
'label' => __('To'),
'arguments' => [
'id' => 'rangeDefaultTo',
'name' => 'rangeDefaultTo',
'type' => 'number',
'value' => 0,
'return' => true,
'min' => 0,
],
],
[
'label' => __('Color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'rangeDefaultColor',
'type' => 'color',
'value' => '#000000',
'return' => true,
],
],
[
'arguments' => [
'name' => 'add',
'label' => '',
'type' => 'button',
'attributes' => 'class="add-item-img"',
'return' => true,
'script' => 'createColorRange(\''.$baseUrl.'\',\''.$values['vCId'].'\')',
],
],
],
];
// Label.
$inputs[] = [
'label' => __('Current ranges').':',
];
if (isset($values['colorRanges']) === true
&& is_array($values['colorRanges']) === true
&& empty($values['colorRanges']) === false
) {
foreach ($values['colorRanges'] as $k => $v) {
$uniqId = \uniqid();
$inputs[] = [
'block_id' => $uniqId,
'class' => 'interval-color-ranges flex-row flex-start w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('From'),
'arguments' => [
'name' => 'rangeFrom[]',
'type' => 'number',
'value' => $v['fromValue'],
'return' => true,
'min' => 0,
],
],
[
'label' => __('To'),
'arguments' => [
'name' => 'rangeTo[]',
'type' => 'number',
'value' => $v['toValue'],
'return' => true,
'min' => 0,
],
],
[
'label' => __('Color'),
'arguments' => [
'wrapper' => 'div',
'id' => 'rangeColor'.$uniqId,
'name' => 'rangeColor[]',
'type' => 'color',
'value' => $v['color'],
'return' => true,
],
],
[
'arguments' => [
'name' => 'remove-'.$uniqId,
'label' => '',
'type' => 'button',
'attributes' => 'class="remove-item-img"',
'return' => true,
'script' => 'removeColorRange(
\''.$uniqId.'\'
)',
],
],
],
];
}
}
}
return $inputs;
}
/**
* Default values.
*
* @param array $values Array values.
*
* @return array Array with default values.
*
* @overrides Item->getDefaultGeneralValues.
*/
public function getDefaultGeneralValues(array $values): array
{
// Retrieve global - common inputs.
$values = parent::getDefaultGeneralValues($values);
// Default values.
if (isset($values['width']) === false) {
$values['width'] = 300;
}
if (isset($values['height']) === false) {
$values['height'] = 180;
}
return $values;
}
}

View File

@ -124,9 +124,9 @@ final class DonutGraph extends Item
// Maybe connect to node.
$nodeConnected = false;
if (\is_metaconsole() === true && $metaconsoleId !== null) {
$server = \metaconsole_get_connection_by_id($metaconsoleId);
$nodeConnected = \metaconsole_connect(
null,
$metaconsoleId
$server
) === NOERR;
if ($nodeConnected === false) {
@ -147,28 +147,14 @@ final class DonutGraph extends Item
$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;
}
if ($isString === true) {
$graphData = \get_donut_module_data($moduleId);
$data['html'] = \d3_donut_graph(
(int) $data['id'],
@ -183,11 +169,125 @@ final class DonutGraph extends Item
$src = '../../'.$src;
}
$data['html'] = '<img src="'.$src.'">';
$style = 'width:'.$width.'px; height:'.$height.'px;';
$data['html'] = '<img src="'.$src.'" style="'.$style.'">';
}
// Restore connection.
if ($nodeConnected === true) {
\metaconsole_restore_db();
}
return $data;
}
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
// Retrieve global - common inputs.
$inputs = Item::getFormInputs($values);
if (is_array($inputs) !== true) {
throw new Exception(
'[DonutGraph]::getFormInputs parent class return is not an array'
);
}
if ($values['tabSelected'] === 'specific') {
// Autocomplete agents.
$inputs[] = [
'label' => __('Agent'),
'arguments' => [
'type' => 'autocomplete_agent',
'name' => 'agentAlias',
'id_agent_hidden' => $values['agentId'],
'name_agent_hidden' => 'agentId',
'server_id_hidden' => $values['metaconsoleId'],
'name_server_hidden' => 'metaconsoleId',
'return' => true,
'module_input' => true,
'module_name' => 'moduleId',
'module_none' => false,
],
];
// Autocomplete module.
$inputs[] = [
'label' => __('Module'),
'arguments' => [
'type' => 'autocomplete_module',
'fields' => $fields,
'name' => 'moduleId',
'selected' => $values['moduleId'],
'return' => true,
'sort' => false,
'agent_id' => $values['agentId'],
'metaconsole_id' => $values['metaconsoleId'],
],
];
// Resume data color.
$inputs[] = [
'label' => __('Resume data color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'legendBackgroundColor',
'type' => 'color',
'value' => $values['legendBackgroundColor'],
'return' => true,
],
];
// Inputs LinkedVisualConsole.
$inputsLinkedVisualConsole = self::inputsLinkedVisualConsole(
$values
);
foreach ($inputsLinkedVisualConsole as $key => $value) {
$inputs[] = $value;
}
}
return $inputs;
}
/**
* Default values.
*
* @param array $values Array values.
*
* @return array Array with default values.
*
* @overrides Item->getDefaultGeneralValues.
*/
public function getDefaultGeneralValues(array $values): array
{
// Retrieve global - common inputs.
$values = parent::getDefaultGeneralValues($values);
// Default values.
if (isset($values['width']) === false) {
$values['width'] = 300;
}
if (isset($values['height']) === false) {
$values['height'] = 300;
}
return $values;
}
}

View File

@ -102,12 +102,6 @@ final class EventsHistory extends Item
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,
@ -116,7 +110,8 @@ final class EventsHistory extends Item
(int) $data['height'],
static::extractMaxTime($data),
'',
true
true,
2
);
$data['html'] = $html;
@ -156,4 +151,121 @@ final class EventsHistory extends Item
}
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
// Retrieve global - common inputs.
$inputs = Item::getFormInputs($values);
if (is_array($inputs) !== true) {
throw new Exception(
'[EventHistory]::getFormInputs parent class return is not an array'
);
}
if ($values['tabSelected'] === 'specific') {
// Autocomplete agents.
$inputs[] = [
'label' => __('Agent'),
'arguments' => [
'type' => 'autocomplete_agent',
'name' => 'agentAlias',
'id_agent_hidden' => $values['agentId'],
'name_agent_hidden' => 'agentId',
'server_id_hidden' => $values['metaconsoleId'],
'name_server_hidden' => 'metaconsoleId',
'return' => true,
'module_input' => true,
'module_name' => 'moduleId',
'module_none' => false,
],
];
// Autocomplete module.
$inputs[] = [
'label' => __('Module'),
'arguments' => [
'type' => 'autocomplete_module',
'fields' => $fields,
'name' => 'moduleId',
'selected' => $values['moduleId'],
'return' => true,
'sort' => false,
'agent_id' => $values['agentId'],
'metaconsole_id' => $values['metaconsoleId'],
],
];
// Type percentile.
$fields = [
'86400' => __('24h'),
'43200' => __('12h'),
'28800' => __('8h'),
'7200' => __('2h'),
'3600' => __('1h'),
];
$inputs[] = [
'label' => __('Max. Time'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'maxTime',
'selected' => $values['maxTime'],
'return' => true,
'sort' => false,
],
];
// Inputs LinkedVisualConsole.
$inputsLinkedVisualConsole = self::inputsLinkedVisualConsole(
$values
);
foreach ($inputsLinkedVisualConsole as $key => $value) {
$inputs[] = $value;
}
}
return $inputs;
}
/**
* Default values.
*
* @param array $values Array values.
*
* @return array Array with default values.
*
* @overrides Item->getDefaultGeneralValues.
*/
public function getDefaultGeneralValues(array $values): array
{
// Retrieve global - common inputs.
$values = parent::getDefaultGeneralValues($values);
// Default values.
if (isset($values['width']) === false) {
$values['width'] = 500;
}
if (isset($values['height']) === false) {
$values['height'] = 70;
}
return $values;
}
}

View File

@ -34,6 +34,68 @@ final class Group extends Item
protected static $indexCacheByUser = true;
/**
* Get the "show statistics" switch value.
*
* @param array $data Unknown input data structure.
*
* @return mixed If the statistics should be shown or not.
*/
private static function getShowStatistics(array $data)
{
return static::issetInArray(
$data,
[
'showStatistics',
'show_statistics',
]
);
}
/**
* Extract a group Id (for ACL) value.
*
* @param array $data Unknown input data structure.
*
* @return integer Valid identifier of a group.
*/
private static function getGroupId(array $data)
{
return static::parseIntOr(
static::issetInArray($data, ['id_group', 'groupId']),
null
);
}
/**
* Return a valid representation of a record in database.
*
* @param array $data Input data.
*
* @return array Data structure representing a record in database.
*
* @overrides Item->encode.
*/
protected function encode(array $data): array
{
$return = parent::encode($data);
$id_group = static::getGroupId($data);
if ($id_group !== null) {
$return['id_group'] = $id_group;
}
$show_statistics = static::getShowStatistics($data);
if ($show_statistics !== null) {
$return['show_statistics'] = static::parseBool($show_statistics);
}
return $return;
}
/**
* Returns a valid representation of the model.
*
@ -209,7 +271,7 @@ final class Group extends Item
$agentsOk = \agents_get_agents(
[
'id_grupo' => $groupId,
'status' => AGENT_STATUS_OK,
'status' => AGENT_STATUS_NORMAL,
],
['COUNT(*) AS total'],
'AR',
@ -221,20 +283,39 @@ final class Group extends Item
$numNormal = $agentsOk[0]['total'];
$numTotal = ($numCritical + $numWarning + $numUnknown + $numNormal);
$agentStats = [
'critical' => 0,
'warning' => 0,
'normal' => 0,
'unknown' => 0,
];
if ($numTotal !== 0) {
$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']
$agentStats
);
if (isset($data['width']) === false
|| (int) $data['width'] === 0
) {
$data['width'] = 500;
}
if (isset($data['height']) === false
|| (int) $data['height'] === 0
) {
$data['height'] = 70;
}
} else {
if (\is_metaconsole()) {
$groupFilter = $groupId;
@ -308,98 +389,54 @@ final class Group extends Item
*
* @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
array $agentStats
): 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: #e63c52;',
'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 = \number_format($agentStats['critical'], 2).'%';
$warning = \number_format($agentStats['warning'], 2).'%';
$normal = \number_format($agentStats['normal'], 2).'%';
$unknown = \number_format($agentStats['unknown'], 2).'%';
$html = '<div class="group-container">';
$html .= '<div class="group-item-title">';
$html .= $groupName;
$html .= '</div>';
$html .= '<div class="group-item-info">';
// Critical.
$html .= '<div style="'.$valueStyle.'background-color: #e63c52;">';
$html .= \number_format($agentStats['critical'], 2).'%';
$html .= '<div class="group-item-info-container">';
$html .= '<div class="value-style" style="background-color: #e63c52;">';
$html .= $critical;
$html .= '</div>';
$html .= '<div class="name-style">'.__('Critical').'</div>';
$html .= '</div>';
$html .= '<div style="'.$nameStyle.'">'.__('Critical').'</div>';
// Warning.
$html .= '<div style="'.$valueStyle.'background-color: #f8db3f;">';
$html .= \number_format($agentStats['warning'], 2).'%';
$html .= '<div class="group-item-info-container">';
$html .= '<div class="value-style" style="background-color: #f8db3f;">';
$html .= $warning;
$html .= '</div>';
$html .= '<div class="name-style">'.__('Warning').'</div>';
$html .= '</div>';
$html .= '<div style="'.$nameStyle.'">'.__('Warning').'</div>';
// Normal.
$html .= '<div style="'.$valueStyle.'background-color: #84b83c;">';
$html .= \number_format($agentStats['normal'], 2).'%';
$html .= '<div class="group-item-info-container">';
$html .= '<div class="value-style" style="background-color: #84b83c;">';
$html .= $normal;
$html .= '</div>';
$html .= '<div class="name-style">'.__('Normal').'</div>';
$html .= '</div>';
$html .= '<div style="'.$nameStyle.'">'.__('Normal').'</div>';
// Unknown.
$html .= '<div style="'.$valueStyle.'background-color: #9d9ea0;">';
$html .= \number_format($agentStats['unknown'], 2).'%';
$html .= '<div class="group-item-info-container">';
$html .= '<div class="value-style" style="background-color: #9d9ea0;">';
$html .= $unknown;
$html .= '</div>';
$html .= '<div class="name-style">'.__('Unknown').'</div>';
$html .= '</div>';
$html .= '<div style="'.$nameStyle.'">'.__('Unknown').'</div>';
$html .= '</td>';
$html .= '</tr>';
$html .= '</table>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
@ -447,4 +484,95 @@ final class Group extends Item
}
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
// Retrieve global - common inputs.
$inputs = Item::getFormInputs($values);
if (is_array($inputs) !== true) {
throw new Exception(
'[Group]::getFormInputs parent class return is not an array'
);
}
if ($values['tabSelected'] === 'specific') {
// List images VC.
if (isset($values['imageSrc']) === false) {
$values['imageSrc'] = 'appliance';
}
$baseUrl = ui_get_full_url('/', false, false, false);
$inputs[] = [
'label' => __('Image'),
'arguments' => [
'type' => 'select',
'fields' => self::getListImagesVC(),
'name' => 'imageSrc',
'selected' => $values['imageSrc'],
'script' => 'imageVCChange(\''.$baseUrl.'\',\''.$values['vCId'].'\')',
'return' => true,
],
];
$images = self::imagesElementsVC($values['imageSrc']);
$inputs[] = [
'block_id' => 'image-item',
'class' => 'flex-row flex-end w100p',
'direct' => 1,
'block_content' => [
['label' => $images],
],
];
// Group.
$inputs[] = [
'label' => __('Group'),
'arguments' => [
'type' => 'select_groups',
'name' => 'groupId',
'returnAllGroup' => true,
'privilege' => $values['access'],
'selected' => $values['groupId'],
'return' => true,
],
];
// Show statistics.
$inputs[] = [
'label' => __('Show statistics'),
'arguments' => [
'name' => 'showStatistics',
'id' => 'showStatistics',
'type' => 'switch',
'value' => $values['showStatistics'],
],
];
// Inputs LinkedVisualConsole.
$inputsLinkedVisualConsole = self::inputsLinkedVisualConsole(
$values
);
foreach ($inputsLinkedVisualConsole as $key => $value) {
$inputs[] = $value;
}
}
return $inputs;
}
}

View File

@ -129,4 +129,101 @@ final class Icon extends Item
}
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
// Retrieve global - common inputs.
$inputs = Item::getFormInputs($values);
if (is_array($inputs) !== true) {
throw new Exception(
'[Icon]::getFormInputs parent class return is not an array'
);
}
if ($values['tabSelected'] === 'specific') {
// List images VC.
if (isset($values['imageSrc']) === false) {
$values['imageSrc'] = 'appliance';
} else {
$explode_url = explode('/', $values['imageSrc']);
$total = count($explode_url);
$values['imageSrc'] = substr(
$explode_url[($total - 1)],
0,
-4
);
}
$baseUrl = ui_get_full_url('/', false, false, false);
$inputs[] = [
'label' => __('Image'),
'arguments' => [
'type' => 'select',
'fields' => self::getListImagesVC(),
'name' => 'imageSrc',
'selected' => $values['imageSrc'],
'script' => 'imageVCChange(\''.$baseUrl.'\',\''.$values['vCId'].'\',1)',
'return' => true,
],
];
$images = self::imagesElementsVC($values['imageSrc'], true);
$inputs[] = [
'block_id' => 'image-item',
'class' => 'flex-row flex-end w100p',
'direct' => 1,
'block_content' => [
['label' => $images],
],
];
// Inputs LinkedVisualConsole.
$inputsLinkedVisualConsole = self::inputsLinkedVisualConsole(
$values
);
foreach ($inputsLinkedVisualConsole as $key => $value) {
$inputs[] = $value;
}
}
return $inputs;
}
/**
* Default values.
*
* @param array $values Array values.
*
* @return array Array with default values.
*
* @overrides Item->getDefaultGeneralValues.
*/
public function getDefaultGeneralValues(array $values): array
{
if (isset($values['isLinkEnabled']) === false) {
$values['isLinkEnabled'] = false;
}
// Retrieve global - common inputs.
$values = parent::getDefaultGeneralValues($values);
return $values;
}
}

View File

@ -20,30 +20,6 @@ final class Label extends Item
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.
*
@ -61,4 +37,62 @@ final class Label extends Item
}
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
// Retrieve global - common inputs.
$inputs = Item::getFormInputs($values);
if (is_array($inputs) !== true) {
throw new Exception(
'[Label]::getFormInputs parent class return is not an array'
);
}
return $inputs;
}
/**
* Default values.
*
* @param array $values Array values.
*
* @return array Array with default values.
*
* @overrides Item->getDefaultGeneralValues.
*/
public function getDefaultGeneralValues(array $values): array
{
if (isset($values['isLinkEnabled']) === false) {
$values['isLinkEnabled'] = false;
}
// Retrieve global - common inputs.
$values = parent::getDefaultGeneralValues($values);
// Default values.
if (isset($values['width']) === false) {
$values['width'] = 10;
}
if (isset($values['height']) === false) {
$values['height'] = 10;
}
return $values;
}
}

View File

@ -218,64 +218,74 @@ final class Line extends Model
protected function encode(array $data): array
{
$result = [];
$result['type'] = LINE_ITEM;
$id = static::getId($data);
if ($id) {
$result['id'] = $id;
}
$id_layout = static::getIdLayout($data);
if ($id_layout) {
$result['id_layout'] = $id_layout;
$layoutId = static::getIdLayout($data);
if ($layoutId > 0) {
$result['id_layout'] = $layoutId;
}
$pos_x = static::parseIntOr(
static::issetInArray($data, ['x', 'pos_x', 'posX']),
$startX = static::parseIntOr(
static::issetInArray($data, ['pos_x', 'startX']),
null
);
if ($pos_x !== null) {
$result['pos_x'] = $pos_x;
if ($startX !== null) {
$result['pos_x'] = $startX;
}
$pos_y = static::parseIntOr(
static::issetInArray($data, ['y', 'pos_y', 'posY']),
$startY = static::parseIntOr(
static::issetInArray($data, ['pos_y', 'startY']),
null
);
if ($pos_y !== null) {
$result['pos_y'] = $pos_y;
if ($startY !== null) {
$result['pos_y'] = $startY;
}
$height = static::getHeight($data);
if ($height !== null) {
$result['height'] = $height;
}
$width = static::getWidth($data);
if ($width !== null) {
$result['width'] = $width;
}
$type = static::parseIntOr(
static::issetInArray($data, ['type']),
$endX = static::parseIntOr(
static::issetInArray($data, ['width', 'endX']),
null
);
if ($type !== null) {
$result['type'] = $type;
if ($endX !== null) {
$result['width'] = $endX;
}
$border_width = static::getBorderWidth($data);
if ($border_width !== null) {
$result['border_width'] = $border_width;
$endY = static::parseIntOr(
static::issetInArray($data, ['height', 'endY']),
null
);
if ($endY !== null) {
$result['height'] = $endY;
}
$border_color = static::extractBorderColor($data);
if ($border_color !== null) {
$result['border_color'] = $border_color;
$borderWidth = static::getBorderWidth($data);
if ($borderWidth !== null) {
if ($borderWidth < 1) {
$borderWidth = 1;
}
$show_on_top = static::issetInArray($data, ['isOnTop', 'show_on_top', 'showOnTop']);
if ($show_on_top !== null) {
$result['show_on_top'] = static::parseBool($show_on_top);
$result['border_width'] = $borderWidth;
}
$borderColor = static::extractBorderColor($data);
if ($borderColor !== null) {
$result['border_color'] = $borderColor;
}
$showOnTop = static::issetInArray(
$data,
[
'isOnTop',
'show_on_top',
'showOnTop',
]
);
if ($showOnTop !== null) {
$result['show_on_top'] = static::parseBool($showOnTop);
}
return $result;
@ -367,42 +377,122 @@ final class Line extends Model
*
* @param array $data Unknown input data structure.
*
* @return boolean The modeled element data structure stored into the DB.
* @return integer The modeled element data structure stored into the DB.
*
* @overrides Model::save.
*/
public function save(array $data=[]): bool
public function save(array $data=[]): int
{
$data_model = $this->encode($this->toArray());
$newData = $this->encode($data);
$save = \array_merge($data_model, $newData);
if (!empty($save)) {
if (empty($save['id'])) {
if (empty($data) === false) {
if (empty($data['id']) === true) {
// Insert.
$save = static::encode($data);
$result = \db_process_sql_insert('tlayout_data', $save);
if ($result !== false) {
$item = static::fromDB(['id' => $result]);
$item->setData($item->toArray());
}
} else {
// Update.
$result = \db_process_sql_update('tlayout_data', $save, ['id' => $save['id']]);
}
}
$dataModelEncode = $this->encode($this->toArray());
$dataEncode = $this->encode($data);
// Update the model.
if ($result) {
if (empty($save['id'])) {
$item = static::fromDB(['id' => $result]);
} else {
$save = array_merge($dataModelEncode, $dataEncode);
$result = \db_process_sql_update(
'tlayout_data',
$save,
['id' => $save['id']]
);
// Invalidate the item's cache.
if ($result !== false && $result > 0) {
$item = static::fromDB(['id' => $save['id']]);
}
if (!empty($item)) {
// Update the model.
if (empty($item) === false) {
$this->setData($item->toArray());
}
}
}
}
return $result;
}
/**
* Delete a line in the database
*
* @param integer $itemId Identifier of the Item.
*
* @return boolean The modeled element data structure stored into the DB.
*
* @overrides Model::delete.
*/
public function delete(int $itemId): bool
{
$result = db_process_sql_delete(
'tlayout_data',
['id' => $itemId]
);
return (bool) $result;
}
/**
* Generates inputs for form (global, common).
*
* @param array $values Default values.
*
* @return array Of inputs.
*/
public static function getFormInputs(array $values): array
{
$inputs = [];
if ($values['tabSelected'] === 'specific') {
// Width.
if ($values['borderWidth'] < 1) {
$values['borderWidth'] = 1;
}
$inputs[] = [
'label' => __('Width'),
'arguments' => [
'name' => 'borderWidth',
'type' => 'number',
'value' => $values['borderWidth'],
'return' => true,
'min' => 1,
],
];
// Color.
$inputs[] = [
'label' => __('Color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'borderColor',
'type' => 'color',
'value' => $values['borderColor'],
'return' => true,
],
];
// Show on top.
$inputs[] = [
'label' => __('Show on top'),
'arguments' => [
'name' => 'isOnTop',
'id' => 'isOnTop',
'type' => 'switch',
'value' => $values['isOnTop'],
],
];
}
return $inputs;
}
}

View File

@ -35,6 +35,97 @@ final class ModuleGraph extends Item
protected static $useHtmlOutput = true;
/**
* Extract the "show Legend" switch value.
*
* @param array $data Unknown input data structure.
*
* @return mixed If the statistics should be shown or not.
*/
private static function getShowLegend(array $data)
{
return static::issetInArray($data, ['showLegend', 'show_statistics']);
}
/**
* Return a valid representation of a record in database.
*
* @param array $data Input data.
*
* @return array Data structure representing a record in database.
*
* @overrides Item->encode.
*/
protected function encode(array $data): array
{
$return = parent::encode($data);
$id_custom_graph = static::extractIdCustomGraph($data);
if ($id_custom_graph !== null) {
$return['id_custom_graph'] = $id_custom_graph;
}
$type_graph = static::getTypeGraph($data);
if ($type_graph !== null) {
$return['type_graph'] = $type_graph;
}
$show_legend = static::getShowLegend($data);
if ($show_legend !== null) {
$return['show_statistics'] = static::parseBool($show_legend);
}
return $return;
}
/**
* Extract a custom id graph value.
*
* @param array $data Unknown input data structure.
*
* @return integer Valid identifier of an agent.
*/
private static function extractIdCustomGraph(array $data)
{
return static::parseIntOr(
static::issetInArray(
$data,
[
'id_custom_graph',
'idCustomGraph',
'customGraphId',
]
),
null
);
}
/**
* Extract a type graph value.
*
* @param array $data Unknown input data structure.
*
* @return string One of 'vertical' or 'horizontal'. 'vertical' by default.
*/
private static function getTypeGraph(array $data)
{
return static::notEmptyStringOr(
static::issetInArray(
$data,
[
'typeGraph',
'type_graph',
'graphType',
]
),
null
);
}
/**
* Returns a valid representation of the model.
*
@ -50,6 +141,7 @@ final class ModuleGraph extends Item
$return['type'] = MODULE_GRAPH;
$return['backgroundType'] = static::extractBackgroundType($data);
$return['period'] = static::extractPeriod($data);
$return['showLegend'] = static::extractShowLegend($data);
$customGraphId = static::extractCustomGraphId($data);
@ -68,7 +160,8 @@ final class ModuleGraph extends Item
*
* @param array $data Unknown input data structure.
*
* @return string 'transparent', 'white' or 'black'. 'transparent' by default.
* @return string 'transparent', 'white' or 'black'.
* 'transparent' by default.
*/
private static function extractBackgroundType(array $data): string
{
@ -102,6 +195,21 @@ final class ModuleGraph extends Item
}
/**
* Extract the "show Legend" switch value.
*
* @param array $data Unknown input data structure.
*
* @return boolean If the statistics should be shown or not.
*/
private static function extractShowLegend(array $data): bool
{
return static::parseBool(
static::issetInArray($data, ['showLegend', 'show_statistics'])
);
}
/**
* Extract a custom graph Id value.
*
@ -168,10 +276,11 @@ final class ModuleGraph extends Item
\enterprise_include_once('include/functions_metaconsole.php');
}
$imageOnly = false;
$imageOnly = true;
$backgroundType = static::extractBackgroundType($data);
$period = static::extractPeriod($data);
$showLegend = static::extractShowLegend($data);
$customGraphId = static::extractCustomGraphId($data);
$graphType = static::extractGraphType($data);
$linkedModule = static::extractLinkedModule($data);
@ -205,21 +314,26 @@ final class ModuleGraph extends Item
* the height of one of it to replicate the legacy functionality.
*/
$width = (int) $data['width'];
$height = (int) $data['height'];
// Custom graph.
if (empty($customGraphId) === false) {
$customGraph = \db_get_row('tgraph', 'id_graph', $customGraphId);
$params = [
'period' => $period,
'width' => (int) $data['width'],
'height' => ($data['height'] - 30),
'width' => $width,
'height' => $height,
'title' => '',
'unit_name' => null,
'show_alerts' => false,
'only_image' => $imageOnly,
'vconsole' => true,
'document_ready' => false,
'backgroundColor' => $backgroundType,
'return_img_base_64' => true,
'show_legend' => true,
'show_title' => false,
];
$paramsCombined = [
@ -230,7 +344,8 @@ final class ModuleGraph extends Item
'modules_series' => $customGraph['modules_series'],
];
$data['html'] = \graphic_combined_module(
$imgbase64 = 'data:image/jpg;base64,';
$imgbase64 .= \graphic_combined_module(
false,
$params,
$paramsCombined
@ -245,21 +360,27 @@ final class ModuleGraph extends Item
'agent_module_id' => $moduleId,
'period' => $period,
'show_events' => false,
'width' => (int) $data['width'],
'height' => ($data['height'] - 30),
'title' => \modules_get_agentmodule_name($moduleId),
'width' => $width,
'height' => $height,
'title' => \modules_get_agentmodule_name(
$moduleId
),
'unit' => \modules_get_unit($moduleId),
'only_image' => $imageOnly,
'menu' => false,
'backgroundColor' => $backgroundType,
'type_graph' => $graphType,
'vconsole' => true,
'document_ready' => false,
'return_img_base_64' => true,
'show_legend' => $showLegend,
'show_title' => false,
];
$data['html'] = \grafico_modulo_sparse($params);
$imgbase64 = 'data:image/jpg;base64,';
$imgbase64 .= \grafico_modulo_sparse($params);
}
$data['html'] = $imgbase64;
// Restore connection.
if ($nodeConnected === true) {
\metaconsole_restore_db();
@ -269,4 +390,260 @@ final class ModuleGraph extends Item
}
/**
* Return List custom graph.
*
* @return array
*/
public function getListCustomGraph():array
{
include_once 'include/functions_custom_graphs.php';
enterprise_include_once('include/functions_metaconsole.php');
$data = [];
if (is_metaconsole() === true) {
$data = metaconsole_get_custom_graphs(true);
} else {
$data = custom_graphs_get_user(
$config['id_user'],
false,
true,
'RR'
);
}
$data[0] = __('None');
return array_reverse($data);
}
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
// Retrieve global - common inputs.
$inputs = Item::getFormInputs($values);
if (is_array($inputs) !== true) {
throw new Exception(
'[ModuleGraph]::getFormInputs parent class return is not an array'
);
}
if ($values['tabSelected'] === 'specific') {
// Default values.
if (isset($values['period']) === false) {
$values['period'] = 3600;
}
// Background color.
$fields = [
'white' => __('White'),
'black' => __('Black'),
'transparent' => __('Transparent'),
];
$inputs[] = [
'label' => __('Background color'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'backgroundType',
'selected' => $values['backgroundType'],
'return' => true,
'sort' => false,
],
];
$hiddenModule = false;
$hiddenCustom = true;
$checkedModule = true;
$checkedCustom = false;
if (isset($values['customGraphId']) === true
&& $values['customGraphId'] !== 0
) {
$hiddenModule = true;
$hiddenCustom = false;
$checkedModule = false;
$checkedCustom = true;
}
// Choose Type module graph if graph normal or custom.
$inputs[] = [
'wrapper' => 'div',
'class' => 'flex-row-vcenter',
'direct' => 1,
'block_content' => [
[
'label' => __('Module Graph'),
'arguments' => [
'type' => 'radio_button',
'attributes' => 'class="btn"',
'name' => 'choosetype',
'value' => 'module',
'checkedvalue' => $checkedModule,
'script' => 'typeModuleGraph(\'module\')',
'return' => true,
],
],
[
'label' => __('Custom Graph'),
'arguments' => [
'type' => 'radio_button',
'attributes' => 'class="btn"',
'name' => 'choosetype',
'value' => 'custom',
'checkedvalue' => $checkedCustom,
'script' => 'typeModuleGraph(\'custom\')',
'return' => true,
],
],
],
];
// Autocomplete agents.
$inputs[] = [
'id' => 'MGautoCompleteAgent',
'hidden' => $hiddenModule,
'label' => __('Agent'),
'arguments' => [
'type' => 'autocomplete_agent',
'name' => 'agentAlias',
'id_agent_hidden' => $values['agentId'],
'name_agent_hidden' => 'agentId',
'server_id_hidden' => $values['metaconsoleId'],
'name_server_hidden' => 'metaconsoleId',
'return' => true,
'module_input' => true,
'module_name' => 'moduleId',
'module_none' => false,
],
];
// Autocomplete module.
$inputs[] = [
'id' => 'MGautoCompleteModule',
'hidden' => $hiddenModule,
'label' => __('Module'),
'arguments' => [
'type' => 'autocomplete_module',
'fields' => $fields,
'name' => 'moduleId',
'selected' => $values['moduleId'],
'return' => true,
'sort' => false,
'agent_id' => $values['agentId'],
'metaconsole_id' => $values['metaconsoleId'],
],
];
// Custom graph.
$fields = self::getListCustomGraph();
$inputs[] = [
'id' => 'MGcustomGraph',
'hidden' => $hiddenCustom,
'label' => __('Custom graph'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'customGraphId',
'selected' => $values['customGraphId'],
'return' => true,
],
];
// Period.
$inputs[] = [
'label' => __('Period'),
'arguments' => [
'name' => 'period',
'type' => 'interval',
'value' => $values['period'],
'nothing' => __('None'),
'nothing_value' => 0,
],
];
// Graph Type.
$fields = [
'line' => __('Line'),
'area' => __('Area'),
];
$inputs[] = [
'id' => 'MGgraphType',
'hidden' => $hiddenModule,
'label' => __('Graph Type'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'graphType',
'selected' => $values['graphType'],
'return' => true,
],
];
// Show legend.
$inputs[] = [
'id' => 'MGshowLegend',
'hidden' => $hiddenModule,
'label' => __('Show legend'),
'arguments' => [
'name' => 'showLegend',
'id' => 'showLegend',
'type' => 'switch',
'value' => $values['showLegend'],
],
];
// Inputs LinkedVisualConsole.
$inputsLinkedVisualConsole = self::inputsLinkedVisualConsole(
$values
);
foreach ($inputsLinkedVisualConsole as $key => $value) {
$inputs[] = $value;
}
}
return $inputs;
}
/**
* Default values.
*
* @param array $values Array values.
*
* @return array Array with default values.
*
* @overrides Item->getDefaultGeneralValues.
*/
public function getDefaultGeneralValues(array $values): array
{
// Retrieve global - common inputs.
$values = parent::getDefaultGeneralValues($values);
// Default values.
if (isset($values['width']) === false) {
$values['width'] = 300;
}
if (isset($values['height']) === false) {
$values['height'] = 180;
}
return $values;
}
}

View File

@ -28,6 +28,165 @@ final class Percentile extends Item
protected static $useLinkedVisualConsole = true;
/**
* Encode type item.
*
* @param array $data Data for encode.
*
* @return string Return 'PERCENTILE_BAR', 'PERCENTILE_BUBBLE',
* 'CIRCULAR_PROGRESS_BAR' or 'CIRCULAR_INTERIOR_PROGRESS_BAR'.
* 'PERCENTILE_BAR' by default.
*/
protected function encodePercentileType(array $data): ?int
{
$type = null;
if (isset($data['percentileType']) === true) {
switch ($data['percentileType']) {
case 'bubble':
$type = PERCENTILE_BUBBLE;
break;
case 'circular-progress-bar':
$type = CIRCULAR_PROGRESS_BAR;
break;
case 'circular-progress-bar-alt':
$type = CIRCULAR_INTERIOR_PROGRESS_BAR;
break;
default:
case 'progress-bar':
$type = PERCENTILE_BAR;
break;
}
}
return $type;
}
/**
* Encode type item.
*
* @param array $data Data for encode.
*
* @return string Return 'PERCENTILE_BAR', 'PERCENTILE_BUBBLE',
* 'CIRCULAR_PROGRESS_BAR' or 'CIRCULAR_INTERIOR_PROGRESS_BAR'.
* 'PERCENTILE_BAR' by default.
*/
protected function encodeValueType(array $data): ?string
{
$valueType = null;
if (isset($data['valueType']) === true) {
switch ($data['valueType']) {
case 'percent':
case 'value':
$valueType = $data['valueType'];
break;
default:
$valueType = 'percent';
break;
}
}
return $valueType;
}
/**
* Encode type item.
*
* @param array $data Data for encode.
*
* @return string Return 'PERCENTILE_BAR', 'PERCENTILE_BUBBLE',
* 'CIRCULAR_PROGRESS_BAR' or 'CIRCULAR_INTERIOR_PROGRESS_BAR'.
* 'PERCENTILE_BAR' by default.
*/
protected function encodeLabelColor(array $data): ?string
{
$labelColor = null;
if (isset($data['labelColor']) === true) {
$labelColor = $data['labelColor'];
}
return $labelColor;
}
/**
* Encode type item.
*
* @param array $data Data for encode.
*
* @return string Return 'PERCENTILE_BAR', 'PERCENTILE_BUBBLE',
* 'CIRCULAR_PROGRESS_BAR' or 'CIRCULAR_INTERIOR_PROGRESS_BAR'.
* 'PERCENTILE_BAR' by default.
*/
protected function encodeColor(array $data): ?string
{
$color = null;
if (isset($data['color']) === true) {
$color = $data['color'];
}
return $color;
}
/**
* Return a valid representation of a record in database.
*
* @param array $data Input data.
*
* @return array Data structure representing a record in database.
*
* @overrides Item->encode.
*/
protected function encode(array $data): array
{
$return = parent::encode($data);
$max_value = static::parseIntOr(
static::issetInArray($data, ['maxValue']),
null
);
if ($max_value !== null) {
$return['height'] = $max_value;
}
$min_value = static::parseIntOr(
static::issetInArray($data, ['minValue']),
null
);
if ($min_value !== null) {
$return['border_width'] = $min_value;
}
$percentileType = static::encodePercentileType($data);
if ($percentileType !== null) {
$return['type'] = (int) $percentileType;
}
$valueType = static::encodeValueType($data);
if ($valueType !== null) {
$return['image'] = (string) $valueType;
}
$color = static::encodeColor($data);
if ($border_color !== null) {
$return['border_color'] = $color;
}
$labelColor = static::encodeLabelColor($data);
if ($labelColor !== null) {
$return['fill_color'] = $labelColor;
}
return $return;
}
/**
* Returns a valid representation of the model.
*
@ -40,12 +199,11 @@ final class Percentile extends Item
protected function decode(array $data): array
{
$return = parent::decode($data);
$return['type'] = PERCENTILE_BAR;
$return['type'] = (int) $data['type'];
$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']),
static::issetInArray($data, ['minValue', 'border_width']),
null
);
$return['maxValue'] = static::parseFloatOr(
@ -200,10 +358,7 @@ final class Percentile extends Item
// Get the value type.
$valueType = static::extractValueType($data);
if ($moduleId === null) {
throw new \InvalidArgumentException('missing module Id');
}
if ($moduleId !== null && $moduleId !== 0) {
// Maybe connect to node.
$nodeConnected = false;
if (\is_metaconsole() === true && $metaconsoleId !== null) {
@ -225,13 +380,24 @@ final class Percentile extends Item
'error fetching the module value'
);
}
} else {
$moduleValue = 0;
}
// Store the module value.
$data['value'] = (float) \number_format((float) $moduleValue, (int) $config['graph_precision'], '.', '');
$data['value'] = (float) \number_format(
(float) $moduleValue,
(int) $config['graph_precision'],
'.',
''
);
$unit = '';
if ($moduleId !== null && $moduleId !== 0) {
$unit = \modules_get_unit($moduleId);
if (empty($unit) === false) {
$data['unit'] = \io_safe_output($unit);
}
}
// Restore connection.
if ($nodeConnected === true) {
@ -242,4 +408,197 @@ final class Percentile extends Item
}
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
// Retrieve global - common inputs.
$inputs = Item::getFormInputs($values);
if (is_array($inputs) !== true) {
throw new Exception(
'[Percentile]::getFormInputs parent class return is not an array'
);
}
// Default specific values.
if (isset($values['color']) === false) {
$values['color'] = '#000000';
}
if (isset($values['labelColor']) === false) {
$values['labelColor'] = '#bcbcbc';
}
if (isset($values['percentileType']) === false) {
$values['percentileType'] = 'circular-progress-bar';
}
if ($values['tabSelected'] === 'specific') {
// Type percentile.
$fields = [
'progress-bar' => __('Percentile'),
'bubble' => __('Bubble'),
'circular-progress-bar' => __('Circular porgress bar'),
'circular-progress-bar-alt' => __(
'Circular progress bar (interior)'
),
];
$inputs[] = [
'label' => __('Type'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'percentileType',
'selected' => $values['percentileType'],
'return' => true,
'sort' => false,
],
];
// Min Value.
$inputs[] = [
'label' => __('Min. Value'),
'arguments' => [
'name' => 'minValue',
'type' => 'number',
'value' => $values['minValue'],
'return' => true,
'min' => 0,
],
];
// Max Value.
$inputs[] = [
'label' => __('Max. Value'),
'arguments' => [
'name' => 'maxValue',
'type' => 'number',
'value' => $values['maxValue'],
'return' => true,
'min' => 0,
],
];
// Value to show.
$fields = [
'percent' => __('Percent'),
'value' => __('Value'),
];
$inputs[] = [
'label' => __('Value to show'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'valueType',
'selected' => $values['valueType'],
'return' => true,
'sort' => false,
],
];
// Element color.
$inputs[] = [
'label' => __('Element color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'color',
'type' => 'color',
'value' => $values['color'],
'return' => true,
],
];
// Value color.
$inputs[] = [
'label' => __('Value color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'labelColor',
'type' => 'color',
'value' => $values['labelColor'],
'return' => true,
],
];
// Autocomplete agents.
$inputs[] = [
'label' => __('Agent'),
'arguments' => [
'type' => 'autocomplete_agent',
'name' => 'agentAlias',
'id_agent_hidden' => $values['agentId'],
'name_agent_hidden' => 'agentId',
'server_id_hidden' => $values['metaconsoleId'],
'name_server_hidden' => 'metaconsoleId',
'return' => true,
'module_input' => true,
'module_name' => 'moduleId',
'module_none' => false,
],
];
// Autocomplete module.
$inputs[] = [
'label' => __('Module'),
'arguments' => [
'type' => 'autocomplete_module',
'fields' => $fields,
'name' => 'moduleId',
'selected' => $values['moduleId'],
'return' => true,
'sort' => false,
'agent_id' => $values['agentId'],
'metaconsole_id' => $values['metaconsoleId'],
],
];
// Inputs LinkedVisualConsole.
$inputsLinkedVisualConsole = self::inputsLinkedVisualConsole(
$values
);
foreach ($inputsLinkedVisualConsole as $key => $value) {
$inputs[] = $value;
}
}
return $inputs;
}
/**
* Default values.
*
* @param array $values Array values.
*
* @return array Array with default values.
*
* @overrides Item->getDefaultGeneralValues.
*/
public function getDefaultGeneralValues(array $values): array
{
// Retrieve global - common inputs.
$values = parent::getDefaultGeneralValues($values);
// Default values.
if (isset($values['width']) === false) {
$values['width'] = 100;
}
return $values;
}
}

Some files were not shown because too many files have changed in this diff Show More