Merge pull request #127 from mediatemple/add_extra_config
allow specifying extra config
This commit is contained in:
commit
22f90831cf
@ -52,6 +52,7 @@ usage() {
|
|||||||
echo " -z Enable comp-lzo compression."
|
echo " -z Enable comp-lzo compression."
|
||||||
echo " -2 Enable two factor authentication using Google Authenticator."
|
echo " -2 Enable two factor authentication using Google Authenticator."
|
||||||
echo " -f Set the fragment directive."
|
echo " -f Set the fragment directive."
|
||||||
|
echo " -e Add extra server config"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$DEBUG" == "1" ]; then
|
if [ "$DEBUG" == "1" ]; then
|
||||||
@ -76,16 +77,20 @@ TMP_DNS_SERVERS=()
|
|||||||
OVPN_TLS_CIPHER=''
|
OVPN_TLS_CIPHER=''
|
||||||
OVPN_CIPHER=''
|
OVPN_CIPHER=''
|
||||||
OVPN_AUTH=''
|
OVPN_AUTH=''
|
||||||
|
OVPN_EXTRA_CONFIG=''
|
||||||
|
|
||||||
# Import defaults if present
|
# Import defaults if present
|
||||||
[ -r "$OVPN_ENV" ] && source "$OVPN_ENV"
|
[ -r "$OVPN_ENV" ] && source "$OVPN_ENV"
|
||||||
|
|
||||||
# Parse arguments
|
# 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
|
case $opt in
|
||||||
a)
|
a)
|
||||||
OVPN_AUTH="$OPTARG"
|
OVPN_AUTH="$OPTARG"
|
||||||
;;
|
;;
|
||||||
|
e)
|
||||||
|
OVPN_EXTRA_CONFIG="$OPTARG"
|
||||||
|
;;
|
||||||
C)
|
C)
|
||||||
OVPN_CIPHER="$OPTARG"
|
OVPN_CIPHER="$OPTARG"
|
||||||
;;
|
;;
|
||||||
@ -230,6 +235,8 @@ EOF
|
|||||||
|
|
||||||
[ -n "$OVPN_FRAGMENT" ] && echo "fragment $OVPN_FRAGMENT" >> "$conf"
|
[ -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
|
[ "$OVPN_DNS" == "1" ] && for i in "${OVPN_DNS_SERVERS[@]}"; do
|
||||||
echo "push dhcp-option DNS $i" >> "$conf"
|
echo "push dhcp-option DNS $i" >> "$conf"
|
||||||
done
|
done
|
||||||
|
@ -15,8 +15,13 @@ sudo docker run --name $OVPN_DATA -v /etc/openvpn busybox
|
|||||||
#
|
#
|
||||||
# Generate openvpn.config file
|
# 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)
|
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
|
# 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_REQUIRED_FRAGMENT="fragment 1400"
|
||||||
CONFIG_MATCH_FRAGMENT=$(sudo docker run --rm -it --volumes-from $OVPN_DATA busybox grep fragment /etc/openvpn/openvpn.conf)
|
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
|
# Clean up
|
||||||
#
|
#
|
||||||
@ -52,4 +65,18 @@ then
|
|||||||
echo "==> Config match found: $CONFIG_REQUIRED_FRAGMENT == $CONFIG_MATCH_FRAGMENT"
|
echo "==> Config match found: $CONFIG_REQUIRED_FRAGMENT == $CONFIG_MATCH_FRAGMENT"
|
||||||
else
|
else
|
||||||
abort "==> Config match not found: $CONFIG_REQUIRED_FRAGMENT != $CONFIG_MATCH_FRAGMENT"
|
abort "==> Config match not found: $CONFIG_REQUIRED_FRAGMENT != $CONFIG_MATCH_FRAGMENT"
|
||||||
fi
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user