#!/usr/bin/env python3 import json, re, urllib.request, urllib.error, paramiko PASS = "Bbt9115xty9176!" CF = "https://api.cloudflare.com/client/v4" def get_pfsense_token(): 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() text = (o.read() + e.read()).decode() c.close() return re.search(r"CLOUDFLARE_API_TOKEN=([^\s\"']+)", text).group(1) def call(token, path, method="GET", body=None): req = urllib.request.Request( CF + path, data=json.dumps(body).encode() if body else None, method=method, headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"}, ) try: with urllib.request.urlopen(req, timeout=30) as r: return json.load(r) except urllib.error.HTTPError as e: return json.loads(e.read().decode()) tokens = { "pfsense": get_pfsense_token(), "apply_mail": "cfut_zlUt5lAKVsu7qIcRCHJnyhAvpJVF5jx24HlrIEn9a8fcd6a1", } for name, tok in tokens.items(): v = call(tok, "/user/tokens/verify") print(name, "verify:", v.get("success"), v.get("messages"), v.get("errors")) z = call(tok, "/zones?name=exposedgays.com") print(name, "zone:", z.get("success"), len(z.get("result") or []), z.get("errors")) c = call(tok, "/zones", "POST", {"name": "exposedgays.com", "account": {"id": "2599c23bbb1255dbb73e8d34b4115fda"}, "type": "full"}) print(name, "create:", c.get("success"), c.get("errors")) if c.get("success"): print(" nameservers:", c["result"].get("name_servers"))