#!/bin/sh # BroV network core — TUN diagnosis, about a minute without internet (run by hand): # sudo sh scripts/netcore/diag.sh # # A: the core with traffic capture on and a debug log, as is. # B: the same with the AmneziaVPN background service stopped (it stays up after the app # is closed and may own the routes / pf rules) — put back afterwards. # Then the core service comes back as it was (capture off). The report goes to # /tmp/brov-diag.txt (owner: you, 0600); the subscription URL is cut out of the logs. set -u [ "$(id -u)" -eq 0 ] || { echo "Запусти через sudo: sudo sh $0"; exit 1; } USER_NAME="${SUDO_USER:?запусти через sudo из своей учётной записи}" if pgrep -qx AmneziaVPN; then echo "Закрой приложение AmneziaVPN (⌘Q) и запусти снова."; exit 1; fi ROOT="/Library/Application Support/BroV" CORE="$ROOT/netcore" BIN="$ROOT/mihomo" LABEL="local.maksar.brov.netd" AMZ_PLIST="/Library/LaunchDaemons/AmneziaVPN.plist" OUT=/tmp/brov-diag.txt T=$(mktemp -d) : > "$OUT"; chmod 600 "$OUT"; chown "$USER_NAME" "$OUT" sec() { echo "→ $1"; printf '\n########## %s\n' "$1" >> "$OUT"; } run() { printf '\n$ %s\n' "$*" >> "$OUT"; "$@" >> "$OUT" 2>&1; } redact() { sed -E 's#https?://[^" ]*/sub/[^" ]*##g'; } snapshot() { run netstat -rn -f inet run sh -c 'ifconfig | grep -A2 "^utun"' run route -n get 1.1.1.1 run route -n get 198.18.0.2 run sh -c 'scutil --dns | grep -E "resolver|nameserver|if_index" | head -20' run sh -c 'curl -s -m 6 -o /dev/null -w "google %{http_code} %{time_total}s\n" https://www.google.com' run sh -c 'curl -s -m 6 -o /dev/null -w "ya.ru %{http_code} %{time_total}s\n" https://ya.ru' run sh -c 'curl -s -m 6 -o /dev/null -w "1.1.1.1 by IP %{http_code} %{time_total}s\n" https://1.1.1.1' run sh -c 'dig +time=2 +tries=1 example.com +short | head -2' } core_test() { # $1 = A|B "$BIN" -d "$CORE" -f "$T/diag.yaml" > "$T/$1.log" 2>&1 & pid=$! sleep 7 snapshot kill "$pid" 2>/dev/null; sleep 2; kill -9 "$pid" 2>/dev/null printf '\n--- core log %s (TUN, routes, errors) ---\n' "$1" >> "$OUT" grep -iE "tun|route|interface|listen|error|warn|fatal|hijack|stack" "$T/$1.log" \ | grep -v "Health Checked" | redact | head -120 >> "$OUT" } sec "Система" run sw_vers run "$BIN" -v run sh -c "pgrep -lf AmneziaVPN-service" run sh -c "pfctl -s info 2>&1 | head -3" run sh -c "pfctl -s Anchors 2>&1" run sh -c "pfctl -s rules 2>&1 | head -40" sec "До теста (ядро без перехвата)" snapshot # Test config: the real one with capture on and a debug log. /usr/bin/python3 - "$CORE/config.yaml" "$T/diag.yaml" <<'EOF' import sys s = open(sys.argv[1]).read() s = s.replace("tun:\n enable: false", "tun:\n enable: true") s = s.replace('log-level: "error"', 'log-level: "debug"') open(sys.argv[2], "w").write(s) EOF chmod 600 "$T/diag.yaml" launchctl bootout "system/$LABEL" 2>/dev/null sleep 1 sec "A: ядро с перехватом" core_test A if [ -f "$AMZ_PLIST" ]; then sec "B: то же, служба AmneziaVPN остановлена" launchctl bootout system "$AMZ_PLIST" 2>/dev/null sleep 2 run sh -c "pfctl -s Anchors 2>&1" run sh -c "pfctl -s rules 2>&1 | head -40" core_test B launchctl bootstrap system "$AMZ_PLIST" 2>/dev/null fi sec "Возвращаю ядро как было" launchctl bootstrap system "/Library/LaunchDaemons/$LABEL.plist" 2>/dev/null || launchctl kickstart -k "system/$LABEL" sleep 3 snapshot rm -rf "$T" echo "Готово. Отчёт: $OUT — напиши в чат, я его прочитаю."