dns_zones: add "registry-sync" zone generator
This commit is contained in:
parent
2f4c8aa0ae
commit
a855c0aa04
1 changed files with 48 additions and 0 deletions
48
__main__.py
48
__main__.py
|
@ -229,11 +229,59 @@ class Registry(object):
|
|||
print(f"WARN: unknown ip version of '{ip}' for {server}")
|
||||
except ValueError:
|
||||
print(f"WARN: '{ip}' for {server} isn't a a valid ip address")
|
||||
|
||||
for ds in ds_rdata:
|
||||
records.append(f"{record_name}. {TTL} IN DS {ds}")
|
||||
|
||||
return records
|
||||
|
||||
def _build_registry_sync_zone(self, zone:str, TTL:int) -> [str]:
|
||||
# returns A/AAAA records for nservers of the form "$(reverse_ipv4).ipv4.${zone}" and "${reverse_ipv6}.ipv6.${zone}" as well as the records based on data/dns/${zone}
|
||||
|
||||
zone = zone[:-1] if zone.endswith(".") else zone
|
||||
|
||||
if not zone in self.index["dns"]:
|
||||
print(f"ERROR: object for dns/{zone} doesn't exist not generating a empty zone for it")
|
||||
return []
|
||||
|
||||
domain_data = self.index["dns"][zone]
|
||||
|
||||
records = self._build_records(zone, zone, TTL, domain_data["nserver"], domain_data["ds-rdata"] if "ds-rdata" in domain_data else [])
|
||||
|
||||
v4_domain = f".ipv4.{zone}"
|
||||
v6_domain = f".ipv6.{zone}"
|
||||
|
||||
joined = self.index["dns"] | self.index["inet6num"] | self.index["inetnum"]
|
||||
|
||||
for key in joined:
|
||||
|
||||
object_data = joined[key]
|
||||
|
||||
if not "nserver" in object_data:
|
||||
continue
|
||||
|
||||
for nserver in object_data["nserver"]:
|
||||
|
||||
nserver = nserver.split(" ", 1)
|
||||
if not nserver[0].endswith(zone):
|
||||
continue
|
||||
|
||||
elif not len(nserver) == 1:
|
||||
print(f"WARN: registry sync: {key} specifies ip address for a registry-sync address, ignoring that address")
|
||||
|
||||
|
||||
if nserver[0].endswith(v4_domain):
|
||||
records.append(f"{nserver[0]}. {TTL} IN A {'.'.join(nserver[0].replace(v4_domain, '').split('.')[::-1])}")
|
||||
elif nserver[0].endswith(v6_domain):
|
||||
_ip6 = nserver[0].replace(v6_domain, "").replace(".", "")[::-1]
|
||||
try:
|
||||
records.append(f"{nserver[0]}. {TTL} IN AAAA {ip_address(':'.join(a+b+c+d for a, b, c, d in zip(_ip6[::4], _ip6[1::4], _ip6[2::4], _ip6[3::4]))).compressed}")
|
||||
except ValueError:
|
||||
print(f"WARN: {nserver[0]} couldn't get parsed to ipv6 address, not adding it to the zone")
|
||||
else:
|
||||
print(f"WARN: unknown registry-sync prefix in {key} not parsing that hostname")
|
||||
return records
|
||||
|
||||
def _generate_forward_zone(self, zone:str, TTL:int) -> [str]:
|
||||
records = []
|
||||
zone = zone[:-1] if zone.endswith(".") else zone
|
||||
|
|
Loading…
Add table
Reference in a new issue