#!/usr/bin/env sh # Script to deploy a certificate to FortiGate via API and set it as the current web GUI certificate. # # REQUIRED: # export FGT_HOST="fortigate_hostname-or-ip" # export FGT_TOKEN="fortigate_api_token" # # OPTIONAL: # export FGT_PORT="10443" # Custom HTTPS port (defaults to 443 if not set) # # This script is intended for use as an acme.sh deploy hook. # # Run `acme.sh --deploy -d example.com --deploy-hook fortigate --insecure` to use this script. # '--insecure' is required to allow acme.sh to connect to the FortiGate API over HTTPS without a pre-existing valid certificate. # Function to parse response from the firewall parse_response() { status=$(echo "$1" | grep -o '"status":[ ]*"[^"]*"' | sed 's/"status":[ ]*"\([^"]*\)"/\1/') if [ "$status" != "success" ]; then _err "Operation failed. Deploy with --insecure if current certificate is invalid. Try deploying with --debug to troubleshoot." return 1 else _debug "Operation successful." return 0 fi } # Function to deploy certificate to firewall deployer() { cert_base64=$(cat "$_cfullchain" | _base64) key_base64=$(cat "$_ckey" | _base64) payload=$(cat <