25 lines
639 B
Python
Executable file
25 lines
639 B
Python
Executable file
#!/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}")
|
|
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'))
|