import os, paramiko, json PW = os.environ["REMOTE_PASS"] NEW_PW = "Owner2026!" c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("207.57.129.228", port=19717, username="root", password=PW, timeout=15, allow_agent=False, look_for_keys=False) def run(cmd, t=60): si, so, se = c.exec_command(cmd, timeout=t) out = so.read().decode("utf-8", "replace") err = se.read().decode("utf-8", "replace") rc = so.channel.recv_exit_status() if out: print(out, end="") if err: print("[err]", err, end="", file=__import__("sys").stderr) return out # pull + 重建 api print("--- pull + 重建 api ---") run("cd /srv/news && sudo -u news git pull --rebase 2>&1 | tail -3") run('docker compose -f /srv/news/docker-compose.yml up -d --force-recreate --no-deps --build api', t=120) import time time.sleep(6) # 登录 print("\n--- 登录 ---") body = json.dumps({"username": "owner", "password": NEW_PW}) out = run(f"curl -s -X POST http://localhost/api/v1/auth/login -H 'Content-Type: application/json' -d '{body}'") data = json.loads(out) token = data.get("access_token") print(f" 登录 OK, token: {token[:30]}...") # 拉 articles print("\n--- /api/v1/articles ---") out = run(f"curl -s -H 'Authorization: Bearer {token}' 'http://localhost/api/v1/articles?limit=3'") try: ad = json.loads(out) print(f" 返回 {len(ad.get('items', []))} 条:") for a in ad.get("items", [])[:3]: print(f" [{a['translation_status']:8s}] {a['source']['name']:14s} | {a['title'][:50]}") if a.get("title_zh"): print(f" zh: {a['title_zh'][:50]}") except Exception as e: print(f" parse err: {e}\n raw: {out[:300]}") # /me print("\n--- /me ---") me = json.loads(run(f"curl -s -H 'Authorization: Bearer {token}' 'http://localhost/api/v1/me'")) print(f" {me}") # /me/usage print("\n--- /me/usage ---") u = json.loads(run(f"curl -s -H 'Authorization: Bearer {token}' 'http://localhost/api/v1/me/usage'")) print(f" {u}") # /sources print("\n--- /sources ---") sl = json.loads(run(f"curl -s -H 'Authorization: Bearer {token}' 'http://localhost/api/v1/sources'")) print(f" {len(sl)} 个源:") for s in sl: en = "✓" if s["enabled"] else "✗" print(f" {en} [{s['priority']:3d}] {s['slug']:18s} {s['name']}") c.close()