Skip to content

Commit

Permalink
feat: extend tls script to search for certs in a directory
Browse files Browse the repository at this point in the history
  • Loading branch information
d-Rickyy-b committed Sep 24, 2024
1 parent c411d5d commit a92d6df
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions 70-tls
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
# REQUIREMENTS: openssl
## CONFIG

certificates=(
"/path/to/cert"
"/etc/letsencrypt/live/domain/fullchain.pem"
certificate_dirs=(
"/opt/servarr/config/caddy/data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/"
)

certificateNames=(
"example.com"
"nice.domain.com"
custom_certificates=(
"/path/to/cert"
"/etc/letsencrypt/live/domain/fullchain.pem"
)

red="\e[31m"
Expand Down Expand Up @@ -47,6 +46,11 @@ expires_in () {
fi
}

# Find all certificates and extend with custom certificates
IFS=$'\n'
certificates=($(find "${certificate_dirs[*]}" -type f -name "*.crt" -o -name "*.cer" 2>/dev/null))
unset IFS
certificates+=("${custom_certificates[@]}")

echo ""
echo "tls certificates:"
Expand All @@ -55,7 +59,6 @@ output+=" Domain | Status\n"
for i in "${!certificates[@]}"; do
cert="${certificates[$i]}"
certname=$(openssl x509 -subject -noout -in "$cert" | cut -d " " -f3)

exp_date=$(expiry_date "$cert")
expires=$(unix_date "$exp_date")
now=$(unix_date "now")
Expand All @@ -69,11 +72,11 @@ for i in "${!certificates[@]}"; do
# But that takes a lot of time. We don't want to wait during login

if [ "$expires" -le "$now" ]; then
output+=" $red$undim ${certificateNames[$i]} | ${red}expired ($expiryDate)$undim\n"
output+=" $red$undim $certname | ${red}expired ($expiryDate)$undim\n"
elif [ "$expires" -le "$inAWeek" ]; then
output+=" $orange$undim ${certificateNames[$i]} | ${orange}expiring soon ($expiresIn left)$undim\n"
output+=" $orange$undim $certname | ${orange}expiring soon ($expiresIn left)$undim\n"
else
output+=" $green$undim ${certificateNames[$i]} | ${green}expires in $expiresIn ($expiryDate)$undim\n"
output+=" $green$undim $certname | ${green}expires in $expiresIn ($expiryDate)$undim\n"
fi
done

Expand Down

0 comments on commit a92d6df

Please sign in to comment.