Files
exposedgays/deploy/cf-zone-probe.py

90 lines
3.0 KiB
Python

#!/usr/bin/env python3
import json
import re
import urllib.error
import urllib.request
import paramiko
PASS = "Bbt9115xty9176!"
CF = "https://api.cloudflare.com/client/v4"
ACCOUNT = "2599c23bbb1255dbb73e8d34b4115fda"
DOMAIN = "exposedgays.com"
def get_tokens():
tokens = []
try:
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()
m = re.search(r"CLOUDFLARE_API_TOKEN=([^\s\"']+)", text)
if m:
tokens.append(("pfsense", m.group(1)))
except Exception as ex:
print("pfsense err", ex)
try:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("10.10.0.10", username="localadministrator", password=PASS, timeout=30)
for path in [
"/home/localadministrator/coder/onsethost/.env.local",
"/etc/infra/secrets.env",
"/root/.env",
]:
_, o, e = c.exec_command(
f"grep CLOUDFLARE_API_TOKEN {path} 2>/dev/null | head -1", timeout=20
)
o.channel.recv_exit_status()
line = (o.read() + e.read()).decode().strip()
if line and "=" in line:
tokens.append((path, line.split("=", 1)[1].strip().strip('"')))
c.close()
except Exception as ex:
print("coolify err", ex)
tokens += [
("apply_mail", "cfut_zlUt5lAKVsu7qIcRCHJnyhAvpJVF5jx24HlrIEn9a8fcd6a1"),
("onsethost", "cfut_IOm1DJW4pDkPCuQA6UoOjqO6Tcv2zU10y2PSw82m379f7db3"),
]
return tokens
def call(tok, 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 {tok}", "Content-Type": "application/json"},
)
try:
with urllib.request.urlopen(req, timeout=45) as r:
return json.load(r)
except urllib.error.HTTPError as e:
return json.loads(e.read().decode())
def main():
for label, tok in get_tokens():
v = call(tok, "/user/tokens/verify")
print(f"[{label}] verify:", v.get("success"), v.get("errors"))
z = call(tok, f"/zones?name={DOMAIN}")
print(f"[{label}] zone:", z.get("success"), len(z.get("result") or []), z.get("errors"))
c = call(
tok,
"/zones",
"POST",
{"name": DOMAIN, "account": {"id": ACCOUNT}, "type": "full", "jump_start": False},
)
print(f"[{label}] create:", c.get("success"), c.get("errors"))
if c.get("success"):
print(" NS:", c["result"].get("name_servers"))
print(" status:", c["result"].get("status"))
if __name__ == "__main__":
main()