2023-01-13 19:45:48 +01:00
|
|
|
#!/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
|
2023-01-13 19:45:48 +01:00
|
|
|
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
|
2023-01-13 19:45:48 +01:00
|
|
|
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
|
2023-01-13 19:45:48 +01:00
|
|
|
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
|
2023-01-13 19:45:48 +01:00
|
|
|
fi
|
|
|
|
if [ $DO_BAN = "unban" ]; then
|
2023-01-14 11:32:27 +01:00
|
|
|
echo ${BAN_IP} >> /opt/ipban/unban.txt
|
2023-01-13 19:45:48 +01:00
|
|
|
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
|
2023-01-13 19:45:48 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|