mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Cleanup get_dns_zone_from_domain utils
This commit is contained in:
parent
2f3467dd17
commit
22aa1f2538
1 changed files with 29 additions and 16 deletions
|
@ -32,9 +32,11 @@ def get_public_suffix(domain):
|
||||||
psl = PublicSuffixList()
|
psl = PublicSuffixList()
|
||||||
|
|
||||||
public_suffix = psl.publicsuffix(domain)
|
public_suffix = psl.publicsuffix(domain)
|
||||||
|
|
||||||
|
# FIXME: wtf is this supposed to do ? :|
|
||||||
if public_suffix in YNH_DYNDNS_DOMAINS:
|
if public_suffix in YNH_DYNDNS_DOMAINS:
|
||||||
domain_prefix = domain_name[0:-(1 + len(public_suffix))]
|
domain_prefix = domain[0:-(1 + len(public_suffix))]
|
||||||
public_suffix = domain_prefix.plit(".")[-1] + "." + public_suffix
|
public_suffix = domain_prefix.split(".")[-1] + "." + public_suffix
|
||||||
|
|
||||||
return public_suffix
|
return public_suffix
|
||||||
|
|
||||||
|
@ -47,17 +49,28 @@ def get_dns_zone_from_domain(domain):
|
||||||
domain -- The domain name
|
domain -- The domain name
|
||||||
|
|
||||||
"""
|
"""
|
||||||
separator = "."
|
|
||||||
domain_subs = domain.split(separator)
|
# For foo.bar.baz.gni we want to scan all the parent domains
|
||||||
for i in range(0, len(domain_subs)):
|
# (including the domain itself)
|
||||||
current_domain = separator.join(domain_subs)
|
# foo.bar.baz.gni
|
||||||
answer = dig(current_domain, rdtype="NS", full_answers=True, resolvers="force_external")
|
# bar.baz.gni
|
||||||
if answer[0] == "ok" :
|
# baz.gni
|
||||||
|
# gni
|
||||||
|
parent_list = [domain.split(".", i)[-1]
|
||||||
|
for i, _ in enumerate(domain.split("."))]
|
||||||
|
|
||||||
|
for parent in parent_list:
|
||||||
|
|
||||||
|
# Check if there's a NS record for that domain
|
||||||
|
answer = dig(parent, rdtype="NS", full_answers=True, resolvers="force_external")
|
||||||
|
if answer[0] == "ok":
|
||||||
# Domain is dns_zone
|
# Domain is dns_zone
|
||||||
return current_domain
|
return parent
|
||||||
if separator.join(domain_subs[1:]) == get_public_suffix(current_domain):
|
# Otherwise, check if the parent of this parent is in the public suffix list
|
||||||
# Couldn't check if domain is dns zone,
|
if parent.split(".", 1)[-1] == get_public_suffix(parent):
|
||||||
|
# Couldn't check if domain is dns zone, # FIXME : why "couldn't" ...?
|
||||||
# returning private suffix
|
# returning private suffix
|
||||||
return current_domain
|
return parent
|
||||||
domain_subs.pop(0)
|
|
||||||
|
# FIXME: returning None will probably trigger bugs when this happens, code expects a domain string
|
||||||
return None
|
return None
|
Loading…
Add table
Reference in a new issue