50 lines
1.0 KiB
Bash
Executable File
50 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
action=$1
|
|
ip=$2
|
|
service=$3
|
|
|
|
curDir=$(dirname $0)
|
|
|
|
cd $curDir
|
|
|
|
source bancount.cfg
|
|
|
|
if [ -f "GeoIP.dat" ]
|
|
then
|
|
allInfoIp=`geoiplookup $ip`;
|
|
else
|
|
allInfoIp=`geoiplookup -f GeoIP.dat $ip`;
|
|
fi
|
|
|
|
geoip () {
|
|
echo $allInfoIp | awk -F, '{print $2}' | sed s/\ //
|
|
}
|
|
|
|
countryCode () {
|
|
echo $allInfoIp $ip | awk -F ": " '{ print $2 }' | awk -F "," '{ print $1 }' | head -n 1
|
|
}
|
|
|
|
case $action in
|
|
|
|
ban)
|
|
mysql $mysqldb -u $mysqluser --password=$mysqlpw -e "INSERT INTO bans (ip, service, ban_date, ban_time, country, countryCode) VALUES ( '$ip', '$service', '`date +%F`', '`date +%T`', '`geoip`', '`countryCode`');"
|
|
;;
|
|
|
|
unban)
|
|
mysql $mysqldb -u $mysqluser --password=$mysqlpw -e "INSERT INTO unbans (ip, service, unban_date, unban_time, country, countryCode) VALUES ( '$ip', '$service', '`date +%F`', '`date +%T`', '`geoip`', '`countryCode`');"
|
|
;;
|
|
|
|
*)
|
|
cat << EOF
|
|
Fail2BanCount - by k6b - MySQL logger
|
|
|
|
$(basename $0) <ban/unban> <ip> <service>
|
|
|
|
Performs geoip lookup and stamps time
|
|
and date into MySQL database.
|
|
EOF
|
|
|
|
;;
|
|
|
|
esac |