Last active
August 24, 2023 06:37
-
-
Save joltcan/e421b131450aee532ea209e32e8c186c to your computer and use it in GitHub Desktop.
Add and update VPN certificate in fortigate firewalls from acme.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CRTFILE=~/.acme.sh/domain.com_ecc/fullchain.cer | |
KEYFILE=~/.acme.sh/domain.com_ecc/domain.com.key | |
CRTNAME="Acme.sh domain.com $(date +%Y-%m-%d)" | |
ADMINPORT=8444 | |
APITOKEN="<apitoken>" | |
for FIREWALL in vpnhost1 vpnhost2 | |
do | |
POSTCERT=$(echo -n '{"type":"regular","certname":"'"${CRTNAME}"'","scope":"global","file_content":"'$(base64 -w0 ${CRTFILE})'","key_file_content":"'$(base64 -w0 ${KEYFILE})'"}' | \ | |
curl -H "Content-Type: application/json" -d @- -s -k "https://${FIREWALL}:${ADMINPORT}/api/v2/monitor/vpn-certificate/local/import?vdom=root&access_token=${APITOKEN}" | jq -e '.status == "success"') | |
if [ "$?" -eq 0 ] | |
then | |
CHANGECERT=$(echo -n '{"servercert":"'"${CRTNAME}"'"}' | \ | |
curl -XPUT -H 'Content-Type: application/json' -d @- -s -k "https://${FIREWALL}:${ADMINPORT}/api/v2/cmdb/vpn.ssl/settings?vdom=root&access_token=${APITOKEN}" | jq -e '.status == "success"') | |
if [ "$?" -gt 0 ] | |
then | |
/usr/local/bin/slackpost.sh notifications "Could not activate acme certificate on ${VPNHOST}" | |
fi | |
else | |
/usr/local/bin/slackpost.sh notifications "Could not update acme certificate on ${VPNHOST}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment