-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagic.sh
More file actions
executable file
·90 lines (81 loc) · 2.1 KB
/
magic.sh
File metadata and controls
executable file
·90 lines (81 loc) · 2.1 KB
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
#!/bin/bash
#
# Author: Payne Zheng <zzuai520@live.com>
# Date: 2017-07-20 17:34:38
# Location: Shenzhen
# Desc: check access url evaluation score,
# if score exceed threshold, push the url and score to wechat and DRMS.
#
rePort() {
local groupName apiUrl msg
#groupName="PLCDN-SUPPORT"
groupName="SUSPICIOUS"
apiUrl="http://push.plcdn.net:7890/20160128"
msg=$1
#groupName=$2
wgetArg='--tries=1 --timeout=30'
wget -q --header="To: $groupName" \
--post-data="$msg" "$apiUrl" \
-O /dev/null
}
makeMsg() {
msg="# suspicious:"$'\n'
msg+="--------------------"$'\n'
msg+="URL: $Url"$'\n'
msg+="Score: $score"$'\n'
msg+="Node: $localIp"$'\n'
msg+="cTime: $cTime"$'\n'
msg+="Time: $(date '+%Y-%m-%d %H:%M:%S')"
}
makeToken() {
token=$(echo -n "$score$key" | md5sum | awk '{print $1}')
}
toDrms() {
curl -o /dev/null -s -d "url=$Url&score=$score&token=$token" $drmsApi
}
makeTodo() {
totalNum=$(wc -l $doingList | awk '{print $1}')
for ((i=1;i<=$preNum;i++))
do
randNum=$((RANDOM%$totalNum+1))
sed -n "$randNum p" $doingList >> $tempfile
done
sort $tempfile | uniq > $toDoList
}
cleanUp() {
rm -f $toDoList $doingList $tempfile
}
drmsApi="http://drms.powerleadercdn.com/index.php/portal/urlPurify/"
localIp=$(awk '/bind/{print $2}' /etc/nginx/node.conf | tr -d ';')
queueList="/dev/shm/d-queue.lst"
doingList="/dev/shm/d-doing.lst"
nsfwAppDir="/opt/open_nsfw/"
tempfile=$(mktemp)
toDoList=$(mktemp)
key="portal"
threshold="9000"
preNum="130"
while :
do
if test -f $queueList; then
mv $queueList $doingList
makeTodo
while read Url Size Hits Stat cTime
do
cd $nsfwAppDir
score=$(bash nsfw.sh "$Url" 2>&1 | tail -1)
grep -qE '[a-z]' <<<$score && continue
if test $score -gt $threshold; then
makeMsg
makeToken
rePort "$msg"
toDrms
fi
done < $toDoList
cleanUp
else
sleep 5
continue
fi
done
trap cleanUp exit