Created
September 21, 2018 00:25
-
-
Save spencerbutler/79281a6e4d2771d7b6b5e4ff23fd52ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ ! $1 ]; then | |
echo "What VPN do you want to connect to?" | |
echo "Usage: $(basename $0) <changeme|anotherserver>" | |
exit | |
fi | |
if [ $(id -u) -ne 0 ]; then | |
echo 'use root' | |
exit | |
fi | |
host="$1" | |
luser=your-local-user | |
ruser=your-remote-user | |
server= | |
ctl= | |
case $host in | |
changeme) | |
server="${host}.example.net" | |
ctl=vpn_changme_example_net | |
;; | |
anotherserver) | |
server="${host}.example.net" | |
ctl=vpn_anotherserver_example_net | |
;; | |
esac | |
config="/var/lib/connman-vpn/${host}.config" | |
conn="/tmp/${host}.conn" | |
/usr/sbin/openconnect --setuid ${luser} --authenticate --user ${ruser} ${server} > ${conn} | |
cookie="$(grep COOKIE ${conn} | cut -d '=' -f 2-)" | |
finger="$(grep FINGERPRINT ${conn} | cut -d '=' -f 2)" | |
sed -i -e "s#\(OpenConnect.Cookie=\).*#\1${cookie}#" \ | |
-e "s#\(OpenConnect.ServerCert=\).*#\1${finger}#" \ | |
-e "s/'//g" ${config} #2>/dev/null | |
/usr/sbin/connmanctl connect ${ctl} | |
rm ${conn} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment