diff --git a/plinth/modules/email/dns.py b/plinth/modules/email/dns.py index 6491c44ef..095ea071d 100644 --- a/plinth/modules/email/dns.py +++ b/plinth/modules/email/dns.py @@ -46,9 +46,8 @@ class Entry: # pylint: disable=too-many-instance-attributes return ' '.join(pieces) -def get_entries(): - """Return the list of DNS entries to make.""" - domain = privileged.domain.get_domains()['primary_domain'] +def get_entries(domain: str) -> list[Entry]: + """Return the list of DNS entries to be set in DNS server for domain.""" mx_spam_entries = [ Entry(type_='MX', value=f'{domain}.'), Entry(type_='TXT', value='v=spf1 mx a ~all'), @@ -77,10 +76,9 @@ def get_entries(): return mx_spam_entries + dkim_entries + autoconfig_entries -def get_reverse_entries() -> list[Entry]: +def get_reverse_entries(domain: str) -> list[Entry]: """Return the list of reverse DNS entries to make.""" entries = [] - domain = privileged.domain.get_domains()['primary_domain'] for ip_type in typing.get_args(typing.Literal['ipv4', 'ipv6']): try: ip_address = lookup_public_address(ip_type) diff --git a/plinth/modules/email/templates/email-dns.html b/plinth/modules/email/templates/email-dns.html new file mode 100644 index 000000000..9ecc939b9 --- /dev/null +++ b/plinth/modules/email/templates/email-dns.html @@ -0,0 +1,95 @@ +{% extends "base.html" %} +{% comment %} +# SPDX-License-Identifier: AGPL-3.0-or-later +{% endcomment %} + +{% load i18n %} + +{% block content %} +

{% trans "DNS Records for domain:" %} {{ domain }}

+ +

+ {% blocktrans trimmed %} + The following DNS records must be added manually on this domain for the + mail server to work properly for this domain. + {% endblocktrans %} +

+ +
+ + + + + + + + + + + + + + + {% for dns_entry in dns_entries %} + + + + + + + + + + + {% endfor %} + +
{% trans "Domain" %}{% trans "TTL" %}{% trans "Class" %}{% trans "Type" %}{% trans "Priority" %}{% trans "Weight" %}{% trans "Port" %}{% trans "Host/Target/Value" %}
{{ dns_entry.domain|default_if_none:"" }}{{ dns_entry.ttl }}{{ dns_entry.class_ }}{{ dns_entry.type_ }}{{ dns_entry.priority }}{{ dns_entry.weight|default_if_none:"" }}{{ dns_entry.port|default_if_none:"" }}{{ dns_entry.get_split_value }}
+
+ + {% if domain == primary_domain %} +

{% trans "Reverse DNS Records for IP Addresses" %}

+ +

+ {% blocktrans trimmed %} + If your {{ box_name }} runs on a cloud service infrastructure, you + should configure + Reverse DNS lookup. This isn't mandatory, however, it greatly improves + email deliverability. Reverse DNS isn't configured where your regular DNS + is. You should look for it in the settings of your VPS/ISP. Some providers + preconfigure the IP address part for you and you only have to set the + domain part. Only one of your domains can have Revese DNS lookup + configured unless you have multiple public IP addresses. + {% endblocktrans %} +

+ +

+ {% blocktrans trimmed %} + An external service is used to lookup public IP address to show in the + following section. This can be configured in the privacy app. + {% endblocktrans %} +

+ +
+ + + + + + + + + + + {% for dns_entry in reverse_dns_entries %} + + + + + + + {% endfor %} + +
{% trans "Host" %}{% trans "TTL" %}{% trans "Type" %}{% trans "Host/Target/Value" %}
{{ dns_entry.domain|default_if_none:"" }}{{ dns_entry.ttl }}{{ dns_entry.type_ }}{{ dns_entry.get_split_value }}
+
+ {% endif %} +{% endblock %} diff --git a/plinth/modules/email/templates/email.html b/plinth/modules/email/templates/email.html index 4fa1d4da2..d0ff370c4 100644 --- a/plinth/modules/email/templates/email.html +++ b/plinth/modules/email/templates/email.html @@ -17,82 +17,28 @@ {% endblock %} {% block extra_content %} - {{ block.super }} - -

