45 lines
1.6 KiB
Bash
Executable File
45 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Get current status of a VPN connection with options to connect/disconnect.
|
|
# Working with OpenConnect, but can work with any executable VPN. Commands
|
|
# that require admin permissions should be whitelisted with 'visudo', e.g.:
|
|
#
|
|
#joesmith ALL=(ALL) NOPASSWD: /path/to/always-on-openconnect-vpn/run-vpn.sh
|
|
#joesmith ALL=(ALL) NOPASSWD: /usr/bin/killall -2 openconnect
|
|
|
|
# <xbar.title>VPN Status</xbar.title>
|
|
# <xbar.version>v1.0</xbar.version>
|
|
# <xbar.author>Jesse Jarzynka</xbar.author>
|
|
# <xbar.author.github>jessejoe</xbar.author.github>
|
|
# <xbar.desc>Displays status of a VPN interface with option to connect/disconnect.</xbar.desc>
|
|
# <xbar.image>http://i.imgur.com/RkmptwO.png</xbar.image>
|
|
|
|
VPN_CONNECTED="ifconfig | egrep -A1 utun3 | grep inet"
|
|
|
|
case "$1" in
|
|
connect)
|
|
terminal-notifier -title "VPN" -message "Connecting..." -sender "SwiftBar"
|
|
cd /path/to/always-on-openconnect-vpn/
|
|
sudo /path/to/always-on-openconnect-vpn/run-vpn.sh &> /tmp/vpn.log &
|
|
until eval "$VPN_CONNECTED"; do sleep 1; done
|
|
terminal-notifier -title "VPN" -message "Connected!" -sender "SwiftBar"
|
|
;;
|
|
disconnect)
|
|
eval "sudo killall -2 openconnect"
|
|
until [ -z "$(eval "$VPN_CONNECTED")" ]; do sleep 1; done
|
|
terminal-notifier -title "VPN" -message "Disconnected" -sender "SwiftBar"
|
|
;;
|
|
esac
|
|
|
|
if [ -n "$(eval "$VPN_CONNECTED")" ]; then
|
|
echo "VPN ✔"
|
|
echo '---'
|
|
echo "Disconnect VPN | bash='$0' param1=disconnect terminal=false refresh=true"
|
|
exit
|
|
else
|
|
echo "VPN ✘"
|
|
echo '---'
|
|
echo "Connect VPN | bash='$0' param1=connect terminal=false refresh=true"
|
|
exit
|
|
fi
|