2014-07-01 05:43:00 +00:00
|
|
|
#!/bin/bash
|
2014-06-04 23:49:13 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Generate OpenVPN configs
|
|
|
|
#
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
2014-07-01 05:43:00 +00:00
|
|
|
server_url=$1
|
|
|
|
[ -z "$server_url" ] && server_url=$(cat "$OPENVPN/server_url" 2> /dev/null)
|
2014-06-04 23:49:13 +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]};
|
|
|
|
port=${BASH_REMATCH[5]};
|
|
|
|
else
|
2014-06-04 23:49:13 +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-30 06:09:18 +00:00
|
|
|
conf=$OPENVPN/udp1194.conf
|
|
|
|
if [ -f "$conf" ]; then
|
|
|
|
bak=$conf.$(date +%s).bak
|
|
|
|
echo "Backing up $conf -> $bak"
|
|
|
|
mv "$conf" "$bak"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat > "$conf" <<EOF
|
2014-06-30 05:45:30 +00:00
|
|
|
server 192.168.255.0 255.255.255.0
|
2014-06-04 23:49:13 +00:00
|
|
|
verb 3
|
|
|
|
#duplicate-cn
|
|
|
|
key $EASYRSA_PKI/private/$cn.key
|
|
|
|
ca $EASYRSA_PKI/ca.crt
|
|
|
|
cert $EASYRSA_PKI/issued/$cn.crt
|
|
|
|
dh $EASYRSA_PKI/dh.pem
|
|
|
|
tls-auth $EASYRSA_PKI/ta.key
|
|
|
|
key-direction 0
|
|
|
|
keepalive 10 60
|
|
|
|
persist-key
|
|
|
|
persist-tun
|
|
|
|
push "dhcp-option DNS 8.8.4.4"
|
|
|
|
push "dhcp-option DNS 8.8.8.8"
|
2014-06-30 07:10:52 +00:00
|
|
|
|
2014-06-30 05:44:05 +00:00
|
|
|
client-config-dir $OPENVPN/ccd
|
2014-06-30 07:10:52 +00:00
|
|
|
route 192.168.254.0 255.255.255.0
|
2014-06-04 23:49:13 +00:00
|
|
|
|
2014-07-01 05:43:00 +00:00
|
|
|
proto $proto
|
|
|
|
port $port
|
2014-06-04 23:49:13 +00:00
|
|
|
dev tun1194
|
|
|
|
status /tmp/openvpn-status-1194.log
|
|
|
|
EOF
|