4G: better Signal Strength detection cd ..
[tomato.git] / release / src / router / others / stealthMode
blobb84b7dd1d2dbc6e4ae07d3bc1bb84d30b6336b6a
1 #!/bin/sh
3 # Turn off/on all led for Asus routers RT-N16 and RT-N66u
5 # Version: 0.8 "Sunset"
6 # Authors: Monter, Shibby
8 # Unlock lan ports, Permanent On function, Sunset mode,
9 # Scheduler mode and Clear All option written by Monter
11 # configuration
12 VERSION="v0.9"
13 # /configuration
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`
23 if /usr/bin/[ "$N16" == "1" -o "$N66U" == "1" ]; then
24 case "$1" in
25 on)
26 /usr/sbin/et robowr 0x00 0x18 0x1e0
27 /bin/sleep 1 # strobo effect
28 $dir/$stms perm_on
29 /usr/bin/logger -p6 -s -t stealthMode Activated
30 /usr/sbin/cru a stealthmode "*/5 * * * * $dir/$stms perm_on"
32 sun)
33 if /usr/bin/[ "$2" != "" -a "0$(/bin/echo $2 | /usr/bin/tr -d ' ')" -ge 0 ] 2>/dev/null; then
34 /usr/bin/logger -p6 -s -t stealthMode Sunset Enabled
35 /usr/sbin/cru a stealthsun_on "0 2 * * * $dir/$stms sun_on $2"
36 $dir/$stms sun_on $2
37 else
38 /usr/bin/logger -p3 -s -t stealthMode Sunset error - the city code does not specified!
39 $dir/$stms
40 exit 1
43 sun_on)
44 # check internet connection
45 CONERR=1
46 YAHOOAPIS="weather.yahooapis.com"
48 if /usr/bin/[ `/bin/echo $YAHOOAPIS | /usr/bin/wc -c` -gt 2 ]; then
49 /bin/ping -q -w 1 -c 1 $YAHOOAPIS > /dev/null
50 if /usr/bin/[ $? == 0 ]; then CONERR=0; fi
53 # result of internet connection check
54 if /usr/bin/[ "$CONERR" -ne 0 ] ; then
55 /usr/bin/logger -p3 -s -t stealthMode Sunset error - no active Internet connection!
56 $dir/$stms
57 exit 1
58 else
59 if /usr/bin/[ "$2" != "" -a "0$(/bin/echo $2 | /usr/bin/tr -d ' ')" -ge 0 ] 2>/dev/null; then
60 $dir/$stms sch_clear # clear scheduled tasks when sunset is enabled
61 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'`
62 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
63 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'`
64 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
65 /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 }' )
66 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
67 /usr/bin/logger -p6 -s -t stealthMode The time now is $( /bin/date +%H:%M), so StealthMode will be activated at next sun set
68 else
69 $dir/$stms on
71 else
72 /usr/bin/logger -p3 -s -t stealthMode Sunset error - the city code does not specified!
73 $dir/$stms
74 exit 1
78 perm_on)
79 if /usr/bin/[ "$N66U" == "1" ]; then
80 /usr/sbin/wl -i eth2 leddc 1
81 /sbin/gpio enable 12 #power led
82 /sbin/gpio enable 15 #usb led
83 else
84 /sbin/gpio enable 1 #power led
85 /usr/sbin/et robord 0x1 0x4 > /dev/null 2>&1 #unlock lan ports
87 /usr/sbin/et robowr 0x00 0x18 0x1e0
88 /usr/sbin/et robowr 0x00 0x1a 0x1e0
89 /usr/sbin/wl -i eth1 leddc 1
91 sun_off)
92 /usr/bin/logger -p6 -s -t stealthMode Sunset Disactivated
93 /usr/sbin/cru d stealthsun_on
94 /usr/sbin/cru d stealthsunset
95 /usr/sbin/cru d stealthsunrise
96 $dir/$stms off
98 sch_on)
99 if /usr/bin/[ "${2}" != "" -a "${2}" -le 23 -a "0$(/bin/echo $2 | /usr/bin/tr -d ' ')" -ge 0 ] 2>/dev/null; then
100 if /usr/bin/[ "${3}" != "" -a "${3}" -le 59 -a "${3}" -eq "${3}" ] 2>/dev/null; then SCHMIN=${3}; else SCHMIN="0"; fi
101 /usr/sbin/cru a stealthsheduleon $SCHMIN $2 "* * * $dir/$stms on"
102 /usr/bin/logger -p6 -s -t stealthMode Scheduled On set to $2:$(/usr/bin/printf "%02d" $SCHMIN)
103 else
104 /usr/bin/logger -p3 -s -t stealthMode Scheduled On error - Hour / Minutes does not specified!
105 $dir/$stms
106 exit 1
109 sch_off)
110 if /usr/bin/[ "${2}" != "" -a "${2}" -le 23 -a "0$(/bin/echo $2 | /usr/bin/tr -d ' ')" -ge 0 ] 2>/dev/null; then
111 if /usr/bin/[ "${3}" != "" -a "${3}" -le 59 -a "${3}" -eq "${3}" ] 2>/dev/null; then SCHMIN=${3}; else SCHMIN="0"; fi
112 /usr/sbin/cru a stealthsheduleoff $SCHMIN $2 "* * * $dir/$stms off"
113 /usr/bin/logger -p6 -s -t stealthMode Scheduled Off set to $2:$(/usr/bin/printf "%02d" $SCHMIN)
114 else
115 /usr/bin/logger -p3 -s -t stealthMode Scheduled Off error - Hour / Minutes does not specified!
116 $dir/$stms
117 exit 1
120 sch_clear)
121 /usr/sbin/cru d stealthsheduleon
122 /usr/sbin/cru d stealthsheduleoff
123 /usr/bin/logger -p6 -s -t stealthMode Scheduler Tasks Deleted
125 clear_all)
126 $dir/$stms sun_off
127 $dir/$stms sch_clear
128 /usr/bin/logger -p6 -s -t stealthMode Complete shutdown and delete all jobs from Crontab - done
130 off)
131 /usr/sbin/cru d stealthmode
132 if /usr/bin/[ "$N66U" == "1" ]; then
133 /usr/sbin/wl -i eth2 leddc 0
134 /sbin/gpio disable 12 #power led
135 /sbin/gpio disable 15 #usb led
136 else
137 /sbin/gpio disable 1 #power led
138 /usr/sbin/et robord 0x1 0x4 > /dev/null 2>&1 #unlock lan ports
140 /usr/sbin/et robowr 0x00 0x18 0x1ff
141 /usr/sbin/et robowr 0x00 0x1a 0x1ff
142 /bin/sleep 1 # delay before repeat off commands - strobo error fix
143 /usr/sbin/et robowr 0x00 0x18 0x1ff
144 /usr/sbin/et robowr 0x00 0x1a 0x1ff
145 /usr/sbin/wl -i eth1 leddc 0
146 /usr/bin/logger -p6 -s -t stealthMode Disactivated
149 /bin/echo "stealthMode Sunset ${VERSION} by Monter"
150 /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}"
151 /bin/echo
152 /bin/echo " [Standard mode]"
153 /bin/echo " on | off - enable or disable steathMode in real time"
154 /bin/echo
155 /bin/echo " [Sunset mode]"
156 /bin/echo " sun <city_code> - will daily get the sunrise and sunset times of a specific"
157 /bin/echo " location automatically and activate Sunset mode"
158 /bin/echo " To be able to determine your <city_code> you need to first"
159 /bin/echo " go to http://weather.yahoo.com/ and look up your location"
160 /bin/echo " The last NUMBERS in the URL will be your <city_code>"
161 /bin/echo " Example: \"$stms sun 514048\" if you live in Poznan/Poland ;)"
162 /bin/echo " This feature requires a working Internet connection"
163 /bin/echo " sun_off - fully deactivate Sunset mode"
164 /bin/echo
165 /bin/echo " [Scheduled mode]"
166 /bin/echo " sch_on <H> <M> - set the hour and minutes of the scheduled enable/disable"
167 /bin/echo " sch_off <H> <M> stealthMode in Standard mode and adding jobs to the Crontab"
168 /bin/echo " Hour and minute time must be a numbers without any additional"
169 /bin/echo " characters, where hour is a mandatory parameter, while not"
170 /bin/echo " specifying an minute will assign a default 00 value"
171 /bin/echo " These options add just the right job for Crontab, nothing more"
172 /bin/echo " sch_clear - removes tasks from Crontab for scheduled enable/disable"
173 /bin/echo " stealthMode function set by sch_on and sch_off switches"
174 /bin/echo
175 /bin/echo " [Repair / debug]"
176 /bin/echo " clear_all - removes all jobs from Crontab and completely disables all"
177 /bin/echo " available stealthMode modes"
178 /bin/echo
179 exit 1
180 esac
181 else
182 /usr/bin/logger -p3 -s -t stealthMode Router does not supported by this feature