#!/bin/bash
#RP_L2TPD, version 1.1
# By: Hendrik-Jan Heins hjh@NOSPAM.passys.nl
# and: Jasper "AuC" Reuhman Jasper.Reuhman@NOSPAM.nethsoft.nl

# Verander onderstaande variabelen naar het juiste adres
# Change these settings to the ones that apply to your connection
L2TPDSERV=10.255.253.1                        # VPN Server
GATEWAY=10.206.240.1                          # Gateway

# Verander onder deze regel NIETS
# Don't change anything below this line

#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=l2tpd
DAEMON=/usr/local/sbin/l2tpd
CONTROL=/usr/local/sbin/l2tp-control
DESC="RP-l2tpd"
NAME=l2tpd

# Controleer of l2tpd bestaat
# Check whether l2tpd exists
if [ -x "$DAEMON" ]
then
        echo "Kan $DAEMON niet vinden. Installeer L2TPD voordat je dit script
start. Of controleer of de server nog niet geactiveerd is / Cannot find $DEAMON. Please install L2TPD
before running this script. Or check whether the server is activated."
        exit 0
fi

set -e

case "$1" in
        start)
                /sbin/route del default gw $GATEWAY
                sleep 1
                /sbin/route add -host $L2TPDSERV gw $GATEWAY
                sleep 2
                echo -n "Bezig met het starten van $DESC: $NAME / Starting $DESC: $NAME"
                $DAEMON start-stop-daemon
                sleep 1
                $CONTROL "start-session $L2TPDSERV"
                echo "tunnel... start!"
                ;;
        stop)
                echo -n "Bezig met het stoppen van $DESC: $NAME / Stopping $DESC: $NAME"
                $CONTROL exit
                echo "helaas, afgelopen! / too bad, stopped!"
                ;;
        restart|force-reload)
	#
	#	Als de "reload" optie bestaat, laat "force-reload" dan de "reload"
	#	optie uitvoeren. Zoniet, dan is de "force-reload" optie hetzelfde
	#	als "restart".
        #       If the "reload" option is implemented, move the "force-reload"
        #       option to the "reload" entry above. If not, "force-reload" is
        #       just the same as "restart".
        #
                echo -n "Bezig met herstarten van $DESC: $NAME / restarting $DESC: $NAME"
                $CONTROL exit
                sleep 1
                $DAEMON start-stop-daemon
                sleep 1
                $CONTROL "start-session $L2TPDSERV"
                echo "doet ie het nu nog niet? / Stil not working?"
                ;;
        *)
                N=/etc/init.d/$NAME
                echo "Usage: $N {start|stop|restart|force-reload}" >&2
                exit 1
                ;;
esac

exit 0
