79 lines
2.5 KiB
Python
79 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""CDP probe: Tampermonkey tabs / Studio console / script markers on ops-neko 1+2."""
|
|
import json
|
|
import sys
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
CMD = r"""
|
|
echo 4669805 | sudo -S -p '' bash -lc '
|
|
for i in 1 2; do
|
|
echo "===== OPS$i CDP ====="
|
|
docker exec douyinweb-ops-neko-$i python3 - <<'"'"'PY'"'"'
|
|
import json, urllib.request
|
|
def get(url, timeout=4):
|
|
with urllib.request.urlopen(url, timeout=timeout) as r:
|
|
return r.read().decode("utf-8", "replace")
|
|
try:
|
|
tabs = json.loads(get("http://127.0.0.1:9222/json/list"))
|
|
except Exception as e:
|
|
print("cdp_fail", e)
|
|
raise SystemExit(0)
|
|
print("tabs", len(tabs))
|
|
for t in tabs:
|
|
u = t.get("url") or ""
|
|
title = (t.get("title") or "")[:60]
|
|
print("-", title, "|", u[:120])
|
|
# Find studio or TM dashboard
|
|
junk = 0
|
|
for t in tabs:
|
|
u = (t.get("url") or "").lower()
|
|
if "tampermonkey.net/changelog" in u or "tampermonkey.net/installed" in u:
|
|
junk += 1
|
|
tid = t.get("id")
|
|
if tid:
|
|
try:
|
|
urllib.request.urlopen(f"http://127.0.0.1:9222/json/close/{tid}", timeout=3)
|
|
except Exception:
|
|
pass
|
|
print("closed_junk", junk)
|
|
# Evaluate on Studio tab if any
|
|
studio = None
|
|
for t in tabs:
|
|
u = t.get("url") or ""
|
|
if "studio.youtube.com" in u and t.get("webSocketDebuggerUrl"):
|
|
studio = t
|
|
break
|
|
if not studio:
|
|
print("no_studio_tab")
|
|
raise SystemExit(0)
|
|
ws = studio.get("webSocketDebuggerUrl")
|
|
print("studio", (studio.get("url") or "")[:100])
|
|
# Use HTTP /json/runtime/evaluate is not available; use websocket via simple HTTP endpoint if exists
|
|
# Fallback: chrome remote via /json/activate + print marker via Runtime — need websocket.
|
|
# Instead dump LES keys for enabled scripts.
|
|
import os, subprocess, re
|
|
p = "/home/neko/.config/google-chrome/Default/Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo"
|
|
out = subprocess.check_output(["bash","-lc", f"strings {p}/* 2>/dev/null | grep -E \"YouTube Studio|@version|enabled|error|internal\" | head -40"], text=True, errors="replace")
|
|
print("--- LES strings ---")
|
|
print(out)
|
|
PY
|
|
done
|
|
'
|
|
"""
|
|
|
|
|
|
def main() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
_i, o, e = c.exec_command(CMD, timeout=120)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|