#!/bin/sh

# place the commands to run after the pppd dial up successfully.

#check if multi-pppoe has dialed.
wanmode=`nvram_get 2860 wanConnectionMode`
wan_if=eth2.2

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

  level=`cat /etc/ppp_status`

	if [ "$level" = "1" ]; then
      if [ -x /bin/qos_run ]; then
      	echo "/bin/qos_run"
      	/bin/qos_run
      fi
	    
			cp /etc_ro/ppp/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`
      echo "$u * $pw" >> $chap_file
      echo "$u * $pw" >> $pap_file

	    pppoe_opmode=`nvram_get 2860 wan_pppoe_opmode`
      ac=`nvram_get 2860 wan_pppoe_ac2` 

	    if [ "$pppoe_opmode" = "" ]; 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 $ac
	    fi
      echo "2" > /etc/ppp_status  
	fi

  #session 2 link up.
	if [ "$level" = "2" ]; then
      rm -fr /etc/ppp_status 
			cat /etc_ro/ppp/resolv.conf >> /etc/resolv.conf
			/sbin/ddns.sh
      # run ppp1 route rules.
      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
  fi

else
if [ -x /bin/qos_run ]; then
	echo "/bin/qos_run"
	/bin/qos_run
fi
#patch for ddns update procedure by lonwn 2009/1/19 12:51
	echo "resolv.conf backup to /etc/resolv.conf"
	cp /etc_ro/ppp/resolv.conf /etc/resolv.conf
	sleep 1
  
  if [ -f "/var/resolv.ppp0" ]; then 
	eval `cat /var/resolv.ppp0 | grep remote`
	route add default gw $remote dev ppp0
  fi
  
	echo "rung ddns update procedure."
	/sbin/ddns.sh

fi
