#!/usr/bin/env python3 from findzone import * import sys import subprocess record = sys.argv[1].strip() ip = sys.argv[2].strip() zone = findzone(record) host = record.replace(zone, '').rstrip(".") reverseip_array = ip.split(".") reverserecord = f"{reverseip_array[3]}.{reverseip_array[2]}.{reverseip_array[1]}.{reverseip_array[0]}.in-addr.arpa" reversezone = findzone(reverserecord) reversehost = reverserecord.replace(reversezone, '').rstrip(".") if not zone: print(f"[ERROR] no suitable zone found for {record}") exit(1) if not reversezone: print(f"[ERROR] no suitable reverse zone found for {reverserecord}") exit(1) if zone == record: host = "@" print(f"+ pdnsutil add-record {zone} {host} A 3600 {ip}") print(subprocess.check_output(["ssh", "-q", str(os.environ.get('PDNS_PRIMARY_SSH')), "pdnsutil", "add-record", zone, host, "A", "3600", ip, "2>", "/dev/null"]).decode('utf-8')) print(f"+ pdnsutil add-record {reversezone} {reversehost} PTR 3600 {record}") print(subprocess.check_output(["ssh", "-q", str(os.environ.get('PDNS_PRIMARY_SSH')), "pdnsutil", "add-record", reversezone, reversehost, "PTR", "3600", record, "2>", "/dev/null"]).decode('utf-8')) # pdnsutil add-record ZONE NAME TYPE [ttl] content