commit f0de085223ebb72ffe6c3d182725dcf69549f054
parent 4020ce23c984832db90950b11903553f5c8f6eec
Author: hhvn <hayden@haydenvh.com>
Date: Tue, 2 Feb 2021 16:38:24 +0000
hbbs.sh bin/login.sh include/log.sh: allow only one registration per day
Diffstat:
3 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/bin/login.sh b/bin/login.sh
@@ -2,6 +2,7 @@
. $cwd/include/userinfo.sh
. $cwd/include/common.sh
+. $cwd/include/log.sh
login(){
clear
@@ -11,6 +12,11 @@ login(){
prompt "login" user
[ "$user" = "new" ] && {
+ [ "$(get_log "create_account" | grep -v "localhost" | grep "${REMOTE_HOST:-localhost}")" != "" ] && {
+ error "you have already created an account today"
+ anykey
+ return 1
+ }
clear
echo "Registration"
echo
@@ -54,6 +60,7 @@ login(){
userset "$user" "email" "$email"
userset "$user" "passwd" "$(echo "$passwd" | sha512sum)"
userset "$user" "realname" "$user"
+ add_log "create_account" "${REMOTE_HOST:-localhost}"
touch $datadir/profile/$user
ok "account \"$user\" created"
[ "$verify_email" = "yes" ] && info "Your account expires in 2 days unless verified"
diff --git a/hbbs.sh b/hbbs.sh
@@ -8,7 +8,13 @@ export cwd=$(dirname $0)
mkdir $datadir -p || die "cannot write to data dir"
touch $datadir/.test || die "cannot write to data dir"
-mkdir -p $datadir/profile $datadir/boards $datadir/users $(for b in $(echo "$boards" | tr '[:upper:]' '[:lower:]'); do echo $datadir/boards/$b; done)
+mkdir -p \
+ $datadir/profile \
+ $datadir/boards \
+ $datadir/users \
+ $(for b in $(echo "$boards" | tr '[:upper:]' '[:lower:]'); do echo $datadir/boards/$b; done) \
+ $datadir/log
+touch $datadir/log/log
[ "$1" = "-f" ] && bin finger && exit 1
diff --git a/include/log.sh b/include/log.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+add_log(){
+ awk -v "date=$(date +%Y-%d-%m)" -v "time=$(date +%H:%M)" -v "key=$1" -v "value=$2" -F" " '
+ $1 == date # only keep logs from today
+ END {printf("%s\t%s\t%s\t%s", date, time, key, value)}
+ ' < $datadir/log/log > $datadir/log/log.new
+ mv $datadir/log/log.new $datadir/log/log
+}
+
+get_log(){
+ awk -v "date=$(date +%Y-%d-%m)" -v "key=$1" -F" " '
+ $1 == date && $3 == key
+ ' < $datadir/log/log
+}