2020-12-16 15:29:12 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import toml
|
2021-06-08 08:26:26 +08:00
|
|
|
|
2021-06-08 08:53:11 +08:00
|
|
|
from rfc2317 import gen_reverse_pointers, ZONE as RFC2317_ZONE
|
|
|
|
from roa import export_dnssec_dnskey
|
|
|
|
|
|
|
|
ZONE_FILE_MAP = {
|
|
|
|
'neo.': Path("dns", "neonetwork"),
|
|
|
|
'127.10.in-addr.arpa.': Path("dns", "db.10.127"),
|
|
|
|
'7.2.1.0.0.1.d.f.ip6.arpa.': Path("dns", "db.fd10.127")
|
|
|
|
}
|
2020-12-16 15:29:12 +08:00
|
|
|
RFC2317_FILE = Path("dns", "rfc2317.toml")
|
|
|
|
|
2021-06-08 08:26:26 +08:00
|
|
|
|
2020-12-16 15:29:12 +08:00
|
|
|
def iter_rfc2317_entry():
|
|
|
|
entries = toml.loads(RFC2317_FILE.read_text())
|
|
|
|
for (route, attributes) in entries.items():
|
2021-06-08 08:26:26 +08:00
|
|
|
ns = attributes.get("NS")
|
|
|
|
ds = attributes.get("DS", list())
|
|
|
|
ttl = attributes.get("TTL", -1)
|
|
|
|
yield (route, ns, ds, ttl)
|
|
|
|
|
2020-12-16 15:29:12 +08:00
|
|
|
|
|
|
|
def main():
|
2022-12-05 16:08:07 +08:00
|
|
|
DNSKEYS = {entry['zone']: entry['records'] for entry in export_dnssec_dnskey(include_zsk=True)}
|
2021-06-08 08:53:11 +08:00
|
|
|
for zone, zone_file in ZONE_FILE_MAP.items():
|
|
|
|
orignal = zone_file.read_text()
|
|
|
|
records = [orignal, "; AUTOGENERATED"]
|
|
|
|
if zone.strip('.') == RFC2317_ZONE.strip('.'):
|
|
|
|
records.extend(("", "; rfc2317"))
|
|
|
|
for route, ns, ds, ttl in iter_rfc2317_entry():
|
|
|
|
records.extend(gen_reverse_pointers(route, ns, ds, ttl))
|
|
|
|
records.append("")
|
|
|
|
records.extend(("", "; dnskey"))
|
2022-12-05 16:08:07 +08:00
|
|
|
for dnskey in DNSKEYS[zone]:
|
|
|
|
records.append(f"@ IN DNSKEY {dnskey['dnskey']}")
|
2020-12-16 15:29:12 +08:00
|
|
|
records.append("")
|
2021-06-08 08:53:11 +08:00
|
|
|
zone_file.write_text("\n".join(records))
|
2020-12-16 15:29:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|