#!/bin/sh
CNT_FORCE=`rdcsman 0x8001000E u32`
usage () {
        echo "$0 [start|stop]"
        exit 1
}


# main ##########################################################

[ -z "$1" ] && usage
case "$1" in

	start)
		if [ $CNT_FORCE = 1 ] ; then
			pptp-stop
		fi
		uvm /usr/uo/pap-secrets.uo > /etc/ppp/pap-secrets 
    	uvm /usr/uo/chap-secrets.uo > /etc/ppp/chap-secrets            
        uvm /usr/uo/pptp.conf.uo > /etc/ppp/pptp.conf
		uvm /usr/uo/options.pptp.uo > /etc/ppp/options.pptp
		echo "$0: start"		
		
		pptp-start 

		if [ "$CNT_FORCE" = "1" ] ; then
			wrcsman "0x8001000E 0x00"
		fi		
		
		if [ $? = 0 ] ; then
			exit 0
		else
			wrcsman "0x80050700 0x03 && \
					 0x80010007 0x03"
			exit 1	         
		fi
		;;	
	
	stop)
		#pptp-stop > /dev/null 2>&1 
		pptp-stop 
		RET=$?
		
		wrcsman "0x80050200 0x00 && \
			 	 0x80050300 0x00 && \
			 	 0x80050400 0x00 && \
				 0x80050500 0x00 && \
				 0x80050600 0x00 && \
				 0x80050700 0x00 && \
				 0x80010002 0x00 && \
				 0x80010003 0x00 && \
				 0x80010004 0x00 && \
				 0x80010005 0x00 && \
				 0x80010006 0x00 && \
				 0x80010007 0x00"
			 
		exit $RET
		
		;;
			
	*)
		exit 1
esac

exit 0		

		
	
			
