From 430457b30a5fa73f29a957d5da364e1254079d1b Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Tue, 15 Dec 2020 13:12:00 +0100 Subject: [PATCH 01/22] Deleted logstash references --- pandora_console/include/class/ConsoleSupervisor.php | 2 -- pandora_server/conf/pandora_server.conf.new | 4 ---- pandora_server/lib/PandoraFMS/Config.pm | 11 ----------- 3 files changed, 17 deletions(-) diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 2d14003ba2..5bfd50624b 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -658,7 +658,6 @@ class ConsoleSupervisor case 'NOTIF.PANDORADB.HISTORICAL': case 'NOTIF.HISTORYDB.MR': case 'NOTIF.EXT.ELASTICSEARCH': - case 'NOTIF.EXT.LOGSTASH': case 'NOTIF.METACONSOLE.DB_CONNECTION': case 'NOTIF.DOWNTIME': case 'NOTIF.UPDATEMANAGER.REGISTRATION': @@ -1790,7 +1789,6 @@ class ConsoleSupervisor { global $config; - // Cannot check logstash, configuration is only available from server. // Cannot check selenium, configuration is only available from server. if (isset($config['log_collector']) && $config['log_collector'] == 1 diff --git a/pandora_server/conf/pandora_server.conf.new b/pandora_server/conf/pandora_server.conf.new index ed561e2909..a951508b5d 100644 --- a/pandora_server/conf/pandora_server.conf.new +++ b/pandora_server/conf/pandora_server.conf.new @@ -668,10 +668,6 @@ syslog_max 65535 # Address # sync_address -# Target LogStash server, to allow Dataserver and SyslogServer store log information in ElasticSearch -#logstash_host ip -#logstash_port 10514 - # Pandora FMS Database HA Tool execution interval in seconds (PANDORA FMS ENTERPRISE ONLY). ha_interval 30 diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index f20ed49263..8e6a389c77 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -518,10 +518,6 @@ sub pandora_load_config { $pa_config->{"warmup_unknown_interval"} = 300; # 6.1 $pa_config->{"warmup_unknown_on"} = 1; # 6.1 - # Logstash - $pa_config->{"logstash_host"} = ''; - $pa_config->{"logstash_port"} = 0; - $pa_config->{"wuxserver"} = 1; # 7.0 $pa_config->{"wux_host"} = undef; # 7.0 $pa_config->{"wux_port"} = 4444; # 7.0 @@ -1192,13 +1188,6 @@ sub pandora_load_config { elsif ($parametro =~ m/^dynamic_constant\s+([0-9]*)/i) { $pa_config->{'dynamic_constant'}= clean_blank($1); } - - elsif ($parametro =~ m/^logstash_host\s+(.*)/i) { - $pa_config->{'logstash_host'}= clean_blank($1); - } - elsif ($parametro =~ m/^logstash_port\s+([0-9]*)/i) { - $pa_config->{'logstash_port'}= clean_blank($1); - } elsif ($parametro =~ m/^wuxserver\s+([0-1]*)/i) { $pa_config->{"wuxserver"} = clean_blank($1); } From 1f7a68cacc39dfd6e18c2de94bf2b60f2d1cbdd8 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 7 Jan 2021 16:37:13 +0100 Subject: [PATCH 02/22] Added group_password to print_agent --- pandora_server/lib/PandoraFMS/PluginTools.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index ecffeef396..62ed06e010 100644 --- a/pandora_server/lib/PandoraFMS/PluginTools.pm +++ b/pandora_server/lib/PandoraFMS/PluginTools.pm @@ -504,10 +504,20 @@ sub print_agent { # print header $xml .= "{'group_password'})) { + $xml .= " group_password='".$config->{'group_password'}."' "; } $xml .= ">"; From 32d09a23535f742fb6500020d36211d085147398 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 7 Jan 2021 18:24:51 +0100 Subject: [PATCH 03/22] added name method alias of nombre to Group class --- pandora_console/include/lib/Group.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pandora_console/include/lib/Group.php b/pandora_console/include/lib/Group.php index fc9615cfce..3bd6585344 100644 --- a/pandora_console/include/lib/Group.php +++ b/pandora_console/include/lib/Group.php @@ -105,6 +105,23 @@ class Group extends Entity } + /** + * Alias of 'nombre'. + * + * @param string|null $name Name of group. + * + * @return string|void Name assigned or void if set operation. + */ + public function name(?string $name=null) + { + if ($name === null) { + return $this->nombre(); + } + + return $this->nombre($name); + } + + /** * Retrieves a list of groups fitered. * From 96a8dbd0c8ed9b9dbe63c0f1b0f2c2976e9569e6 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 7 Jan 2021 18:25:59 +0100 Subject: [PATCH 04/22] added name method alias of nombre to Group class --- pandora_console/include/lib/Group.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/lib/Group.php b/pandora_console/include/lib/Group.php index 3bd6585344..a9c2ef6494 100644 --- a/pandora_console/include/lib/Group.php +++ b/pandora_console/include/lib/Group.php @@ -136,7 +136,7 @@ class Group extends Entity if (empty($filter['id_user']) === true) { // By default query current user groups. $filter['id_user'] = false; - } else if (!\users_is_admin()) { + } else if ((bool) \users_is_admin() === false) { // Override user queried if user is not an admin. $filter['id_user'] = false; } @@ -243,8 +243,9 @@ class Group extends Entity if (isset($config['centralized_management']) === true && $config['centralized_management'] > 0 ) { + $msg = 'cannot be modified in a centralized management environment'; throw new \Exception( - get_class($this).' error, cannot be modified while centralized management environment.' + get_class($this).' error, '.$msg ); } From 0be3e0ab90cddc49622817126f4089896dcb9999 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 10 Feb 2021 15:00:23 +0100 Subject: [PATCH 05/22] Event widget and some notices fixed --- pandora_console/general/header.php | 6 +- pandora_console/general/register.php | 7 +- .../include/class/ConsoleSupervisor.php | 30 +- pandora_console/include/class/HTML.class.php | 36 ++- pandora_console/include/functions_config.php | 2 +- pandora_console/include/functions_events.php | 128 ++++++++- .../include/lib/Dashboard/Manager.php | 38 +++ .../include/lib/Dashboard/Widget.php | 37 ++- .../lib/Dashboard/Widgets/events_list.php | 269 +++++++++++------- pandora_console/views/dashboard/header.php | 8 +- 10 files changed, 435 insertions(+), 126 deletions(-) diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index 1f573749e7..272af10720 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -877,7 +877,9 @@ if ($config['menu_type'] == 'classic') { blinkpubli(); var fb64 = ''; diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php index 9f90e7ad39..3d598383c1 100644 --- a/pandora_console/general/register.php +++ b/pandora_console/general/register.php @@ -188,7 +188,12 @@ try { $double_auth_enabled = (bool) db_get_value('id', 'tuser_double_auth', 'id_user', $config['id_user']); -if (!$double_auth_enabled && $config['2FA_all_users'] != '' +if (isset($config['2FA_all_users']) === false) { + $config['2FA_all_users'] = null; +} + +if (!$double_auth_enabled + && $config['2FA_all_users'] != '' && $config['2Fa_auth'] != '1' && $config['double_auth_enabled'] ) { diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index cc52f2062f..378eb29d68 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -118,8 +118,14 @@ class ConsoleSupervisor // Assign targets. $targets = get_notification_source_targets($this->sourceId); - $this->targetGroups = $targets['groups']; - $this->targetUsers = $targets['users']; + if (isset($targets['groups']) === true) { + $this->targetGroups = $targets['groups']; + } + + if (isset($targets['users']) === true) { + $this->targetUsers = $targets['users']; + } + $this->targetUpdated = true; } @@ -622,8 +628,14 @@ class ConsoleSupervisor if ($this->targetUpdated === false) { $targets = get_notification_source_targets($this->sourceId); - $this->targetGroups = $targets['groups']; - $this->targetUsers = $targets['users']; + if (isset($targets['groups']) === true) { + $this->targetGroups = $targets['groups']; + } + + if (isset($targets['users']) === true) { + $this->targetUsers = $targets['users']; + } + $this->targetUpdated = false; } @@ -631,8 +643,14 @@ class ConsoleSupervisor $source_id = $this->sourceId; // Assign targets. $targets = get_notification_source_targets($source_id); - $this->targetGroups = $targets['groups']; - $this->targetUsers = $targets['users']; + if (isset($targets['groups']) === true) { + $this->targetGroups = $targets['groups']; + } + + if (isset($targets['users']) === true) { + $this->targetUsers = $targets['users']; + } + $this->targetUpdated = false; } diff --git a/pandora_console/include/class/HTML.class.php b/pandora_console/include/class/HTML.class.php index 820062d7bc..6335d05e37 100644 --- a/pandora_console/include/class/HTML.class.php +++ b/pandora_console/include/class/HTML.class.php @@ -782,8 +782,40 @@ class HTML } if (isset($data['form']) === true) { - $output_head .= '
'; + $output_head .= ' 0) { - $children = groups_get_children($groups); + if ((bool) $user_is_admin === false + && isset($groups) === false + ) { + // Not being filtered by group but not an admin, limit results. + $groups = array_keys(users_get_groups(false, 'AR')); + } - $_groups = [ $groups ]; - if (empty($children) === false) { - foreach ($children as $child) { - $_groups[] = (int) $child['id_grupo']; + if (isset($groups) === true + && (is_array($groups) === true || ($groups > 0)) + ) { + if ($recursiveGroups === true) { + // Add children groups. + $children = []; + if (is_array($groups) === true) { + foreach ($groups as $g) { + $children = array_merge( + groups_get_children($g), + $children + ); + } + } else { + $children = groups_get_children($groups); } + + if (is_array($groups) === true) { + $_groups = $groups; + } else { + $_groups = [ $groups ]; + } + + if (empty($children) === false) { + foreach ($children as $child) { + $_groups[] = (int) $child['id_grupo']; + } + } + + if ((bool) $user_is_admin === false) { + $user_groups = users_get_groups(false, 'AR'); + $_groups = array_intersect( + $_groups, + array_keys($user_groups) + ); + } + + $groups = $_groups; } - $groups = $_groups; + if (is_array($groups) === false) { + $groups = [ $groups ]; + } $sql_filters[] = sprintf( ' AND (te.id_grupo IN (%s) OR tasg.id_group IN (%s))', @@ -1466,6 +1535,8 @@ function events_get_all( /** + * @deprecated Use events_get_all instead. + * * Get all rows of events from the database, that * pass the filter, and can get only some fields. * @@ -1502,7 +1573,9 @@ function events_get_all( */ function events_get_events($filter=false, $fields=false) { - if ($filter['criticity'] == EVENT_CRIT_WARNING_OR_CRITICAL) { + if (isset($filter['criticity']) === true + && (int) $filter['criticity'] === EVENT_CRIT_WARNING_OR_CRITICAL + ) { $filter['criticity'] = [ EVENT_CRIT_WARNING, EVENT_CRIT_CRITICAL, @@ -7363,3 +7436,40 @@ function events_get_instructions($event) return $output; } + + +/** + * Return class name matching criticity received. + * + * @param integer $criticity Event's criticity. + * + * @return string + */ +function events_get_criticity_class($criticity) +{ + switch ($criticity) { + case EVENT_CRIT_CRITICAL: + return 'datos_red'; + + case EVENT_CRIT_MAINTENANCE: + return 'datos_grey'; + + case EVENT_CRIT_INFORMATIONAL: + return 'datos_blue'; + + case EVENT_CRIT_MAJOR: + return 'datos_pink'; + + case EVENT_CRIT_MINOR: + return 'datos_pink'; + + case EVENT_CRIT_NORMAL: + return 'datos_green'; + + case EVENT_CRIT_WARNING: + return 'datos_yellow'; + + default: + return 'datos_blue'; + } +} diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php index 891ef524df..337027d426 100644 --- a/pandora_console/include/lib/Dashboard/Manager.php +++ b/pandora_console/include/lib/Dashboard/Manager.php @@ -257,6 +257,23 @@ class Manager $extradata = \get_parameter('extradata', ''); if (empty($extradata) === false) { $extradata = json_decode(\io_safe_output($extradata), true); + + if (isset($extradata['dashboardId']) === false) { + $extradata['dashboardId'] = null; + } + + if (isset($extradata['cellId']) === false) { + $extradata['cellId'] = null; + } + + if (isset($extradata['offset']) === false) { + $extradata['offset'] = null; + } + + if (isset($extradata['widgetId']) === false) { + $extradata['widgetId'] = null; + } + $this->dashboardId = (int) $extradata['dashboardId']; $this->cellId = (int) $extradata['cellId']; $this->offset = (int) $extradata['offset']; @@ -1031,6 +1048,10 @@ class Manager ); } + if (isset($config['public_dashboard']) === false) { + $config['public_dashboard'] = false; + } + // View. if ($this->slides === 0 || $this->cellModeSlides === 0) { View::render( @@ -1450,4 +1471,21 @@ class Manager } + /** + * Prints error. + * + * @param string $msg Message. + * + * @return void + */ + public function error(string $msg) + { + if ((bool) \is_ajax() === true) { + echo json_encode(['error' => $msg]); + } else { + \ui_print_error_message($msg); + } + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index bfc640eaf0..6e843803d5 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -21,7 +21,7 @@ class Widget * * @var integer */ - private $cellId; + protected $cellId; /** * Widget Id. @@ -99,8 +99,6 @@ class Widget */ public function getOptionsWidget():array { - global $config; - $result = []; if (empty($this->dataCell['options']) === false) { $result = \json_decode($this->dataCell['options'], true); @@ -591,4 +589,37 @@ class Widget } + /** + * Get description should be implemented for each child. + * + * @return string + */ + public static function getDescription() + { + return '**NOT DEFINED**'; + } + + + /** + * Load should be implemented for each child. + * + * @return string + */ + public function load() + { + return '**NOT DEFINED**'; + } + + + /** + * Get name should be implemented for each child. + * + * @return string + */ + public static function getName() + { + return '**NOT DEFINED**'; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index 5cce5ae1d7..b00fb7cde6 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -172,7 +172,7 @@ class EventsListWidget extends Widget $this->className = $class->getShortName(); // Title. - $this->title = __('List of latest events'); + $this->title = \__('List of latest events'); // Name. if (empty($this->name) === true) { @@ -242,6 +242,10 @@ class EventsListWidget extends Widget $values['groupId'] = $decoder['id_groups']; } + if (isset($decoder['groupRecursion']) === true) { + $values['groupRecursion'] = $decoder['groupRecursion']; + } + if (isset($decoder['groupId']) === true) { $values['groupId'] = $decoder['groupId']; } @@ -271,7 +275,7 @@ class EventsListWidget extends Widget $inputs = parent::getFormInputs(); $fields = \get_event_types(); - $fields['not_normal'] = __('Not normal'); + $fields['not_normal'] = \__('Not normal'); // Default values. if (isset($values['maxHours']) === false) { @@ -284,21 +288,21 @@ class EventsListWidget extends Widget // Event Type. $inputs[] = [ - 'label' => __('Event type'), + 'label' => \__('Event type'), 'arguments' => [ 'type' => 'select', 'fields' => $fields, 'name' => 'eventType', 'selected' => $values['eventType'], 'return' => true, - 'nothing' => __('Any'), + 'nothing' => \__('Any'), 'nothing_value' => 0, ], ]; // Max. hours old. Default 8. $inputs[] = [ - 'label' => __('Max. hours old'), + 'label' => \__('Max. hours old'), 'arguments' => [ 'name' => 'maxHours', 'type' => 'number', @@ -320,7 +324,7 @@ class EventsListWidget extends Widget ]; $inputs[] = [ - 'label' => __('Limit'), + 'label' => \__('Limit'), 'arguments' => [ 'type' => 'select', 'fields' => $fields, @@ -332,13 +336,13 @@ class EventsListWidget extends Widget // Event status. $fields = [ - -1 => __('All event'), - 1 => __('Only validated'), - 0 => __('Only pending'), + -1 => \__('All event'), + 1 => \__('Only validated'), + 0 => \__('Only pending'), ]; $inputs[] = [ - 'label' => __('Event status'), + 'label' => \__('Event status'), 'arguments' => [ 'type' => 'select', 'fields' => $fields, @@ -352,14 +356,14 @@ class EventsListWidget extends Widget $fields = \get_priorities(); $inputs[] = [ - 'label' => __('Severity'), + 'label' => \__('Severity'), 'arguments' => [ 'type' => 'select', 'fields' => $fields, 'name' => 'severity', 'selected' => $values['severity'], 'return' => true, - 'nothing' => __('All'), + 'nothing' => \__('All'), 'nothing_value' => -1, ], ]; @@ -367,14 +371,18 @@ class EventsListWidget extends Widget $return_all_group = false; $selected_groups_array = explode(',', $values['groupId'][0]); - if (users_can_manage_group_all('RM') || ($selected_groups_array[0] !== '' && in_array(0, $selected_groups_array) === true)) { - // Return all group if user has permissions or it is a currently selected group. + if ((bool) \users_can_manage_group_all('RM') === true + || ($selected_groups_array[0] !== '' + && in_array(0, $selected_groups_array) === true) + ) { + // Return all group if user has permissions or it is a currently + // selected group. $return_all_group = true; } // Groups. $inputs[] = [ - 'label' => __('Groups'), + 'label' => \__('Groups'), 'arguments' => [ 'type' => 'select_groups', 'name' => 'groupId[]', @@ -387,18 +395,31 @@ class EventsListWidget extends Widget ], ]; + // Group recursion. + $inputs[] = [ + 'label' => \__('Group recursion'), + 'arguments' => [ + 'type' => 'switch', + 'name' => 'groupRecursion', + 'value' => $values['groupRecursion'], + 'return' => true, + ], + ]; + // Tags. - $fields = tags_get_user_tags($config['id_user'], 'AR'); + $fields = \tags_get_user_tags($config['id_user'], 'AR'); $inputs[] = [ - 'label' => __('Tags'), + 'label' => \__('Tags'), 'arguments' => [ - 'type' => 'select', - 'fields' => $fields, - 'name' => 'tagsId[]', - 'selected' => explode(',', $values['tagsId'][0]), - 'return' => true, - 'multiple' => true, + 'type' => 'select', + 'fields' => $fields, + 'name' => 'tagsId[]', + 'selected' => explode(',', $values['tagsId'][0]), + 'return' => true, + 'multiple' => true, + 'nothing' => __('None'), + 'nothing_value' => 0, ], ]; @@ -423,6 +444,7 @@ class EventsListWidget extends Widget $values['severity'] = \get_parameter_switch('severity', -1); $values['groupId'] = \get_parameter_switch('groupId', []); $values['tagsId'] = \get_parameter_switch('tagsId', []); + $values['groupRecursion'] = \get_parameter_switch('groupRecursion', 0); return $values; } @@ -441,97 +463,138 @@ class EventsListWidget extends Widget $return_all_group = false; - if (users_can_manage_group_all('RM')) { + if ((bool) \users_can_manage_group_all('RM') === true) { $return_all_group = true; } $user_groups = \users_get_groups(false, 'AR', $return_all_group); - ui_require_css_file('events', 'include/styles/', true); - ui_require_css_file('tables', 'include/styles/', true); + \ui_require_css_file('events', 'include/styles/', true); + \ui_require_css_file('tables', 'include/styles/', true); $this->values['groupId'] = explode(',', $this->values['groupId'][0]); $this->values['tagsId'] = explode(',', $this->values['tagsId'][0]); if (empty($this->values['groupId']) === true) { - $output .= __('You must select some group'); + $output .= \__('You must select some group'); return $output; } - $useTags = \tags_has_user_acl_tags($config['id_user']); - if ($useTags) { + $useTags = (bool) \tags_has_user_acl_tags($config['id_user']); + if ($useTags === true) { if (empty($this->values['tagsId']) === true) { - $output .= __('You don\'t have access'); + $output .= \__('You don\'t have access'); return; } } $hours = ($this->values['maxHours'] * SECONDS_1HOUR); - $unixtime = (get_system_time() - $hours); // Put hours in seconds. $filter = []; - // Group all. - if (in_array(0, $this->values['groupId'])) { - $filter['id_grupo'] = array_keys($user_groups); - } else { - $filter['id_grupo'] = array_intersect($this->values['groupId'], array_keys($user_groups)); + $order = []; + + // Filtering. + $filter['event_view_hr'] = $hours; + + // Group. + $filter['id_group_filter'] = $this->values['groupId']; + if (empty($filter['id_group_filter']) === true + || $filter['id_group_filter'][0] === '' + || $filter['id_group_filter'][0] === '0' + ) { + // No filter specified. Don't filter at all... + $filter['id_group_filter'] = null; } - if (empty($filter['id_grupo'])) { - $output .= '
'; - $output .= \ui_print_error_message( - __('You have no access'), - '', - true + // Tags. + if (empty($this->values['tagsId']) === false) { + $filter['tag_with'] = base64_encode( + json_encode($this->values['tagsId']) ); - $output .= '
'; - return $output; } - $filter['utimestamp'] = '>'.$unixtime; + // Severity. + if (isset($this->values['severity']) === true) { + $filter['severity'] = $this->values['severity']; + } + // Event types. if (empty($this->values['eventType']) === false) { $filter['event_type'] = $this->values['eventType']; - - if ($filter['event_type'] === 'warning' - || $filter['event_type'] === 'critical' - || $filter['event_type'] === 'normal' - ) { - $filter['event_type'] = '%'.$filter['event_type'].'%'; - } else if ($filter['event_type'] === 'not_normal') { - unset($filter['event_type']); - $filter[] = '(event_type REGEXP "warning|critical|unknown")'; - } } + // Event status. if ((int) $this->values['eventStatus'] !== -1) { - $filter['estado'] = $this->values['eventStatus']; + $filter['status'] = $this->values['eventStatus']; } - $filter['limit'] = $this->values['limit']; - $filter['order'] = '`utimestamp` DESC'; + // Order. + $order['field'] = 'timestamp'; + $order['direction'] = 'DESC'; - if (isset($this->values['severity']) === true) { - if ((int) $this->values['severity'] === 20) { - $filter['criticity'] = [ - EVENT_CRIT_WARNING, - EVENT_CRIT_CRITICAL, - ]; - } else if ((int) $this->values['severity'] !== -1) { - $filter['criticity'] = $this->values['severity']; - } + $fields = [ + 'te.id_evento', + 'te.id_agente', + 'te.id_usuario', + 'te.id_grupo', + 'te.estado', + 'te.timestamp', + 'te.evento', + 'te.utimestamp', + 'te.event_type', + 'te.id_alert_am', + 'te.criticity', + 'te.user_comment', + 'te.tags', + 'te.source', + 'te.id_extra', + 'te.critical_instructions', + 'te.warning_instructions', + 'te.unknown_instructions', + 'te.owner_user', + 'if(te.ack_utimestamp > 0, from_unixtime(te.ack_utimestamp),"") as ack_utimestamp', + 'te.custom_data', + 'te.data', + 'te.module_status', + 'ta.alias as agent_name', + 'tg.nombre as group_name', + ]; + if ((bool) \is_metaconsole() === false) { + $fields[] = 'am.nombre as module_name'; + $fields[] = 'am.id_agente_modulo as id_agentmodule'; + $fields[] = 'am.custom_id as module_custom_id'; + $fields[] = 'ta.server_name as server_name'; + } else { + $fields[] = 'ts.server_name as server_name'; + $fields[] = 'te.id_agentmodule'; + $fields[] = 'te.server_id'; } - if (empty($this->values['tagsId']) === false) { - foreach ($this->values['tagsId'] as $tag) { - $tag_name[$tag] = \tags_get_name($tag); - } - - $filter['tags'] = $tag_name; - } - - $events = \events_get_events($filter); + $events = \events_get_all( + // Fields. + $fields, + // Filter. + $filter, + // Offset. + null, + // Limit. + $this->values['limit'], + // Order. + $order['direction'], + // Sort field. + $order['field'], + // History. + false, + // SQL. + false, + // Having. + '', + // ValidatedEvents. + false, + // Recursive Groups. + (bool) $this->values['groupRecursion'] + ); if ($events === false) { $events = []; @@ -542,9 +605,9 @@ class EventsListWidget extends Widget && is_array($events) === true && empty($events) === false ) { - $output .= html_print_input_hidden( + $output .= \html_print_input_hidden( 'ajax_file', - ui_get_full_url('ajax.php', false, false, false), + \ui_get_full_url('ajax.php', false, false, false), true ); @@ -558,15 +621,10 @@ class EventsListWidget extends Widget foreach ($events as $event) { $data = []; - $event['evento'] = io_safe_output($event['evento']); - if ($event['estado'] === 0) { - $img = 'images/pixel_red.png'; - } else { - $img = 'images/pixel_green.png'; - } + $event['evento'] = \io_safe_output($event['evento']); - $data[0] = events_print_type_img($event['event_type'], true); - $agent_alias = agents_get_alias($event['id_agente']); + $data[0] = \events_print_type_img($event['event_type'], true); + $agent_alias = \agents_get_alias($event['id_agente']); if ($agent_alias !== '') { $data[1] = ''; + $data[4] = ''; } - $data[2] .= substr(io_safe_output($event['evento']), 0, 150); + $data[4] .= substr(\io_safe_output($event['evento']), 0, 150); if (strlen($event['evento']) > 150) { - $data[2] .= '...'; + $data[4] .= '...'; } if ($this->publicLink === false) { - $data[2] .= ''; + $data[4] .= ''; } - $data[3] = ui_print_timestamp($event['timestamp'], true); + $data[5] = \ui_print_timestamp($event['timestamp'], true); $table->data[$i] = $data; $table->cellstyle[$i][0] = 'background: #E8E8E8;'; - $rowclass = get_priority_class($event['criticity']); + $rowclass = \events_get_criticity_class($event['criticity']); $table->cellclass[$i][1] = $rowclass; $table->cellclass[$i][2] = $rowclass; $table->cellclass[$i][3] = $rowclass; + $table->cellclass[$i][4] = $rowclass; + $table->cellclass[$i][5] = $rowclass; $i++; } - $output .= html_print_table($table, true); + $output .= \html_print_table($table, true); $output .= "
"; $output .= "
"; - $output .= "
"; - $output .= ui_require_javascript_file( + $output .= "
"; + $output .= \ui_require_javascript_file( 'pandora_events', 'include/javascript/', true @@ -632,7 +701,7 @@ class EventsListWidget extends Widget } else { $output .= '
'; $output .= \ui_print_info_message( - __('There are no events matching selected search filters'), + \__('There are no events matching selected search filters'), '', true ); @@ -650,7 +719,7 @@ class EventsListWidget extends Widget */ public static function getDescription() { - return __('List of latest events'); + return \__('List of latest events'); } diff --git a/pandora_console/views/dashboard/header.php b/pandora_console/views/dashboard/header.php index 0449e4dfb6..561196cc20 100644 --- a/pandora_console/views/dashboard/header.php +++ b/pandora_console/views/dashboard/header.php @@ -120,7 +120,9 @@ $publiclink['text'] .= html_print_image( $publiclink['text'] .= ''; // Refresh selector time dashboards. -if ($config['public_dashboard'] === true) { +if (isset($config['public_dashboard']) === true + && (bool) $config['public_dashboard'] === true +) { $urlRefresh = $publicUrl; } else { $queryRefresh = [ @@ -188,7 +190,9 @@ $newWidget['text'] .= html_print_image( ); $newWidget['text'] .= ''; -if ($config['public_dashboard'] === true) { +if (isset($config['public_dashboard']) === true + && (bool) $config['public_dashboard'] === true +) { $buttons = [ 'combo_refresh_one_dashboard' => $comboRefresh, 'combo_refresh_countdown' => $comboRefreshCountdown, From 20dc58a1400c527a055ed5ad84ed9dfc123f4dd1 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 10 Feb 2021 18:41:53 +0100 Subject: [PATCH 06/22] Improved event widget, added custom filters --- .../include/javascript/pandora_events.js | 8 ++ .../include/lib/Dashboard/Manager.php | 2 + .../include/lib/Dashboard/Widget.php | 11 ++ .../lib/Dashboard/Widgets/events_list.php | 121 ++++++++++++------ .../views/dashboard/configurationWidgets.php | 1 + 5 files changed, 107 insertions(+), 36 deletions(-) diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index c1b604b4e2..1a957cd4a5 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -1002,3 +1002,11 @@ function check_massive_response_event( counter++; }); } + +function event_widget_options() { + if ($("#customFilter").val() != "-1") { + $(".event-widget-input").disable(); + } else { + $(".event-widget-input").enable(); + } +} diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php index 337027d426..a9a1f5051e 100644 --- a/pandora_console/include/lib/Dashboard/Manager.php +++ b/pandora_console/include/lib/Dashboard/Manager.php @@ -1362,6 +1362,7 @@ class Manager $instance = $this->instanceWidget(); $htmlInputs = $instance->getFormInputs([]); + $js = $instance->getFormJS(); View::render( 'dashboard/configurationWidgets', @@ -1369,6 +1370,7 @@ class Manager 'dashboardId' => $this->dashboardId, 'cellId' => $this->cellId, 'htmlInputs' => $htmlInputs, + 'js' => $js, ] ); diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 6e843803d5..8d57ce1e86 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -622,4 +622,15 @@ class Widget } + /** + * Return aux javascript code for forms. + * + * @return string + */ + public function getFormJS() + { + return ''; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index b00fb7cde6..904cd2cdb8 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -246,6 +246,10 @@ class EventsListWidget extends Widget $values['groupRecursion'] = $decoder['groupRecursion']; } + if (isset($decoder['customFilter']) === true) { + $values['customFilter'] = $decoder['customFilter']; + } + if (isset($decoder['groupId']) === true) { $values['groupId'] = $decoder['groupId']; } @@ -258,6 +262,17 @@ class EventsListWidget extends Widget } + /** + * Aux javascript to be run after form load. + * + * @return string + */ + public function getFormJS(): string + { + return '$( document ).ready(function() {event_widget_options();});'; + } + + /** * Generates inputs for form (specific). * @@ -274,6 +289,21 @@ class EventsListWidget extends Widget // Retrieve global - common inputs. $inputs = parent::getFormInputs(); + // Select pre built filter. + $inputs[] = [ + 'label' => \__('Custom filters'), + 'arguments' => [ + 'type' => 'select', + 'id' => 'select-custom-filter', + 'fields' => \events_get_event_filter_select(false), + 'name' => 'customFilter', + 'script' => 'event_widget_options();', + 'nothing' => \__('None'), + 'nothing_value' => -1, + 'selected' => $this->values['customFilter'], + ], + ]; + $fields = \get_event_types(); $fields['not_normal'] = \__('Not normal'); @@ -292,6 +322,7 @@ class EventsListWidget extends Widget 'arguments' => [ 'type' => 'select', 'fields' => $fields, + 'class' => 'event-widget-input', 'name' => 'eventType', 'selected' => $values['eventType'], 'return' => true, @@ -306,6 +337,7 @@ class EventsListWidget extends Widget 'arguments' => [ 'name' => 'maxHours', 'type' => 'number', + 'class' => 'event-widget-input', 'value' => $values['maxHours'], 'return' => true, 'min' => 0, @@ -328,6 +360,7 @@ class EventsListWidget extends Widget 'arguments' => [ 'type' => 'select', 'fields' => $fields, + 'class' => 'event-widget-input', 'name' => 'limit', 'selected' => $values['limit'], 'return' => true, @@ -346,6 +379,7 @@ class EventsListWidget extends Widget 'arguments' => [ 'type' => 'select', 'fields' => $fields, + 'class' => 'event-widget-input', 'name' => 'eventStatus', 'selected' => $values['eventStatus'], 'return' => true, @@ -360,6 +394,7 @@ class EventsListWidget extends Widget 'arguments' => [ 'type' => 'select', 'fields' => $fields, + 'class' => 'event-widget-input', 'name' => 'severity', 'selected' => $values['severity'], 'return' => true, @@ -386,6 +421,7 @@ class EventsListWidget extends Widget 'arguments' => [ 'type' => 'select_groups', 'name' => 'groupId[]', + 'class' => 'event-widget-input', 'returnAllGroup' => true, 'privilege' => 'AR', 'selected' => $selected_groups_array, @@ -401,6 +437,7 @@ class EventsListWidget extends Widget 'arguments' => [ 'type' => 'switch', 'name' => 'groupRecursion', + 'class' => 'event-widget-input', 'value' => $values['groupRecursion'], 'return' => true, ], @@ -414,6 +451,7 @@ class EventsListWidget extends Widget 'arguments' => [ 'type' => 'select', 'fields' => $fields, + 'class' => 'event-widget-input', 'name' => 'tagsId[]', 'selected' => explode(',', $values['tagsId'][0]), 'return' => true, @@ -445,6 +483,7 @@ class EventsListWidget extends Widget $values['groupId'] = \get_parameter_switch('groupId', []); $values['tagsId'] = \get_parameter_switch('tagsId', []); $values['groupRecursion'] = \get_parameter_switch('groupRecursion', 0); + $values['customFilter'] = \get_parameter('customFilter', -1); return $values; } @@ -461,14 +500,6 @@ class EventsListWidget extends Widget $output = ''; - $return_all_group = false; - - if ((bool) \users_can_manage_group_all('RM') === true) { - $return_all_group = true; - } - - $user_groups = \users_get_groups(false, 'AR', $return_all_group); - \ui_require_css_file('events', 'include/styles/', true); \ui_require_css_file('tables', 'include/styles/', true); @@ -494,39 +525,51 @@ class EventsListWidget extends Widget $filter = []; $order = []; - // Filtering. - $filter['event_view_hr'] = $hours; - - // Group. - $filter['id_group_filter'] = $this->values['groupId']; - if (empty($filter['id_group_filter']) === true - || $filter['id_group_filter'][0] === '' - || $filter['id_group_filter'][0] === '0' - ) { - // No filter specified. Don't filter at all... - $filter['id_group_filter'] = null; - } - - // Tags. - if (empty($this->values['tagsId']) === false) { + $customFilter = \events_get_event_filter($this->values['customFilter']); + if ($customFilter !== false) { + $filter = $customFilter; $filter['tag_with'] = base64_encode( - json_encode($this->values['tagsId']) + json_encode($filter['tag_with']) ); - } - // Severity. - if (isset($this->values['severity']) === true) { - $filter['severity'] = $this->values['severity']; - } + $filter['tag_without'] = base64_encode( + json_encode($filter['tag_without']) + ); + } else { + // Filtering. + $filter['event_view_hr'] = $hours; - // Event types. - if (empty($this->values['eventType']) === false) { - $filter['event_type'] = $this->values['eventType']; - } + // Group. + $filter['id_group_filter'] = $this->values['groupId']; + if (empty($filter['id_group_filter']) === true + || $filter['id_group_filter'][0] === '' + || $filter['id_group_filter'][0] === '0' + ) { + // No filter specified. Don't filter at all... + $filter['id_group_filter'] = null; + } - // Event status. - if ((int) $this->values['eventStatus'] !== -1) { - $filter['status'] = $this->values['eventStatus']; + // Tags. + if (empty($this->values['tagsId']) === false) { + $filter['tag_with'] = base64_encode( + json_encode($this->values['tagsId']) + ); + } + + // Severity. + if (isset($this->values['severity']) === true) { + $filter['severity'] = $this->values['severity']; + } + + // Event types. + if (empty($this->values['eventType']) === false) { + $filter['event_type'] = $this->values['eventType']; + } + + // Event status. + if ((int) $this->values['eventStatus'] !== -1) { + $filter['status'] = $this->values['eventStatus']; + } } // Order. @@ -638,6 +681,12 @@ class EventsListWidget extends Widget $data[1] = ' '; } + if (isset($event['event_rep']) === true + && $event['event_rep'] > 1 + ) { + $data[1] .= ' ('.$event['event_rep'].')'; + } + // Group. $data[2] = $event['group_name']; diff --git a/pandora_console/views/dashboard/configurationWidgets.php b/pandora_console/views/dashboard/configurationWidgets.php index 5cebd952d7..d912027d53 100644 --- a/pandora_console/views/dashboard/configurationWidgets.php +++ b/pandora_console/views/dashboard/configurationWidgets.php @@ -51,6 +51,7 @@ HTML::printForm( [ 'form' => $form, 'inputs' => $htmlInputs, + 'js' => $js, ] ); From f445ddc9eaa011ccdfcd8507991da1356e6f8994 Mon Sep 17 00:00:00 2001 From: Luis Calvo Date: Fri, 5 Mar 2021 14:11:08 +0100 Subject: [PATCH 07/22] Fixed refresh auto hide on visual c --- pandora_console/operation/visual_console/view.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandora_console/operation/visual_console/view.php b/pandora_console/operation/visual_console/view.php index 7e39f2c856..169238db6b 100644 --- a/pandora_console/operation/visual_console/view.php +++ b/pandora_console/operation/visual_console/view.php @@ -422,6 +422,8 @@ ui_require_css_file('form'); var props = ; var items = ; var baseUrl = ""; + var controls = document.getElementById('vc-controls'); + autoHideElement(controls, 1000); var handleUpdate = function (prevProps, newProps) { if (!newProps) return; From b63f1ad681b587e51d39ab0b707279714419541e Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 15 Mar 2021 10:07:36 +0100 Subject: [PATCH 08/22] Removed extra verbosity --- pandora_console/operation/events/events_rss.php | 2 +- pandora_console/ws.php | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/pandora_console/operation/events/events_rss.php b/pandora_console/operation/events/events_rss.php index f6a155e676..613b88b423 100644 --- a/pandora_console/operation/events/events_rss.php +++ b/pandora_console/operation/events/events_rss.php @@ -30,7 +30,7 @@ global $config; // Don't display other errors, messes up XML. -ini_set('display_errors', E_ALL); +ini_set('display_errors', 0); require_once '../../include/config.php'; require_once '../../include/functions.php'; diff --git a/pandora_console/ws.php b/pandora_console/ws.php index 0c9509720c..e873cdf7f2 100644 --- a/pandora_console/ws.php +++ b/pandora_console/ws.php @@ -91,10 +91,6 @@ if (isset($config['gotty']) === false) { config_update_value('gotty', '/usr/bin/gotty'); } - -ini_set('display_errors', 1); -error_reporting(E_ALL); - $os = strtolower(PHP_OS); if (substr($os, 0, 3) !== 'win') { if (empty($config['gotty']) === false) { From 1762e758fa6ee8eebcd8c2f5dd65b3d659da482f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 15 Mar 2021 10:09:02 +0100 Subject: [PATCH 09/22] forced no display_errors --- pandora_console/include/config_process.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 1f0f644a72..83ddd741aa 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -52,6 +52,10 @@ if ((int) $develop_bypass === 1) { } ini_set('display_errors', 1); +} else { + // Leave user decide error_level, but limit errors to be displayed only in + // logs. + ini_set('display_errors', 0); } // Check if mysqli is available From 4c5f220264e5702f015a67d38b626ac8a529d62b Mon Sep 17 00:00:00 2001 From: marcos Date: Mon, 15 Mar 2021 17:55:54 +0100 Subject: [PATCH 10/22] fixed visual error --- pandora_console/include/class/AgentsAlerts.class.php | 2 +- pandora_console/include/functions_html.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/class/AgentsAlerts.class.php b/pandora_console/include/class/AgentsAlerts.class.php index 41a75ffa8a..b63860f84d 100644 --- a/pandora_console/include/class/AgentsAlerts.class.php +++ b/pandora_console/include/class/AgentsAlerts.class.php @@ -651,7 +651,7 @@ class AgentsAlerts extends HTML $alias = db_get_row('tagente', 'id_agente', $agent['id_agente']); echo ''; // Name of the agent. - echo ''.$alias['alias'].''; + echo ''.$alias['alias'].''; // Alerts of the agent. foreach ($templates as $tid => $tname) { $anyfired = 0; diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index adb1fd9b9d..cde4a9e867 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -467,10 +467,9 @@ function html_print_select_groups( $output = ''; global $config; + $select2_css = 'select2.min'; - if ($config['style'] === 'pandora') { - $select2_css = 'select2.min'; - } else { + if ($config['style'] === 'pandora_black') { $select2_css = 'select2_dark.min'; } From bfaaba9dbd1ea17683a39d8212c5632d5e298eb6 Mon Sep 17 00:00:00 2001 From: marcos Date: Thu, 18 Mar 2021 12:08:02 +0100 Subject: [PATCH 11/22] fixed spinner bug --- pandora_console/include/functions_snmp_browser.php | 6 +++--- pandora_console/include/styles/pandora.css | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index 5c55dd4e69..54bc1a5ce6 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -1065,16 +1065,16 @@ function snmp_browser_print_container( ); $output .= '
'; - $output .= '
'.html_print_image('images/spinner.gif', true).'
'; + $output .= ''; $output .= '
'; $output .= '
'; - $output .= '
'; + $output .= '
'; $output .= '
'; $output .= ''; $output .= ''; if ($show_massive_buttons) { - $output .= '