2014-07-01 05:43:00 +00:00
|
|
|
#!/bin/bash
|
2014-06-04 23:49:13 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Generate OpenVPN configs
|
|
|
|
#
|
|
|
|
|
2016-09-22 20:02:59 +00:00
|
|
|
TMP_PUSH_CONFIGFILE=$(mktemp -t vpn_push.XXXXXXX)
|
|
|
|
TMP_ROUTE_CONFIGFILE=$(mktemp -t vpn_route.XXXXXXX)
|
2016-09-16 22:42:45 +00:00
|
|
|
TMP_EXTRA_CONFIGFILE=$(mktemp -t vpn_extra.XXXXXXX)
|
|
|
|
|
|
|
|
#Traceback on Error and Exit come from https://docwhat.org/tracebacks-in-bash/
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
_showed_traceback=f
|
|
|
|
|
|
|
|
traceback() {
|
|
|
|
# Hide the traceback() call.
|
|
|
|
local -i start=$(( ${1:-0} + 1 ))
|
|
|
|
local -i end=${#BASH_SOURCE[@]}
|
|
|
|
local -i i=0
|
|
|
|
local -i j=0
|
|
|
|
|
|
|
|
echo "Traceback (last called is first):" 1>&2
|
|
|
|
for ((i=${start}; i < ${end}; i++)); do
|
|
|
|
j=$(( $i - 1 ))
|
|
|
|
local function="${FUNCNAME[$i]}"
|
|
|
|
local file="${BASH_SOURCE[$i]}"
|
|
|
|
local line="${BASH_LINENO[$j]}"
|
|
|
|
echo " ${function}() in ${file}:${line}" 1>&2
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
on_error() {
|
|
|
|
local _ec="$?"
|
|
|
|
local _cmd="${BASH_COMMAND:-unknown}"
|
|
|
|
traceback 1
|
|
|
|
_showed_traceback=t
|
|
|
|
echo "The command ${_cmd} exited with exit code ${_ec}." 1>&2
|
|
|
|
}
|
|
|
|
trap on_error ERR
|
|
|
|
|
|
|
|
|
|
|
|
on_exit() {
|
|
|
|
echo "Cleaning up before Exit ..."
|
2016-09-22 20:02:59 +00:00
|
|
|
rm -f $TMP_PUSH_CONFIGFILE
|
|
|
|
rm -f $TMP_ROUTE_CONFIGFILE
|
2016-09-16 22:42:45 +00:00
|
|
|
rm -f $TMP_EXTRA_CONFIGFILE
|
|
|
|
local _ec="$?"
|
|
|
|
if [[ $_ec != 0 && "${_showed_traceback}" != t ]]; then
|
|
|
|
traceback 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
trap on_exit EXIT
|
|
|
|
|
2014-07-06 04:16:02 +00:00
|
|
|
# Convert 1.2.3.4/24 -> 255.255.255.0
|
|
|
|
cidr2mask()
|
|
|
|
{
|
|
|
|
local i
|
|
|
|
local subnetmask=""
|
|
|
|
local cidr=${1#*/}
|
|
|
|
local full_octets=$(($cidr/8))
|
|
|
|
local partial_octet=$(($cidr%8))
|
|
|
|
|
|
|
|
for ((i=0;i<4;i+=1)); do
|
|
|
|
if [ $i -lt $full_octets ]; then
|
|
|
|
subnetmask+=255
|
|
|
|
elif [ $i -eq $full_octets ]; then
|
|
|
|
subnetmask+=$((256 - 2**(8-$partial_octet)))
|
|
|
|
else
|
|
|
|
subnetmask+=0
|
|
|
|
fi
|
|
|
|
[ $i -lt 3 ] && subnetmask+=.
|
|
|
|
done
|
|
|
|
echo $subnetmask
|
|
|
|
}
|
|
|
|
|
|
|
|
# Used often enough to justify a function
|
|
|
|
getroute() {
|
|
|
|
echo ${1%/*} $(cidr2mask $1)
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "usage: $0 [-d]"
|
|
|
|
echo " -u SERVER_PUBLIC_URL"
|
2016-09-03 22:45:55 +00:00
|
|
|
echo " [-e EXTRA_SERVER_CONFIG ]"
|
2017-02-18 21:53:35 +00:00
|
|
|
echo " [-E EXTRA_CLIENT_CONFIG ]"
|
2016-09-03 22:45:55 +00:00
|
|
|
echo " [-f FRAGMENT ]"
|
2015-10-16 13:41:22 +00:00
|
|
|
echo " [-n DNS_SERVER ...]"
|
2016-09-03 22:45:55 +00:00
|
|
|
echo " [-p PUSH ...]"
|
|
|
|
echo " [-r ROUTE ...]"
|
|
|
|
echo " [-s SERVER_SUBNET]"
|
2014-07-06 04:16:02 +00:00
|
|
|
echo
|
|
|
|
echo "optional arguments:"
|
2016-09-03 22:45:55 +00:00
|
|
|
echo " -2 Enable two factor authentication using Google Authenticator."
|
|
|
|
echo " -a Authenticate packets with HMAC using the given message digest algorithm (auth)."
|
2017-03-09 23:04:21 +00:00
|
|
|
echo " -b Disable 'push block-outside-dns'"
|
2014-07-09 15:17:19 +00:00
|
|
|
echo " -c Enable client-to-client option"
|
2016-09-03 22:45:55 +00:00
|
|
|
echo " -C A list of allowable TLS ciphers delimited by a colon (cipher)."
|
2017-03-09 23:04:21 +00:00
|
|
|
echo " -d Disable default route"
|
2015-10-16 13:41:22 +00:00
|
|
|
echo " -D Do not push dns servers"
|
2017-03-09 23:04:21 +00:00
|
|
|
echo " -k Set keepalive. Default: '10 60'"
|
2015-01-17 09:07:52 +00:00
|
|
|
echo " -m Set client MTU"
|
2016-09-03 22:45:55 +00:00
|
|
|
echo " -N Configure NAT to access external server network"
|
2015-08-18 22:46:07 +00:00
|
|
|
echo " -t Use TAP device (instead of TUN device)"
|
2015-08-26 10:43:25 +00:00
|
|
|
echo " -T Encrypt packets with the given cipher algorithm instead of the default one (tls-cipher)."
|
2015-11-27 14:02:33 +00:00
|
|
|
echo " -z Enable comp-lzo compression."
|
2014-07-06 04:16:02 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 20:02:59 +00:00
|
|
|
process_route_config() {
|
|
|
|
local ovpn_route_config=''
|
|
|
|
ovpn_route_config="$1"
|
|
|
|
# If user passed "0" skip this, assume no extra routes
|
|
|
|
[[ "$ovpn_route_config" == "0" ]] && break;
|
|
|
|
echo "Processing Route Config: '${ovpn_route_config}'"
|
|
|
|
[[ -n "$ovpn_route_config" ]] && echo "route $(getroute $ovpn_route_config)" >> "$TMP_ROUTE_CONFIGFILE"
|
|
|
|
}
|
|
|
|
|
|
|
|
process_push_config() {
|
|
|
|
local ovpn_push_config=''
|
|
|
|
ovpn_push_config="$1"
|
|
|
|
echo "Processing PUSH Config: '${ovpn_push_config}'"
|
2017-05-10 16:33:30 +00:00
|
|
|
[[ -n "$ovpn_push_config" ]] && echo "push \"$ovpn_push_config\"" >> "$TMP_PUSH_CONFIGFILE"
|
2016-09-22 20:02:59 +00:00
|
|
|
}
|
|
|
|
|
2016-09-16 22:42:45 +00:00
|
|
|
process_extra_config() {
|
|
|
|
local ovpn_extra_config=''
|
|
|
|
ovpn_extra_config="$1"
|
|
|
|
echo "Processing Extra Config: '${ovpn_extra_config}'"
|
2016-09-22 20:02:59 +00:00
|
|
|
[[ -n "$ovpn_extra_config" ]] && echo "$ovpn_extra_config" >> "$TMP_EXTRA_CONFIGFILE"
|
2017-02-18 21:53:35 +00:00
|
|
|
}
|
|
|
|
|
2016-09-16 22:42:45 +00:00
|
|
|
if [ "${DEBUG:-}" == "1" ]; then
|
2015-02-28 10:45:31 +00:00
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
2014-06-04 23:49:13 +00:00
|
|
|
|
2016-09-16 22:42:45 +00:00
|
|
|
if [ -z "${OPENVPN:-}" ]; then
|
|
|
|
export OPENVPN="$PWD"
|
|
|
|
fi
|
|
|
|
if [ -z "${EASYRSA_PKI:-}" ]; then
|
|
|
|
export EASYRSA_PKI="$OPENVPN/pki"
|
|
|
|
fi
|
|
|
|
|
2017-06-20 23:29:29 +00:00
|
|
|
OVPN_AUTH=''
|
|
|
|
OVPN_CIPHER=''
|
|
|
|
OVPN_CLIENT_TO_CLIENT=''
|
|
|
|
OVPN_CN=''
|
|
|
|
OVPN_COMP_LZO=0
|
2014-07-06 04:16:02 +00:00
|
|
|
OVPN_DEFROUTE=1
|
2015-08-18 22:46:07 +00:00
|
|
|
OVPN_DEVICE="tun"
|
|
|
|
OVPN_DEVICEN=0
|
2017-06-20 23:29:29 +00:00
|
|
|
OVPN_DISABLE_PUSH_BLOCK_DNS=0
|
|
|
|
OVPN_DNS=1
|
|
|
|
OVPN_DNS_SERVERS=()
|
|
|
|
OVPN_ENV=${OPENVPN}/ovpn_env.sh
|
|
|
|
OVPN_EXTRA_CLIENT_CONFIG=()
|
|
|
|
OVPN_EXTRA_SERVER_CONFIG=()
|
|
|
|
OVPN_FRAGMENT=''
|
2017-03-09 23:04:21 +00:00
|
|
|
OVPN_KEEPALIVE="10 60"
|
2017-06-20 23:29:29 +00:00
|
|
|
OVPN_MTU=''
|
|
|
|
OVPN_NAT=0
|
|
|
|
OVPN_PORT=''
|
|
|
|
OVPN_PROTO=''
|
|
|
|
OVPN_PUSH=()
|
|
|
|
OVPN_ROUTES=()
|
|
|
|
OVPN_SERVER=192.168.255.0/24
|
|
|
|
OVPN_SERVER_URL=''
|
2015-08-26 10:43:25 +00:00
|
|
|
OVPN_TLS_CIPHER=''
|
2014-06-04 23:49:13 +00:00
|
|
|
|
2017-06-20 23:29:29 +00:00
|
|
|
# Import existing configuration if present
|
2014-07-06 01:51:58 +00:00
|
|
|
[ -r "$OVPN_ENV" ] && source "$OVPN_ENV"
|
|
|
|
|
2014-07-06 04:16:02 +00:00
|
|
|
# Parse arguments
|
2017-05-13 16:42:49 +00:00
|
|
|
while getopts ":a:e:E:C:T:r:s:du:bcp:n:k:DNm:f:tz2" opt; do
|
2014-07-06 04:16:02 +00:00
|
|
|
case $opt in
|
2015-08-26 10:43:25 +00:00
|
|
|
a)
|
|
|
|
OVPN_AUTH="$OPTARG"
|
|
|
|
;;
|
2016-05-16 16:56:27 +00:00
|
|
|
e)
|
2017-06-20 23:29:29 +00:00
|
|
|
mapfile -t TMP_EXTRA_SERVER_CONFIG < <(echo "$OPTARG")
|
|
|
|
for i in "${TMP_EXTRA_SERVER_CONFIG[@]}"; do
|
|
|
|
OVPN_EXTRA_SERVER_CONFIG+=("$i")
|
|
|
|
done
|
2016-05-16 16:56:27 +00:00
|
|
|
;;
|
2017-02-18 21:53:35 +00:00
|
|
|
E)
|
2017-06-20 23:29:29 +00:00
|
|
|
mapfile -t TMP_EXTRA_CLIENT_CONFIG < <(echo "$OPTARG")
|
|
|
|
for i in "${TMP_EXTRA_CLIENT_CONFIG[@]}"; do
|
|
|
|
OVPN_EXTRA_CLIENT_CONFIG+=("$i")
|
|
|
|
done
|
2017-02-18 21:53:35 +00:00
|
|
|
;;
|
2015-08-26 10:43:25 +00:00
|
|
|
C)
|
|
|
|
OVPN_CIPHER="$OPTARG"
|
|
|
|
;;
|
|
|
|
T)
|
|
|
|
OVPN_TLS_CIPHER="$OPTARG"
|
|
|
|
;;
|
2014-07-06 04:16:02 +00:00
|
|
|
r)
|
2017-06-20 23:29:29 +00:00
|
|
|
mapfile -t TMP_ROUTES < <(echo "$OPTARG")
|
|
|
|
for i in "${TMP_ROUTES[@]}"; do
|
|
|
|
OVPN_ROUTES+=("$i")
|
|
|
|
done
|
2014-07-06 04:16:02 +00:00
|
|
|
;;
|
|
|
|
s)
|
2017-06-20 23:29:29 +00:00
|
|
|
OVPN_SERVER="$OPTARG"
|
2014-07-06 04:16:02 +00:00
|
|
|
;;
|
|
|
|
d)
|
|
|
|
OVPN_DEFROUTE=0
|
2017-03-09 23:04:21 +00:00
|
|
|
OVPN_DISABLE_PUSH_BLOCK_DNS=1
|
2014-07-06 04:16:02 +00:00
|
|
|
;;
|
|
|
|
u)
|
2017-06-20 23:29:29 +00:00
|
|
|
OVPN_SERVER_URL="$OPTARG"
|
2014-07-06 04:16:02 +00:00
|
|
|
;;
|
2017-03-09 23:04:21 +00:00
|
|
|
b)
|
|
|
|
OVPN_DISABLE_PUSH_BLOCK_DNS=1
|
|
|
|
;;
|
2014-07-09 15:17:19 +00:00
|
|
|
c)
|
|
|
|
OVPN_CLIENT_TO_CLIENT=1
|
|
|
|
;;
|
2014-07-09 17:28:54 +00:00
|
|
|
p)
|
2017-06-20 23:29:29 +00:00
|
|
|
mapfile -t TMP_PUSH < <(echo "$OPTARG")
|
|
|
|
for i in "${TMP_PUSH[@]}"; do
|
|
|
|
OVPN_PUSH+=("$i")
|
|
|
|
done
|
2014-07-09 17:28:54 +00:00
|
|
|
;;
|
2015-10-16 13:41:22 +00:00
|
|
|
n)
|
2017-06-20 23:29:29 +00:00
|
|
|
mapfile -t TMP_DNS_SERVERS < <(echo "$OPTARG")
|
|
|
|
for i in "${TMP_DNS_SERVERS[@]}"; do
|
|
|
|
OVPN_DNS_SERVERS+=("$i")
|
|
|
|
done
|
2015-10-16 13:41:22 +00:00
|
|
|
;;
|
2015-01-17 08:56:21 +00:00
|
|
|
D)
|
|
|
|
OVPN_DNS=0
|
|
|
|
;;
|
2015-01-17 08:56:46 +00:00
|
|
|
N)
|
|
|
|
OVPN_NAT=1
|
|
|
|
;;
|
2017-03-09 23:04:21 +00:00
|
|
|
k)
|
|
|
|
OVPN_KEEPALIVE="$OPTARG"
|
|
|
|
;;
|
2015-01-17 09:07:52 +00:00
|
|
|
m)
|
2017-06-20 23:29:29 +00:00
|
|
|
OVPN_MTU="$OPTARG"
|
2015-01-17 09:07:52 +00:00
|
|
|
;;
|
2015-08-18 22:46:07 +00:00
|
|
|
t)
|
|
|
|
OVPN_DEVICE="tap"
|
|
|
|
;;
|
2015-11-27 14:02:33 +00:00
|
|
|
z)
|
|
|
|
OVPN_COMP_LZO=1
|
|
|
|
;;
|
2016-02-06 19:23:59 +00:00
|
|
|
2)
|
|
|
|
OVPN_OTP_AUTH=1
|
|
|
|
;;
|
2016-04-06 07:06:02 +00:00
|
|
|
f)
|
2017-06-20 23:29:29 +00:00
|
|
|
OVPN_FRAGMENT="$OPTARG"
|
2016-04-06 07:06:02 +00:00
|
|
|
;;
|
2014-07-06 04:16:02 +00:00
|
|
|
\?)
|
|
|
|
set +x
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
:)
|
|
|
|
set +x
|
|
|
|
echo "Option -$OPTARG requires an argument." >&2
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2016-06-08 07:14:08 +00:00
|
|
|
# Create ccd directory for static routes
|
2016-09-16 22:42:45 +00:00
|
|
|
[ ! -d "${OPENVPN:-}/ccd" ] && mkdir -p ${OPENVPN:-}/ccd
|
2016-06-08 07:14:08 +00:00
|
|
|
|
2014-07-06 01:51:58 +00:00
|
|
|
# Server name is in the form "udp://vpn.example.com:1194"
|
2017-02-03 19:34:09 +00:00
|
|
|
if [[ "${OVPN_SERVER_URL:-}" =~ ^((udp|tcp|udp6|tcp6)://)?([0-9a-zA-Z\.\-]+)(:([0-9]+))?$ ]]; then
|
2014-07-06 01:51:58 +00:00
|
|
|
OVPN_PROTO=${BASH_REMATCH[2]};
|
|
|
|
OVPN_CN=${BASH_REMATCH[3]};
|
|
|
|
OVPN_PORT=${BASH_REMATCH[5]};
|
2014-07-01 05:43:00 +00:00
|
|
|
else
|
2014-07-06 04:16:02 +00:00
|
|
|
set +x
|
|
|
|
echo "Common name not specified, see '-u'"
|
|
|
|
usage
|
2014-06-04 23:49:13 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-06-20 23:29:29 +00:00
|
|
|
# Apply defaults. If dns servers were not defined with -n, use google nameservers
|
|
|
|
set +u
|
|
|
|
[ -z "$OVPN_DNS_SERVERS" ] && OVPN_DNS_SERVERS=("8.8.8.8" "8.8.4.4")
|
2014-07-06 01:51:58 +00:00
|
|
|
[ -z "$OVPN_PROTO" ] && OVPN_PROTO=udp
|
|
|
|
[ -z "$OVPN_PORT" ] && OVPN_PORT=1194
|
2017-06-20 23:29:29 +00:00
|
|
|
set -u
|
|
|
|
[ "${#OVPN_ROUTES[@]}" == "0" ] && [ "$OVPN_DEFROUTE" == "1" ] && OVPN_ROUTES+=("192.168.254.0/24")
|
2014-07-06 01:51:58 +00:00
|
|
|
|
|
|
|
# Preserve config
|
|
|
|
if [ -f "$OVPN_ENV" ]; then
|
|
|
|
bak_env=$OVPN_ENV.$(date +%s).bak
|
|
|
|
echo "Backing up $OVPN_ENV -> $bak_env"
|
|
|
|
mv "$OVPN_ENV" "$bak_env"
|
|
|
|
fi
|
2017-02-18 21:53:35 +00:00
|
|
|
|
2017-06-20 23:29:29 +00:00
|
|
|
# Save the current OVPN_ vars to the ovpn_env.sh file
|
|
|
|
while read -r var; do
|
|
|
|
echo "declare -x $var" >> "$OVPN_ENV"
|
|
|
|
done < <(set | grep '^OVPN_')
|
2014-07-01 05:43:00 +00:00
|
|
|
|
2016-09-16 22:42:45 +00:00
|
|
|
conf=${OPENVPN:-}/openvpn.conf
|
2014-06-30 06:09:18 +00:00
|
|
|
if [ -f "$conf" ]; then
|
|
|
|
bak=$conf.$(date +%s).bak
|
|
|
|
echo "Backing up $conf -> $bak"
|
|
|
|
mv "$conf" "$bak"
|
|
|
|
fi
|
|
|
|
|
2017-06-20 23:29:29 +00:00
|
|
|
# Echo extra client configurations
|
|
|
|
if [ ${#OVPN_EXTRA_CLIENT_CONFIG[@]} -gt 0 ]; then
|
|
|
|
for i in "${OVPN_EXTRA_CLIENT_CONFIG[@]}"; do
|
|
|
|
echo "Processing Extra Client Config: $i"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2014-06-30 06:09:18 +00:00
|
|
|
cat > "$conf" <<EOF
|
2014-07-06 04:16:02 +00:00
|
|
|
server $(getroute $OVPN_SERVER)
|
2014-06-04 23:49:13 +00:00
|
|
|
verb 3
|
2014-07-06 04:16:02 +00:00
|
|
|
key $EASYRSA_PKI/private/${OVPN_CN}.key
|
2014-06-04 23:49:13 +00:00
|
|
|
ca $EASYRSA_PKI/ca.crt
|
2014-07-06 04:16:02 +00:00
|
|
|
cert $EASYRSA_PKI/issued/${OVPN_CN}.crt
|
2014-06-04 23:49:13 +00:00
|
|
|
dh $EASYRSA_PKI/dh.pem
|
|
|
|
tls-auth $EASYRSA_PKI/ta.key
|
|
|
|
key-direction 0
|
2017-03-09 23:04:21 +00:00
|
|
|
keepalive $OVPN_KEEPALIVE
|
2014-06-04 23:49:13 +00:00
|
|
|
persist-key
|
|
|
|
persist-tun
|
2014-06-30 07:10:52 +00:00
|
|
|
|
2014-07-06 01:51:58 +00:00
|
|
|
proto $OVPN_PROTO
|
2014-07-06 17:51:44 +00:00
|
|
|
# Rely on Docker to do port mapping, internally always 1194
|
|
|
|
port 1194
|
2015-08-18 22:46:07 +00:00
|
|
|
dev $OVPN_DEVICE$OVPN_DEVICEN
|
2014-07-01 05:56:26 +00:00
|
|
|
status /tmp/openvpn-status.log
|
2014-07-06 04:16:02 +00:00
|
|
|
|
2014-12-31 20:57:22 +00:00
|
|
|
user nobody
|
|
|
|
group nogroup
|
2014-06-04 23:49:13 +00:00
|
|
|
EOF
|
2014-07-01 15:30:28 +00:00
|
|
|
|
2017-03-09 23:04:21 +00:00
|
|
|
if [ "${OVPN_DISABLE_PUSH_BLOCK_DNS}" == "1" ]; then
|
|
|
|
echo "Disable default push of 'block-outside-dns'"
|
|
|
|
else
|
|
|
|
process_push_config "block-outside-dns"
|
|
|
|
fi
|
2016-09-22 20:02:59 +00:00
|
|
|
|
2015-08-26 10:43:25 +00:00
|
|
|
[ -n "$OVPN_TLS_CIPHER" ] && echo "tls-cipher $OVPN_TLS_CIPHER" >> "$conf"
|
|
|
|
[ -n "$OVPN_CIPHER" ] && echo "cipher $OVPN_CIPHER" >> "$conf"
|
|
|
|
[ -n "$OVPN_AUTH" ] && echo "auth $OVPN_AUTH" >> "$conf"
|
2015-05-11 17:33:56 +00:00
|
|
|
|
2016-09-16 22:50:48 +00:00
|
|
|
[ -n "${OVPN_CLIENT_TO_CLIENT:-}" ] && echo "client-to-client" >> "$conf"
|
2017-03-09 23:04:21 +00:00
|
|
|
[ "$OVPN_COMP_LZO" == "1" ] && echo "comp-lzo" >> "$conf"
|
2015-11-01 01:27:55 +00:00
|
|
|
|
2016-09-16 22:42:45 +00:00
|
|
|
[ -n "${OVPN_FRAGMENT:-}" ] && echo "fragment $OVPN_FRAGMENT" >> "$conf"
|
2016-05-16 16:56:27 +00:00
|
|
|
|
2017-06-20 23:29:29 +00:00
|
|
|
# Append route commands
|
|
|
|
if [ ${#OVPN_ROUTES[@]} -gt 0 ]; then
|
|
|
|
for i in "${OVPN_ROUTES[@]}"; do
|
|
|
|
process_route_config "$i"
|
|
|
|
done
|
|
|
|
echo -e "\n### Route Configurations Below" >> "$conf"
|
|
|
|
cat $TMP_ROUTE_CONFIGFILE >> "$conf"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Append push commands
|
2015-11-01 01:27:55 +00:00
|
|
|
[ "$OVPN_DNS" == "1" ] && for i in "${OVPN_DNS_SERVERS[@]}"; do
|
2016-09-22 22:12:45 +00:00
|
|
|
process_push_config "dhcp-option DNS $i"
|
2014-07-06 04:16:02 +00:00
|
|
|
done
|
|
|
|
|
2017-06-20 23:29:29 +00:00
|
|
|
[ ${#OVPN_PUSH[@]} -gt 0 ] && for i in "${OVPN_PUSH[@]}"; do
|
|
|
|
process_push_config "$i"
|
|
|
|
done
|
2016-09-22 20:02:59 +00:00
|
|
|
|
|
|
|
echo -e "\n### Push Configurations Below" >> "$conf"
|
|
|
|
cat $TMP_PUSH_CONFIGFILE >> "$conf"
|
|
|
|
|
2017-06-20 23:29:29 +00:00
|
|
|
# Append optional OTP authentication support
|
2016-09-16 22:42:45 +00:00
|
|
|
if [ -n "${OVPN_OTP_AUTH:-}" ]; then
|
2016-02-06 19:23:59 +00:00
|
|
|
echo -e "\n\n# Enable OTP+PAM for user authentication" >> "$conf"
|
2016-02-11 17:10:51 +00:00
|
|
|
echo "plugin /usr/lib/openvpn/plugins/openvpn-plugin-auth-pam.so openvpn" >> "$conf"
|
2017-01-24 14:37:48 +00:00
|
|
|
echo "reneg-sec 0" >> "$conf"
|
2016-02-06 19:23:59 +00:00
|
|
|
fi
|
|
|
|
|
2017-06-20 23:29:29 +00:00
|
|
|
# Append extra server configurations
|
|
|
|
if [ ${#OVPN_EXTRA_SERVER_CONFIG[@]} -gt 0 ]; then
|
|
|
|
for i in "${OVPN_EXTRA_SERVER_CONFIG[@]}"; do
|
|
|
|
process_extra_config "$i"
|
|
|
|
done
|
|
|
|
echo -e "\n### Extra Configurations Below" >> "$conf"
|
|
|
|
cat $TMP_EXTRA_CONFIGFILE >> "$conf"
|
|
|
|
fi
|
2016-09-16 22:42:45 +00:00
|
|
|
|
2015-08-18 22:46:07 +00:00
|
|
|
set +e
|
2015-03-09 16:17:42 +00:00
|
|
|
|
2015-03-08 00:35:08 +00:00
|
|
|
# Clean-up duplicate configs
|
2016-09-16 22:42:45 +00:00
|
|
|
if diff -q "${bak_env:-}" "$OVPN_ENV" 2>/dev/null; then
|
2015-03-08 00:35:08 +00:00
|
|
|
echo "Removing duplicate back-up: $bak_env"
|
|
|
|
rm -fv "$bak_env"
|
|
|
|
fi
|
2016-09-16 22:42:45 +00:00
|
|
|
if diff -q "${bak:-}" "$conf" 2>/dev/null; then
|
2015-03-08 00:35:08 +00:00
|
|
|
echo "Removing duplicate back-up: $bak"
|
|
|
|
rm -fv "$bak"
|
|
|
|
fi
|
2014-07-09 15:17:47 +00:00
|
|
|
|
|
|
|
echo "Successfully generated config"
|