simbiot-harness/scripts/portal_serving_probe.py

47 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Ищу в portal-репо: как отдаются sites/*, есть ли upload/write-эндпоинты, .gitignore."""
import json
import re
import sys
import urllib.request
GIT = "https://git.cil.by"
TOK = re.search(r":([a-f0-9]{40})@", open("/home/hermes/vybirai/.git/config", errors="ignore").read()).group(1)
REPO = "symbiot/portal"
def raw(path, br="main"):
req = urllib.request.Request(f"{GIT}/{REPO}/raw/branch/{br}/{path}",
headers={"Authorization": f"token {TOK}"})
with urllib.request.urlopen(req, timeout=15) as r:
return r.read().decode(errors="ignore")
def api(path):
req = urllib.request.Request(f"{GIT}/api/v1{path}", headers={"Authorization": f"token {TOK}"})
with urllib.request.urlopen(req, timeout=15) as r:
return json.loads(r.read())
# 1) .gitignore — не спрятан ли sites/simbiot
try:
print("== .gitignore ==")
print(raw(".gitignore"))
except Exception as e: # noqa: BLE001
print("no .gitignore:", e)
# 2) поиск "sites/" в коде — как отдаются
tree = api(f"/repos/{REPO}/git/trees/main?recursive=1")
py_files = [t["path"] for t in tree["tree"]
if t["path"].endswith((".py", ".md", ".sh", "Caddyfile", ".conf"))
and not t["path"].startswith(("sites/", "agent-"))]
print(f"== сканирую {len(py_files)} файлов на 'sites/' и upload ==")
for p in py_files:
try:
c = raw(p)
except Exception: # noqa: BLE001
continue
for i, line in enumerate(c.splitlines(), 1):
if re.search(r"sites/|send_from_directory\(.*sites|upload|write_file|open\(.*[\"']w", line) \
and "def " not in line and "import" not in line:
print(f"{p}:{i}: {line.strip()[:110]}")