-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdoctor.sh
executable file
·95 lines (77 loc) · 1.57 KB
/
doctor.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
#!/bin/sh
source /usr/share/libubox/jshn.sh
ip=8.8.8.8
host=www.google.com
api_url=https://api.ctapp.io
url=$api_url/api/v1/ping.json
splashprocess=chilli
mtucheck=0
splashcheck=0
urlstatus=0
icmpip=0
icmphost=0
icmp_check () {
ping -c 2 $1 >/dev/null 2>&1
if [ $? -eq 0 ] ; then
icmpcheck=1
else
icmpcheck=0
fi
}
icmp_check $ip
if [ $icmpcheck -eq 1 ] ; then
icmpip=1
fi
icmp_check $host
if [ $icmpcheck -eq 1 ] ; then
icmphost=1
fi
url_status_check () {
res=$(curl --connect-timeout 5 -k -s -o /dev/null -w '%{http_code}' $1)
if [ $res -eq 200 ] ; then
urlstatus=1
fi
}
splash_check () {
pidof $splashprocess >/dev/null 2>&1
if [ $? -eq 0 ] ; then
splashcheck=1
fi
}
sync_id () {
syncstatus=`cat /etc/sync`
}
mtu_check () {
mtu=`cat /etc/config/network | grep mtu | awk -F"'" '{ print $2 }'`
ping -c 2 -s $mtu bbc.com >/dev/null 2>&1
if [ $? -eq 0 ] ; then
mtucheck=1
fi
}
serial_check () {
serial=`cat /etc/serial`
}
mac_check () {
mac=`cat /etc/mac`
}
url_status_check $url
splash_check $splashcheck
sync_id
mac_check
mtu_check
serial_check
json_init
json_add_object "data"
json_add_boolean "icmp_host" $icmphost
json_add_boolean "icmp_ip" $icmpip
json_add_boolean "ct" $urlstatus
json_add_boolean "splash" $splashcheck
json_add_boolean "mtu_check" $mtucheck
json_add_string "sync_id" "$syncstatus"
json_close_object
health_check=`json_dump`
echo $health_check
post_ct () {
curl --connect-timeout 5 -d "$health_check" -s -H "Content-Type: application/json" -X POST $api_url/api/v1/nas/reporter\?mac\=$mac\&serial\=$serial\&type\=doctor -k
}
post_ct