From dbf315e4079fd9359b7b8f87560ad1a36c46c5fb Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Mon, 23 Oct 2023 14:48:34 +0200 Subject: [PATCH] #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(); }