From 76ee15c388604826238d0d82b481c8b50b3dcfa1 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Tue, 20 Nov 2018 16:50:57 +0100 Subject: [PATCH] Added DNS configuration page for domain. see #1621 --- modoboa/admin/forms/domain.py | 2 +- modoboa/admin/models/domain.py | 2 +- .../admin/_domain_dnschecks_status.html | 2 ++ .../admin/templates/admin/domain_detail.html | 6 +++- .../dnstools/locale/en/LC_MESSAGES/django.po | 25 +++++++++++++- .../dnstools/locale/fr/LC_MESSAGES/django.po | 27 +++++++++++++-- .../dnstools/domain_dns_configuration.html | 33 +++++++++++++++++++ modoboa/dnstools/tests.py | 6 ++++ modoboa/dnstools/urls.py | 3 ++ modoboa/dnstools/views.py | 19 +++++++++++ 10 files changed, 119 insertions(+), 6 deletions(-) create mode 100644 modoboa/dnstools/templates/dnstools/domain_dns_configuration.html diff --git a/modoboa/admin/forms/domain.py b/modoboa/admin/forms/domain.py index cbb238105..6a05eba45 100644 --- a/modoboa/admin/forms/domain.py +++ b/modoboa/admin/forms/domain.py @@ -40,7 +40,7 @@ class DomainFormGeneral(forms.ModelForm, DynamicForm): ) ) dkim_key_selector = forms.CharField( - label=ugettext_lazy("Key selector"), required=False) + label=ugettext_lazy("Key selector"), initial="modoboa", required=False) quota = forms.CharField( label=ugettext_lazy("Quota"), initial=0, diff --git a/modoboa/admin/models/domain.py b/modoboa/admin/models/domain.py index 230a97b81..a06932b87 100644 --- a/modoboa/admin/models/domain.py +++ b/modoboa/admin/models/domain.py @@ -237,7 +237,7 @@ class Domain(AdminObject): split_record.append(" \"%s\"" % record) break record = "\n".join(split_record) - return "{}._domainkey.{}. 10800 IN TXT (\n{})".format( + return "{}._domainkey.{}. IN TXT (\n{})".format( self.dkim_key_selector, self.name, record) def add_admin(self, account): diff --git a/modoboa/admin/templates/admin/_domain_dnschecks_status.html b/modoboa/admin/templates/admin/_domain_dnschecks_status.html index 4fc6fdfec..b66c4e8e9 100644 --- a/modoboa/admin/templates/admin/_domain_dnschecks_status.html +++ b/modoboa/admin/templates/admin/_domain_dnschecks_status.html @@ -22,6 +22,8 @@ {% if enable_dkim_checks and domain.enable_dkim %} {% if not domain.dkim_public_key %} DKIM + {% elif not domain.dkim_record %} + DKIM {% else %} DKIM diff --git a/modoboa/admin/templates/admin/domain_detail.html b/modoboa/admin/templates/admin/domain_detail.html index fbebca6ab..f6acf7d92 100644 --- a/modoboa/admin/templates/admin/domain_detail.html +++ b/modoboa/admin/templates/admin/domain_detail.html @@ -88,7 +88,11 @@
-

{% trans "DNS" %}

+

+ {% trans "DNS" %} + +

