Files
exposedgays/deploy/_remote_ingress.py

40 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""Parse cloudflared journal for remote ingress hostnames."""
import json
import paramiko
PASS = "Bbt9115xty9176!"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("10.10.0.10", username="localadministrator", password=PASS, timeout=30)
_, o, e = c.exec_command(
"sudo journalctl -u cloudflared --no-pager -n 100 | grep 'Updated to new configuration' | tail -1",
timeout=30,
)
o.channel.recv_exit_status()
line = (o.read() + e.read()).decode()
idx = line.find('version=')
if idx == -1:
print("no config line found")
print(line[:500])
c.close()
raise SystemExit(1)
# extract JSON after version=N
import re
m = re.search(r"config=(\{.*\})", line)
if not m:
print("no json in line")
print(line[:1000])
c.close()
raise SystemExit(1)
cfg = json.loads(m.group(1))
ingress = cfg.get("ingress", [])
hosts = sorted(h for h in (i.get("hostname") for i in ingress) if h)
print(f"remote ingress hostnames: {len(hosts)}")
for h in hosts:
if any(x in (h or "") for x in ["exposed", "avbeat", "pink", "freerange", "onsethost"]):
print(" ", h)
print("...")
for target in ["exposedgays.com", "www.exposedgays.com", "avbeat.com", "thepinkpulse.com", "*.onsethost.com"]:
print(f"{target}: {target in hosts}")
c.close()