| Current Path : /cmd/ |
| Current File : //cmd/zweb-certscan.20220422 |
#!/bin/bash
debug=0
notify=0
notify_state='Expir'
host=$(head -1 /etc/HOSTNAME)
rcpt='help@zootzone.com'
export PATH=/cmd:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
mkdir -p $HOME/tmp
touch $HOME/tmp/tls.crt.tmp
for i in hosts panel; do
[[ -d /etc/nginx/$i ]] || continue
cd /etc/nginx/$i
grep -E '^[ \t]{1,}(ssl_certificate).*\.crt' w* \
| tr -s '[[:space:]]' \
| sed 's/.*ssl_certificate //g' \
| tr -d ';' \
>> $HOME/tmp/tls.crt.tmp
done
cd $HOME/tmp
cat tls.crt.tmp | sort | uniq > tls.crt
rm tls.crt.tmp
if ! cat tls.crt | wc -l | grep -qv ^0; then
# no certs found
exit 0
fi
cat /dev/null > tls.notify
cat tls.crt | sort | uniq > tls.crt.uniq
while read path; do
cert=$(basename $path)
if [ $debug -eq 1 ]; then
echo "$path"
fi
if [ ! -f $path ]; then
notify=1
echo "Missing $path" >> tls.notify
else
result=$(ssl-cert-check -c $path \
| grep -Ev '^(--|Host)' \
| tr -s ' ' \
| sed 's/FILE://g' \
| tr -d "\n");
state=$(echo "$result" | cut -d ' ' -f2)
stamp=$(echo "$result" | cut -d ' ' -f3-5)
days=$(echo "$result" | cut -d ' ' -f6)
if echo "$state" | grep -q $notify_state; then
notify=1
if [ $debug -eq 1 ]; then
echo "$state $days ($stamp) $cert"
fi
echo "$state $days ($stamp) $path" >> tls.notify
fi
fi
done < tls.crt.uniq
if [ $notify -eq 1 ]; then
echo "From: root@$host
To: zoot@zootzone.com
Subject: SSL Cert Expiry ($host)
$(cat tls.notify)" | qmail-inject -f root@$host $rcpt
fi