From 6997a0b9a7ec41c3c19dcebb95f71cb300d10e0e Mon Sep 17 00:00:00 2001 From: Kaladin Light <0.kaladin@gmail.com> Date: Wed, 9 Nov 2016 15:02:40 -0500 Subject: [PATCH] Fixes Issue #71: - Uses network address instead of IP in the push route to avoid warnings - If a second DNS is not entered, remove second occurence of the dhcp-option DNS --- auto_install/install.sh | 22 ++++++++++++++++++---- server_config.txt | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 8472e70..83955ed 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -271,7 +271,6 @@ It is also possible to use a DHCP reservation, but if you are going to do that, IP address: $IPv4addr Gateway: $IPv4gw" $r $c)then # If the settings are correct, then we need to set the piVPNIP - # Saving it to a temporary file us to retrieve it later when we run the gravity.sh script echo "${IPv4addr%/*}" > /tmp/pivpnIP echo "$pivpnInterface" > /tmp/pivpnINT # After that's done, the loop ends and we move on @@ -319,6 +318,15 @@ setStaticIPv4() { fi } +setNetwork() { + # Sets the Network IP and Mask correctly + LOCALMASK=$(ifconfig "$pivpnInterface" | awk '/Mask:/{ print $4;} ' | cut -c6-) + LOCALIP=$(ifconfig "$pivpnInterface" | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*') + IFS=. read -r i1 i2 i3 i4 <<< "$LOCALIP" + IFS=. read -r m1 m2 m3 m4 <<< "$LOCALMASK" + LOCALNET=$(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))") +} + function valid_ip() { local ip=$1 @@ -627,7 +635,11 @@ setClientDNS() { if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $OVPNDNS1\n DNS Server 2: $OVPNDNS2" $r $c) then DNSSettingsCorrect=True $SUDO sed -i '0,/\(dhcp-option DNS \)/ s/\(dhcp-option DNS \).*/\1'${OVPNDNS1}'\"/' /etc/openvpn/server.conf - $SUDO sed -i '0,/\(dhcp-option DNS \)/! s/\(dhcp-option DNS \).*/\1'${OVPNDNS2}'\"/' /etc/openvpn/server.conf + if [ -z ${OVPNDNS2} ]; then + $SUDO sed -i '/\(dhcp-option DNS \)/{n;N;d}' /etc/openvpn/server.conf + else + $SUDO sed -i '0,/\(dhcp-option DNS \)/! s/\(dhcp-option DNS \).*/\1'${OVPNDNS2}'\"/' /etc/openvpn/server.conf + fi else # If the settings are wrong, the loop continues DNSSettingsCorrect=False @@ -779,10 +791,10 @@ fi ${SUDOE} openvpn --genkey --secret keys/ta.key # Write config file for server using the template .txt file - LOCALIP=$(ifconfig "$pivpnInterface" | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*') $SUDO cp /etc/.pivpn/server_config.txt /etc/openvpn/server.conf - $SUDO sed -i "s/LOCALIP/${LOCALIP}/g" /etc/openvpn/server.conf + $SUDO sed -i "s/LOCALNET/${LOCALNET}/g" /etc/openvpn/server.conf + $SUDO sed -i "s/LOCALMASK/${LOCALMASK}/g" /etc/openvpn/server.conf # Set the user encryption key size $SUDO sed -i "s/\(dh \/etc\/openvpn\/easy-rsa\/keys\/dh\).*/\1${ENCRYPT}.pem/" /etc/openvpn/server.conf @@ -990,6 +1002,8 @@ else setStaticIPv4 fi +setNetwork + # Choose the user for the ovpns chooseUser diff --git a/server_config.txt b/server_config.txt index ef78680..900bbba 100644 --- a/server_config.txt +++ b/server_config.txt @@ -13,7 +13,7 @@ push "route 10.8.0.1 255.255.255.255" # Add route to Client routing table for the OPenVPN Subnet push "route 10.8.0.0 255.255.255.0" # your local subnet -push "route LOCALIP 255.255.255.0" +push "route LOCALNET LOCALMASK" # Set your primary domain name server address for clients push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4"