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-08-18 04:12:54 -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.~~ (Prompting is currently broken)
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-23 13:44:41 -04:00
This script also requires you to install the following PIP packages:
```
pip3 install python-whois
pip3 install requests
2023-07-29 12:10:47 -04:00
pip3 install matrix-nio
2023-07-23 13:44:41 -04:00
```
2023-08-18 04:12:54 -04:00
***
## Running the script
2023-08-18 04:28:31 -04:00
`$ python3 moderation_tool.py`
2023-08-18 04:12:54 -04:00
2023-07-08 05:55:48 -04:00
2020-05-12 00:43:03 -04:00
***
## Upgrade user to 'server admin'
2023-07-29 12:10:47 -04:00
To use this moderation script you need an OAuth token of a "server admin" account. If you've just setup a Matrix server, you'll need to promote an account to server admin by altering your database.
2020-05-12 00:43:03 -04:00
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=#
2023-07-29 12:10:47 -04:00
Note: A ‘ -’ sign instead of ‘ =’ means you didn't type a complete SQL query yet!
2020-05-12 00:43:03 -04:00
2023-07-29 12:10:47 -04:00
(You need a semicolon (;) at the end to terminate the command.)
2020-05-12 00:43:03 -04:00
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://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-20 15:15:08 -04:00
- https://github.com/matrix-org/synapse/blob/master/docs/admin_api/delete_group.md
2023-07-26 15:39:48 -04:00
2) Add fully automated (should just return a web link and decryption password) reporting functions for users:
2023-07-29 11:46:32 -04:00
- Description of why the report was made (what happened), include key information
2023-07-22 16:21:50 -04:00
- Any other usernames associated with that IP
- Timestamp for when illegal material was accessed
2023-07-20 15:15:08 -04:00
- Description of report format and contents (to guide the reader)
2023-07-27 17:15:46 -04:00
- Collect state event dumps of recently read rooms as well (as they may have looked at other suss rooms recently)
3) Have recommended rdlist function:
2023-08-18 04:12:54 -04:00
- return a list of offending accounts and the tags they accessed (for creating incident_dict's) - DONE
2023-07-29 11:46:32 -04:00
- add the shadowban function to prevent members alerting others after mass shutdowns - DONE
2023-07-26 15:39:48 -04:00
4) Only email reportID in incident report?
5) Add a room report function to create a properly formatted report for rdlist
2023-07-29 11:46:32 -04:00
6) Expand the incident reporting to also issue reports over Matrix
7) Automated public room joining and reminder if reporting email is not available?
8) Refine ipinfo module to also return extra details about the IP
9) Make existing functions compatible with JSON formatted inputs
2023-07-22 16:21:50 -04:00
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-08-18 06:17:19 -04:00
For more information on rdlist related function consult the [support document ](./docs/rdlist_functions.md ).
2023-08-18 06:46:48 -04:00
***
## One-touch Reporting
WARNING: This section is under heavy development and shouldn't be used by anyone!!!
This script can automatically generate reports about user accounts for law enforcement.
It collects as much data about the target user account as possible, then packages it into an encrypted ZIP file that can be shared:
```
Please enter a number from the above menu, or enter 'q' or 'e' to exit.
150
Please enter the username to automatically generate a report: pedobear
...
Report generated successfully on user: "pedobear"
You can send this .zip file and password when reporting a user to law enforcement.
.zip file location: ./reports/pedobear_2023-07-23_02-21-56.zip
.zip file size: 0.503927 MB
```