Module: check_mk
Branch: master
Commit: c9d80c57de83b69bb49f5c25186a49b3cee58aef
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c9d80c57de83b6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Dec 17 11:15:03 2014 +0100
#1766 FIX Fixed exceptions in Web GUI when host or service groups used non ascii
characters in names
It is possible to define host and service groups which contain non ascii characters (e.g.
umlauts)
in their names. This is only possible to configure via config files, not via WATO for the
moment.
These groups lead to exceptions in the Web GUI, which has been fixed now.
---
.werks/1766 | 12 ++++++++++++
ChangeLog | 1 +
modules/check_mk.py | 4 ++--
web/htdocs/htmllib.py | 17 ++++++++++++-----
web/htdocs/valuespec.py | 7 +++++++
5 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/.werks/1766 b/.werks/1766
new file mode 100644
index 0000000..7b6c1b6
--- /dev/null
+++ b/.werks/1766
@@ -0,0 +1,12 @@
+Title: Fixed exceptions in Web GUI when host or service groups used non ascii characters
in names
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i1
+Date: 1418811123
+
+It is possible to define host and service groups which contain non ascii characters (e.g.
umlauts)
+in their names. This is only possible to configure via config files, not via WATO for the
moment.
+These groups lead to exceptions in the Web GUI, which has been fixed now.
diff --git a/ChangeLog b/ChangeLog
index cf01f4c..60b0076 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -22,6 +22,7 @@
* 1758 Improved exception hander: Shows details without additional debug request,
added mailto link for error report...
* 1781 FIX: Fix broken grouping by host/service group in availability
* 1783 FIX: Finish the view "History of Scheduled Downtimes"...
+ * 1766 FIX: Fixed exceptions in Web GUI when host or service groups used non ascii
characters in names...
WATO:
* 1760 Added search form to manual checks page
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 8c2881e..00f53b8 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -4605,8 +4605,8 @@ def dump_host(hostname):
parents_list = parents_of(hostname)
if len(parents_list) > 0:
print tty_yellow + "Parents: " + tty_normal + ",
".join(parents_list)
- print tty_yellow + "Host groups: " + tty_normal + ",
".join(hostgroups_of(hostname))
- print tty_yellow + "Contact groups: " + tty_normal + ",
".join(host_contactgroups_of([hostname]))
+ print tty_yellow + "Host groups: " + tty_normal +
make_utf8(", ".join(hostgroups_of(hostname)))
+ print tty_yellow + "Contact groups: " + tty_normal +
make_utf8(", ".join(host_contactgroups_of([hostname])))
agenttypes = []
if is_tcp_host(hostname):
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 7f0a305..1bd52a4 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -500,7 +500,7 @@ class html:
self.text_input(varname, default_value, type="password", size = size,
**args)
def text_area(self, varname, deflt="", rows=4, cols=30, attrs = {}):
- value = self.vars.get(varname, deflt)
+ value = self.var(varname, deflt)
error = self.user_errors.get(varname)
if error:
self.write("<x class=inputerror>")
@@ -528,7 +528,10 @@ class html:
self.write("<select%s name=\"%s\"
id=\"%s\"%s>\n" %
(onchange_code, varname, varname, attributes))
for value, text in options:
- if value == None: value = ""
+ if value == None:
+ value = ""
+ elif type(value) == unicode:
+ value = value.encode('utf-8')
sel = value == current and " selected" or ""
self.write("<option
value=\"%s\"%s>%s</option>\n" %
(self.attrencode(value), sel, self.attrencode(text)))
@@ -887,7 +890,7 @@ class html:
if self.myfile == "view":
mode_name = self.var('mode') == "availability" and
"availability" or "view"
- encoded_vars = self.attrencode([ (k, v != None and str(v) or '') for
k,v in self.page_context.items() ])
+ encoded_vars = self.attrencode([ (k, v != None and v or '') for k,v
in self.page_context.items() ])
h += '<div class="visualadd"><a
class="visualadd" href="javascript:void(0)" ' \
'onclick="toggle_add_to_visual(event, this, \'%s\', %s,
{\'name\': \'%s\'})">' \
'<img class=statusicon
src="images/status_add_dashlet.png"
title="%s"></a></div>\n' % \
@@ -1256,13 +1259,17 @@ class html:
# From here: Former not class functions
+ # This function returns a str object, never unicode!
# Encode HTML attributes: replace " with ", also replace
# < and >. This code is slow.
def attrencode(self, value):
- if type(value) == int:
+ ty = type(value)
+ if ty == int:
return str(value)
- elif type(value) not in [str, unicode]:
+ elif ty not in [str, unicode]:
value = str(value)
+ elif ty == unicode:
+ value = value.encode("utf-8")
return value.replace('"',
""").replace("<",
"<").replace(">", ">")
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 57c7b11..5d14de3 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -457,6 +457,13 @@ class ID(TextAscii):
self._regex = re.compile('^[a-zA-Z_][-a-zA-Z0-9_]*$')
self._regex_error = _("An identifier must only consist of letters, digits,
dash and underscore and it must start with a letter or underscore.")
+# Same as the ID class, but allowing unicode objects
+class UnicodeID(TextUnicode):
+ def __init__(self, **kwargs):
+ TextAscii.__init__(self, **kwargs)
+ self._regex = re.compile(r'^[\w][-\w0-9_]*$', re.UNICODE)
+ self._regex_error = _("An identifier must only consist of letters, digits,
dash and underscore and it must start with a letter or underscore.")
+
class RegExp(TextAscii):
def __init__(self, **kwargs):
TextAscii.__init__(self, attrencode = True, cssclass = 'text regexp',
**kwargs)