${RED}${local_command_available_cmd}${COLOR_DEBUG} is not available on this host."
return_command_available="1"
fi
unset local_command_available_cmd
unset debug_prefix
return"${return_command_available}"
}
# }}}
main(){# {{{
debug_message "--- MAIN BEGIN"
## If forticlient command is not available {{{
### Exit with error
is_command_available "forticlient""| "\
|| error_message "forticlient is not in PATH, ensure the package is installed."01
## }}}
## Define all vars
define_vars
debug_message "| Define vars"
## If the VPN must be stopped {{{
if["${request_status}"="stop"];then
debug_message "-- Disconnect VPN BEGIN"
### If the VPN is still connected {{{
forticlient_status=$(forticlient vpn 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…"
### Try to discconnect
forticlient vpn disconnect > /dev/null \
|| error_message "Error when disconnecting VPN."11
fi
### }}}
### Stop the systemd service {{{
debug_message "| Try to stop and disable forticlient.service unit"
sudo systemctl stop forticlient.service \
|| error_message "Error while stopping forticlient.service unit"12
### Ensure to disable it
sudo systemctl disable forticlient.service \
|| error_message "Error while disabling forticlient.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.service unit is not started {{{
systemd_forticlient_status=$(systemctl show --property ActiveState --value forticlient.service || error_message "Error while requesting forticlient.service unit status." 21)
systemd_forticlient_status=$(systemctl show --property ActiveState --value forticlient.service || error_message "Error while requesting forticlient.service unit status." 21)
debug_message "| forticlient.service unit is ${RED}started${COLOR_DEBUG}."
fi
### }}}
### If the VPN is not connected {{{
forticlient_status=$(forticlient vpn status | head --lines=1| sed 's/Status: \(.*\)/\1/'|| error_message "Error while requesting current VPN status." 23)
|| error_message "Error when connecting to VPN profile (${vpn_profile_name})."25
fi
### }}}
fi
### }}}
### If the VPN is connected {{{
forticlient_status=$(forticlient vpn status | head --lines=1| sed 's/Status: \(.*\)/\1/'|| error_message "Error while requesting current VPN status." 25)
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