add nuke users script

This commit is contained in:
creme 2024-12-25 19:10:46 +01:00
parent 86a18749a6
commit 6c7eec5155
No known key found for this signature in database
GPG Key ID: C147C3B7FBDF08D0

View File

@ -0,0 +1,42 @@
#!/bin/bash
set -e -u
token=''
domain='matrix.envs.net'
username='matrix'
db='matrix'
file="$HOME/nukeusers.txt"
ban_dom='frontdomain.org rustyload.com'
for bd in $ban_dom
do
query="select user_id from user_threepids where address ilike '%$bd' order by added_at"
psql -q -U "$username" -d "$db" -c "\copy ($query) TO '$file.tmp'"
cat "$file.tmp" >> "$file"; rm "$file.tmp"
done
nuke_user() {
for user in $(cat nukeusers.txt)
do
curl --header "Authorization: Bearer $token" -X POST "https://$domain/_synapse/admin/v1/deactivate/$user"
printf ' %s deactivated.\n' "$user"
done
}
if [ -n "$file" ]; then
while true; do
read -p "Do you like to deactivate the user in nukeusers.txt? " ysn
case $ysn in
[Yy]* ) nuke_user; break;;
[Ss]* ) less "$file"; break;;
[Nn]* ) exit;;
* ) printf 'Please answer with '"'y'"' (for yes) or '"'n'"' (for no). you can also use '"'s'"' to get a list of all users.\n\n';;
esac
done
rm "$file"
else
printf 'no entry in %s.\n' "$file"
fi
exit 0