dominic revised this gist . Go to revision
1 file changed, 91 insertions
send-suspicips.sh(file created)
@@ -0,0 +1,91 @@ | |||
1 | + | #!/bin/sh | |
2 | + | # | |
3 | + | # Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com> | |
4 | + | ||
5 | + | suspicfile=~/suspic | |
6 | + | tmpfile=/tmp/ips | |
7 | + | ||
8 | + | clean_up() { | |
9 | + | echo -n "Removing tmp file..." | |
10 | + | rm -f $tmpfile | |
11 | + | rm -f $suspicfile | |
12 | + | if [ "$?" -eq "0" ]; then | |
13 | + | echo " done" | |
14 | + | else | |
15 | + | echo " *** FAILED ***" | |
16 | + | echo "Could not delete tmp file \`$tmpfile\`" | |
17 | + | exit 1 | |
18 | + | fi | |
19 | + | } | |
20 | + | ||
21 | + | # inspect url files first by hand | |
22 | + | echo -n "Inspecting first..." | |
23 | + | ret="$(alacritty -e $EDITOR $suspicfile)" | |
24 | + | ||
25 | + | if [ "$?" -eq "0" ]; then | |
26 | + | echo " done" | |
27 | + | else | |
28 | + | echo " *** FAILED ***" | |
29 | + | ecoh "Could not open editor. Aborting..." | |
30 | + | clean_up | |
31 | + | exit 1 | |
32 | + | fi | |
33 | + | ||
34 | + | # awk '{ print $1 }' $suspicfile | sort -h | uniq > ips | |
35 | + | ||
36 | + | # Remove false-positives (like requests to the /posts URL which should be valid) | |
37 | + | # I used some bad words in some filenames like "admin-panel..." | |
38 | + | sed '/posts\//d' $suspicfile | awk '{ print $1 }' | sort -h | uniq > $tmpfile | |
39 | + | ||
40 | + | ips_1=`wc -l $tmpfile | awk '{ print $1 }'` | |
41 | + | ||
42 | + | #ip=`ifconfig | grep inet | egrep -v "inet6|127" | grep 0xffffff00 | awk '{ print $2 }'` | |
43 | + | ip=`curl -s ifconfig.me` | |
44 | + | echo "My remote ip address is $ip" | |
45 | + | ||
46 | + | sed -i "/$ip/d" $tmpfile | |
47 | + | ips_2=`wc -l $tmpfile | awk '{ print $1 }'` | |
48 | + | ||
49 | + | removed_ips=`expr "$ips_1" - "$ips_2"` | |
50 | + | ||
51 | + | echo "Removed $removed_ips ip address(es)" | |
52 | + | ||
53 | + | echo -n "Inspecting ip file..." | |
54 | + | ret="$(alacritty -e $EDITOR $tmpfile)" | |
55 | + | ||
56 | + | if [ "$?" -eq "0" ]; then | |
57 | + | echo " done" | |
58 | + | else | |
59 | + | echo " *** FAILED ***" | |
60 | + | echo "Could not open editor. Aborting..." | |
61 | + | clean_up | |
62 | + | exit 1 | |
63 | + | fi | |
64 | + | ||
65 | + | echo -n "Sending to bor..." | |
66 | + | ret="$(scp -q $tmpfile bor:)" | |
67 | + | ||
68 | + | if [ "$?" -eq "0" ]; then | |
69 | + | echo " done" | |
70 | + | else | |
71 | + | echo " *** FAILED ***" | |
72 | + | echo "Could not send the new ips to the OpenBSD server. Aborting..." | |
73 | + | clean_up | |
74 | + | exit 1 | |
75 | + | fi | |
76 | + | ||
77 | + | echo -n "Sending to celeste..." | |
78 | + | ret="$(scp -q $tmpfile celeste:)" | |
79 | + | ||
80 | + | if [ "$?" -eq "0" ]; then | |
81 | + | echo " done" | |
82 | + | else | |
83 | + | echo " *** FAILED ***" | |
84 | + | echo "Could not send the new ips to the Archlinux server. Aborting..." | |
85 | + | clean_up | |
86 | + | exit 1 | |
87 | + | fi | |
88 | + | ||
89 | + | clean_up | |
90 | + | ||
91 | + | echo "Ok all done." |
Newer
Older