commit 93b8fe22d37f969da6f8aaff78586a3d49b531a5 Author: BuildTools Date: Sun Nov 22 14:51:07 2026 +0100 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..78665f0 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# CF2PDNS + +Converts a Cloudflare DNS zone export (BIND format) into CSV for Poweradmin's **Bulk add records** form. + +## Usage + +``` +python3 cf2pa.py [more exports...] +``` + +The CSV is written to stdout and warnings go to stderr. Paste the output into +*Zone → Bulk add records* in Poweradmin. + +Output format: `name,type,content,prio,ttl` + +## What it does + +- Skips `SOA` and `NS` records (these come from your Poweradmin zone template) +- Strips Cloudflare `cf_tags` comments and trailing dots +- Converts TTL `1` (Cloudflare "Auto") to `3600` +- Moves the MX/SRV priority into the `prio` column +- Escapes TXT quotes for CSV (`"..."` → `"""..."""`), keeping multi-string TXT (e.g. DKIM) intact + +## Warnings (records not converted) + +- **Apex CNAME**: Cloudflare flattens it, but standard DNS doesn't allow it. Add an `A`/`AAAA` record manually. +- **PTR records named `*.arpa.`**: these have no effect inside a forward zone. Set reverse DNS with your IP provider. + +## Migration checklist + +1. Disable DNSSEC at Cloudflare first and wait at least a day for the DS record's TTL to expire. +2. Create the zone in Poweradmin as **Master** using the NS template. +3. Bulk-import the CSV and verify that the secondary has the zone: `dig +short SOA @` +4. Change the nameservers at the registrar. +5. Delete the Cloudflare zone a day later. diff --git a/cf2pdns.py b/cf2pdns.py new file mode 100644 index 0000000..5066f06 --- /dev/null +++ b/cf2pdns.py @@ -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]} [...]") + +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)