banhammer

This commit is contained in:
SkyperTHC 2024-01-22 10:37:02 +00:00
parent 44f0018fff
commit abe588221e
No known key found for this signature in database
GPG Key ID: A9BD386DF9113CD6

View File

@ -11,29 +11,39 @@ do_ban() {
lgban "$2" "$3"
}
run_ban() {
do_stop() {
echo "[$(date '+%F %H:%M:%S' -u)] Stopping $2 [$1]. See /sf/config/db/user/${2}/syscop-ps.txt"
[[ -n $SF_DEBUG ]] && {
lgwall "$2" "$3"
return
}
lgstop "$2" "$3"
}
run() {
local interval
local rx_fn="/sf/config/db/private/${1}"
local msg_fn="/sf/config/db/private/${2}"
local regex
local reason="${rx_fn%.txt}"
local cmd="${3:-ban}"
reason="${reason##*rx_}"
while :; do
source "$rx_fn" || { sleep 60; continue; }
for lg in $(lgx "$regex" skiptoken); do
if [[ -f "$msg_fn" ]]; then
do_ban "$reason" "$lg" "$(<"$msg_fn"))"
"do_${cmd}" "$reason" "$lg" "$(<"$msg_fn"))"
else
do_ban "$reason" "$lg" "You got banned. Contact a SysCop to discuss [ERROR: $msg_fn]."
"do_${cmd}" "$reason" "$lg" "Your server was stopped. Contact a SysCop to discuss [ERROR: $msg_fn]."
fi
done
sleep "${interval:-360}"
done
}
run_ban rx_dos.txt banmsg_dos.txt &
run_ban rx_egress.txt banmsg_egress.txt &
run_ban rx_exhaust.txt banmsg_exhaust.txt &
run rx_dos.txt banmsg_dos.txt ban &
run rx_egress.txt banmsg_egress.txt ban &
run rx_exhaust.txt stop_exhaust.txt stop &
# CTRL-c here will also send a SIGINTR to all child processes (and kill them)
echo "Banhammer started. Press CTRL-c to stop."