Fix proto sort
[tomato.git] / release / src / router / others / tomatoanon
blob23d13f2c14f1217033d30754d7e9cb6701d3b5af
1 #!/bin/sh
3 ###############################
4 # Copyright (C) 2012/2013 shibby
6 # This script send anonymous or incompleted information about model of router and installed tomato version.
7 # Those information will be used ONLY for stats.
8 # Any of private information will be NOT sended!
9 # Results you can explore on http://anon.groov.pl page.
10 # If you don`t agree to run this script you can disable it in GUI.
12 # Sended information:
13 # - MD5SUM of WAN+LAN MAC addresses - this will identify a router. Ex: 1c1dbd4202d794251ec1acf1211bb2c8
14 # - Model of router. Ex: Asus RT-N66U
15 # - Version of installed tomato. Ex: 110 K26 USB
16 # - Builtype. Ex: Mega-VPN-64K
17 # - Uptime of your router. Ex: 3 days
18 # - Number of version for tomato update notification system. Ex: 110
20 # That`s all
21 ###############################
23 ANON_ENABLED=`nvram get tomatoanon_enable`
24 ANON_ANSWER=`nvram get tomatoanon_answer`
25 ANON_NOTIFY=`nvram get tomatoanon_notify`
27 if [ "$ANON_ANSWER" == "1" ]; then
28 if [ "$ANON_ENABLED" == "1" ]; then
30 ############################
31 MOD=Shibby
32 ############################
34 #Detect Version and Buildtype
35 KERNEL=`uname -r | cut -d "." -f1,2`
36 if [ "$KERNEL" == "2.6" ]; then
37 IS_USB=`nvram get os_version | grep USB | wc -l`
38 if [ "$IS_USB" == "0" ]; then #if K26
39 VER=`nvram get os_version | awk '{ print $2" "$3 }' | cut -d "-" -f2`
40 BUILDTYPE=`nvram get os_version | awk '{ print $4 }'`
41 else #if K26USB
42 VER=`nvram get os_version | awk '{ print $2" "$3" "$4 }' | cut -d "-" -f2`
43 BUILDTYPE=`nvram get os_version | awk '{ print $5 }'`
45 else #K2.4
46 IS_USB=`nvram get os_version | grep USB | wc -l`
47 if [ "$IS_USB" == "0" ]; then #if K24
48 VER=`nvram get os_version | awk '{ print $2" "$3 }'`
49 BUILDTYPE=`nvram get os_version | awk '{ print $4 }'`
50 else # if K24USB
51 VER=`nvram get os_version | awk '{ print $2" "$3" "$4 }'`
52 BUILDTYPE=`nvram get os_version | awk '{ print $5 }'`
56 if [ "$1" == "checkver" -a "$ANON_NOTIFY" == "1" ]; then
57 # Tomato Update Notification Script
58 # This works only for Shibby`s builds !!!
59 CHECK_VER=`echo $VER | awk '{print $1}' | cut -d "." -f1 | sed 's/[^0-9]*//g`
61 #Change all spaces to %20
62 echo "http://anon.groov.pl/index.php?v=$CHECK_VER&mod=$MOD&anon=2" > /tmp/AnonLink
63 sed -i "s/ /%20/g" /tmp/AnonLink
64 ANONSEND=`cat /tmp/AnonLink`
65 rm /tmp/AnonLink
67 RESULT="/tmp/anon.version"
68 wget -O $RESULT $ANONSEND
70 #do we have result? If don`t, then set no update needed
71 if [ ! -f "$RESULT" ]; then
72 echo "have_update=no" > $RESULT
75 #Thanks. Now add cron job
77 ISCRU=`cru l | grep checkver | wc -l`
78 if [ "$ISCRU" == "0" ]; then
80 #random minutes 0..59
81 MINUTES=`awk 'BEGIN {srand(); printf "%d", 60*rand()}'`
83 #random hour 0..23
84 HOUR=`awk 'BEGIN {srand(); printf "%d", 23*rand()}'`
86 #checkver daily
87 cru a checkver "$MINUTES $HOUR * * * /usr/sbin/tomatoanon checkver"
90 else #just update anon database
91 #Collect datas
92 MOD=Shibby
93 UPTIME=`uptime | cut -d "," -f1 | cut -d " " -f4,5`
94 WANMAC=`nvram get wan_hwaddr`
95 LANMAC=`nvram get lan_hwaddr`
96 MODEL=`nvram get t_model_name`
97 DRIVER=`wl ver | grep version | awk '{ print $7 }'`
98 WANMAC_MD5=`echo "$WANMAC+$LANMAC" | md5sum | awk '{ print $1 }'`
100 ROUTERID=`nvram get tomatoanon_id`
101 if [ ! "$ROUTERID" == "$WANMAC_MD5" ]; then
102 nvram set tomatoanon_id="$WANMAC_MD5"
103 nvram commit
106 #Change all spaces to %20.
107 echo "http://anon.groov.pl/index.php?wanmac_md5=$WANMAC_MD5&model=$MODEL&version=$VER&buildtype=$BUILDTYPE&driver=$DRIVER&uptime=$UPTIME&mod=$MOD&anon=1" > /tmp/AnonLink
108 sed -i "s/ /%20/g" /tmp/AnonLink
109 ANONSEND=`cat /tmp/AnonLink`
110 rm /tmp/AnonLink
112 #We have all we need well we can send datas to Anon database
113 RESULT="/tmp/anon.result"
114 wget -O $RESULT $ANONSEND
116 #Thanks. Now add cron job
118 ISCRU=`cru l | grep anonupdate | wc -l`
119 if [ "$ISCRU" == "0" ]; then
121 #random minutes 0..59
122 MINUTES=`awk 'BEGIN {srand(); printf "%d", 60*rand()}'`
124 #random hour 0..23
125 HOUR=`awk 'BEGIN {srand(); printf "%d", 23*rand()}'`
127 #random day of week 0..6
128 DAY=`awk 'BEGIN {srand(); printf "%d", 6*rand()}'`
130 #update anon one time per week
131 cru a anonupdate "$MINUTES $HOUR * * $DAY /usr/sbin/tomatoanon"
135 else #if anon is not enabled or was disabled right now
137 ISCRU=`cru l | grep anonupdate | wc -l`
138 if [ "$ISCRU" == "0" ]; then
139 cru d anonupdate
142 ISCRU=`cru l | grep checkver | wc -l`
143 if [ "$ISCRU" == "0" ]; then
144 cru d checkver
147 fi #end ANON_ENABLE
149 else #if answer is not enabled or was disabled right now
151 ISCRU=`cru l | grep anonupdate | wc -l`
152 if [ "$ISCRU" == "0" ]; then
153 cru d anonupdate
156 ISCRU=`cru l | grep checkver | wc -l`
157 if [ "$ISCRU" == "0" ]; then
158 cru d checkver
161 fi #end ANON_ANSWER