From a8305ba541273a2df61405352a30b585bd4359d4 Mon Sep 17 00:00:00 2001 From: Gondolf <145931259+vGondolf@users.noreply.github.com> Date: Mon, 3 Feb 2025 21:41:49 +0100 Subject: [PATCH] Create fortigate.sh Deploy certificates to FortiGate firewall --- deploy/fortigate.sh | 104 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 deploy/fortigate.sh diff --git a/deploy/fortigate.sh b/deploy/fortigate.sh new file mode 100644 index 00000000..e5b80a57 --- /dev/null +++ b/deploy/fortigate.sh @@ -0,0 +1,104 @@ +#!/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) +# +# 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/') + error_code=$(echo "$1" | grep -o '"error":[ ]*[-0-9]*' | sed 's/"error":[ ]*\([-0-9]*\)/\1/') + http_status=$(echo "$1" | grep -o '"http_status":[ ]*[0-9]*' | sed 's/"http_status":[ ]*\([0-9]*\)/\1/') + + if [ "$status" != "success" ]; then + _err "FortiGate error: HTTP $http_status, Code $error_code" + 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 <