mystic/dbp/banunban.sh
2023-01-18 20:41:49 +01:00

61 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
usage() { echo "Usage: $0 [-f dbp.ini] -d [ban|unban] -i IP" 1>&2; exit 1; }
while getopts ":f:d:i:" o; do
case "${o}" in
f)
INIFILE=${OPTARG}
;;
d)
DO_BAN=${OPTARG}
;;
i)
BAN_IP=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${INIFILE}" ] || [ -z "${DO_BAN}" ] || [ -z "${BAN_IP}" ]; then
usage
fi
MYSTIC_DIR="@MYSTIC_DIR@"
TMP_DIR=$(mktemp -d)
BAN_UNBAN_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k BanUnbanIP --silent`
BAN_UNBAN_SERVICE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S BanUnbanIP -k BanningService --silent`
BAN_UNBAN_MYSTIC=`${MYSTIC_DIR}/inimod r ${INIFILE} -S BanUnbanIP -k UnbanInMystic --silent`
if [ $BAN_UNBAN_ENABLE = "true" ]; then
if [ $BAN_UNBAN_SERVICE = "fail2ban" ]; then
if [ $DO_BAN = "ban" ]; then
/usr/bin/fail2ban-client set mysticbbs banip ${BAN_IP}
fi
if [ $DO_BAN = "unban" ]; then
/usr/bin/fail2ban-client set mysticbbs unbanip ${BAN_IP}
if [ $BAN_UNBAN_MYSTIC = "true" ]; then
sed -e "/${BAN_IP}/d" -i ${MYSTIC_DIR}/data/denylist.txt
fi
fi
fi
if [ $BAN_UNBAN_SERVICE = "ipban" ]; then
if [ $DO_BAN = "ban" ]; then
echo ${BAN_IP} >> /opt/ipban/ban.txt
fi
if [ $DO_BAN = "unban" ]; then
echo ${BAN_IP} >> /opt/ipban/unban.txt
if [ $BAN_UNBAN_MYSTIC = "true" ]; then
sed -e "/${BAN_IP}/d" -i ${MYSTIC_DIR}/data/denylist.txt
fi
fi
fi
fi
exit 0