Fixed lan and ru-inside bugs

This commit is contained in:
Sam Latsin 2026-10-09 16:33:55 +03:00
parent fb5f144df9
commit f7a719cc2c
5 changed files with 25 additions and 5 deletions

View File

@ -32,7 +32,15 @@ ENV_FILE="${ENV_FILE:-/etc/nikki/bmstu.env}"
: "${GROUP_NAME:=BMSTU}" : "${GROUP_NAME:=BMSTU}"
# API address/secret: from nikki's mixin settings unless set in the env file # API address/secret: from nikki's mixin settings unless set in the env file
uci_get() { uci -q get "$1" 2>/dev/null; } 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)}" : "${API_SECRET:=$(uci_get nikki.mixin.api_secret)}"
# while this file exists the tunnel stays off (bmstu-otp.sh off/on) # while this file exists the tunnel stays off (bmstu-otp.sh off/on)
: "${OFF_FLAG:=/etc/nikki/bmstu.off}" : "${OFF_FLAG:=/etc/nikki/bmstu.off}"
@ -190,6 +198,16 @@ api() {
fi 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() { alive() {
api GET "/proxies/$GROUP_NAME/delay" -G \ api GET "/proxies/$GROUP_NAME/delay" -G \
--data-urlencode "url=$CHECK_URL" --data-urlencode "timeout=$CHECK_TIMEOUT" >/dev/null 2>&1 --data-urlencode "url=$CHECK_URL" --data-urlencode "timeout=$CHECK_TIMEOUT" >/dev/null 2>&1
@ -205,6 +223,7 @@ write_off_provider() {
refresh() { refresh() {
[ -f "$OFF_FLAG" ] && die "OpenVPN is off (bmstu-otp.sh on)" [ -f "$OFF_FLAG" ] && die "OpenVPN is off (bmstu-otp.sh on)"
write_provider write_provider
wait_api
api PUT "/providers/proxies/$PROVIDER_NAME" >/dev/null || die "provider reload failed (API $API)" api PUT "/providers/proxies/$PROVIDER_NAME" >/dev/null || die "provider reload failed (API $API)"
# handshake right now, while the OTP is valid # handshake right now, while the OTP is valid
if alive; then if alive; then
@ -227,6 +246,7 @@ case "${1:-}" in
off) off)
touch "$OFF_FLAG" touch "$OFF_FLAG"
write_off_provider write_off_provider
wait_api
api PUT "/providers/proxies/$PROVIDER_NAME" >/dev/null || die "provider reload failed (API $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)" log "OpenVPN off: tunnel closed, the server frees the session within its ping-restart (~5 min)"
;; ;;

View File

@ -7,7 +7,7 @@ TOTP_SECRET="XXXXXXXXXXXXXXXX"
#PASS_FORMAT=otp-last #PASS_FORMAT=otp-last
# nikki API: read from uci (nikki.mixin.api_listen / api_secret) unless set here # 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="" #API_SECRET=""
# something reachable only (or at least) through the VPN # something reachable only (or at least) through the VPN

View File

@ -9,7 +9,7 @@ dns:
- '*.local' #@router - '*.local' #@router
- '+.ru' - '+.ru'
- '+.xn--p1ai' #@router - '+.xn--p1ai' #@router
- rule-set:ru-inside #@router - geosite:ru-inside #@router
default-nameserver: default-nameserver:
- 77.88.8.8 - 77.88.8.8

View File

@ -20,7 +20,7 @@ for f in tests/fixtures/*.env; do
if [ -n "${MIHOMO:-}" ]; then if [ -n "${MIHOMO:-}" ]; then
mkdir -p "$out/home" mkdir -p "$out/home"
# geosite needs a download: drop those rules for the syntax check # 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 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 echo "FAIL $n: mihomo -t"; tail -3 "$out/$n.log"; fail=1; continue
fi fi

View File

@ -368,7 +368,7 @@
</script> </script>
<script> <script>
const TEMPLATES = { const TEMPLATES = {
"dns/10-base.yaml": "dns:\n enable: true\n ipv6: false\n respect-rules: true\n enhanced-mode: fake-ip\n fake-ip-range: 198.18.0.1/16\n fake-ip-filter:\n - '*.lan'\n - '*.local' #@router\n - '+.ru'\n - '+.xn--p1ai' #@router\n - rule-set:ru-inside #@router\n\n default-nameserver:\n - 77.88.8.8\n - 1.1.1.1 #@router\n - 223.5.5.5 #@mobile\n\n proxy-server-nameserver:\n - https://77.88.8.8/dns-query\n\n direct-nameserver:\n - 77.88.8.8\n - 77.88.8.1\n\n nameserver:\n - https://1.1.1.1/dns-query #@router\n - https://dns.google/dns-query\n - https://1.1.1.1/dns-query #@mobile\n", "dns/10-base.yaml": "dns:\n enable: true\n ipv6: false\n respect-rules: true\n enhanced-mode: fake-ip\n fake-ip-range: 198.18.0.1/16\n fake-ip-filter:\n - '*.lan'\n - '*.local' #@router\n - '+.ru'\n - '+.xn--p1ai' #@router\n - geosite:ru-inside #@router\n\n default-nameserver:\n - 77.88.8.8\n - 1.1.1.1 #@router\n - 223.5.5.5 #@mobile\n\n proxy-server-nameserver:\n - https://77.88.8.8/dns-query\n\n direct-nameserver:\n - 77.88.8.8\n - 77.88.8.1\n\n nameserver:\n - https://1.1.1.1/dns-query #@router\n - https://dns.google/dns-query\n - https://1.1.1.1/dns-query #@mobile\n",
"groups/10-boot.yaml": " - name: BOOT\n type: select\n proxies: [seed]\n", "groups/10-boot.yaml": " - name: BOOT\n type: select\n proxies: [seed]\n",
"groups/20-sub.yaml": " - name: RU\n type: url-test\n use: [${SUB_LIST}]\n filter: \"(?i)🇷🇺|\\\\bru\\\\b|russia|росси|моск\"\n url: \"https://ya.ru\"\n interval: 300\n tolerance: 50\n lazy: false\n\n - name: FOREIGN\n type: url-test\n use: [${SUB_LIST}]\n exclude-filter: \"(?i)🇷🇺|\\\\bru\\\\b|russia|росси|моск\"\n url: \"https://www.gstatic.com/generate_204\"\n interval: 300\n tolerance: 50\n lazy: false\n", "groups/20-sub.yaml": " - name: RU\n type: url-test\n use: [${SUB_LIST}]\n filter: \"(?i)🇷🇺|\\\\bru\\\\b|russia|росси|моск\"\n url: \"https://ya.ru\"\n interval: 300\n tolerance: 50\n lazy: false\n\n - name: FOREIGN\n type: url-test\n use: [${SUB_LIST}]\n exclude-filter: \"(?i)🇷🇺|\\\\bru\\\\b|russia|росси|моск\"\n url: \"https://www.gstatic.com/generate_204\"\n interval: 300\n tolerance: 50\n lazy: false\n",
"groups/30-torrent.yaml": " - name: TORRENT\n type: url-test\n use: [${SUB_LIST}]\n filter: \"(?i)torrent|\\\\[tor\\\\]\"\n url: \"https://www.gstatic.com/generate_204\"\n interval: 300\n timeout: 6000\n tolerance: 500\n max-failed-times: 5\n lazy: false\n", "groups/30-torrent.yaml": " - name: TORRENT\n type: url-test\n use: [${SUB_LIST}]\n filter: \"(?i)torrent|\\\\[tor\\\\]\"\n url: \"https://www.gstatic.com/generate_204\"\n interval: 300\n timeout: 6000\n tolerance: 500\n max-failed-times: 5\n lazy: false\n",