Files
BurpCheckAge/check_burp_age.sh
tom 02d25b52eb script read burp client config file looking for warn and email parameter.
If present, it checks timestamp file and send an email if timestamp mtime is older than warn
2021-09-01 21:49:44 +02:00

61 lines
2.0 KiB
Bash
Executable File

#! /bin/bash
set -e
set -u
# read burp client config files
# if file include "warn", then check last backup date
# if older than "warn" send message to "email"
not_found=1
too_old=2
source <(grep clientconfdir /etc/burp/burp-server.conf | sed 's/ *= */=/g')
function mail_error {
user=$1
code=$2
fileage=$3
case $code in
($not_found):
echo "timestamp file for $user not found or not readable" | mail -s "backup error" rscj@opendoor.fr
exit $code
;;
($too_old):
echo -e "Bonjour,\n\nVotre poste n'a pas été sauvegardé depuis $fileage jours.\n\nPensez à laisser votre pc allumé et connecté ce soir, afin que la sauvegarde puisse se faire correctement. \n\nN'hésitez pas à me contacter si le problème persiste ou pour plus de renseignement.\n\n---\nThomas Constans\nthomas@opendoor.fr\n" | mail -s "Pb de sauvegarde" $user
esac
}
for file in $clientconfdir/* ; do
if ( ! grep -q warn $file ) ; then continue ; fi
if [ ! -f $file ] ; then continue ; fi
maxage=$(awk -F= '/warn/{print $2}' $file)
mail=$(awk -F= '/mail/{print $2}' $file)
userdir=$(awk -F= '/directory/{print $2}' $file)
userdir=${userdir}/$(basename $file)
timestampfile=${userdir}/current/timestamp
let "maxage=$maxage*86400"
#test -r $timestampfile || { mail_error $mail $not_found ; continue ; }
test -r $timestampfile || { echo $mail $not_found ; continue ; }
fileage=$( stat -c '%Y' $timestampfile)
now=$(date "+%s")
let "delta=$now-$fileage"
if [ $delta -gt $maxage ] ; then
echo $mail $too_old $(($delta/86400))
mail_error $mail $too_old $(($delta/86400))
fi
done
#while read userdir mail maxage ; do
# if [[ $userdir =~ ^# ]] ; then continue ; fi
# timestampfile=${userdir}/current/timestamp
# let "maxage=$maxage*86400"
# test -r $timestampfile || { mail_error $mail $not_found ; continue ; }
#
# fileage=$( stat -c '%Y' $timestampfile)
# now=$(date "+%s")
# let "delta=$now-$fileage"
# if [ $delta -gt $maxage ] ; then
# echo $mail $too_old $(($delta/86400))
# fi
#done < $1