diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql
index 8b69233913..3e011368c4 100644
--- a/pandora_console/extras/mr/67.sql
+++ b/pandora_console/extras/mr/67.sql
@@ -23,5 +23,9 @@ INSERT IGNORE INTO `tdiscovery_apps_tasks_macros` (`id_task`, `macro`, `type`, `
INSERT IGNORE INTO `tdiscovery_apps_tasks_macros` (`id_task`, `macro`, `type`, `value`, `temp_conf`) SELECT id_rt, '_clientPath_', 'custom', '', 0 FROM `trecon_task` WHERE `id_app` = @id_app;
UPDATE `trecon_task` SET `setup_complete` = 1 WHERE `id_app` = @id_app;
+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 d03b8d7412..855083dac5 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/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php
index dfcdfe0238..4430bfa253 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;
}
@@ -1041,6 +1047,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'] : '';
@@ -1050,6 +1058,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 82fc7cbda5..ca48e6d61a 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.
@@ -824,4 +838,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/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/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/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 c77d343ea3..b3c124f039 100644
--- a/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php
+++ b/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php
@@ -135,8 +135,6 @@ class SecurityHardening extends Widget
// Includes.
include_once ENTERPRISE_DIR.'/include/functions_security_hardening.php';
include_once $config['homedir'].'/include/graphs/fgraph.php';
- include_once $config['homedir'].'/include/functions_graph.php';
-
// WARNING: Do not edit. This chunk must be in the constructor.
parent::__construct(
$cellId,
@@ -328,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 dbca9fa5f0..a718217a57 100644
--- a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php
+++ b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php
@@ -440,6 +440,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/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'];
diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n.php b/pandora_console/include/lib/Dashboard/Widgets/top_n.php
index 3ab2f922a3..5e885927db 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/pandoradb.sql b/pandora_console/pandoradb.sql
index 4c527345c0..2d8a258f42 100644
--- a/pandora_console/pandoradb.sql
+++ b/pandora_console/pandoradb.sql
@@ -2640,6 +2640,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..be21a3142e 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_from'] === '0' && $arrayDashboard['date_to'] === '0') ? 300 : 'chose_range',
+ 'type' => 'date_range',
+ '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']),
+ ],
+ ],
[
'block_id' => 'private',
'direct' => 1,
@@ -135,3 +160,30 @@ HTML::printForm(
'inputs' => $inputs,
]
);
+
+?>
+
+
\ No newline at end of file