#!/usr/bin/env python3 import json import re import urllib.error import urllib.request import paramiko PASS = "Bbt9115xty9176!" ACCOUNT = "2599c23bbb1255dbb73e8d34b4115fda" TUNNEL = "03079a26-f14c-4622-b463-ba54a24f7472" CF = "https://api.cloudflare.com/client/v4" tokens = {} 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() tokens["pfsense"] = re.search(r"CLOUDFLARE_API_TOKEN=([^\s\"']+)", text).group(1) c.close() c2 = paramiko.SSHClient() c2.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c2.connect("10.10.0.10", username="localadministrator", password=PASS, timeout=30) for path in [ "/home/localadministrator/coder/onsethost/.env.local", "/etc/infra/mail-watchdog.env", "/etc/infra/secrets.env", ]: _, o, e = c2.exec_command( f"echo '{PASS}' | sudo -S grep -h CLOUDFLARE_API_TOKEN {path} 2>/dev/null | head -1", timeout=20, ) o.channel.recv_exit_status() line = (o.read() + e.read()).decode().strip() if "CLOUDFLARE_API_TOKEN=" in line: tokens[path] = line.split("=", 1)[1].strip().strip('"') c2.close() tokens["hardcoded_mail"] = "cfut_zlUt5lAKVsu7qIcRCHJnyhAvpJVF5jx24HlrIEn9a8fcd6a1" def probe(label, tok): results = {} for name, path, method in [ ("zone_list", "/zones?per_page=1", "GET"), ("zone_create", "/zones", "POST"), ("tunnel_cfg", f"/accounts/{ACCOUNT}/cfd_tunnel/{TUNNEL}/configurations", "GET"), ]: body = None if name == "zone_create": body = {"name": "exposedgays.com", "account": {"id": ACCOUNT}, "type": "full"} req = urllib.request.Request( CF + path, data=json.dumps(body).encode() if body else None, method=method if name != "zone_list" else "GET", headers={"Authorization": f"Bearer {tok}", "Content-Type": "application/json"}, ) try: with urllib.request.urlopen(req, timeout=30) as r: data = json.load(r) results[name] = ("OK", data.get("success"), len(data.get("result") or [])) except urllib.error.HTTPError as e: err = json.loads(e.read().decode()) results[name] = (e.code, err.get("errors", [{}])[0].get("message", "")[:80]) print(label, results) for label, tok in tokens.items(): if tok: probe(label, tok)