51 lines
1.6 KiB
Python
51 lines
1.6 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"
|
|
DOMAIN = "exposedgays.com"
|
|
|
|
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()
|
|
|
|
|
|
def call(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())
|
|
|
|
|
|
for path in ["/accounts", "/user", "/user/tokens/verify"]:
|
|
res = call(path)
|
|
print(path, json.dumps(res, indent=2)[:2000])
|
|
print()
|
|
|
|
accounts = call("/accounts").get("result", [])
|
|
for acct in accounts:
|
|
aid = acct["id"]
|
|
print(f"Trying account {acct.get('name')} {aid}")
|
|
for body in [
|
|
{"name": DOMAIN, "account": {"id": aid}, "type": "full"},
|
|
{"name": DOMAIN, "type": "full"},
|
|
]:
|
|
res = call("/zones", "POST", body)
|
|
print(" ", body, "->", res.get("success"), res.get("errors"))
|
|
if res.get("success"):
|
|
print(" NS:", res["result"].get("name_servers")) |