Compare commits

..

3 Commits

Author SHA1 Message Date
Thomas Schmauder
4dd92e3427 added 2023-02-14 21:34:52 +01:00
Thomas Schmauder
37d5c4932c verschiedenes. Not ready 2023-02-14 21:31:49 +01:00
Thomas Schmauder
5a09f4d1c8 Vorlage Accountsdatei 2023-02-14 21:31:06 +01:00
3 changed files with 37 additions and 12 deletions

2
.accounts.csv.sample Normal file
View File

@ -0,0 +1,2 @@
#Name,E-Mail,Host,ServerFingerprint
bib,vorname.nachname@bib.de,vpn.bib.de,pin-sha265:asdasdasdasdasdasdasdasdasdasdadasd

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.DS_Store

View File

@ -21,12 +21,15 @@ PATH=$PATH:/usr/local/bin
VPN_EXECUTABLE=$(which openconnect) VPN_EXECUTABLE=$(which openconnect)
VPN_HOST="$3" VPN_HOST="$3"
VPN_USERNAME="$2" VPN_USERNAME="$2"
DIR=$(dirname "${BASH_SOURCE[0]}") #DIR=$(dirname "${BASH_SOURCE[0]}")
DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
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'
SET_ICONS='no'
NET_FILTER='172.[123][0-9].1[67][80].' NET_FILTER='172.[123][0-9].1[67][80].'
FONT=( 'size=14' 'font=UbuntuMono' )
# Icons # Icons
ICON_connected="iVBORw0KGgoAAAANSUhEUgAAABgAAAAWCAYAAAGtemweAAAACXBIWXMAAAsSAAALEgHS3X78AAAA+klEQVR4nNRUwQ2DMAzMKy8WYIZOwb8LtUtAJSZp34zBCn3y4Y3cWLEr13KSllKhnnRKcvHZ4AScS6BJbUSMgRCncfJcaBG0KMcvMIj83ircWcUh9VTI46on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kzTxVqGbMK2Wr+KQAU09Xx/wW3gCAAD//+SvwXMAAAACSURBVAMAV9bueQAAAABJRU5ErkJggg==" ICON_disconnected="iVBORw0KGgoAAAANSUhEUgAAABgAAAAWCAYAAAGtemweAAAACXBIWXMAAAsSAAALEgHS3X78AAAA2klEQVR4nNxTQQ6DMAyrqvGAXfeK7Uh5wHbgyhlxaP//hDXClbLOXUHqhDZLFsGJEzUUYwq4lBIrpsiwhirQEDHxRSw69mFU/a1OJNHh+ZYILMHibThjHUtkXyuU9tdMD5GeGSQh1LF+/2hguQPRY0MTFlGEzQ6bOJYMnhzuBo1OCrjejqx0KhnSk32TdgamhyaGP4SNHNQFYPSokdpdGLJGd1yaDpT4kdWIZ/PPoBsLTriRM+igmWyQeKtYlKGDNpP1iGZQkzTxVqGbMK2Wr+KQAU09Xx/wW3gCAAD//+SvwXMAAAACSURBVAMAV9bueQAAAABJRU5ErkJggg=="
@ -48,6 +51,17 @@ 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 $NET_FILTER' |cut -d' ' -f2)
function askForVPNName(){
results=$( /usr/bin/osascript -e 'display dialog "Wie lautet die E-Mail des Benutzers, der zum Verbinden verwendet werden soll?" default answer "vorname.nachname@bib.de" buttons {"Cancel","OK"} default button {"OK"} with title "Neuen User für das VPN anlegen"' )
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;
fi
}
case "$1" in case "$1" in
connect) connect)
VPN_PASSWORD=$(eval "$GET_VPN_PASSWORD") VPN_PASSWORD=$(eval "$GET_VPN_PASSWORD")
@ -72,19 +86,28 @@ case "$1" in
osascript -e 'display notification "VPN Tunnel erfolgreich geschlossen" with title "OpenFortiVPN" subtitle "Mach Feierabend" sound name "Submarine"' osascript -e 'display notification "VPN Tunnel erfolgreich geschlossen" with title "OpenFortiVPN" subtitle "Mach Feierabend" sound name "Submarine"'
;; ;;
newuser) newuser)
NEWUSER=$(read "Wie lautet die E-Mail des neuen Benutzers?") echo "Sie wollen einen weiteren Benutzer für das VPN anlegen. Geben Sie dazu die folgenden Dinge ein."
NEW_VPN_PASSWORD=$("security find-generic-password -g -a $NEWUSER 2>&1 >/dev/null | cut -d'\"' -f2") #echo -n "Wie lautet der Name der neuen Verbindung? " ; read NEW_VPN_NAME
if [ -z $NEW_VPN_PASSWORD ] ; then NEW_VPN_NAME=$(askForVPNName)
echo -n "Wie lautet der VPN-Server? "; read NEW_VPN_HOST
echo -n "Wie lautet die E-Mail des Benutzers? " ; read NEW_VPN_USERNAME
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)
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 : " ; echo -n "Es ist noch kein Passwort im Schlüsselbund hinterlegt Bitte einmal das Passwort angeben : " ;
$GET_NEW_PASS = $(read) NEW_VPN_PASS = $(read )
security add-generic-password -a $NEW_VPN_USERNAME -s openconnect -w $NEW_VPN_PASS
fi fi
echo "$NEW_VPN_NAME,$NEW_VPN_USERNAME,$NEW_VPN_HOST,$NEW_VPN_PUBKEY" #>> $ACCOUNTFILE
;; ;;
esac esac
#if [ -n "$(eval "$VPN_CONNECTED")" ]; then #if [ -n "$(eval "$VPN_CONNECTED")" ]; then
if [ -f $OC_PIDFILE ]; then if [ -f $OC_PIDFILE ]; then
#echo "VPN ✔ | color=green" if [ $SET_ICONS == 'yes']; then echo "| templateImage=$ICON_connected" ; else echo "VPN ✔ |$FONT color=green" ; fi
echo "| templateImage=$ICON_connected" #
echo '---' echo '---'
echo "Disconnect VPN | bash='$0' param1=disconnect terminal=false refresh=true" echo "Disconnect VPN | bash='$0' param1=disconnect terminal=false refresh=true"
echo "User: $(ps -ef | grep -e '--user\ ' | cut -d' ' -f 33)" echo "User: $(ps -ef | grep -e '--user\ ' | cut -d' ' -f 33)"
@ -93,11 +116,10 @@ if [ -f $OC_PIDFILE ]; then
echo "Settings" echo "Settings"
echo "--Farbige Icons aus" echo "--Farbige Icons aus"
echo "--Tunnelblick Icons aus" echo "--Tunnelblick Icons aus"
echo "--Neuen User anlegen| bash='$0' param1=newuser terminal=true refresh=true" echo "--Neuen User anlegen| shell='/Users/$USER/Library/Application\ Support/xbar/plugins/$(basename $0)' param1=newuser terminal=true refresh=true"
exit exit
else else
echo "| templateImage=$ICON_disconnected" if [ $SET_ICONS == 'yes' ] ; then echo "| templateImage=$ICON_disconnected" ; else echo "VPN ❌ | $FONT color=Crimson" ; fi
#echo "VPN ❌ | color=Crimson"
echo '---' echo '---'
# Alle User aus der accounts.csv auslesen und dann zur Auswahl anbieten. # Alle User aus der accounts.csv auslesen und dann zur Auswahl anbieten.
cat "$ACCOUNTFILE" | while IFS= read config; cat "$ACCOUNTFILE" | while IFS= read config;
@ -106,7 +128,7 @@ else
cfgMail=$(echo $config|cut -d',' -f2) cfgMail=$(echo $config|cut -d',' -f2)
cfgHost=$(echo $config|cut -d',' -f3) cfgHost=$(echo $config|cut -d',' -f3)
cfgPubKey=$(echo $config|cut -d',' -f4) cfgPubKey=$(echo $config|cut -d',' -f4)
echo "Connect $cfgName VPN | bash='$0' param1=connect param2=$cfgMail param3=$cfgHost param4=$cfgPubKey terminal=false refresh=true" echo "Connect $cfgName VPN | shell='...$0' param1=connect param2=$cfgMail param3=$cfgHost param4=$cfgPubKey terminal=false refresh=true"
done done
if [[ $SHOW_SETTINGS == "ON" ]]; then if [[ $SHOW_SETTINGS == "ON" ]]; then
@ -115,7 +137,7 @@ else
echo "--$SETTINGSFILE" echo "--$SETTINGSFILE"
echo "--Farbige Icons aus" echo "--Farbige Icons aus"
echo "--Tunnelblick Icons aus" echo "--Tunnelblick Icons aus"
echo "--Neuen User anlegen| bash='$0' param1=newuser terminal=true refresh=true" echo "--Neuen User anlegen| bash=$0 param1=newuser terminal=true refresh=true"
fi fi
exit exit
fi fi