Module: check_mk
Branch: master
Commit: e027a5fe4bf56ea8ab2cc4b9bf681ca46406f2d7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e027a5fe4bf56e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Jun 17 14:14:02 2015 +0200
WATO: disallow invalid host names when specifying list of explicit hosts
---
web/htdocs/valuespec.py | 3 ++-
web/htdocs/wato.py | 9 +++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 12ea130..1373c81 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -591,7 +591,8 @@ class Hostname(TextAscii):
def __init__(self, **kwargs):
TextAscii.__init__(self, **kwargs)
self._regex = re.compile('^[-0-9a-zA-Z_.]+$')
- self._regex_error = _("Please enter a valid hostname or IPv4
address.")
+ self._regex_error = _("Please enter a valid hostname or IPv4 address.
"
+ "Only only letters, digits, dash, underscore and dot
are allowed.")
class AbsoluteDirname(TextAscii):
def __init__(self, **kwargs):
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index b085225..a6caa57 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -2179,9 +2179,8 @@ def check_new_hostname(varname, hostname):
if not hostname:
raise MKUserError(varname, _("Please specify a host name."))
elif hostname in g_folder[".hosts"]:
- raise MKUserError(varname, _("A host with this name already exists."))
- elif not re.match("^[a-zA-Z0-9-_.]+$", hostname):
- raise MKUserError(varname, _("Invalid host name: must contain only
characters, digits, dash, underscore and dot."))
+ raise MKUserError(varname, _("A host with this name already exists in this
folder."))
+ Hostname().validate_value(hostname, varname)
def check_new_host_permissions(folder, host, hostname):
config.need_permission("wato.manage_hosts")
@@ -14834,7 +14833,9 @@ def get_rule_conditions(ruleset):
else:
negate = html.get_checkbox("negate_hosts")
nr = 0
- host_list = ListOfStrings().from_html_vars("hostlist")
+ vs = ListOfStrings(valuespec=Hostname())
+ host_list = vs.from_html_vars("hostlist")
+ vs.validate_value(host_list, "hostlist")
if negate:
host_list = [ "!" + h for h in host_list ]
# append ALL_HOSTS to negated host lists