#! /bin/sh
#
# portsentry    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: portsentry
# configfile: /etc/portsentry/portsentry.conf
# pidfile: /var/run/portsentry.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: "
        if [ -s /etc/portsentry/portsentry.modes ] ; then
                modes=`cut -d "#" -f 1 /etc/portsentry/portsentry.modes`
        else
                modes="tcp udp"
        fi
        for i in $modes ; do
                portsentry -$i
                echo -n "$i "
        done
        echo
        touch /var/lock/subsys/portsentry
        ;;
  stop)
        echo -n "Stopping Port Scan Detector: "
        killproc portsentry
        echo
        rm -f /var/lock/subsys/portsentry
        ;;
  status)
        status portsentry
        ;;
  restart|reload)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: portsentry {start|stop|status|restart|reload}"
        exit 1
esac

exit 0
