Compare commits

..

No commits in common. "35080343654080e49f30495ee36326161947f1cc" and "c62c2a7b586744b822afadd0a447af27442d50a0" have entirely different histories.

View File

@ -14,19 +14,15 @@
# <xbar.desc>Displays status of a VPN interface with option to connect/disconnect.</xbar.desc> # <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> # <xbar.image>http://i.imgur.com/RkmptwO.png</xbar.image>
mkdir -p "/Users/$USER/.log/"
logfile="/Users/$USER/.log/bibVPN.log"
echo -e "\nRun $0 , $(date)" >>$logfile
PATH=$PATH:/usr/local/bin
VPN_EXECUTABLE=$(which openconnect) VPN_EXECUTABLE=$(which openconnect)
VPN_HOST="$3" VPN_EXECUTABLE_PARAMS="--servercert pin-sha256:NFR9+lG+7SvvEqnraijD1l5R1ShK9KKtwYjqedfx78U= --protocol=fortinet" # Optional
VPN_HOST="vpn.bib.de"
VPN_USERNAME="$2" VPN_USERNAME="$2"
DIR=$(dirname "${BASH_SOURCE[0]}") DIR=$(dirname "${BASH_SOURCE[0]}")
OC_PIDFILE="/var/run/openconnect/vpn.bib.de.pid" OC_PIDFILE="/var/run/openconnect/vpn.bib.de.pid"
SETTINGSFILE="$DIR/settings.csv" SETTINGSFILE="$DIR/settings.csv"
ACCOUNTFILE="$DIR/accounts.csv" ACCOUNTFILE="$DIR/accounts.csv"
SHOW_SETTINGS='ON' SHOW_SETTINGS='ON'
NET_FILTER='172.[123][0-9].1[67][80].'
# Icons # Icons
ICON_connected="iVBORw0KGgoAAAANSUhEUgAAABgAAAAWCAYAAAGtemweAAAACXBIWXMAAAsSAAALEgHS3X78AAAA+klEQVR4nNRUwQ2DMAzMKy8WYIZOwb8LtUtAJSZp34zBCn3y4Y3cWLEr13KSllKhnnRKcvHZ4AScS6BJbUSMgRCncfJcaBG0KMcvMIj83ircWcUh9VTI46onO1A75sC2FIjpT0qHwMUy4AZSzuU6a7D2smDzLRu1Fi11aKRGJOHVyzKHlGExX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ABJRU5ErkJggg==" ICON_disconnected="iVBORw0KGgoAAAANSUhEUgAAABgAAAAWCAYAAAGtemweAAAACXBIWXMAAAsSAAALEgHS3X78AAAA2klEQVR4nNxTQQ6DMAyrqvGAXfeK7Uh5wHbgyhlxaP//hDXClbLOXUHqhDZLFsGJEzUUYwq4lBIrpsiwhirQEDHxRSw69mFU/a1OJNHh+ZYILMHibThjHUtkXyuU9tdMD5GeGSQh1LF+/2hguQPRY0MTFlGEzQ6bOJYMnhzuBo1OCrjejqx0KhnSk32TdgamhyaGP4SNHNQFYPSokdpdGLJGd1yaDpT4kdWIZ/PPoBsLTriRM+igmWyQeKtYlKGDNpP1iGZQkzTxVqGbMK2Wr+KQAU09Xx/wW3gCAAD//+SvwXMAAAACSURBVAMAV9bueQAAAABJRU5ErkJggg=="
@ -34,7 +30,7 @@ ICON_disconnected="iVBORw0KGgoAAAANSUhEUgAAABgAAAAWCAYAAAGtemweAAAACXBIWXMAAAsSA
# "security find-generic-password -g -a foo" where foo is an account # "security find-generic-password -g -a foo" where foo is an account
# in your OSX Keychain, to avoid passwords stored in plain text # in your OSX Keychain, to avoid passwords stored in plain text
GET_VPN_PASSWORD="security find-generic-password -g -a $VPN_USERNAME 2>&1 >/dev/null | cut -d'\"' -f2" GET_VPN_PASSWORD="security find-generic-password -g -a $VPN_USERNAME 2>&1 >/dev/null | cut -d'\"' -f2"
if [[ -z $GET_VPN_PASSWORD ]] ; then if [ -z $GET_VPN_PASSWORD ] ; then
if $(read "Es wurde kein Passwort im Schlüsselbund gefunden. Soll dort eins hinterlegt werden? (ja/nein)") == '[Jj][aA]' ; then if $(read "Es wurde kein Passwort im Schlüsselbund gefunden. Soll dort eins hinterlegt werden? (ja/nein)") == '[Jj][aA]' ; then
local $keychainPW = $(read "Wie lautet das Password für den Benutzer $VPN_USERNAME ?") local $keychainPW = $(read "Wie lautet das Password für den Benutzer $VPN_USERNAME ?")
security add-generic-password -a $VPN_USERNAME -s openconnect -w $keychainPW security add-generic-password -a $VPN_USERNAME -s openconnect -w $keychainPW
@ -42,23 +38,21 @@ if [[ -z $GET_VPN_PASSWORD ]] ; then
fi fi
# Command to determine if VPN is connected or disconnected # Command to determine if VPN is connected or disconnected
VPN_CONNECTED="ifconfig | egrep -A1 'inet $NET_FILTER' |cut -d' ' -f2" VPN_CONNECTED="ifconfig | egrep -A1 'inet 172.[123][0-9]' |cut -d' ' -f2"
# Command to run to disconnect VPN # Command to run to disconnect VPN
VPN_DISCONNECT_CMD="sudo killall -2 openconnect" VPN_DISCONNECT_CMD="sudo killall -2 openconnect"
# Get IP of Current VPN Tunnel # Get IP of Current VPN Tunnel
IP=$(ifconfig | egrep -A1 'inet $NET_FILTER' |cut -d' ' -f2) IP=$(ifconfig | egrep -A1 'inet 172.[123][0-9]' |cut -d' ' -f2)
case "$1" in case "$1" in
connect) connect)
VPN_PASSWORD=$(eval "$GET_VPN_PASSWORD") VPN_PASSWORD=$(eval "$GET_VPN_PASSWORD")
VPN_EXECUTABLE_PARAMS="--servercert $4 --protocol=fortinet" # Optional
# VPN connection command, should eventually result in $VPN_CONNECTED, # VPN connection command, should eventually result in $VPN_CONNECTED,
# may need to be modified for VPN clients other than openconnect # may need to be modified for VPN clients other than openconnect
echo "echo $VPN_PASSWORD | sudo $VPN_EXECUTABLE $VPN_EXECUTABLE_PARAMS --user $VPN_USERNAME --passwd-on-stdin $VPN_HOST --pid-file=$OC_PIDFILE --background" > $logfile 2>&1 echo "$VPN_PASSWORD" | sudo "$VPN_EXECUTABLE" $VPN_EXECUTABLE_PARAMS --user "$VPN_USERNAME" --passwd-on-stdin "$VPN_HOST" --pid-file=$OC_PIDFILE --background #&> /dev/null &
echo "$VPN_PASSWORD" | sudo $VPN_EXECUTABLE $VPN_EXECUTABLE_PARAMS --user $VPN_USERNAME --passwd-on-stdin $VPN_HOST --pid-file=$OC_PIDFILE --background > $logfile 2>&1
IP=$(ifconfig | egrep -A1 'inet $NET_FILTER' |cut -d' ' -f2) IP=$(ifconfig | egrep -A1 'inet 172.[123][0-9]' |cut -d' ' -f2)
while [ -z $IP ]; do echo "noch keine IP" ; sleep 0.5 ; IP=$(ifconfig | egrep -A1 'inet $NET_FILTER' |cut -d' ' -f2) ; done while [ -z $IP ]; do echo "noch keine IP" ; sleep 0.5 ; IP=$(ifconfig | egrep -A1 'inet 172.[123][0-9]' |cut -d' ' -f2) ; done
msg='display notification "Erfolgreich verbunden \nConnected User: '$VPN_USERNAME'" with title "OpenFortiVPN" subtitle "Deine IP lautet: '$IP'" sound name "Brise"' msg='display notification "Erfolgreich verbunden \nConnected User: '$VPN_USERNAME'" with title "OpenFortiVPN" subtitle "Deine IP lautet: '$IP'" sound name "Brise"'
errmsg='display notification "Verbindungsversuch nicht erfolgreich" with title "OpenFortiVPN" subtitle "Schade" sound name "Brise"' errmsg='display notification "Verbindungsversuch nicht erfolgreich" with title "OpenFortiVPN" subtitle "Schade" sound name "Brise"'
if [[ $IP =~ 172 ]] ; then osascript -e "$msg" ; else osascript -e "$errmsg" ; fi if [[ $IP =~ 172 ]] ; then osascript -e "$msg" ; else osascript -e "$errmsg" ; fi
@ -99,16 +93,14 @@ else
echo "| templateImage=$ICON_disconnected" echo "| templateImage=$ICON_disconnected"
#echo "VPN ❌ | color=Crimson" #echo "VPN ❌ | color=Crimson"
echo '---' echo '---'
# Alle User aus der accounts.csv auslesen und dann zur Auswahl anbieten. for config in $(cat $ACCOUNTFILE) ; do
cat "$ACCOUNTFILE" | while IFS= read config; cfgName=$config
do cfgMail=
cfgName=$(echo $config|cut -d',' -f1) cfgHost=
cfgMail=$(echo $config|cut -d',' -f2) echo "Connect $cfgName VPN | bash='$0' param1=connect param2=$cfgMail param3=$cfgHost terminal=false refresh=true"
cfgHost=$(echo $config|cut -d',' -f3)
cfgPubKey=$(echo $config|cut -d',' -f4)
echo "Connect $cfgName VPN | bash='$0' param1=connect param2=$cfgMail param3=$cfgHost param4=$cfgPubKey terminal=false refresh=true"
done done
echo "Connect Admin VPN | bash='$0' param1=connect param2=admsct@bib.de terminal=false refresh=true"
echo "Connect ScT VPN | bash='$0' param1=connect param2=thomas.schmauder@bib.de terminal=false refresh=true"
if [[ $SHOW_SETTINGS == "ON" ]]; then if [[ $SHOW_SETTINGS == "ON" ]]; then
echo "---" echo "---"
echo "Settings" echo "Settings"