#! /bin/sh
#
# chkconfig: 2345 90 25
#
### BEGIN INIT INFO
# Provides: $sshguard
# Required-Start: $syslog
# Default-Start: 2 3 4 5
# Short-Description: starting and stoppning SSHGuard Daemon
# Description: Sshguard is a small program that monitors services running \
# on your machine from the log files. When it detects that someone is \
# doing something bad to a service, sshguard blocks the IP address of \
# the bad guy with a firewall rule.\
# Project page http://www.sshguard.net\
# Startup script by an0maly.andr@gmail.com
#

#Source function library.
. /etc/init.d/functions

D_PATH="/usr/local/sbin/sshguard"
LOGFILES=(/var/log/secure)
PIDFILE="/var/run/sshguard.pid"
PROG="SSHGuard"
OPTIONS="-a 5 -w 127.0.0.1"
LOGSUCKER_OPT=""

check() {
status $D_PATH
}

start() {
echo -n $"Starting $PROG: "
if [ -f $PIDFILE ]; then
echo -n "$PROG already started"
echo_failure
echo
else
for lfl in ${LOGFILES[@]}; do
if [ ! -f $lfl ]; then
echo -n "$lfl not found!"
else
LOGSUCKER_OPT="$LOGSUCKER_OPT -l $lfl"
fi;
done
$D_PATH $LOGSUCKER_OPT $OPTIONS -i $PIDFILE 2>/dev/null &
sleep 2
if [ -f $PIDFILE ]; then
echo_success
else
echo_failure
fi;
echo
return
fi;
}

stop() {
echo -n $"Stopping $PROG: "
killproc -p $PIDFILE
echo
return $RETVAL
}

case "$1" in

start)
start
;;

stop)
stop
;;

status)
check
;;

restart)
stop
start
;;

*)
echo $"Usage: $0 {start|stop|restart|status}"
;;
esac

exit $RETVAL 