Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.62 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # SSID for AP (clients), most cases 'Freifunk'
  4. ffupssid='FreifunkGE'
  5. # SSID for 'No public internet available'
  6. ffdownssid='FF_noInternet'
  7.  
  8. # two major sites which most likely will not fail at the same time
  9. # and for which a simultaneous outage renders the AP for most end users
  10. # as 'no internet'
  11. pinghost1='ipv6.google.com'
  12. pingcount1=5 # number of packets which have to fail 100%
  13. delaytime=30 # seconds between attempts
  14. pinghost2='www.heise.de'
  15. pingcount=5
  16.  
  17. #get current ssid from uci
  18. ssid="$(/sbin/uci get wireless.client_radio0.ssid)"
  19.  
  20. # it would be nice to have a way to get the real state
  21. # iw dev wlan0-1 info would work, but it is parsing a file
  22. # otherwise we should run a '/sbin/wifi' somwhere to make sure the uci config is active
  23.  
  24. if ping6 -q -c $pingcount1 $pinghost1 >/dev/null
  25. then
  26.   if [ $ssid != $ffupssid ]
  27.   then
  28.     echo 'AP-SSID change to "'$ffupssid'"'
  29.     /sbin/uci set wireless.client_radio0.ssid=$ffupssid
  30.     /sbin/wifi
  31.   else
  32.    /bin/echo 'AP-SSID is already "'$ffupssid'"'
  33.   fi
  34. else
  35.   # it would be nice to have a way to get the real state
  36.   # iw dev wlan0-1 info would work, but it is parsing a file
  37.   if [ $ssid != $ffdownssid ]
  38.   then
  39.     echo 'ipv6-host "'$pinghost1'" non reachable'
  40.     sleep $delaytime
  41.     if ping6 -q -c $pingcount2 $pinghost2 > /dev/null
  42.     then
  43.       echo '"'$pinghost1'" not reachable, "'$pinghost2'" reachable. doing nothing'
  44.     else
  45.       echo 'AP-SSID changing to "'$ffdownssid'"'
  46.       /sbin/uci set wireless.client_radio0.ssid=$ffdownssid
  47.       /sbin/wifi
  48.     fi
  49.   else
  50.     /bin/echo 'AP-SSID is already "'$ffdownssid'"'
  51.   fi
  52. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement