Compare commits
29 Commits
4dd92e3427
...
main
Author | SHA1 | Date | |
---|---|---|---|
a757d917b4 | |||
fd38c8b47d | |||
6aa1cfda8e | |||
![]() |
4dfd9e8ccf | ||
![]() |
c4339873f5 | ||
![]() |
3af7e917e2 | ||
49505ffa7e | |||
780622e6e9 | |||
06712dddc9 | |||
ccbc6a94da | |||
![]() |
b40a491e11 | ||
6f2c85c982 | |||
4c2eacb8ca | |||
03b4d45695 | |||
b437ec4f4e | |||
b56dbd03ae | |||
e684a05392 | |||
2c6221d182 | |||
f7714f24aa | |||
8280db2ba5 | |||
26daa798d9 | |||
e570f401ca | |||
![]() |
b6240894a1 | ||
![]() |
65cbe6cfb2 | ||
![]() |
ad38a0db29 | ||
![]() |
0a1af03f9d | ||
![]() |
60126dc275 | ||
![]() |
95479bf28c | ||
![]() |
253b5867ea |
33
README.md
33
README.md
@@ -1,4 +1,4 @@
|
|||||||
# OpenFortiVPN_macOS
|
# OpenConnect_macOS_Bar
|
||||||
|
|
||||||
Enthält Skripte, mit denen man unter macOS und evtl. unter Linux eine Verbindung zum VPN aufbauen kann.
|
Enthält Skripte, mit denen man unter macOS und evtl. unter Linux eine Verbindung zum VPN aufbauen kann.
|
||||||
|
|
||||||
@@ -6,6 +6,12 @@ Voraussetzung dafür sind die Tools openconnect und xbar
|
|||||||
|
|
||||||
Diese lassen sich einfach über [Homebrew](https://brew.sh/) installieren.
|
Diese lassen sich einfach über [Homebrew](https://brew.sh/) installieren.
|
||||||
|
|
||||||
|
## Installation des Tools (Skript)
|
||||||
|
```bash
|
||||||
|
/bin/bash -c "$(curl -fsSL https://git.bib.de/ITS/OpenConnect_macOS_Bar/raw/branch/main/install.sh)"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Manuelle Installation in Einzelschritten
|
||||||
Zunächst Homebrew installieren, sofern noch nicht geschehen.
|
Zunächst Homebrew installieren, sofern noch nicht geschehen.
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
@@ -13,19 +19,25 @@ Zunächst Homebrew installieren, sofern noch nicht geschehen.
|
|||||||
```
|
```
|
||||||
|
|
||||||
Danach kann man simple die benötigten Tools installieren.
|
Danach kann man simple die benötigten Tools installieren.
|
||||||
|
- [SwiftBar](https://github.com/swiftbar/SwiftBar)
|
||||||
|
- [OpenConnect](https://www.infradead.org/openconnect/)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew update && brew install openconnect xbar
|
brew update && brew install openconnect swiftbar
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Nach der Installation muss man eines der beiden Skripte unter dem folgenden Pfad ablegen und ausführbar machen.
|
Nach der Installation laden wir das Skript und machen es ausführbar.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /Users/$USER/Library/Application\ Support/xbar/plugins
|
# Ordner anlegen, falls noch nicht vorhanden und dann dorhin navigieren
|
||||||
wget https://git.bib.de/itssct/OpenFortiVPN_macOS/raw/branch/main/bibVPN.sh
|
mkdir -p "/Users/$USER/Library/SwiftBar/plugins" && cd $_
|
||||||
|
# Skript laden und ausführbar machen
|
||||||
|
wget https://git.bib.de/ITS/OpenConnect_macOS_Bar/raw/branch/main/bibVPN.sh
|
||||||
chmod +x bibVPN.sh
|
chmod +x bibVPN.sh
|
||||||
|
|
||||||
|
# PluginFolder für SwiftBar setzen
|
||||||
|
defaults write /Users/$USER/Library/Preferences/com.ameba.SwiftBar.plist PluginDirectory "/Users/$USER/Library/SwiftBar/plugins"
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -38,7 +50,12 @@ $USER ALL=(ALL) NOPASSWD: /usr/bin/killall -2 openconnect" | sudo tee /private/e
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Anschließend xbar starten und die erscheinenden Fenster bestätigen. Danach sollte in der Menüleiste das Tool auftauchen.
|
Anschließend SwiftBar starten und die erscheinenden Fenster bestätigen.
|
||||||
|
Für den PluginOrdner bitte, dann im Userverzeichnis `Library/Application Support/SwiftBar/plugins`auswählen.
|
||||||
|
Danach sollte in der Menüleiste das Tool auftauchen.
|
||||||
```zsh
|
```zsh
|
||||||
open /Applications/xbar.app
|
open /Applications/SwiftBar.app
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Es sollte nun das Menüicon auftauchen.
|
||||||
|

|
327
bibVPN.sh
327
bibVPN.sh
@@ -8,138 +8,289 @@
|
|||||||
#joesmith ALL=(ALL) NOPASSWD: /usr/bin/killall -2 openconnect
|
#joesmith ALL=(ALL) NOPASSWD: /usr/bin/killall -2 openconnect
|
||||||
|
|
||||||
# <xbar.title>VPN Status</xbar.title>
|
# <xbar.title>VPN Status</xbar.title>
|
||||||
# <xbar.version>v1.1</xbar.version>
|
# <xbar.version>v1.3</xbar.version>
|
||||||
# <xbar.author>Jesse Jarzynka</xbar.author>
|
# <xbar.author>Thomas Schmauder</xbar.author>
|
||||||
# <xbar.author.github>jessejoe</xbar.author.github>
|
# <xbar.author.github>itssct</xbar.author.github>
|
||||||
# <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>
|
||||||
|
# <xbar.dependencies>openconnect</xbar.dependencies>
|
||||||
mkdir -p "/Users/$USER/.log/"
|
# <xbar.about>https://git.bib.de/itssct/OpenFortiVPN_macOS</xbar.about>
|
||||||
logfile="/Users/$USER/.log/bibVPN.log"
|
# <swiftbar.hideAbout>true</swiftbar.hideAbout>
|
||||||
echo -e "\nRun $0 , $(date)" >>$logfile
|
# <swiftbar.hideRunInTerminal>true</swiftbar.hideRunInTerminal>
|
||||||
|
# <swiftbar.hideLastUpdated>false</swiftbar.hideLastUpdated>
|
||||||
|
# <swiftbar.hideDisablePlugin>true</swiftbar.hideDisablePlugin>
|
||||||
|
# <swiftbar.hideSwiftBar>true</swiftbar.hideSwiftBar>
|
||||||
|
###################
|
||||||
|
#### Variables ####
|
||||||
|
###################
|
||||||
|
VERSION='1.5.1'
|
||||||
|
WORKDIR="/Users/$USER/.openconnect"
|
||||||
|
mkdir -p $WORKDIR
|
||||||
|
LOG="$WORKDIR/bibVPN.log"
|
||||||
|
ERRORLOG="$WORKDIR/ERROR.log"
|
||||||
|
echo -e "\nStart: $(date)" >>$LOG
|
||||||
|
echo "Run $0 $@" >> $LOG
|
||||||
PATH=$PATH:/usr/local/bin
|
PATH=$PATH:/usr/local/bin
|
||||||
VPN_EXECUTABLE=$(which openconnect)
|
VPN_EXECUTABLE=$(which openconnect)
|
||||||
VPN_HOST="$3"
|
OC_PIDFILE="$WORKDIR/vpn.bib.de.pid"
|
||||||
|
SETTINGSFILE="$WORKDIR/settings.txt"
|
||||||
|
ACCOUNTFILE="$WORKDIR/accounts.csv"
|
||||||
VPN_USERNAME="$2"
|
VPN_USERNAME="$2"
|
||||||
#DIR=$(dirname "${BASH_SOURCE[0]}")
|
VPN_HOST="$3"
|
||||||
DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
|
||||||
OC_PIDFILE="/var/run/openconnect/vpn.bib.de.pid"
|
|
||||||
SETTINGSFILE="$DIR/settings.csv"
|
|
||||||
ACCOUNTFILE="$DIR/accounts.csv"
|
|
||||||
SHOW_SETTINGS='ON'
|
|
||||||
SET_ICONS='no'
|
|
||||||
NET_FILTER='172.[123][0-9].1[67][80].'
|
|
||||||
FONT=( 'size=14' 'font=UbuntuMono' )
|
|
||||||
# Icons
|
|
||||||
ICON_connected="iVBORw0KGgoAAAANSUhEUgAAABgAAAAWCAYAAAGtemweAAAACXBIWXMAAAsSAAALEgHS3X78AAAA+klEQVR4nNRUwQ2DMAzMKy8WYIZOwb8LtUtAJSZp34zBCn3y4Y3cWLEr13KSllKhnnRKcvHZ4AScS6BJbUSMgRCncfJcaBG0KMcvMIj83ircWcUh9VTI46onO1A75sC2FIjpT0qHwMUy4AZSzuU6a7D2smDzLRu1Fi11aKRGJOHVyzKHlGExXu5MmlkJ6HpfRHbWx5SBR+tMtjNYOuQMfGV5Lecm8HSLQf8BH9iLC2BxoRiM/Qi9SnSlS1MRG9VLIM/bH4NM7Cgp/rImYkeaU4XQW8QsDBVpk9GeSRRnDb1FyCSWVtovYpcCtZG83rLALzwvuKskSNT2xwMAAP//L6vzxgAAAAJJREFUAwBX1u55AAAAAElFTkSuQmCC"
|
|
||||||
ICON_disconnected="iVBORw0KGgoAAAANSUhEUgAAABgAAAAWCAYAAAGtemweAAAACXBIWXMAAAsSAAALEgHS3X78AAAA2klEQVR4nNxTQQ6DMAyrqvGAXfeK7Uh5wHbgyhlxaP//hDXClbLOXUHqhDZLFsGJEzUUYwq4lBIrpsiwhirQEDHxRSw69mFU/a1OJNHh+ZYILMHibThjHUtkXyuU9tdMD5GeGSQh1LF+/2hguQPRY0MTFlGEzQ6bOJYMnhzuBo1OCrjejqx0KhnSk32TdgamhyaGP4SNHNQFYPSokdpdGLJGd1yaDpT4kdWIZ/PPoBsLTriRM+igmWyQeKtYlKGDNpP1iGZQkzTxVqGbMK2Wr+KQAU09Xx/wW3gCAAD//+SvwXMAAAACSURBVAMAV9bueQAAAABJRU5ErkJggg=="
|
|
||||||
# A command that will result in your VPN password. Recommend using
|
|
||||||
# "security find-generic-password -g -a foo" where foo is an account
|
|
||||||
# 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"
|
|
||||||
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
|
|
||||||
local $keychainPW = $(read "Wie lautet das Password für den Benutzer $VPN_USERNAME ?")
|
|
||||||
security add-generic-password -a $VPN_USERNAME -s openconnect -w $keychainPW
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Command to determine if VPN is connected or disconnected
|
#### Settings ####
|
||||||
VPN_CONNECTED="ifconfig | egrep -A1 'inet $NET_FILTER' |cut -d' ' -f2"
|
SHOW_SETTINGS='true'
|
||||||
# Command to run to disconnect VPN
|
SHOW_ICON='true'
|
||||||
VPN_DISCONNECT_CMD="sudo killall -2 openconnect"
|
SHOW_COLOR='true'
|
||||||
# Get IP of Current VPN Tunnel
|
DEBUG_OUTPUT='false'
|
||||||
IP=$(ifconfig | egrep -A1 'inet $NET_FILTER' |cut -d' ' -f2)
|
NET_FILTER='inet 172.[123][0-9].1[67][80].'
|
||||||
|
|
||||||
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"' )
|
#### Functions ####
|
||||||
|
###################
|
||||||
|
function saveSettings(){
|
||||||
|
echo "Speichere die Einstellungen" >> $LOG
|
||||||
|
echo "SHOW_SETTINGS='$SHOW_SETTINGS'
|
||||||
|
SHOW_ICON='$SHOW_ICON'
|
||||||
|
SHOW_COLOR='$SHOW_COLOR'
|
||||||
|
DEBUG_OUTPUT=$DEBUG_OUTPUT" | tee $SETTINGSFILE
|
||||||
|
|
||||||
|
echo "Lade die Einstellungsdatei" >> $LOG
|
||||||
|
source $SETTINGSFILE
|
||||||
|
open swiftbar://refreshplugin?name=$(basename $0)
|
||||||
|
}
|
||||||
|
|
||||||
theButton=$( echo "$results" | /usr/bin/awk -F "button returned:|," '{print $2}' )
|
function askFor(){
|
||||||
theText=$( echo "$results" | /usr/bin/awk -F "text returned:" '{print $2}' )
|
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 >> $LOG
|
||||||
|
results=$( /usr/bin/osascript -e "$osascript")
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
clmsg='display notification "" with title "OpenConnectVPN" subtitle "Beende mich" sound name "Submarine"'
|
||||||
|
osascript -e "$clmsg"
|
||||||
|
exit 2
|
||||||
|
else
|
||||||
|
#echo $results >> $LOG
|
||||||
|
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
|
if [[ $theButton == "OK" ]] ;then
|
||||||
echo $theText;
|
if [ -z $theText ];then
|
||||||
|
echo "OK"
|
||||||
|
else
|
||||||
|
echo $theText
|
||||||
|
fi
|
||||||
|
elif [[ $theButton == "Cancel" ]] ; then
|
||||||
|
clmsg='display notification "" with title "OpenConnectVPN" subtitle "Beende mich" sound name "Submarine"'
|
||||||
|
osascript -e "$clmsg"
|
||||||
|
break
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showSettings()
|
||||||
|
{
|
||||||
|
echo '---'
|
||||||
|
echo "Neues **VPN** Profil anlegen | shell='$0' param1=newuser terminal=false refresh=true md=true"
|
||||||
|
if [[ $SHOW_SETTINGS == "true" ]]; then
|
||||||
|
echo "---"
|
||||||
|
echo "Settings"
|
||||||
|
echo "--Icons verwenden | shell='$0' terminal=false param1=toggleIcon tooltip='Icon im Menü anzeigen oder Text' checked=$SHOW_ICON"
|
||||||
|
echo "--Farbiges Icon/Schrift | shell='$0' terminal=false param1=toggleColor tooltip='Icon oder Schrift einfärben oder eintönig lassen' checked=$SHOW_COLOR"
|
||||||
|
echo "---"
|
||||||
|
echo "-- --- INFOS ---"
|
||||||
|
echo "--**Logfile:** *${LOG}* | shell='$0' param1=openlog terminal=false refresh=true tooltip='Das Logfile öffnen' md=true"
|
||||||
|
echo "--${SETTINGSFILE} | shell='$0' param1=openDIR terminal=false refresh=true tooltip='Ordner öffnen'"
|
||||||
|
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"
|
||||||
|
if [[ $DEBUG_OUTPUT == 'true' ]] ; then
|
||||||
|
echo "-- --- DEBUG ---"
|
||||||
|
echo "--SHOW_ICON: $SHOW_ICON"
|
||||||
|
echo "--SHOW_COLOR: $SHOW_COLOR"
|
||||||
|
echo "--COLOR_CONNECTED: $COLOR_CONNECTED"
|
||||||
|
echo "--COLOR_UNCONNECTED: $COLOR_UNCONNECTED"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
###################
|
||||||
|
#### Prüfungen ####
|
||||||
|
###################
|
||||||
|
if [ -f $SETTINGSFILE ] ; then
|
||||||
|
echo "Lade die Einstellungsdatei" >> $LOG
|
||||||
|
source $SETTINGSFILE
|
||||||
|
else
|
||||||
|
saveSettings
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $SHOW_COLOR == 'true' ] ; then
|
||||||
|
COLOR_CONNECTED='green'
|
||||||
|
COLOR_UNCONNECTED='crimson'
|
||||||
|
else
|
||||||
|
COLOR_CONNECTED='none'
|
||||||
|
COLOR_UNCONNECTED='none'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# A command that will result in your VPN password.
|
||||||
|
GET_VPN_PASSWORD="security find-generic-password -w -l openconnect -a $VPN_USERNAME 2>&1"
|
||||||
|
# Command to determine if VPN is connected or disconnected
|
||||||
|
VPN_CONNECTED="ifconfig | egrep -A1 '$NET_FILTER' |cut -d' ' -f2"
|
||||||
|
# Command to run to disconnect VPN
|
||||||
|
VPN_DISCONNECT_CMD="sudo killall -2 openconnect"
|
||||||
|
|
||||||
|
# Get IP of Current VPN Tunnel
|
||||||
|
IP=$(ifconfig | egrep -A1 "$NET_FILTER" |cut -d' ' -f2)
|
||||||
|
|
||||||
|
###################
|
||||||
|
###### MAIN #######
|
||||||
|
###################
|
||||||
case "$1" in
|
case "$1" in
|
||||||
connect)
|
connect)
|
||||||
|
rm -f $ERRORLOG
|
||||||
|
echo "$GET_VPN_PASSWORD" >> $LOG
|
||||||
VPN_PASSWORD=$(eval "$GET_VPN_PASSWORD")
|
VPN_PASSWORD=$(eval "$GET_VPN_PASSWORD")
|
||||||
VPN_EXECUTABLE_PARAMS="--servercert $4 --protocol=fortinet" # Optional
|
# Passwort checken
|
||||||
# VPN connection command, should eventually result in $VPN_CONNECTED,
|
if [[ $VPN_PASSWORD =~ 'item could not be found in the keychain.' ]] ; then
|
||||||
# may need to be modified for VPN clients other than openconnect
|
echo "Es konnte kein Passwort für $VPN_USERNAME gefunden werden" >> $LOG
|
||||||
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
|
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" | sudo $VPN_EXECUTABLE $VPN_EXECUTABLE_PARAMS --user $VPN_USERNAME --passwd-on-stdin $VPN_HOST --pid-file=$OC_PIDFILE --background > $logfile 2>&1
|
if [[ $? != 0 ]]; then exit 2 ; fi # Beim Abbruch der Maske, gesamte Script beenden.
|
||||||
|
#echo $VPN_PASSWORD
|
||||||
IP=$(ifconfig | egrep -A1 'inet $NET_FILTER' |cut -d' ' -f2)
|
VPN_PASSWORD=$NEW_VPN_PASSWORD
|
||||||
while [ -z $IP ]; do echo "noch keine IP" ; sleep 0.5 ; IP=$(ifconfig | egrep -A1 'inet $NET_FILTER' |cut -d' ' -f2) ; done
|
#echo "security add-generic-password -a $VPN_USERNAME -s openconnect -w '$VPN_PASSWORD'" >> $LOG
|
||||||
msg='display notification "Erfolgreich verbunden \nConnected User: '$VPN_USERNAME'" with title "OpenFortiVPN" subtitle "Deine IP lautet: '$IP'" sound name "Brise"'
|
SAVE_PASSWORD=$(askFor 'display dialog "Soll das Passwort, dauerhaft im Schlüsselbund gespeichert werden? "')
|
||||||
errmsg='display notification "Verbindungsversuch nicht erfolgreich" with title "OpenFortiVPN" subtitle "Schade" sound name "Brise"'
|
if [[ $SAVE_PASSWORD == "OK" ]]; then
|
||||||
if [[ $IP =~ 172 ]] ; then osascript -e "$msg" ; else osascript -e "$errmsg" ; fi
|
security add-generic-password -a $VPN_USERNAME -s openconnect -T /usr/bin/security -w "$NEW_VPN_PASSWORD"
|
||||||
|
fi
|
||||||
|
#else
|
||||||
|
#echo "VPN PASSWORT: $VPN_PASSWORD" >> $LOG
|
||||||
|
fi
|
||||||
|
VPN_EXECUTABLE_PARAMS="--passwd-on-stdin --servercert $4 --protocol=fortinet --pid-file=$OC_PIDFILE --background" # Optional
|
||||||
|
|
||||||
|
# Verbindung aufbauen
|
||||||
|
echo "<pseudoPasswort>| sudo $VPN_EXECUTABLE $VPN_EXECUTABLE_PARAMS --user $VPN_USERNAME $VPN_HOST" >> $LOG
|
||||||
|
echo "$VPN_PASSWORD" | sudo $VPN_EXECUTABLE $VPN_EXECUTABLE_PARAMS --user $VPN_USERNAME $VPN_HOST 2> $ERRORLOG 1>> $LOG
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
if [ -f $ERRORLOG ] ; then
|
||||||
|
cat $ERRORLOG >> $LOG
|
||||||
|
if grep -q "None of the 1 fingerprint(s) specified via --servercert match server's certificate:" $ERRORLOG ; then
|
||||||
|
newServerCert=$(grep -o 'pin-.*=$' $ERRORLOG)
|
||||||
|
echo "Das Servercert ist nicht aktuell. Dieses muss aktualisiert werden. (ALT: $4 | NEU: $newServerCert)" >> $LOG
|
||||||
|
dialogCert=$(osascript -e "display alert \"Das Servercert ist nicht aktuell. \nSoll dieses aktualisiert werden?\n\nAlt : \n$4\n\nNeu : \n$newServerCert\" buttons {\"Nein\", \"Ja\"}")
|
||||||
|
theButton=$( echo "$dialogCert" | /usr/bin/awk -F "button returned:|," '{print $2}' )
|
||||||
|
if [[ $theButton == "Ja" ]] ;then
|
||||||
|
echo "Ändere das Servercert" >> $LOG
|
||||||
|
# sed mit | statt / , da im String auch Slashes vorhanden sein können.
|
||||||
|
echo "sed -i '' -e \"s|$4|$newServerCert|g\" $ACCOUNTFILE" >> $LOG
|
||||||
|
sed -i '' -e "s|$4|$newServerCert|g" $ACCOUNTFILE
|
||||||
|
if [[ $? = 0 ]]; then
|
||||||
|
osascript -e 'display alert "Erfolgreich geändert. Bitte die Verbindung erneut aufbauen."'
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Wie du willst. Das Servercert wird nicht geändert." >> $LOG
|
||||||
|
fi
|
||||||
|
elif grep -q "nodename nor servname provided, or not known" $ERRORLOG; then
|
||||||
|
echo "Verbindungsaufbau fehlgeschlagen. $VPN_HOST kann nicht aufgelöst werden." >> $LOG
|
||||||
|
osascript -e "display notification \"Verbindungsaufbau fehlgeschlagen. $VPN_HOST kann nicht aufgelöst werden.\" with title \"OpenConnectVPN\" subtitle \"Schade\" sound name \"Brise\""
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
osascript -e 'display notification "Verbindungsaufbau fehlgeschlagen. Bitte im Log prüfen, was die Ursache ist." with title "OpenConnectVPN" subtitle "Schade" sound name "Brise"'
|
||||||
|
fi
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
IP=$(ifconfig | egrep -A1 "$NET_FILTER" |cut -d' ' -f2)
|
||||||
|
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 "OpenConnectVPN" subtitle "Deine IP lautet: '$IP'" sound name "Brise"'
|
||||||
|
errmsg='display notification "Verbindungsversuch nicht erfolgreich. Vermutlich ist das Passwort falsch." with title "OpenConnectVPN" subtitle "Schade" sound name "Brise"'
|
||||||
|
if [[ $IP =~ 172 ]] ; then
|
||||||
|
osascript -e "$msg" ;
|
||||||
|
else
|
||||||
|
osascript -e "$errmsg"
|
||||||
|
echo "Vermutlich ist das Passwort falsch. Es konnte keine Verbindung hergestellt werden." >> $LOG
|
||||||
|
exit 5 ;
|
||||||
|
fi
|
||||||
# Wait for connection so menu item refreshes instantly
|
# Wait for connection so menu item refreshes instantly
|
||||||
until eval "$VPN_CONNECTED"; do sleep 1; done
|
until eval "$VPN_CONNECTED"; do sleep 1; done
|
||||||
;;
|
;;
|
||||||
disconnect)
|
disconnect)
|
||||||
eval "$VPN_DISCONNECT_CMD"
|
eval "$VPN_DISCONNECT_CMD"
|
||||||
# Wait for disconnection so menu item refreshes instantly
|
# Wait for disconnection so menu item refreshes instantly
|
||||||
until [ -z "$(eval "$VPN_CONNECTED")" ]; do sleep 1; done
|
until [ -z "$(eval "$VPN_CONNECTED")" ]; do sleep 1; eval "$VPN_CONNECTED" ;done
|
||||||
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 "OpenConnectVPN" subtitle "Mach Feierabend" sound name "Submarine"'
|
||||||
;;
|
;;
|
||||||
newuser)
|
newuser)
|
||||||
echo "Sie wollen einen weiteren Benutzer für das VPN anlegen. Geben Sie dazu die folgenden Dinge ein."
|
#echo "Sie wollen einen weiteren Benutzer für das VPN anlegen. Geben Sie dazu die folgenden Dinge ein."
|
||||||
#echo -n "Wie lautet der Name der neuen Verbindung? " ; read NEW_VPN_NAME
|
askFor 'display dialog "Sie wollen einen weiteren Benutzer für das VPN anlegen. Geben Sie dazu die benötigten Daten an."'
|
||||||
NEW_VPN_NAME=$(askForVPNName)
|
NEW_VPN_NAME=$(askFor 'display dialog "Wie soll die neue Verbindung heißen?" default answer "bib | eduUP | FHDW"' ); if [[ $? != 0 ]]; then exit 2 ; fi # Beim Abbruch der Maske, gesamte Script beenden.
|
||||||
echo -n "Wie lautet der VPN-Server? "; read NEW_VPN_HOST
|
NEW_VPN_USERNAME=$(askFor 'display dialog "Wie lautet die E-Mail des Benutzers, der zum Verbinden verwendet werden soll?" default answer "vorname.nachname@bib.de"' ); if [[ $? != 0 ]]; then exit 2 ; fi
|
||||||
echo -n "Wie lautet die E-Mail des Benutzers? " ; read NEW_VPN_USERNAME
|
NEW_VPN_HOST=$(askFor 'display dialog "Wie lautet der Servername?" default answer "vpn.bib.de"'); if [[ $? != 0 ]]; then exit 2 ; fi
|
||||||
|
if [[ -z $NEW_VPN_NAME ]] ; then echo -n "Wie lautet der Name der neuen Verbindung? " ; read NEW_VPN_NAME ; fi
|
||||||
|
if [[ -z $NEW_VPN_HOST ]] ; then echo -n "Wie lautet der VPN-Server? "; read NEW_VPN_HOST ; fi
|
||||||
|
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_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 ) # >>$LOG) #>/dev/null)
|
||||||
if [[ $NEW_VPN_PASSWORD =~ password ]] ; then
|
if [[ $NEW_VPN_PASSWORD =~ password ]] ; then
|
||||||
echo "Es ist bereits ein Passwort im Schlüsselbund für $NEW_VPN_USERNAME hinterlegt."
|
echo "Es ist bereits ein Passwort im Schlüsselbund für $NEW_VPN_USERNAME hinterlegt."
|
||||||
else
|
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 : " ;
|
||||||
NEW_VPN_PASS = $(read )
|
NEW_VPN_PASSWORD=$(askFor 'display dialog "Es ist kein Passwort im Schlüsselbund vorhanden. Wie lautet das Passwort? " default answer "Mein Passwort..." with hidden answer')
|
||||||
security add-generic-password -a $NEW_VPN_USERNAME -s openconnect -w $NEW_VPN_PASS
|
SAVE_PASSWORD=$(askFor 'display dialog "Soll das Passwort, dauerhaft im Schlüsselbund gespeichert werden? "')
|
||||||
|
if [[ $SAVE_PASSWORD == "OK" ]] ; then
|
||||||
|
security add-generic-password -a $NEW_VPN_USERNAME -s openconnect -w $NEW_VPN_PASSWORD
|
||||||
|
fi
|
||||||
fi
|
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" >> $LOG >> $ACCOUNTFILE
|
||||||
|
# Refreshen, damit das Profil direkt angezeigt wird.
|
||||||
|
open swiftbar://refreshplugin?name=$(basename $0)
|
||||||
|
osascript -e 'display notification "VPN Profil '$NEW_VPN_NAME' erfolgreich angelegt" with title "OpenVPN" subtitle "'$NEW_VPN_HOST' - '$NEW_VPN_USERNAME'" sound name "Brise"'
|
||||||
|
;;
|
||||||
|
openlog)
|
||||||
|
open -a console $LOG
|
||||||
|
;;
|
||||||
|
openDIR)
|
||||||
|
open ${WORKDIR}
|
||||||
|
;;
|
||||||
|
toggleColor)
|
||||||
|
if [ $SHOW_COLOR == 'false' ];then SHOW_COLOR='true';else SHOW_COLOR='false' ; fi
|
||||||
|
echo "Switche den Farbmodus ($SHOW_COLOR)" >> $LOG
|
||||||
|
saveSettings
|
||||||
|
;;
|
||||||
|
toggleIcon)
|
||||||
|
if [ $SHOW_ICON == 'false' ];then SHOW_ICON='true';else SHOW_ICON='false' ; fi
|
||||||
|
echo "Switche den Iconmodus ($SHOW_ICON)" >> $LOG
|
||||||
|
saveSettings
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
#if [ -n "$(eval "$VPN_CONNECTED")" ]; then
|
|
||||||
if [ -f $OC_PIDFILE ]; then
|
if [ -f $OC_PIDFILE ]; then
|
||||||
if [ $SET_ICONS == 'yes']; then echo "| templateImage=$ICON_connected" ; else echo "VPN ✔ |$FONT color=green" ; fi
|
if [ $SHOW_ICON == 'true' ]; then echo ":firewall.fill:| sfcolor=$COLOR_CONNECTED sfsize=17" ; else echo "VPN ✔ | color=$COLOR_CONNECTED" ; fi
|
||||||
#
|
|
||||||
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)"
|
aUser=$(ps -ef | grep -e '--user\ ' | cut -d' ' -f 32)
|
||||||
|
if [[ $aUser =~ .*@.* ]]; then echo "User: $aUser" ; fi
|
||||||
echo "IP: $IP"
|
echo "IP: $IP"
|
||||||
echo "---"
|
pidTime=$(stat $OC_PIDFILE | cut -d'"' -f4)
|
||||||
echo "Settings"
|
|
||||||
echo "--Farbige Icons aus"
|
|
||||||
echo "--Tunnelblick Icons aus"
|
startZeit=$(date -j -f "%b %d %H:%M:%S %Y" "$pidTime" +%s)
|
||||||
echo "--Neuen User anlegen| shell='/Users/$USER/Library/Application\ Support/xbar/plugins/$(basename $0)' param1=newuser terminal=true refresh=true"
|
now=$(date +%s)
|
||||||
|
seitZeit="$(( (now-startZeit) ))"
|
||||||
|
echo "Verbunden seit: $pidTime ($seitZeit Sek ~ $(( seitZeit/60 )) Min) "
|
||||||
|
showSettings
|
||||||
exit
|
exit
|
||||||
else
|
else
|
||||||
if [ $SET_ICONS == 'yes' ] ; then echo "| templateImage=$ICON_disconnected" ; else echo "VPN ❌ | $FONT color=Crimson" ; fi
|
if [ $SHOW_ICON == 'true' ] ; then echo ":firewall:| sfcolor=$COLOR_UNCONNECTED sfsize=17" ; else echo "VPN X | color=$COLOR_UNCONNECTED" ; fi
|
||||||
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;
|
||||||
do
|
do
|
||||||
|
[[ $config =~ ^#.* ]] && continue
|
||||||
cfgName=$(echo $config|cut -d',' -f1)
|
cfgName=$(echo $config|cut -d',' -f1)
|
||||||
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 | shell='...$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
|
||||||
|
showSettings
|
||||||
if [[ $SHOW_SETTINGS == "ON" ]]; then
|
|
||||||
echo "---"
|
|
||||||
echo "Settings"
|
|
||||||
echo "--$SETTINGSFILE"
|
|
||||||
echo "--Farbige Icons aus"
|
|
||||||
echo "--Tunnelblick Icons aus"
|
|
||||||
echo "--Neuen User anlegen| bash=$0 param1=newuser terminal=true refresh=true"
|
|
||||||
fi
|
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#if [ -f $OC_PIDFILE ]; then
|
|
||||||
|
40
install.sh
Normal file
40
install.sh
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Author : Thomas Schmauder, bib e.V.
|
||||||
|
# Datum : 2023-03-16
|
||||||
|
# Funktion : Installiere alle benötigten Module, um das VPN über die Menübar in macOS zu steuern.
|
||||||
|
# Grund : Schlanke Alternative zum fetten FortiClient VPN Only
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
PLUGINDIR='/Users/'$USER'/Library/SwiftBar/plugins'
|
||||||
|
# Farben definieren
|
||||||
|
noColor="\033[0m";
|
||||||
|
Purple='\033[0;35m'
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
echo -e "${Purple}Checke, ob HomeBrew verfügbar ist${noColor}"
|
||||||
|
if ! which brew > /dev/null ; then
|
||||||
|
echo -e "${Purple}Homebrew nicht verfügbar. Installiere...${noColor}"
|
||||||
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${Purple}Starte die Installation der benötigten Komponenten (SwiftBar & OpenConnect)${noColor}"
|
||||||
|
brew update && brew install openconnect swiftbar
|
||||||
|
|
||||||
|
# Konfiguration
|
||||||
|
echo -e "${Purple}Lade das Skript und stelle die Konfiguration für SwiftBar ein.${noColor}"
|
||||||
|
|
||||||
|
mkdir -p $PLUGINDIR && cd $PLUGINDIR
|
||||||
|
defaults write com.ameba.SwiftBar.plist PluginDirectory $PLUGINDIR
|
||||||
|
wget https://git.bib.de/ITS/OpenConnect_macOS_Bar/raw/branch/main/bibVPN.sh
|
||||||
|
chmod +x bibVPN.sh
|
||||||
|
|
||||||
|
# SecuritySettings
|
||||||
|
echo -e "${Purple}Setze die Security Einstellungen, damit man nicht immer nach dem Passwort gefragt wird.\nBitte dazu einmalig das Passwort für deinen Mac eingeben.${noColor}"
|
||||||
|
echo "$USER ALL=(ALL) NOPASSWD: $(which openconnect)
|
||||||
|
$USER ALL=(ALL) NOPASSWD: /usr/bin/killall -2 openconnect" | sudo tee /private/etc/sudoers.d/openconnect
|
||||||
|
|
||||||
|
# Erstmaliger Start vom Skript und SwiftBar
|
||||||
|
echo -e "${Purple}Starte nun das Skript erstmalig, um einen neuen Benutzer anzulegen.${noColor}"
|
||||||
|
$PLUGINDIR/bibVPN.sh newuser
|
||||||
|
|
||||||
|
open /Applications/SwiftBar.app
|
BIN
menubar.png
Normal file
BIN
menubar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 60 KiB |
68
v1.sh
68
v1.sh
@@ -1,68 +0,0 @@
|
|||||||
#!/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: /usr/local/bin/openconnect
|
|
||||||
#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_EXECUTABLE=$(which openconnect)
|
|
||||||
VPN_EXECUTABLE_PARAMS="--servercert pin-sha256:NFR9+lG+7SvvEqnraijD1l5R1ShK9KKtwYjqedfx78U= --protocol=fortinet" # Optional
|
|
||||||
VPN_HOST="vpn.bib.de"
|
|
||||||
VPN_USERNAME="$2"
|
|
||||||
# A command that will result in your VPN password. Recommend using
|
|
||||||
# "security find-generic-password -g -a foo" where foo is an account
|
|
||||||
# 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"
|
|
||||||
MEINE_MAIL="meine.mail@edu-up.de"
|
|
||||||
# Command to determine if VPN is connected or disconnected
|
|
||||||
VPN_CONNECTED="ifconfig | egrep -A1 'inet 172.[123][0-9]' |cut -d' ' -f2"
|
|
||||||
# Command to run to disconnect VPN
|
|
||||||
VPN_DISCONNECT_CMD="sudo killall -2 openconnect"
|
|
||||||
# Get IP of Current VPN Tunnel
|
|
||||||
IP=$(ifconfig | egrep -A1 'inet 172.[123][0-9]' |cut -d' ' -f2)
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
connect)
|
|
||||||
VPN_PASSWORD=$(eval "$GET_VPN_PASSWORD")
|
|
||||||
# VPN connection command, should eventually result in $VPN_CONNECTED,
|
|
||||||
# may need to be modified for VPN clients other than openconnect
|
|
||||||
echo "$VPN_PASSWORD" | sudo "$VPN_EXECUTABLE" $VPN_EXECUTABLE_PARAMS --user "$VPN_USERNAME" --passwd-on-stdin "$VPN_HOST" &> /dev/null &
|
|
||||||
|
|
||||||
IP=$(ifconfig | egrep -A1 'inet 172.[123][0-9]' |cut -d' ' -f2)
|
|
||||||
while [ -z $IP ]; do 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"'
|
|
||||||
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
|
|
||||||
# Wait for connection so menu item refreshes instantly
|
|
||||||
until eval "$VPN_CONNECTED"; do sleep 1; done
|
|
||||||
;;
|
|
||||||
disconnect)
|
|
||||||
eval "$VPN_DISCONNECT_CMD"
|
|
||||||
# Wait for disconnection so menu item refreshes instantly
|
|
||||||
until [ -z "$(eval "$VPN_CONNECTED")" ]; do sleep 1; done
|
|
||||||
osascript -e 'display notification "VPN Tunnel erfolgreich geschlossen" with title "OpenFortiVPN" subtitle "Mach Feierabend" sound name "Submarine"'
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ -n "$(eval "$VPN_CONNECTED")" ]; then
|
|
||||||
echo "VPN ✔ | color=green"
|
|
||||||
echo '---'
|
|
||||||
echo "Disconnect VPN | bash='$0' param1=disconnect terminal=false refresh=true"
|
|
||||||
echo "User: $(ps -ef | grep -e '--user\ ' | cut -d' ' -f 33)"
|
|
||||||
echo "IP: $IP"
|
|
||||||
exit
|
|
||||||
else
|
|
||||||
echo "VPN ❌ | color=red"
|
|
||||||
echo '---'
|
|
||||||
echo "Connect VPN | bash='$0' param1=connect param2=$MEINE_MAIL terminal=false refresh=true"
|
|
||||||
exit
|
|
||||||
fi
|
|
Reference in New Issue
Block a user