Extended MOTD with GUI
[tomato.git] / release / src / router / others / stealthMode
blob9c6c2f02f4f88ba11c74b6205575e3a25cd2d208
1 #!/bin/sh
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
13 case "$1" in
14 on)
15 /usr/sbin/stealthMode perm_on
16 echo "StealthMode Activated"
17 logger StealthMode Activated
18 cru a stealthmode "*/5 * * * * /usr/sbin/stealthMode perm_on"
20 sun)
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
26 else
27 echo "StealthMode Sunset error - the city code does not specified!"
28 logger StealthMode Sunset error - the city code does not specified!
29 /usr/sbin/stealthMode
30 exit 1
33 sun_on)
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!
38 /usr/sbin/stealthMode
39 exit 1
40 else
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
51 else
52 /usr/sbin/stealthMode on
54 else
55 echo "StealthMode Sunset error - the city code does not specified!"
56 logger StealthMode Sunset error - the city code does not specified!
57 /usr/sbin/stealthMode
58 exit 1
62 perm_on)
63 if [ "$N66U" == "1" ]; then
64 wl -i eth2 leddc 1
65 gpio enable 12 #power led
66 gpio enable 15 #usb led
67 else
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
73 wl -i eth1 leddc 1
75 sun_off)
76 echo "StealthMode Sunset Disactivated"
77 logger StealthMode Sunset Disactivated
78 cru d stealthsun_on
79 cru d stealthsunset
80 cru d stealthsunrise
81 /usr/sbin/stealthMode off
83 off)
84 if [ "$N66U" == "1" ]; then
85 wl -i eth2 leddc 0
86 gpio disable 12 #power led
87 gpio disable 15 #usb led
88 else
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
94 wl -i eth1 leddc 0
95 echo "StealthMode Disactivated"
96 logger StealthMode Disactivated
97 cru d stealthmode
100 echo $"Usage: $0 {on|off|sun <city_code>|sun_off}"
101 echo
102 echo " Standard mode"
103 echo " on | off - enable or disable steathMode in real time"
104 echo
105 echo " Sunset mode"
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"
113 exit 1
114 esac
115 else
116 echo "Router does not supported by this feature"
117 logger Router does not supported by this feature