diff --git a/bibVPN.sh b/bibVPN.sh
old mode 100755
new mode 100644
index 89f04d4..95d4495
--- a/bibVPN.sh
+++ b/bibVPN.sh
@@ -8,7 +8,7 @@
#joesmith ALL=(ALL) NOPASSWD: /usr/bin/killall -2 openconnect
# VPN Status
-# v1.2
+# v1.3
# Thomas Schmauder
# itssct
# Displays status of a VPN interface with option to connect/disconnect.
@@ -23,7 +23,7 @@
###################
#### Variables ####
###################
-VERSION=1.2.1
+VERSION=1.3.1
WORKDIR="/Users/$USER/.openconnect"
mkdir -p $WORKDIR
logfile="$WORKDIR/bibVPN.log"
@@ -58,15 +58,25 @@ IP=$(ifconfig | egrep -A1 "$NET_FILTER" |cut -d' ' -f2)
#### Functions ####
###################
function askFor(){
- osascript="$1 buttons {\"Cancel\",\"OK\"} default button {\"OK\"} with title \"Neuen User für das VPN anlegen\""
+ osascript="$1 buttons {\"Cancel\",\"OK\"} default button {\"OK\"} cancel button \"Cancel\" with title \"Neuen User für das VPN anlegen\" with icon caution"
echo $osascript
results=$( /usr/bin/osascript -e "$osascript")
+ if [[ $? != 0 ]]; then
+ clmsg='display notification "" with title "OpenFortiVPN" subtitle "Beende mich" sound name "Submarine"'
+ osascript -e "$clmsg"
+ exit 2
+ else
+ echo $results >> $logfile
+ theButton=$( echo "$results" | /usr/bin/awk -F "button returned:|," '{print $2}' )
+ theText=$( echo "$results" | /usr/bin/awk -F "text returned:" '{print $2}' )
- theButton=$( echo "$results" | /usr/bin/awk -F "button returned:|," '{print $2}' )
- theText=$( echo "$results" | /usr/bin/awk -F "text returned:" '{print $2}' )
-
- if [[ $theButton == "OK" ]] ;then
- echo $theText;
+ if [[ $theButton == "OK" ]] ;then
+ echo $theText;
+ elif [[ $theButton == "Cancel" ]] ; then
+ clmsg='display notification "" with title "OpenFortiVPN" subtitle "Beende mich" sound name "Submarine"'
+ osascript -e "$clmsg"
+ exit 2
+ fi
fi
}
@@ -75,11 +85,13 @@ function showSettings()
if [[ $SHOW_SETTINGS == "ON" ]]; then
echo "---"
echo "Settings"
- echo "--$SETTINGSFILE"
- echo "--Farbige Icons aus (not ready)"
- echo "--Neuen User anlegen| shell='$0' param1=newuser terminal=true refresh=true"
+ echo "--Farbige Icons aus (not ready) | tooltip='Vielleicht klappt es irgendwann :)' checked=false"
+ echo "--Neues VPN Profil anlegen | shell='$0' param1=newuser terminal=false refresh=true"
echo "---"
- echo "--$(basename -- "$0") v$VERSION"
+ echo "-- --- INFOS ---"
+ echo "--Logfile: $logfile | shell='$0' param1=openlog terminal=false refresh=true tooltip='Das Logfile öffnen'"
+ echo "--__${SETTINGSFILE}__ | md=true"
+ echo "--Script: $(basename -- "$0") Version: **v$VERSION** | href="https://git.bib.de/itssct/OpenFortiVPN_macOS" terminal=false refresh=true tooltip='Die Projektwebsite im Browser öffnen' md=true"
fi
}
###################
@@ -87,20 +99,37 @@ function showSettings()
###################
case "$1" in
connect)
+ echo "$GET_VPN_PASSWORD" >> $logfile 2>&1
VPN_PASSWORD=$(eval "$GET_VPN_PASSWORD")
# Passwort checken
- #if [[ -z VPN_PASSWORD ]]; then VPN_PASSWORD=$(askFor 'display dialog "Es ist kein Passwort im Schlüsselbund vorhanden. Wie lautet das Passwort? " default answer "vpn.bib.de"'); fi
- #security add-generic-password -a $VPN_USERNAME -s openconnect -w $keychainPW
- VPN_EXECUTABLE_PARAMS="--servercert $4 --protocol=fortinet" # Optional
+ if [[ $VPN_PASSWORD =~ 'item could not be found in the keychain.' ]] ; then
+
+ echo "Es konnte kein Passwort für $VPN_USERNAME gefunden werden" >> $logfile 2>&1
+ #errmsg_noPass='display notification "Es konnte kein Passwort für '$VPN_USERNAME' gefunden werden" with title "OpenFortiVPN" subtitle "Verbindungsversuch nicht erfolgreich" sound name "Brise"'
+ #osascript -e "$errmsg_noPass"
+ NEW_VPN_PASSWORD=$(askFor 'display dialog "Es ist kein Passwort im Schlüsselbund vorhanden. Wie lautet das Passwort für '$VPN_USERNAME'? " default answer "Mein Passwort..." with hidden answer')
+ echo $VPN_PASSWORD
+ if [[ $? != 0 ]]; then exit 2 ; fi # Beim Abbruch der Maske, gesamte Script beenden.
+ echo "security add-generic-password -a $VPN_USERNAME -s openconnect -w '$VPN_PASSWORD'" >> $logfile 2>&1
+ security add-generic-password -a $VPN_USERNAME -s "openconnect" -T /usr/bin/security -w "$NEW_VPN_PASSWORD"
+ VPN_PASSWORD=$NEW_VPN_PASSWORD
+ #else
+ #echo $VPN_PASSWORD >> $logfile 2>&1
+ fi
+ VPN_EXECUTABLE_PARAMS="--passwd-on-stdin --servercert $4 --protocol=fortinet --pid-file=$OC_PIDFILE --background" # Optional
# Verbindung aufbauen
- echo "echo | 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 > $logfile 2>&1
+ echo "$VPN_PASSWORD | sudo $VPN_EXECUTABLE $VPN_EXECUTABLE_PARAMS --user $VPN_USERNAME $VPN_HOST" >> $logfile 2>&1
+ echo "$VPN_PASSWORD" | sudo $VPN_EXECUTABLE $VPN_EXECUTABLE_PARAMS --user $VPN_USERNAME $VPN_HOST>> $logfile 2>&1
+ if [[ $? != 0 ]]; then
+ osascript -e 'display altert "Verbindungsaufbau Fehlgeschlagen. Bitte im Log prüfen, was die Ursache ist."'
+ fi
IP=$(ifconfig | egrep -A1 "$NET_FILTER" |cut -d' ' -f2)
- while [ -z $IP ]; do echo "noch keine IP" ; sleep 0.5 ; IP=$(ifconfig | egrep -A1 "$NET_FILTER"|cut -d' ' -f2) ; done
+ ii=0
+ while [ -z $IP ] && [[ $ii != 20 ]]; do echo "noch keine IP" ; sleep 0.5 ; IP=$(ifconfig | egrep -A1 "$NET_FILTER"|cut -d' ' -f2) ; ((ii++)) ; done
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"'
- if [[ $IP =~ 172 ]] ; then osascript -e "$msg" ; else osascript -e "$errmsg" ; fi
+ if [[ $IP =~ 172 ]] ; then osascript -e "$msg" ; else osascript -e "$errmsg" ; exit 5 ; fi
# Wait for connection so menu item refreshes instantly
until eval "$VPN_CONNECTED"; do sleep 1; done
;;
@@ -121,15 +150,18 @@ case "$1" in
if [[ -z $NEW_VPN_USERNAME ]] ; then echo -n "Wie lautet die E-Mail des Benutzers? " ; read NEW_VPN_USERNAME ; fi
NEW_VPN_PUBKEY=$(gnutls-cli --print-cert $NEW_VPN_HOST |grep -e 'pin-.*:'|awk '{$1=$1;print}')
- NEW_VPN_PASSWORD=$(security find-generic-password -g -a $NEW_VPN_USERNAME 2>&1 >/dev/null)
+ NEW_VPN_PASSWORD=$(security find-generic-password -g -a $NEW_VPN_USERNAME 2>&1 >>$logfile) #>/dev/null)
if [[ $NEW_VPN_PASSWORD =~ password ]] ; then
echo "Es ist bereits ein Passwort im Schlüsselbund für $NEW_VPN_USERNAME hinterlegt."
else
- echo -n "Es ist noch kein Passwort im Schlüsselbund hinterlegt Bitte einmal das Passwort angeben : " ;
- NEW_VPN_PASS = $(read )
- security add-generic-password -a $NEW_VPN_USERNAME -s openconnect -w $NEW_VPN_PASS
+ echo -n "Es ist noch kein Passwort im Schlüsselbund hinterlegt. Bitte einmal das Passwort angeben : " ;
+ NEW_VPN_PASSWORD=$(askFor 'display dialog "Es ist kein Passwort im Schlüsselbund vorhanden. Wie lautet das Passwort? " default answer "Mein Passwort..."')
+ security add-generic-password -a $NEW_VPN_USERNAME -s openconnect -w $NEW_VPN_PASSWORD
fi
- echo "$NEW_VPN_NAME,$NEW_VPN_USERNAME,$NEW_VPN_HOST,$NEW_VPN_PUBKEY" #>> $ACCOUNTFILE
+ echo "$NEW_VPN_NAME,$NEW_VPN_USERNAME,$NEW_VPN_HOST,$NEW_VPN_PUBKEY" >> $logfile # $ACCOUNTFILE
+ ;;
+ openlog)
+ open -a console $logfile
;;
esac