DNS: fix some crashes in cmdeploy dns

This commit is contained in:
missytake
2023-12-19 17:05:08 +01:00
parent 39fc9d628f
commit 7921f5dd0b

View File

@@ -47,6 +47,7 @@ class DNS:
def check_ptr_record(self, ip: str, mail_domain) -> str: def check_ptr_record(self, ip: str, mail_domain) -> str:
"""Check the PTR record for an IPv4 or IPv6 address.""" """Check the PTR record for an IPv4 or IPv6 address."""
result = self.get("-x", ip) result = self.get("-x", ip)
if result:
if ip_address(ip).version == 6: if ip_address(ip).version == 6:
result = result.split()[-1] result = result.split()[-1]
if result[:-1] == mail_domain: if result[:-1] == mail_domain:
@@ -101,7 +102,7 @@ def show_dns(args, out):
zf.write(zonefile) zf.write(zonefile)
print(f"DNS records successfully written to: {args.zonefile}") print(f"DNS records successfully written to: {args.zonefile}")
return return
except AttributeError: except TypeError:
pass pass
started_dkim_parsing = False started_dkim_parsing = False
for line in zonefile.splitlines(): for line in zonefile.splitlines():
@@ -135,6 +136,7 @@ def show_dns(args, out):
domain, value = line.split(" TXT ") domain, value = line.split(" TXT ")
current = dns.get("TXT", domain.strip()[:-1]) current = dns.get("TXT", domain.strip()[:-1])
if domain.startswith("_mta-sts."): if domain.startswith("_mta-sts."):
if current:
if current.split("id=")[0] == value.split("id=")[0]: if current.split("id=")[0] == value.split("id=")[0]:
continue continue
if current != value: if current != value:
@@ -145,10 +147,13 @@ def show_dns(args, out):
if started_dkim_parsing and line.startswith('"'): if started_dkim_parsing and line.startswith('"'):
dkim_lines.append(" " + line) dkim_lines.append(" " + line)
domain, data = "\n".join(dkim_lines).split(" IN TXT ") domain, data = "\n".join(dkim_lines).split(" IN TXT ")
current = dns.get("TXT", domain.strip()[:-1]).replace('" "', '"\n "') current = dns.get("TXT", domain.strip()[:-1])
current = f"( {current} )" if current:
current = "( %s )" % (current.replace('" "', '"\n "'))
if current.replace(";", "\\;") != data: if current.replace(";", "\\;") != data:
to_print.append(dkim_entry) to_print.append(dkim_entry)
else:
to_print.append(dkim_entry)
if to_print: if to_print:
to_print.insert( to_print.insert(
@@ -190,8 +195,6 @@ def check_necessary_dns(out, mail_domain):
if not (ipv4 or ipv6): if not (ipv4 or ipv6):
to_print.append(f"\t{mail_domain}.\t\t\tA<your server's IPv4 address>") to_print.append(f"\t{mail_domain}.\t\t\tA<your server's IPv4 address>")
if not mta_ip or not (mta_ip == ipv4 or mta_ip == ipv6): if not mta_ip or not (mta_ip == ipv4 or mta_ip == ipv6):
#print(mta_entry, mta_ip)
#print(ipv4, ipv6)
to_print.append(f"\tmta-sts.{mail_domain}.\tCNAME\t{mail_domain}.") to_print.append(f"\tmta-sts.{mail_domain}.\tCNAME\t{mail_domain}.")
if to_print: if to_print:
to_print.insert( to_print.insert(