diff --git a/powerdns/dns-cname-add b/powerdns/dns-cname-add index 5d97d71..7a8d6e6 100755 --- a/powerdns/dns-cname-add +++ b/powerdns/dns-cname-add @@ -10,8 +10,6 @@ target = sys.argv[2].strip() zone = findzone(record) host = record.replace(zone, '').rstrip(".") - - if not zone: print(f"[ERROR] no suitable zone found for {record}") exit(1) @@ -20,6 +18,7 @@ if zone == record: print(f"[ERROR] CNAME can't be at the root of zone {zone}") exit(1) - print(f"+ pdnsutil add-record {zone} {host} CNAME 3600 {target}") -print(subprocess.check_output(["ssh", "-q", str(os.environ.get('PDNS_PRIMARY_SSH')), "pdnsutil", "add-record", zone, host, "CNAME", "3600", target, "2>", "/dev/null"]).decode('utf-8')) +print(subprocess.check_output( + ["ssh", "-q", str(os.environ.get('PDNS_PRIMARY_SSH')), "pdnsutil", "add-record", zone, host, "CNAME", "3600", + target, "2>", "/dev/null"]).decode('utf-8')) diff --git a/powerdns/findzone.py b/powerdns/findzone.py index 2f71a59..c81a104 100755 --- a/powerdns/findzone.py +++ b/powerdns/findzone.py @@ -2,6 +2,7 @@ import subprocess import os + def findzone(record : str) -> str: """Suggest best matching zone from existing zone Proposal is done on longer zone names matching the record suffix. @@ -18,7 +19,7 @@ def findzone(record : str) -> str: best_match = None for zone in pdnsdomains: - if record.endswith(zone): + if record.endswith(f".{zone}"): if not best_match: best_match = zone if best_match and len(zone) > len(best_match):