{% if enable_mx_checks or enable_dnsbl_checks %} diff --git a/modoboa/dnstools/locale/en/LC_MESSAGES/django.po b/modoboa/dnstools/locale/en/LC_MESSAGES/django.po index 35a9dfc02..a72e91518 100644 --- a/modoboa/dnstools/locale/en/LC_MESSAGES/django.po +++ b/modoboa/dnstools/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-11-20 10:22+0100\n" +"POT-Creation-Date: 2018-11-20 16:48+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -133,6 +133,25 @@ msgstr "" msgid "A DNS record has been found but its syntax is not valid:" msgstr "" +#: templates/dnstools/domain_dns_configuration.html:7 +msgid "" +"Here is an example of DNS configuration (bind format). Replace value between " +"[ ] by the appropriate ones." +msgstr "" + +#: templates/dnstools/domain_dns_configuration.html:15 +msgid "IP address of your Modoboa server" +msgstr "" + +#: templates/dnstools/domain_dns_configuration.html:28 +msgid "Auto configuration" +msgstr "" + +#: templates/dnstools/domain_dns_configuration.html:30 +#: templates/dnstools/domain_dns_configuration.html:31 +msgid "hostname of your automx server" +msgstr "" + #: views.py:36 msgid "{} record of {}" msgstr "" @@ -140,3 +159,7 @@ msgstr "" #: views.py:64 msgid "Auto configuration records for {}" msgstr "" + +#: views.py:84 +msgid "DNS configuration for {}" +msgstr "" diff --git a/modoboa/dnstools/locale/fr/LC_MESSAGES/django.po b/modoboa/dnstools/locale/fr/LC_MESSAGES/django.po index 9bda3a7fe..4c6be5d71 100644 --- a/modoboa/dnstools/locale/fr/LC_MESSAGES/django.po +++ b/modoboa/dnstools/locale/fr/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-11-20 10:22+0100\n" -"PO-Revision-Date: 2018-11-20 10:31+0100\n" +"POT-Creation-Date: 2018-11-20 16:48+0100\n" +"PO-Revision-Date: 2018-11-20 16:50+0100\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" @@ -133,6 +133,25 @@ msgstr "Un enregistrement DNS a été trouvé et est correct." msgid "A DNS record has been found but its syntax is not valid:" msgstr "Un enregistrement DNS a été trouvé mais sa syntaxe est incorrecte :" +#: templates/dnstools/domain_dns_configuration.html:7 +msgid "" +"Here is an example of DNS configuration (bind format). Replace value between " +"[ ] by the appropriate ones." +msgstr "Voici un exemple de configuration DNS (format bind). Remplacez les valeurs entre [ ] par celles appropriées." + +#: templates/dnstools/domain_dns_configuration.html:15 +msgid "IP address of your Modoboa server" +msgstr "Adresse IP de votre serveur Modoboa" + +#: templates/dnstools/domain_dns_configuration.html:28 +msgid "Auto configuration" +msgstr "Configuration automatique" + +#: templates/dnstools/domain_dns_configuration.html:30 +#: templates/dnstools/domain_dns_configuration.html:31 +msgid "hostname of your automx server" +msgstr "Nom d'hôte de votre serveur automx" + #: views.py:36 msgid "{} record of {}" msgstr "Enregistrement {} de {}" @@ -140,3 +159,7 @@ msgstr "Enregistrement {} de {}" #: views.py:64 msgid "Auto configuration records for {}" msgstr "Enregistrements d'autoconfiguration pour {}" + +#: views.py:84 +msgid "DNS configuration for {}" +msgstr "Configuration DNS pour {}" diff --git a/modoboa/dnstools/templates/dnstools/domain_dns_configuration.html b/modoboa/dnstools/templates/dnstools/domain_dns_configuration.html new file mode 100644 index 000000000..f76aa587b --- /dev/null +++ b/modoboa/dnstools/templates/dnstools/domain_dns_configuration.html @@ -0,0 +1,33 @@ +{% extends "common/generic_modal.html" %} + +{% load i18n %} + +{% block modalbody %} +
+ {% blocktrans trimmed %} + Here is an example of DNS configuration (bind format). Replace value between + [ ] by the appropriate ones. + {% endblocktrans %} +
+ + MX +
+mail.{{ domain.name }}. IN A [{% trans "IP address of your Modoboa server" %}]
+@ IN MX 10 mail.{{ domain.name }}.
+ SPF +
+@ IN TXT "v=spf1 mx ~all"
+ {% if domain.enable_dkim and domain.dkim_public_key %} + DKIM +
+{{ domain.bind_format_dkim_public_key }}
+ {% endif %} + DMARC +
+_dmarc.{{ domain.name }}. IN TXT "v=DMARC1; p=quarantine; pct=100"
+ {% trans "Auto configuration" %} +
+autoconfig.{{ domain.name }}. IN CNAME [{% trans "hostname of your automx server" %}]
+autodiscover.{{ domain.name }}. IN CNAME [{% trans "hostname of your automx server" %}]
+ +{% endblock %} diff --git a/modoboa/dnstools/tests.py b/modoboa/dnstools/tests.py index b0f7613c7..f2c2a296c 100644 --- a/modoboa/dnstools/tests.py +++ b/modoboa/dnstools/tests.py @@ -148,3 +148,9 @@ class ViewsTestCase(ModoTestCase): self.assertContains(response, "autoconfig record (Mozilla) found") self.assertContains( response, "autodiscover record (Microsoft) not found") + + def test_domain_dns_configuration(self): + url = reverse( + "dnstools:domain_dns_configuration", args=[self.ac_rec.domain.pk]) + response = self.client.get(url) + self.assertContains(response, "[IP address of your Modoboa server]") diff --git a/modoboa/dnstools/urls.py b/modoboa/dnstools/urls.py index b7c1f8496..ecbc96491 100644 --- a/modoboa/dnstools/urls.py +++ b/modoboa/dnstools/urls.py @@ -11,4 +11,7 @@ urlpatterns = [ url(r'^dnsrecords/autoconfig/(?P\d+)/$', views.AutoConfigRecordsStatusView.as_view(), name="autoconfig_records_status"), + url(r'^configuration/(?P\d+)/$', + views.DomainDNSConfigurationView.as_view(), + name="domain_dns_configuration"), ] diff --git a/modoboa/dnstools/views.py b/modoboa/dnstools/views.py index b6ea4c9c0..6ce92c739 100644 --- a/modoboa/dnstools/views.py +++ b/modoboa/dnstools/views.py @@ -65,3 +65,22 @@ class AutoConfigRecordsStatusView( self.object.name) }) return context + + +class DomainDNSConfigurationView( + auth_mixins.LoginRequiredMixin, + DomainAccessRequiredMixin, + generic.DetailView): + """Page to display DNS configuration for a domain.""" + + model = admin_models.Domain + template_name = "dnstools/domain_dns_configuration.html" + + def get_context_data(self, **kwargs): + """Add extra variables.""" + context = super(DomainDNSConfigurationView, self).get_context_data( + **kwargs) + context.update({ + "title": _("DNS configuration for {}").format(self.object) + }) + return context