From 191cb45106979cba8b9b5e968fc18d2f13381f79 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Mon, 16 May 2016 09:56:27 -0700 Subject: [PATCH 1/2] allow specifying extra config --- bin/ovpn_genconfig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/ovpn_genconfig b/bin/ovpn_genconfig index c957b80..dfa4555 100755 --- a/bin/ovpn_genconfig +++ b/bin/ovpn_genconfig @@ -52,6 +52,7 @@ usage() { echo " -z Enable comp-lzo compression." echo " -2 Enable two factor authentication using Google Authenticator." echo " -f Set the fragment directive." + echo " -e Add extra server config" } if [ "$DEBUG" == "1" ]; then @@ -76,16 +77,20 @@ TMP_DNS_SERVERS=() OVPN_TLS_CIPHER='' OVPN_CIPHER='' OVPN_AUTH='' +OVPN_EXTRA_CONFIG='' # Import defaults if present [ -r "$OVPN_ENV" ] && source "$OVPN_ENV" # Parse arguments -while getopts ":a:C:T:r:s:du:cp:n:DNmf:tz2" opt; do +while getopts ":a:e:C:T:r:s:du:cp:n:DNmf:tz2" opt; do case $opt in a) OVPN_AUTH="$OPTARG" ;; + e) + OVPN_EXTRA_CONFIG="$OPTARG" + ;; C) OVPN_CIPHER="$OPTARG" ;; @@ -230,6 +235,8 @@ EOF [ -n "$OVPN_FRAGMENT" ] && echo "fragment $OVPN_FRAGMENT" >> "$conf" +[ -n "$OVPN_EXTRA_CONFIG" ] && echo "$OVPN_EXTRA_CONFIG" >> "$conf" + [ "$OVPN_DNS" == "1" ] && for i in "${OVPN_DNS_SERVERS[@]}"; do echo "push dhcp-option DNS $i" >> "$conf" done From 793f83d6201ef2620d7c1f7e8d5c421a399385a6 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Tue, 17 May 2016 08:42:22 -0700 Subject: [PATCH 2/2] adding tests for extra server config --- tests/openvpn_conf_options.test.sh | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/openvpn_conf_options.test.sh b/tests/openvpn_conf_options.test.sh index 6c315fb..13c238e 100755 --- a/tests/openvpn_conf_options.test.sh +++ b/tests/openvpn_conf_options.test.sh @@ -15,8 +15,13 @@ sudo docker run --name $OVPN_DATA -v /etc/openvpn busybox # # Generate openvpn.config file # +read -d '' EXTRA_SERVER_CONF << EOF +management localhost 7505 +max-clients 10 +EOF + SERV_IP=$(ip -4 -o addr show scope global | awk '{print $4}' | sed -e 's:/.*::' | head -n1) -sudo docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_genconfig -u udp://$SERV_IP -f 1400 +sudo docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_genconfig -u udp://$SERV_IP -f 1400 -e "$EXTRA_SERVER_CONF" # # grep for config lines from openvpn.conf @@ -31,6 +36,14 @@ CONFIG_MATCH_VERB=$(sudo docker run --rm -it --volumes-from $OVPN_DATA busybox g CONFIG_REQUIRED_FRAGMENT="fragment 1400" CONFIG_MATCH_FRAGMENT=$(sudo docker run --rm -it --volumes-from $OVPN_DATA busybox grep fragment /etc/openvpn/openvpn.conf) +# 3. management config +CONFIG_REQUIRED_MANAGEMENT="^management localhost 7505" +CONFIG_MATCH_MANAGEMENT=$(sudo docker run --rm -it --volumes-from $OVPN_DATA busybox grep management /etc/openvpn/openvpn.conf) + +# 4. max-clients config +CONFIG_REQUIRED_MAX_CLIENTS="^max-clients 10" +CONFIG_MATCH_MAX_CLIENTS=$(sudo docker run --rm -it --volumes-from $OVPN_DATA busybox grep max-clients /etc/openvpn/openvpn.conf) + # # Clean up # @@ -52,4 +65,18 @@ then echo "==> Config match found: $CONFIG_REQUIRED_FRAGMENT == $CONFIG_MATCH_FRAGMENT" else abort "==> Config match not found: $CONFIG_REQUIRED_FRAGMENT != $CONFIG_MATCH_FRAGMENT" -fi \ No newline at end of file +fi + +if [[ $CONFIG_MATCH_MANAGEMENT =~ $CONFIG_REQUIRED_MANAGEMENT ]] +then + echo "==> Config match found: $CONFIG_REQUIRED_MANAGEMENT == $CONFIG_MATCH_MANAGEMENT" +else + abort "==> Config match not found: $CONFIG_REQUIRED_MANAGEMENT != $CONFIG_MATCH_MANAGEMENT" +fi + +if [[ $CONFIG_MATCH_MAX_CLIENTS =~ $CONFIG_REQUIRED_MAX_CLIENTS ]] +then + echo "==> Config match found: $CONFIG_REQUIRED_MAX_CLIENTS == $CONFIG_MATCH_MAX_CLIENTS" +else + abort "==> Config match not found: $CONFIG_REQUIRED_MAX_CLIENTS != $CONFIG_MATCH_MAX_CLIENTS" +fi