#!/bin/sh
#
# Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for Debian by Christoph Lameter <clameter@debian.org>.
# Modified for icmplogd by Johnie Ingram <johnie@debian.org>.
# Modified for configuration options by Hugo Haas <hugo@debian.org>.

PATH=/bin:/usr/bin:/sbin:/usr/sbin
TCPLOGD=/usr/sbin/tcplogd
ICMPLOGD=/usr/sbin/icmplogd

test -f $ICMPLOGD || exit 0
test -f $TCPLOGD || exit 0

#
# Read the configuration file
#

CONFIG=/etc/iplogger.conf

test -f $CONFIG || exit 0

RUN_ICMPLOGD=0
if grep -q ^start-icmplogger $CONFIG
then
  RUN_ICMPLOGD=1
fi

RUN_TCPLOGD=0
if grep -q ^start-tcplogger $CONFIG
then
  RUN_TCPLOGD=1
fi

if grep -q ^log-in-file $CONFIG
then
  OPTIONS=-l
fi


#
# Run the daemons
#

case "$1" in
  start)
    echo -n "Starting IP paranoia daemons:"
    if [ $RUN_TCPLOGD = 1 -a -x $TCPLOGD ]
    then
	echo -n " tcplogd"
	start-stop-daemon --start --verbose --quiet --exec $TCPLOGD -- $OPTIONS
    fi
    if [ $RUN_ICMPLOGD = 1 -a -x $ICMPLOGD ]
    then
	echo -n " icmplogd"
	start-stop-daemon --start --verbose --quiet --exec $ICMPLOGD -- $OPTIONS
    fi
    echo "."
    ;;

  stop)
    echo "Stopping IP paranoia daemons."
    start-stop-daemon --stop --quiet --oknodo --exec $TCPLOGD
    start-stop-daemon --stop --quiet --oknodo --exec $ICMPLOGD
    ;;

  restart)
    $0 stop
    $0 start
    ;;

  force-reload)
    $0 restart
    ;;

  *)
    echo "Usage: /etc/init.d/$0 {start|stop|restart|force-reload}"
    exit 1
    ;;
esac

exit 0
