MyFail2BanInfo/bin/bancountmysql

45 lines
976 B
Bash
Executable File

#!/bin/bash
action=$1
ip=$2
service=$3
curDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
source $curDir/bancount.cfg
allInfoIp=`geoiplookup $ip`;
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>
Performs geoip lookup and stamps time
and date into MySQL database.
EOF
;;
esac