#!/bin/sh
# Copyright (C) 2000-2013 Boris Wesslowski
# $Id: fwlogsummary.cgi 731 2013-05-17 14:15:23Z bw $

# This script generates 8 fwlogwatch html summaries in a directory visible
# to your web server.
# The log file to be used can be specified as first parameter, default is
# /var/log/messages
# With respective permissions it can be run as cgi by the webserver.
# You can also invoke this script directly from the command line or from
# cron (you might want to remove the header output).

echo 'Content-type: text/plain'
echo

echo -n 'fwlogsummary invoked '
date

RECENT="-l 1h"
WEBDIR="/var/www/html/fwlogwatch"
FWLOGWATCH="/usr/local/sbin/fwlogwatch"

if [ ! -d $WEBDIR ] ; then
  echo "Directory $WEBDIR does not exist!"
  exit
fi

if [ ! -f $FWLOGWATCH ] ; then
  echo "$FWLOGWATCH not found!"
  exit
fi

if [ -z $1 ]
then
  MESSAGES="/var/log/messages"
else
  MESSAGES="$1"
fi

$FWLOGWATCH $MESSAGES $RECENT -w -t -z -S                -o $WEBDIR/dst.html
$FWLOGWATCH $MESSAGES $RECENT -w -t -z    -D             -o $WEBDIR/src.html
$FWLOGWATCH $MESSAGES $RECENT -w -t -z                   -o $WEBDIR/src_dst.html
$FWLOGWATCH $MESSAGES $RECENT -w -t -z       -s          -o $WEBDIR/src_dst_sp.html
$FWLOGWATCH $MESSAGES $RECENT -w -t -z          -d       -o $WEBDIR/src_dst_dp.html
$FWLOGWATCH $MESSAGES $RECENT -w -t -z       -s -d       -o $WEBDIR/src_dst_sp_dp.html
$FWLOGWATCH $MESSAGES $RECENT -w -t -z       -s -d -y    -o $WEBDIR/src_dst_sp_dp_op.html
$FWLOGWATCH $MESSAGES $RECENT -w -t -z       -s -d -y -n -o $WEBDIR/all.html

cat <<EOF > $WEBDIR/index.html

fwlogwatch

fwlogwatch summaries
regenerate summaries now

Summary by criteria:
Press the back button of your browser to return here.

- source IP address only
 
- destination IP address only
 
- source and destination IP addresses

- with source port
  
- with destination port
  
- with source and destination ports

- with tcp options

- everything and name resolution

fwlogwatch (http://fwlogwatch.inside-security.de/) © Boris Wesslowski

EOF

echo -n "Finished "
date

# EOF
