Last active
February 23, 2022 02:45
-
-
Save lstellway/41f90155b1f57560b240154be257df60 to your computer and use it in GitHub Desktop.
Shell utility to help find the certificates used by a specified FQDN on Synology NAS
This file contains hidden or 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/sh | |
# Help | |
if [ "$1" == "-h" -o "$1" == "--help" ]; then | |
SCRIPT="$(basename ${0})" | |
cat <<EOF | |
${SCRIPT} | |
Shell utility to help find the certificates used by a specified FQDN on Synology NAS | |
Usage | |
${SCRIPT} example.com | |
EOF | |
exit | |
fi | |
# Ensure a FQDN is provided | |
if [ -z "$1" ]; then | |
printf "Please provide a domain name to search for.\n" | |
exit 1 | |
fi | |
# Get the related service ID | |
SERVICE=$(jq -r 'keys[] as $k | select($k != "version") | select(.[$k].frontend.fqdn | contains("'$1'")) | $k' "/usr/syno/etc/www/ReverseProxy.json") | |
if [ -z "$SERVICE" ]; then | |
printf "Could not find service with requested FQDN.\n" | |
exit 1 | |
fi | |
# Get certificates used by service | |
DIR="/usr/syno/etc/certificate/_archive" | |
ID=$(jq -r 'keys[] as $k | select(.[$k].services[0].service == "'$SERVICE'") | $k' "${DIR}/INFO") | |
if [ -z "${ID}" ]; then | |
printf "No certificates could be found for the requested service.\n" | |
exit 1 | |
fi | |
cat <<EOF | |
${DIR}/${ID}/cert.pem | |
${DIR}/${ID}/chain.pem | |
${DIR}/${ID}/fullchain.pem | |
${DIR}/${ID}/privkey.pem | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment