Skip to content

Instantly share code, notes, and snippets.

@itsamirhn
Last active April 8, 2024 08:12
Show Gist options
  • Save itsamirhn/d7ce1ec19543e6099a66c068159f99d1 to your computer and use it in GitHub Desktop.
Save itsamirhn/d7ce1ec19543e6099a66c068159f99d1 to your computer and use it in GitHub Desktop.
OpenFortiVPN easy usage with OTP in Terminal
#!/bin/zsh
### Fill these paramters in your enviroment
# export OPENFORTIVPN_GATEWAY = '...' (host:port)
# export OPENFORTIVPN_OTP = '...' (4-digit)
# export OPENFORTIVPN_OTP_COMMAND = '...' (runtime otp)
# export OPENFORTIVPN_CONFIG = '...' (config file path)
_forti() {
args=()
if [[ -v OPENFORTIVPN_GATEWAY ]]; then
args+=($OPENFORTIVPN_GATEWAY)
fi
if [[ -v OPENFORTIVPN_CONFIG ]]; then
args+=("--config" $OPENFORTIVPN_CONFIG)
fi
if [[ ${#args[@]} -eq 0 ]]; then
echo "At Least on of OPENFORTIVPN_CONFIG or OPENFORTIVPN_GATEWAY should provided!"
return 1
fi
if [[ -v OPENFORTIVPN_OTP ]]; then
args+=("--otp" $OPENFORTIVPN_OTP)
elif [[ -v OPENFORTIVPN_OTP_COMMAND ]]; then
tmpOtp=$(eval $OPENFORTIVPN_OTP_COMMAND)
args+=("--otp" $tmpOtp)
fi
exec sudo openfortivpn ${args[@]}
}
_forti

Requirements

You just need to install openfortivpn as documented here

Usage

  1. Copy forti file into /usr/local/bin folder
  2. Give execute permission to forti file (chmod +x /usr/local/bin/forti)
  3. Setup OPENFORTIVPN env variables as needed. Checkout totp-cli for OTP. e.g:
export OPENFORTIVPN_OTP_COMMAND="totp-cli g work forti" 
export OPENFORTIVPN_CONFIG=path/to/forticonfig

# --- forticonfig content ---
# host = forti.domain.xyz
# port = 443
# username = [email protected]
# otp-prompt = "Please Enter OTP Code"
# ---------------------------
  1. Run forti in terminal and enter necessary passwords!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment