init
This commit is contained in:
commit
93b8fe22d3
2 files changed
+84
No files matched your search
+49
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
# CF2PDNS: Cloudflare zone export -> Poweradmin bulk CSV (name,type,content,prio,ttl)
|
||||
import sys, re
|
||||
|
||||
TTL = 3600 # replaces Cloudflare's TTL 1 ("Auto")
|
||||
SKIP = {"SOA", "NS"} # provided by the Poweradmin zone template
|
||||
|
||||
def conv(path):
|
||||
out, warn = [], []
|
||||
apex = None
|
||||
for line in open(path, encoding="utf-8"):
|
||||
line = line.rstrip("\n")
|
||||
if not line.strip() or line.lstrip().startswith(";"):
|
||||
continue
|
||||
line = re.sub(r"\s*;\s*cf_tags=.*$", "", line)
|
||||
p = line.split(None, 4)
|
||||
if len(p) < 5:
|
||||
continue
|
||||
name, ttl, _cls, typ, data = p
|
||||
name = name.rstrip(".")
|
||||
if typ == "SOA":
|
||||
apex = name
|
||||
if typ in SKIP:
|
||||
continue
|
||||
ttl = TTL if ttl == "1" else int(ttl)
|
||||
prio = 0
|
||||
if typ == "PTR" and ".arpa." in name + ".":
|
||||
warn.append(f"PTR skipped: {name}")
|
||||
continue
|
||||
if typ in ("MX", "SRV"):
|
||||
prio, data = data.split(None, 1)
|
||||
elif typ == "TXT":
|
||||
data = '"' + data.replace('"', '""') + '"'
|
||||
if typ in ("CNAME", "MX", "SRV", "PTR"):
|
||||
data = data.rstrip(".")
|
||||
if typ == "CNAME" and name == apex:
|
||||
warn.append(f"Apex CNAME {name} -> {data}: replace with A/AAAA")
|
||||
continue
|
||||
out.append(f"{name},{typ},{data},{prio},{ttl}")
|
||||
return out, warn
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit(f"usage: {sys.argv[0]} <export.txt> [...]")
|
||||
|
||||
for f in sys.argv[1:]:
|
||||
out, warn = conv(f)
|
||||
print("\n".join(out))
|
||||
for w in warn:
|
||||
print(f"# WARNING: {w}", file=sys.stderr)
|
||||
Reference in new issue
Block a user