From d6a31dc4382acbc21c383bf3de2ad6a429337822 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 9 Dec 2020 09:19:42 +0100 Subject: [PATCH] Extending bin/start-openfortivpn by checking the gateway IP address --- bin/start-openfortivpn | 24 ++++++++++++++++++++++++ lib/functions.rc | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bin/start-openfortivpn b/bin/start-openfortivpn index 8ead94c..76baf4d 100755 --- a/bin/start-openfortivpn +++ b/bin/start-openfortivpn @@ -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" diff --git a/lib/functions.rc b/lib/functions.rc index c24d318..536c692 100644 --- a/lib/functions.rc +++ b/lib/functions.rc @@ -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" -- 2.39.5