Compare commits

...

3 Commits

Author SHA1 Message Date
PC-Admin
d986fb424e attempt to straighten text ui out 2023-08-20 19:33:52 +08:00
PC-Admin
d3e858a3ed update README.md 2023-08-20 19:29:06 +08:00
PC-Admin
7c19dfbf94 added event report functions and updated docs/ui 2023-08-20 19:10:54 +08:00
4 changed files with 169 additions and 17 deletions

View File

@ -6,6 +6,64 @@ A Matrix moderation tool to make managing a Synapse server easier.
Contact me at [@michael:perthchat.org](https://matrix.to/#/@michael:perthchat.org) if you get stuck or have an edit in mind.
***
## List of Functions
This tool abstracts the Synapse API so you can perform common moderation functions easier and in batch.
Here is a preview of the CLI interface:
```
##########################
# MATRIX MODERATION TOOL #
##########################
A tool for making common Synapse moderation tasks easier. Created by @PC-Admin.
----------------------------------------------
#### User Account Commands #### #### Room Commands ####
1) Deactivate a user account. 50) List details of a room.
2) Deactivate multiple user accounts. 51) List the members of a room.
3) Create a user account. 52) Export the state events of a room.
4) Create multiple user accounts. 53) Export the state events of multiple rooms.
5) Reset a users password. 54) List rooms in public directory.
6) Whois user account. 55) Remove a room from the public directory.
7) Whois multiple user accounts. 56) Remove multiple rooms from the public directory.
8) Query user account. 57) Redact a room event.
9) Query multiple user accounts. 58) List/Download all media in a room.
10) List room memberships of user. 59) Download media from multiple rooms.
11) Promote a user to server admin. 60) Quarantine all media in a room.
12) List all user accounts. 61) Shutdown a room.
13) Quarantine all media a users uploaded. 62) Shutdown multiple rooms.
14) Collect account data. 63) Delete a room.
15) List account pushers. 64) Delete multiple rooms.
16) Get rate limit of a user account. 65) Purge the event history of a room to a specific timestamp.
17) Set rate limit of a user account. 66) Purge the event history of multiple rooms to a specific timestamp.
18) Delete rate limit of a user account. 67) Get blocked status for room.
19) Check if user account exists. 68) Block a room.
20) Shadow ban a user. 69) Unblock a room.
21) Find a user by their 3PID.
#### Server Commands #### #### ipinfo.io ####
100) Delete and block a specific media. 140) Analyse a users country of origin.
101) Purge remote media repository up to a certain date. 141) Analyse multiple users country of origin.
102) Prepare database for copying events of multiple rooms.
103) Show last 10 reported events. #### Report Generation ####
104) Get all reported events. 150) Generate user report.
105) Get details of a reported event. 151) Lookup homeserver admin contact details.
152) Send a test email (to yourself).
#### rdlist - General #### 153) Send a test Matrix message (to yourself).
120) Block all rooms with specific rdlist tags. 154) Send test incident reports (to yourself).
121) Get rdlist tags for a room.
#### rdlist - Recommended Tags ####
For rdlist rooms with recommended tags, the following actions are available:
130) Collect User Reports on local accounts in rdlist rooms.
131) Send Incident Reports on remote accounts in rdlist rooms.
132) Block/Purge all rdlist rooms.
```
***
## Licensing
@ -135,7 +193,8 @@ To do:
- https://github.com/matrix-org/synapse/blob/master/docs/admin_api/delete_group.md
- https://matrix-org.github.io/synapse/v1.38/admin_api/rooms.html#make-room-admin-api
- https://matrix-org.github.io/synapse/latest/admin_api/server_notices.html
https://matrix-org.github.io/synapse/latest/usage/administration/admin_api/federation.html#destination-rooms
- https://matrix-org.github.io/synapse/latest/admin_api/event_reports.html
- https://matrix-org.github.io/synapse/latest/usage/administration/admin_api/federation.html#destination-rooms
2) Add fully automated (should just return a web link and decryption password) reporting functions for users:
- Description of why the report was made (what happened), include key information
- Any other usernames associated with that IP

View File

