You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.6 KiB

#!/bin/sh
suspicfile=~/suspic
tmpfile=/tmp/ips
clean_up() {
echo -n "Removing tmp file..."
rm -f $tmpfile
rm -f $suspicfile
if [ "$?" -eq "0" ]; then
echo " done"
else
echo " *** FAILED ***"
echo "Could not delete tmp file \`$tmpfile\`"
exit 1
fi
}
# awk '{ print $1 }' $suspicfile | sort -h | uniq > ips
# Remove false-positives (like requests to the /posts URL which should be valid)
# I used some bad words in some filenames like "admin-panel..."
sed '/posts\//d' $suspicfile | awk '{ print $1 }' | sort -h | uniq > $tmpfile
ips_1=`wc -l $tmpfile | awk '{ print $1 }'`
#ip=`ifconfig | grep inet | egrep -v "inet6|127" | grep 0xffffff00 | awk '{ print $2 }'`
ip=`curl -s ifconfig.me`
echo "My remote ip address is $ip"
sed -i bak "/$ip/d" $tmpfile
ips_2=`wc -l $tmpfile | awk '{ print $1 }'`
removed_ips=`expr "$ips_1" - "$ips_2"`
echo "Removed $removed_ips ip address(es)"
echo -n "Inspecting ip file..."
ret="$(alacritty -e $EDITOR $tmpfile)"
if [ "$?" -eq "0" ]; then
echo " done"
else
echo " *** FAILED ***"
echo "Could not open editor. Aborting..."
clean_up
exit 1
fi
echo -n "Sending to openbsd-server..."
ret="$(scp -q $tmpfile openbsd-server:)"
if [ "$?" -eq "0" ]; then
echo " done"
else
echo " *** FAILED ***"
echo "Could not send the new ips to the OpenBSD server. Aborting..."
clean_up
exit 1
fi
echo -n "Sending to linux-server..."
ret="$(scp -q $tmpfile linux-server:)"
if [ "$?" -eq "0" ]; then
echo " done"
else
echo " *** FAILED ***"
echo "Could not send the new ips to the Archlinux server. Aborting..."
clean_up
exit 1
fi
clean_up
echo "Ok all done."