2023-03-31 10:42:21 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from findzone import *
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
record = sys.argv[1].strip()
|
|
|
|
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)
|
|
|
|
|
|
|
|
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}")
|
2023-04-01 18:03:44 +02:00
|
|
|
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'))
|