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
This commit is contained in:
tom
2021-09-01 21:49:44 +02:00
committed by Thomas C
parent 4dae925030
commit 02d25b52eb

View File

@@ -1,15 +1,14 @@
#! /bin/bash #! /bin/bash
# param IN: csv file containing userdir,useremail,maxageofbackup in days set -e
# ex: /srv/burp/cafeine:thomas@foobar.org:4 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 not_found=1
too_old=2 too_old=2
source <(grep clientconfdir /etc/burp/burp-server.conf | sed 's/ *= */=/g')
list=$1
if [ ! -r $list ] ; then
echo "gimme a csv file"
exit 5
fi
function mail_error { function mail_error {
user=$1 user=$1
@@ -21,21 +20,42 @@ function mail_error {
exit $code exit $code
;; ;;
($too_old): ($too_old):
echo -e "Pas de sauvegarde depuis $fileage jours.\n\nPensez a laisser votre pc connecte entre midi et 2, ou lancez une sauvegarde manuelle." | mail -s "Pb de sauvegarde" $user 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 esac
} }
IFS=\; for file in $clientconfdir/* ; do
while read userdir mail maxage ; do if ( ! grep -q warn $file ) ; then continue ; fi
if [[ $userdir =~ ^# ]] ; then continue ; fi if [ ! -f $file ] ; then continue ; fi
timestampfile=${userdir}/current/timestamp maxage=$(awk -F= '/warn/{print $2}' $file)
let "maxage=$maxage*86400" mail=$(awk -F= '/mail/{print $2}' $file)
test -r $timestampfile || { mail_error $mail $not_found ; continue ; } 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") fileage=$( stat -c '%Y' $timestampfile)
let "delta=$now-$fileage" now=$(date "+%s")
if [ $delta -gt $maxage ] ; then let "delta=$now-$fileage"
echo $mail $too_old $(($delta/86400)) if [ $delta -gt $maxage ] ; then
fi echo $mail $too_old $(($delta/86400))
done < $1 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