hbbs

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

commit 55fe1486ad0c225f74f02f3d7d79a8297512f187
parent 1f3259cb0ed876427a45031fc4a7c6e8ba3602fd
Author: hhvn <hayden@haydenvh.com>
Date:   Mon,  1 Feb 2021 12:01:37 +0000

add posting permissions to boards

Diffstat:
Mbin/interface.sh | 8++++++--
Mconfig.sh | 11++++++++---
Ainclude/permissions.sh | 33+++++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/bin/interface.sh b/bin/interface.sh @@ -1,8 +1,10 @@ #!/bin/sh . $cwd/include/userinfo.sh +. $cwd/include/permissions.sh k=$(tput setaf $key___colour) +e=$(tput setaf $error_colour) s=$(tput sgr0) set_mode(){ @@ -83,7 +85,7 @@ menu_list(){ 1 {printf("%s% 3s.%- 3s%s [%s%s%s] %- 10s | %s\n", c1, $1, $2, c0, c2, $3, c0, $4, $5); n=$1}' \ < $datadir/boards/$board/list | pager 5 $(echo "$banner" | wc -l) printf '=%- 10s============================================================Page:%- 3d=\n' "$(echo "$board" | tr '[:lower:]' '[:upper:]')" "$page" | tr ' ' '=' | sed 's/==$/ =/;s/:=/: /' - while prompt "Ne${k}x${s}t ${k}p${s}revious ${k}b${s}oards rel${k}o${s}ad ${k}r${s}ead ${k}n${s}ew ${k}h${s}elp" input + while prompt "Ne${k}x${s}t ${k}p${s}revious ${k}b${s}oards rel${k}o${s}ad ${k}r${s}ead ${k}$(check_post_perm $board $user noprint || printf "${e}")n${s}ew ${k}h${s}elp" input do parse_in "$input" case "$cmd" in @@ -103,6 +105,7 @@ menu_list(){ } || error "no such id" ;; n) + check_post_perm $board $user || continue [ "$arg" = "" ] && prompt "Subject" subject || subject="$arg" info "Type ctrl+d to end the post" file="$datadir/boards/$board/$(echo "$(find $datadir/boards/$board/ -type f | wc -l) + 1" | bc).post" @@ -159,7 +162,7 @@ menu_read(){ id2=${id##*.} cat $datadir/boards/$board/$(echo "$file" | sed -E 's/.* (.)/\1/') pager2 < $datadir/boards/$board/$(echo "$file" | sed -E 's/.* (.)/\1/') - while prompt "($(($id2+1))/$(awk -v "file=$(echo "$file" | sed 's/ .*//')" -F" " '$6 == file' < $datadir/boards/$board/list | wc -l)) Ne${k}x${s}t ${k}p${s}revious rep${k}l${s}y ${k}b${s}oards b${k}a${s}ck ${k}h${s}elp" input + while prompt "($(($id2+1))/$(awk -v "file=$(echo "$file" | sed 's/ .*//')" -F" " '$6 == file' < $datadir/boards/$board/list | wc -l)) Ne${k}x${s}t ${k}p${s}revious rep${k}$(check_reply_perm $board $user noprint)l${s}y ${k}b${s}oards b${k}a${s}ck ${k}h${s}elp" input do parse_in "$input" case "$cmd" in @@ -177,6 +180,7 @@ menu_read(){ ;; b) set_mode boards; break ;; l) + check_reply_perm $board $user || continue info "Type ctrl+d save the post" ofile="$file" file="$datadir/boards/$board/$(echo "$(find $datadir/boards/$board/ -type f | wc -l) + 1" | bc).post" diff --git a/config.sh b/config.sh @@ -11,14 +11,19 @@ Welcome to the bbs. If you do not have an account, login as "new" to register. There'\''s no guest view. ' -bbs_addr="bbs.hlirc.net" -email_addr="bbs@hlirc.net" boards="QUOTES SANDBOX GENERAL ADMIN FILES" + board_quotes_desc="Quotes from the irc server" board_sandbox_desc="Send test messages here" board_general_desc="General discussions/ideas" -board_admin_desc="The Administration" +board_admin_desc="Announcements/news" board_files_desc="Links to files/torrents" + +board_admin_post_whitelist="hhvn" +#board_admin_reply_whitelist="hhvn" + +bbs_addr="bbs.hlirc.net" +email_addr="bbs@hlirc.net" term="xterm-256color" datadir="/var/bbs" error_colour=88 diff --git a/include/permissions.sh b/include/permissions.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +check_post_perm(){ + local board="$1" + local user="$2" + local whitelist="$(eval "echo \$board_${board}_post_whitelist")" + [ "$whitelist" = "" ] && return + + for u in $whitelist + do + [ "$u" = "$user" ] && return + done + + # this point shouldn't be reached if user has perms + [ "$3" != "noprint" ] && error "no permission to post new threads on this board" + return 1 +} + +check_reply_perm(){ + local board="$1" + local user="$2" + local whitelist="$(eval "echo \$board_${board}_reply_whitelist")" + [ "$whitelist" = "" ] && return + + for u in $whitelist + do + [ "$u" = "$user" ] && return + done + + # this point shouldn't be reached if user has perms + [ "$3" != "noprint" ] && error "no permission to post replies to this board" + return 1 +}