From 6c7eec515565c8d60a5af50c227efc11f9577393 Mon Sep 17 00:00:00 2001 From: creme Date: Wed, 25 Dec 2024 19:10:46 +0100 Subject: [PATCH] add nuke users script --- usr/local/bin/matrix-nukeusers.sh | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 usr/local/bin/matrix-nukeusers.sh diff --git a/usr/local/bin/matrix-nukeusers.sh b/usr/local/bin/matrix-nukeusers.sh new file mode 100644 index 0000000..0b0f305 --- /dev/null +++ b/usr/local/bin/matrix-nukeusers.sh @@ -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