From abe588221ec923480b12b8645dacef7bfb4ddc69 Mon Sep 17 00:00:00 2001 From: SkyperTHC Date: Mon, 22 Jan 2024 10:37:02 +0000 Subject: [PATCH] banhammer --- sfbin/banhammer.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/sfbin/banhammer.sh b/sfbin/banhammer.sh index 1451d04..fcf9da6 100755 --- a/sfbin/banhammer.sh +++ b/sfbin/banhammer.sh @@ -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."