douyinWEB/scripts/_diag_neko3_tm3.py
2026-09-13 22:10:49 -05:00

125 lines
3.7 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
SCRIPT = r"""#!/bin/bash
set +e
N=douyinweb-neko-3
echo === children of browser-launch ===
docker exec "$N" python3 - <<'PY'
import os, json, urllib.request
# find all chrome-related cmdlines
for pid in sorted(os.listdir("/proc"), key=lambda x: int(x) if x.isdigit() else 0):
if not pid.isdigit():
continue
try:
raw = open(f"/proc/{pid}/cmdline", "rb").read()
except Exception:
continue
if not raw:
continue
cmd = raw.replace(b"\0", b" ").decode("utf-8", "replace")
if "chrome" not in cmd.lower() and "browser-launch" not in cmd:
continue
if "--type=" in cmd:
continue
print("--- PID", pid, "ppid", open(f"/proc/{pid}/status").read().split("PPid:")[1].split()[0])
print(cmd[:500])
if "load-extension" in cmd:
for part in raw.split(b"\0"):
if b"load-extension" in part or b"user-data" in part:
print(" FLAG", part.decode())
PY
echo === CDP tabs/sw ===
docker exec "$N" python3 - <<'PY'
import json, urllib.request
try:
tabs = json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=5).read())
except Exception as e:
print("cdp_err", e)
tabs = []
print("tabs", len(tabs))
for t in tabs:
print(t.get("type"), (t.get("title") or "")[:40], (t.get("url") or "")[:120])
PY
echo === simulate extension_flags logic ===
docker exec "$N" sh - <<'SH'
set -eu
family=google-chrome
profile_dir=/home/neko/.config/google-chrome
NEKO_LIVE_OPS_EXTENSION=1
NEKO_LIVE_OPS_EXTENSION_DIR=/etc/neko/live-ops-extension
NEKO_TAMPERMONKEY_SEED_DIR=/etc/neko/tampermonkey-seed
extension_flags=""
case "${NEKO_LIVE_OPS_EXTENSION:-1}" in
0|false|FALSE|off|OFF|disable|disabled) ;;
*)
live_ops_extension_dir="${NEKO_LIVE_OPS_EXTENSION_DIR:-/etc/neko/live-ops-extension}"
if [ -f "$live_ops_extension_dir/manifest.json" ]; then
extension_flags="--load-extension=${live_ops_extension_dir}"
fi
;;
esac
tm_ext_id="dhdgffkkebhmkfjojejmpbldmpobfkfo"
tm_load_dir=""
for candidate in \
"${NEKO_TAMPERMONKEY_SEED_DIR:-/etc/neko/tampermonkey-seed}/Default/Extensions/$tm_ext_id"/*/manifest.json \
"$profile_dir/Default/Extensions/$tm_ext_id"/*/manifest.json
do
echo "cand: $candidate exists=$( [ -f "$candidate" ] && echo y || echo n )"
if [ -f "$candidate" ]; then
tm_load_dir="$(dirname "$candidate")"
break
fi
done
echo "tm_load_dir=$tm_load_dir"
if [ -n "$tm_load_dir" ]; then
if [ -n "$extension_flags" ]; then
extension_flags="${extension_flags},${tm_load_dir}"
else
extension_flags="--load-extension=${tm_load_dir}"
fi
fi
echo "extension_flags=$extension_flags"
SH
echo === google-chrome.conf ===
docker exec "$N" cat /etc/neko/supervisord/google-chrome.conf 2>/dev/null || docker exec "$N" ls /etc/neko/supervisord/ /etc/supervisor/conf.d/ 2>&1
# find conf on host
cat /opt/douyinWEB/backend/neko/google-chrome.conf 2>/dev/null | head -40
"""
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
4014,
"eric",
"4669805",
timeout=45,
allow_agent=False,
look_for_keys=False,
banner_timeout=120,
)
sftp = c.open_sftp()
with sftp.file("/tmp/_diag_neko3_tm3.sh", "w") as f:
f.write(SCRIPT)
sftp.close()
_i, o, e = c.exec_command(
"echo '4669805' | sudo -S -p '' bash /tmp/_diag_neko3_tm3.sh",
timeout=90,
)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
if __name__ == "__main__":
main()