-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk.ionewu.cli.sh
executable file
·312 lines (275 loc) · 8.69 KB
/
k.ionewu.cli.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/sh
. /usr/share/libubox/jshn.sh
NETLISTDFT="pppoe-vwan1 pppoe-vwan2 pppoe-vwan3 macvlan1 macvlan2 macvlan3 eth0 eth1 eth2 eth3 eth4 eth5"
IPV4URL="114.114.114.114"
UUID="$1"
OPENID="$2"
NETMAC=""
if [ -z "$UUID" ]; then
echo no uid
exit 1
fi
if [ -z "$OPENID" ]; then
echo no openid
exit 1
fi
GETOPKG=`opkg list | grep jshn`
if [ -z "$GETOPKG" ]; then
echo pls install jshn
exit 1
fi
GETCURL=`which curl`
if [ -z "$GETCURL" ]; then
echo pls install curl
exit 1
fi
unset GETOPKG
unset GETCURL
if [ ! -z "$3" ]; then
if [ "$3" = "connected" ]; then
NETMAC=$4
else
echo not connected
exit 0
fi
fi
echo set uid $UUID
echo set openid $OPENID
CURLRE=""
SETNET=""
do_curl(){
if [ -f "re.json" ]; then
rm re.json
fi
curl -s $SETNET -H "Content-Type: application/json; charset=utf-8" \
-d @post.json "$1" -o re.json
}
chk_re(){
local GET=`cat re.json | grep ok`
if [ -z "$GET" ]; then
echo get error
echo post
cat post.json
echo ret
cat re.json
rm lock
logger -p ERROR "k.ionewu failed $NETMAC"
exit 1
fi
}
URL1="https://tan.ionewu.com/api/kuandai/log/user"
URL2="https://kdts.ionewu.com/c/query"
URL3="https://c.ionewu.com/wcjs/lan/find"
URL4="https://kdts.ionewu.com/c/status"
URL5="https://kdts.ionewu.com/c/open"
chknet(){
if [ -z "$NETMAC" ]; then
NETLIST=`ifconfig | grep mtu | grep flag | awk -F':\ flag' '{print $1}'`
IFACE=`ip -4 addr | awk '{if ($1 ~ /inet/ && $NF ~ /^[ve]/) {a=$NF}} END{print a}'`
if [ -z "${NETLIST}" ]; then
NETLIST="$NETLISTDFT"
fi
for netdev in ${NETLIST}
do
NETSTAT=`ifconfig $netdev`
if [ ! -z "$NETSTAT" ]; then
echo "find $netdev"
NETSTAT=`ifconfig $netdev | grep inet | grep 127.0.0`
if [ -z "$NETSTAT" ]; then
PINGDAT=`ping -c 2 -I $netdev $IPV4URL | grep ttl`
if [ "$netdev" = "$IFACE" ]; then
NETMAC=$netdev
fi
if [ ! -z "$PINGDAT" ]; then
NETMAC=$netdev
break
fi
fi
fi
done
fi
echo "find netdev $NETMAC"
if [ ! -z "$NETMAC" ]; then
SETNET=" --interface $NETMAC"
fi
}
chknet
echo $NETMAC
cd /tmp
mkdir dapengjiasu_$NETMAC
cd dapengjiasu_$NETMAC
if [ -f "lock" ]; then
echo in prg
exit 0
fi
touch lock
logger -p INFO "k.ionewu start ${NETMAC}"
curl $SETNET "https://c.ionewu.com/user/devs?uid=${UUID}&openid=${OPENID}"
#1
json_init
json_add_string "uid" "$UUID"
json_add_string "openid" "$OPENID"
json_add_string "pid" ""
json_add_string "appid" ""
json_add_string "chanid" ""
json_add_string "refuid" ""
json_add_string "type" "open"
json_add_string "msg" "http://k.ionewu.com/web/app/"
json_dump > post.json
sed -i "s_\\\/_\/_g" post.json
#cat post.json
do_curl $URL1
chk_re
echo -n 1:
#cat re.json
mv re.json re1.json
do_curl $URL1
chk_re
echo -n 1:
#cat re.json
mv re.json re1_1.json
#2
json_init
json_add_string "uid" "$UUID"
json_add_string "openid" "$OPENID"
json_add_int "type" 2
json_dump > post.json
do_curl $URL2
chk_re
echo -n 2:
#cat re.json
mv re.json re2.json
#3
json_init
json_add_string "uid" "$UUID"
json_add_string "openid" "$OPENID"
json_dump > post.json
do_curl $URL3
echo -n 3:
#cat re.json
mv re.json re3.json
#4
json_init
json_add_string "uid" "$UUID"
json_add_string "openid" "$OPENID"
json_add_int "type" 2
json_dump > post.json
do_curl $URL4
chk_re
echo -n 4:
#cat re.json
mv re.json re4.json
#5
json_init
json_init(){
echo -n call
}
json_add_string "uid" "$UUID"
json_add_string "openid" "$OPENID"
json_add_string "pid" ""
json_add_string "appid" ""
json_add_string "chanid" ""
json_add_string "refuid" ""
json_add_string "type" "status_down"
GETRE=`cat re4.json`
json_add_string "msg" "${GETRE}"
#eval "`jshn -R re4.json`"
#json_select ..
json_dump > post.json
unset json_init
#cat post.json
do_curl $URL1
chk_re
echo -n 5:
#cat re.json
mv re.json re5.json
#6
json_add_string "type" "check_down_success"
json_dump > post.json
do_curl $URL1
chk_re
echo -n 6:
#cat re.json
mv re.json re6.json
#7
json_init
json_add_string "uid" "$UUID"
json_add_string "openid" "$OPENID"
json_add_string "pid" ""
json_add_int "type" 2
json_dump > post.json
do_curl $URL2
chk_re
echo -n 7:
#cat re.json
mv re.json re7.json
#8
json_init
json_init(){
echo -n call
}
json_add_string "uid" "$UUID"
json_add_string "openid" "$OPENID"
json_add_string "pid" ""
json_add_string "appid" ""
json_add_string "chanid" ""
json_add_string "refuid" ""
json_add_string "type" "check_down"
GETRE=`cat re7.json`
json_add_string "msg" "${GETRE}"
json_dump > post.json
unset json_init
#cat post.json
do_curl $URL1
chk_re
echo -n 8:
#cat re.json
mv re.json re8.json
#9
json_add_string "type" "check_down_success"
json_dump > post.json
do_curl $URL1
chk_re
echo -n 9:
#cat re.json
mv re.json re9.json
#10
json_init
json_add_string "uid" "$UUID"
json_add_string "openid" "$OPENID"
json_add_int "type" 2
json_add_string "addr" ""
json_add_string "pid" ""
json_dump > post.json
do_curl $URL5
chk_re
echo -n 10:
#cat re.json
mv re.json re10.json
#11
json_init
json_init(){
echo -n call
}
json_add_string "uid" "$UUID"
json_add_string "openid" "$OPENID"
json_add_string "pid" ""
json_add_string "appid" ""
json_add_string "chanid" ""
json_add_string "refuid" ""
json_add_string "type" "open_down"
GETRE=`cat re10.json`
json_add_string "msg" "${GETRE}"
json_dump > post.json
unset json_init
#cat post.json
do_curl $URL1
chk_re
echo -n 11:
#cat re.json
mv re.json re11.json
echo done
cd ..
rm -r dapengjiasu_$NETMAC
logger -p INFO "k.ionewu done $NETMAC"
exit 0