From 7d9ffa59b0674128de5c7ea21ed7bc51da6703c4 Mon Sep 17 00:00:00 2001 From: sergio Date: Mon, 3 Oct 2022 14:27:33 +0200 Subject: [PATCH 001/128] ent #9417 fixed visual bug update buttom --- pandora_console/include/styles/sound_events.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/styles/sound_events.css b/pandora_console/include/styles/sound_events.css index 7b25e55a63..322cf52757 100644 --- a/pandora_console/include/styles/sound_events.css +++ b/pandora_console/include/styles/sound_events.css @@ -97,7 +97,7 @@ } #tabs-sound-modal button.upd, -input.upd { +#button-melody_sound { background-image: url(../../images/sound_wave.png); background-position: 90px 8px; } From 2c57873898a2e05411d40e2451901472213fe0e1 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 13 Oct 2022 12:03:15 +0200 Subject: [PATCH 002/128] fix alert deletion from agent alerts --- pandora_console/godmode/alerts/alert_list.list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php index 24b19f1586..c682062b0b 100644 --- a/pandora_console/godmode/alerts/alert_list.list.php +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -451,7 +451,7 @@ $simple_alerts = agents_get_alerts_simple( if (!$id_agente) { $url = 'index.php?sec='.$sec.'&sec2=godmode/alerts/alert_list&tab=list&pure='.$pure.'&offset='.$offset.$form_params; } else { - $url = 'index.php?sec='.$sec.'&sec2=godmode/agentes/configurar_agente&pure='.$pure.'&tab=alert&id_agente='.$id_agente.'&offset='.$offset.$form_params; + $url = 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&pure='.$pure.'&tab=alert&id_agente='.$id_agente.'&offset='.$offset.$form_params; } // Urls to sort the table. From 657e7fe7d5aff4973b516436db7efea6be76bda8 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 13 Oct 2022 12:27:31 +0200 Subject: [PATCH 003/128] fix count --- pandora_console/operation/search_agents.getdata.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/operation/search_agents.getdata.php b/pandora_console/operation/search_agents.getdata.php index a701b63f90..1010f2fc2a 100644 --- a/pandora_console/operation/search_agents.getdata.php +++ b/pandora_console/operation/search_agents.getdata.php @@ -269,7 +269,7 @@ if ($searchAgents) { if ($agents !== false) { $totalAgents = db_get_value_sql( - 'SELECT COUNT(id_agente) AS agent_count '.$sql + 'SELECT COUNT(DISTINCT id_agente) AS agent_count '.$sql ); } } From dbe329f1de1d7753b2f76d48276c65de04e13cf7 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 24 Oct 2022 15:17:02 +0200 Subject: [PATCH 004/128] #9494 Fixed custom data --- pandora_console/include/functions_events.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 9e0a3650d6..7f5e09d8e4 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1102,13 +1102,13 @@ function events_get_all( $sql_filters[] = sprintf( ' AND JSON_VALID(custom_data) = 1 AND (JSON_EXTRACT(custom_data, "$.*") LIKE lower("%%%s%%") COLLATE utf8mb4_0900_ai_ci) ', - io_safe_output($filter['custom_data']) + $filter['custom_data'] ); } else { $sql_filters[] = sprintf( ' AND JSON_VALID(custom_data) = 1 AND (JSON_SEARCH(JSON_KEYS(custom_data), "all", lower("%%%s%%") COLLATE utf8mb4_0900_ai_ci) IS NOT NULL) ', - io_safe_output($filter['custom_data']) + $filter['custom_data'] ); } } else { From 8bf3de92aed8af7ef72b90be598ec3d5291ff529 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 24 Oct 2022 17:23:08 +0200 Subject: [PATCH 005/128] fixed cron execution of modules with week day setted --- pandora_console/include/functions_cron.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_cron.php b/pandora_console/include/functions_cron.php index f7b1d25f13..62333f00b8 100644 --- a/pandora_console/include/functions_cron.php +++ b/pandora_console/include/functions_cron.php @@ -89,23 +89,34 @@ function cron_next_execution($cron, $module_interval, $module_id) 'id_agente_modulo', $module_id ); + + $cron_elems = explode(' ', $cron); + + if (isset($cron_elems[4]) === true) { + $cron_elems[4] = '*'; + } + + $cron = implode(' ', $cron_elems); + $cur_time = ($last_execution !== false) ? $last_execution : time(); $nex_time = cron_next_execution_date($cron, $cur_time, $module_interval); $nex_wday = (int) date('w', $nex_time); + // Check the wday values to avoid infinite loop. $wday_int = cron_get_interval($wday); if ($wday_int['down'] !== '*' && ($wday_int['down'] > 6 || ($wday_int['up'] !== false && $wday_int['up'] > 6))) { $wday = '*'; } - // Check day of the way. + // Check week day. while (!cron_check_interval($nex_wday, $wday)) { // If it does not acomplish the day of the week, go to the next day. $nex_time += SECONDS_1DAY; - $nex_time = cron_next_execution_date($cron, $nex_time, 0); $nex_wday = (int) date('w', $nex_time); } + $nex_time = cron_next_execution_date($cron, $nex_time, 0); + return ($nex_time - $cur_time); } From f9b2c9a2432ca0972ed85f0ee93e50dc95331ae3 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 25 Oct 2022 13:27:49 +0200 Subject: [PATCH 006/128] #9678 Fixed _time_down_human_ and _time_down_seconds_ --- pandora_server/lib/PandoraFMS/Core.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index cf3c0df901..edb5f7cc77 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1299,13 +1299,17 @@ sub pandora_execute_action ($$$$$$$$$;$$) { $group = get_db_single_row ($dbh, 'SELECT * FROM tgrupo WHERE id_grupo = ?', $agent->{'id_grupo'}); } - my $agent_status; - if(ref ($module) eq "HASH") { - $agent_status = get_db_single_row ($dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module->{'id_agente_modulo'}); + my $time_down; + if ($alert_mode == RECOVERED_ALERT && defined($extra_macros->{'_modulelaststatuschange_'})) { + $time_down = (time() - $extra_macros->{'_modulelaststatuschange_'}); + } else { + my $agent_status; + if(ref ($module) eq "HASH") { + $agent_status = get_db_single_row ($dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module->{'id_agente_modulo'}); + } + $time_down = (defined ($agent_status)) ? (time() - $agent_status->{'last_status_change'}) : undef; } - my $time_down = (defined ($agent_status)) ? (time() - $agent_status->{'last_status_change'}) : undef; - if (is_numeric($data)) { my $data_precision = $pa_config->{'graph_precision'}; $data = sprintf("%.$data_precision" . "f", $data); From 6dbc71713a630366095da8f97594468e7c70ec1f Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Tue, 25 Oct 2022 15:52:30 +0200 Subject: [PATCH 007/128] add enable modules massive option --- .../godmode/agentes/module_manager.php | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 6cfa2685b4..89c9ef5c81 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -454,8 +454,6 @@ if ($module_action === 'delete') { } } else if ($module_action === 'disable') { $id_agent_modules_disable = (array) get_parameter('id_delete'); - - $count_correct_delete_modules = 0; $updated_count = 0; foreach ($id_agent_modules_disable as $id_agent_module_disable) { @@ -499,6 +497,52 @@ if ($module_action === 'delete') { ); } } +} else if ($module_action === 'enable') { + $id_agent_modules_enable = (array) get_parameter('id_delete'); + $updated_count = 0; + + foreach ($id_agent_modules_enable as $id_agent_module_enable) { + $sql = sprintf( + 'UPDATE tagente_modulo + SET disabled = 0 + WHERE id_agente_modulo = %d', + $id_agent_module_enable + ); + + $id_agent_changed[] = modules_get_agentmodule_agent($id_agent_module_enable); + $agent_update_result = db_process_sql_update( + 'tagente', + ['update_module_count' => 1], + ['id_agente' => $id_agent_changed] + ); + + if (db_process_sql($sql) !== false && $agent_update_result !== false) { + $updated_count++; + } + } + + $count_modules_to_enable = count($id_agent_modules_enable); + + if ($updated_count === 0) { + ui_print_error_message( + sprintf( + __('There was a problem completing the operation. Applied to 0/%d modules.'), + $count_modules_to_enable + ) + ); + } else { + if ($updated_count == $count_modules_to_enable) { + ui_print_success_message(__('Operation finished successfully.')); + } else { + ui_print_error_message( + sprintf( + __('There was a problem completing the operation. Applied to %d/%d modules.'), + $updated_count, + $count_modules_to_enable + ) + ); + } + } } @@ -1283,6 +1327,7 @@ if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) { html_print_select( [ 'disable' => 'Disable selected modules', + 'enable' => 'Enable selected modules', 'delete' => 'Delete selected modules', ], 'module_action', @@ -1295,6 +1340,8 @@ if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) { false ); + echo '    '; + html_print_submit_button( __('Execute action'), 'submit_modules_action', From c32da23dd0cc25426d08beb792f0ee43285e5d13 Mon Sep 17 00:00:00 2001 From: "edu.corral" Date: Wed, 26 Oct 2022 10:46:20 +0200 Subject: [PATCH 008/128] ent 9501 user duplicated profiles --- .../godmode/users/configure_user.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index bc3c440f87..77bf40a6f3 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -1665,7 +1665,25 @@ $(document).ready (function () { } if (profile === '0' || group === '-1') { - alert(''); + alert(''); + return; + } + + var rows = $("#table_profiles tr"); + var control_profiles = 0; + + $('#table_profiles tr').each(function() { + var profile_user = $(this).find("td:first").text(); + var group_user = $(this).find("td").eq(1).text(); + + if(profile_user === profile_text && group_user === group_text){ + control_profiles = 1; + alert(''); + return; + } + }); + + if (control_profiles === 1){ return; } From 59f0bba7f3f857ba16da32d20c0aa5afb9c6cbaa Mon Sep 17 00:00:00 2001 From: Daniel Barbero Date: Thu, 27 Oct 2022 09:07:04 +0200 Subject: [PATCH 009/128] fix styles events list dashboards pandora_enterprise#9705 --- pandora_console/include/ajax/events.php | 2 +- .../include/styles/js/datatables.min.css | 44 ++++--------------- 2 files changed, 9 insertions(+), 37 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 5cb86d027e..c119e831d8 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -1580,7 +1580,7 @@ if ($get_extended_event) { $filter = get_parameter('filter', []); $similar_ids = get_parameter('similar_ids', $event_id); $group_rep = $filter['group_rep']; - $event_rep = $group_rep; + $event_rep = (empty($group_rep) === true) ? EVENT_GROUP_REP_EVENTS : $group_rep; $timestamp_first = $event['timestamp_first']; $timestamp_last = $event['timestamp_last']; $server_id = $event['server_id']; diff --git a/pandora_console/include/styles/js/datatables.min.css b/pandora_console/include/styles/js/datatables.min.css index 8478cd1469..1c4fce9fe0 100644 --- a/pandora_console/include/styles/js/datatables.min.css +++ b/pandora_console/include/styles/js/datatables.min.css @@ -457,8 +457,11 @@ button.ui-button::-moz-focus-inner { outline: 0; } .ui-dialog .ui-dialog-titlebar { - padding: 0.4em 1em; - position: relative; + height: 38px; + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; } .ui-dialog .ui-dialog-title { float: left; @@ -471,7 +474,6 @@ button.ui-button::-moz-focus-inner { .ui-dialog .ui-dialog-titlebar-close { position: absolute; right: 0.3em; - top: 50%; width: 20px; margin: -10px 0 0 0; padding: 1px; @@ -847,11 +849,7 @@ body .ui-tooltip { .ui-widget textarea, .ui-widget button { } -.ui-widget.ui-widget-content { - border: 1px solid #c5c5c5; -} .ui-widget-content { - border: 1px solid #ddd; background: #fff; color: #333; } @@ -859,7 +857,6 @@ body .ui-tooltip { color: #333; } .ui-widget-header { - border: 1px solid #ddd; background: #e9e9e9; color: #333; font-weight: bold; @@ -867,6 +864,9 @@ body .ui-tooltip { .ui-widget-header a { color: #333; } +.ui-dialog .ui-widget-header { + margin: -3px -3px 0px -3px; +} .ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default, @@ -998,34 +998,6 @@ a.ui-button:active, width: 16px; height: 16px; } -.ui-icon, -.ui-widget-content .ui-icon { - background-image: url("jQueryUI-1.12.1/themes/base/images/ui-icons_444444_256x240.png"); -} -.ui-widget-header .ui-icon { - background-image: url("jQueryUI-1.12.1/themes/base/images/ui-icons_444444_256x240.png"); -} -.ui-state-hover .ui-icon, -.ui-state-focus .ui-icon, -.ui-button:hover .ui-icon, -.ui-button:focus .ui-icon { - background-image: url("jQueryUI-1.12.1/themes/base/images/ui-icons_555555_256x240.png"); -} -.ui-state-active .ui-icon, -.ui-button:active .ui-icon { - background-image: url("jQueryUI-1.12.1/themes/base/images/ui-icons_ffffff_256x240.png"); -} -.ui-state-highlight .ui-icon, -.ui-button .ui-state-highlight.ui-icon { - background-image: url("jQueryUI-1.12.1/themes/base/images/ui-icons_777620_256x240.png"); -} -.ui-state-error .ui-icon, -.ui-state-error-text .ui-icon { - background-image: url("jQueryUI-1.12.1/themes/base/images/ui-icons_cc0000_256x240.png"); -} -.ui-button .ui-icon { - background-image: url("jQueryUI-1.12.1/themes/base/images/ui-icons_777777_256x240.png"); -} .ui-icon-blank { background-position: 16px 16px; } From 548308405c2862a268831acc5628178e4db2f0a2 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Thu, 27 Oct 2022 09:40:33 +0200 Subject: [PATCH 010/128] #9447 WIP --- pandora_server/util/pandora_manage.pl | 31 +++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 17a62f37dc..4ce5d40ae9 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -21,7 +21,7 @@ use JSON qw(decode_json encode_json); use MIME::Base64; use Encode qw(decode encode_utf8); use LWP::Simple; -#use Data::Dumper; +use Data::Dumper; # Default lib dir for RPM and DEB packages BEGIN { push @INC, '/usr/lib/perl5'; } @@ -1144,6 +1144,22 @@ sub help_screen_line($$$){ print "\n\t$option $parameters : $help.\n" unless ($param ne '' && $param ne $option); } +sub test ($) { + my (@item) = @_; + my @args = @ARGV; + my $arg_cont = 2; + my $total = $#args; + + print_log Dumper(@item); + + # print_log "$item[0]{name}\n\n"; + + while ($arg_cont <= $total) { + print_log "$args[$arg_cont]\n\n"; + $arg_cont++; + } +} + ############################################################################### ############################################################################### # CLI FUNCTIONS @@ -7648,9 +7664,16 @@ sub pandora_manage_main ($$$) { cli_delete_profile(); } elsif ($param eq '--create_event') { - param_check($ltotal, 20, 17); - cli_create_event(); - } + my @items = ( + {'type' => 'string', 'name' => 'user'}, + {'type' => 'int', 'name' => 'group'} + ); + + test(\@items); + # param_check($ltotal, 20, 17); + + # cli_create_event(); + } elsif ($param eq '--validate_event') { param_check($ltotal, 8, 7); cli_validate_event(); From d76d46c1abdd731512465ff7f79c3385a0b49fef Mon Sep 17 00:00:00 2001 From: "edu.corral" Date: Thu, 27 Oct 2022 13:00:39 +0200 Subject: [PATCH 011/128] ent 9466 tip icon fix --- pandora_console/godmode/agentes/agent_manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 676a4db993..2261c5e9a5 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -309,7 +309,7 @@ $table_ip .= '
'.html_print_input( 'name' => 'fixed_ip', 'value' => $fixed_ip, ] -).__('Fix IP address').ui_print_help_tip(__('Avoid automatic IP address update when agent IP changes.'), true).'
'; +).__('Fix IP address').'

