#!/bin/sh

#patch for ddns update procedure by lonwn 2009/1/19 12:51

	echo "resolv.conf backup to /etc/resolv.conf"
	#cp /etc_ro/resolv.conf /etc/resolv.conf
	sleep 1
	echo "rung ddns update procedure."
	/sbin/ddns.sh
wanmode=`nvram_get 2860 wanConnectionMode`
mtu=`nvram_get 2860 wan_pppoe_mtu`
model=`nvram_get 2860 Modelname`

wan_if=eth2.2

if [ "$wanmode" = "MPPPOE" ]; then

	level=`cat /etc/ppp_status`
	
	if [ "$level" = "1" ]; then
		#cp /etc_ro/resolv.conf /etc/resolv.conf
		sleep 1
		
		rm -fr /etc/ppp_status
		u=`nvram_get 2860 wan_pppoe_user2`
		pw=`nvram_get 2860 wan_pppoe_pass2`
		
		pppoe_opmode=`nvram_get 2860 wan_pppoe_opmode`
		if [ "pppoe_mode" = "" ]; then
			echo "pppoecd $wan_if -u $u -p $pw"
			pppoecd $wan_if -u "$u" -p "$pw"
		else
			pppoe_optime=`nvram_get 2860 wan_pppoe_optime`
			config-pppoe.sh $u $pw $wan_if $pppoe_opmode $pppoe_optime	
		fi
		echo "2" > /etc/ppp_status
		ifconfig ppp0 mtu $mtu

	# place the commands to run after the pppd dial up successfully.
	
	if [ -x /bin/qos_run ]; then
		echo "/bin/qos_run"
		/bin/qos_run
	fi

	fi

	if [ "$level" = "2" ]; then
		rm -fr /etc/ppp_status
		//cat /etc_ro/resolv.conf >> /etc/resolv.conf
		/sbin/ddns.sh
		# run ppp1 route rule
      route add -net 220.210.194.0 netmask 255.255.255.128 dev ppp1
      route add -net 220.210.195.0 netmask 255.255.255.192 dev ppp1
      route add -net 220.210.195.64 netmask 255.255.255.192 dev ppp1
      route add -net 220.210.197.0 netmask 255.255.255.128 dev ppp1
      route add -net 220.210.199.0 netmask 255.255.255.224 dev ppp1
      route add -net 220.210.199.176 netmask 255.255.255.240 dev ppp1
      route add -net 220.210.199.32 netmask 255.255.255.224 dev ppp1
      route add -net 220.210.199.200 netmask 255.255.255.248 dev ppp1
      route add -net 220.210.199.64 netmask 255.255.255.240 dev ppp1
      route add -net 220.210.203.0 netmask 255.255.255.224 dev ppp1       
			route add -net 220.210.203.208 netmask 255.255.255.248 dev ppp1
			route add -net 220.210.203.0 netmask 255.255.255.192 dev ppp1
			ifconfig ppp1 mtu $mtu
			
			//set dns information.
			eval `cat /var/dns_sess0`
			eval `cat /var/dns_sess1`
			dnsp=`nvram_get 2860 dnsPEnabled`
			wantype=`nvram_get 2860 wanConnectionMode`
			if [ "$dnsp" = "1" ] && [ "$wantype" = "MPPPOE" ]; then
			killall dnrd
		  	echo "1" > /proc/sys/net/ipv6/conf/all/forwarding 
	    	mkdir -p /etc/dnrd	
				dnrd -s $PrimaryDNS_02:flets -s $SecondaryDNS_02:flets -s $PrimaryDNS_01 -s $SecondaryDNS_02
			fi
			ifconfig ppp0 mtu $mtu
			ifconfig ppp1 mtu $mtu	
  fi
else

	# place the commands to run after the pppd dial up successfully.
	
	if [ -x /bin/qos_run ]; then
		echo "/bin/qos_run"
		/bin/qos_run
	fi

	echo "resolv.conf backup to /etc/resolv.conf"
	cp /etc_ro/resolv.conf /etc/resolv.conf
	sleep 1
	echo "run ddns update procedure."
	/sbin/ddns.sh
	ifconfig ppp0 mtu $mtu
fi