2014-07-01 05:43:00 +00:00
|
|
|
#!/bin/bash
|
2014-06-04 18:13:59 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Get an OpenVPN client configuration file
|
|
|
|
#
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
2014-07-01 05:43:00 +00:00
|
|
|
if [ -s "$OPENVPN/server_url" ]; then
|
|
|
|
server_url=$(cat "$OPENVPN/server_url" 2> /dev/null)
|
|
|
|
else
|
|
|
|
# TODO Backwards compatible, need to throw away eventually
|
|
|
|
server_url=$(cat "$OPENVPN/servername" 2> /dev/null)
|
|
|
|
fi
|
2014-06-04 18:13:59 +00:00
|
|
|
|
2014-07-01 05:43:00 +00:00
|
|
|
if [[ "$server_url" =~ ^((udp|tcp)://)?([0-9a-zA-Z\.]+)(:([0-9]+))?$ ]]; then
|
|
|
|
proto=${BASH_REMATCH[2]};
|
|
|
|
servername=${BASH_REMATCH[3]};
|
|
|
|
port=${BASH_REMATCH[5]};
|
|
|
|
else
|
2014-06-04 18:13:59 +00:00
|
|
|
echo "Common name not specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-07-01 05:43:00 +00:00
|
|
|
# Apply defaults
|
|
|
|
[ -z "$proto" ] && proto=1194
|
|
|
|
[ -z "$port" ] && port=udp
|
|
|
|
|
2014-06-04 18:13:59 +00:00
|
|
|
if [ ! -f "$EASYRSA_PKI/private/$cn.key" ]; then
|
|
|
|
easyrsa build-server-full $cn nopass
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
client
|
|
|
|
nobind
|
|
|
|
dev tun
|
|
|
|
redirect-gateway def1
|
2014-06-04 22:38:49 +00:00
|
|
|
remote-cert-tls server
|
2014-06-04 18:13:59 +00:00
|
|
|
|
|
|
|
<key>
|
|
|
|
$(cat $EASYRSA_PKI/private/$cn.key)
|
|
|
|
</key>
|
|
|
|
<cert>
|
|
|
|
$(cat $EASYRSA_PKI/issued/$cn.crt)
|
|
|
|
</cert>
|
|
|
|
<ca>
|
|
|
|
$(cat $EASYRSA_PKI/ca.crt)
|
|
|
|
</ca>
|
|
|
|
<dh>
|
|
|
|
$(cat $EASYRSA_PKI/dh.pem)
|
|
|
|
</dh>
|
2014-06-04 22:34:42 +00:00
|
|
|
<tls-auth>
|
|
|
|
$(cat $EASYRSA_PKI/ta.key)
|
|
|
|
</tls-auth>
|
|
|
|
key-direction 1
|
2014-06-04 18:13:59 +00:00
|
|
|
|
|
|
|
<connection>
|
2014-07-01 05:43:00 +00:00
|
|
|
remote $servername $port $proto
|
2014-06-04 18:13:59 +00:00
|
|
|
</connection>
|
|
|
|
EOF
|