mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Improve the way we check DNS records to avoid false negative on TXT or MX
This commit is contained in:
parent
d16dab1c44
commit
ae82fe3693
1 changed files with 36 additions and 9 deletions
|
@ -52,14 +52,15 @@ class DNSRecordsDiagnoser(Diagnoser):
|
||||||
discrepancies = []
|
discrepancies = []
|
||||||
|
|
||||||
for r in records:
|
for r in records:
|
||||||
r["current"] = self.get_current_record(domain, r["name"], r["type"]) or "None"
|
r["current"] = self.get_current_record(domain, r["name"], r["type"])
|
||||||
if r["value"] == "@":
|
if r["value"] == "@":
|
||||||
r["value"] = domain + "."
|
r["value"] = domain + "."
|
||||||
|
|
||||||
if r["current"] == "None":
|
if not self.current_record_match_expected(r):
|
||||||
discrepancies.append(("diagnosis_dns_missing_record", r))
|
if r["current"] is None:
|
||||||
elif r["current"] != r["value"]:
|
discrepancies.append(("diagnosis_dns_missing_record", r))
|
||||||
discrepancies.append(("diagnosis_dns_discrepancy", r))
|
else:
|
||||||
|
discrepancies.append(("diagnosis_dns_discrepancy", r))
|
||||||
|
|
||||||
if discrepancies:
|
if discrepancies:
|
||||||
status = "ERROR" if (category == "basic" or (is_main_domain and category != "extra")) else "WARNING"
|
status = "ERROR" if (category == "basic" or (is_main_domain and category != "extra")) else "WARNING"
|
||||||
|
@ -85,10 +86,36 @@ class DNSRecordsDiagnoser(Diagnoser):
|
||||||
# FIXME : gotta handle case where this command fails ...
|
# FIXME : gotta handle case where this command fails ...
|
||||||
# e.g. no internet connectivity (dependency mechanism to good result from 'ip' diagosis ?)
|
# e.g. no internet connectivity (dependency mechanism to good result from 'ip' diagosis ?)
|
||||||
# or the resolver is unavailable for some reason
|
# or the resolver is unavailable for some reason
|
||||||
output = check_output(command).strip()
|
output = check_output(command).strip().split("\n")
|
||||||
if output.startswith('"') and output.endswith('"'):
|
if len(output) == 0 or not output[0]:
|
||||||
output = '"' + ' '.join(output.replace('"', ' ').split()) + '"'
|
return None
|
||||||
return output
|
elif len(output) == 1:
|
||||||
|
return output[0]
|
||||||
|
else:
|
||||||
|
return output
|
||||||
|
|
||||||
|
def current_record_match_expected(self, r):
|
||||||
|
if r["value"] is not None and r["current"] is None:
|
||||||
|
return False
|
||||||
|
if r["value"] is None and r["current"] is not None:
|
||||||
|
return False
|
||||||
|
elif isinstance(r["current"], list):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if r["type"] == "TXT":
|
||||||
|
# Split expected/current
|
||||||
|
# from "v=DKIM1; k=rsa; p=hugekey;"
|
||||||
|
# to a set like {'v=DKIM1', 'k=rsa', 'p=...'}
|
||||||
|
expected = set(r["value"].strip(' "').strip(";").replace(" ", "").split())
|
||||||
|
current = set(r["current"].strip(' "').strip(";").replace(" ", "").split())
|
||||||
|
return expected == current
|
||||||
|
elif r["type"] == "MX":
|
||||||
|
# For MX, we want to ignore the priority
|
||||||
|
expected = r["value"].split()[-1]
|
||||||
|
current = r["current"].split()[-1]
|
||||||
|
return expected == current
|
||||||
|
else:
|
||||||
|
return r["current"] == r["value"]
|
||||||
|
|
||||||
|
|
||||||
def main(args, env, loggers):
|
def main(args, env, loggers):
|
||||||
|
|
Loading…
Add table
Reference in a new issue