76 lines
3.0 KiB
Python
76 lines
3.0 KiB
Python
import urllib.request
|
|
import json
|
|
|
|
token = "cfut_ojehRrsoofCtvtsb8XUWrjJjTY6VvbCYtxm3yrIp5d8f2f14"
|
|
headers = {
|
|
"Authorization": f"Bearer {token}",
|
|
"Content-Type": "application/json"
|
|
}
|
|
|
|
def get(url):
|
|
req = urllib.request.Request(url, headers=headers)
|
|
with urllib.request.urlopen(req) as resp:
|
|
return json.loads(resp.read().decode("utf-8"))
|
|
|
|
print("--- 1. VERIFYING TOKEN ---")
|
|
try:
|
|
v = get("https://api.cloudflare.com/client/v4/user/tokens/verify")
|
|
print("Token Verify Response:", json.dumps(v, indent=2))
|
|
except Exception as e:
|
|
print("Token Verify Error:", e)
|
|
|
|
print("\n--- 2. ACCOUNTS & TUNNELS ---")
|
|
try:
|
|
accs = get("https://api.cloudflare.com/client/v4/accounts")
|
|
for a in accs.get("result", []):
|
|
aid = a.get("id")
|
|
aname = a.get("name")
|
|
print(f"\nAccount: {aname} ({aid})")
|
|
|
|
# Tunnels
|
|
try:
|
|
tunnels = get(f"https://api.cloudflare.com/client/v4/accounts/{aid}/tunnels")
|
|
for t in tunnels.get("result", []):
|
|
tid = t.get("id")
|
|
tname = t.get("name")
|
|
tstatus = t.get("status")
|
|
print(f" Tunnel: {tname} ({tid}) - Status: {tstatus}")
|
|
# Tunnel Config
|
|
try:
|
|
cfg = get(f"https://api.cloudflare.com/client/v4/accounts/{aid}/tunnels/{tid}/configurations")
|
|
print(" Tunnel Config Ingress:")
|
|
for ing in cfg.get("result", {}).get("config", {}).get("ingress", []):
|
|
print(" -", ing)
|
|
except Exception as ex:
|
|
print(" Config fetch error:", ex)
|
|
for c in t.get("connections", []):
|
|
print(f" Connection Edge: {c.get('colo_name')} | Status: active | IP: {c.get('origin_ip')}")
|
|
except Exception as ex:
|
|
print(" Tunnel fetch error:", ex)
|
|
|
|
# Access Apps
|
|
try:
|
|
apps = get(f"https://api.cloudflare.com/client/v4/accounts/{aid}/access/apps")
|
|
print(f"\n Access Applications for {aname}:")
|
|
for app in apps.get("result", []):
|
|
appid = app.get("id")
|
|
appname = app.get("name")
|
|
appdomain = app.get("domain")
|
|
print(f" App: {appname} -> {appdomain} ({appid})")
|
|
# App policies
|
|
try:
|
|
pols = get(f"https://api.cloudflare.com/client/v4/accounts/{aid}/access/apps/{appid}/policies")
|
|
for p in pols.get("result", []):
|
|
pname = p.get("name")
|
|
pact = p.get("decision")
|
|
pinc = p.get("include")
|
|
print(f" Policy: [{pact.upper()}] {pname} -> Include: {pinc}")
|
|
except Exception as pex:
|
|
print(" Policy fetch error:", pex)
|
|
except Exception as aex:
|
|
print(" Access Apps fetch error:", aex)
|
|
|
|
except Exception as e:
|
|
print("Accounts Error:", e)
|
|
|