From df319395b6d4060004d8c30644e5497a2a26fba9 Mon Sep 17 00:00:00 2001 From: Henrik Bengtsson Date: Wed, 19 Jun 2024 15:48:29 +0200 Subject: [PATCH] Add support for `ucsf vpn status --validate=ucsfit` [#67] --- NEWS.md | 3 +++ bin/ucsf-vpn | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index e880c52..e607f4a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,9 @@ ucsf-vpn * Now `ucsf vpn start --debug` and `ucsf vpn stop --debug` reports on changes to your nameserver settings (`/etc/resolv.conf`). + * Add support for `ucsf vpn status --validate=ucsfit`, which infers + VPN status from . + ## Version 6.0.0 (2024-05-20) diff --git a/bin/ucsf-vpn b/bin/ucsf-vpn index adbb92a..bb5f882 100755 --- a/bin/ucsf-vpn +++ b/bin/ucsf-vpn @@ -109,7 +109,7 @@ ### * UCSF Managing Your Passwords: ### - https://it.ucsf.edu/services/managing-your-passwords ### -### Version: 6.0.0-9004 +### Version: 6.0.0-9005 ### Copyright: Henrik Bengtsson (2016-2024) ### License: GPL (>= 2.1) [https://www.gnu.org/licenses/gpl.html] ### Source: https://github.com/HenrikBengtsson/ucsf-vpn @@ -289,6 +289,10 @@ function assert_sudo() { # ------------------------------------------------------------------------- # Connection, e.g. checking whether connected to the VPN or not # ------------------------------------------------------------------------- +function ucsf_it_network_info() { + curl --silent https://help.ucsf.edu/HelpApps/ipNetVerify.php | grep -E "(Connected to UCSF Network|IP Address|Network Location)" | sed 's/<\/td>/=/' | sed -E 's/<[^>]+>//g' | sed 's/.*Connected to UCSF Network/connected/' | sed 's/.*IP Address/public_ip/' | sed 's/.*Network Location/network/' | sed 's/=No/=false/' | sed 's/=Yes/=true/' | sed -E "s/network=(.*)/network='\1'/" | sort +} + function connection_details() { mdebug "connection_details()" if [[ ! -f "$pii_file" ]]; then @@ -1297,13 +1301,23 @@ function status() { msg="none" fi msgs+=("IP routing tunnels: ${msg}") + elif [[ $method == ucsfit ]]; then + mapfile -t info < <(ucsf_it_network_info) + if grep -q "connected=true" <<< "${info[0]}"; then + connected+=(true) + msg="yes (n=${#info[@]} ${info[*]})" + else + connected+=(false) + msg="no (n=${#info[@]} ${info[*]})" + fi + msgs+=("Public IP information (UCSF IT): ${info[2]}, ${info[1]}") elif [[ $method == ipinfo ]]; then if is_connected; then connected+=(true) else connected+=(false) fi - msgs+=("Public IP information: $(public_info)") + msgs+=("Public IP information (ipinfo.io): $(public_info)") else merror "Unknown --validate value: $method" fi