douyinWEB/scripts/_diag_frp_panel4.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

106 lines
3.3 KiB
Python

# -*- coding: utf-8 -*-
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REMOTE = r'''
set +e
TOKEN=$(curl -sS -X POST 'http://127.0.0.1:9000/api/v1/auth/login' \
-H 'Content-Type: application/json' \
-d '{"username":"hackrobot","password":"Xiao4669805@"}' | python3 -c "import sys,json; print(json.load(sys.stdin)['body']['token'])")
AUTH="Authorization: Bearer $TOKEN"
python3 - <<PY
import json, urllib.request
token = """$TOKEN"""
auth = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
def post(path, body):
req = urllib.request.Request(
f"http://127.0.0.1:9000{path}",
data=json.dumps(body).encode(),
headers=auth,
method="POST",
)
with urllib.request.urlopen(req, timeout=30) as r:
return json.loads(r.read().decode())
# try common pager shapes
shapes = [
{"page": 1, "page_size": 50},
{"page": 1, "pageSize": 50},
{"page": {"page": 1, "pageSize": 50}},
{"pager": {"page": 1, "pageSize": 50}},
{"page": 1, "size": 50},
]
for path in ["/api/v1/server/list", "/api/v1/client/list"]:
print("====", path)
for body in shapes:
try:
d = post(path, body)
except Exception as e:
print(" fail", body, e)
continue
print(" body", body, "->", d.get("code"), d.get("msg"))
if d.get("code") == 200:
print(json.dumps(d, ensure_ascii=False, indent=2)[:4000])
break
# status with various bodies
print("==== clientsstatus")
for body in [{}, {"client_ids": []}, {"ids": []}, {"page":1,"pageSize":50}]:
try:
d = post("/api/v1/platform/clientsstatus", body)
print(body, "->", d.get("code"), d.get("msg"), str(d.get("body"))[:500])
except Exception as e:
print(body, "err", e)
PY
echo
echo '=== sqlite client/server rows ==='
python3 - <<'PY'
import sqlite3, json
c=sqlite3.connect('/opt/frp-panel/data.db')
c.row_factory=sqlite3.Row
tables=[r[0] for r in c.execute("SELECT name FROM sqlite_master WHERE type='table'")]
print('tables', tables)
for t in tables:
cols=[x[1] for x in c.execute(f'PRAGMA table_info("{t}")')]
print(f'\n## {t} cols={cols}')
try:
rows=c.execute(f'SELECT * FROM "{t}" LIMIT 20').fetchall()
except Exception as e:
print(' err', e); continue
for r in rows:
d={k:r[k] for k in r.keys()}
# truncate long blobs
for k,v in list(d.items()):
if isinstance(v, (bytes, bytearray)):
d[k]=f'<bytes {len(v)}>'
elif isinstance(v, str) and len(v)>180:
d[k]=v[:180]+'...'
print(json.dumps(d, ensure_ascii=False, default=str)[:500])
PY
echo
echo '=== TLS error count 24h / scan IPs ==='
docker logs --since 24h frp-panel 2>&1 | grep -c 'TLS handshake error' || true
docker logs --since 24h frp-panel 2>&1 | grep 'TLS handshake error' | sed -E 's/.*from ([0-9.]+):.*/\1/' | sort | uniq -c | sort -rn | head -10
echo
echo '=== port 9001 exposure note ==='
ss -lntp | grep -E '9000|9001|7000|8999'
'''
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.172.77.34", 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
_, o, e = c.exec_command(REMOTE, timeout=180)
print(o.read().decode("utf-8", "replace"))
err = e.read().decode("utf-8", "replace")
if err.strip():
print("STDERR:", err[-1500:])
c.close()