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) zone = findzone(record)
host = record.replace(zone, '').rstrip(".") host = record.replace(zone, '').rstrip(".")
if not zone: if not zone:
print(f"[ERROR] no suitable zone found for {record}") print(f"[ERROR] no suitable zone found for {record}")
exit(1) exit(1)
@ -20,6 +18,7 @@ if zone == record:
print(f"[ERROR] CNAME can't be at the root of zone {zone}") print(f"[ERROR] CNAME can't be at the root of zone {zone}")
exit(1) exit(1)
print(f"+ pdnsutil add-record {zone} {host} CNAME 3600 {target}") 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 subprocess
import os import os
def findzone(record : str) -> str: def findzone(record : str) -> str:
"""Suggest best matching zone from existing zone """Suggest best matching zone from existing zone
Proposal is done on longer zone names matching the record suffix. Proposal is done on longer zone names matching the record suffix.
@ -18,7 +19,7 @@ def findzone(record : str) -> str:
best_match = None best_match = None
for zone in pdnsdomains: for zone in pdnsdomains:
if record.endswith(zone): if record.endswith(f".{zone}"):
if not best_match: if not best_match:
best_match = zone best_match = zone
if best_match and len(zone) > len(best_match): if best_match and len(zone) > len(best_match):