fix DKIM cname check

This commit is contained in:
Son NK 2020-05-03 12:48:42 +02:00
parent 9991723f5e
commit 4ca6b02047
2 changed files with 4 additions and 3 deletions

View File

@ -74,7 +74,7 @@ def domain_detail_dns(custom_domain_id):
spf_errors = get_txt_record(custom_domain.domain)
elif request.form.get("form-name") == "check-dkim":
dkim_record = get_cname_record(custom_domain.domain)
dkim_record = get_cname_record("dkim._domainkey." + custom_domain.domain)
if dkim_record == dkim_cname:
flash("DKIM is setup correctly.", "success")
custom_domain.dkim_verified = True

View File

@ -13,14 +13,15 @@ def _get_dns_resolver():
def get_cname_record(hostname) -> Optional[str]:
"""Return the CNAME record if exists for a domain"""
"""Return the CNAME record if exists for a domain, WITHOUT the trailing period at the end"""
try:
answers = _get_dns_resolver().query(hostname, "CNAME")
except Exception:
return None
for a in answers:
return a
ret = a.to_text()
return ret[:-1]
return None