From 6704da14467ea12fe08be8f74d9be43f6fd0e6bf Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sun, 6 Sep 2015 13:24:15 +0000 Subject: [PATCH] silence errors in the admin if there is an invalid domain name in the database see #531 --- CHANGELOG.md | 1 + management/mailconfig.py | 8 +++++++- management/status_checks.py | 10 ++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36ed932..a369e17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Control panel: * Fixed the jumpiness when a modal is displayed. * Focus is put into the login form fields when the login form is displayed. * Status checks now include a warning if a custom DNS record has been set on a domain that would normally serve web and as a result that domain no longer is serving web. +* Some errors in the control panel when there is invalid data in the database or an improperly named archived user account have been suppressed. v0.13b (August 30, 2015) ------------------------ diff --git a/management/mailconfig.py b/management/mailconfig.py index ca93441..b1ac9b1 100755 --- a/management/mailconfig.py +++ b/management/mailconfig.py @@ -244,7 +244,13 @@ def get_domain(emailaddr, as_unicode=True): # Gets the domain part of an email address. Turns IDNA # back to Unicode for display. ret = emailaddr.split('@', 1)[1] - if as_unicode: ret = idna.decode(ret.encode('ascii')) + if as_unicode: + try: + ret = idna.decode(ret.encode('ascii')) + except (ValueError, UnicodeError, idna.IDNAError): + # Looks like we have an invalid email address in + # the database. Now is not the time to complain. + pass return ret def get_mail_domains(env, filter_aliases=lambda alias : True): diff --git a/management/status_checks.py b/management/status_checks.py index a051e17..65b183b 100755 --- a/management/status_checks.py +++ b/management/status_checks.py @@ -263,8 +263,14 @@ def run_domain_checks(rounded_time, env, output, pool): def run_domain_checks_on_domain(domain, rounded_time, env, dns_domains, dns_zonefiles, mail_domains, web_domains, domains_with_a_records): output = BufferedOutput() - # The domain is IDNA-encoded, but for display use Unicode. - output.add_heading(idna.decode(domain.encode('ascii'))) + # The domain is IDNA-encoded in the database, but for display use Unicode. + try: + domain_display = idna.decode(domain.encode('ascii')) + output.add_heading(domain_display) + except (ValueError, UnicodeError, idna.IDNAError) as e: + # Looks like we have some invalid data in our database. + output.add_heading(domain) + output.print_error("Domain name is invalid: " + str(e)) if domain == env["PRIMARY_HOSTNAME"]: check_primary_hostname_dns(domain, env, output, dns_domains, dns_zonefiles)