mystic/dbp/banunban.sh

61 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
usage() { echo "Usage: $0 [-f dbp.ini] -d [ban|unban] -i IP" 1>&2; exit 1; }
2023-01-14 11:32:27 +01:00
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))
2023-01-14 11:32:27 +01:00
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
2023-01-18 20:41:49 +01:00
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
2023-01-14 11:32:27 +01:00
echo ${BAN_IP} >> /opt/ipban/ban.txt
fi
if [ $DO_BAN = "unban" ]; then
2023-01-14 11:32:27 +01:00
echo ${BAN_IP} >> /opt/ipban/unban.txt
if [ $BAN_UNBAN_MYSTIC = "true" ]; then
2023-01-18 20:41:49 +01:00
sed -e "/${BAN_IP}/d" -i ${MYSTIC_DIR}/data/denylist.txt
fi
fi
fi
fi
exit 0