@ -11,9 +11,9 @@ This guide provides detailed steps for server-side operations that use the datab
---
### 1. Delete and Block Specific Media
100) **Delete and Block Specific Media.**
This command allows an admin to delete a specific media on their Matrix Synapse server and block it to prevent future accesses.
> This command allows an admin to delete a specific media on their Matrix Synapse server and block it to prevent future accesses.
#### Process Flow:
@ -33,7 +33,7 @@ $ ssh matrix.perthchat.org "true > ...path to file..."
$ ssh matrix.perthchat.org "chattr +i ...path to file..."
```
### 2. Purge Remote Media Repository
101) **Purge Remote Media Repository**
This command purges the remote media repository for a certain range of days.
Process Flow:
@ -49,7 +49,7 @@ $ date --date '149 days ago' +%s
$ curl -X POST --header "Authorization: Bearer ACCESS_TOKEN" '... Matrix Synapse purge endpoint ...'
```
### 3. Prepare Database for Copying Events of Multiple Rooms
102) **Prepare Database for Copying Events of Multiple Rooms**
This command prepares the PostgreSQL database to export events from multiple Matrix rooms.
Process Flow:
@ -82,3 +82,19 @@ After copying the data, ensure to clean up the RAM disk:
$ rm -r /matrix/postgres/data/ramdisk/*
$ umount /matrix/postgres/data/ramdisk
```
103) **Show last 10 reported events.**
> Gets the last 10 reported events using the event reports API and returns it.
https://matrix-org.github.io/synapse/latest/admin_api/event_reports.html#show-reported-events
104) **Paginate all reported events.**
> Combines all the events into a large JSON and returns it.
105) **Show details of a specific event report**
> This API returns information about a specific event report.
https://matrix-org.github.io/synapse/latest/admin_api/event_reports.html#show-details-of-a-specific-event-report

View File

@ -73,21 +73,22 @@ while pass_token == False:
print("19) Check if user account exists.\t\t68) Block a room.")
print("20) Shadow ban a user.\t\t\t\t69) Unblock a room.")
print("21) Find a user by their 3PID.")
print("\n#### Server Commands ####\t\t\t\t\t#### Report Generation ####")
print("100) Delete and block a specific media.\t\t\t\t150) Generate user report.")
print("101) Purge remote media repository up to a certain date.\t151) Lookup homeserver admin contact details.")
print("102) Prepare database for copying events of multiple rooms.\t152) Send a test email (to yourself).")
print("\t\t\t\t\t\t\t\t153) Sent a test Matrix message (to yourself).")
print("#### rdlist - General ####\t\t\t\t\t154) Send test incident reports (to yourself).")
print("120) Block all rooms with specific rdlist tags.")
print("\n#### Server Commands ####\t\t\t\t\t#### ipinfo.io ####")
print("100) Delete and block a specific media.\t\t\t\t140) Analyse a users country of origin.")
print("101) Purge remote media repository up to a certain date.\t141) Analyse multiple users country of origin.")
print("102) Prepare database for copying events of multiple rooms.")
print("103) Show last 10 reported events.\t\t\t\t#### Report Generation ####")
print("104) Get all reported events.\t\t\t\t\t150) Generate user report.")
print("105) Get details of a reported event.\t\t\t\t151) Lookup homeserver admin contact details.")
print("\t\t\t\t\t\t\t\t152) Send a test email (to yourself).")
print("#### rdlist - General ####\t\t\t\t\t153) Send a test Matrix message (to yourself).")
print("120) Block all rooms with specific rdlist tags.\t\t\t154) Send test incident reports (to yourself).")
print("121) Get rdlist tags for a room.")
print("\n#### rdlist - Recommended Tags ####\nFor rdlist rooms with recommended tags, the following actions are available:")
print("\n#### rdlist - Recommended Tags ####")
print("For rdlist rooms with recommended tags, the following actions are available:")
print("130) Collect User Reports on local accounts in rdlist rooms.")
print("131) Send Incident Reports on remote accounts in rdlist rooms.")
print("132) Block/Purge all rdlist rooms.")
print("\n#### ipinfo.io ####")
print("140) Analyse a users country of origin.")
print("141) Analyse multiple users country of origin.")
print("\nPlease enter a number from the above menu, or enter 'q' or 'e' to exit.\n")
menu_input = input()
if menu_input == "1":
@ -202,6 +203,15 @@ while pass_token == False:
server_commands.purge_remote_media_repo()
elif menu_input == "102":
server_commands.prepare_database_copy_of_multiple_rooms()
elif menu_input == "103":
reported_events = server_commands.get_reported_events(10)
print(json.dumps(reported_events, indent=4, sort_keys=True))
elif menu_input == "104":
all_reported_events = server_commands.paginate_reported_events() # Again assuming default values are set
print(json.dumps(all_reported_events, indent=4, sort_keys=True))
elif menu_input == "105":
report_details = server_commands.get_event_report_details()
print(json.dumps(report_details, indent=4, sort_keys=True))
elif menu_input == "120":
rdlist_commands.block_all_rooms_with_rdlist_tags(False,'','','')
elif menu_input == "121":

View File

@ -136,3 +136,70 @@ def prepare_database_copy_of_multiple_rooms():
print(chown_command_process.stdout)
print("\nThe sql query files have been generated, as postgres user in container run:\n# docker exec -it matrix-postgres /bin/bash\nbash-5.0$ export PGPASSWORD=your-db-password\nbash-5.0$ for f in /var/lib/postgresql/data/ramdisk/*/dump_room_data.sql; do psql --host=127.0.0.1 --port=5432 --username=synapse -w -f $f; done\n\nAfter copying the data to a cloud location law enforcement can access, clean up the ramdisk like so:\n# rm -r /matrix/postgres/data/ramdisk/*\n# umount /matrix/postgres/data/ramdisk")
def get_reported_events(limit=100, _from=0, dir='b', user_id=None, room_id=None):
url = f"https://{hardcoded_variables.homeserver_url}/_synapse/admin/v1/event_reports"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {hardcoded_variables.access_token}"
}
params = {
'limit': limit,
'from': _from,
'dir': dir
}
if user_id:
params['user_id'] = user_id
if room_id:
params['room_id'] = room_id
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
return response.json()
else:
print(f"Error fetching reported events: {response.status_code}, {response.text}")
return None
def paginate_reported_events(limit=100, dir='b', user_id=None, room_id=None):
_from = 0
all_reports = []
while True:
reports = get_reported_events(limit=limit, _from=_from, dir=dir, user_id=user_id, room_id=room_id)
if not reports or "event_reports" not in reports:
break
all_reports.extend(reports["event_reports"])
if "next_token" in reports:
_from = reports["next_token"]
else:
break
return all_reports
def get_event_report_details(preset_report_id=''):
if preset_report_id == '':
report_id = input("\nEnter the report_id of the report you wish to query (Example: 56): ")
elif preset_report_id != '':
report_id = preset_report_id
url = f"https://{hardcoded_variables.homeserver_url}/_synapse/admin/v1/event_reports/{report_id}"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {hardcoded_variables.access_token}"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()
else:
print(f"Error fetching event report details: {response.status_code}, {response.text}")
return None