35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
import re
|
|
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 200 | grep 'Updated to new configuration' | tail -1",
|
|
timeout=30,
|
|
)
|
|
o.channel.recv_exit_status()
|
|
line = (o.read() + e.read()).decode()
|
|
start = line.find('config="')
|
|
if start == -1:
|
|
print("missing config=")
|
|
print(line[:500])
|
|
c.close()
|
|
raise SystemExit(1)
|
|
raw = line[start + len('config="'):]
|
|
# config value ends before final quote on line
|
|
raw = raw.rsplit('"', 1)[0]
|
|
raw = raw.encode().decode("unicode_escape")
|
|
cfg = json.loads(raw)
|
|
ingress = cfg.get("ingress", [])
|
|
print(f"total rules: {len(ingress)}")
|
|
for i in ingress:
|
|
h = i.get("hostname", "(catch-all)")
|
|
svc = i.get("service")
|
|
print(f" {h} -> {svc}")
|
|
if h and "exposed" in h:
|
|
print("FOUND")
|
|
c.close() |