Module: check_mk
Branch: master
Commit: 080cc2641fad78a599ab23859d8f4789be80f27f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=080cc2641fad78…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Dec 16 14:48:15 2015 +0100
New valuespec for Check_MK version numbers
---
web/htdocs/valuespec.py | 21 ++++++++++++++++-----
web/htdocs/wato.py | 27 +++++++++++++++++----------
2 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index b52d3e9..82532a8 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -622,18 +622,20 @@ class AbsoluteDirname(TextAscii):
self._regex_error = _("Please enter a valid absolut pathname with / as a
path separator.")
-# Valuespec for a HTTP Url (not HTTPS), that
-# automatically adds http:// to the value
+# Valuespec for a HTTP or HTTPS Url, that
+# automatically adds http:// to the value if no protocol has
+# been specified
class HTTPUrl(TextAscii):
def __init__(self, **kwargs):
+ kwargs.setdefault("size", 64)
TextAscii.__init__(self, **kwargs)
self._target = kwargs.get("target")
def validate_value(self, value, varprefix):
TextAscii.validate_value(self, value, varprefix)
if value:
- if not value.startswith("http://"):
- raise MKUserError(varprefix, _("The URL must begin with
http://"))
+ if not value.startswith("http://") and not
value.startswith("https://"):
+ raise MKUserError(varprefix, _("The URL must begin with http:// or
https://"))
ValueSpec.custom_validate(self, value, varprefix)
def from_html_vars(self, varprefix):
@@ -644,7 +646,7 @@ class HTTPUrl(TextAscii):
return value
def value_to_text(self, url):
- if not url.startswith("http://"):
+ if not url.startswith("http://") and not
value.startswith("https://"):
url = "http://" + url
try:
parts = urlparse.urlparse(url)
@@ -661,6 +663,15 @@ class HTTPUrl(TextAscii):
(self._target and 'target="%s" ' % self._target or
""),
html.attrencode(url), html.attrencode(text))
+def CheckMKVersion(**args):
+ args = args.copy()
+ regex_unstable = "(1\.[1234]\.(1|3|5|7|9|11|13|15)i[1-9](p[0-9]+)?)"
+ regex_stable = "(1\.[1234]\.(0|2|4|6|8|10|12|14)([bp][1-9]?[0-9]+)?)"
+ args["regex"] = "(" + regex_unstable + "|" +
regex_stable + ")"
+ args["regex_error"] = _("This is not a valid Check_MK version
number")
+ return TextAscii(**args)
+
+
class TextAreaUnicode(TextUnicode):
def __init__(self, **kwargs):
TextUnicode.__init__(self, **kwargs)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index ac46a43..6cc74b7 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -141,15 +141,7 @@ def page_handler():
raise MKGeneralException(_("WATO is disabled. Please set
<tt>wato_enabled = True</tt>"
" in your <tt>multisite.mk</tt> if
you want to use WATO."))
current_mode = html.var("mode") or "main"
- modeperms, modefunc = modes.get(current_mode, ([], None))
- if type(modefunc) != type(lambda: None):
- mode_class = modefunc
- modefunc = mode_class.create_mode_function()
-
-
- if modeperms != None and not config.may("wato.use"):
- raise MKAuthException(_("You are not allowed to use WATO."))
-
+ modeperms, modefunc = get_mode_function(current_mode)
# If we do an action, we aquire an exclusive lock on the complete
# WATO.
@@ -212,7 +204,7 @@ def page_handler():
html.write("</div>")
html.footer()
return
- modeperms, modefunc = modes.get(newmode)
+ modeperms, modefunc = get_mode_function(newmode)
current_mode = newmode
html.set_var("mode", newmode) # will be used by makeuri
@@ -285,6 +277,21 @@ def page_handler():
html.footer()
+def get_mode_function(mode):
+ modeperms, modefunc = modes.get(mode, ([], None))
+ if modefunc == None:
+ raise MKGeneralException(_("No such WATO module
'<tt>%s</tt>'") % html.attrencode(mode))
+
+ if type(modefunc) != type(lambda: None):
+ mode_class = modefunc
+ modefunc = mode_class.create_mode_function()
+
+ if modeperms != None and not config.may("wato.use"):
+ raise MKAuthException(_("You are not allowed to use WATO."))
+
+ return modeperms, modefunc
+
+
def ensure_mode_permissions(modeperms):
for pname in modeperms:
if '.' not in pname: