105 lines
2.5 KiB
Bash
Executable File
105 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
. /etc/bewan/init.d/setparam
|
|
|
|
tunnel_mngt()
|
|
{
|
|
if [ "$WLANInterface_2_Enable" = 0 ]; then
|
|
if [ -f /var/tmp/gre_mngt_state ]; then
|
|
rm /var/tmp/gre_mngt_state
|
|
fi
|
|
return 0
|
|
fi
|
|
|
|
local ipdest; ipdest=$VPNInterface_1_GRE_IP4Destination
|
|
local ip1; ip1=$Services_GvtHotspot_Address_1_IP
|
|
local ip2; ip2=$Services_GvtHotspot_Address_2_IP
|
|
local count1;
|
|
local count2;
|
|
local res1;
|
|
local res2;
|
|
local st1;
|
|
local st2;
|
|
local status="/var/tmp/gre_mngt_state"
|
|
if [ -f $status ]; then
|
|
count1=`grep "count1" $status | cut -d"=" -f2`
|
|
count2=`grep "count2" $status | cut -d"=" -f2`
|
|
st1=`grep "st1" $status | cut -d"=" -f2`
|
|
st2=`grep "st2" $status | cut -d"=" -f2`
|
|
else
|
|
count1=0
|
|
count2=0
|
|
st1="reachable"
|
|
st2="reachable"
|
|
fi
|
|
|
|
ping -c 1 $ip1
|
|
res1=$?
|
|
ping -c 1 $ip2
|
|
res2=$?
|
|
|
|
if [ $res1 -eq 0 ] && [ $res2 -eq 0 ]; then
|
|
count1=0;
|
|
count2=0;
|
|
elif [ $res1 -eq 0 ] && [ $res2 -eq 1 ]; then
|
|
st1="reachable";
|
|
if [ $count2 -eq 2 ]; then
|
|
count2=0;
|
|
st2="unreachable";
|
|
else
|
|
count2=`expr $count2 + 1`
|
|
fi
|
|
elif [ $res1 -eq 1 ] && [ $res2 -eq 0 ]; then
|
|
st2="reachable";
|
|
count2=0;
|
|
if [ $count1 -eq 2 ]; then
|
|
count1=0;
|
|
st1="unreachable";
|
|
else
|
|
count1=`expr $count1 + 1`
|
|
fi
|
|
else
|
|
if [ $count1 -eq 2 ]; then
|
|
count1=0;
|
|
st1="unreachable";
|
|
else
|
|
count1=`expr $count1 + 1`
|
|
fi
|
|
if [ $count2 -eq 2 ]; then
|
|
count2=0;
|
|
st2="unreachable";
|
|
else
|
|
count2=`expr $count2 + 1`
|
|
fi
|
|
fi
|
|
|
|
if [ "$ip1" = "" ]; then
|
|
st1="unreachable";
|
|
fi
|
|
if [ "$ip2" = "" ]; then
|
|
st2="unreachable";
|
|
fi
|
|
echo "count1=$count1" > $status
|
|
echo "count2=$count2" >> $status
|
|
echo "st1=$st1" >> $status
|
|
echo "st2=$st2" >> $status
|
|
|
|
if [ $st1 = "reachable" ]; then
|
|
if [ "$ipdest" != "$ip1" ]; then
|
|
base_log "Backup hotspot server failed, return to Primary" debug
|
|
echo "cd _VPNInterface_1_GRE; set IP4Destination $ip1; fcommit" | cli -q
|
|
fi
|
|
wl -i $WLANInterface_2_Ifname ssid "$WLANInterface_2_Config_SSID"
|
|
elif [ $st2 = "reachable" ]; then
|
|
if [ "$ipdest" != "$ip2" ]; then
|
|
base_log "Primary hotspot server failed, go to Backup" debug
|
|
echo "cd _VPNInterface_1_GRE; set IP4Destination $ip2; fcommit" | cli -q
|
|
fi
|
|
wl -i $WLANInterface_2_Ifname ssid "$WLANInterface_2_Config_SSID"
|
|
else
|
|
wl -i $WLANInterface_2_Ifname ssid ""
|
|
fi
|
|
}
|
|
|
|
tunnel_mngt
|