Merge pull request #28 from omriiluz/master
Include optional configuration options
This commit is contained in:
		@@ -41,6 +41,9 @@ usage() {
 | 
				
			|||||||
    echo "optional arguments:"
 | 
					    echo "optional arguments:"
 | 
				
			||||||
    echo " -d    Disable NAT routing and default route"
 | 
					    echo " -d    Disable NAT routing and default route"
 | 
				
			||||||
    echo " -c    Enable client-to-client option"
 | 
					    echo " -c    Enable client-to-client option"
 | 
				
			||||||
 | 
					    echo " -D    Disable built in external dns (google dns)"
 | 
				
			||||||
 | 
					    echo " -N    Configure NAT to access external server network"
 | 
				
			||||||
 | 
					    echo " -m    Set client MTU"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set -ex
 | 
					set -ex
 | 
				
			||||||
@@ -48,6 +51,8 @@ set -ex
 | 
				
			|||||||
OVPN_ENV=$OPENVPN/ovpn_env.sh
 | 
					OVPN_ENV=$OPENVPN/ovpn_env.sh
 | 
				
			||||||
OVPN_SERVER=192.168.255.0/24
 | 
					OVPN_SERVER=192.168.255.0/24
 | 
				
			||||||
OVPN_DEFROUTE=1
 | 
					OVPN_DEFROUTE=1
 | 
				
			||||||
 | 
					OVPN_NAT=0
 | 
				
			||||||
 | 
					OVPN_DNS=1
 | 
				
			||||||
OVPN_ROUTES=()
 | 
					OVPN_ROUTES=()
 | 
				
			||||||
OVPN_PUSH=()
 | 
					OVPN_PUSH=()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -55,7 +60,7 @@ OVPN_PUSH=()
 | 
				
			|||||||
[ -r "$OVPN_ENV" ] && source "$OVPN_ENV"
 | 
					[ -r "$OVPN_ENV" ] && source "$OVPN_ENV"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Parse arguments
 | 
					# Parse arguments
 | 
				
			||||||
while getopts ":r:s:du:cp:" opt; do
 | 
					while getopts ":r:s:du:cp:DNm:" opt; do
 | 
				
			||||||
    case $opt in
 | 
					    case $opt in
 | 
				
			||||||
        r)
 | 
					        r)
 | 
				
			||||||
            OVPN_ROUTES+=("$OPTARG")
 | 
					            OVPN_ROUTES+=("$OPTARG")
 | 
				
			||||||
@@ -75,6 +80,15 @@ while getopts ":r:s:du:cp:" opt; do
 | 
				
			|||||||
        p)
 | 
					        p)
 | 
				
			||||||
            OVPN_PUSH+=("$OPTARG")
 | 
					            OVPN_PUSH+=("$OPTARG")
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
 | 
					        D)
 | 
				
			||||||
 | 
					            OVPN_DNS=0
 | 
				
			||||||
 | 
					            ;;
 | 
				
			||||||
 | 
					        N)
 | 
				
			||||||
 | 
					            OVPN_NAT=1
 | 
				
			||||||
 | 
					            ;;
 | 
				
			||||||
 | 
					        m)
 | 
				
			||||||
 | 
					            OVPN_MTU=$OPTARG
 | 
				
			||||||
 | 
					            ;;
 | 
				
			||||||
        \?)
 | 
					        \?)
 | 
				
			||||||
            set +x
 | 
					            set +x
 | 
				
			||||||
            echo "Invalid option: -$OPTARG" >&2
 | 
					            echo "Invalid option: -$OPTARG" >&2
 | 
				
			||||||
@@ -110,7 +124,7 @@ fi
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export OVPN_SERVER OVPN_ROUTES OVPN_DEFROUTE
 | 
					export OVPN_SERVER OVPN_ROUTES OVPN_DEFROUTE
 | 
				
			||||||
export OVPN_SERVER_URL OVPN_ENV OVPN_PROTO OVPN_CN OVPN_PORT
 | 
					export OVPN_SERVER_URL OVPN_ENV OVPN_PROTO OVPN_CN OVPN_PORT
 | 
				
			||||||
export OVPN_CLIENT_TO_CLIENT OVPN_PUSH
 | 
					export OVPN_CLIENT_TO_CLIENT OVPN_PUSH OVPN_NAT OVPN_DNS OVPN_MTU
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Preserve config
 | 
					# Preserve config
 | 
				
			||||||
if [ -f "$OVPN_ENV" ]; then
 | 
					if [ -f "$OVPN_ENV" ]; then
 | 
				
			||||||
@@ -140,8 +154,6 @@ key-direction 0
 | 
				
			|||||||
keepalive 10 60
 | 
					keepalive 10 60
 | 
				
			||||||
persist-key
 | 
					persist-key
 | 
				
			||||||
persist-tun
 | 
					persist-tun
 | 
				
			||||||
push "dhcp-option DNS 8.8.4.4"
 | 
					 | 
				
			||||||
push "dhcp-option DNS 8.8.8.8"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
proto $OVPN_PROTO
 | 
					proto $OVPN_PROTO
 | 
				
			||||||
# Rely on Docker to do port mapping, internally always 1194
 | 
					# Rely on Docker to do port mapping, internally always 1194
 | 
				
			||||||
@@ -156,7 +168,8 @@ group nogroup
 | 
				
			|||||||
EOF
 | 
					EOF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[ -n "$OVPN_CLIENT_TO_CLIENT" ] && echo "client-to-client" >> "$conf"
 | 
					[ -n "$OVPN_CLIENT_TO_CLIENT" ] && echo "client-to-client" >> "$conf"
 | 
				
			||||||
 | 
					[ "$OVPN_DNS" == "1" ] && echo push "dhcp-option DNS 8.8.4.4" >> "$conf"
 | 
				
			||||||
 | 
					[ "$OVPN_DNS" == "1" ] && echo push "dhcp-option DNS 8.8.8.8" >> "$conf"
 | 
				
			||||||
# Append Routes
 | 
					# Append Routes
 | 
				
			||||||
for i in "${OVPN_ROUTES[@]}"; do
 | 
					for i in "${OVPN_ROUTES[@]}"; do
 | 
				
			||||||
    # If user passed "0" skip this, assume no extra routes
 | 
					    # If user passed "0" skip this, assume no extra routes
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,3 +43,5 @@ EOF
 | 
				
			|||||||
if [ "$OVPN_DEFROUTE" != "0" ];then
 | 
					if [ "$OVPN_DEFROUTE" != "0" ];then
 | 
				
			||||||
    echo "redirect-gateway def1"
 | 
					    echo "redirect-gateway def1"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ -n "$OVPN_MTU" ] && echo "tun-mtu $OVPN_MTU"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,7 @@ if [ ! -d "$OPENVPN/ccd" ]; then
 | 
				
			|||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Setup NAT forwarding if requested
 | 
					# Setup NAT forwarding if requested
 | 
				
			||||||
if [ "$OVPN_DEFROUTE" != "0" ];then
 | 
					if [ "$OVPN_DEFROUTE" != "0" ] || [ "$OVPN_NAT" == "1" ] ; then
 | 
				
			||||||
    iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE || {
 | 
					    iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE || {
 | 
				
			||||||
      iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE
 | 
					      iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user