From b9291ea69797c93921236b80ad41b1ed08ab7a5a Mon Sep 17 00:00:00 2001 From: Gondolf <145931259+vGondolf@users.noreply.github.com> Date: Wed, 5 Feb 2025 12:24:33 +0100 Subject: [PATCH] Create fortigate.sh --- deploy/fortigate.sh | 162 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 deploy/fortigate.sh diff --git a/deploy/fortigate.sh b/deploy/fortigate.sh new file mode 100644 index 00000000..24213a16 --- /dev/null +++ b/deploy/fortigate.sh @@ -0,0 +1,162 @@ +#!/usr/bin/env sh +# Script to deploy a certificate to FortiGate via API and set it as the current web GUI certificate. +# +# FortiGate's native ACME integration does not support wildcard certificates, +# and is not supported if you have a custom management web port (eg. DNAT web traffic). +# +# 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 +parse_response() { + response="$1" + func="$2" + status=$(echo "$response" | grep -o '"status":[ ]*"[^"]*"' | sed 's/"status":[ ]*"\([^"]*\)"/\1/') + if [ "$status" != "success" ]; then + _err "[$func] Operation failed. Deploy with --insecure if current certificate is invalid. Try deploying with --debug to troubleshoot." + return 1 + else + _debug "[$func] Operation successful." + return 0 + fi +} + +# Function to deploy base64-encoded certificate to firewall +deployer() { + cert_base64=$(cat "$_cfullchain" | _base64 | tr -d '\n') + key_base64=$(cat "$_ckey" | _base64 | tr -d '\n') + payload=$(cat <