mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-10 09:51:02 +01:00
Merge pull request #2234 from alexbelgium/codex/adapt-vpn-guard-for-openvpn_alt_mode
Handle VPN monitor interface binding
This commit is contained in:
@@ -15,6 +15,7 @@ VPN_INFO_URL="${VPN_INFO_URL:-https://ipinfo.io}"
|
|||||||
_fetch_public_ip() {
|
_fetch_public_ip() {
|
||||||
local resp
|
local resp
|
||||||
local url
|
local url
|
||||||
|
local curl_iface_opts=()
|
||||||
local urls=(
|
local urls=(
|
||||||
"https://icanhazip.com"
|
"https://icanhazip.com"
|
||||||
"https://ifconfig.me/ip"
|
"https://ifconfig.me/ip"
|
||||||
@@ -24,10 +25,15 @@ _fetch_public_ip() {
|
|||||||
"https://ipinfo.io/ip"
|
"https://ipinfo.io/ip"
|
||||||
)
|
)
|
||||||
local shuffled_urls
|
local shuffled_urls
|
||||||
|
|
||||||
|
if [[ -n "${VPN_INTERFACE:-}" ]]; then
|
||||||
|
curl_iface_opts+=(--interface "${VPN_INTERFACE}")
|
||||||
|
fi
|
||||||
|
|
||||||
mapfile -t shuffled_urls < <(printf "%s\n" "${urls[@]}" | shuf)
|
mapfile -t shuffled_urls < <(printf "%s\n" "${urls[@]}" | shuf)
|
||||||
|
|
||||||
for url in "${shuffled_urls[@]}"; do
|
for url in "${shuffled_urls[@]}"; do
|
||||||
resp=$(curl -fsS --max-time 5 "${url}" 2>/dev/null || true)
|
resp=$(curl -fsS --max-time 5 "${curl_iface_opts[@]}" "${url}" 2>/dev/null || true)
|
||||||
resp="${resp//[[:space:]]/}"
|
resp="${resp//[[:space:]]/}"
|
||||||
|
|
||||||
if [[ "${resp}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] || [[ "${resp}" =~ ^[0-9a-fA-F:]+$ ]]; then
|
if [[ "${resp}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] || [[ "${resp}" =~ ^[0-9a-fA-F:]+$ ]]; then
|
||||||
@@ -123,6 +129,13 @@ if bashio::config.true 'openvpn_enabled'; then
|
|||||||
vpn_openvpn=true
|
vpn_openvpn=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "${vpn_openvpn}" == true ]] && ! bashio::config.true 'openvpn_alt_mode'; then
|
||||||
|
VPN_INTERFACE="tun0"
|
||||||
|
bashio::log.info "VPN monitor set to query external IP through interface ${VPN_INTERFACE} (interface binding)."
|
||||||
|
else
|
||||||
|
VPN_INTERFACE=""
|
||||||
|
fi
|
||||||
|
|
||||||
if bashio::config.true 'wireguard_enabled'; then
|
if bashio::config.true 'wireguard_enabled'; then
|
||||||
vpn_wireguard=true
|
vpn_wireguard=true
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user