Skip to content

Instantly share code, notes, and snippets.

@antonengelhardt
Last active April 12, 2023 18:04
Show Gist options
  • Save antonengelhardt/c920a42a1fb8ce9e9f301b57da3b8c59 to your computer and use it in GitHub Desktop.
Save antonengelhardt/c920a42a1fb8ce9e9f301b57da3b8c59 to your computer and use it in GitHub Desktop.
Connect to WWU VPN using openconnect
#!bin/bash
# This script is used to connect to the WWU VPN. It is meant to be used with a
# keyboard shortcut. Change the Constants before running the script.
USER=<put-your-wwu-id-here>
PASSWORD=<put-your-wlan-netzzugangspasswort-here>
OTP_CODE=$(oathtool --totp <put-your-base-16-keimwert-here-get-it-from-wwu-it-portal>
VPN_HOST=vpn.uni-muenster.de
# use openconnect to connect to the VPN
if pgrep openconnect > /dev/null
then
echo "Disconnecting from VPN..."
sudo killall openconnect
else
echo "Connecting to VPN..."
{ echo ${USER}; echo ${PASSWORD}; echo ${OTP_CODE}; } | sudo openconnect -b -q ${VPN_HOST}
fi
@antonengelhardt
Copy link
Author

antonengelhardt commented Mar 13, 2023

GitHub Repo

The script is now being maintained in a GitHub Repo as more contributors joined. Feel free to contribute aswell

Run

To run this script, use sh wwu-vpn.sh

When you are prompted for a password, enter the password which you use to login to your computer.

Before running:

Install tools

Before you run this script, install:

  • openconnect
  • oathtool

With brew:

brew install oath-toolkit; brew install openconnect

Change constants:

At the top of the script, change the values accordingly:

USER=mmuster1
PASSWORD=verysecurepassword
OTP_CODE=$(oathtool --totp 100000000000000000005224)

The Keimwert is displayed in the WWU-IT-Portal when you create your OTP profile. It is the "Keimwert im Base16-Format"

Disconnect

To disconnect, run the script again. It should disconnect you automatically.

To manually disconnect, run: sudo killall openconnect

Feedback & Questions

Feedback and Questions are appreciated

@antonengelhardt
Copy link
Author

Shortcut automation

Get KeySmith.

Recreate this Shortcut:

Screenshot-Keysmith-001308@2x

@antonengelhardt
Copy link
Author

antonengelhardt commented Mar 15, 2023

Aliases in Terminal

Es ist ebenso möglich die Ausführung des Skriptes oder Teile davon in eigene Befehle zu verpacken - Stichwort "Alias"

Alle Befehle erfordern ggfs. das Computer-Passwort.

Der Befehl wwu-vpn-check produziert keine Ausgabe, wenn der VPN nicht aktiv ist und gibt die ID des Prozesses wieder, wenn der VPN aktiv ist.

Für zsh

Datei ~/.zshrc anpassen:

alias wwu-vpn-connect="sh ~/Documents/scripts/wwu-vpn.sh" // Je nachdem wo das Skript liegt
alias wwu-vpn-disconnect="sudo killall openconnect" 
alias wwu-vpn-check="sudo pgrep openconnect"

Für fish

Datei in ~/.config/fish/config.fish

alias wwu-vpn-connect "sh ~/Documents/scripts/wwu-vpn.sh" // Je nachdem wo das Skript liegt
alias wwu-vpn-disconnect "sudo killall openconnect"
alias wwu-vpn-check "sudo pgrep openconnect"

@antonengelhardt
Copy link
Author

The script is now being maintained here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment