From f7a719cc2c08df692ae2f9933df1c1880d644658 Mon Sep 17 00:00:00 2001 From: Sam Latsin Date: Fri, 9 Oct 2026 16:33:55 +0300 Subject: [PATCH] Fixed lan and ru-inside bugs --- router/bmstu-otp.sh | 22 +++++++++++++++++++++- router/bmstu.env.example | 2 +- templates/dns/10-base.yaml | 2 +- tools/test.sh | 2 +- web/index.html | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/router/bmstu-otp.sh b/router/bmstu-otp.sh index 7495b44..ff9ef7b 100755 --- a/router/bmstu-otp.sh +++ b/router/bmstu-otp.sh @@ -32,7 +32,15 @@ ENV_FILE="${ENV_FILE:-/etc/nikki/bmstu.env}" : "${GROUP_NAME:=BMSTU}" # API address/secret: from nikki's mixin settings unless set in the env file uci_get() { uci -q get "$1" 2>/dev/null; } -: "${API:=http://127.0.0.1:$(p=$(uci_get nikki.mixin.api_listen); echo "${p##*:}" | grep -E '^[0-9]+$' || echo 9090)}" +# api_listen is host:port; a wildcard/empty host means loopback works +api_from_uci() { + l=$(uci_get nikki.mixin.api_listen) + port=${l##*:} host=${l%:*} + case "$port" in '' | *[!0-9]*) port=9090 ;; esac + case "$host" in '' | 0.0.0.0 | '[::]' | '::' | '*' | "$l") host=127.0.0.1 ;; esac + echo "http://$host:$port" +} +: "${API:=$(api_from_uci)}" : "${API_SECRET:=$(uci_get nikki.mixin.api_secret)}" # while this file exists the tunnel stays off (bmstu-otp.sh off/on) : "${OFF_FLAG:=/etc/nikki/bmstu.off}" @@ -190,6 +198,16 @@ api() { fi } +# right after "nikki restart" the API is not up yet +wait_api() { + i=0 + until api GET /version >/dev/null 2>&1; do + i=$((i + 1)) + [ "$i" -ge "${API_WAIT:-30}" ] && die "mihomo API not reachable at $API (nikki running? check nikki.mixin.api_listen)" + sleep 1 + done +} + alive() { api GET "/proxies/$GROUP_NAME/delay" -G \ --data-urlencode "url=$CHECK_URL" --data-urlencode "timeout=$CHECK_TIMEOUT" >/dev/null 2>&1 @@ -205,6 +223,7 @@ write_off_provider() { refresh() { [ -f "$OFF_FLAG" ] && die "OpenVPN is off (bmstu-otp.sh on)" write_provider + wait_api api PUT "/providers/proxies/$PROVIDER_NAME" >/dev/null || die "provider reload failed (API $API)" # handshake right now, while the OTP is valid if alive; then @@ -227,6 +246,7 @@ case "${1:-}" in off) touch "$OFF_FLAG" write_off_provider + wait_api api PUT "/providers/proxies/$PROVIDER_NAME" >/dev/null || die "provider reload failed (API $API)" log "OpenVPN off: tunnel closed, the server frees the session within its ping-restart (~5 min)" ;; diff --git a/router/bmstu.env.example b/router/bmstu.env.example index e8e96c4..55eb98c 100644 --- a/router/bmstu.env.example +++ b/router/bmstu.env.example @@ -7,7 +7,7 @@ TOTP_SECRET="XXXXXXXXXXXXXXXX" #PASS_FORMAT=otp-last # nikki API: read from uci (nikki.mixin.api_listen / api_secret) unless set here -#API="http://127.0.0.1:9090" +#API="http://192.168.1.1:9090" #API_SECRET="" # something reachable only (or at least) through the VPN diff --git a/templates/dns/10-base.yaml b/templates/dns/10-base.yaml index 862ff94..33802b0 100644 --- a/templates/dns/10-base.yaml +++ b/templates/dns/10-base.yaml @@ -9,7 +9,7 @@ dns: - '*.local' #@router - '+.ru' - '+.xn--p1ai' #@router - - rule-set:ru-inside #@router + - geosite:ru-inside #@router default-nameserver: - 77.88.8.8 diff --git a/tools/test.sh b/tools/test.sh index b42d266..fa48974 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -20,7 +20,7 @@ for f in tests/fixtures/*.env; do if [ -n "${MIHOMO:-}" ]; then mkdir -p "$out/home" # geosite needs a download: drop those rules for the syntax check - sed '/GEOSITE/d; /rule-set:ru-inside/d' "$out/$n.sh.yaml" > "$out/home/$n.yaml" + sed '/GEOSITE/d; /geosite:ru-inside/d' "$out/$n.sh.yaml" > "$out/home/$n.yaml" if ! "$MIHOMO" -t -d "$out/home" -f "$out/home/$n.yaml" >"$out/$n.log" 2>&1; then echo "FAIL $n: mihomo -t"; tail -3 "$out/$n.log"; fail=1; continue fi diff --git a/web/index.html b/web/index.html index ffbb3d0..8d2cfc7 100644 --- a/web/index.html +++ b/web/index.html @@ -368,7 +368,7 @@