3 # Turn off/on all led for Asus routers RT-N16 and RT-N66u and RT-AC66u
5 # Version: 0.10 "Sunset"
6 # Authors: Monter, Shibby
8 # Unlock lan ports, Permanent On function, Sunset mode,
9 # Scheduler mode and Clear All option written by Monter
15 # Please do not make any changes in the code below without authors permission
16 # Send your bug report to monter[at]techlog.pl
18 dir
=`/bin/echo $( cd "$(/usr/bin/dirname "$0")" ; /bin/pwd -P )`
19 stms
=`/usr/bin/basename ${0}`
20 N16
=`/bin/nvram get t_model_name | /bin/grep RT-N16 | /usr/bin/wc -l`
21 N66U
=`/bin/nvram get t_model_name | /bin/grep RT-N66U | /usr/bin/wc -l`
22 AC66U
=`/bin/nvram get t_model_name | /bin/grep RT-AC66U | /usr/bin/wc -l`
24 if /usr
/bin
/[ "$N16" == "1" -o "$N66U" == "1" -o "$AC66U" == "1" ]; then
27 /usr
/sbin
/et robowr
0x00 0x18 0x1e0
28 /bin
/sleep 1 # strobo effect
30 /usr
/bin
/logger
-p6 -s -t stealthMode Activated
31 /usr
/sbin
/cru a stealthmode
"*/5 * * * * $dir/$stms perm_on"
34 if /usr
/bin
/[ "$2" != "" -a "0$(/bin/echo $2 | /usr/bin/tr -d ' ')" -ge 0 ] 2>/dev
/null
; then
35 /usr
/bin
/logger
-p6 -s -t stealthMode Sunset Enabled
36 /usr
/sbin
/cru a stealthsun_on
"0 2 * * * $dir/$stms sun_on $2"
39 /usr
/bin
/logger
-p3 -s -t stealthMode Sunset error
- the city code does not specified
!
45 # check internet connection
47 YAHOOAPIS
="weather.yahooapis.com"
49 if /usr
/bin
/[ `/bin/echo $YAHOOAPIS | /usr/bin/wc -c` -gt 2 ]; then
50 /bin
/ping -q -w 1 -c 1 $YAHOOAPIS > /dev
/null
51 if /usr
/bin
/[ $?
== 0 ]; then CONERR
=0; fi
54 # result of internet connection check
55 if /usr
/bin
/[ "$CONERR" -ne 0 ] ; then
56 /usr
/bin
/logger
-p3 -s -t stealthMode Sunset error
- no active Internet connection
!
60 if /usr
/bin
/[ "$2" != "" -a "0$(/bin/echo $2 | /usr/bin/tr -d ' ')" -ge 0 ] 2>/dev
/null
; then
61 $dir/$stms sch_clear
# clear scheduled tasks when sunset is enabled
62 sun
=`l=$2;/usr/bin/wget -q -O - http://weather.yahooapis.com/forecastrss?w=$l | /bin/grep astronomy | /usr/bin/awk -F\" '{print $4}' | /usr/bin/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'`
63 if /usr
/bin
/[ "$sun" = "" ] ; then /usr
/bin
/logger
-p3 -s -t stealthMode Weather sunset
time error
!; exit 1; else /usr
/sbin
/cru a stealthsunset
$sun "* * * $dir/$stms on"; fi
64 sur
=`l=$2;/usr/bin/wget -q -O - http://weather.yahooapis.com/forecastrss?w=$l | /bin/grep astronomy | /usr/bin/awk -F\" '{print $2}' | /usr/bin/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'`
65 if /usr
/bin
/[ "$sur" = "" ] ; then /usr
/bin
/logger
-p3 -s -t stealthMode Weather sunrise
time error
!; exit 1; else /usr
/sbin
/cru a stealthsunrise
$sur "* * * $dir/$stms off"; fi
66 /usr
/bin
/logger
-p6 -s -t stealthMode Sunset city code
: $2, sunset
: $
( /bin
/echo $sun |
/usr
/bin
/awk '{$1=sprintf("%02d", $1); print $2":"$1 }' ), sunrise
: $
( /bin
/echo $sur |
/usr
/bin
/awk '{$1=sprintf("%02d", $1); print $2":"$1 }' )
67 HOUR
=$
(/bin
/date +%k
); SUNRUN
=$
( /bin
/echo $sun |
/usr
/bin
/awk '{ print $2 }' ); SURRUN
=$
( /bin
/echo $sur |
/usr
/bin
/awk '{ print $2 }' ); if /usr
/bin
/[ "$HOUR" -ge "$SURRUN" -a "$HOUR" -le "$SUNRUN" ] ; then
68 /usr
/bin
/logger
-p6 -s -t stealthMode The
time now is $
( /bin
/date +%H
:%M
), so StealthMode will be activated
at next sun
set
73 /usr
/bin
/logger
-p3 -s -t stealthMode Sunset error
- the city code does not specified
!
80 if /usr
/bin
/[ "$N66U" == "1" -o "$AC66U" == "1" ]; then
81 /usr
/sbin
/wl
-i eth2 leddc
1
82 /sbin
/gpio
enable 12 #power led
83 /sbin
/gpio
enable 15 #usb led
85 /sbin
/gpio
enable 1 #power led
86 /usr
/sbin
/et robord
0x1 0x4 > /dev
/null
2>&1 #unlock lan ports
88 /usr
/sbin
/et robowr
0x00 0x18 0x1e0
89 /usr
/sbin
/et robowr
0x00 0x1a 0x1e0
90 /usr
/sbin
/wl
-i eth1 leddc
1
93 /usr
/bin
/logger
-p6 -s -t stealthMode Sunset Disactivated
94 /usr
/sbin
/cru d stealthsun_on
95 /usr
/sbin
/cru d stealthsunset
96 /usr
/sbin
/cru d stealthsunrise
100 if /usr
/bin
/[ "${2}" != "" -a "${2}" -le 23 -a "0$(/bin/echo $2 | /usr/bin/tr -d ' ')" -ge 0 ] 2>/dev
/null
; then
101 if /usr
/bin
/[ "${3}" != "" -a "${3}" -le 59 -a "${3}" -eq "${3}" ] 2>/dev/null; then SCHMIN=${3}; else SCHMIN="0"; fi
102 /usr/sbin/cru a stealthsheduleon $SCHMIN $2 "* * * $dir/$stms on
"
103 /usr/bin/logger -p6 -s -t stealthMode Scheduled On set to $2:$(/usr/bin/printf "%02d
" $SCHMIN)
105 /usr/bin/logger -p3 -s -t stealthMode Scheduled On error - Hour / Minutes does not specified!
111 if /usr/bin/[ "${2}" != "" -a "${2}" -le 23 -a "0$
(/bin
/echo $2 |
/usr
/bin
/tr -d ' ')" -ge 0 ] 2>/dev/null; then
112 if /usr/bin/[ "${3}" != "" -a "${3}" -le 59 -a "${3}" -eq "${3}" ] 2>/dev/null; then SCHMIN=${3}; else SCHMIN
="0"; fi
113 /usr
/sbin
/cru a stealthsheduleoff
$SCHMIN $2 "* * * $dir/$stms off"
114 /usr
/bin
/logger
-p6 -s -t stealthMode Scheduled Off
set to
$2:$
(/usr
/bin
/printf "%02d" $SCHMIN)
116 /usr
/bin
/logger
-p3 -s -t stealthMode Scheduled Off error
- Hour
/ Minutes does not specified
!
122 /usr
/sbin
/cru d stealthsheduleon
123 /usr
/sbin
/cru d stealthsheduleoff
124 /usr
/bin
/logger
-p6 -s -t stealthMode Scheduler Tasks Deleted
129 /usr
/bin
/logger
-p6 -s -t stealthMode Complete shutdown and delete all
jobs from Crontab
- done
132 /usr
/sbin
/cru d stealthmode
133 if /usr
/bin
/[ "$N66U" == "1" -o "$AC66U" == "1" ]; then
134 /usr
/sbin
/wl
-i eth2 leddc
0
135 /sbin
/gpio disable
12 #power led
136 /sbin
/gpio disable
15 #usb led
138 /sbin
/gpio disable
1 #power led
139 /usr
/sbin
/et robord
0x1 0x4 > /dev
/null
2>&1 #unlock lan ports
141 /usr
/sbin
/et robowr
0x00 0x18 0x1ff
142 /usr
/sbin
/et robowr
0x00 0x1a 0x1ff
143 /bin
/sleep 1 # delay before repeat off commands - strobo error fix
144 /usr
/sbin
/et robowr
0x00 0x18 0x1ff
145 /usr
/sbin
/et robowr
0x00 0x1a 0x1ff
146 /usr
/sbin
/wl
-i eth1 leddc
0
147 /usr
/bin
/logger
-p6 -s -t stealthMode Disactivated
150 /bin
/echo "stealthMode Sunset ${VERSION} by Monter"
151 /usr
/bin
/logger
-p1 -s -t Usage
"$stms {on|off|sun <city_code>|sun_off|sch_on <H> <M>|sch_off <H> <M>|sch_clear|clear_all}"
153 /bin
/echo " [Standard mode]"
154 /bin
/echo " on | off - enable or disable steathMode in real time"
156 /bin
/echo " [Sunset mode]"
157 /bin
/echo " sun <city_code> - will daily get the sunrise and sunset times of a specific"
158 /bin
/echo " location automatically and activate Sunset mode"
159 /bin
/echo " To be able to determine your <city_code> you need to first"
160 /bin
/echo " go to http://weather.yahoo.com/ and look up your location"
161 /bin
/echo " The last NUMBERS in the URL will be your <city_code>"
162 /bin
/echo " Example: \"$stms sun 514048\" if you live in Poznan/Poland ;)"
163 /bin
/echo " This feature requires a working Internet connection"
164 /bin
/echo " sun_off - fully deactivate Sunset mode"
166 /bin
/echo " [Scheduled mode]"
167 /bin
/echo " sch_on <H> <M> - set the hour and minutes of the scheduled enable/disable"
168 /bin
/echo " sch_off <H> <M> stealthMode in Standard mode and adding jobs to the Crontab"
169 /bin
/echo " Hour and minute time must be a numbers without any additional"
170 /bin
/echo " characters, where hour is a mandatory parameter, while not"
171 /bin
/echo " specifying an minute will assign a default 00 value"
172 /bin
/echo " These options add just the right job for Crontab, nothing more"
173 /bin
/echo " sch_clear - removes tasks from Crontab for scheduled enable/disable"
174 /bin
/echo " stealthMode function set by sch_on and sch_off switches"
176 /bin
/echo " [Repair / debug]"
177 /bin
/echo " clear_all - removes all jobs from Crontab and completely disables all"
178 /bin
/echo " available stealthMode modes"
183 /usr
/bin
/logger
-p3 -s -t stealthMode Router does not supported by this feature