diff --git a/core/admin/mailu/models.py b/core/admin/mailu/models.py index 926ef2fc..45ec457c 100644 --- a/core/admin/mailu/models.py +++ b/core/admin/mailu/models.py @@ -232,9 +232,7 @@ class Domain(Base): """ return DKIM record for domain """ if self.dkim_key: selector = app.config['DKIM_SELECTOR'] - txt = f'v=DKIM1; k=rsa; p={self.dkim_publickey}' - record = ' '.join(f'"{txt[p:p+250]}"' for p in range(0, len(txt), 250)) - return f'{selector}._domainkey.{self.name}. 600 IN TXT {record}' + return f'{selector}._domainkey.{self.name}. 600 IN TXT "v=DKIM1; k=rsa; p={self.dkim_publickey}"' @cached_property def dns_dmarc(self): diff --git a/core/admin/mailu/translations/en/LC_MESSAGES/messages.po b/core/admin/mailu/translations/en/LC_MESSAGES/messages.po index 4ec33e05..f19e191f 100644 --- a/core/admin/mailu/translations/en/LC_MESSAGES/messages.po +++ b/core/admin/mailu/translations/en/LC_MESSAGES/messages.po @@ -511,6 +511,10 @@ msgstr "" msgid "Generate keys" msgstr "" +#: mailu/ui/templates/domain/details.html:19 +msgid "Download zonefile" +msgstr "" + #: mailu/ui/templates/domain/details.html:30 msgid "DNS MX entry" msgstr "" diff --git a/core/admin/mailu/ui/templates/domain/details.html b/core/admin/mailu/ui/templates/domain/details.html index 28f3f570..74657c28 100644 --- a/core/admin/mailu/ui/templates/domain/details.html +++ b/core/admin/mailu/ui/templates/domain/details.html @@ -10,13 +10,13 @@ {%- block main_action %} {%- if current_user.global_admin %} - + {%- if domain.dkim_publickey %} {% trans %}Regenerate keys{% endtrans %} {%- else %} {% trans %}Generate keys{% endtrans %} {%- endif %} - + {% trans %}Download zonefile{% endtrans %} {%- endif %} {%- endblock %} @@ -36,10 +36,6 @@ {%- if domain.dkim_publickey %} - - {% trans %}DKIM public key{% endtrans %} - {{ macros.clip("dkim_key") }}
{{ domain.dkim_publickey }}
- {% trans %}DNS DKIM entry{% endtrans %} {{ macros.clip("dns_dkim") }}
{{ domain.dns_dkim }}
diff --git a/core/admin/mailu/ui/views/domains.py b/core/admin/mailu/ui/views/domains.py index 4cdd830a..dcd1aedd 100644 --- a/core/admin/mailu/ui/views/domains.py +++ b/core/admin/mailu/ui/views/domains.py @@ -70,6 +70,27 @@ def domain_details(domain_name): domain = models.Domain.query.get(domain_name) or flask.abort(404) return flask.render_template('domain/details.html', domain=domain) +@ui.route('/domain/details//zonefile', methods=['GET']) +@access.domain_admin(models.Domain, 'domain_name') +def domain_download_zonefile(domain_name): + domain = models.Domain.query.get(domain_name) or flask.abort(404) + res = [domain.dns_mx, domain.dns_spf] + if domain.dkim_publickey: + record = domain.dns_dkim.split('"', 1)[0].strip() + txt = f'v=DKIM1; k=rsa; p={domain.dkim_publickey}' + txt = ' '.join(f'"{txt[p:p+250]}"' for p in range(0, len(txt), 250)) + res.append(f'{record} {txt}') + res.append(domain.dns_dmarc) + if domain.dns_tlsa: + res.append(domain.dns_tlsa) + res.extend(domain.dns_autoconfig) + res.append("") + return flask.Response( + "\n".join(res), + content_type="text/plain", + headers={"Content-disposition": f"attachment; filename={domain.name}-zonefile.txt"} + ) + @ui.route('/domain/genkeys/', methods=['GET', 'POST']) @access.domain_admin(models.Domain, 'domain_name') diff --git a/docs/webadministration.rst b/docs/webadministration.rst index 802ce43b..3ce53fe8 100644 --- a/docs/webadministration.rst +++ b/docs/webadministration.rst @@ -280,7 +280,7 @@ On the `Mail domains` page all the domains served by Mailu are configured. Via t Details ``````` -This page is also accessible for domain managers. On the details page all DNS settings are displayed for configuring your DNS server. It contains information on what to configure as MX record and SPF record. On this page it is also possible to (re-)generate the keys for DKIM and DMARC. The option for generating keys for DKIM and DMARC is only available for global administrators. After generating the keys for DKIM and DMARC, this page will also show the DNS records for configuring the DKIM/DMARC records on the DNS server. +This page is also accessible for domain managers. On the details page all DNS settings are displayed for configuring your DNS server. It contains information on what to configure as MX record and SPF record. On this page it is also possible to (re-)generate the keys for DKIM and DMARC. The option for generating keys for DKIM and DMARC is only available for global administrators. After generating the keys for DKIM and DMARC, this page will also show the DNS records for configuring the DKIM/DMARC records on the DNS server. You can also download a zonefile for easy upload to your nameserver. Edit diff --git a/towncrier/newsfragments/3023.feature b/towncrier/newsfragments/3023.feature new file mode 100644 index 00000000..1bc39cb1 --- /dev/null +++ b/towncrier/newsfragments/3023.feature @@ -0,0 +1 @@ +Add "download zonefile" button to domain configuration and un-split dkim key in dns table