{% trans "DNS Records" %}

+

{% trans "Domains" %}

{% blocktrans trimmed %} - The following DNS records must be added manually on your primary domain - for the mail server to work properly. + The following domains are configured. View details to see the list of DNS + entries to be made for the domain. {% endblocktrans %}

-
- - - - - - - - - - - - - - - {% for dns_entry in dns_entries %} - - - - - - - - - - +
+
+
+ {% for domain in all_domains %} +
+ + {{ domain }} + {% if domain == primary_domain %}
{% endif %} +
{% endfor %} -
-
{% trans "Domain" %}{% trans "TTL" %}{% trans "Class" %}{% trans "Type" %}{% trans "Priority" %}{% trans "Weight" %}{% trans "Port" %}{% trans "Host/Target/Value" %}
{{ dns_entry.domain|default_if_none:"" }}{{ dns_entry.ttl }}{{ dns_entry.class_ }}{{ dns_entry.type_ }}{{ dns_entry.priority }}{{ dns_entry.weight|default_if_none:"" }}{{ dns_entry.port|default_if_none:"" }}{{ dns_entry.get_split_value }}
-
- -

{% trans "Reverse DNS" %}

- -

- {% blocktrans trimmed %} - If your {{ box_name }} runs on a cloud service infrastructure, you - should configure - Reverse DNS lookup. This isn't mandatory, however, it greatly improves - email deliverability. Reverse DNS isn't configured where your regular DNS - is. You should look for it in the settings of your VPS. Some providers - preconfigure the IP address part for you and you only have to set the domain part. - {% endblocktrans %} -

- -
- - - - - - - - - - - {% for dns_entry in reverse_dns_entries %} - - - - - - - {% endfor %} - -
{% trans "Host" %}{% trans "TTL" %}{% trans "Type" %}{% trans "Host/Target/Value" %}
{{ dns_entry.domain|default_if_none:"" }}{{ dns_entry.ttl }}{{ dns_entry.type_ }}{{ dns_entry.get_split_value }}
+
+ {% endblock %} diff --git a/plinth/modules/email/urls.py b/plinth/modules/email/urls.py index e1e919b98..7c74adb5d 100644 --- a/plinth/modules/email/urls.py +++ b/plinth/modules/email/urls.py @@ -3,7 +3,7 @@ URLs for the email module. """ -from django.urls import path +from django.urls import path, re_path from stronghold.decorators import public from plinth.utils import non_admin_view @@ -12,6 +12,8 @@ from . import views urlpatterns = [ path('apps/email/', views.EmailAppView.as_view(), name='index'), + re_path('apps/email/dns/(?P[^/]+)/$', views.DnsView.as_view(), + name='dns'), path('apps/email/aliases/', non_admin_view(views.AliasView.as_view()), name='aliases'), path('apps/email/config.xml', public(views.XmlView.as_view())), diff --git a/plinth/modules/email/views.py b/plinth/modules/email/views.py index d2a8b325e..29e7fb46a 100644 --- a/plinth/modules/email/views.py +++ b/plinth/modules/email/views.py @@ -25,8 +25,7 @@ class EmailAppView(AppView): def get_context_data(self, **kwargs): """Add additional context data for rendering the template.""" context = super().get_context_data(**kwargs) - context['dns_entries'] = dns.get_entries() - context['reverse_dns_entries'] = dns.get_reverse_entries() + context.update(privileged.domain.get_domains()) return context def get_initial(self): @@ -51,6 +50,21 @@ class EmailAppView(AppView): return super().form_valid(form) +class DnsView(TemplateView): + """Show the DNS records to configure on a given domain.""" + template_name = 'email-dns.html' + + def get_context_data(self, **kwargs): + """Add additional context data for rendering the template.""" + domain = self.kwargs['domain'] + context = super().get_context_data(**kwargs) + primary_domain = privileged.domain.get_domains()['primary_domain'] + context['primary_domain'] = primary_domain + context['dns_entries'] = dns.get_entries(domain) + context['reverse_dns_entries'] = dns.get_reverse_entries(domain) + return context + + class AliasView(FormView): """View to create, list, enable, disable and delete aliases.