diff --git a/README.md b/README.md index 442531a..d4789eb 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,10 @@ more informations on https://envs.net/chat/matrix/ -**synapse blocklist tool:** - -An collection of modules for Synapse to block temporary email addresses and block invite-spam. - -see: https://git.envs.net/envs/synapse_blocklist_module - ## useful documentations -\- [matrix-spec](https://matrix.org/docs/spec/) +\- [matrix-spec](https://spec.matrix.org/latest/) + \- [synapse INSTALL.md](https://github.com/matrix-org/synapse/blob/master/docs/setup/installation.md) \- [synapse default homeserver.yaml](https://github.com/matrix-org/synapse/blob/master/docs/sample_config.yaml) @@ -24,3 +19,17 @@ see: https://git.envs.net/envs/synapse_blocklist_module \- [matrix-synchrotron-balancer](https://github.com/Sorunome/matrix-synchrotron-balancer) \- [matrix-media-repo](https://github.com/turt2live/matrix-media-repo) + +## useful tools + +### envs - synapse blocklist tool + +An collection of modules for Synapse to block temporary email addresses and invite-spam. + +see: https://git.envs.net/envs/synapse_blocklist_module + +### synadm + +Command line admin tool for Synapse + +repo: [https://github.com/JOJ0/synadm](https://github.com/JOJ0/synadm) diff --git a/usr/local/bin/README.md b/usr/local/bin/README.md index ddc8b5a..f4d61dd 100644 --- a/usr/local/bin/README.md +++ b/usr/local/bin/README.md @@ -1,8 +1,12 @@ # useful aliases +**deps.:** + +install moreutils +`apt install moreutils` + simple add it to your alias file. -**deps.:** ``` source "$HOME/.token" # contains $token server='server.tld' @@ -28,11 +32,15 @@ matrix-show_users() { ```bash matrix-deactivate-users() { - while read i; do - printf '%s\n' "$i"; \ - curl -s -H "Authorization: Bearer $token" -X POST 'https://'"$server"'/_synapse/admin/v1/deactivate/'"$i" -d '{"erase": true}'; printf '\n' - done < ~/deactivate_users.txt - echo > ~/deactivate_users.txt + if [ -s ~/deactivate_users.txt ]; then + while read i; do + printf '%s\n' "$i"; \ + curl -s -H "Authorization: Bearer $token" -X POST 'https://'"$server"'/_synapse/admin/v1/deactivate/'"$i" -d '{"erase": true}'; printf '\n' + done < ~/deactivate_users.txt + echo > ~/deactivate_users.txt + else + printf '~/deactivate_users.txt is empty.\n' + fi } ``` @@ -42,7 +50,6 @@ matrix-deactivate-users() { matrix-remove-empty-rooms() { TOPURGE=$(curl -s -H "Authorization: Bearer $token" -X GET \ 'https://'"$server"'/_synapse/admin/v1/rooms?limit=1000000' | jq -Mr '.rooms[] | select(.joined_local_members == 0) | .room_id') - for i in $TOPURGE; do printf 'processing room %s ..\n' "$i" curl -s -w "\nResponse code: %{response_code}\n" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X DELETE -d '{}' \ @@ -55,20 +62,24 @@ matrix-remove-empty-rooms() { ```bash matrix-purge-rooms() { - echo > ~/blocked_members.txt - while read i; do - printf '%s\n' "$i" - curl -s -H "Authorization: Bearer $token" -X GET 'https://'"$server"'/_synapse/admin/v1/rooms/'"$i"'/members' | jq -Mr .members[] >> ~/blocked_members.txt - curl -s -H "Authorization: Bearer $token" -X DELETE 'https://'"$server"'/_synapse/admin/v1/rooms/'"$i" -d '{"purge": true, "block": true}' - printf '\n' - done < ~/purge_rooms.txt - sed -i -e '/^$/d' ~/blocked_members.txt - sort -u -o ~/blocked_members.txt{,} - for i in $(grep "$server" ~/blocked_members.txt); do - printf '%s\n' "$i" - curl -s -H "Authorization: Bearer $token" -X POST 'https://'"$server"'/_synapse/admin/v1/deactivate/'"$i" -d '{"erase": true}' - done - sed -i '/'"$server"'/d' ~/blocked_members.txt + if [ -s ~/purge_rooms.txt ]; then + echo > ~/blocked_members.txt + while read i; do + printf '%s\n' "$i" + curl -s -H "Authorization: Bearer $token" -X GET 'https://'"$server"'/_synapse/admin/v1/rooms/'"$i"'/members' | jq -Mr .members[] >> ~/blocked_members.txt >/dev/null 2>&1 + curl -s -H "Authorization: Bearer $token" -X DELETE 'https://'"$server"'/_synapse/admin/v1/rooms/'"$i" -d '{"purge": true, "block": true}' + printf '\n' + done < ~/purge_rooms.txt + sed -i -e '/^$/d' ~/blocked_members.txt + sort -u -o ~/blocked_members.txt{,} + for i in $(grep "$server" ~/blocked_members.txt); do + printf '%s\n' "$i" + curl -s -H "Authorization: Bearer $token" -X POST 'https://'"$server"'/_synapse/admin/v1/deactivate/'"$i" -d '{"erase": true}' + done + sed -i '/'"$server"'/d' ~/blocked_members.txt + else + printf '~/purge_rooms.txt is empty.\n' + fi } ``` @@ -76,9 +87,8 @@ matrix-purge-rooms() { ```bash matrix-get-blocked_rooms() { - sudo -iu postgres psql -d matrix -c "SELECT room_id FROM blocked_rooms" > ~/blocked_rooms.tmp - sed -i -e 's/ //' -e '1,2d' ~/blocked_rooms.tmp - head -n -2 ~/blocked_rooms.tmp > ~/blocked_rooms.txt - rm ~/blocked_rooms.tmp + sudo -iu postgres psql -d matrix -c "SELECT room_id FROM blocked_rooms" > ~/blocked_rooms.txt + sed -i -e 's/ //' -e '1,2d' ~/blocked_rooms.txt + head -n -2 ~/blocked_rooms.txt | sponge ~/blocked_rooms.txt } ```