&& error_message "Forticlient installed version (${forticlient_current_version}) seems newest than expected (<${FORTICLIENT_NEW_VERSION}). Please see fortinet.vpn.v7.sh script instead."02
## }}}
## If the VPN must be stopped {{{
if["${request_status}"="stop"];then
debug_message "-- Disconnect VPN BEGIN"
### If the VPN is still connected {{{
forticlient_status=$(/opt/forticlient/fortivpn status | head --lines=1| sed 's/Status: \(.*\)/\1/'|| error_message "Error while requesting current VPN status." 22)
if["${forticlient_status}"="Connected"];then
debug_message "| VPN is ${RED}${forticlient_status}${COLOR_DEBUG}, try to disconnect it…"
|| error_message "Error while disabling forticlient-scheduler.service unit"13
### }}}
### Ensure to restart DNS resolver {{{
debug_message "| Try to restart systemd-resolved.service unit to have correct DNS resolvers."
sudo systemctl restart systemd-resolved.service \
|| error_message "Error while restart systemd-resolved.service unit"14
### }}}
debug_message "-- Disconnect VPN END"
fi
## }}}
## If the VPN must be started {{{
if["${request_status}"="start"];then
debug_message "-- Connect VPN BEGIN"
### If forticlient-scheduler.service unit is not started {{{
systemd_forticlient_status=$(systemctl show --property ActiveState --value forticlient-scheduler.service || error_message "Error while requesting forticlient-scheduler.service unit status." 21)
|| error_message "Error while (re)starting forticlient-scheduler.service unit"22
fi
### }}}
### If forticlient-scheduler.service unit is started {{{
systemd_forticlient_status=$(systemctl show --property ActiveState --value forticlient-scheduler.service || error_message "Error while requesting forticlient-scheduler.service unit status." 21)
if["${systemd_forticlient_status}"="active"];then
debug_message "| forticlient-scheduler.service unit is ${RED}started${COLOR_DEBUG}."
fi
### }}}
### If the VPN is not connected {{{
forticlient_status=$(/opt/forticlient/fortivpn status | head --lines=1| sed 's/Status: \(.*\)/\1/'|| error_message "Error while requesting current VPN status." 22)
if["${forticlient_status}"="Not Running"];then
### If script was started from a launcher {{{
if[ -n "${DISPLAY-}"]&&["${TERM}"="linux"];then
### Try to launch a new TERM_EMULATOR to ask the password
|| error_message "Error when connecting to VPN profile (${vpn_profile_name})."25
fi
### }}}
fi
### }}}
### If the VPN is connected {{{
forticlient_status=$(/opt/forticlient/fortivpn status | head --lines=1| sed 's/Status: \(.*\)/\1/'|| error_message "Error while requesting current VPN status." 22)
if["${forticlient_status}"="Connected"];then
debug_message "| VPN is ${RED}${forticlient_status}${COLOR_DEBUG}."
fi
### }}}
debug_message "-- Connect VPN END"
fi
## }}}
debug_message "--- MAIN END"
}
# }}}
# Manage arguments # {{{
# This code can't be in a function due to argument management
if[ ! "${NBARGS}" -eq "0"];then
manage_arg="0"
## If the first argument ask for help (h|help|-h|-help|-*h|-*help)