2020-05-12 00:43:03 -04:00
2023-07-07 11:24:11 -04:00
# Matrix Moderation Tool
2020-05-12 00:43:03 -04:00
2023-07-08 05:55:48 -04:00
A Matrix moderation tool to make managing a Synapse server easier.
2020-05-12 00:43:03 -04:00
2023-07-08 06:11:05 -04:00
Contact me at [@michael:perthchat.org ](https://matrix.to/#/@michael:perthchat.org ) if you get stuck or have an edit in mind.
2023-07-08 05:55:48 -04:00
2020-05-12 00:43:03 -04:00
***
## Licensing
2023-07-01 15:23:16 -04:00
This work is published under the MIT license, for more information on this license see here: https://opensource.org/license/mit/
2020-05-12 00:43:03 -04:00
2023-07-08 05:55:48 -04:00
2020-05-12 00:43:03 -04:00
***
## Setup script
2023-07-08 05:55:48 -04:00
You can hard code the server URL, federation port and access token into the [hardcoded_variables.py ](./hardcoded_variables.py ) file for faster use, it will prompt you for these values if you don't.
2020-05-12 00:43:03 -04:00
2020-09-22 09:23:04 -04:00
Your access token can be found in Element > Settings > Help & About, your user account must first be upgraded to a server admin.
2020-05-12 00:43:03 -04:00
2023-07-08 05:55:48 -04:00
2020-05-12 00:43:03 -04:00
***
## Upgrade user to 'server admin'
https://github.com/matrix-org/synapse/tree/master/docs/admin_api
“So first connect to the correct db and then run the UPDATE users...”
$ sudo -i -u postgres
$ psql synapse
synapse=# UPDATE users SET admin=1 WHERE name='@PC-Admin:perthchat.org';
UPDATE 1
synapse=#
‘ -’ sign instead of ‘ =’ means:
It means you didn't type a complete SQL query yet.
You need a semicolon to terminate the command.
2023-07-08 05:55:48 -04:00
2020-05-12 00:43:03 -04:00
***
## Make sure /_synapse/ is mapped
A few of the commands will not work unless /_synapse/ is mapped to port 8008. Here is a example for nginx:
```
location /_matrix {
proxy_pass http://127.0.0.1:8008;
proxy_set_header X-Forwarded-For $remote_addr;
}
location /_synapse {
proxy_pass http://127.0.0.1:8008;
proxy_set_header X-Forwarded-For $remote_addr;
}
```
2020-06-01 04:21:16 -04:00
You can also run the script locally on your server if you do not wish to map /_synapse/.
2023-07-14 13:49:08 -04:00
With the popular [matrix-docker-ansible-deploy ](https://github.com/spantaleev/matrix-docker-ansible-deploy ) playbook you can expose this API interface by enabling 'Synapse Admin':
`matrix_synapse_admin_enabled: true`
2023-07-08 05:55:48 -04:00
***
## Roadmap
To do:
2023-07-18 18:01:40 -04:00
1) Add the following functions:
2023-07-18 18:02:46 -04:00
- https://github.com/matrix-org/synapse/blob/master/docs/admin_api/delete_group.md
- https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#account-data
- https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#list-all-pushers
- https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#override-ratelimiting-for-users
- https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#check-username-availability
- https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#find-a-user-based-on-their-id-in-an-auth-provider
- https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#find-a-user-based-on-their-third-party-id-threepid-or-3pid
2023-07-18 18:01:40 -04:00
2) Make the menu prettier! - DONE
2023-07-08 05:55:48 -04:00
3) Modularise the functions into multiple files - DONE
2023-07-14 16:47:51 -04:00
4) Use URI module for all API calls instead of curl - DONE
5) Add more automated rdlist function with sane defaults - DONE
6) Add fully automated (should just return a web link and decryption password) reporting functions for users:
2023-07-08 05:55:48 -04:00
- User's ID
2023-07-18 18:01:40 -04:00
- Whois Data
- Account Data
- Query Data
- Pushers List
- List of the rooms the user is participating in, divided into 1:1 conversations and larger rooms
2023-07-08 05:55:48 -04:00
- The content of the messages they've sent (if they were sent to rooms your server is participating in)
2023-07-18 18:01:40 -04:00
- Copies of any media they've sent
7) Add a room report function to create a properly formatted report for rdlist
8) Add a function to extract a users email or 3PID
9) Do room shutdowns in parallel
2023-07-08 05:55:48 -04:00
2023-07-01 15:23:16 -04:00
***
## rdlist Functionality
'rdlist' is a comprehensive list of child abuse related rooms on Matrix, it's a safety initiative led by the [Legion of Janitors ](https://matrix.to/#/#janitors:glowers.club ).
This script can automatically load and block/purge abusive rooms from rdlist, making it **very easy** for inexperienced administrators to block this harmful content.
2023-07-07 18:22:43 -04:00
If you are running a public server, please dm me at [@michael:perthchat.org ](https://matrix.to/#/@michael:perthchat.org ) and I can invite you to the 'Legion of Janitors' room.
2023-07-01 15:23:16 -04:00
2023-07-04 09:44:03 -04:00
Once you have read access to the [rdlist repository ](https://code.glowers.club/loj/rdlist ), simply run this moderation script like so:
2023-07-01 15:23:16 -04:00
```
2023-07-08 05:55:48 -04:00
$ python3 moderation_tool.py
2023-07-01 15:23:16 -04:00
Please select one of the following options:
...
#### rdlist ####
30) Block all rooms with specific rdlist tags.
2023-07-07 18:19:10 -04:00
34) Block all rooms with recommended rdlist tags.
2023-07-01 15:23:16 -04:00
('q' or 'e') Exit.
2023-07-07 18:19:10 -04:00
34
2023-07-01 15:23:16 -04:00
2023-07-14 16:47:51 -04:00
Successfully set user as server admin.
2023-07-07 18:19:10 -04:00
rdlist repo already cloned...
Fetching origin
rdlist repo is up-to-date, no need to pull changes.
2023-07-01 15:23:16 -04:00
2023-07-07 18:19:10 -04:00
Using recommended rdlist tags.
2023-07-01 15:23:16 -04:00
2023-07-14 16:47:51 -04:00
Number of rooms being shutdown: 318
2023-07-01 15:23:16 -04:00
2023-07-14 16:47:51 -04:00
Are you sure you want to shutdown these rooms? y/n? y
2023-07-01 15:23:16 -04:00
2023-07-14 16:47:51 -04:00
https://matrix.perthchat.org/_synapse/admin/v1/rooms/!***REDACTED***:matrix.org/state
2023-07-01 15:23:16 -04:00
2023-07-14 16:47:51 -04:00
{"errcode":"M_NOT_FOUND","error":"Room not found"}
The room was not found.
https://matrix.perthchat.org/_synapse/admin/v1/rooms/!***REDACTED***:cuteworld.space/state
{"errcode":"M_NOT_FOUND","error":"Room not found"}
The room was not found.
https://matrix.perthchat.org/_synapse/admin/v1/rooms/!***REDACTED***:matrix.org/state
{"errcode":"M_NOT_FOUND","error":"Room not found"}
The room was not found.
https://matrix.perthchat.org/_synapse/admin/v1/rooms/!***REDACTED***:matrix.org/state
{"errcode":"M_NOT_FOUND","error":"Room not found"}
The room was not found.
...
2023-07-01 15:23:16 -04:00
```
2023-07-14 16:47:51 -04:00
Note that this script before shutting these rooms down will save the state events to the "./state_events" folder, please keep this data as it's important for law enforcement.