From b61035137fdf6bc3412be137ec268bf7346565c0 Mon Sep 17 00:00:00 2001
From: hwdsl2 <hwdsl2@users.noreply.github.com>
Date: Thu, 21 Jan 2016 09:45:31 -0600
Subject: [PATCH] Important: Fixed an error in IP format checking.

- Due to a mistake in the "grep" command, empty strings would pass the IP
  regex checks, which is not OK.
- Please update your VPN scripts with this commit!
---
 vpnsetup.sh        | 4 ++--
 vpnsetup_centos.sh | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/vpnsetup.sh b/vpnsetup.sh
index bb2b413..65c893e 100644
--- a/vpnsetup.sh
+++ b/vpnsetup.sh
@@ -93,11 +93,11 @@ PRIVATE_IP=$(wget --retry-connrefused -t 3 -T 15 -qO- 'http://169.254.169.254/la
 
 # Check IPs for correct format
 IP_REGEX="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
-if printf %s "$PUBLIC_IP" | grep -vEq "$IP_REGEX"; then
+if ! printf %s "$PUBLIC_IP" | grep -Eq "$IP_REGEX"; then
   echo "Cannot find valid Public IP, please edit the VPN script manually."
   exit 1
 fi
-if printf %s "$PRIVATE_IP" | grep -vEq "$IP_REGEX"; then
+if ! printf %s "$PRIVATE_IP" | grep -Eq "$IP_REGEX"; then
   echo "Cannot find valid Private IP, please edit the VPN script manually."
   exit 1
 fi
diff --git a/vpnsetup_centos.sh b/vpnsetup_centos.sh
index 1e1c2b4..7bfa1cb 100644
--- a/vpnsetup_centos.sh
+++ b/vpnsetup_centos.sh
@@ -103,11 +103,11 @@ PRIVATE_IP=$(wget --retry-connrefused -t 3 -T 15 -qO- 'http://169.254.169.254/la
 
 # Check IPs for correct format
 IP_REGEX="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
-if printf %s "$PUBLIC_IP" | grep -vEq "$IP_REGEX"; then
+if ! printf %s "$PUBLIC_IP" | grep -Eq "$IP_REGEX"; then
   echo "Cannot find valid Public IP, please edit the VPN script manually."
   exit 1
 fi
-if printf %s "$PRIVATE_IP" | grep -vEq "$IP_REGEX"; then
+if ! printf %s "$PRIVATE_IP" | grep -Eq "$IP_REGEX"; then
   echo "Cannot find valid Private IP, please edit the VPN script manually."
   exit 1
 fi