Last active 1731171438

send-suspicips.sh Raw
1#!/bin/sh
2#
3# Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com>
4
5suspicfile=~/suspic
6tmpfile=/tmp/ips
7
8clean_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
22echo -n "Inspecting first..."
23ret="$(alacritty -e $EDITOR $suspicfile)"
24
25if [ "$?" -eq "0" ]; then
26 echo " done"
27else
28 echo " *** FAILED ***"
29 ecoh "Could not open editor. Aborting..."
30 clean_up
31 exit 1
32fi
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..."
38sed '/posts\//d' $suspicfile | awk '{ print $1 }' | sort -h | uniq > $tmpfile
39
40ips_1=`wc -l $tmpfile | awk '{ print $1 }'`
41
42#ip=`ifconfig | grep inet | egrep -v "inet6|127" | grep 0xffffff00 | awk '{ print $2 }'`
43ip=`curl -s ifconfig.me`
44echo "My remote ip address is $ip"
45
46sed -i "/$ip/d" $tmpfile
47ips_2=`wc -l $tmpfile | awk '{ print $1 }'`
48
49removed_ips=`expr "$ips_1" - "$ips_2"`
50
51echo "Removed $removed_ips ip address(es)"
52
53echo -n "Inspecting ip file..."
54ret="$(alacritty -e $EDITOR $tmpfile)"
55
56if [ "$?" -eq "0" ]; then
57 echo " done"
58else
59 echo " *** FAILED ***"
60 echo "Could not open editor. Aborting..."
61 clean_up
62 exit 1
63fi
64
65echo -n "Sending to bor..."
66ret="$(scp -q $tmpfile bor:)"
67
68if [ "$?" -eq "0" ]; then
69 echo " done"
70else
71 echo " *** FAILED ***"
72 echo "Could not send the new ips to the OpenBSD server. Aborting..."
73 clean_up
74 exit 1
75fi
76
77echo -n "Sending to celeste..."
78ret="$(scp -q $tmpfile celeste:)"
79
80if [ "$?" -eq "0" ]; then
81 echo " done"
82else
83 echo " *** FAILED ***"
84 echo "Could not send the new ips to the Archlinux server. Aborting..."
85 clean_up
86 exit 1
87fi
88
89clean_up
90
91echo "Ok all done."
92