#!/bin/bash

#-----------------------------------------------------------------------------#
#  Copyright (C) 2001 - 2002 Multi-Tech Systems Inc., USA
#  All Rights Reserved
#  Multi-Tech Systems, Inc., 2205, Woodale Dr, Mounds View MN USA
#-----------------------------------------------------------------------------#
#  ModName: Deletion of all the Logs & Graphs 
#  Version: 3.25
#  Date: 2005-10-05
#  Modification History - Begin
#  Modification History - End

#----------------------------------------------------------------------------
#Description	:	This script is used to delete all the log files from
#			/var/log , /usr/local/apache/htdocs/mrtg , Quarantine
#			mails , HTTP Access & Reject Reports ,PPTP history
#			of calls and Interface based accounting. 
#----------------------------------------------------------------------------

#To clear all the /var/log related Files.


PATH=/var/log
list_of_files=`/bin/ls $PATH`
#echo -n "Do you want to delete the Log Backups ? (y/n): "
#read ch
ch=$1
for i in $list_of_files
do
	if [ -f "$PATH/$i" ]
	then
		>$PATH/$i
	elif [ -d "$PATH/$i" ]
	then
		if [ "$i" = "snort" ]
		then
			list=`/bin/ls $PATH/$i  2>/dev/null`
				for j in $list
				do
					>$PATH/$i/$j
				done
		elif [ "$i" = "qmail" ]
		then
			>$PATH/$i/current
			list_qmail=`/bin/ls $PATH/$i/*.u 2>/dev/null`
				for k in $list_qmail
				do
					>$k
				done
			/bin/rm -f $PATH/$i/smtpd/*.u 2>/dev/null
			/bin/rm -f $PATH/$i/smtpd/*.s 2>/dev/null
			/bin/rm -f $PATH/$i/qmaillog/*.gz 2>/dev/null
		elif [ "$i" = "backup" ]
		then
			if [ $ch = "y" ]
			then
				list_bkp=`/bin/ls $PATH/$i 2>/dev/null`
				for l in $list_bkp
				do
					if [ -f "$PATH/$i/$l" ]
					then
						`/bin/rm -f $PATH/$i/$l`
					elif [ -d "$PATH/$i/$l" ]
					then
						if [ "$l" = "iptables" ]
						then
							list_ipt=`/bin/ls $PATH/$i/$l 2>/dev/null`
							for m in $list_ipt
							do
								`/bin/rm -f $PATH/$i/$l/$m`
							done
						fi
					fi
				done
			fi
		fi
	fi
done

#To clear all the MRTG related graphs.
#echo "Clearing logs related to MRTG graphs"
/bin/rm -f /usr/local/apache/htdocs/mrtg/* 2>/dev/null 
/etc/cron.sevenmins/mrtg  2>/dev/null

#To clear all the Qmail Analyzer logs
/bin/rm -rf /usr/local/apache/htdocs/qmaillog/* 2>/dev/null

post_pid=`/sbin/pidof postmaster`
if [ "$post_pid" != "" ]
then
	#To clear the Quarantine Mails from database and web UI.
#	echo "Clearing Quarantine Mails"
	/etc/multiconf/scripts/delquarantine 0 spam smtp -f
	/etc/multiconf/scripts/delquarantine 0 virus smtp -f
	/etc/multiconf/scripts/delquarantine 0 virus pop -f

	#To clear the PPTP History of Calls 
#	echo "Clearing PPTP Connection logs"
	/etc/multiconf/scripts/delpptp
else
	echo "Postgresql is not Running!!"
fi


#To clear the HTTP Access and Reject Reports
echo "Clearing HTTP logs" 
/bin/rm -rf /usr/local/apache/htdocs/squid-reports/* 1>/dev/null 2>/dev/null
/bin/rm -rf /usr/local/apache/htdocs/deny-reports/* 1>/dev/null 2>/dev/null

#To clear the Interface based Accounting details
echo "Clearing Interface based Accounting Logs"
>/etc/multiconf/accountingtx.txt
>/etc/multiconf/accountingrx.txt

#To clear the qmailqueue logs
>/var/spool/qmailscan/qmailqueue.log

#To clear the HTTP Access and Reject logs
/bin/rm -f /var/chroot-squid/usr/local/squid/logs/*.log.*
>/var/chroot-squid/usr/local/squid/logs/access.log
>/var/chroot-squid/usr/local/squid/logs/store.log
>/var/chroot-squid/usr/local/squid/logs/cache.log
>/var/chroot-squid/usr/local/squid/surfcontrol/surfing.log

#To clear the Apache logs
>/usr/local/apache/logs/access_log
>/usr/local/apache/logs/error_log
>/usr/local/apache/logs/ssl_engine_log
>/usr/local/apache/logs/ssl_request_log

