Files
buryan-infra/ops/sso/domains-audit.sh
T
architect c985c0617b
lint / hygiene (push) Failing after 30s
lint / hygiene (pull_request) Failing after 21s
standard / check (push) Successful in 9s
standard / check (pull_request) Successful in 14s
[INFRA] migrate active old VPS 193.233.210.184 to 45.133.209.253
2026-12-02 18:00:21 +03:00

49 lines
2.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# ============================================================
# domains-vs-proxies.sh — у кого есть домен, а у кого только прокси
# ============================================================
set -uo pipefail
VPS=45.133.209.253
echo "=== 1. ДОМЕНЫ В NGINX (VPS) ==="
ssh -o BatchMode=yes -o ConnectTimeout=25 root@$VPS "grep -oE 'server_name [a-z0-9.-]+\.buryans\.ru' /etc/nginx/conf.d/buryans-all.conf | sed 's/server_name //' | sort" 2>/dev/null > /tmp/nginx-domains.txt
wc -l < /tmp/nginx-domains.txt | sed 's/^/ доменов: /'
sed 's/^/ /' /tmp/nginx-domains.txt
echo
echo "=== 2. ДОМЕНЫ, КУДА ВЕДУТ ПРОКСИ (из журнала сверки) ==="
awk 'NR>4 && NF>=4 {print $3}' /root/sso-reconcile.txt 2>/dev/null | sort -u > /tmp/proxy-domains.txt
sed 's/^/ /' /tmp/proxy-domains.txt
echo
echo "=== 3. ДОМЕНЫ ПРОКСИ, КОТОРЫХ НЕТ В NGINX (вход не заработает) ==="
comm -23 /tmp/proxy-domains.txt /tmp/nginx-domains.txt | sed 's/^/ ОТСУТСТВУЕТ: /'
echo
echo "=== 4. ПОРТЫ ПРОКСИ, НА КОТОРЫЕ НЕ ВЕДЁТ НИ ОДИН ДОМЕН ==="
ssh -o BatchMode=yes -o ConnectTimeout=25 root@$VPS "grep -oE 'proxy_pass http://192\.168\.1\.[0-9]+:(9[0-9]{3}|8[0-9]{3}|9977|998[0-9])' /etc/nginx/conf.d/buryans-all.conf | sed 's/.*://' | sort -u" 2>/dev/null > /tmp/nginx-proxyports.txt
for row in $(cat /root/sso-reconcile.txt 2>/dev/null | awk 'NR>4 && NF>=4 {print $2":"$1}'); do
ct=$(echo "$row" | cut -d: -f1)
svc=$(echo "$row" | cut -d: -f2)
# ищу порт прокси
port=$(pct exec $ct -- bash -c "docker inspect oauth2-proxy-$svc --format '{{range \$p,\$c := .HostConfig.PortBindings}}{{\$p}}{{end}}' 2>/dev/null" 2>/dev/null | tr -d '\r' | cut -d/ -f1)
if [ -n "$port" ] && ! grep -qx "$port" /tmp/nginx-proxyports.txt; then
echo " никто не ведёт на порт $port ($svc, CT $ct)"
fi
done
echo
echo "=== 5. ПРОВЕРКА КАЖДОГО ДОМЕНА (живой ответ) ==="
printf '%-30s %-6s %s\n' "ДОМЕН" "КОД" "ВХОД"
for d in $(cat /tmp/nginx-domains.txt); do
h=$(curl -s -o /dev/null -D - --max-time 8 -k "https://$d/" 2>/dev/null)
code=$(echo "$h" | head -1 | awk '{print $2}')
loc=$(echo "$h" | grep -i '^location:' | head -1)
v="—"
echo "$loc" | grep -q "authentik.buryans.ru/application" && v="ВХОД"
echo "$loc" | grep -qE "buryans\.ru" && ! echo "$loc" | grep -q authentik && v="перенаправление"
[ "$code" = "200" ] && v="открыт"
[ "$code" = "401" ] && v="свой пароль"
printf '%-30s %-6s %s\n' "$d" "${code:-—}" "$v"
done