Files
exposedgays/deploy/try-cf-graphql.py

40 lines
1.1 KiB
Python

#!/usr/bin/env python3
import json, re, urllib.request, paramiko
PASS = "Bbt9115xty9176!"
ACCOUNT = "2599c23bbb1255dbb73e8d34b4115fda"
TUNNEL = "03079a26-f14c-4622-b463-ba54a24f7472"
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()
query = """
query {
viewer {
accounts(filter: {accountTag: "%s"}) {
tunnels(filter: {uuid: "%s"}) {
id
name
config {
ingress {
hostname
service
}
}
}
}
}
}
""" % (ACCOUNT, TUNNEL)
req = urllib.request.Request(
"https://api.cloudflare.com/client/v4/graphql",
data=json.dumps({"query": query}).encode(),
method="POST",
headers={"Authorization": f"Bearer {TOK}", "Content-Type": "application/json"},
)
with urllib.request.urlopen(req, timeout=30) as r:
print(json.dumps(json.load(r), indent=2)[:5000])