Module: check_mk
Branch: master
Commit: 08f8e95eb51be04bd91e3ebcf61301f501546e2d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=08f8e95eb51be0…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Nov 25 09:26:43 2013 +0100
FIX Fixed bookmarking of absolute URLs or PNP/NagVis URLs in sidebar snapin
In previous versions, the URLs not pointing to multisite pages, bookmarked with
the sidebar snapin, could not be used, as they pointed to non existing URLs. This
was caused by th URL shortening algorithm used within the bookmark snapin.
---
.werks/285 | 10 ++++++++++
ChangeLog | 1 +
web/htdocs/sidebar.py | 41 ++++++++++++++++++++++++++++++++---------
3 files changed, 43 insertions(+), 9 deletions(-)
diff --git a/.werks/285 b/.werks/285
new file mode 100644
index 0000000..b854415
--- /dev/null
+++ b/.werks/285
@@ -0,0 +1,10 @@
+Title: Fixed bookmarking of absolute URLs or PNP/NagVis URLs in sidebar snapin
+Level: 1
+Component: multisite
+Version: 1.2.3i7
+Date: 1385367764
+Class: fix
+
+In previous versions, the URLs not pointing to multisite pages, bookmarked with
+the sidebar snapin, could not be used, as they pointed to non existing URLs. This
+was caused by th URL shortening algorithm used within the bookmark snapin.
diff --git a/ChangeLog b/ChangeLog
index 8a77f1c..2a31f2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -45,6 +45,7 @@
* 0035 FIX: http[s] links are display again in the plugin output...
* 0006 FIX: Checkboxes for hosts/services were missing on modified views...
* 0284 FIX: Context help toggled on/off randomly...
+ * 0285 FIX: Fixed bookmarking of absolute URLs or PNP/NagVis URLs in sidebar
snapin...
WATO:
* 0053 New rule for configuring the display_name of a service...
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index 151bb9e..3283123 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -25,7 +25,7 @@
# Boston, MA 02110-1301 USA.
import config, defaults, livestatus, views, pprint, os, copy, userdb
-import notify
+import notify, urlparse
from lib import *
# Constants to be used in snapins
@@ -562,16 +562,39 @@ def ajax_add_bookmark():
href = html.var("href")
if title and href:
bookmarks = load_bookmarks()
- # We try to remove
http://hostname/some/path/check_mk from the
- # URI. That keeps the configuration files (bookmarks) portable.
- # Problem here: We have not access to our own URL, only to the
- # path part. The trick: we use the Referrer-field from our
- # request. That points to the sidebar.
referer = html.req.headers_in.get("Referer")
+
if referer:
- while '/' in referer and referer.split('/')[0] ==
href.split('/')[0]:
- referer = referer.split('/', 1)[1]
- href = href.split('/', 1)[1]
+ ref_p = urlparse.urlsplit(referer)
+ url_p = urlparse.urlsplit(href)
+
+ # If http/https or user, pw, host, port differ, don't try to shorten
+ # the URL to be linked. Simply use the full URI
+ if ref_p.scheme == url_p.scheme and ref_p.netloc == url_p.netloc:
+ # We try to remove
http://hostname/some/path/check_mk from the
+ # URI. That keeps the configuration files (bookmarks) portable.
+ # Problem here: We have not access to our own URL, only to the
+ # path part. The trick: we use the Referrer-field from our
+ # request. That points to the sidebar.
+ referer = ref_p.path
+ href = url_p.path
+ if url_p.query:
+ href += '?' + url_p.query
+ removed = 0
+ while '/' in referer and referer.split('/')[0] ==
href.split('/')[0]:
+ referer = referer.split('/', 1)[1]
+ href = href.split('/', 1)[1]
+ removed += 1
+
+ if removed == 1:
+ # removed only the first "/". This should be an absolute
path.
+ href = '/' + href
+ elif '/' in referer:
+ # there is at least one other directory layer in the path, make
+ # the link relative to the sidebar.py's topdir. e.g. for pnp
+ # links in OMD setups
+ href = '../' + href
+
bookmarks.append((title, href))
save_bookmarks(bookmarks)
render_bookmarks()