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()
|
||||
|
||||
public_suffix = psl.publicsuffix(domain)
|
||||
|
||||
# FIXME: wtf is this supposed to do ? :|
|
||||
if public_suffix in YNH_DYNDNS_DOMAINS:
|
||||
domain_prefix = domain_name[0:-(1 + len(public_suffix))]
|
||||
public_suffix = domain_prefix.plit(".")[-1] + "." + public_suffix
|
||||
domain_prefix = domain[0:-(1 + len(public_suffix))]
|
||||
public_suffix = domain_prefix.split(".")[-1] + "." + public_suffix
|
||||
|
||||
return public_suffix
|
||||
|
||||
|
@ -47,17 +49,28 @@ def get_dns_zone_from_domain(domain):
|
|||
domain -- The domain name
|
||||
|
||||
"""
|
||||
separator = "."
|
||||
domain_subs = domain.split(separator)
|
||||
for i in range(0, len(domain_subs)):
|
||||
current_domain = separator.join(domain_subs)
|
||||
answer = dig(current_domain, rdtype="NS", full_answers=True, resolvers="force_external")
|
||||
|
||||
# For foo.bar.baz.gni we want to scan all the parent domains
|
||||
# (including the domain itself)
|
||||
# foo.bar.baz.gni
|
||||
# bar.baz.gni
|
||||
# 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
|
||||
return current_domain
|
||||
if separator.join(domain_subs[1:]) == get_public_suffix(current_domain):
|
||||
# Couldn't check if domain is dns zone,
|
||||
return parent
|
||||
# Otherwise, check if the parent of this parent is in the public suffix list
|
||||
if parent.split(".", 1)[-1] == get_public_suffix(parent):
|
||||
# Couldn't check if domain is dns zone, # FIXME : why "couldn't" ...?
|
||||
# returning private suffix
|
||||
return current_domain
|
||||
domain_subs.pop(0)
|
||||
return parent
|
||||
|
||||
# FIXME: returning None will probably trigger bugs when this happens, code expects a domain string
|
||||
return None
|
Loading…
Add table
Reference in a new issue