##  Copyright (c) 2004  Code Fusion cc
##
##  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; either version 2, or
##  (at your option) any later version.
##
##  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 for more details.
##
##  You can view the  GNU General Public License, online, at the GNU
##  Project's homepage; see <http://www.gnu.org/licenses/gpl.html>.
##

prefix=@l_prefix@

if [ ".$1" = ".--showhelp" ]; then
	echo "Display the Kolab server logs"
	exit 0
	HASHELP
fi

#list of logfiles, maintainers please update
logfiles="
$prefix/var/proftpd/proftpd.log
$prefix/var/amavisd/amavis.log
$prefix/var/fsl/fsl.log
$prefix/var/sasl/log/saslauthd.log
$prefix/var/resmgr/resmgr.log
$prefix/var/resmgr/freebusy.log
$prefix/var/clamav/clamd.log
$prefix/var/imapd/log/master.log
$prefix/var/imapd/log/misc.log
$prefix/var/apache/log/apache-error.log
$prefix/var/apache/log/apache-access.log
$prefix/var/openldap/openldap.log
$prefix/var/postfix/log/postfix.log
"

if [ ".$PAGER" = "." ]; then
	PAGER=less
fi


if [ ".$1" = "." ]; then
	for log in $logfiles; do
		echo $log 
	done
	echo
	echo "To view a log please specify the <logname> or \"-t <logname>\""
	echo "It is also possible to abbreviate the logname, for example:"
	echo "\"showlog postfix\" will display the postfix log."
else 
	if [ ".$1" = ".-t" ]; then
		PAGER="tail -f "
		if [ ".$2" = "." ]; then
			exit 0;
		else
			showme=$2
		fi
	else 
		showme=$1
	fi
		
	for log in $logfiles; do
		match=`echo $log | grep $showme`
		if [ ".$match" != "." ]; then
			$PAGER $log
		fi
	done
fi

