import paramiko

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('152.136.232.83', port=22, username='root', password='Jianhua105', timeout=10)

def run(cmd):
    print(f"\n>>> {cmd[:120]}")
    stdin, stdout, stderr = client.exec_command(cmd, timeout=15)
    out = stdout.read().decode('utf-8', errors='replace').strip()
    err = stderr.read().decode('utf-8', errors='replace').strip()
    if out: print(out[-800:])
    if err: print(f"ERR: {err[-200:]}")
    return out

# Check if our endpoint exists
run("grep -n 'system/config/public' /www/wwwroot/zhinengtiapp/index.js")

# Check what pm2 is running
run("pm2 list")

# Check the actual loaded file
run("pm2 show 0 2>/dev/null | grep 'script path'")

# Check the cosBucket value
run("node -e \"const fs=require('fs');const c=fs.readFileSync('/www/wwwroot/zhinengtiapp/data/sysConfig.json','utf8');console.log(c);\"")

# Check the .env file COS entries
run("grep COS_ /www/wwwroot/zhinengtiapp/.env")

client.close()
print("\n=== DONE ===")
