Updated vpn toggle

This commit is contained in:
Ezri Brimhall 2025-03-13 09:37:39 -06:00
parent 6a603a5c9b
commit baacfff7c4
Signed by: ezri
GPG Key ID: 058A78E5680C6F24

View File

@ -1,18 +1,16 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
exec </dev/null exec </dev/null
exec > >(systemd-cat -t gpclient -p info) 2>&1
# Toggles the GlobalProtect VPN connection on and off # Toggles the GlobalProtect VPN connection on and off
# Get the current state of the VPN connection # Get the current state of the VPN connection
if pgrep gpclient &>/dev/null; then if pgrep gpclient &>/dev/null; then
# VPN is connected, so disconnect # VPN is connected, so disconnect
echo "Disconnecting from VPN..." echo "Disconnecting from VPN..."
pkexec env TZ=Etc/UTC gpclient disconnect systemctl stop usu-gpclient
else else
# VPN is disconnected, so connect # VPN is disconnected, so connect
echo "Connecting to VPN..." echo "Connecting to VPN..."
# pkexec doesn't pass the DISPLAY and XAUTHORITY environment variables, so we need to pass them manually systemd-run --unit=usu-gpclient --setenv=SUDO_USER=$(whoami) --setenv=SUDO_UID=$(id -u) --setenv=SUDO_GID=$(id -g) --setenv=SUDO_HOME=$HOME --setenv=DISPLAY=$DISPLAY --setenv=XAUTHORITY=$XAUTHORITY -- /usr/sbin/gpclient --fix-openssl connect gp.usu.edu
TZ=Etc/UTC sudo /usr/sbin/gpclient --fix-openssl connect gp.usu.edu sudo nft add element inet router vpn_cgroups \{ '"system.slice/usu-gpclient.service"' \}
fi fi