2014-07-06 04:39:50 +00:00
|
|
|
#!/bin/bash
|
2014-06-04 18:13:59 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Run the OpenVPN server normally
|
|
|
|
#
|
|
|
|
|
2015-02-28 10:45:31 +00:00
|
|
|
if [ "$DEBUG" == "1" ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
2014-06-04 18:13:59 +00:00
|
|
|
|
2014-07-06 04:39:50 +00:00
|
|
|
source "$OPENVPN/ovpn_env.sh"
|
|
|
|
|
2014-06-04 18:13:59 +00:00
|
|
|
mkdir -p /dev/net
|
|
|
|
if [ ! -c /dev/net/tun ]; then
|
|
|
|
mknod /dev/net/tun c 10 200
|
|
|
|
fi
|
|
|
|
|
2014-06-30 06:22:03 +00:00
|
|
|
if [ ! -d "$OPENVPN/ccd" ]; then
|
|
|
|
mkdir -p /etc/openvpn/ccd
|
|
|
|
fi
|
|
|
|
|
2014-07-06 04:39:50 +00:00
|
|
|
# Setup NAT forwarding if requested
|
2015-01-17 09:00:18 +00:00
|
|
|
if [ "$OVPN_DEFROUTE" != "0" ] || [ "$OVPN_NAT" == "1" ] ; then
|
2014-10-23 13:16:51 +00:00
|
|
|
iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE || {
|
|
|
|
iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE
|
|
|
|
}
|
2014-07-09 17:34:39 +00:00
|
|
|
for i in "${OVPN_ROUTES[@]}"; do
|
2014-10-23 13:16:51 +00:00
|
|
|
iptables -t nat -C POSTROUTING -s "$i" -o eth0 -j MASQUERADE || {
|
|
|
|
iptables -t nat -A POSTROUTING -s "$i" -o eth0 -j MASQUERADE
|
|
|
|
}
|
2014-07-06 04:39:50 +00:00
|
|
|
done
|
|
|
|
fi
|
2014-07-01 05:56:26 +00:00
|
|
|
|
2015-05-12 07:59:43 +00:00
|
|
|
# Use a hacky hardlink as the CRL Needs to be readable by the user/group
|
|
|
|
# OpenVPN is running as. Only pass arguments to OpenVPN if it's found.
|
|
|
|
if [ -r "$EASYRSA_PKI/crl.pem" ]; then
|
|
|
|
if [ ! -r "$OPENVPN/crl.pem" ]; then
|
|
|
|
ln "$EASYRSA_PKI/crl.pem" "$OPENVPN/crl.pem"
|
|
|
|
chmod 644 "$OPENVPN/crl.pem"
|
|
|
|
fi
|
|
|
|
ARGS=("--crl-verify" "$OPENVPN/crl.pem")
|
|
|
|
fi
|
|
|
|
|
2015-05-09 22:17:17 +00:00
|
|
|
if [ "$#" -gt 0 ]; then
|
|
|
|
exec openvpn "$@"
|
|
|
|
else
|
2015-05-12 07:59:43 +00:00
|
|
|
exec openvpn ${ARGS[@]} --config "$OPENVPN/openvpn.conf"
|
2015-05-09 22:17:17 +00:00
|
|
|
fi
|