#!/bin/sh
. /etc/functions.sh
PPP_IFACE="$1"
PPP_TTY="$2"
PPP_SPEED="$3"
PPP_LOCAL="$4"
PPP_REMOTE="$5"
PPP_IPPARAM="$6"
export PPP_IFACE PPP_TTY PPP_SPEED PPP_LOCAL PPP_REMOTE PPP_IPPARAM
[ -z "$PPP_IPPARAM" -o -z "$PPP_LOCAL" ] || {
	if [ "$PPP_IPPARAM" == "wan" ]; then
		uci_set_state network "$PPP_IPPARAM" ipaddr "$PPP_LOCAL"
		uci_set_state network "$PPP_IPPARAM" gateway "$PPP_REMOTE"
		sh /etc/setup_shnat_pppoe.sh > /tmp/re
		sh /etc/check_shnat_ip.sh &
		/etc/init.d/firewall restart
	fi
}
[ -z "$PPP_IPPARAM" ] || env -i ACTION="ifup" INTERFACE="$PPP_IPPARAM" DEVICE="$PPP_IFACE" PROTO=ppp /sbin/hotplug-call "iface"

[ -d /etc/ppp/ip-up.d ] && {
	for SCRIPT in /etc/ppp/ip-up.d/*
	do
		[ -x "$SCRIPT" ] && "$SCRIPT" $@
	done
}
if [ "$PPP_IPPARAM" == "wan" ]; then
	en_ipsec=$(uci -c /etc/config/grocx/ get vtss_fw.@basic[0].enable_vpn)
	if [ $en_ipsec = "1" ]; then
		logger "restart ipsect in ppp ip-up..."
		/etc/init.d/ipsec restart
	fi
fi
