Update makeuser

added banned user support and now moves added users to signups_current file instead of having to go through the  large list every time new users are added.    Also touches the .new_user file to ensure the date is the date the user was created so it'll be easier to figure out stale new user accounts in future.
This commit is contained in:
deepend-tildeclub 2023-09-24 14:45:14 -06:00 committed by GitHub
parent ff283a7a77
commit 642debc22d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 3 deletions

View File

@ -23,6 +23,22 @@ Subject: subscribe
" | sudo -u $1 sendmail tildeclub-join@lists.tildeverse.org " | sudo -u $1 sendmail tildeclub-join@lists.tildeverse.org
} }
is_banned() {
while read -r line; do
banned_user=$(echo "$line" | awk '{print $1}')
banned_email=$(echo "$line" | awk '{print $2}')
if [[ "$1" == "$banned_user" || "$2" == "$banned_email" ]]; then
return 0
fi
done < /var/signups_banned
return 1
}
move_to_current() {
grep -E "makeuser\s+$1\s+$2\s+\"$3\"" /var/signups >> /var/signups_current
sed -i "/makeuser\s\+$1\s\+$2\s\+\"$3\"/d" /var/signups
}
case $1 in case $1 in
-h | --help) -h | --help)
usage; exit ;; usage; exit ;;
@ -31,8 +47,12 @@ case $1 in
*) *)
[[ $# -ne 3 ]] && error_exit "not enough args" [[ $# -ne 3 ]] && error_exit "not enough args"
if is_banned "$1" "$2"; then
error_exit "user or email is banned"
fi
if id $1 > /dev/null 2>&1; then if id $1 > /dev/null 2>&1; then
exit 0 exit 0
fi fi
echo "adding new user $1" echo "adding new user $1"
@ -52,11 +72,14 @@ case $1 in
sudo rm -rf /home/$1/.git sudo rm -rf /home/$1/.git
sudo rm -rf /home/$1/README.md sudo rm -rf /home/$1/README.md
# Changing last edit date.
sudo touch /home/$1/.new_user
echo "adding ssh pubkey" echo "adding ssh pubkey"
echo "$3" | sudo tee /home/$1/.ssh/authorized_keys echo "$3" | sudo tee /home/$1/.ssh/authorized_keys
echo "making znc user" echo "moving user from signups to signups_current"
znccreate.py "$1" "$newpw" move_to_current $1 $2 "$3"
echo "announcing new user on mastodon" echo "announcing new user on mastodon"
toot "welcome new user ~$1!" toot "welcome new user ~$1!"