'.ui_print_help_tip(__('Avoid automatic IP address update when agent IP changes.'), true).'

'; $table_ip .= ''; From 8a43421b49aad8d5ee2a72d44a4a41247de2d35e Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 27 Oct 2022 15:18:15 +0200 Subject: [PATCH 012/128] Fix module type validadion on api set create network module --- pandora_console/include/functions_api.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 0f5f01590d..8b8c46e7c3 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -3587,6 +3587,19 @@ function api_set_create_network_module($id, $thrash1, $other, $thrash3) // Column 'module_macros' cannot be null. } + $type_exist = db_get_value_filter( + 'id_tipo', + 'ttipo_modulo', + [ + 'id_tipo' => $values['id_tipo_modulo'], + ] + ); + + if ((bool) $type_exist === false) { + returnError('Module type does not exist'); + return; + } + if ($agent_by_alias) { $agents_affected = 0; $idModule = false; From 6d19391c723bd77673886b7d634cd026953e1e2b Mon Sep 17 00:00:00 2001 From: Daniel Barbero Date: Thu, 27 Oct 2022 16:12:17 +0200 Subject: [PATCH 013/128] fix interfaces charts pandora_enterprise#9683 --- pandora_console/include/functions_graph.php | 6 +++++- .../include/functions_reporting_html.php | 16 ++++++---------- pandora_console/include/functions_ui.php | 13 +++++++------ .../include/graphs/flot/pandora.flot.js | 8 ++++---- pandora_console/include/styles/agent_view.css | 4 ---- .../operation/agentes/estado_generalagente.php | 13 +++---------- .../agentes/interface_traffic_graph_win.php | 2 ++ 7 files changed, 27 insertions(+), 35 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 11012b96eb..dc2616765c 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1416,7 +1416,7 @@ function graphic_combined_module( } } - if (isset($sources) && is_array($sources)) { + if (isset($sources) === true && is_array($sources) === true) { $weights = []; $labels = []; $modules = []; @@ -1498,6 +1498,10 @@ function graphic_combined_module( } } + if ((bool) $params_combined['from_interface'] === true) { + $labels = []; + } + if ($module_list) { $params_combined['modules_id'] = $module_list; } else { diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index cd764dbf32..e5342f0a2c 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -5980,11 +5980,7 @@ function reporting_get_event_histogram($events, $text_header_event=false) include_once '../../include/graphs/functions_gd.php'; } - $max_value = count($events); - - if (is_metaconsole()) { - $max_value = SECONDS_1HOUR; - } + $period = SECONDS_1DAY; if (!$text_header_event) { $text_header_event = __('Events info (1hr.)'); @@ -6057,7 +6053,7 @@ function reporting_get_event_histogram($events, $text_header_event=false) } else { $graph_data[] = [ 'data' => $color, - 'utimestamp' => 1, + 'utimestamp' => SECONDS_1DAY, ]; } } @@ -6076,9 +6072,9 @@ function reporting_get_event_histogram($events, $text_header_event=false) $slicebar = flot_slicesbar_graph( $graph_data, - $max_value, - '450px;border:0', - 25, + $period, + '400px;border:0', + 40, $full_legend, $colors, $config['fontpath'], @@ -6091,7 +6087,7 @@ function reporting_get_event_histogram($events, $text_header_event=false) [], true, 1, - false, + 450, true ); diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 6ae90f29ef..d31a7010f9 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -4001,11 +4001,12 @@ function ui_toggle( ); // Options. + $style = 'overflow:hidden;'; if ($hidden_default) { - $style = 'display:none'; + $style .= 'height:0;'; $original = $img_b; } else { - $style = ''; + $style .= 'height:auto;'; $original = $img_a; } @@ -4111,24 +4112,24 @@ function ui_toggle( $output .= ' if (is_metaconsole == 0) {'; $output .= ' if (hide_tgl_ctrl_'.$uniqid.") {\n"; $output .= ' hide_tgl_ctrl_'.$uniqid." = 0;\n"; - $output .= " $('#tgl_div_".$uniqid."').toggle();\n"; + $output .= " $('#tgl_div_".$uniqid."').css('height', 'auto');\n"; $output .= " }\n"; $output .= " else {\n"; $output .= ' hide_tgl_ctrl_'.$uniqid." = 1;\n"; - $output .= " $('#tgl_div_".$uniqid."').toggle();\n"; + $output .= " $('#tgl_div_".$uniqid."').css('height', 0);\n"; $output .= " }\n"; $output .= " }\n"; $output .= " });\n"; $output .= " $('#tgl_ctrl_".$uniqid."').click(function() {\n"; $output .= ' if (hide_tgl_ctrl_'.$uniqid.") {\n"; $output .= ' hide_tgl_ctrl_'.$uniqid." = 0;\n"; - $output .= " $('#tgl_div_".$uniqid."').toggle();\n"; + $output .= " $('#tgl_div_".$uniqid."').css('height', 'auto');\n"; $output .= " $('#image_".$uniqid."').attr({src: '".$image_a."'});\n"; $output .= " $('#checkbox-".$switch_name."').prop('checked', true);\n"; $output .= " }\n"; $output .= " else {\n"; $output .= ' hide_tgl_ctrl_'.$uniqid." = 1;\n"; - $output .= " $('#tgl_div_".$uniqid."').toggle();\n"; + $output .= " $('#tgl_div_".$uniqid."').css('height', 0);\n"; $output .= " $('#image_".$uniqid."').attr({src: '".$image_b."'});\n"; $output .= " $('#checkbox-".$switch_name."').prop('checked', false);\n"; $output .= " }\n"; diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 16e1b31a82..629e1a48f4 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -2461,14 +2461,14 @@ function pandoraFlotArea( ); } else { $.each(update_legend, function(index, value) { - if (typeof value[x] !== "undefined") { + if (typeof value[x - 1] !== "undefined") { data_legend[index] = " Min: " + - number_format(value[x].min, 0, unit, short_data, divisor) + + number_format(value[x - 1].min, 0, unit, short_data, divisor) + " Max: " + - number_format(value[x].max, 0, unit, short_data, divisor) + + number_format(value[x - 1].max, 0, unit, short_data, divisor) + " Avg: " + - number_format(value[x].avg, 0, unit, short_data, divisor); + number_format(value[x - 1].avg, 0, unit, short_data, divisor); } else { data_legend[index] = " Min: " + 0 + " Max: " + 0 + " Avg: " + 0; } diff --git a/pandora_console/include/styles/agent_view.css b/pandora_console/include/styles/agent_view.css index 9b0ce63bdd..c4ce4f7d47 100644 --- a/pandora_console/include/styles/agent_view.css +++ b/pandora_console/include/styles/agent_view.css @@ -6,10 +6,6 @@ div#bullets_modules span { font-weight: 700; } -table#agent_interface_info .noresizevc.graph { - margin-bottom: 10px; -} - div.agent_details_agent_alias { flex: 1; } diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 91714803f9..970da79aaa 100755 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -681,9 +681,8 @@ if (!empty($network_interfaces)) { $table_interface->style['interface_graph'] = 'width: 20px;padding-top:0px;padding-bottom:0px;'; $table_interface->style['interface_event_graph'] = 'width: 35%;padding-top:0px;padding-bottom:0px;'; $table_interface->align['interface_event_graph'] = 'right'; - // $table_interface->style['interface_event_graph'] = 'width: 5%;padding-top:0px;padding-bottom:0px;'; - $table_interface->align['interface_event_graph_text'] = 'left'; - $table_interface->style['interface_name'] = 'width: 10%;padding-top:0px;padding-bottom:0px;'; + $table_interface->style['interface_event_graph'] = 'width: 3%;padding-top:0px;padding-bottom:0px;'; + $table_interface->style['interface_name'] = 'width: 30%;padding-top:0px;padding-bottom:0px;'; $table_interface->align['interface_name'] = 'left'; $table_interface->align['interface_ip'] = 'left'; $table_interface->align['last_contact'] = 'left'; @@ -819,12 +818,6 @@ if (!empty($network_interfaces)) { $data['interface_mac'] = $interface['mac']; $data['last_contact'] = __('Last contact: ').$last_contact; $data['interface_event_graph'] = $e_graph; - if ($event_text_cont == 0) { - $data['interface_event_graph_text'] = ui_print_help_tip('Module events graph', true); - $event_text_cont++; - } else { - $data['interface_event_graph_text'] = ''; - } $table_interface->data[] = $data; } @@ -939,7 +932,7 @@ if ($table_access_rate) { echo $agent_incidents; -if (isset($table_interface)) { +if (isset($table_interface) === true) { ui_toggle( html_print_table($table_interface, true), ''.__('Interface information (SNMP)').'', diff --git a/pandora_console/operation/agentes/interface_traffic_graph_win.php b/pandora_console/operation/agentes/interface_traffic_graph_win.php index 7e003eb013..6dd25aee23 100644 --- a/pandora_console/operation/agentes/interface_traffic_graph_win.php +++ b/pandora_console/operation/agentes/interface_traffic_graph_win.php @@ -95,10 +95,12 @@ if ($refresh > 0) { <?php echo __('%s Interface Graph', get_product_name()).' ('.agents_get_alias($agent_id).' - '.$interface_name; ?>) + + Date: Fri, 28 Oct 2022 10:10:53 +0200 Subject: [PATCH 014/128] fix timestamp modal event grouped by extra id pandora_enterprise#9716 --- pandora_console/include/functions_events.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 3aa121ec6a..c01215a486 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -4701,22 +4701,30 @@ function events_page_general($event) $data = []; $data[0] = __('Timestamp'); - if ($group_rep == 1 && $event['event_rep'] > 1) { - $data[1] = __('First event').': '.date($config['date_format'], $event['timestamp_first']).'
'.__('Last event').': '.date($config['date_format'], $event['timestamp_last']); + if ($event['event_rep'] > 1) { + $data[1] = __('First event').': '; + $data[1] .= date($config['date_format'], $event['timestamp_first']); + $data[1] .= '
'; + $data[1] .= __('Last event').': '; + $data[1] .= date($config['date_format'], $event['timestamp_last']); } else { $data[1] = date($config['date_format'], $event['utimestamp']); } $table_general->data[] = $data; - // $event['owner_user'] = $event['id_usuario']; $data = []; $data[0] = __('Owner'); - if (empty($event['owner_user'])) { + if (empty($event['owner_user']) === true) { $data[1] = ''.__('N/A').''; } else { - $user_owner = db_get_value('fullname', 'tusuario', 'id_user', $event['owner_user']); - if (empty($user_owner)) { + $user_owner = db_get_value( + 'fullname', + 'tusuario', + 'id_user', + $event['owner_user'] + ); + if (empty($user_owner) === true) { $user_owner = $event['owner_user']; } From f4693b3cba3f1c3f36272d9d1f7e9852be3398de Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 31 Oct 2022 16:59:38 +0100 Subject: [PATCH 015/128] #9447 Added check_value --- pandora_server/util/pandora_manage.pl | 103 ++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 13 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 4ce5d40ae9..19bf26c81d 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -1144,18 +1144,54 @@ sub help_screen_line($$$){ print "\n\t$option $parameters : $help.\n" unless ($param ne '' && $param ne $option); } -sub test ($) { - my (@item) = @_; - my @args = @ARGV; +sub check_values($) { + my ($check) = @_; + use experimental 'smartmatch'; + my $arg_cont = 2; + my $cont = 0; + my @args = @ARGV; my $total = $#args; - print_log Dumper(@item); - - # print_log "$item[0]{name}\n\n"; - while ($arg_cont <= $total) { - print_log "$args[$arg_cont]\n\n"; + # Check type. + if ($check->[$cont]->{'type'} eq 'json') { + my $json_out = eval { decode_json($args[$arg_cont]) }; + if ($@) + { + print "\nValue `$args[$arg_cont]` is an invalid json. \nError:$@\n"; + exit; + } + } + + # Check values. + if (defined($check->[$cont]->{'values'})) { + if (!($args[$arg_cont] ~~ $check->[$cont]->{'values'})) { + print "\nError: value `$args[$arg_cont]` is not valid for $check->[$cont]->{'name'}\n"; + print "\tAvailable options: \t$check->[$cont]->{'values'}->[0]"; + if (defined($check->[$cont]->{'text_extra'}->[0])) { + print " $check->[$cont]->{'text_extra'}->[0]"; + } + print "\n"; + + my $cont_aux = 1; + my $while = 'false'; + while ($while eq 'false') { + if (defined($check->[$cont]->{'values'}->[$cont_aux])) { + print "\t\t\t\t$check->[$cont]->{'values'}->[$cont_aux]"; + if (defined($check->[$cont]->{'text_extra'}->[$cont_aux])) { + print " $check->[$cont]->{'text_extra'}->[$cont_aux]"; + } + print "\n"; + } else { + exit; + } + $cont_aux++; + } + } + } + + $cont++; $arg_cont++; } } @@ -7664,13 +7700,54 @@ sub pandora_manage_main ($$$) { cli_delete_profile(); } elsif ($param eq '--create_event') { - my @items = ( - {'type' => 'string', 'name' => 'user'}, - {'type' => 'int', 'name' => 'group'} + my @fields = ( + {'name' => 'event'}, + { + 'name' => 'event_type', + 'values' => [ + 'unknown','alert_fired','alert_recovered','alert_ceased', + 'alert_manual_validation','recon_host_detected','system', + 'error','new_agent','going_up_warning','going_up_criticalgoing_down_warning', + 'going_down_normal','going_down_critical','going_up_normal','configuration_change' + ] + }, + {'name' => 'group_name'}, + {'name' => 'agent_name'}, + {'name' => 'module_name'}, + { + 'name' => 'event_status', + 'values' => ['0', '1'], + 'text_extra' => ['(New)', '(Validated)'] + }, + { + 'name' => 'severity', + 'values' => ['0', '1', '2', '3', '4', '5', '6'], + 'text_extra' => [ + '(Maintenance)', '(Informational)', '(Normal)', + '(Warning)', '(Critical)', '(Minor)', '(Major)' + ] + }, + {'name' => 'template_name'}, + {'name' => 'user_name'}, + {'name' => 'comment'}, + {'name' => 'source'}, + {'name' => 'id_extra'}, + {'name' => 'tags'}, + {'type' => 'json', 'name' => 'custom_data_json'}, + { + 'name' => 'force_create_agent', + 'values' => ['0', '1'] + }, + {'name' => 'critical_instructions'}, + {'name' => 'warning_instructions'}, + {'name' => 'unknown_instructions'}, + {'name' => 'use_alias'}, + {'name' => 'metaconsole'} ); - test(\@items); - # param_check($ltotal, 20, 17); + param_check($ltotal, 20, 17); + + check_values(\@fields); # cli_create_event(); } From 8971dba9c5f25c9fdb39e319b9f032fb77084ab3 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 31 Oct 2022 17:16:08 +0100 Subject: [PATCH 016/128] #9447 uncomment --- pandora_server/util/pandora_manage.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 19bf26c81d..3a90ea074a 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -7749,7 +7749,7 @@ sub pandora_manage_main ($$$) { check_values(\@fields); - # cli_create_event(); + cli_create_event(); } elsif ($param eq '--validate_event') { param_check($ltotal, 8, 7); From 7655c236371f288909c25c5074e4c5c198fea26d Mon Sep 17 00:00:00 2001 From: Daniel Barbero Date: Wed, 2 Nov 2022 13:40:23 +0100 Subject: [PATCH 017/128] fix api get events pandora_enterprise#9723 --- pandora_console/include/functions_api.php | 544 +++++-------------- pandora_console/include/functions_events.php | 8 +- 2 files changed, 140 insertions(+), 412 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 0f5f01590d..260bd2c166 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -64,6 +64,7 @@ use PandoraFMS\Agent; use PandoraFMS\Module; use PandoraFMS\Enterprise\Cluster; use PandoraFMS\Enterprise\Metaconsole\Node; +use PandoraFMS\Event; use PandoraFMS\SpecialDay; @@ -11228,366 +11229,6 @@ function api_set_gis_agent($id_agent, $trash1, $other, $return_type, $user_in_db } -function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db) -{ - global $config; - - $table_events = 'tevento'; - - // By default. - $status = 3; - $search = ''; - $event_type = ''; - $severity = -1; - $id_agent = -1; - $id_agentmodule = -1; - $id_alert_am = -1; - $id_event = -1; - $id_user_ack = 0; - $event_view_hr = 0; - $tag = ''; - $group_rep = EVENT_GROUP_REP_ALL; - $utimestamp_upper = 0; - $utimestamp_bottom = 0; - $id_alert_template = -1; - - $use_agent_name = ($other['data'][16] === '1') ? true : false; - - $filter = otherParameter2Filter($other, true, $use_agent_name); - - if (isset($filter['criticity'])) { - $severity = $filter['criticity']; - } - - if (isset($filter['id_agente'])) { - $id_agent = $filter['id_agente']; - } - - if (isset($filter['id_agentmodule'])) { - $id_agentmodule = $filter['id_agentmodule'][0]; - } - - if (isset($filter['id_alert_am'])) { - $id_alert_am = $filter['id_alert_am']; - } - - if (isset($filter['id_usuario'])) { - $id_user_ack = $filter['id_usuario']; - } - - if (isset($filter['estado'])) { - $status = $filter['estado']; - } - - if (isset($filter['evento'])) { - $search = $filter['evento']; - } - - if (isset($filter['id_alert_template'])) { - $id_alert_template = $filter['id_alert_template']; - } - - $id_group = (int) $filter['id_group']; - - $user_groups = users_get_groups($user_in_db, 'ER'); - $user_id_groups = []; - if (!empty($user_groups)) { - $user_id_groups = array_keys($user_groups); - } - - $is_admin = (bool) db_get_value( - 'is_admin', - 'tusuario', - 'id_user', - $user_in_db - ); - - if (isset($filter['id_group'])) { - // The admin can see all groups - if ($is_admin) { - if (($id_group !== -1) && ($id_group !== 0)) { - $id_groups = [$id_group]; - } - } else { - if (empty($id_group)) { - $id_groups = $user_id_groups; - } else { - if (in_array($id_group, $user_id_groups)) { - $id_groups = [$id_group]; - } else { - $id_groups = []; - } - } - } - } else { - if (!$is_admin) { - $id_groups = $user_id_groups; - } - } - - if (isset($filter['tag'])) { - $tag = $filter['tag']; - } - - if (isset($filter['event_type'])) { - $event_type = $filter['event_type']; - } - - if ($filter['utimestamp']) { - if (isset($filter['utimestamp']['>'])) { - $utimestamp_upper = $filter['utimestamp']['>']; - } - - if (isset($filter['utimestamp']['<'])) { - $utimestamp_bottom = $filter['utimestamp']['<']; - } - } - - // TODO MOVE THIS CODE AND THE CODE IN pandora_console/operation/events/events_list.php - // to a function. - $sql_post = ''; - - if (!empty($id_groups)) { - $sql_post = ' AND id_grupo IN ('.implode(',', $id_groups).')'; - } else { - // The admin can see all groups - if (!$is_admin) { - $sql_post = ' AND 1=0'; - } - } - - // Skip system messages if user is not PM - if (!check_acl($user_in_db, 0, 'PM')) { - $sql_post .= ' AND id_grupo != 0'; - } - - switch ($status) { - case 0: - case 1: - case 2: - $sql_post .= ' AND estado = '.$status; - break; - - case 3: - $sql_post .= ' AND (estado = 0 OR estado = 2)'; - break; - } - - if ($search != '') { - $sql_post .= " AND evento LIKE '%".io_safe_input($search)."%'"; - } - - if ($event_type != '') { - // If normal, warning, could be several (going_up_warning, going_down_warning... too complex - // for the user so for him is presented only "warning, critical and normal" - if ($event_type == 'warning' || $event_type == 'critical' || $event_type == 'normal') { - $sql_post .= " AND event_type LIKE '%$event_type%' "; - } else if ($event_type == 'not_normal') { - $sql_post .= " AND ( event_type LIKE '%warning%' - OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%' ) "; - } else { - $sql_post .= " AND event_type = '".$event_type."'"; - } - } - - if ($severity != -1) { - $sql_post .= ' AND criticity = '.$severity; - } - - if ($id_agent != -1) { - $sql_post .= ' AND id_agente = '.$id_agent; - } - - if ($id_agentmodule != -1) { - $sql_post .= ' AND id_agentmodule = '.$id_agentmodule; - } - - if ($id_event != -1) { - $sql_post .= ' AND id_evento = '.$id_event; - } - - if ($id_user_ack != '0') { - $sql_post .= " AND id_usuario = '".$id_user_ack."'"; - } - - if ($utimestamp_upper != 0) { - $sql_post .= ' AND utimestamp >= '.$utimestamp_upper; - } - - if ($utimestamp_bottom != 0) { - $sql_post .= ' AND utimestamp <= '.$utimestamp_bottom; - } - - if ($event_view_hr > 0) { - // Put hours in seconds - $unixtime = (get_system_time() - ($event_view_hr * SECONDS_1HOUR)); - $sql_post .= ' AND (utimestamp > '.$unixtime.' OR estado = 2)'; - } - - // Search by tag - if ($tag != '') { - $sql_post .= " AND tags LIKE '".io_safe_input($tag)."'"; - } - - // Inject the raw sql - if (isset($filter['sql'])) { - $sql_post .= ' AND ('.$filter['sql'].') '; - } - - // Inject agent ID filter (it is set as the first numeric key in filter array). - if (isset($filter[0]) === true) { - $sql_post .= ' AND '.$filter[0]; - } - - if ($id_alert_template !== -1) { - $sql_post .= ' AND talert_template_modules.id_alert_template = '.$id_alert_template; - } - - $alert_join = ''; - - if ($id_alert_template !== -1) { - $alert_join = ' INNER JOIN talert_template_modules ON '.$table_events.'.id_alert_am=talert_template_modules.id'; - } - - if ($group_rep == EVENT_GROUP_REP_ALL) { - if ($filter['total']) { - $sql = 'SELECT COUNT(*) - FROM '.$table_events.' - WHERE 1=1 '.$sql_post; - } else if ($filter['more_criticity']) { - $sql = 'SELECT criticity - FROM '.$table_events.' - WHERE 1=1 '.$sql_post.' - ORDER BY criticity DESC - LIMIT 1'; - } else { - if (is_metaconsole() === true) { - $sql = 'SELECT *, - (SELECT t2.nombre - FROM tgrupo t2 - WHERE t2.id_grupo = '.$table_events.'.id_grupo) AS group_name, - (SELECT t2.icon - FROM tgrupo t2 - WHERE t2.id_grupo = '.$table_events.'.id_grupo) AS group_icon - FROM '.$table_events.$alert_join.' - WHERE 1=1 '.$sql_post.' - ORDER BY utimestamp DESC'; - } else { - $sql = 'SELECT *, - (SELECT t1.alias - FROM tagente t1 - WHERE t1.id_agente = tevento.id_agente) AS agent_name, - (SELECT t2.nombre - FROM tgrupo t2 - WHERE t2.id_grupo = tevento.id_grupo) AS group_name, - (SELECT t2.icon - FROM tgrupo t2 - WHERE t2.id_grupo = tevento.id_grupo) AS group_icon, - (SELECT tmodule.name - FROM tmodule - WHERE id_module IN ( - SELECT tagente_modulo.id_modulo - FROM tagente_modulo - WHERE tagente_modulo.id_agente_modulo=tevento.id_agentmodule)) AS module_name - FROM '.$table_events.$alert_join.' - WHERE 1=1 '.$sql_post.' - ORDER BY utimestamp DESC'; - } - } - } else { - db_process_sql('SET group_concat_max_len = 9999999'); - - $sql = "SELECT *, MAX(id_evento) AS id_evento, - GROUP_CONCAT(DISTINCT user_comment SEPARATOR '') AS user_comment, - MIN(estado) AS min_estado, MAX(estado) AS max_estado, - COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_last - FROM ".$table_events.' - WHERE 1=1 '.$sql_post.' - GROUP BY evento, id_agentmodule - ORDER BY timestamp_last DESC'; - } - - if ($other['type'] == 'string') { - if ($other['data'] != '') { - returnError('Parameter error.'); - return; - } else { - // Default values - $separator = ';'; - } - } else if ($other['type'] == 'array') { - $separator = $other['data'][0]; - } - - $result = db_get_all_rows_sql($sql); - - if (($result !== false) - && (!$filter['total']) - && (!$filter['more_criticity']) - ) { - $urlImage = ui_get_full_url(false); - - // Add the description and image - foreach ($result as $key => $row) { - if (defined('METACONSOLE')) { - $row['agent_name'] = agents_meta_get_name( - $row['id_agente'], - 'none', - $row['server_id'] - ); - - $row['module_name'] = meta_modules_get_name( - $row['id_agentmodule'], - $row['server_id'] - ); - } - - // FOR THE TEST THE API IN THE ANDROID - // $row['evento'] = $row['id_evento']; - $row['description_event'] = events_print_type_description($row['event_type'], true); - $row['img_description'] = events_print_type_img($row['event_type'], true, true); - $row['criticity_name'] = get_priority_name($row['criticity']); - - switch ($row['criticity']) { - default: - case EVENT_CRIT_MAINTENANCE: - $img_sev = $urlImage.'/images/status_sets/default/severity_maintenance.png'; - break; - case EVENT_CRIT_INFORMATIONAL: - $img_sev = $urlImage.'/images/status_sets/default/severity_informational.png'; - break; - - case EVENT_CRIT_NORMAL: - $img_sev = $urlImage.'/images/status_sets/default/severity_normal.png'; - break; - - case EVENT_CRIT_WARNING: - $img_sev = $urlImage.'/images/status_sets/default/severity_warning.png'; - break; - - case EVENT_CRIT_CRITICAL: - $img_sev = $urlImage.'/images/status_sets/default/severity_critical.png'; - break; - } - - $row['img_criticy'] = $img_sev; - - $result[$key] = $row; - } - } - - $data['type'] = 'array'; - $data['data'] = $result; - - returnData($returnType, $data, $separator); - if (empty($result)) { - return false; - } - - return true; -} - - /** * Update an event * @@ -11657,71 +11298,158 @@ function api_set_event($id_event, $unused1, $params, $unused2, $unused3) /** + * Get events. * * @param $trash1 * @param $trah2 * @param $other * @param $returnType - * @param $user_in_db */ -function api_get_events($node_id, $trash2, $other, $returnType, $user_in_db=null) +function api_get_events($node_id, $trash2, $other, $returnType) { - if ($user_in_db !== null) { - $correct = get_events_with_user( - $trash1, - $trash2, - $other, - $returnType, - $user_in_db - ); + $separator = (isset($other['data'][0]) === true && empty($other['data'][0]) === false) ? $other['data'][0] : ';'; - $last_error = error_get_last(); - if (!$correct && !empty($last_error)) { - $errors = [ - E_ERROR, - E_WARNING, - E_USER_ERROR, - E_USER_WARNING, - ]; - if (in_array($last_error['type'], $errors)) { - returnError('ERROR_API_PANDORAFMS', $returnType); - } - } - - return; - } - - if ($other['type'] == 'string') { - if ($other['data'] != '') { - returnError('Parameter error.'); - return; + if (is_metaconsole() === true) { + if (empty($node_id) === true && (int) $node_id !== 0) { + $node_id = array_keys(metaconsole_get_names(['disabled' => 0])); + $node_id[] = 0; } else { - // Default values - $separator = ';'; + $node_id = [(int) $node_id]; } - } else if ($other['type'] == 'array') { - $separator = $other['data'][0]; - - // By default it uses agent alias. - $use_agent_name = ($other['data'][16] === '1') ? true : false; - - $filterString = otherParameter2Filter($other, false, $use_agent_name); + } else { + $node_id = 0; } - $dataRows = db_get_all_rows_filter('tevento', $filterString); + $filters = [ + 'group_rep' => EVENT_GROUP_REP_ALL, + 'severity' => (isset($other['data'][1]) === true) ? $other['data'][1] : null, + 'agent_alias' => (isset($other['data'][2]) === true) ? $other['data'][2] : null, + 'module_search' => (isset($other['data'][3]) === true) ? $other['data'][3] : null, + 'filter_only_alert' => (isset($other['data'][4]) === true) ? $other['data'][4] : null, + 'id_user_ack' => (isset($other['data'][5]) === true) ? $other['data'][5] : null, + 'date_from' => (isset($other['data'][6]) === true && empty($other['data'][6]) === false) ? date('y-m-d', $other['data'][6]) : null, + 'date_to' => (isset($other['data'][7]) === true && empty($other['data'][7]) === false) ? date('y-m-d', $other['data'][7]) : null, + 'time_from' => (isset($other['data'][6]) === true && empty($other['data'][6]) === false) ? date('h:i:s', $other['data'][6]) : null, + 'time_to' => (isset($other['data'][7]) === true && empty($other['data'][7]) === false) ? date('h:i:s', $other['data'][7]) : null, + 'status' => (isset($other['data'][8]) === true) ? $other['data'][8] : null, + 'search' => (isset($other['data'][9]) === true) ? $other['data'][9] : null, + 'id_group_filter' => (isset($other['data'][13]) === true) ? $other['data'][13] : null, + 'tag_with' => (isset($other['data'][14]) === true) ? $other['data'][14] : null, + 'event_type' => (isset($other['data'][15]) === true) ? $other['data'][15] : null, + 'id_server' => $node_id, + ]; - $last_error = error_get_last(); - if (empty($dataRows)) { - if (!empty($last_error)) { - returnError('ERROR_API_PANDORAFMS', $returnType); - - return; + $limit = null; + if (isset($other['data'][10]) === true) { + if (empty($other['data'][10]) === true) { + $limit = 0; + } else { + $limit = $other['data'][10]; } } - $data['type'] = 'array'; - $data['data'] = $dataRows; + $offset = null; + if (isset($other['data'][11]) === true) { + if (empty($other['data'][11]) === true) { + $offset = 0; + } else { + $offset = $other['data'][11]; + } + } + $fields = ['te.*']; + $order_direction = 'desc'; + $order_field = 'te.utimestamp'; + $filter_total = false; + if (isset($other['data'][12]) === true + && empty($other['data'][12]) === false + ) { + $filter_total = true; + if ($other['data'][12] === 'total') { + $fields = ['count']; + $limit = null; + $offset = null; + } else if ($other['data'][12] === 'more_criticity') { + $fields = ['te.criticity']; + $order_direction = 'desc'; + $order_field = 'te.criticity'; + $limit = 1; + $offset = 0; + } + } + + $events = Event::search( + $fields, + $filters, + $offset, + $limit, + $order_direction, + $order_field + ); + + $result = $events; + if (is_metaconsole() === true && empty($limit) === false) { + $result = $events['data']; + } + + if (is_array($result) === true && $filter_total === false) { + $urlImage = ui_get_full_url(false); + + // Add the description and image. + foreach ($result as $key => $row) { + if (is_metaconsole() === true) { + if (empty($row['id_agente']) === false) { + $row['agent_name'] = agents_meta_get_name( + $row['id_agente'], + 'none', + $row['server_id'] + ); + } + + if (empty($row['id_agentmodule']) === false) { + $row['module_name'] = meta_modules_get_name( + $row['id_agentmodule'], + $row['server_id'] + ); + } + } + + // FOR THE TEST THE API IN THE ANDROID. + $row['description_event'] = events_print_type_description($row['event_type'], true); + $row['img_description'] = events_print_type_img($row['event_type'], true, true); + $row['criticity_name'] = get_priority_name($row['criticity']); + + switch ($row['criticity']) { + default: + case EVENT_CRIT_MAINTENANCE: + $img_sev = $urlImage.'/images/status_sets/default/severity_maintenance.png'; + break; + + case EVENT_CRIT_INFORMATIONAL: + $img_sev = $urlImage.'/images/status_sets/default/severity_informational.png'; + break; + + case EVENT_CRIT_NORMAL: + $img_sev = $urlImage.'/images/status_sets/default/severity_normal.png'; + break; + + case EVENT_CRIT_WARNING: + $img_sev = $urlImage.'/images/status_sets/default/severity_warning.png'; + break; + + case EVENT_CRIT_CRITICAL: + $img_sev = $urlImage.'/images/status_sets/default/severity_critical.png'; + break; + } + + $row['img_criticy'] = $img_sev; + + $result[$key] = $row; + } + } + + $data['type'] = $returnType; + $data['data'] = $result; returnData($returnType, $data, $separator); return; } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 3aa121ec6a..7a70d3bcd7 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1311,7 +1311,7 @@ function events_get_all( 'te.', // Alt table tag for id_grupo. $user_admin_group_all, - (bool) $filter['search_secondary_groups'] + (bool) (isset($filter['search_secondary_groups']) === true) ? $filter['search_secondary_groups'] : false ); // FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)". } else if (check_acl($config['id_user'], 0, 'EW')) { @@ -1338,7 +1338,7 @@ function events_get_all( 'te.', // Alt table tag for id_grupo. $user_admin_group_all, - (bool) $filter['search_secondary_groups'] + (bool) (isset($filter['search_secondary_groups']) === true) ? $filter['search_secondary_groups'] : false ); // FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)". } else if (check_acl($config['id_user'], 0, 'EM')) { @@ -1365,7 +1365,7 @@ function events_get_all( 'te.', // Alt table tag for id_grupo. $user_admin_group_all, - (bool) $filter['search_secondary_groups'] + (bool) (isset($filter['search_secondary_groups']) === true) ? $filter['search_secondary_groups'] : false ); // FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)". } @@ -1870,7 +1870,7 @@ function events_get_all( return $return; } else { - return $data; + return ['count' => count($data)]; } } From 0ff07d7224dcad2ca44a26be92a2ee581384aca0 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Date: Wed, 2 Nov 2022 16:59:04 +0100 Subject: [PATCH 018/128] add new macro event response group_contact pandora_enterprise#9246 --- pandora_console/include/functions_events.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 3aa121ec6a..f034e48ca1 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -3721,6 +3721,15 @@ function events_get_response_target( ); } + if (strpos($target, '_group_contact_') !== false) { + $info_groups = groups_get_group_by_id($event['id_grupo']); + $target = str_replace( + '_group_contact_', + (isset($info_groups['contact']) === true) ? $info_groups['contact'] : 'N/A', + $target + ); + } + if (strpos($target, '_event_utimestamp_') !== false) { $target = str_replace( '_event_utimestamp_', From 92455e7ef99f7ed812e8c64ee6b9b020c796ba56 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 2 Nov 2022 17:36:17 +0100 Subject: [PATCH 019/128] fixed backup cron task --- pandora_console/include/db/mysql.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index 40eae95573..87cc29be15 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -1021,7 +1021,7 @@ function mysql_db_get_row_filter($table, $filter, $fields=false, $where_join='AN * * @return mixed Array of the row or false in case of error. */ -function mysql_db_get_all_rows_filter($table, $filter=[], $fields=false, $where_join='AND', $search_history_db=false, $returnSQL=false) +function mysql_db_get_all_rows_filter($table, $filter=[], $fields=false, $where_join='AND', $search_history_db=false, $returnSQL=false, $cache=true) { // TODO: Validate and clean fields if (empty($fields)) { @@ -1052,7 +1052,7 @@ function mysql_db_get_all_rows_filter($table, $filter=[], $fields=false, $where_ if ($returnSQL) { return $sql; } else { - return db_get_all_rows_sql($sql, $search_history_db); + return db_get_all_rows_sql($sql, $search_history_db, $cache); } } From ccc2e830f4231ae4219266d36df1c4282476e836 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Date: Thu, 3 Nov 2022 15:12:50 +0100 Subject: [PATCH 020/128] add sound events to metaconsole pandora_enterprise#8854 --- pandora_console/include/ajax/events.php | 2 +- .../include/javascript/pandora_events.js | 14 +++++++------- pandora_console/include/styles/sound_events.css | 3 +++ pandora_console/operation/menu.php | 5 +---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 5cb86d027e..b9a863cfcd 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -2270,7 +2270,7 @@ if ($drawConsoleSound === true) { ], ], [ - 'label' => __('Time Sound'), + 'label' => __('Sound duration'), 'arguments' => [ 'type' => 'select', 'fields' => $times_sound, diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index df84985a37..84be4f824c 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -920,7 +920,7 @@ function openSoundEventModal(settings) { sound = true; } - test_sound_button(sound); + test_sound_button(sound, settings.urlSound); }); // Play Stop. @@ -977,9 +977,9 @@ function openSoundEventModal(settings) { .show(); } -function test_sound_button(test_sound) { +function test_sound_button(test_sound, urlSound) { if (test_sound === true) { - add_audio(); + add_audio(urlSound); } else { remove_audio(); } @@ -1035,8 +1035,8 @@ function action_events_sound(mode, settings) { } } -function add_audio() { - var sound = "./include/sounds/" + $("#tabs-sound-modal #sound_id").val(); +function add_audio(urlSound) { + var sound = urlSound + $("#tabs-sound-modal #sound_id").val(); $(".actions-sound-modal").append( "