]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Extending bin/start-openfortivpn by checking the gateway IP address
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 9 Dec 2020 08:19:42 +0000 (09:19 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 9 Dec 2020 08:19:42 +0000 (09:19 +0100)
bin/start-openfortivpn
lib/functions.rc

index 8ead94c4016de6be1802a561c67dfa1c9cd1ae49..76baf4d83bbcf9a483392e86c9f963a1eddecc3f 100755 (executable)
@@ -10,6 +10,7 @@ BASE_DIR=$( dirname "${BIN_DIR}" )
 LIB_DIR="${BASE_DIR}/lib"
 CONF_DIR="${BASE_DIR}/etc"
 DNS_DIR="${BASE_DIR}/dns"
+OFVPN_CONFIG="/etc/openfortivpn/config"
 
 if [[ -f "${LIB_DIR}/functions.rc" ]] ; then
     . "${LIB_DIR}/functions.rc"
@@ -97,6 +98,7 @@ check_preferences() {
     local rfile=
     local file_ok="y"
     local sample_file=
+    local gateway_ip=
 
     debug "Checking for openfortivpn ..."
     if type -p openfortivpn >/dev/null ; then
@@ -106,6 +108,28 @@ check_preferences() {
         error "Did not found openfortivpn. Maybe not installed?"
     fi
 
+    if [[ ! -f "${OFVPN_CONFIG}" ]] ; then
+        error "Config file '${RED}${OFVPN_CONFIG}${NORMAL}' not found."
+        all_ok="n"
+    else
+        gateway_ip=$( cat "${OFVPN_CONFIG}" | \
+                grep -i '^[    ]*host[         ]*=' | \
+                awk -F= '{print $2}' | \
+                sed -e 's/^[   ]*//' -e 's/[   ]*$//' )
+        if [[ -z "${gateway_ip}" ]] ; then
+            error "Did not found Gateway IP address in '${RED}${OFVPN_CONFIG}${NORMAL}'."
+            all_ok="n"
+        else
+            echo "Checking Gateway IP '${GREEN}${gateway_ip}${NORMAL}' ..."
+            if ping -q -c 2 -w 2 "${gateway_ip}" ; then
+                debug "Gateway IP '${CYAN}${gateway_ip}${NORMAL}' is okay."
+            else
+                error "Could not ping '${RED}${gateway_ip}${NORMAL}'."
+                all_ok="n"
+            fi
+        fi
+    fi
+
     for rfile in "${RESOLV_CONF_DPX}" "${RESOLV_CONF_NON_DPX}" ; do
         debug "Checking '${CYAN}${rfile}${NORMAL}' ..."
         file_ok="y"
index c24d318677fa7ca421fd86075a01196de52622de..536c692ee2ca384872860572e999f2f40bdb6709 100644 (file)
@@ -10,7 +10,7 @@ BLUE=""
 CYAN=""
 NORMAL=""
 
-VERSION="0.3.7"
+VERSION="0.3.8"
 
 STD_SHORT_OPTIONS="sdvhV"
 STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version"