mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2024-11-23 02:27:05 +00:00
Add dns time out handling changes
This commit is contained in:
parent
8d8d6e158b
commit
ecbb210058
@ -1030,17 +1030,29 @@ def set_secondary_dns(hostnames, env):
|
|||||||
resolver = dns.resolver.get_default_resolver()
|
resolver = dns.resolver.get_default_resolver()
|
||||||
resolver.timeout = 5
|
resolver.timeout = 5
|
||||||
resolver.lifetime = 5
|
resolver.lifetime = 5
|
||||||
|
|
||||||
for item in hostnames:
|
for item in hostnames:
|
||||||
if not item.startswith("xfr:"):
|
if not item.startswith("xfr:"):
|
||||||
# Resolve hostname.
|
# Resolve hostname.
|
||||||
try:
|
tries = 2
|
||||||
response = resolver.resolve(item, "A")
|
|
||||||
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout):
|
while tries > 0:
|
||||||
|
tries = tries - 1
|
||||||
try:
|
try:
|
||||||
response = resolver.resolve(item, "AAAA")
|
response = resolver.resolve(item, "A")
|
||||||
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout):
|
tries = 0
|
||||||
raise ValueError("Could not resolve the IP address of %s." % item)
|
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||||
|
try:
|
||||||
|
response = resolver.resolve(item, "AAAA")
|
||||||
|
tries = 0
|
||||||
|
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||||
|
raise ValueError("Could not resolve the IP address of %s." % item)
|
||||||
|
except (dns.resolver.Timeout):
|
||||||
|
if tries < 1:
|
||||||
|
raise ValueError("Could not resolve the IP address of %s due to timeout." % item)
|
||||||
|
except (dns.resolver.Timeout):
|
||||||
|
if tries < 1:
|
||||||
|
raise ValueError("Could not resolve the IP address of %s due to timeout." % item)
|
||||||
else:
|
else:
|
||||||
# Validate IP address.
|
# Validate IP address.
|
||||||
try:
|
try:
|
||||||
|
@ -303,7 +303,7 @@ def run_network_checks(env, output):
|
|||||||
# by a spammer, or the user may be deploying on a residential network. We
|
# by a spammer, or the user may be deploying on a residential network. We
|
||||||
# will not be able to reliably send mail in these cases.
|
# will not be able to reliably send mail in these cases.
|
||||||
rev_ip4 = ".".join(reversed(env['PUBLIC_IP'].split('.')))
|
rev_ip4 = ".".join(reversed(env['PUBLIC_IP'].split('.')))
|
||||||
zen = query_dns(rev_ip4+'.zen.spamhaus.org', 'A', nxdomain=None)
|
zen = query_dns(rev_ip4+'.zen.spamhaus.org', 'A', nxdomain=None, retry = False)
|
||||||
if zen is None:
|
if zen is None:
|
||||||
output.print_ok("IP address is not blacklisted by zen.spamhaus.org.")
|
output.print_ok("IP address is not blacklisted by zen.spamhaus.org.")
|
||||||
elif zen == "[timeout]":
|
elif zen == "[timeout]":
|
||||||
@ -739,7 +739,7 @@ def check_mail_domain(domain, env, output):
|
|||||||
# Stop if the domain is listed in the Spamhaus Domain Block List.
|
# Stop if the domain is listed in the Spamhaus Domain Block List.
|
||||||
# The user might have chosen a domain that was previously in use by a spammer
|
# The user might have chosen a domain that was previously in use by a spammer
|
||||||
# and will not be able to reliably send mail.
|
# and will not be able to reliably send mail.
|
||||||
dbl = query_dns(domain+'.dbl.spamhaus.org', "A", nxdomain=None)
|
dbl = query_dns(domain+'.dbl.spamhaus.org', "A", nxdomain=None, retry=False)
|
||||||
if dbl is None:
|
if dbl is None:
|
||||||
output.print_ok("Domain is not blacklisted by dbl.spamhaus.org.")
|
output.print_ok("Domain is not blacklisted by dbl.spamhaus.org.")
|
||||||
elif dbl == "[timeout]":
|
elif dbl == "[timeout]":
|
||||||
@ -775,7 +775,7 @@ def check_web_domain(domain, rounded_time, ssl_certificates, env, output):
|
|||||||
# website for also needs a signed certificate.
|
# website for also needs a signed certificate.
|
||||||
check_ssl_cert(domain, rounded_time, ssl_certificates, env, output)
|
check_ssl_cert(domain, rounded_time, ssl_certificates, env, output)
|
||||||
|
|
||||||
def query_dns(qname, rtype, nxdomain='[Not Set]', at=None, as_list=False):
|
def query_dns(qname, rtype, nxdomain='[Not Set]', at=None, as_list=False, retry=True):
|
||||||
# Make the qname absolute by appending a period. Without this, dns.resolver.query
|
# Make the qname absolute by appending a period. Without this, dns.resolver.query
|
||||||
# will fall back a failed lookup to a second query with this machine's hostname
|
# will fall back a failed lookup to a second query with this machine's hostname
|
||||||
# appended. This has been causing some false-positive Spamhaus reports. The
|
# appended. This has been causing some false-positive Spamhaus reports. The
|
||||||
@ -800,15 +800,25 @@ def query_dns(qname, rtype, nxdomain='[Not Set]', at=None, as_list=False):
|
|||||||
# lifetime expires a dns.exception.Timeout exception will be raised.
|
# lifetime expires a dns.exception.Timeout exception will be raised.
|
||||||
resolver.lifetime = 5
|
resolver.lifetime = 5
|
||||||
|
|
||||||
|
if retry:
|
||||||
|
tries = 2
|
||||||
|
else:
|
||||||
|
tries = 1
|
||||||
|
|
||||||
# Do the query.
|
# Do the query.
|
||||||
try:
|
while tries > 0:
|
||||||
response = resolver.resolve(qname, rtype)
|
tries = tries - 1
|
||||||
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
try:
|
||||||
# Host did not have an answer for this query; not sure what the
|
response = resolver.resolve(qname, rtype, search=True)
|
||||||
# difference is between the two exceptions.
|
tries = 0
|
||||||
return nxdomain
|
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||||
except dns.exception.Timeout:
|
# Host did not have an answer for this query; not sure what the
|
||||||
return "[timeout]"
|
# difference is between the two exceptions.
|
||||||
|
if tries < 1:
|
||||||
|
return nxdomain
|
||||||
|
except dns.exception.Timeout:
|
||||||
|
if tries < 1:
|
||||||
|
return "[timeout]"
|
||||||
|
|
||||||
# Normalize IP addresses. IP address --- especially IPv6 addresses --- can
|
# Normalize IP addresses. IP address --- especially IPv6 addresses --- can
|
||||||
# be expressed in equivalent string forms. Canonicalize the form before
|
# be expressed in equivalent string forms. Canonicalize the form before
|
||||||
|
Loading…
Reference in New Issue
Block a user