All pastes #267821 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-12-05 03:13 UTC
rendered paste body
#!/bin/sh
# $Id$
# Establish an SA between Schlund+Partner and me

if [ `id -u` -ne "0" ]; then
	sudo $0 $@
    exit
fi

SETKEY=/usr/local/sbin/setkey
MYIP=`/sbin/ifconfig | grep -A2 vr0 | grep 'inet ' | cut -d ' ' -f 2`
GWIP="212.227.125.246"

RUNFILE="/var/run/schlund-ipsec.log"

case "$1" in
	start)
		if [ -e $RUNFILE ]; then
			echo "!==> IPSEC services already running."
			return 1;
		fi
		touch $RUNFILE

		echo "Starting IPsec"

		# Cleaning up old configurations
		killall racoon 2>/dev/null
        killall l2tpd 2>/dev/null
		$SETKEY -PF

        echo "---> setkey configuration"
	    $SETKEY -c <<EOF
		spdadd $MYIP $GWIP any -P out ipsec esp/tunnel/$MYIP-$GWIP/unique ;
		spdadd $GWIP $MYIP any -P  in ipsec esp/tunnel/$GWIP-$MYIP/unique ;
EOF

        echo "---> Starting racoon"
		racoon -f /usr/local/etc/racoon/racoon.conf -l /var/log/racoon.log
        
        echo "---> Starting l2tp"
        l2tpd -c /usr/local/etc/l2tp/l2tpd.conf
		;;

	stop)
		if [ ! -e $RUNFILE ]; then
			echo "!==> IPSEC services not running."
			return 1;
		fi
		echo "Stopping IPSEC services"

        echo "h SchlundVPN" > /var/run/l2tp-control
        sleep 1

		killall racoon
        killall l2tpd
		$SETKEY -PF

		rm -f $RUNFILE
		;;

	status)
		echo -n "IPSEC services "
		if [ -e $RUNFILE ]; then echo "running."; fi
		if [ ! -e $RUNFILE ]; then echo "not running."; fi
		;;
	*)
		echo "$0 (start|stop|status)"
		;;
esac