#!/bin/sh
# variables passed to wan-event
# $1 > Wan Adaptor
# $2 > Wan state
# init
# connecting
# connected
# disconnected
# stopped
# disabled
# stopping
if ! [ -d "/jffs/wan" ]; then
mkdir /jffs/wan
fi
case $2 in
"disconnected")
echo "" > /jffs/wan/disconnected.txt
echo "Wan$1 Port reported disconnected on $(date)" >> /jffs/wan/disconnected.txt
echo "" >> /jffs/wan/disconnected.txt
;;
"connected")
sleep 5
T1="$(nvram get ntp_server0)"
T2="$(nvram get ntp_server1)"
C1="True"
C2=0
while [ "$C1" = "True" ]
do
if [ "$(nvram get ntp_ready)" = "1" ]; then
IP=$(nvram get wan${1}_ipaddr)
PUBLIC=$(wget -qO -
http://ipecho.net/plain | xargs echo)
if [ -e "/jffs/wan/disconnected.txt" ]; then
cat /jffs/wan/disconnected.txt > /jffs/wan/connected.txt
rm /jffs/wan/disconnected.txt
else
echo "" > /jffs/wan/connected.txt
echo "There is no record of the last time WAN port become disconnected" >> /jffs/wan/connected.txt
echo "" >> /jffs/wan/connected.txt
fi
echo "Wan$1 Port reported connected at $(date)" >> /jffs/wan/connected.txt
echo "" >> /jffs/wan/connected.txt
echo "The Wan$1 Address is: $IP" >> /jffs/wan/connected.txt
echo "The Public Address is: $PUBLIC" >> /jffs/wan/connected.txt
echo "" >> /jffs/wan/connected.txt
echo "Waited for $C2 loops for time to be synced" >> /jffs/wan/connected.txt
echo "" >> /jffs/wan/connected.txt
/jffs/addons/young/smail.sh /jffs/wan/connected.txt "AC86U Router Connected to the Internet"
C1="False"
else
sleep 3
let "C2=C2+1"
if [ "$C2" -gt 10 ]; then
C1="False"
logger "wan-event - wan event script did not start - ntp server failed to respond"
fi
fi
done
# Start SoftEtherVPN Server
# /jffs/addons/young/start_vpn_server
/jffs/addons/young/wakedc.sh
exit 0
;;
esac