From 31f41240831a1554df37e2981a40642e569aaf99 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 11 Apr 2024 11:57:42 +0200 Subject: [PATCH] #13344 dashboard remove dashboardId on public link --- .../include/lib/Dashboard/Manager.php | 26 ++++++++++++++++--- pandora_console/views/dashboard/header.php | 24 ++++++++++++----- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php index 9c823ead01..36769c4338 100644 --- a/pandora_console/include/lib/Dashboard/Manager.php +++ b/pandora_console/include/lib/Dashboard/Manager.php @@ -994,6 +994,27 @@ class Manager implements PublicLogin ui_require_css_file('modal'); ui_require_css_file('form'); + $hash_aux = get_parameter('hash'); + if (empty($dashboardId)) { + $dashboards = $this->getDashboards(); + $dashboards = array_reduce( + $dashboards, + function ($carry, $item) { + $carry[$item['id']] = $item['name']; + return $carry; + }, + [] + ); + + foreach ($dashboards as $key => $layout) { + $hash_compare = self::generatePublicHash($key); + if (hash_equals($hash_aux, $hash_compare)) { + $this->dashboardId = $key; + break; + } + } + } + if ($this->dashboardId === 0 || $this->deleteDashboard === true || $this->copyDashboard === true @@ -1164,11 +1185,10 @@ class Manager implements PublicLogin [ 'dashboards' => $dashboards, 'ajaxController' => $this->ajaxController, - 'dashboardId' => $this->dashboardId, 'refr' => $this->refr, 'url' => $this->url, 'dashboardName' => $this->dashboardFields['name'], - 'hash' => self::generatePublicHash(), + 'hash' => self::generatePublicHash($this->dashboardId), 'publicLink' => $this->publicLink, 'dashboardGroup' => $this->dashboardFields['id_group'], 'dashboardUser' => $this->dashboardFields['id_user'], @@ -1210,7 +1230,7 @@ class Manager implements PublicLogin 'updateDashboard' => $this->updateDashboard, 'cellIdCreate' => \get_parameter('cellIdCreate', 0), 'class' => (($config['public_dashboard'] === true) ? quotemeta(__CLASS__) : ''), - 'hash' => (($config['public_dashboard'] === true) ? self::generatePublicHash() : ''), + 'hash' => (($config['public_dashboard'] === true) ? self::generatePublicHash($this->dashboardId) : ''), ] ); } else { diff --git a/pandora_console/views/dashboard/header.php b/pandora_console/views/dashboard/header.php index 6dce805533..cc1cb8d1fa 100644 --- a/pandora_console/views/dashboard/header.php +++ b/pandora_console/views/dashboard/header.php @@ -27,12 +27,23 @@ */ // Button for display full screen mode. +use PandoraFMS\Dashboard\Manager; global $config; +if (empty($dashboardId)) { + foreach ($dashboards as $key => $layout) { + $hash_compare = Manager::generatePublicHash($key); + if (hash_equals($hash, $hash_compare)) { + $dashboardId = $key; + break; + } + } +} + $queryFull = [ - 'dashboardId' => $dashboardId, - 'refr' => $refr, - 'pure' => 1, + 'refr' => $refr, + 'pure' => 1, + 'hash' => $hash, ]; $urlFull = $url.'&'.http_build_query($queryFull); $fullscreen['text'] = ''; @@ -124,10 +135,9 @@ $slides['text'] .= ''; // Public Url. $queryPublic = [ - 'dashboardId' => $dashboardId, - 'hash' => $hash, - 'id_user' => $config['id_user'], - 'pure' => 1, + 'hash' => $hash, + 'id_user' => $config['id_user'], + 'pure' => 1, ]; $publicUrl = ui_get_full_url( 'operation/dashboard/public_dashboard.php?'.http_build_query($queryPublic)