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

107 lines
3.8 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Diagnose Tampermonkey EXTENSION load errors on ops-neko 1/2."""
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 ====="
docker exec douyinweb-ops-neko-$i bash -lc "
P=/home/neko/.config/google-chrome/Default
EXT=dhdgffkkebhmkfjojejmpbldmpobfkfo
echo --- Preferences TM entry ---
python3 -c \"
import json
from pathlib import Path
ext='dhdgffkkebhmkfjojejmpbldmpobfkfo'
p=Path('/home/neko/.config/google-chrome/Default/Preferences')
d=json.loads(p.read_text()) if p.exists() else {}
e=((d.get('extensions') or {}).get('settings') or {}).get(ext) or {}
print('state', e.get('state'))
print('path', e.get('path'))
print('location', e.get('location'))
mf=e.get('manifest') if isinstance(e.get('manifest'), dict) else {}
print('manifest_ver', mf.get('version'))
print('disable_reasons', e.get('disable_reasons'))
print('from_webstore', e.get('from_webstore'))
print('blacklist', e.get('blacklist'))
print('keys', sorted(e.keys())[:40])
\"
echo --- Extension files ---
ls -la \"\$P/Extensions/\$EXT\" 2>/dev/null || echo NO_EXT_DIR
ls -la \"\$P/Extensions/\$EXT\"/*/ 2>/dev/null | head -30 || echo NO_VER
python3 -c \"
import json
from pathlib import Path
root=Path('/home/neko/.config/google-chrome/Default/Extensions/dhdgffkkebhmkfjojejmpbldmpobfkfo')
print('exists', root.exists())
for m in root.glob('*/manifest.json'):
d=json.load(open(m))
print('manifest', m.parent.name, 'mv', d.get('manifest_version'), 'ver', d.get('version'), 'name', d.get('name'))
# check required files
for rel in ['background.html','background.js','extension.js']:
p=m.parent/rel
print(' ', rel, 'ok' if p.exists() else 'MISSING', p.stat().st_size if p.exists() else 0)
\"
echo --- Secure Preferences ---
python3 -c \"
import json
from pathlib import Path
ext='dhdgffkkebhmkfjojejmpbldmpobfkfo'
p=Path('/home/neko/.config/google-chrome/Default/Secure Preferences')
print('exists', p.exists(), 'size', p.stat().st_size if p.exists() else 0)
if p.exists():
d=json.loads(p.read_text())
e=((d.get('extensions') or {}).get('settings') or {}).get(ext) or {}
print('secure_state', e.get('state'), 'path', e.get('path'), 'disable', e.get('disable_reasons'))
\"
echo --- chrome logs ---
for f in /var/log/neko/google-chrome.log /var/log/supervisor/google-chrome*.log /tmp/chrome*.log; do
[ -f \"\$f\" ] || continue
echo FILE \$f
grep -iE 'tamper|dhdgff|Failed to load|Manifest file is missing|Extension error|Could not load' \"\$f\" 2>/dev/null | tail -20
done
ls /var/log/neko/ 2>/dev/null
echo --- CDP ---
python3 -c \"
import json,urllib.request
try:
tabs=json.loads(urllib.request.urlopen('http://127.0.0.1:9222/json/list',timeout=4).read())
except Exception as e:
print('cdp_fail',e); raise SystemExit
print('tabs',len(tabs))
for t in tabs[:20]:
print('-',(t.get('title') or '')[:45],'|',(t.get('url') or '')[:110])
\"
"
done
echo ===== HOST SEED =====
ls /opt/douyinWEB/backend/neko/tampermonkey-seed/Default/Extensions/dhdgffkkebhmkfjojejmpbldmpobfkfo/
python3 -c "
import json
from pathlib import Path
m=next(Path('/opt/douyinWEB/backend/neko/tampermonkey-seed/Default/Extensions/dhdgffkkebhmkfjojejmpbldmpobfkfo').glob('*/manifest.json'))
d=json.load(open(m))
print(m)
print('mv',d.get('manifest_version'),'ver',d.get('version'))
"
'
"""
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()