#!/bin/bash # # junkshow: junkview driver 2005-10-24, updated 2008-09-01 # # script to run junkview to produce a report for the last 24 (default) # hours for inclusion on we site # # Copyright (C) 2005-2008 Grant Coady # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; # version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License: # http://www.gnu.org/licenses/licenses.html#GPL # # Home site: http://bugsplatter.id.au/junkshow/ # # this program is run as cron job, it may need changing to suit your site, # written for a slackware system. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # 2008-09-01 # some mods for operation with pak-web-site, filenames and SSI marker # # 2008-08-13 # convert to new ip2cn-server operation, removing old access locking # # 2008-06-06 # remove multiple outputs and generate only the last 24 hours report # # 2006-09-04 # new timebased decision on reading prior logfile # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # user variables # report_hours=24 # report most recent number of hours report_owner="grant:wheel" # script run by root, chown output FILEPATH="/home/web/bugsplatter/junkshow" FILENAME="$FILEPATH/junkdata.text" # where to drop report # discover code path codepath=$(awk '/^codepath/ {print $2; exit}' /etc/junkview.conf) JUNKVIEW="$codepath/bin/junkview" LOG="messages" # file that gets iptables log events OPTIONS="verbose=1 " # options passed to junkview #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # output file must carry a SSI marker so it can be detected by the # pak-web-site script as an SSI include file to be inserted prior # to compressing the caller's file -- marker shall be on first line # printf "%s\n%s\n" "" "
" > $FILENAME

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# previous logfile may be messages.1 or messages.1.gz, choose prior 
#  logfile name and gawk input pipe method
#
log_read=""
log_file=""
if [ -r /var/log/$LOG.1.gz ]		# previous logfile is compressed
then
	log_file="/var/log/$LOG.1.gz"
	log_read="zcat"
	
elif [ -r /var/log/$LOG.1 ]		# previous logfile is not compressed
then
	log_file="/var/log/$LOG.1"
	log_read="cat"
fi

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# get datestamp of prior logfile and check if it is with the last 24 hours, 
#  in which case we shall have to read the previous logfile to get a full 
#  previous n hours' log events to build report from
#
now_stamp=$(date +%s)
log_stamp=$now_stamp

[ -r $log_file ] && log_stamp=$(stat --format=%Z $log_file)

start=$(( now_stamp - (report_hours * 3600) ))

if [ $start -lt $log_stamp ]
then
	$log_read $log_file | $JUNKVIEW -v hours=$report_hours \
			$OPTIONS - /var/log/$LOG >> $FILENAME
else
	$JUNKVIEW -v hours=$report_hours $OPTIONS /var/log/$LOG >> $FILENAME
fi

echo "
" >> $FILENAME chown $report_owner $FILENAME #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # run the .html file compressor # echo $(date +%F.%T) > /var/log/junkshow.log cd $FILEPATH /usr/local/bin/pak-web -d >> /var/log/junkshow.log chown $report_owner index.html.gz # end