Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
fix: fallback for VPN protocol and port
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumedsde committed Jun 18, 2020
1 parent 68e1016 commit ac5d7d0
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions rootfs/etc/cont-init.d/03-setup-iptables
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,34 @@ DECTECTED_DOCKER_CIDR=$(ip -o -f inet addr show | awk '/scope global/ {print $4}
DOCKER_CIDR=${DECTECTED_DOCKER_CIDR:-DOCKER_CIDR}

# extract VPN protocol, host and port from configuration
VPN_PROTO=$(awk '/proto / { print $2 }' "${OPENVPN_CONFIG_FILE}")
VPN_HOST=$(awk '/remote / { print $2 }' "${OPENVPN_CONFIG_FILE}")
VPN_PORT=$(awk '/remote / { print $3 }' "${OPENVPN_CONFIG_FILE}")
CONFIG_PROTO=$(awk '/proto / { print $2 }' "${OPENVPN_CONFIG_FILE}")
CONFIG_PORT=$(awk '/remote / { print $3 }' "${OPENVPN_CONFIG_FILE}")
CONFIG_VPN_HOST=$(awk '/remote / { print $2 }' "${OPENVPN_CONFIG_FILE}")

VPN_PROTO="${CONFIG_PROTO:=udp}"
VPN_HOST="${CONFIG_VPN_HOST}"
VPN_PORT="${CONFIG_PORT:=1194}"

DNS_SERVER=${DNS}

# Check that VPN information was sucessfully extracted from configuration
if [[ -z "${VPN_PROTO}" || -z "${VPN_HOST}" || -z "${VPN_PORT}" ]]; then
echo "One of the following variables could not be detected in the VPN configuration:

if [ -z "${VPN_HOST}" ]; then
echo "ERROR could not find VPN_HOST in the VPN configuration"
exit 1
fi

if [ -z "${VPN_PROTO}" || -z "${VPN_PORT}" ]; then
echo "INFO: One of the following variables could not be detected in the VPN configuration, fell back to default:
VPN_PROTO: $VPN_PROTO
VPN_HOST: $VPN_HOST
VPN_PORT: $VPN_PORT
"
exit 1
fi

# change openvpn config 'tcp-client' to compatible iptables 'tcp'
if [ "${VPN_PROTO}" == "tcp-client" ]; then
export VPN_PROTO="tcp"
fi

# reset iptables
Expand Down

0 comments on commit ac5d7d0

Please sign in to comment.