Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
University of Potsdam WLAN-over-VPN wrapper
#!/bin/sh
# University of Potsdam WLAN-over-VPN wrapper
VPNUSER=$(read -p "Username:")
#VPNUSER=johndoe
WLANIFACE=wlan0
VPNIFACE=zeik.tun0
# kill all remaining Cisco AnyConnect VPNs
pkill openconnect
[ "x$1" = "xstop" ] && exit 1
# determine hostname
essid=`iwgetid --raw $WLANIFACE`
case $essid in
"Uni-WLAN-Wohnheim") host=wh group=wohnheim-wlan ;;
"Universitaet Potsdam ZEIK") host=wlan group=WLAN ;;
*) host=ssl group=SSLVPN
ping -c 1 sslvpn.uni-potsdam.de || exit 1 ;;
esac
host=${host}vpn.uni-potsdam.de
# connect to the VPN
echo "Connecting to $host:$group..."
openconnect $host --user=$VPNUSER --authgroup=$group \
--verbose --syslog --background --interface=$VPNIFACE \
&& echo "Connected!"
# route all connections thru the VPN interface
if [ "$host" != "ssl" ]; then
route add default dev $VPNIFACE
else
route add uni-potsdam.de dev $VPNIFACE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment