#!/bin/sh

# Bring up/down ipsec

PIDFILE="/var/run/pptpd.pid"
SERVICE=pptpd

. /etc/sysconfig/rc.conf
. /bin/network-functions
. /etc/image_features

BINDIR="/bin"
CONFDIR="/etc/ppp-poptop"

do_start ()
{
    if ! ServiceCheckRunning1 ; then
	return $?
    fi

    /etc/init.d/softdogd wait
    ## update/erase logfile
    echo "<--erase fiadlog-->" > /tmp/logs/pptpd.log

#if [ "$FEATURE_FIREWALL" = "1" ] ; then
#    /bin/firewall system add pptpd > /dev/null 2>&1
#fi

    /bin/setsid "$BINDIR"/pptpd -c "$CONFDIR"/pptpd.conf --option "$CONFDIR"/options.pptpd  > /dev/null 2>&1
    
    ServiceCheckRunning2
    return $?
}

do_stop ()
{
	/etc/init.d/softdogd wait
    ## kill service
    ServiceStop

    ## it's childs 
    killall ppp-poptop > /dev/null 2>&1

#if [ "$FEATURE_FIREWALL" = "1" ] ; then
#    ## and close the firewall
#    /bin/firewall system del pptpd > /dev/null 2>&1
#fi

    return $?
}

do_status ()
{
    ServiceStatus
    return $?
}

case "$1" in
	start)
		do_start
		;;
	stop)
		do_stop
		;;
	status)
		do_status
		;;
	restart)
		do_stop
		do_start
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 1
esac

exit $?
