Skip to content

Instantly share code, notes, and snippets.

@spencerbutler
Created September 21, 2018 00:25
Show Gist options
  • Save spencerbutler/79281a6e4d2771d7b6b5e4ff23fd52ba to your computer and use it in GitHub Desktop.
Save spencerbutler/79281a6e4d2771d7b6b5e4ff23fd52ba to your computer and use it in GitHub Desktop.
#!/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