From d0dce8bdc9924b5c62d5f650e0a7777ccde351d9 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Fri, 6 Mar 2026 16:59:56 -0500 Subject: [PATCH] testing --- piawg.sh | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/piawg.sh b/piawg.sh index fd6dad2..f986a36 100755 --- a/piawg.sh +++ b/piawg.sh @@ -141,6 +141,24 @@ pia_addkey() { 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 renew_token() { local login_response @@ -291,15 +309,4 @@ unset wg_reply [ "$server_ip" != "$piawgsrv_srvaddr" ] && pia_addkey # Check tunnel -piawg_tunaddr="$(opn_curl 'wireguard/server/searchServer' -d '{}' | - 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 +tunnel_check && printf '%s\n' "[INFO]: $server_cn tunnel working on $OPN_IF"