47 lines
1.7 KiB
Python
47 lines
1.7 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"
|
|
TUNNEL = "03079a26-f14c-4622-b463-ba54a24f7472"
|
|
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 r.status, json.load(r)
|
|
except urllib.error.HTTPError as e:
|
|
return e.code, json.loads(e.read().decode())
|
|
|
|
|
|
endpoints = [
|
|
("GET", f"/accounts/{ACCOUNT}/cfd_tunnel/{TUNNEL}/configurations"),
|
|
("GET", f"/accounts/{ACCOUNT}/cfd_tunnel/{TUNNEL}"),
|
|
("GET", f"/accounts/{ACCOUNT}/cfd_tunnel"),
|
|
("POST", f"/accounts/{ACCOUNT}/cfd_tunnel/{TUNNEL}/routes", {"network": "0.0.0.0/0", "comment": "test"}),
|
|
("POST", f"/accounts/{ACCOUNT}/cfd_tunnel/{TUNNEL}/connections", {}),
|
|
]
|
|
for method, path, *body in [(e[0], e[1], e[2] if len(e) > 2 else None) for e in endpoints]:
|
|
code, res = call(path, method, body[0] if body else None)
|
|
print(f"{method} {path}")
|
|
print(f" code={code} success={res.get('success')} errors={res.get('errors')}") |