102 lines
2.8 KiB
Python
102 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Check FRP S3 tunnel + seaweed public config (read-only)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def run(host, script):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(6):
|
|
try:
|
|
c.connect(host, 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=120)
|
|
break
|
|
except Exception as e:
|
|
print("retry", host, e, flush=True)
|
|
time.sleep(2)
|
|
else:
|
|
raise SystemExit(f"ssh fail {host}")
|
|
_i, o, e = c.exec_command(script, timeout=60)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
c.close()
|
|
return out
|
|
|
|
|
|
print("=== VPS FRP / s3.json ===", flush=True)
|
|
print(
|
|
run(
|
|
"107.173.30.245",
|
|
r"""
|
|
set +e
|
|
systemctl is-active dy-frp-http-aux.service frpp.service
|
|
systemctl status dy-frp-http-aux.service --no-pager -l 2>&1 | head -40
|
|
ss -lntp | grep -E '28333|18333|8333' | head
|
|
echo '--- s3.json (redact secrets) ---'
|
|
python3 - <<'PY'
|
|
import json
|
|
p='/etc/seaweedfs/s3.json'
|
|
d=json.load(open(p))
|
|
# redact
|
|
def scrub(x):
|
|
if isinstance(x, dict):
|
|
return {k:('***' if 'secret' in k.lower() or k.lower() in ('secretkey','secret_key') else scrub(v)) for k,v in x.items()}
|
|
if isinstance(x, list):
|
|
return [scrub(i) for i in x]
|
|
return x
|
|
print(json.dumps(scrub(d), indent=2)[:2500])
|
|
PY
|
|
""",
|
|
),
|
|
flush=True,
|
|
)
|
|
|
|
print("=== physical dy seaweed config ===", flush=True)
|
|
print(
|
|
run(
|
|
"108.174.50.68",
|
|
r"""
|
|
set +e
|
|
systemctl is-active douyinweb-s3.service
|
|
echo '--- douyinweb-s3.json scrubbed ---'
|
|
python3 - <<'PY'
|
|
import json
|
|
p='/etc/seaweedfs/douyinweb-s3.json'
|
|
d=json.load(open(p))
|
|
def scrub(x):
|
|
if isinstance(x, dict):
|
|
return {k:('***' if 'secret' in k.lower() or 'key'==k.lower() or k.lower().endswith('secretkey') else scrub(v)) for k,v in x.items()}
|
|
if isinstance(x, list):
|
|
return [scrub(i) for i in x]
|
|
return x
|
|
print(json.dumps(scrub(d), indent=2)[:3000])
|
|
PY
|
|
echo '--- identities (secrets redacted) ---'
|
|
python3 - <<'PY'
|
|
import json
|
|
d=json.load(open('/etc/seaweedfs/douyinweb-s3.json'))
|
|
for ident in d.get('identities') or []:
|
|
name=ident.get('name')
|
|
creds=ident.get('credentials') or []
|
|
for c in creds:
|
|
ak=(c.get('accessKey') or '')
|
|
sk=(c.get('secretKey') or '')
|
|
print('identity', name, 'ak', ak[:4]+'***' if ak else '', 'sk_len', len(sk))
|
|
for a in ident.get('actions') or []:
|
|
print(' action', a)
|
|
print('buckets', [b.get('name') for b in (d.get('buckets') or [])])
|
|
PY
|
|
# check frpc for 8333
|
|
grep -RniE '8333|28333|s3' /etc/frp* /opt/frp* /etc/frpp* 2>/dev/null | head -40
|
|
ps aux | grep -iE 'frpc|frp' | grep -v grep | head
|
|
""",
|
|
),
|
|
flush=True,
|
|
)
|
|
print("ALL_DONE", flush=True)
|