1
0
mirror of https://github.com/Mailu/Mailu.git synced 2025-01-18 03:21:36 +02:00

adding section for the alternative domain names to the details page of the domain

code goes through all of the alternative domain names and displays:
- name of the alternative domain
- DNS MX entry
- DNS SPF entry
- if main domain has DKIM key: DNS DKIM entry
- if main domain has DKIM key: DNS DMARC entry

file modified:   core/admin/mailu/models.py
file modified:   core/admin/mailu/ui/templates/domain/details.html
This commit is contained in:
Jumper78 2024-07-22 10:16:38 +00:00
parent 4f0eb0ef35
commit 189689565c
2 changed files with 80 additions and 0 deletions

View File

@ -355,6 +355,54 @@ class Alternative(Base):
domain = db.relationship(Domain,
backref=db.backref('alternatives', cascade='all, delete-orphan'))
@property
def dns_dkim(self):
""" return DKIM record for domain """
if self.domain.dkim_key:
selector = app.config['DKIM_SELECTOR']
return f'{selector}._domainkey.{self.name}. 600 IN TXT "v=DKIM1; k=rsa; p={self.domain.dkim_publickey}"'
@cached_property
def dns_dmarc(self):
""" return DMARC record for domain """
if self.domain.dkim_key:
domain = app.config['DOMAIN']
rua = app.config['DMARC_RUA']
rua = f' rua=mailto:{rua}@{domain};' if rua else ''
ruf = app.config['DMARC_RUF']
ruf = f' ruf=mailto:{ruf}@{domain};' if ruf else ''
return f'_dmarc.{self.name}. 600 IN TXT "v=DMARC1; p=reject;{rua}{ruf} adkim=s; aspf=s"'
@cached_property
def dns_dmarc_report(self):
""" return DMARC report record for mailu server """
if self.domain.dkim_key:
domain = app.config['DOMAIN']
return f'{self.name}._report._dmarc.{domain}. 600 IN TXT "v=DMARC1;"'
@cached_property
def dns_mx(self):
""" return MX record for domain """
hostname = app.config['HOSTNAME']
return f'{self.name}. 600 IN MX 10 {hostname}.'
@cached_property
def dns_spf(self):
""" return SPF record for domain """
hostname = app.config['HOSTNAME']
return f'{self.name}. 600 IN TXT "v=spf1 mx a:{hostname} ~all"'
def check_mx(self):
""" checks if MX record for domain points to mailu host """
try:
hostnames = set(app.config['HOSTNAMES'].split(','))
return any(
rset.exchange.to_text().rstrip('.') in hostnames
for rset in dns.resolver.resolve(self.name, 'MX')
)
except dns.exception.DNSException:
return False
class Relay(Base):
""" Relayed mail domain.

View File

@ -63,4 +63,36 @@
</pre></td>
</tr>
{%- endcall %}
{%- for alternative in domain.alternatives %}
{%- call macros.table(datatable=False) %}
<tr>
<th>{% trans %}Alternative Domain name{% endtrans %}</th>
<td>{{ alternative.name }}</td>
</tr>
<tr>
<th>{% trans %}DNS MX entry{% endtrans %} <i class="fa {{ 'fa-check-circle text-success' if alternative.check_mx() else 'fa-exclamation-circle text-danger' }}"></i></th>
<td>{{ macros.clip("dns_mx") }}<pre id="dns_mx" class="pre-config border bg-light">{{ alternative.dns_mx }}</pre></td>
</tr>
<tr>
<th>{% trans %}DNS SPF entries{% endtrans %}</th>
<td>{{ macros.clip("dns_spf") }}<pre id="dns_spf" class="pre-config border bg-light">{{ alternative.dns_spf }}</pre>
</td>
</tr>
{%- if alternative.domain.dkim_publickey %}
<tr>
<th>{% trans %}DNS DKIM entry{% endtrans %}</th>
<td>{{ macros.clip("dns_dkim") }}<pre id="dns_dkim" class="pre-config border bg-light">{{ alternative.dns_dkim }}</pre></td>
</tr>
<tr>
<th>{% trans %}DNS DMARC entry{% endtrans %}</th>
<td>
{{ macros.clip("dns_dmarc") }}<pre id="dns_dmarc" class="pre-config border bg-light">{{ alternative.dns_dmarc }}</pre>
{{ macros.clip("dns_dmarc_report") }}<pre id="dns_dmarc_report" class="pre-config border bg-light">{{ alternative.dns_dmarc_report }}</pre>
</td>
</tr>
{%- endif %}
{%- endcall %}
{%- endfor %}
{%- endblock %}