This commit is contained in:
2026-03-06 16:59:56 -05:00
parent e2e16cdcb4
commit d0dce8bdc9

View File

@@ -141,6 +141,24 @@ pia_addkey() {
opn_curl 'firewall/alias/reconfigure' -d '{}' opn_curl 'firewall/alias/reconfigure' -d '{}'
} }
tunnel_check() {
local tunneladdr
local response
local peer_status
tunneladdr="$(opn_curl 'wireguard/server/searchServer' -d '{}' |
jq -r ".rows[] | select(.name == \"$OPN_IF\") | .tunneladdress")"
response="$(opn_curl 'wireguard/service/show' -d '{}' |
jq ".rows[] | select(.name == \"$OPN_PEER\")")"
peer_status="$(printf '%s' "$response" | jq -r '."peer-status"')"
[ "$peer_status" != "online" ] && return 1
if ! ping -c1 -W3 -S "${tunneladdr%/32}" 1.1.1.1 >/dev/null 2>&1; then
if ! ping -c1 -W3 -S "${tunneladdr%/32}" 8.8.8.8 >/dev/null 2>&1; then
return 1
fi
fi
return 0
}
# Get a new PIA API token and store # Get a new PIA API token and store
renew_token() { renew_token() {
local login_response local login_response
@@ -291,15 +309,4 @@ unset wg_reply
[ "$server_ip" != "$piawgsrv_srvaddr" ] && pia_addkey [ "$server_ip" != "$piawgsrv_srvaddr" ] && pia_addkey
# Check tunnel # Check tunnel
piawg_tunaddr="$(opn_curl 'wireguard/server/searchServer' -d '{}' | tunnel_check && printf '%s\n' "[INFO]: $server_cn tunnel working on $OPN_IF"
jq -r ".rows[] | select(.name == \"$OPN_IF\") | .tunneladdress")"
wg_status_reply="$(opn_curl 'wireguard/service/show' -d '{}' |
jq ".rows[] | select(.name == \"$OPN_PEER\")")"
echo "$wg_status_reply" | jq .
wg_status="$(printf '%s' "$wg_status_reply" | jq -r '."peer-status"')"
[ ! "$wg_status" = "online" ] && err "$OPN_PEER is offline"
if ! ping -c1 -W3 -S "${piawg_tunaddr%/32}" 1.1.1.1 >/dev/null 2>&1; then
if ! ping -c1 -W3 -S "${piawg_tunaddr%/32}" 8.8.8.8 >/dev/null 2>&1; then
err "$OPN_PEER failed to ping internet"
fi
fi