Milí majitelé routerů Turris,
toto fórum bylo 9. 12. 2016 zmrazeno a nahrazeno naším novým Turris fórem. Ještě chvíli bude dostupné k prohlížení, ale již zde není možné přispívat. Více informací naleznete v oznámení o uzavření fóra.
Dear Turris routers users,
this forum has been frozen on Dec 9th, 2016 and replaced by our new Turris forum. It will be read-only accessible for some time after. For more information, read the announcement about closing the forum.
#!/bin/bash
#
# WAN TEST & DEFAULT ROUTE SWITCH
#
#
###
###### d e k l a r a c e f u n k c i
### case-insensitive.
shopt -s nocasematch
log=/dev/null
### knihovna network funkci
source /lib/functions/network.sh
### Zmeni aktualni stav default GW
_route(){
route del default >> $log 2>&1
route add default gw $1 $2 >> $log 2>&1
msg=`echo "$msg- Prepinam na rozhrani $2 [$1]\n"`
}
### LED diskoteka
_rainbow(){
rainbow wan $1
rainbow intensity $2
### Kdyz je interface bez signalu at alespon sviti
if [ $(</sys/class/net/eth2/carrier) == 1 ]; then
rainbow wan auto
else
msg=`echo "$msg- Rozhrani WAN[eth2] nema link/connect !!!\n"`
rainbow wan enable
fi
}
### Test ping na rozhrani
# V pripade velke latence zvetsit parametr -W
_test_ping(){
if [ -z "$1" ] ; then
echo ERR
else
route del -host $TEST_IP >> $log 2>&1
route add -host $TEST_IP gw $1 $2 >> $log 2>&1
if ping -q -c 3 -W 1 $TEST_IP >> $log 2>&1 ; then
echo OK
else
echo BED
fi
route del -host $TEST_IP >> $log 2>&1
fi
}
###
###### K o n f i g u r a c e
#
### Definice sledovanych rozhrani z luci
WAN1=wan
WAN2=MODEM
# aktualizace
network_flush_cache
### Nazev rozhrani
network_get_device WAN1_if $WAN1
if [ -z "$WAN1_if" ]; then
msg=`echo "$msg- Rozhrani WAN1 - $WAN1 neeixstuje...\n"`
fi
network_get_device WAN2_if $WAN2
if [ -z $WAN2_if ]; then
msg=`echo "$msg- Rozhrani WAN2 - $WAN2 neeixstuje...\n"`
fi
### IP adresa rozhrani
network_get_ipaddr WAN1_ip $WAN1
network_get_ipaddr WAN2_ip $WAN2
### Gateway rozhrani
network_get_gateway WAN1_gw $WAN1 1
network_get_gateway WAN2_gw $WAN2 1
### Aktualni default route
#network_find_wan DGW
DGW=`ip route show | grep 'default' | awk '{print $5}'`
### Test IP adresa (DNS google)
TEST_IP=8.8.8.8
### Testy dostupnosti pro jednotlive rozhrani
stat_WAN1=$(_test_ping $WAN1_gw $WAN1_if)
stat_WAN2=$(_test_ping $WAN2_gw $WAN2_if)
###
###### V y k o n n a c a s t
#
### Nic nefunguje - LED do cervena
if [ "$stat_WAN1" != "OK" ] && [ "$stat_WAN2" != "OK" ] ; then
msg=`echo "$msg- Obe rozhrani nefunguji [WAN1 rozhrani $WAN1($WAN1_if) | WAN2 rozhrani $WAN2($WAN2_if)] !!!\n"`
_rainbow red 0
### Prepnuti do normalu na WAN1 - LED do modra
elif [ "$stat_WAN1" == "OK" ] && [ "$DGW" != "$WAN1_if" ] ; then
_route $WAN1_gw $WAN1_if
_rainbow blue 6
### Nefunguje jen WAN2 to nevadi.... - LED nejaka hneda?
elif [ "$stat_WAN2" != "OK" ] ; then
msg=`echo "$msg- Nefunguje WAN2 rozhrani $WAN2($WAN2_if) !!!\n"`
_rainbow '10FF10' 3
### Prepnuti na WAN2 - LED do zelena
elif [ "$stat_WAN1" != "OK" ] && [ "$DGW" == "$WAN1_if" ] ; then
_route $WAN2_gw $WAN2_if
_rainbow green 3
### Nefunguje jen WAN1 jedeme na zalohu - LED zelena
elif [ "$stat_WAN1" != "OK" ] ; then
msg=`echo "$msg- Nefunguje WAN1 rozhrani $WAN1($WAN1_if) !!!\n"`
_rainbow green 3
### Normalni stav WAN1 - LED do modra
else
msg=`echo "$msg- $WAN1($WAN1_if) spojeni je O.K.\n"`
_rainbow blue 6
fi
### shell vystup z prikazu
if [ "$1" != "-q" ] ; then
echo -e "WAN1 rozhrani $WAN1($WAN1_if) je $stat_WAN1"
echo -e "WAN2 rozhrani $WAN2($WAN2_if) je $stat_WAN2"
echo -e "Default routing je na rozhrani $DGW"
echo -e "Diag MSG:\n"
echo -e $msg
fi
Powered by mwForum 2.29.3 © 1999-2013 Markus Wichitill