ovpn: Convert from servername -> server_url
* Previously the server name cached the common name generated during init and assumed always 1194/udp. * The new configuration allows for users to pass in a url in a new form that allows the protocol to be specified as well as the port. * Example: udp://vpn.example.com:1194 * Try to be backwards compatible.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Get an OpenVPN client configuration file
|
||||
@ -6,19 +6,30 @@
|
||||
|
||||
set -ex
|
||||
|
||||
cn=$1
|
||||
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
|
||||
|
||||
if [ -z "$cn" ]; then
|
||||
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
|
||||
echo "Common name not specified"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Apply defaults
|
||||
[ -z "$proto" ] && proto=1194
|
||||
[ -z "$port" ] && port=udp
|
||||
|
||||
if [ ! -f "$EASYRSA_PKI/private/$cn.key" ]; then
|
||||
easyrsa build-server-full $cn nopass
|
||||
fi
|
||||
|
||||
servername=$(cat $OPENVPN/servername)
|
||||
|
||||
cat <<EOF
|
||||
client
|
||||
nobind
|
||||
@ -44,6 +55,6 @@ $(cat $EASYRSA_PKI/ta.key)
|
||||
key-direction 1
|
||||
|
||||
<connection>
|
||||
remote $servername 1194 udp
|
||||
remote $servername $port $proto
|
||||
</connection>
|
||||
EOF
|
||||
|
Reference in New Issue
Block a user