53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
#!/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"
|
|
|
|
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()
|
|
|
|
paths = [
|
|
f"/accounts/{ACCOUNT}/cfd_tunnel",
|
|
f"/accounts/{ACCOUNT}/cfd_tunnel/{TUNNEL}",
|
|
f"/accounts/{ACCOUNT}/cfd_tunnel/{TUNNEL}/configurations",
|
|
f"/accounts/{ACCOUNT}/tunnels",
|
|
f"/accounts/{ACCOUNT}/tunnels/{TUNNEL}",
|
|
f"/accounts/{ACCOUNT}/tunnels/{TUNNEL}/configurations",
|
|
f"/accounts/{ACCOUNT}/access/apps",
|
|
f"/accounts/{ACCOUNT}/access/apps/policies",
|
|
f"/zones/b9e032992b315331c8b0571473fedc89/dns_records?name=exposedgays.com",
|
|
f"/accounts/{ACCOUNT}/teamnet/routes",
|
|
f"/accounts/{ACCOUNT}/teamnet/hostnames",
|
|
f"/accounts/{ACCOUNT}/teamnet/tunnels",
|
|
f"/accounts/{ACCOUNT}/teamnet/tunnels/{TUNNEL}/routes",
|
|
]
|
|
|
|
for path in paths:
|
|
req = urllib.request.Request(CF + path, headers={"Authorization": f"Bearer {TOK}", "Content-Type": "application/json"})
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=25) as r:
|
|
data = json.load(r)
|
|
result = data.get("result")
|
|
summary = ""
|
|
if isinstance(result, list):
|
|
summary = f"list[{len(result)}]"
|
|
if result and isinstance(result[0], dict):
|
|
summary += " keys=" + ",".join(list(result[0].keys())[:6])
|
|
elif isinstance(result, dict):
|
|
summary = "dict keys=" + ",".join(list(result.keys())[:8])
|
|
print(f"OK {path} -> {summary}")
|
|
except urllib.error.HTTPError as e:
|
|
body = e.read().decode()[:120]
|
|
print(f"ERR {e.code} {path} -> {body}") |