testing
This commit is contained in:
32
piawg.sh
32
piawg.sh
@@ -141,6 +141,25 @@ 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\")")"
|
||||||
|
echo "$response" | jq .
|
||||||
|
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 +310,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
|
||||||
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user