mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2024-12-21 07:07:05 +00:00
refactor custom DNS records
This commit is contained in:
parent
2e0680de4f
commit
1ad9c70887
@ -182,22 +182,9 @@ def build_zone(domain, all_domains, additional_records, env, is_zone=True):
|
||||
return False
|
||||
|
||||
# The user may set other records that don't conflict with our settings.
|
||||
for qname, value in additional_records.items():
|
||||
if qname != domain and not qname.endswith("." + domain): continue
|
||||
if qname == domain:
|
||||
qname = None
|
||||
else:
|
||||
qname = qname[0:len(qname)-len("." + domain)]
|
||||
if isinstance(value, str):
|
||||
values = [("A", value)]
|
||||
elif isinstance(value, dict):
|
||||
values = value.items()
|
||||
else:
|
||||
raise ValueError()
|
||||
for rtype, value2 in values:
|
||||
if has_rec(qname, rtype): continue
|
||||
if rtype == "TXT": value2 = "\"" + value2 + "\""
|
||||
records.append((qname, rtype, value2, "(Set by user.)"))
|
||||
for qname, rtype, value in get_custom_records(domain, additional_records):
|
||||
if has_rec(qname, rtype): continue
|
||||
records.append((qname, rtype, value, "(Set by user.)"))
|
||||
|
||||
# Add defaults if not overridden by the user's custom settings.
|
||||
defaults = [
|
||||
@ -230,6 +217,40 @@ def build_zone(domain, all_domains, additional_records, env, is_zone=True):
|
||||
|
||||
########################################################################
|
||||
|
||||
def get_custom_records(domain, additional_records):
|
||||
for qname, value in additional_records.items():
|
||||
# Is this record for the domain or one of its subdomains?
|
||||
if qname != domain and not qname.endswith("." + domain): continue
|
||||
|
||||
# Turn the fully qualified domain name in the YAML file into
|
||||
# our short form (None => domain, or a relative QNAME).
|
||||
if qname == domain:
|
||||
qname = None
|
||||
else:
|
||||
qname = qname[0:len(qname)-len("." + domain)]
|
||||
|
||||
# Short form. Mapping a domain name to a string is short-hand
|
||||
# for creating A records.
|
||||
if isinstance(value, str):
|
||||
values = [("A", value)]
|
||||
|
||||
# A mapping creates multiple records.
|
||||
elif isinstance(value, dict):
|
||||
values = value.items()
|
||||
|
||||
# No other type of data is allowed.
|
||||
else:
|
||||
raise ValueError()
|
||||
|
||||
for rtype, value2 in values:
|
||||
# For typical zone file output, quote a text record.
|
||||
if rtype == "TXT":
|
||||
value2 = "\"" + value2 + "\""
|
||||
|
||||
yield (qname, rtype, value2)
|
||||
|
||||
########################################################################
|
||||
|
||||
def build_tlsa_record(env):
|
||||
# A DANE TLSA record in DNS specifies that connections on a port
|
||||
# must use TLS and the certificate must match a particular certificate.
|
||||
|
Loading…
Reference in New Issue
Block a user