Files
exposedgays/deploy/_cf_dns_both.py

38 lines
1.4 KiB
Python

#!/usr/bin/env python3
import json
import re
import urllib.request
import paramiko
PASS = "Bbt9115xty9176!"
CF = "https://api.cloudflare.com/client/v4"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("10.10.0.1", username="admin", password=PASS, timeout=15)
_, o, e = c.exec_command("cat /usr/local/etc/wan-dns-failover.env", timeout=30)
o.channel.recv_exit_status()
TOK = re.search(r"CLOUDFLARE_API_TOKEN=([^\s\"']+)", (o.read() + e.read()).decode()).group(1)
c.close()
for domain in ["exposedgays.com", "thepinkpulse.com"]:
req = urllib.request.Request(
f"{CF}/zones?name={domain}",
headers={"Authorization": f"Bearer {TOK}", "Content-Type": "application/json"},
)
with urllib.request.urlopen(req, timeout=30) as r:
zones = json.load(r)["result"]
if not zones:
print(domain, "NO ZONE")
continue
zid = zones[0]["id"]
req2 = urllib.request.Request(
f"{CF}/zones/{zid}/dns_records?per_page=100",
headers={"Authorization": f"Bearer {TOK}", "Content-Type": "application/json"},
)
with urllib.request.urlopen(req2, timeout=30) as r:
recs = json.load(r)["result"]
print(f"\n=== {domain} zone {zid} ===")
for rec in recs:
if rec["type"] in ("A", "CNAME", "AAAA") and "domainconnect" not in rec["name"]:
print(f" {rec['type']:5} {rec['name']:35} -> {rec['content']} proxied={rec.get('proxied')}")