Module: check_mk
Branch: master
Commit: 049d423d1281bf77b2af99ffcf254ae12809542d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=049d423d1281bf…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Dec 7 13:05:45 2012 +0100
Moved ValueSpec PasswordSpec to general lib
---
web/htdocs/index.py | 2 +-
web/htdocs/js/checkmk.js | 16 ++++++++++++++++
web/htdocs/lib.py | 4 ++--
web/htdocs/valuespec.py | 16 ++++++++++++++--
4 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index c946514..9a878ed 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -371,7 +371,7 @@ def handler(req, profiling = True):
html.header(_("Error"))
html.show_error(str(e))
html.footer()
- apache.log_error(_("Error: %s") % (e,), apache.APLOG_ERR)
+ # apache.log_error(_("Error: %s") % (e,), apache.APLOG_ERR)
except livestatus.MKLivestatusNotFoundError, e:
if plain_error:
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 29b5434..028e9e0 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -1594,6 +1594,22 @@ function valuespec_listof_fixarrows(oTbody) {
}
}
+function vs_passwordspec_randomize(img) {
+ password = "";
+ while (password.length < 8) {
+ a = parseInt(Math.random() * 128);
+ if ((a >= 97 && a <= 122) ||
+ (a >= 65 && a <= 90) ||
+ (a >= 48 && a <= 57)) {
+ c = String.fromCharCode(a);
+ password += c;
+ }
+ }
+ img.previousElementSibling.value = password;
+}
+
+
+
function help_enable() {
var aHelp = document.getElementById('helpbutton');
aHelp.style.display = "inline-block";
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 5af2f44..00f7e7c 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -34,13 +34,13 @@ class MKGeneralException(Exception):
def __init__(self, reason):
self.reason = reason
def __str__(self):
- return str(self.reason)
+ return self.reason
class MKAuthException(Exception):
def __init__(self, reason):
self.reason = reason
def __str__(self):
- return str(self.reason)
+ return self.reason
class MKUnauthenticatedException(MKGeneralException):
pass
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 6f9498e..76fe659 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -336,10 +336,10 @@ class TextAscii(ValueSpec):
if self._none_is_empty and value == "":
raise MKUserError(varprefix, _("An empty value must be represented with
None here."))
if not self._allow_empty and value.strip() == "":
- raise MKUserError(varprefix, self.title() + ": " + _("An empty
value is not allowed here."))
+ raise MKUserError(varprefix, _("An empty value is not allowed
here."))
if value and self._regex:
if not self._regex.match(value):
- raise MKUserError(varprefix, self.title() + ": " +
self._regex_error)
+ raise MKUserError(varprefix, self._regex_error)
# Internal ID as used in many places (for contact names, group name,
# an so on)
@@ -2158,3 +2158,15 @@ class Password(TextAscii):
return _("none")
else:
return '******'
+
+class PasswordSpec(TextAscii):
+ def __init__(self, **kwargs):
+ TextAscii.__init__(self, **kwargs)
+
+ def render_input(self, varprefix, value):
+ TextAscii.render_input(self, varprefix, value)
+ if not value:
+ html.icon_button("#", _(u"Randomize password"),
"random",
+ onclick="vs_passwordspec_randomize(this);")
+
+