nomadro/apps/admin/deploy/_diag_config_sources.py
eric 0e85d71386 Add Douyin BMI audit homepage with remote A/B switch.
Ship a health-management BMI home for review, keep the nomad hub as hub, and let admin switch platforms.tt.homeVariant live with track/ntfy; fix tt config fetch to api.nomadro.cn/api/config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-03 02:32:26 -05:00

68 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""Diagnose config source mismatch: admin PUT vs public /api/config."""
from __future__ import annotations
import json
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
CMD = r"""
set -e
echo '=== remote-config.json tt ==='
python3 - <<'PY'
import json
from pathlib import Path
for p in [
Path('/var/www/nomadro.cn/data/remote-config.json'),
Path('/opt/nomadmini/backend/data/tt-platform-config.json'),
Path('/opt/nomadmini/data/tt-platform-config.json'),
]:
print('---', p, 'exists', p.exists())
if not p.exists():
continue
try:
d=json.loads(p.read_text(encoding='utf-8'))
except Exception as e:
print('read err', e); continue
tt=(d.get('platforms') or {}).get('tt') if 'platforms' in d else d
if not isinstance(tt, dict):
tt={}
mods=tt.get('modules') or {}
print('homeVariant', tt.get('homeVariant'))
print('mods', {k:(v or {}).get('enabled') for k,v in mods.items()})
print('mtime', p.stat().st_mtime)
PY
echo '=== who serves api.nomadro.cn/api/config ==='
curl -sk https://api.nomadro.cn/api/config | python3 -c 'import sys,json; d=json.load(sys.stdin); print("source", d.get("source")); tt=((d.get("config") or {}).get("platforms") or {}).get("tt") or {}); print("hv", tt.get("homeVariant")); print("mods", {k:(v or {}).get("enabled") for k,v in (tt.get("modules") or {}).items()})'
echo '=== nginx hint ==='
sudo grep -R "api.nomadro.cn\|/api/config" /www/server/panel/vhost/nginx/ /etc/nginx/ 2>/dev/null | head -30 || true
"""
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False)
_, stdout, _ = c.exec_command(CMD, timeout=90, get_pty=True)
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
time.sleep(0.05)
while stdout.channel.recv_ready():
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
code = stdout.channel.recv_exit_status()
c.close()
return code
if __name__ == "__main__":
raise SystemExit(main())