Skip to content

Commit 6c7f1e5

Browse files
committed
Dashlet: Properly embed iframe urls
fixes #5346
1 parent 219b117 commit 6c7f1e5

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

library/Icinga/Web/Widget/Dashboard/Dashlet.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace Icinga\Web\Widget\Dashboard;
55

6+
use Icinga\Web\Session;
67
use Icinga\Web\Url;
78
use Icinga\Data\ConfigObject;
8-
use Icinga\Exception\IcingaException;
99

1010
/**
1111
* A dashboard pane dashlet
@@ -57,18 +57,15 @@ class Dashlet extends UserWidget
5757
*/
5858
private $template =<<<'EOD'
5959
60-
<div class="container" data-icinga-url="{URL}">
61-
<h1><a href="{FULL_URL}" aria-label="{TOOLTIP}" title="{TOOLTIP}" data-base-target="col1">{TITLE}</a></h1>
60+
<div class="container" data-icinga-url="{URL}" data-url-hash="{URL_HASH}">
61+
<h1><a
62+
href="{FULL_URL}"
63+
aria-label="{TOOLTIP}"
64+
title="{TOOLTIP}"
65+
data-url-hash="{FULL_URL_HASH}"
66+
data-base-target="col1"
67+
>{TITLE}</a></h1>
6268
<p class="progress-label">{PROGRESS_LABEL}<span>.</span><span>.</span><span>.</span></p>
63-
<noscript>
64-
<div class="iframe-container">
65-
<iframe
66-
src="{IFRAME_URL}"
67-
frameborder="no"
68-
title="{TITLE_PREFIX}{TITLE}">
69-
</iframe>
70-
</div>
71-
</noscript>
7269
</div>
7370
EOD;
7471

@@ -250,13 +247,22 @@ public function render()
250247

251248
$url = $this->getUrl();
252249
$url->setParam('showCompact', true);
253-
$iframeUrl = clone $url;
254-
$iframeUrl->setParam('isIframe');
250+
$fullUrl = $url->getUrlWithout(['showCompact', 'limit', 'view']);
251+
252+
$urlHash = '';
253+
$fullUrlHash = '';
254+
if ($url->getPath() === 'iframe') {
255+
$urlHash = hash('sha256', Url::fromPath($url->getParam('url'))->getAbsoluteUrl()
256+
. Session::getSession()->getId());
257+
$fullUrlHash = hash('sha256', Url::fromPath($fullUrl->getParam('url'))->getAbsoluteUrl()
258+
. Session::getSession()->getId());
259+
}
255260

256261
$searchTokens = array(
257262
'{URL}',
258-
'{IFRAME_URL}',
263+
'{URL_HASH}',
259264
'{FULL_URL}',
265+
'{FULL_URL_HASH}',
260266
'{TOOLTIP}',
261267
'{TITLE}',
262268
'{TITLE_PREFIX}',
@@ -265,8 +271,9 @@ public function render()
265271

266272
$replaceTokens = array(
267273
$url,
268-
$iframeUrl,
269-
$url->getUrlWithout(['showCompact', 'limit', 'view']),
274+
$urlHash,
275+
$fullUrl,
276+
$fullUrlHash,
270277
sprintf($view->translate('Show %s', 'dashboard.dashlet.tooltip'), $view->escape($this->getTitle())),
271278
$view->escape($this->getTitle()),
272279
$view->translate('Dashlet') . ': ',

public/js/icinga/events.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,21 @@
170170
var $dashlet = $(this);
171171
var url = $dashlet.data('icingaUrl');
172172
if (typeof url !== 'undefined') {
173-
_this.icinga.loader.loadUrl(url, $dashlet).autorefresh = true;
173+
const urlHash = this.dataset.urlHash;
174+
if (urlHash) {
175+
_this.icinga.loader.loadUrl(
176+
url,
177+
$dashlet,
178+
undefined,
179+
undefined,
180+
undefined,
181+
true,
182+
undefined,
183+
{ "X-Icinga-URLHash": urlHash }
184+
);
185+
} else {
186+
_this.icinga.loader.loadUrl(url, $dashlet).autorefresh = true;
187+
}
174188
}
175189
});
176190
}

0 commit comments

Comments
 (0)