1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#!/usr/bin/env bash
echo "Running notify script: $@"
# Arguments specified by the burp binary come first.
# Normally, most of the following get set as you would expect.
# In the server_script_pre/post case, burp does not have a directory from
# which to read a log. In that case, it will set 'client' to the clientname,
# 'basedir' blank, and 'storagedir' to the log buffer.
client="$1" ; shift
basedir="$1" ; shift
storagedir="$1" ; shift
file="$1" ; shift
brv="$1" ; shift # one of backup/restore/verify/delete/list/unknown
warning_count="$1" ; shift
# Arguments given by the user in the conf files come next.
sendmail="$1" ; shift
working="$basedir/working"
finishing="$basedir/finishing"
while [ "$#" -gt 0 ] ; do
case "$1" in
Subject:*)
w=""
[ -n "$warning_count" -a "$warning_count" != "0" ] \
&& w="($warning_count warnings)"
h="$1"
h="${h//%c/$client}"
h="${h//%w/$w}"
h="${h//%b/$brv}"
;;
*) h="$1"
;;
esac
if [ -z "$headers" ] ; then
headers="$h"
else
headers=$(printf "%s\n%s\n" "$headers" "$h")
fi
shift
done
catcmd="gunzip -c"
# Look for a log to attach
if [ "$brv" = "backup" ] ; then
[ -z "$log" -a -f "$working/$file" ] && \
log="$working/$file" && id=$(cat "$working"/timestamp) && catcmd="cat"
[ -z "$log" -a -f "$working/$file.gz" ] && \
log="$working/$file.gz" && id=$(cat "$working"/timestamp)
[ -z "$log" -a -f "$finishing/$file" ] && \
log="$finishing/$file" && id=$(cat "$finishing"/timestamp) && catcmd="cat"
[ -z "$log" -a -f "$finishing/$file.gz" ] && \
log="$finishing/$file.gz" && id=$(cat "$finishing"/timestamp)
fi
[ -z "$log" -a -f "$storagedir/$file" ] && \
log="$storagedir/$file" && id=$(cat "$storagedir"/timestamp) && catcmd="cat"
[ -z "$log" -a -f "$storagedir/$file.gz" ] && \
log="$storagedir/$file.gz" && id=$(cat "$storagedir"/timestamp)
if [ -z "$log" -a -z "$basedir" -a -n "$storagedir" ] ; then
# This is the case where burp has no log directory and has given a buffer to
# log via the storagedir argument.
(echo "$headers" && echo && echo "$storagedir") | $sendmail
elif [ -z "$log" ] ; then
echo "$headers" && echo && echo "No log found to send in email" | $sendmail
else
# The normal case.
maximum_line_count=1000
(echo "$headers" && echo && echo "$id" && echo && echo "Last $maximum_line_count lines of $log:" && echo && ($catcmd "$log" 2>/dev/null || cat "$log") | tail -n "$maximum_line_count") | $sendmail
fi
exit 0
|