mirror of
https://github.com/Mailu/Mailu.git
synced 2024-12-12 10:45:38 +02:00
Add a status field to the domain list
This commit is contained in:
parent
bb0d7bf6dc
commit
62d1a0c104
@ -135,6 +135,16 @@ class Domain(Base):
|
||||
else:
|
||||
return False
|
||||
|
||||
def check_mx(self):
|
||||
try:
|
||||
hostnames = app.config['HOSTNAMES'].split(',')
|
||||
return any(
|
||||
str(rset).split()[-1][:-1] in hostnames
|
||||
for rset in dns.resolver.query(self.name, 'MX')
|
||||
)
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
<th>{% trans %}Domain name{% endtrans %}</th>
|
||||
<th>{% trans %}Mailbox count{% endtrans %}</th>
|
||||
<th>{% trans %}Alias count{% endtrans %}</th>
|
||||
<th>{% trans %}Status{% endtrans %}</th>
|
||||
<th>{% trans %}Comment{% endtrans %}</th>
|
||||
<th>{% trans %}Created{% endtrans %}</th>
|
||||
<th>{% trans %}Last edit{% endtrans %}</th>
|
||||
@ -42,6 +43,7 @@
|
||||
<td>{{ domain.name }}</td>
|
||||
<td>{{ domain.users | count }} / {{ domain.max_users or '∞' }}</td>
|
||||
<td>{{ domain.aliases | count }} / {{ domain.max_aliases or '∞' }}</td>
|
||||
<td>{{ 'ok' if domain.check_mx() else 'MX error' }}</td>
|
||||
<td>{{ domain.comment or '' }}</td>
|
||||
<td>{{ domain.created_at }}</td>
|
||||
<td>{{ domain.updated_at or '' }}</td>
|
||||
|
@ -90,23 +90,15 @@ def domain_signup(domain_name=None):
|
||||
conflicting_domain = models.Domain.query.get(form.name.data)
|
||||
conflicting_alternative = models.Alternative.query.get(form.name.data)
|
||||
conflicting_relay = models.Relay.query.get(form.name.data)
|
||||
hostnames = app.config['HOSTNAMES'].split(',')
|
||||
if conflicting_domain or conflicting_alternative or conflicting_relay:
|
||||
flask.flash('Domain %s is already used' % form.name.data, 'error')
|
||||
else:
|
||||
# Check if the domain MX actually points to this server
|
||||
try:
|
||||
mxok = any(str(rset).split()[-1][:-1] in hostnames
|
||||
for rset in dns.resolver.query(form.name.data, 'MX'))
|
||||
except Exception as e:
|
||||
mxok = False
|
||||
if mxok:
|
||||
# Actually create the domain
|
||||
domain = models.Domain()
|
||||
form.populate_obj(domain)
|
||||
domain.max_quota_bytes = app.config['DEFAULT_QUOTA']
|
||||
domain.max_users = 10
|
||||
domain.max_aliases = 10
|
||||
domain = models.Domain()
|
||||
form.populate_obj(domain)
|
||||
domain.max_quota_bytes = app.config['DEFAULT_QUOTA']
|
||||
domain.max_users = 10
|
||||
domain.max_aliases = 10
|
||||
if domain.check_mx():
|
||||
db.session.add(domain)
|
||||
if flask_login.current_user.is_authenticated:
|
||||
user = models.User.query.get(flask_login.current_user.email)
|
||||
|
Loading…
Reference in New Issue
Block a user