This commit is contained in:
Adora Laura Kalb 2023-04-01 18:03:44 +02:00
parent cb91ce468f
commit 3aee8712e5
Signed by: adoralaura
GPG key ID: 7A4552166FC8C056
2 changed files with 5 additions and 5 deletions

View file

@ -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'))

View file

@ -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):