hbbs

bbs.hlirc.net
Log | Files | Refs | README | LICENSE

commit 92ef08edefc99dfd13e6179978699b324e622d97
parent 16e8beacafdc66e34ea0dc797292a78872a0ef0e
Author: hhvn <hayden@haydenvh.com>
Date:   Wed,  3 Feb 2021 01:19:34 +0000

bin/interface.sh include/log.sh include/permissions.sh: add throttling for excessive posting

Diffstat:
Mbin/interface.sh | 4++++
Minclude/log.sh | 2+-
Minclude/permissions.sh | 17+++++++++++++++++
3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/bin/interface.sh b/bin/interface.sh @@ -137,6 +137,8 @@ menu_list(){ mv $datadir/boards/$board/list.new $datadir/boards/$board/list unlock $datadir/boards/$board/list ok "message sent" + add_log "post" "$user" + check_post_throttle "$user" anykey break ;; @@ -222,6 +224,8 @@ menu_read(){ unlock $datadir/boards/$board/list set_mode list ok "message sent" + add_log "post" "$user" + check_post_throttle "$user" anykey break ;; diff --git a/include/log.sh b/include/log.sh @@ -20,6 +20,6 @@ get_log(){ get_log_time(){ awk -v "date=$(date +%Y-%d-%m)" -v "key=$1" -F" " ' - $1 == date && $3 == key {print $2 "\t" $3} + $1 == date && $3 == key {print $2 "\t" $4} ' < $datadir/log/log } diff --git a/include/permissions.sh b/include/permissions.sh @@ -3,6 +3,12 @@ check_post_perm(){ local board="$1" local user="$2" + + [ "$(get_log_time "post-throttle" | grep "^$(date +%H:)" | awk '{print $2}' | grep "^$user$")" != "" ] && { + [ "$3" != "noprint" ] && error "you have been throttled due to sending $post_limit posts/replies/messages in a minute" + return 1 + } + local whitelist="$(eval "echo \$board_${board}_post_whitelist")" [ "$whitelist" = "" ] && return @@ -19,6 +25,12 @@ check_post_perm(){ check_reply_perm(){ local board="$1" local user="$2" + + [ "$(get_log_time "post-throttle" | grep "^$(date +%H:)" | awk '{print $2}' | grep "^$user$")" != "" ] && { + [ "$3" != "noprint" ] && error "you have been throttled due to sending $post_limit posts/replies/messages in a minute" + return 1 + } + local whitelist="$(eval "echo \$board_${board}_reply_whitelist")" [ "$whitelist" = "" ] && return @@ -31,3 +43,8 @@ check_reply_perm(){ [ "$3" != "noprint" ] && error "no permission to post replies to this board" return 1 } + +check_post_throttle(){ + [ $(get_log_time "post" | grep "^$(date +%H:%M)" | awk '{print $2}' | grep "^$1$" | wc -l) -eq $post_limit ] && \ + error "you have been throttled due to sending $post_limit posts/replies/messages in a minute" +}