Added bitbar script

This commit is contained in:
Janis Jansons 2023-07-06 09:44:38 +03:00
parent 7e6acc7a89
commit 830c6e9979
2 changed files with 67 additions and 0 deletions

View File

@ -13,6 +13,8 @@ git clone this repo
brew install openconnect
brew install vpn-slice
brew install oath-toolkit
brew install swiftbar
brew install terminal-notifier
```
Add server address, username, password and 2fa seed in keychain with these names:

65
bitbar-openconnect.sh Executable file
View File

@ -0,0 +1,65 @@
#!/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 | grep -E -A1 tun | grep inet"
function notify(){
if [[ "$OSTYPE" == "darwin"* ]]; then
terminal-notifier -title "VPN" -message "${1}" -sender "SwiftBar"
fi
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
notify-send "VPN" "${1}"
fi
}
# Get location to this script from symlink
SCRIPT_LOCATION=$(dirname $([ -L $0 ] && readlink -f $0 || echo $0))
LOG_FILE=/tmp/vpn.log
case "$1" in
connect)
notify "Connecting..."
# For Linux desktop use DBUS to use keychain
export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
cd $SCRIPT_LOCATION
sudo --preserve-env $SCRIPT_LOCATION/run-vpn.sh &>> $LOG_FILE &
until eval "$VPN_CONNECTED"; do sleep 1; done
notify "Connected!"
;;
disconnect)
eval "sudo killall -2 openconnect"
until [ -z "$(eval "$VPN_CONNECTED")" ]; do sleep 1; done
notify "Disconnected"
;;
esac
if [ -n "$(eval "$VPN_CONNECTED")" ]; then
echo "VPN ✔"
echo '---'
echo "Disconnect VPN | bash='$0' param1=disconnect terminal=false refresh=true"
else
echo "VPN ✘"
echo '---'
echo "Connect VPN | bash='$0' param1=connect terminal=false refresh=true"
fi
echo '---'
echo "Edit routes | iconName=folder-symbolic href='file://$SCRIPT_LOCATION/routes.txt' refresh=false"
echo "Tail VPN log file | bash='tail -f $LOG_FILE -n 200' terminal=true refresh=false"
exit