3 # Turn off/on all led for routers RT-N16 and RT-N66U
5 # Version: 0.5 "Sunset"
7 # unlock lan ports and sunset mode by monter[at]techlog.pl
9 N16
=`nvram get t_model_name | grep RT-N16 | wc -l`
10 N66U
=`nvram get t_model_name | grep RT-N66U | wc -l`
12 if [ "$N16" == "1" -o "$N66U" == "1" ]; then
15 /usr
/sbin
/stealthMode perm_on
16 echo "StealthMode Activated"
17 logger StealthMode Activated
18 cru a stealthmode
"*/5 * * * * /usr/sbin/stealthMode perm_on"
21 if [ "$2" != "" -a "0$(echo $2|tr -d ' ')" -ge 0 ] ; then
22 echo "StealthMode Sunset Enabled"
23 logger StealthMode Sunset Enabled
24 cru a stealthsun_on
"0 2 * * * /usr/sbin/stealthMode sun_on $2"
25 /usr
/sbin
/stealthMode sun_on
$2
27 echo "StealthMode Sunset error - the city code does not specified!"
28 logger StealthMode Sunset error
- the city code does not specified
!
34 ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev
/null
35 if [ $?
-ne 0 ] ; then
36 echo "StealthMode Sunset error - no active Internet connection!"
37 logger StealthMode Sunset error
- no active Internet connection
!
41 if [ "$2" != "" -a "0$(echo $2|tr -d ' ')" -ge 0 ] ; then
42 sun
=`l=$2;wget -q -O - http://weather.yahooapis.com/forecastrss?w=$l|grep astronomy| awk -F\" '{print $4}' | awk -F\" '{split($1, A, " ");split(A[1], B, ":");HR=B[1];MIN=B[2];if(A[2] == "pm") HR+=12;$1=sprintf("%d %d", MIN, HR);}1'`
43 if [ "$sun" = "" ] ; then echo "Weather sunset error!"; logger Weather sunset error
!; exit 1; else cru a stealthsunset
$sun "* * * /usr/sbin/stealthMode on"; fi
44 sur
=`l=$2;wget -q -O - http://weather.yahooapis.com/forecastrss?w=$l|grep astronomy| awk -F\" '{print $2}' | awk -F\" '{split($1, A, " ");split(A[1], B, ":");HR=B[1];MIN=B[2];if(A[2] == "pm") HR+=12;$1=sprintf("%d %d", MIN, HR);}1'`
45 if [ "$sur" = "" ] ; then echo "Weather sunrise error!"; logger Weather sunrise error
!; exit 1; else cru a stealthsunrise
$sur "* * * /usr/sbin/stealthMode off"; fi
46 echo "StealthMode Sunset city code: $2, sunset: $( echo $sun | awk '{ print $2":"$1 }' ), sunrise: $( echo $sur | awk '{ print $2":"$1 }' )"
47 logger StealthMode Sunset city code
: $2, sunset
: $
( echo $sun |
awk '{ print $2":"$1 }' ), sunrise
: $
( echo $sur |
awk '{ print $2":"$1 }' )
48 HOUR
=$
(date +%k
); SUNRUN
=$
( echo $sun |
awk '{ print $2 }' ); SURRUN
=$
( echo $sur |
awk '{ print $2 }' ); if [ "$HOUR" -ge "$SURRUN" -a "$HOUR" -le "$SUNRUN" ] ; then
49 echo "StealthMode will be activated at next sun set"
50 logger StealthMode will be activated
at next sun
set
52 /usr
/sbin
/stealthMode on
55 echo "StealthMode Sunset error - the city code does not specified!"
56 logger StealthMode Sunset error
- the city code does not specified
!
63 if [ "$N66U" == "1" ]; then
65 gpio
enable 12 #power led
66 gpio
enable 15 #usb led
68 gpio
enable 1 #power led
69 et robord
0x1 0x4 > /dev
/null
2>&1 #unlock lan ports
71 et robowr
0x00 0x18 0x1e0
72 et robowr
0x00 0x1a 0x1e0
76 echo "StealthMode Sunset Disactivated"
77 logger StealthMode Sunset Disactivated
81 /usr
/sbin
/stealthMode off
84 if [ "$N66U" == "1" ]; then
86 gpio disable
12 #power led
87 gpio disable
15 #usb led
89 gpio disable
1 #power led
90 et robord
0x1 0x4 > /dev
/null
2>&1 #unlock lan ports
92 et robowr
0x00 0x18 0x1ff
93 et robowr
0x00 0x1a 0x1ff
95 echo "StealthMode Disactivated"
96 logger StealthMode Disactivated
100 echo $
"Usage: $0 {on|off|sun <city_code>|sun_off}"
102 echo " Standard mode"
103 echo " on | off - enable or disable steathMode in real time"
106 echo " sun <city_code> - will daily get the sunrise and sunset times of a specific"
107 echo " location automatically and activate Sunset mode"
108 echo " To be able to determine your <city_code> you need to first"
109 echo " go to http://weather.yahoo.com/ and look up your location"
110 echo " The last NUMBERS in the URL will be your <city_code>"
111 echo " This feature requires a working Internet connection"
112 echo " sun_off - fully deactivate Sunset mode"
116 echo "Router does not supported by this feature"
117 logger Router does not supported by this feature