diff --git a/modoboa/admin/app_settings.py b/modoboa/admin/app_settings.py index 7a8678e59..efe660930 100644 --- a/modoboa/admin/app_settings.py +++ b/modoboa/admin/app_settings.py @@ -51,6 +51,16 @@ ADMIN_EVENTS = [ class AdminParametersForm(parameters.AdminParametersForm): app = "admin" + dom_sep = SeparatorField(label=ugettext_lazy("Domains")) + + enable_dnsbl_checks = YesNoField( + label=ugettext_lazy("Enable DNSBL checks"), + initial="yes", + help_text=ugettext_lazy( + "Check every domain against major DNSBL providers" + ) + ) + mbsep = SeparatorField(label=ugettext_lazy("Mailboxes")) handle_mailboxes = YesNoField( diff --git a/modoboa/admin/management/commands/subcommands/_dnsbl.py b/modoboa/admin/management/commands/subcommands/_dnsbl.py index c2819502e..ff8695334 100644 --- a/modoboa/admin/management/commands/subcommands/_dnsbl.py +++ b/modoboa/admin/management/commands/subcommands/_dnsbl.py @@ -11,6 +11,7 @@ from django.core.management.base import BaseCommand from modoboa.admin import constants from modoboa.admin import models +from modoboa.lib import parameters class CheckDNSBLCommand(BaseCommand): @@ -58,6 +59,9 @@ class CheckDNSBLCommand(BaseCommand): finally: if address is not None: ip_list.append(address) + print domain.name, ip_list + if len(ip_list) == 0: + return if not hasattr(settings, "DNSBL_PROVIDERS"): providers = constants.DNSBL_PROVIDERS else: @@ -78,5 +82,7 @@ class CheckDNSBLCommand(BaseCommand): def handle(self, *args, **options): """Command entry point.""" + if parameters.get_admin("ENABLE_DNSBL_CHECKS") == "no": + return for domain in models.Domain.objects.filter(enabled=True): self.check_domain(domain, options.get("timeout")) diff --git a/modoboa/admin/models/domain.py b/modoboa/admin/models/domain.py index 2dc24b73d..277db2d40 100644 --- a/modoboa/admin/models/domain.py +++ b/modoboa/admin/models/domain.py @@ -3,6 +3,7 @@ from django.db import models from django.db.models.manager import Manager from django.utils.encoding import python_2_unicode_compatible, smart_text +from django.utils.functional import cached_property from django.utils.translation import ugettext as _, ugettext_lazy from django.contrib.contenttypes.fields import GenericRelation @@ -101,9 +102,15 @@ class Domain(AdminObject): def aliases(self): return self.domainalias_set - def is_in_dnsbl(self): + @cached_property + def dnsbl_status_color(self): """Shortcut to DNSBL results.""" - return self.dnsblresult_set.blacklisted().exists() + if not self.dnsblresult_set.exists(): + return "warning" + elif self.dnsblresult_set.blacklisted().exists(): + return "danger" + else: + return "success" def add_admin(self, account): """Add a new administrator to this domain. diff --git a/modoboa/admin/templates/admin/dnsbl_domain_detail.html b/modoboa/admin/templates/admin/dnsbl_domain_detail.html index d68210708..e69e42f79 100644 --- a/modoboa/admin/templates/admin/dnsbl_domain_detail.html +++ b/modoboa/admin/templates/admin/dnsbl_domain_detail.html @@ -3,7 +3,7 @@ {% load i18n %} {% block modalbody %} - {% if domain.is_in_dnsbl %} + {% if domain.dnsbl_status_color == "danger" %}