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

@ -11,29 +11,39 @@ do_ban() {
lgban "$2" "$3" 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 interval
local rx_fn="/sf/config/db/private/${1}" local rx_fn="/sf/config/db/private/${1}"
local msg_fn="/sf/config/db/private/${2}" local msg_fn="/sf/config/db/private/${2}"
local regex local regex
local reason="${rx_fn%.txt}" local reason="${rx_fn%.txt}"
local cmd="${3:-ban}"
reason="${reason##*rx_}" reason="${reason##*rx_}"
while :; do while :; do
source "$rx_fn" || { sleep 60; continue; } source "$rx_fn" || { sleep 60; continue; }
for lg in $(lgx "$regex" skiptoken); do for lg in $(lgx "$regex" skiptoken); do
if [[ -f "$msg_fn" ]]; then if [[ -f "$msg_fn" ]]; then
do_ban "$reason" "$lg" "$(<"$msg_fn"))" "do_${cmd}" "$reason" "$lg" "$(<"$msg_fn"))"
else 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 fi
done done
sleep "${interval:-360}" sleep "${interval:-360}"
done done
} }
run_ban rx_dos.txt banmsg_dos.txt & run rx_dos.txt banmsg_dos.txt ban &
run_ban rx_egress.txt banmsg_egress.txt & run rx_egress.txt banmsg_egress.txt ban &
run_ban rx_exhaust.txt banmsg_exhaust.txt & run rx_exhaust.txt stop_exhaust.txt stop &
# CTRL-c here will also send a SIGINTR to all child processes (and kill them) # CTRL-c here will also send a SIGINTR to all child processes (and kill them)
echo "Banhammer started. Press CTRL-c to stop." echo "Banhammer started. Press CTRL-c to stop."