From d8e0df19122f2b12f84029e09beab960066ab40f Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Wed, 6 Sep 2023 08:52:46 +0200 Subject: [PATCH 01/14] #10983 new function for get date parameter and added parent date in dashboard --- pandora_console/extras/mr/66.sql | 5 ++ pandora_console/include/functions.php | 64 +++++++++++++++++++ pandora_console/include/functions_html.php | 14 ++++ .../include/lib/Dashboard/Manager.php | 11 ++++ .../include/lib/Dashboard/Widget.php | 51 +++++++++++++++ .../lib/Dashboard/Widgets/BlockHistogram.php | 3 + .../lib/Dashboard/Widgets/single_graph.php | 4 ++ pandora_console/pandoradb.sql | 3 + .../views/dashboard/formDashboard.php | 39 +++++++++++ 9 files changed, 194 insertions(+) diff --git a/pandora_console/extras/mr/66.sql b/pandora_console/extras/mr/66.sql index 8161c4c2b6..a30bcb4565 100644 --- a/pandora_console/extras/mr/66.sql +++ b/pandora_console/extras/mr/66.sql @@ -44,4 +44,9 @@ ADD COLUMN `time_init` VARCHAR(45) NULL AFTER `date_init`, ADD COLUMN `date_end` VARCHAR(45) NULL AFTER `time_init`, ADD COLUMN `time_end` VARCHAR(45) NULL AFTER `date_end`; +ALTER TABLE `tdashboard` +ADD COLUMN `date_range` TINYINT NOT NULL DEFAULT 0 AFTER `cells_slideshow`, +ADD COLUMN `date_from` INT NOT NULL DEFAULT 0 AFTER `date_range`, +ADD COLUMN `date_to` INT NOT NULL DEFAULT 0 AFTER `date_from`; + COMMIT; diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 0895325ef5..0a166a28d2 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -990,6 +990,70 @@ function get_parameter($name, $default='') } +function get_parameter_date($name, $default='', $date_format='Y/m/d') +{ + $date_end = get_parameter('date_end', 0); + $time_end = get_parameter('time_end'); + $datetime_end = strtotime($date_end.' '.$time_end); + + $custom_date = get_parameter('custom_date', 0); + $range = get_parameter('range', SECONDS_1DAY); + $date_text = get_parameter('range_text', SECONDS_1DAY); + $date_init_less = (strtotime(date('Y/m/d')) - SECONDS_1DAY); + $date_init = get_parameter('date_init', date(DATE_FORMAT, $date_init_less)); + $time_init = get_parameter('time_init', date(TIME_FORMAT, $date_init_less)); + $datetime_init = strtotime($date_init.' '.$time_init); + if ($custom_date === '1') { + if ($datetime_init >= $datetime_end) { + $datetime_init = $date_init_less; + } + + $date_init = date('Y/m/d H:i:s', $datetime_init); + $date_end = date('Y/m/d H:i:s', $datetime_end); + $period = ($datetime_end - $datetime_init); + } else if ($custom_date === '2') { + $date_units = get_parameter('range_units'); + $date_end = date('Y/m/d H:i:s'); + $date_init = date('Y/m/d H:i:s', (strtotime($date_end) - ((int) $date_text * (int) $date_units))); + $period = (strtotime($date_end) - strtotime($date_init)); + } else if (in_array($range, ['this_week', 'this_month', 'past_week', 'past_month'])) { + if ($range === 'this_week') { + $monday = date('Y/m/d', strtotime('last monday')); + + $sunday = date('Y/m/d', strtotime($monday.' +6 days')); + $period = (strtotime($sunday) - strtotime($monday)); + $date_init = $monday; + $date_end = $sunday; + } else if ($range === 'this_month') { + $date_end = date('Y/m/d', strtotime('last day of this month')); + $first_of_month = date('Y/m/d', strtotime('first day of this month')); + $date_init = $first_of_month; + $period = (strtotime($date_end) - strtotime($first_of_month)); + } else if ($range === 'past_month') { + $date_end = date('Y/m/d', strtotime('last day of previous month')); + $first_of_month = date('Y/m/d', strtotime('first day of previous month')); + $date_init = $first_of_month; + $period = (strtotime($date_end) - strtotime($first_of_month)); + } else if ($range === 'past_week') { + $date_end = date('Y/m/d', strtotime('sunday', strtotime('last week'))); + $first_of_week = date('Y/m/d', strtotime('monday', strtotime('last week'))); + $date_init = $first_of_week; + $period = (strtotime($date_end) - strtotime($first_of_week)); + } + } else { + $date_end = date('Y/m/d H:i:s'); + $date_init = date('Y/m/d H:i:s', (strtotime($date_end) - $range)); + $period = (strtotime($date_end) - strtotime($date_init)); + } + + return [ + 'date_init' => date($date_format, strtotime($date_init)), + 'date_end' => date($date_format, strtotime($date_end)), + 'period' => $period, + ]; +} + + /** * Get a parameter from a get request. * diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 3d8eb231b9..1f33023bf9 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -6280,6 +6280,20 @@ function html_print_input($data, $wrapper='div', $input_only=false) ); break; + case 'date_range': + $output .= html_print_select_date_range( + $data['name'], + true, + (isset($data['selected']) === true) ? $data['selected'] : SECONDS_1DAY, + (isset($data['date_init']) === true) ? $data['date_init'] : '', + (isset($data['time_init']) === true) ? $data['time_init'] : '', + (isset($data['date_end']) === true) ? $data['date_end'] : '', + (isset($data['time_end']) === true) ? $data['time_end'] : '', + (isset($data['date_text']) === true) ? $data['date_text'] : SECONDS_1DAY, + (isset($data['class']) === true) ? $data['class'] : 'w100p', + ); + break; + default: // Ignore. break; diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php index 40b6d2d1a0..10ab96986c 100644 --- a/pandora_console/include/lib/Dashboard/Manager.php +++ b/pandora_console/include/lib/Dashboard/Manager.php @@ -458,6 +458,12 @@ class Manager implements PublicLogin $this->publicLink ); + if ((bool) $this->dashboardFields['date_range'] === true) { + $dateFrom = $this->dashboardFields['date_from']; + $dateTo = $this->dashboardFields['date_to']; + $instance->setDateRange($dateFrom, $dateTo); + } + return $instance; } @@ -1015,6 +1021,8 @@ class Manager implements PublicLogin $id_group = \get_parameter('id_group'); $slideshow = \get_parameter_switch('slideshow'); $favourite = \get_parameter_switch('favourite'); + $dateRange = \get_parameter_switch('date_range'); + $dateData = \get_parameter_date('range', '', 'U'); $id_user = (empty($private) === false) ? $config['id_user'] : ''; @@ -1024,6 +1032,9 @@ class Manager implements PublicLogin 'id_group' => $id_group, 'cells_slideshow' => $slideshow, 'active' => $favourite, + 'date_range' => $dateRange, + 'date_from' => $dateData['date_init'], + 'date_to' => $dateData['date_end'], ]; if ($this->dashboardId === 0) { diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index b9364fcd31..acd9f4c94f 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -51,6 +51,20 @@ class Widget */ private $showSelectNodeMeta; + /** + * Date from init for filter widget. + * + * @var integer + */ + private $dateFrom; + + /** + * Date from end for filter widget. + * + * @var integer + */ + private $dateTo; + /** * Contructor widget. @@ -804,4 +818,41 @@ class Widget } + /** + * Set the date range of parent configuration. + * + * @param integer $dateFrom Date from init for filter widget. + * @param integer $dateTo Date from end for filter widget. + * + * @return void + */ + public function setDateRange(int $dateFrom, int $dateTo) + { + $this->dateFrom = $dateFrom; + $this->dateTo = $dateTo; + } + + + public function getDateFrom() + { + return $this->dateFrom; + } + + + public function getDateTo() + { + return $this->dateTo; + } + + + public function getPeriod():mixed + { + if (empty($this->dateFrom) === false && empty($this->dateTo) === false) { + return ($this->dateTo - $this->dateFrom); + } else { + return null; + } + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php b/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php index a3ff215c76..1484823518 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php +++ b/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php @@ -520,6 +520,9 @@ class BlockHistogram extends Widget global $config; $size = parent::getSize(); + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } // Desactive scroll bars only this item. $id_agent = $data['agent_id']; diff --git a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php index 72ad55309b..013faf1e67 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php @@ -399,6 +399,10 @@ class SingleGraphWidget extends Widget $module_name = \modules_get_agentmodule_name($this->values['moduleId']); $units_name = \modules_get_unit($this->values['moduleId']); + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + $trickHight = 0; if ($this->values['showLegend'] === 1) { // Needed for legend. diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index b50a5ba149..a92eb3b2c5 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -2665,6 +2665,9 @@ CREATE TABLE IF NOT EXISTS `tdashboard` ( `active` TINYINT NOT NULL DEFAULT 0, `cells` INT UNSIGNED DEFAULT 0, `cells_slideshow` TINYINT NOT NULL DEFAULT 0, + `date_range` TINYINT NOT NULL DEFAULT 0, + `date_from` INT NOT NULL DEFAULT 0, + `date_to` INT NOT NULL DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; diff --git a/pandora_console/views/dashboard/formDashboard.php b/pandora_console/views/dashboard/formDashboard.php index c36df6cf06..fafacd583d 100644 --- a/pandora_console/views/dashboard/formDashboard.php +++ b/pandora_console/views/dashboard/formDashboard.php @@ -102,6 +102,31 @@ $inputs = [ ], ], ], + [ + 'label' => __('Date range'), + 'arguments' => [ + 'name' => 'date_range', + 'id' => 'date_range', + 'type' => 'switch', + 'value' => $arrayDashboard['date_range'], + 'onchange' => 'handle_date_range(this)', + ], + ], + [ + 'label' => __('Select range'), + 'style' => 'display: none;', + 'class' => 'row_date_range', + 'arguments' => [ + 'name' => 'range', + 'id' => 'range', + 'selected' => ($arrayDashboard['date_to'] - $arrayDashboard['date_from']), + 'type' => 'date_range', + 'date_init' => $arrayDashboard['date_from'], + 'time_init' => $arrayDashboard['date_from'], + 'date_end' => $arrayDashboard['date_to'], + 'time_end' => $arrayDashboard['date_to'], + ], + ], [ 'block_id' => 'private', 'direct' => 1, @@ -135,3 +160,17 @@ HTML::printForm( 'inputs' => $inputs, ] ); + +?> + + \ No newline at end of file From 79fe89c3c54059094f1b5c1d069f09ca4cdd9648 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 22 Sep 2023 12:24:15 +0200 Subject: [PATCH 02/14] #11705 new custom_field tevento --- pandora_console/extras/mr/67.sql | 6 ++ .../godmode/events/custom_events.php | 1 + pandora_console/include/ajax/events.php | 48 ++++++++++++ pandora_console/include/functions_api.php | 42 +++++++++++ pandora_console/include/functions_events.php | 74 +++++++++++++++++++ .../include/javascript/pandora_events.js | 31 ++++++++ .../lib/Dashboard/Widgets/events_list.php | 1 + pandora_console/operation/events/events.php | 1 + pandora_console/pandoradb.sql | 1 + 9 files changed, 205 insertions(+) create mode 100644 pandora_console/extras/mr/67.sql diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql new file mode 100644 index 0000000000..92db1c919c --- /dev/null +++ b/pandora_console/extras/mr/67.sql @@ -0,0 +1,6 @@ +START TRANSACTION; + +ALTER TABLE `tevento` +ADD COLUMN `custom_field` TEXT NULL AFTER `module_status`; + +COMMIT; diff --git a/pandora_console/godmode/events/custom_events.php b/pandora_console/godmode/events/custom_events.php index c91a2df8fe..bfa6dce937 100644 --- a/pandora_console/godmode/events/custom_events.php +++ b/pandora_console/godmode/events/custom_events.php @@ -115,6 +115,7 @@ $fields_available['module_status'] = __('Module Status'); $fields_available['mini_severity'] = __('Severity mini'); $fields_available['module_custom_id'] = __('Module custom ID'); $fields_available['custom_data'] = __('Custom data'); +$fields_available['custom_field'] = __('Custom field'); // Remove fields already selected. diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index f9bf50b7ae..517777aacc 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -92,6 +92,7 @@ $get_id_source_event = get_parameter('get_id_source_event'); $node_id = (int) get_parameter('node_id', 0); $settings_modal = get_parameter('settings', 0); $parameters_modal = get_parameter('parameters', 0); +$update_custom_field = get_parameter('update_custom_field', 0); // User private filter. $current_filter = get_parameter('current_filter', 0); $private_filter_event = get_parameter('private_filter_event', 0); @@ -2759,3 +2760,50 @@ if ($draw_row_response_info === true) { echo $output; return; } + +if ($update_custom_field) { + $custom_field = get_parameter('custom_field_value'); + $event_id = get_parameter('event_id'); + $server_id = 0; + if (is_metaconsole() === true) { + $server_id = (int) get_parameter('server_id'); + } + + // Safe custom fields for hacks. + if (preg_match('/script/i', io_safe_output($custom_field))) { + $return = false; + } else { + try { + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node = new Node($server_id); + $node->connect(); + } + + $return = events_custom_field( + $event_id, + $custom_field + ); + } catch (\Exception $e) { + // Unexistent agent. + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node->disconnect(); + } + + $return = false; + } finally { + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node->disconnect(); + } + } + } + + echo ($return === true) ? 'update_ok' : 'update_error'; + + return; +} \ No newline at end of file diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 7e22befbee..dc6bdeb30f 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -17783,3 +17783,45 @@ function api_token_check(string $token) return db_get_value('id_user', 'tusuario', 'api_token', $token); } } + + +/** + * Set custom field value in tevento + * + * @param mixed $id_event Event id. + * @param mixed $custom_field Custom field to set. + * @return void + */ +function api_set_event_custom_field($id, $value) +{ + // Get the event + $event = events_get_event($id, false, is_metaconsole()); + // If event not exists, end the execution. + if ($event === false) { + returnError( + 'event_not_exists', + 'Event not exists' + ); + $result = false; + } + + // Safe custom fields for hacks. + if (preg_match('/script/i', io_safe_output($value))) { + $result = false; + } + + $result = events_custom_field( + $id, + $value + ); + + // If update results failed + if (empty($result) === true || $result === false) { + returnError( + 'The event could not be updated' + ); + return false; + } else { + returnData('string', ['data' => 'Event updated.']); + } +} diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 7068d554e6..c40a1eb9c7 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -219,6 +219,7 @@ function events_get_all_fields() $columns['module_status'] = __('Module status'); $columns['module_custom_id'] = __('Module custom id'); $columns['custom_data'] = __('Custom data'); + $columns['custom_field'] = __('Custom field'); return $columns; } @@ -322,6 +323,9 @@ function events_get_column_name($field, $table_alias=false) case 'custom_data': return __('Custom data'); + case 'custom_field': + return __('Custom field'); + default: return __($field); } @@ -4632,6 +4636,22 @@ function events_page_details($event, $server_id=0) $table_details->data[] = $data; + $data = []; + $data[0] = __('Custom Field'); + $data[1] = '
'.html_print_input_text('custom_field', $event['custom_field'], '', false, 255, true, false, false, '', 'w60p'); + $data[1] .= html_print_button( + __('Update'), + 'update_custom_field', + false, + 'update_custom_field('.$event['id_evento'].', '.$event['server_id'].');', + [ + 'icon' => 'next', + 'mode' => 'link', + ], + true + ).'
'; + $table_details->data[] = $data; + $details = '
'.html_print_table($table_details, true).'
'; if (is_metaconsole() === true && empty($server_id) === false) { @@ -6203,3 +6223,57 @@ function event_get_counter_extraId(array $event, ?array $filters) return $counters; } + + +/** + * Update event detail custom field + * + * @param mixed $id_event Event ID or array of events. + * @param string $custom_field Custom_field to be update. + * + * @return boolean Whether or not it was successful + */ +function events_custom_field( + $id_event, + $custom_field, +) { + global $config; + // Cleans up the selection for all unwanted values also casts any single + // values as an array. + $id_event = (array) safe_int($id_event, 1); + // Check ACL. + foreach ($id_event as $k => $id) { + $event_group = events_get_group($id); + if (check_acl($config['id_user'], $event_group, 'EW') == 0) { + db_pandora_audit( + AUDIT_LOG_ACL_VIOLATION, + 'Attempted updating event #'.$id + ); + + unset($id_event[$k]); + } + } + + if (empty($id_event) === true) { + return false; + } + + // Get the current event comments. + $first_event = $id_event; + if (is_array($id_event) === true) { + $first_event = reset($id_event); + } + + // Update comment. + $ret = db_process_sql_update( + 'tevento', + ['custom_field' => $custom_field], + ['id_evento' => $first_event] + ); + + if (($ret === false) || ($ret === 0)) { + return false; + } + + return true; +} diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 940fd3ce5d..ce782769cb 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -492,6 +492,37 @@ function event_comment(current_event) { return false; } +// Save custom_field into an event. +function update_custom_field(event_id, server_id) { + var custom_field_value = $("#text-custom_field").val(); + + var params = { + page: "include/ajax/events", + update_custom_field: 1, + custom_field_value: custom_field_value, + event_id: event_id, + server_id: server_id + }; + + $("#button-update_custom_field").attr("disabled", "disabled"); + $("#response_loading").show(); + + jQuery.ajax({ + data: params, + type: "POST", + url: getUrlAjax(), + dataType: "html", + success: function(data) { + if (data === "update_error") { + alert("Custom field not valid"); + } + $("#button-update_custom_field").removeAttr("disabled"); + $("#response_loading").hide(); + $("#button-events_form_search_bt").trigger("click"); + } + }); +} + var processed = 0; function update_event(table, id_evento, type, event_rep, row, server_id) { var inputs = $("#events_form :input"); diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index b7ad581dc0..b84f11aa4a 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -837,6 +837,7 @@ class EventsListWidget extends Widget 'mini_severity' => __('Severity mini'), 'module_custom_id' => __('Module custom ID'), 'custom_data' => __('Custom data'), + 'custom_field' => __('Custom field'), ]; } diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 059c8f90ec..bde20209a4 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -377,6 +377,7 @@ if (is_ajax() === true) { 'te.owner_user', 'if(te.ack_utimestamp > 0, te.ack_utimestamp,"") as ack_utimestamp', 'te.custom_data', + 'te.custom_field', 'te.data', 'te.module_status', 'ta.alias as agent_name', diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 662beb93af..030ef3a76f 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -723,6 +723,7 @@ CREATE TABLE IF NOT EXISTS `tevento` ( `custom_data` TEXT, `data` TINYTEXT, `module_status` INT NOT NULL DEFAULT 0, + `custom_field` TEXT, PRIMARY KEY (`id_evento`), KEY `idx_agente` (`id_agente`), KEY `idx_agentmodule` (`id_agentmodule`), From e5c5f91576801803f0c743e3f3233b71b8708375 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 25 Sep 2023 10:32:23 +0200 Subject: [PATCH 03/14] #11705 change name event_custom_id --- pandora_console/extras/mr/67.sql | 2 +- .../godmode/events/custom_events.php | 2 +- pandora_console/include/ajax/events.php | 12 +++++----- pandora_console/include/functions_api.php | 4 ++-- pandora_console/include/functions_events.php | 24 +++++++++---------- .../include/javascript/pandora_events.js | 10 ++++---- .../lib/Dashboard/Widgets/events_list.php | 2 +- pandora_console/operation/events/events.php | 2 +- pandora_console/pandoradb.sql | 2 +- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index 92db1c919c..7e598f9bd9 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -1,6 +1,6 @@ START TRANSACTION; ALTER TABLE `tevento` -ADD COLUMN `custom_field` TEXT NULL AFTER `module_status`; +ADD COLUMN `event_custom_id` TEXT NULL AFTER `module_status`; COMMIT; diff --git a/pandora_console/godmode/events/custom_events.php b/pandora_console/godmode/events/custom_events.php index bfa6dce937..4ab84fa76b 100644 --- a/pandora_console/godmode/events/custom_events.php +++ b/pandora_console/godmode/events/custom_events.php @@ -115,7 +115,7 @@ $fields_available['module_status'] = __('Module Status'); $fields_available['mini_severity'] = __('Severity mini'); $fields_available['module_custom_id'] = __('Module custom ID'); $fields_available['custom_data'] = __('Custom data'); -$fields_available['custom_field'] = __('Custom field'); +$fields_available['event_custom_id'] = __('Event Custom ID'); // Remove fields already selected. diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 517777aacc..0a1d32825f 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -92,7 +92,7 @@ $get_id_source_event = get_parameter('get_id_source_event'); $node_id = (int) get_parameter('node_id', 0); $settings_modal = get_parameter('settings', 0); $parameters_modal = get_parameter('parameters', 0); -$update_custom_field = get_parameter('update_custom_field', 0); +$update_event_custom_id = get_parameter('update_event_custom_id', 0); // User private filter. $current_filter = get_parameter('current_filter', 0); $private_filter_event = get_parameter('private_filter_event', 0); @@ -2761,8 +2761,8 @@ if ($draw_row_response_info === true) { return; } -if ($update_custom_field) { - $custom_field = get_parameter('custom_field_value'); +if ($update_event_custom_id) { + $event_custom_id = get_parameter('event_custom_id'); $event_id = get_parameter('event_id'); $server_id = 0; if (is_metaconsole() === true) { @@ -2770,7 +2770,7 @@ if ($update_custom_field) { } // Safe custom fields for hacks. - if (preg_match('/script/i', io_safe_output($custom_field))) { + if (preg_match('/script/i', io_safe_output($event_custom_id))) { $return = false; } else { try { @@ -2781,9 +2781,9 @@ if ($update_custom_field) { $node->connect(); } - $return = events_custom_field( + $return = events_event_custom_id( $event_id, - $custom_field + $event_custom_id ); } catch (\Exception $e) { // Unexistent agent. diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index dc6bdeb30f..6271864b5d 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -17792,7 +17792,7 @@ function api_token_check(string $token) * @param mixed $custom_field Custom field to set. * @return void */ -function api_set_event_custom_field($id, $value) +function api_set_event_custom_id($id, $value) { // Get the event $event = events_get_event($id, false, is_metaconsole()); @@ -17810,7 +17810,7 @@ function api_set_event_custom_field($id, $value) $result = false; } - $result = events_custom_field( + $result = events_event_custom_id( $id, $value ); diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index c40a1eb9c7..95f81b90bd 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -219,7 +219,7 @@ function events_get_all_fields() $columns['module_status'] = __('Module status'); $columns['module_custom_id'] = __('Module custom id'); $columns['custom_data'] = __('Custom data'); - $columns['custom_field'] = __('Custom field'); + $columns['event_custom_id'] = __('Event Custom ID'); return $columns; } @@ -323,8 +323,8 @@ function events_get_column_name($field, $table_alias=false) case 'custom_data': return __('Custom data'); - case 'custom_field': - return __('Custom field'); + case 'event_custom_id': + return __('Event Custom ID'); default: return __($field); @@ -4637,13 +4637,13 @@ function events_page_details($event, $server_id=0) $table_details->data[] = $data; $data = []; - $data[0] = __('Custom Field'); - $data[1] = '
'.html_print_input_text('custom_field', $event['custom_field'], '', false, 255, true, false, false, '', 'w60p'); + $data[0] = __('Event Custom ID'); + $data[1] = '
'.html_print_input_text('event_custom_id', $event['event_custom_id'], '', false, 255, true, false, false, '', 'w60p'); $data[1] .= html_print_button( __('Update'), - 'update_custom_field', + 'update_event_custom_id', false, - 'update_custom_field('.$event['id_evento'].', '.$event['server_id'].');', + 'update_event_custom_id('.$event['id_evento'].', '.$event['server_id'].');', [ 'icon' => 'next', 'mode' => 'link', @@ -6228,14 +6228,14 @@ function event_get_counter_extraId(array $event, ?array $filters) /** * Update event detail custom field * - * @param mixed $id_event Event ID or array of events. - * @param string $custom_field Custom_field to be update. + * @param mixed $id_event Event ID or array of events. + * @param string $event_custom_id Event custom ID to be update. * * @return boolean Whether or not it was successful */ -function events_custom_field( +function events_event_custom_id( $id_event, - $custom_field, + $event_custom_id, ) { global $config; // Cleans up the selection for all unwanted values also casts any single @@ -6267,7 +6267,7 @@ function events_custom_field( // Update comment. $ret = db_process_sql_update( 'tevento', - ['custom_field' => $custom_field], + ['event_custom_id' => $event_custom_id], ['id_evento' => $first_event] ); diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index ce782769cb..96f01c2c0d 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -493,13 +493,13 @@ function event_comment(current_event) { } // Save custom_field into an event. -function update_custom_field(event_id, server_id) { - var custom_field_value = $("#text-custom_field").val(); +function update_event_custom_id(event_id, server_id) { + var event_custom_id = $("#text-event_custom_id").val(); var params = { page: "include/ajax/events", - update_custom_field: 1, - custom_field_value: custom_field_value, + update_event_custom_id: 1, + event_custom_id: event_custom_id, event_id: event_id, server_id: server_id }; @@ -514,7 +514,7 @@ function update_custom_field(event_id, server_id) { dataType: "html", success: function(data) { if (data === "update_error") { - alert("Custom field not valid"); + alert("Event Custom ID not valid"); } $("#button-update_custom_field").removeAttr("disabled"); $("#response_loading").hide(); diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index b84f11aa4a..47250e83ac 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -837,7 +837,7 @@ class EventsListWidget extends Widget 'mini_severity' => __('Severity mini'), 'module_custom_id' => __('Module custom ID'), 'custom_data' => __('Custom data'), - 'custom_field' => __('Custom field'), + 'event_custom_id' => __('Event Custom ID'), ]; } diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index bde20209a4..28d9d9eae3 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -377,7 +377,7 @@ if (is_ajax() === true) { 'te.owner_user', 'if(te.ack_utimestamp > 0, te.ack_utimestamp,"") as ack_utimestamp', 'te.custom_data', - 'te.custom_field', + 'te.event_custom_id', 'te.data', 'te.module_status', 'ta.alias as agent_name', diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 030ef3a76f..36fbc4716b 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -723,7 +723,7 @@ CREATE TABLE IF NOT EXISTS `tevento` ( `custom_data` TEXT, `data` TINYTEXT, `module_status` INT NOT NULL DEFAULT 0, - `custom_field` TEXT, + `event_custom_id` TEXT, PRIMARY KEY (`id_evento`), KEY `idx_agente` (`id_agente`), KEY `idx_agentmodule` (`id_agentmodule`), From 70e3707b64805144d4288a4695b53faac9942220 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 25 Sep 2023 12:22:10 +0200 Subject: [PATCH 04/14] #11705 group extra id heredity event custom id --- pandora_console/godmode/setup/setup_general.php | 2 +- pandora_console/include/functions_api.php | 6 ++++-- pandora_console/include/functions_events.php | 4 +++- pandora_server/lib/PandoraFMS/Core.pm | 6 ++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index aa55893d11..3f4c24fbbf 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -733,7 +733,7 @@ $table->data[$i++][] = html_print_label_input_block( ); $help_tip = ui_print_help_tip( - __('If there are any "In process" events with a specific Extra ID and a New event with that Extra ID is received, it will be created as "In process" instead.'), + __('If there are any "In process" events with a specific Extra ID and a New event with that Extra ID is received, it will be created as "In process" instead. The new events also inherit Event Custom ID'), true ); diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 6271864b5d..ee17d7df6d 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -13130,7 +13130,7 @@ function api_set_create_event($id, $trash1, $other, $returnType) if ($other['data'][18] != '') { $values['id_extra'] = $other['data'][18]; - $sql_validation = 'SELECT id_evento,estado,ack_utimestamp,id_usuario + $sql_validation = 'SELECT id_evento,estado,ack_utimestamp,id_usuario,event_custom_id FROM tevento WHERE estado IN (0,2) AND id_extra ="'.$other['data'][18].'";'; @@ -13145,6 +13145,7 @@ function api_set_create_event($id, $trash1, $other, $returnType) $values['status'] = 2; $ack_utimestamp = $val['ack_utimestamp']; $values['id_usuario'] = $val['id_usuario']; + $values['event_custom_id'] = $val['event_custom_id']; } api_set_validate_event_by_id($val['id_evento']); @@ -13175,7 +13176,8 @@ function api_set_create_event($id, $trash1, $other, $returnType) $custom_data, $values['server_id'], $values['id_extra'], - $ack_utimestamp + $ack_utimestamp, + $values['event_custom_id'] ?? null ); if ($other['data'][12] != '') { diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 95f81b90bd..4f016f4f82 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -2339,7 +2339,8 @@ function events_create_event( $custom_data='', $server_id=0, $id_extra='', - $ack_utimestamp=0 + $ack_utimestamp=0, + $event_custom_id=null ) { if ($source === false) { $source = get_product_name(); @@ -2371,6 +2372,7 @@ function events_create_event( 'custom_data' => $custom_data, 'data' => '', 'module_status' => 0, + 'event_custom_id' => $event_custom_id, ]; return (int) db_process_sql_insert('tevento', $values); diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index e7ac485a1d..b2faac90df 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -4160,6 +4160,7 @@ sub pandora_event { my $utimestamp = time (); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); + my $event_custom_id = undef; $id_agentmodule = 0 unless defined ($id_agentmodule); # Validate events with the same event id @@ -4177,6 +4178,7 @@ sub pandora_event { logger($pa_config, "Keeping In process status from last event with extended id '$id_extra'.", 10); $ack_utimestamp = get_db_value ($dbh, 'SELECT ack_utimestamp FROM tevento WHERE id_extra=? AND estado=2', $id_extra); $event_status = 2; + $event_custom_id = get_db_value ($dbh, 'SELECT event_custom_id FROM tevento WHERE id_extra=? AND estado=2', $id_extra); } } @@ -4188,8 +4190,8 @@ sub pandora_event { # Create the event logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10); - $event_id = db_insert ($dbh, 'id_evento','INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, safe_input($module_data), $module_status); + $event_id = db_insert ($dbh, 'id_evento','INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status, event_custom_id) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, safe_input($module_data), $module_status, $event_custom_id); if(defined($event_id) && $comment ne '') { my $comment_id = db_insert ($dbh, 'id','INSERT INTO tevent_comment (id_event, utimestamp, comment, id_user, action) From 538cb4f04dc7b259b8f9f0e321e2d8a55b5c2266 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 25 Sep 2023 13:12:07 +0200 Subject: [PATCH 05/14] #11705 cli function update_event_custom_id --- pandora_server/util/pandora_manage.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index c63d923402..c35a426e12 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -201,6 +201,7 @@ sub help_screen{ help_screen_line('--disable_double_auth', '', 'Disable the double authentication for the specified user'); print "\nEVENTS:\n\n" unless $param ne ''; help_screen_line('--create_event', " [ \n\t \n\t \n\t ]", 'Add event'); + help_screen_line('--update_event_custom_id', " ", 'Update Event Custom ID'); help_screen_line('--validate_event', " \n\t []", 'Validate events'); help_screen_line('--validate_event_id', '', 'Validate event given a event id'); help_screen_line('--get_event_info', '[]', 'Show info about a event given a event id'); @@ -4549,6 +4550,17 @@ sub cli_create_event() { } } +############################################################################## +# Update event custom id +# Related option: --update_event_custom_id +############################################################################## + +sub cli_update_event_custom_id() { + my ($id_event, $event_custom_id) = @ARGV[2..3]; + my $result = api_call(\%conf, 'set', 'event_custom_id', $id_event, $event_custom_id); + print "\n$result\n"; +} + ############################################################################## # Validate event. # Related option: --validate_event @@ -8318,6 +8330,10 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 4, 0); cli_insert_gis_data(); } + elsif ($param eq '--update_event_custom_id'){ + param_check($ltotal, 2); + cli_update_event_custom_id(); + } else { print_log "[ERROR] Invalid option '$param'.\n\n"; $param = ''; From 2a2a1b6e3ebe88b5f9c5ae5528bac600c1536f16 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 3 Oct 2023 10:46:31 +0200 Subject: [PATCH 06/14] #10316 hover ip custom field get value --- pandora_console/godmode/agentes/module_manager.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 5c21fa71a0..3e76a1baef 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -949,7 +949,14 @@ if ($modules !== false) { ); if (strlen($module['ip_target']) !== 0) { - $title .= '
IP: '.$module['ip_target']; + // Check if value is custom field. + if ($module['ip_target'][0] == '_' && $module['ip_target'][(strlen($module['ip_target']) - 1)] == '_') { + $custom_field_name = substr($module['ip_target'], 1, -1); + $custom_value = agents_get_agent_custom_field($id_agente, $custom_field_name); + $title .= '
IP: '.$custom_value; + } else { + $title .= '
IP: '.$module['ip_target']; + } } // This module is initialized ? (has real data). From dbf315e4079fd9359b7b8f87560ad1a36c46c5fb Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Mon, 23 Oct 2023 14:48:34 +0200 Subject: [PATCH 07/14] #10983 revised widgets with intervals --- .../lib/Dashboard/Widgets/BasicChart.php | 4 ++++ .../lib/Dashboard/Widgets/DataMatrix.php | 4 ++++ .../lib/Dashboard/Widgets/custom_graph.php | 4 ++++ .../Widgets/graph_module_histogram.php | 4 ++++ .../include/lib/Dashboard/Widgets/netflow.php | 6 +++++ .../Dashboard/Widgets/security_hardening.php | 6 +++++ .../lib/Dashboard/Widgets/single_graph.php | 4 ++++ .../include/lib/Dashboard/Widgets/top_n.php | 4 ++++ .../views/dashboard/formDashboard.php | 23 +++++++++++++++---- 9 files changed, 54 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php b/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php index c3b9ddf9ad..a140d7fcb4 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php +++ b/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php @@ -637,6 +637,10 @@ class BasicChart extends Widget $color_status = $this->values['colorValue']; } + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + $params = [ 'agent_module_id' => $this->values['moduleId'], 'period' => $this->values['period'], diff --git a/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php b/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php index be38c31bb4..770a3152fe 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php +++ b/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php @@ -473,6 +473,10 @@ class DataMatrix extends Widget return $output; } + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + if (is_metaconsole() === true) { $modules_nodes = array_reduce( $this->values['moduleDataMatrix'], diff --git a/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php b/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php index 377ca145a0..4cb4734105 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php @@ -472,6 +472,10 @@ class CustomGraphWidget extends Widget $size = parent::getSize(); + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + switch ($this->values['type']) { case CUSTOM_GRAPH_STACKED_LINE: case CUSTOM_GRAPH_STACKED_AREA: diff --git a/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php b/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php index b0382ba273..38967c2e47 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php +++ b/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php @@ -302,6 +302,10 @@ class GraphModuleHistogramWidget extends Widget $values['period'] = SECONDS_1DAY; } + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + if (isset($values['sizeLabel']) === false) { $values['sizeLabel'] = 30; } diff --git a/pandora_console/include/lib/Dashboard/Widgets/netflow.php b/pandora_console/include/lib/Dashboard/Widgets/netflow.php index 13a15bf6a0..6c0aa76eca 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/netflow.php +++ b/pandora_console/include/lib/Dashboard/Widgets/netflow.php @@ -309,6 +309,12 @@ class Netflow extends Widget $start_date = (time() - $this->values['period']); $end_date = time(); + + if (empty(parent::getPeriod()) === false) { + $start_date = parent::getDateFrom(); + $end_date = parent::getDateTo(); + } + if ($this->values['chart_type'] === 'usage_map') { $map_data = netflow_build_map_data( $start_date, diff --git a/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php b/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php index 2c936728ed..14afbcfb20 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php +++ b/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php @@ -134,6 +134,7 @@ class SecurityHardening extends Widget // Includes. include_once ENTERPRISE_DIR.'/include/functions_security_hardening.php'; + include_once $config['homedir'].'/include/graphs/fgraph.php'; // WARNING: Do not edit. This chunk must be in the constructor. parent::__construct( $cellId, @@ -325,6 +326,11 @@ class SecurityHardening extends Widget $id_groups = $this->checkAcl($values['group']); $output .= ''.$this->elements[$data_type].''; + if (empty(parent::getPeriod()) === false) { + $values['date_init'] = parent::getDateFrom(); + $values['date_end'] = parent::getDateTo(); + } + switch ($data_type) { case 'top_n_agents_sh': $output .= $this->loadTopNAgentsSh($id_groups, $values['limit']); diff --git a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php index 236b19c554..280bf3226f 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php @@ -300,6 +300,10 @@ class SingleGraphWidget extends Widget $values['period'] = SECONDS_1DAY; } + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + if (isset($values['showLegend']) === false) { $values['showLegend'] = 1; } diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n.php b/pandora_console/include/lib/Dashboard/Widgets/top_n.php index 5a603501c0..f732f8b264 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/top_n.php +++ b/pandora_console/include/lib/Dashboard/Widgets/top_n.php @@ -374,6 +374,10 @@ class TopNWidget extends Widget $size = parent::getSize(); + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + $quantity = $this->values['quantity']; $period = $this->values['period']; diff --git a/pandora_console/views/dashboard/formDashboard.php b/pandora_console/views/dashboard/formDashboard.php index fafacd583d..be21a3142e 100644 --- a/pandora_console/views/dashboard/formDashboard.php +++ b/pandora_console/views/dashboard/formDashboard.php @@ -119,12 +119,12 @@ $inputs = [ 'arguments' => [ 'name' => 'range', 'id' => 'range', - 'selected' => ($arrayDashboard['date_to'] - $arrayDashboard['date_from']), + 'selected' => ($arrayDashboard['date_from'] === '0' && $arrayDashboard['date_to'] === '0') ? 300 : 'chose_range', 'type' => 'date_range', - 'date_init' => $arrayDashboard['date_from'], - 'time_init' => $arrayDashboard['date_from'], - 'date_end' => $arrayDashboard['date_to'], - 'time_end' => $arrayDashboard['date_to'], + 'date_init' => date('Y/m/d', $arrayDashboard['date_from']), + 'time_init' => date('H:i:s', $arrayDashboard['date_from']), + 'date_end' => date('Y/m/d', $arrayDashboard['date_to']), + 'time_end' => date('H:i:s', $arrayDashboard['date_to']), ], ], [ @@ -167,6 +167,19 @@ HTML::printForm( function handle_date_range(element){ if(element.checked) { $(".row_date_range").show(); + var def_state_range = $('#range_range').is(':visible'); + var def_state_default = $('#range_default').is(':visible'); + var def_state_extend = $('#range_extend').is(':visible'); + if ( + def_state_range === false + && def_state_default === false + && def_state_extend === false + && $('#range').val() !== 'chose_range' + ) { + $('#range_default').show(); + } else if ($('#range').val() === 'chose_range') { + $('#range_range').show(); + } } else { $(".row_date_range").hide(); } From a23bc00d171ce805393c078a8cf2008d555cb682 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Mon, 23 Oct 2023 17:17:22 +0200 Subject: [PATCH 08/14] #10983 added control time in graphs --- .../include/lib/Dashboard/Widgets/single_graph.php | 4 ---- pandora_console/include/lib/Dashboard/Widgets/sla_percent.php | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php index 280bf3226f..236b19c554 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php @@ -300,10 +300,6 @@ class SingleGraphWidget extends Widget $values['period'] = SECONDS_1DAY; } - if (empty(parent::getPeriod()) === false) { - $this->values['period'] = parent::getPeriod(); - } - if (isset($values['showLegend']) === false) { $values['showLegend'] = 1; } diff --git a/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php b/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php index 4dfefbf292..f3c7fb826e 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php +++ b/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php @@ -459,6 +459,9 @@ class SLAPercentWidget extends Widget global $config; $size = parent::getSize(); + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } $output .= ''; $id_agent = $this->values['agentId']; From 84ee69b435846510fc38ba6e6fab4194ef43be3d Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 7 Nov 2023 15:56:23 +0100 Subject: [PATCH 09/14] #12095 remove user_comment --- pandora_console/extras/mr/67.sql | 6 ++++++ pandora_console/pandoradb.sql | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 pandora_console/extras/mr/67.sql diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql new file mode 100644 index 0000000000..235a5b3580 --- /dev/null +++ b/pandora_console/extras/mr/67.sql @@ -0,0 +1,6 @@ +START TRANSACTION; + +ALTER TABLE `tevent_rule` DROP COLUMN `user_comment`; +ALTER TABLE `tevent_rule` DROP COLUMN `operator_user_comment`; + +COMMIT; \ No newline at end of file diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 1d7374bc03..eb3810a4f1 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -3029,7 +3029,6 @@ CREATE TABLE IF NOT EXISTS `tevent_rule` ( `module` TEXT, `alert` TEXT, `criticity` TEXT, - `user_comment` TEXT, `id_tag` TEXT, `name` TEXT, `group_recursion` TEXT, @@ -3044,7 +3043,6 @@ CREATE TABLE IF NOT EXISTS `tevent_rule` ( `operator_module` TEXT COMMENT 'Operator for module', `operator_alert` TEXT COMMENT 'Operator for alert', `operator_criticity` TEXT COMMENT 'Operator for criticity', - `operator_user_comment` TEXT COMMENT 'Operator for user_comment', `operator_id_tag` TEXT COMMENT 'Operator for id_tag', `operator_log_content` TEXT COMMENT 'Operator for log_content', `operator_log_source` TEXT COMMENT 'Operator for log_source', From b45c967919d862b1f02161e55a915628f4c3299b Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 15 Nov 2023 08:30:24 +0100 Subject: [PATCH 10/14] add code lost inventory server pandora_enterprise#12188 --- .../lib/PandoraFMS/InventoryServer.pm | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/InventoryServer.pm b/pandora_server/lib/PandoraFMS/InventoryServer.pm index 5f0f90e95d..515d875788 100644 --- a/pandora_server/lib/PandoraFMS/InventoryServer.pm +++ b/pandora_server/lib/PandoraFMS/InventoryServer.pm @@ -183,15 +183,22 @@ sub data_consumer ($$) { # No code to run return if ($module->{'interpreter'} eq ''); - - # Save script in a temporary file + + my $command; my ($fh, $temp_file) = tempfile(); - $fh->print (decode_base64($module->{'code'})); - close ($fh); - set_file_permissions($pa_config, $temp_file, "0777"); - # Run the script - my $command = $module->{'interpreter'} . ' ' . $temp_file . ' "' . $module->{'target'} . '"'; + if ($module->{'script_mode'} == '1') { + my $script_file = $module->{'script_path'}; + $command = $module->{'interpreter'} . ' ' . $script_file; + } else { + # Save script in a temporary file + $fh->print (decode_base64($module->{'code'})); + close ($fh); + set_file_permissions($pa_config, $temp_file, "0777"); + + # Run the script + $command = $module->{'interpreter'} . ' ' . $temp_file . ' "' . $module->{'target'} . '"'; + } # Try to read the custom fields to use them as arguments into the command if (defined($module->{'custom_fields'}) && $module->{'custom_fields'} ne '') { @@ -206,7 +213,11 @@ sub data_consumer ($$) { if (!defined ($decoded_cfields)) { logger ($pa_config, "Remote inventory module ".$module->{'name'}." has failed because the custom fields can't be read", 6); - unlink ($temp_file); + + if ($module->{'script_mode'} == '2') { + unlink ($temp_file); + } + return; } @@ -237,11 +248,18 @@ sub data_consumer ($$) { # Check for errors if ($? != 0) { logger ($pa_config, "Remote inventory module ".$module->{'name'}." has failed with error level $?", 6); - unlink ($temp_file); + + if ($module->{'script_mode'} == '2') { + unlink ($temp_file); + } + return; } - unlink ($temp_file); + if ($module->{'script_mode'} == '2') { + unlink ($temp_file); + } + my $utimestamp = time (); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); eval { From 63b069d739e7aa85f4e36108624aec7a71964e91 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 22 Nov 2023 11:20:46 +0100 Subject: [PATCH 11/14] #11705 fix for id as array --- pandora_console/include/functions_events.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index c680460ec2..07953c1994 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -6245,7 +6245,10 @@ function events_event_custom_id( global $config; // Cleans up the selection for all unwanted values also casts any single // values as an array. - $id_event = (array) safe_int($id_event, 1); + if (![$id_event]) { + $id_event = (array) safe_int($id_event, 1); + } + // Check ACL. foreach ($id_event as $k => $id) { $event_group = events_get_group($id); From 11cc31c0adb7cf48362a031cdfa703b7aed7d751 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 23 Nov 2023 10:23:57 +0100 Subject: [PATCH 12/14] #11705 Event custom id edit by EW only --- pandora_console/include/functions_events.php | 32 ++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index a7bd74096e..dada577ac8 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -4636,21 +4636,29 @@ function events_page_details($event, $server_id=0) } $table_details->data[] = $data; + $readonly = true; + if (check_acl($config['id_user'], 0, 'EW')) { + $readonly = false; + } $data = []; $data[0] = __('Event Custom ID'); - $data[1] = '
'.html_print_input_text('event_custom_id', $event['event_custom_id'], '', false, 255, true, false, false, '', 'w60p'); - $data[1] .= html_print_button( - __('Update'), - 'update_event_custom_id', - false, - 'update_event_custom_id('.$event['id_evento'].', '.$event['server_id'].');', - [ - 'icon' => 'next', - 'mode' => 'link', - ], - true - ).'
'; + $data[1] = '
'.html_print_input_text('event_custom_id', $event['event_custom_id'], '', false, 255, true, $readonly, false, '', 'w60p'); + if ($readonly === false) { + $data[1] .= html_print_button( + __('Update'), + 'update_event_custom_id', + false, + 'update_event_custom_id('.$event['id_evento'].', '.$event['server_id'].');', + [ + 'icon' => 'next', + 'mode' => 'link', + ], + true + ); + } + + $data[1] .= '
'; $table_details->data[] = $data; $details = '
'.html_print_table($table_details, true).'
'; From fafe4bc9b470a61fddc7e0cc300f6e01812b5f06 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 23 Nov 2023 17:21:37 +0100 Subject: [PATCH 13/14] #10316 new function return_agent_macros --- .../godmode/agentes/module_manager.php | 12 +++- pandora_console/include/ajax/module.php | 19 +++++- pandora_console/include/functions_macros.php | 61 +++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 pandora_console/include/functions_macros.php diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 3e76a1baef..c3772c00d3 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -38,6 +38,7 @@ $isFunctionPolicies = enterprise_include_once('include/functions_policies.php'); require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_agents.php'; require_once $config['homedir'].'/include/functions_servers.php'; +require_once $config['homedir'].'/include/functions_macros.php'; $search_string = get_parameter('search_string'); @@ -953,7 +954,16 @@ if ($modules !== false) { if ($module['ip_target'][0] == '_' && $module['ip_target'][(strlen($module['ip_target']) - 1)] == '_') { $custom_field_name = substr($module['ip_target'], 1, -1); $custom_value = agents_get_agent_custom_field($id_agente, $custom_field_name); - $title .= '
IP: '.$custom_value; + if (isset($custom_value) && $custom_value !== false) { + $title .= '
IP: '.$custom_value; + } else { + $array_macros = return_agent_macros($id_agente); + if (isset($array_macros[$module['ip_target']])) { + $title .= '
IP: '.$array_macros[$module['ip_target']]; + } else { + $title .= '
IP: '.$module['ip_target']; + } + } } else { $title .= '
IP: '.$module['ip_target']; } diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 78daacb0a0..620e4a6588 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -35,6 +35,7 @@ if (check_login()) { include_once $config['homedir'].'/include/functions_agents.php'; include_once $config['homedir'].'/include/functions_modules.php'; include_once $config['homedir'].'/include/functions_ui.php'; + include_once $config['homedir'].'/include/functions_macros.php'; enterprise_include_once('include/functions_metaconsole.php'); $get_plugin_macros = get_parameter('get_plugin_macros'); @@ -1197,7 +1198,23 @@ if (check_login()) { ); if (strlen($module['ip_target']) !== 0) { - $title .= '
IP: '.$module['ip_target']; + // Check if value is custom field. + if ($module['ip_target'][0] == '_' && $module['ip_target'][(strlen($module['ip_target']) - 1)] == '_') { + $custom_field_name = substr($module['ip_target'], 1, -1); + $custom_value = agents_get_agent_custom_field($id_agente, $custom_field_name); + if (isset($custom_value) && $custom_value !== false) { + $title .= '
IP: '.$custom_value; + } else { + $array_macros = return_agent_macros($id_agente); + if (isset($array_macros[$module['ip_target']])) { + $title .= '
IP: '.$array_macros[$module['ip_target']]; + } else { + $title .= '
IP: '.$module['ip_target']; + } + } + } else { + $title .= '
IP: '.$module['ip_target']; + } } $last_status_change_text = __('Time elapsed since last status change: '); diff --git a/pandora_console/include/functions_macros.php b/pandora_console/include/functions_macros.php new file mode 100644 index 0000000000..bba0bd1898 --- /dev/null +++ b/pandora_console/include/functions_macros.php @@ -0,0 +1,61 @@ + ($agente['nombre']) ?: '', + '_agentalias_' => ($agente['alias']) ?: '', + '_agent_' => ($agente['alias']) ?: (($agente['nombre']) ?: ''), + '_agentcustomid_' => ($agente['custom_id']) ?: '', + '_agentdescription_' => ($agente['comentarios']) ?: '', + '_agentgroup_' => ($grupo['nombre']) ?: '', + '_agentos_' => ($agente['id_os']) ?: '', + '_address_' => ($agente['direccion']) ?: '', + '_homeurl_' => ($config['public_url']) ?: '', + '_groupcontact_' => ($agente['contact']) ?: '', + '_groupcustomid_' => ($agente['custom_id']) ?: '', + '_groupother_' => ($agente['other']) ?: '', + '_server_ip_' => ($server_ip) ?: '', + '_server_name_' => ($agente['server_name']) ?: '', + ]; + + return $array_macros; +} From d2b6b098a32bf48845b41f86e4bb2dfe775b05ab Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 29 Nov 2023 11:38:19 +0100 Subject: [PATCH 14/14] fix inventory pandora_enterprise#12188 --- pandora_server/lib/PandoraFMS/InventoryServer.pm | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/InventoryServer.pm b/pandora_server/lib/PandoraFMS/InventoryServer.pm index 515d875788..e6b070f4d8 100644 --- a/pandora_server/lib/PandoraFMS/InventoryServer.pm +++ b/pandora_server/lib/PandoraFMS/InventoryServer.pm @@ -181,15 +181,12 @@ sub data_consumer ($$) { AND tagent_module_inventory.id_module_inventory = tmodule_inventory.id_module_inventory', $module_id); - # No code to run - return if ($module->{'interpreter'} eq ''); - my $command; my ($fh, $temp_file) = tempfile(); if ($module->{'script_mode'} == '1') { my $script_file = $module->{'script_path'}; - $command = $module->{'interpreter'} . ' ' . $script_file; + $command = $module->{'interpreter'} . ' ' . $script_file . ' "' . $module->{'target'} . '"'; } else { # Save script in a temporary file $fh->print (decode_base64($module->{'code'}));