#! /bin/sh
#
# senry         Start the portsentry Port Scan Detector
#
# Author:       Craig Rowland <crowland@psionic.com>
#	      	
# chkconfig: 345 98 05
# description: Portsentry Port Scan Detector is part of the Abacus Project \
#              suite of tools. The Abacus Project is an initiative to release \
#              low-maintenance, generic, and reliable host based intrusion \
#              detection software to the Internet community.
# processname: sentry
# pidfile: /var/run/sentry.pid


# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
if [ ${NETWORKING} = "no" ]
then
	exit 0
fi

[ -f /usr/sbin/portsentry ] || exit 0

# See how we were called.
case "$1" in
  start)
	echo -n "Starting port scan detector: "
	for mode in atcp sudp; do
		portsentry -$mode
		echo -n "$mode "
	done
	echo
	touch /var/lock/subsys/portsentry
	;;
  stop)
	echo -n "Stopping port scan detector: "
	for proc in `ps aux | awk '/sentry \-.*$/ {print$2$12}'`; do
		kill `echo $proc | awk -F"-" '{print$1}'` || exit 0
		echo -n `echo $proc | awk -F"-" '{print$2'}`" "
	done
	echo
	rm -f /var/lock/subsys/portsentry*
	;;
  status)
	status portsentry
	;;
  restart|reload)
	$0 stop
	$0 start
	;;
  *)
	echo "Usage: inet {start|stop|status|restart|reload}"
	exit 1
esac

exit 0
