Module: check_mk
Branch: master
Commit: 699b76ffae8040863b5690303736ca62385f2cc4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=699b76ffae8040…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Nov 11 09:39:10 2015 +0100
The LDAP synchronization of Check_MK could already synchronize emails addresses
containing special characters like umlauts. But this was not supported by the
GUI, notification engine and core. This has been fixed now.
Conflicts:
ChangeLog
modules/check_mk.py
---
.werks/2759 | 12 ++++++++++++
ChangeLog | 1 +
modules/check_mk.py | 1 +
modules/nagios.py | 4 ++--
notifications/asciimail | 2 +-
notifications/mail | 2 +-
web/htdocs/valuespec.py | 13 +++++++++++++
web/htdocs/wato.py | 16 +++++++++++-----
8 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/.werks/2759 b/.werks/2759
new file mode 100644
index 0000000..7c748fd
--- /dev/null
+++ b/.werks/2759
@@ -0,0 +1,12 @@
+Title: Allowing Emails to contain special characters like umlauts
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i4
+Date: 1447230555
+
+The LDAP synchronization of Check_MK could already synchronize emails addresses
+containing special characters like umlauts. But this was not supported by the
+GUI, notification engine and core. This has been fixed now.
diff --git a/ChangeLog b/ChangeLog
index fe911f9..1a7a075 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
* 2718 FIX: Fixed agent timeouts not resulting in a crash report anympore...
* 2724 FIX: Discovery check: Fixed exception in simulation mode when no cache file
present
* 2756 FIX: SNMP: Generalized error handling of emtpy info for SNMP checks...
+ * 2759 FIX: Allowing Emails to contain special characters like umlauts...
Checks & Agents:
* 2434 NetApp monitoring: Cluster-Mode is now supported, changes in existing 7Mode
checks...
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 6ed4325..1dc78fa 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -2201,6 +2201,7 @@ def do_update_dns_cache():
return updated, failed
+
def agent_port_of(hostname):
ports = host_extra_conf(hostname, agent_ports)
if len(ports) == 0:
diff --git a/modules/nagios.py b/modules/nagios.py
index 7f51276..fa45388 100644
--- a/modules/nagios.py
+++ b/modules/nagios.py
@@ -848,11 +848,11 @@ def create_nagios_config_contacts(outfile, hostnames):
if not cgrs:
continue
- outfile.write("define contact {\n contact_name\t\t\t%s\n" %
cname)
+ outfile.write("define contact {\n contact_name\t\t\t%s\n" %
make_utf8(cname))
if "alias" in contact:
outfile.write(" alias\t\t\t\t%s\n" %
make_utf8(contact["alias"]))
if "email" in contact:
- outfile.write(" email\t\t\t\t%s\n" %
contact["email"])
+ outfile.write(" email\t\t\t\t%s\n" %
make_utf8(contact["email"]))
if "pager" in contact:
outfile.write(" pager\t\t\t\t%s\n" %
contact["pager"])
if enable_rulebased_notifications:
diff --git a/notifications/asciimail b/notifications/asciimail
index 5d6b203..8ae5a53 100755
--- a/notifications/asciimail
+++ b/notifications/asciimail
@@ -87,7 +87,7 @@ def send_mail(m, target, from_address):
cmd = ["/usr/sbin/sendmail"]
if from_address:
cmd += ['-f', from_address]
- cmd += [ "-i", target]
+ cmd += [ "-i", target.encode("utf-8")]
p = subprocess.Popen(cmd, stdin = subprocess.PIPE)
p.communicate(m.as_string())
diff --git a/notifications/mail b/notifications/mail
index 3ceb71b..6de3ca0 100755
--- a/notifications/mail
+++ b/notifications/mail
@@ -404,7 +404,7 @@ def send_mail(m, target, from_address):
cmd = ["/usr/sbin/sendmail"]
if from_address:
cmd += ['-f', from_address]
- cmd += [ "-i", target]
+ cmd += [ "-i", target.encode("utf-8")]
try:
p = subprocess.Popen(cmd, stdin = subprocess.PIPE)
except OSError:
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index c3617da..6992d39 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -514,6 +514,7 @@ class RegExpUnicode(TextUnicode, RegExp):
RegExp.validate_value(self, value, varprefix)
ValueSpec.custom_validate(self, value, varprefix)
+
class EmailAddress(TextAscii):
def __init__(self, **kwargs):
kwargs.setdefault("size", 40)
@@ -533,6 +534,18 @@ class EmailAddress(TextAscii):
return value
+class EmailAddressUnicode(TextUnicode, EmailAddress):
+ def __init__(self, **kwargs):
+ TextUnicode.__init__(self, **kwargs)
+ EmailAddress.__init__(self, **kwargs)
+ self._regex = re.compile(r'^[\w._%+-]+(a)(localhost|[\w.-]+\.[\w]{2,24})$'})$',
re.I | re.UNICODE)
+
+ def validate_value(self, value, varprefix):
+ TextUnicode.validate_value(self, value, varprefix)
+ EmailAddress.validate_value(self, value, varprefix)
+ ValueSpec.custom_validate(self, value, varprefix)
+
+
# Network as used in routing configuration, such as
# "10.0.0.0/8" or "192.168.56.1"
class IPv4Network(TextAscii):
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 38ef972..1c597b0 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -12876,6 +12876,8 @@ def mode_edit_user(phase):
else:
vs_user_id = FixedValue(userid)
+ vs_email = EmailAddressUnicode()
+
# Returns true if an attribute is locked and should be read only. Is only
# checked when modifying an existing user
locked_attributes = userdb.locked_attributes(user.get('connector'))
@@ -12977,10 +12979,8 @@ def mode_edit_user(phase):
new_user['serial'] = new_user.get('serial', 0) + 1
# Email address
- email = html.var("email", '').strip()
- regex_email =
'^[-a-zäöüÄÖÜA-Z0-9_.+%]+(a)xn--[-a-za-z0-9]+(\-4kba73ab2jc.xn--[-a-za-z0-9]+)*$'-91ba54bb8mc
- if email and not re.match(regex_email, email):
- raise MKUserError("email", _("'%s' is not a valid
email address." % email))
+ email = vs_email.from_html_vars("email")
+ vs_email.validate_value(email, "email")
new_user["email"] = email
# Pager
@@ -13084,7 +13084,13 @@ def mode_edit_user(phase):
# Email address
forms.section(_("Email address"))
- lockable_input('email', '')
+ email = user.get("email", "")
+ if not is_locked("email"):
+ vs_email.render_input("email", email)
+ else:
+ html.write(email)
+ html.hidden_field("email", email)
+
html.help(_("The email address is optional and is needed "
"if the user is a monitoring contact and receives notifications
"
"via Email."))