mirror of
https://github.com/PC-Admin/matrix-moderation-tool.git
synced 2025-09-05 23:40:31 -04:00
Compare commits
8 Commits
1be96637ee
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
0d4b3744f1 | ||
|
6b7b5bf261 | ||
|
7475e38388 | ||
|
d986fb424e | ||
|
d3e858a3ed | ||
|
7c19dfbf94 | ||
|
adc32b2b27 | ||
|
56373d68db |
64
README.md
64
README.md
@@ -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
|
||||
|
||||
@@ -131,8 +189,12 @@ You can send this .zip file and password when reporting a user to law enforcemen
|
||||
To do:
|
||||
1) Add the following functions:
|
||||
- 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
|
||||
- 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 - DONE
|
||||
- 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/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
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
This script can automatically load and block/purge abusive rooms from rdlist, making it **very easy** for inexperienced administrators to block this harmful content.
|
||||
|
||||
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.
|
||||
If you are running a public server, please dm me at [@PC-Admin:matrix.org](https://matrix.to/#/@PC-Admin:matrix.org) and I can invite you to the 'Legion of Janitors' room.
|
||||
|
||||
***
|
||||
## Collect User Reports on local users in rdlist rooms
|
||||
|
@@ -2,63 +2,101 @@
|
||||
#### Room Commands ####
|
||||
|
||||
50) **List details of a room.**
|
||||
- Shows comprehensive information about a specific room.
|
||||
|
||||
> Shows comprehensive information about a specific room.
|
||||
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/rooms.html#room-details-api
|
||||
|
||||
51) **List the members of a room.**
|
||||
- Displays all the members who are part of a particular room.
|
||||
|
||||
> Displays all the members who are part of a particular room.
|
||||
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/rooms.html#room-members-api
|
||||
|
||||
52) **Export the state events of a room.**
|
||||
- Retrieves and saves the state events (such as topic changes, member joins) of a specific room.
|
||||
|
||||
> Retrieves and saves the state events (such as topic changes, member joins) of a specific room.
|
||||
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/rooms.html#room-state-api
|
||||
|
||||
53) **Export the state events of multiple rooms.**
|
||||
- Gathers and saves the state events from several rooms simultaneously.
|
||||
|
||||
> Gathers and saves the state events from several rooms simultaneously.
|
||||
|
||||
54) **List rooms in public directory.**
|
||||
- Displays all the rooms that are publicly available and listed in the directory.
|
||||
|
||||
> Displays all the rooms that are publicly available and listed in the directory.
|
||||
|
||||
https://spec.matrix.org/legacy/client_server/r0.6.0.html#get-matrix-client-r0-publicrooms
|
||||
|
||||
55) **Remove a room from the public directory.**
|
||||
- Takes a specific room off the public directory, making it less accessible to users browsing the directory.
|
||||
|
||||
> Takes a specific room off the public directory, making it less accessible to users browsing the directory.
|
||||
|
||||
56) **Remove multiple rooms from the public directory.**
|
||||
- Removes several rooms from the public directory at once.
|
||||
|
||||
> Removes several rooms from the public directory at once.
|
||||
|
||||
57) **Redact a room event.**
|
||||
- Conceals specific events in a room, such as messages or media, from being visible.
|
||||
|
||||
> Conceals specific events in a room, such as messages or media, from being visible.
|
||||
|
||||
58) **List/Download all media in a room.**
|
||||
- Displays and offers the option to download all media files shared in a specific room.
|
||||
|
||||
> Displays and offers the option to download all media files shared in a specific room.
|
||||
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/media_admin_api.html#list-all-media-in-a-room
|
||||
|
||||
59) **Download media from multiple rooms.**
|
||||
- Enables downloading of media files shared across several rooms.
|
||||
|
||||
> Enables downloading of media files shared across several rooms.
|
||||
|
||||
60) **Quarantine all media in a room.**
|
||||
- Isolates and restricts access to all media files in a specific room, usually due to concerns over inappropriate content.
|
||||
|
||||
> Isolates and restricts access to all media files in a specific room, usually due to concerns over inappropriate content.
|
||||
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/media_admin_api.html#quarantining-media-in-a-room
|
||||
|
||||
61) **Shutdown a room.**
|
||||
- Terminates a room, preventing further activities or messages in it.
|
||||
|
||||
> Terminates a room, preventing further activities or messages in it.
|
||||
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/rooms.html#version-2-new-version
|
||||
|
||||
62) **Shutdown multiple rooms.**
|
||||
- Closes several rooms simultaneously, halting any ongoing activity in them.
|
||||
|
||||
> Closes several rooms simultaneously, halting any ongoing activity in them.
|
||||
|
||||
63) **Delete a room.**
|
||||
- Permanently removes a room and all its content.
|
||||
|
||||
> Permanently removes a room and all its content.
|
||||
|
||||
64) **Delete multiple rooms.**
|
||||
- Erases several rooms and their content from the server at once.
|
||||
|
||||
> Erases several rooms and their content from the server at once.
|
||||
|
||||
65) **Purge the event history of a room to a specific timestamp.**
|
||||
- Deletes all events in a room up to a certain point in time, preserving events after that timestamp.
|
||||
|
||||
> Deletes all events in a room up to a certain point in time, preserving events after that timestamp.
|
||||
|
||||
66) **Purge the event history of multiple rooms to a specific timestamp.**
|
||||
- Clears the events in several rooms up to a specified timestamp.
|
||||
|
||||
> Clears the events in several rooms up to a specified timestamp.
|
||||
|
||||
67) **Get blocked status for room.**
|
||||
- Checks if a room is blocked and restricted from user access.
|
||||
|
||||
> Checks if a room is blocked and restricted from user access.
|
||||
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/rooms.html#get-block-status
|
||||
|
||||
68) **Block a room.**
|
||||
- Restricts access to a room, preventing users from joining or interacting in it.
|
||||
|
||||
> Restricts access to a room, preventing users from joining or interacting in it.
|
||||
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/rooms.html#block-or-unblock-a-room
|
||||
|
||||
69) **Unblock a room.**
|
||||
- Restores access to a previously blocked room, allowing users to join and participate once more.
|
||||
|
||||
> **Note:** Managing rooms is a sensitive operation, especially when dealing with content and user privacy. Ensure you have the required permissions and handle operations with care.
|
||||
> Restores access to a previously blocked room, allowing users to join and participate once more.
|
||||
|
||||
**Note:** Managing rooms is a sensitive operation, especially when dealing with content and user privacy. Ensure you have the required permissions and handle operations with care.
|
||||
|
@@ -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:
|
||||
@@ -45,11 +45,27 @@ Process Flow:
|
||||
|
||||
Example:
|
||||
```bash
|
||||
$ date --date '149 days ago' +%s
|
||||
$ curl -X POST --header "Authorization: Bearer ACCESS_TOKEN" '... Matrix Synapse purge endpoint ...'
|
||||
$ python3 moderation_tool.py
|
||||
|
||||
101
|
||||
|
||||
Enter the number of days to purge from: 30
|
||||
|
||||
Enter the number of days to purge too: -2
|
||||
{"deleted":0}
|
||||
{"deleted":0}
|
||||
{"deleted":3}
|
||||
{"deleted":360}
|
||||
{"deleted":469}
|
||||
...
|
||||
{"deleted":1020}
|
||||
{"deleted":2440}
|
||||
{"deleted":0}
|
||||
{"deleted":0}
|
||||
Done! :)
|
||||
```
|
||||
|
||||
### 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 +98,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
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
> This function disables a specific user's account, making it unusable for the owner.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#deactivate-account
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#deactivate-account
|
||||
|
||||
2) **Deactivate multiple user accounts.**
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
> Use this to generate a new user account.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#create-or-modify-account
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#create-or-modify-account
|
||||
|
||||
4) **Create multiple user accounts.**
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
|
||||
> If a user forgets their password, this function helps set a new one.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#reset-password
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#reset-password
|
||||
|
||||
6) **Whois user account.**
|
||||
|
||||
> Provides detailed information about a specific user's account.
|
||||
> This API returns information about the active sessions for a specific user.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#query-current-sessions-for-a-user
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#query-current-sessions-for-a-user
|
||||
|
||||
7) **Whois multiple user accounts.**
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
> Allows you to get specific details or attributes of a user account.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#query-user-account
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#query-user-account
|
||||
|
||||
9) **Query multiple user accounts.**
|
||||
|
||||
@@ -51,13 +51,13 @@
|
||||
|
||||
> Displays the list of rooms that a user is a part of.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#list-room-memberships-of-a-user
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#list-room-memberships-of-a-user
|
||||
|
||||
11) **Promote a user to server admin.**
|
||||
|
||||
> Elevates a user's privileges, making them an administrator on the server.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#change-whether-a-user-is-a-server-administrator-or-not
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#change-whether-a-user-is-a-server-administrator-or-not
|
||||
|
||||
12) **List all user accounts.**
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
|
||||
> This API quarantines all local media that a local user has uploaded. That is to say, if you would like to quarantine media uploaded by a user on a remote homeserver, you should instead use one of the other APIs. Useful for potential harmful or inappropriate content.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.40/admin_api/media_admin_api.html#quarantining-all-media-of-a-user
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/media_admin_api.html#quarantining-all-media-of-a-user
|
||||
|
||||
14) **Collect account data.**
|
||||
|
||||
@@ -79,25 +79,25 @@
|
||||
|
||||
> Shows devices and services that have push access to a user's account.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#list-all-pushers
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#list-all-pushers
|
||||
|
||||
16) **Get rate limit of a user account.**
|
||||
|
||||
> Displays the frequency at which a user can make requests or actions.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#get-status-of-ratelimit
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#get-status-of-ratelimit
|
||||
|
||||
17) **Set rate limit of a user account.**
|
||||
|
||||
> Adjusts the frequency rate at which a user can make requests or actions.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#set-ratelimit
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#set-ratelimit
|
||||
|
||||
18) **Delete rate limit of a user account.**
|
||||
|
||||
> Removes any rate limits set on a user's account, granting them unrestricted action frequency.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#delete-ratelimit
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#delete-ratelimit
|
||||
|
||||
19) **Check if user account exists.**
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
|
||||
> Shadow-banning a user should be used as a tool of last resort and may lead to confusing or broken behaviour for the client. A shadow-banned user will not receive any notification and it is generally more appropriate to ban or kick abusive users. A shadow-banned user will be unable to contact anyone on the server.
|
||||
|
||||
https://matrix-org.github.io/synapse/v1.38/admin_api/user_admin_api.html#shadow-banning-users
|
||||
https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#controlling-whether-a-user-is-shadow-banned
|
||||
|
||||
21) **Find a user by their 3PID (Third-party ID).**
|
||||
|
||||
|
@@ -73,21 +73,23 @@ 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("\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("106) Send a server notice.\t\t\t\t\t152) Send a test email (to yourself).")
|
||||
print("\t\t\t\t\t\t\t\t\t153) Send a test Matrix message (to yourself).")
|
||||
print("\n#### rdlist - General ####\t\t\t\t\t154) Send test incident reports (to yourself).")
|
||||
print("120) Block all rooms with specific rdlist tags.")
|
||||
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 +204,18 @@ 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 == "106":
|
||||
server_commands.send_server_notice()
|
||||
print("\nServer notice sent.\n")
|
||||
elif menu_input == "120":
|
||||
rdlist_commands.block_all_rooms_with_rdlist_tags(False,'','','')
|
||||
elif menu_input == "121":
|
||||
|
@@ -258,6 +258,7 @@ def lookup_homeserver_admin(preset_baseurl):
|
||||
# If the request was successful, the status code will be 200
|
||||
if response.status_code == 200 and ( "email_address" in response.text or "matrix_id" in response.text ):
|
||||
# Parse the response as JSON
|
||||
print(response.text)
|
||||
data = json.loads(response.text)
|
||||
|
||||
#print("\nAdmin contact details for " + baseurl + " are: " + str(data))
|
||||
|
@@ -136,3 +136,131 @@ 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
|
||||
|
||||
def send_server_notice(preset_user_id='', preset_message='', txnId=None, event_type="m.room.message", state_key=None):
|
||||
"""
|
||||
Sends a server notice to a given user.
|
||||
|
||||
Args:
|
||||
- user_id (str): The Matrix ID of the user to send the notice to, e.g. "@target_user:server_name".
|
||||
- message (str): The message to be sent as a notice.
|
||||
- txnId (str, optional): A unique transaction ID. If provided, retransmissions with the same txnId will be ignored.
|
||||
- event_type (str, optional): The type of event. Defaults to "m.room.message".
|
||||
- state_key (str, optional): Setting this will result in a state event being sent.
|
||||
|
||||
Returns:
|
||||
- dict: A dictionary containing the response from the server.
|
||||
"""
|
||||
|
||||
# Take user_id from user if not provided
|
||||
if preset_user_id == '':
|
||||
user_id = input("\nEnter the user_id of the user you would like to send the server notice to: ")
|
||||
elif preset_user_id != '':
|
||||
user_id = preset_user_id
|
||||
|
||||
# Take message from user if not provided
|
||||
if preset_message == '':
|
||||
message = input("\nEnter the message you would like to send to the user: ")
|
||||
elif preset_message != '':
|
||||
message = preset_message
|
||||
|
||||
# Construct the URL based on whether a txnId is provided
|
||||
if txnId:
|
||||
url = f"https://{hardcoded_variables.homeserver_url}/_synapse/admin/v1/send_server_notice/{txnId}"
|
||||
else:
|
||||
url = f"https://{hardcoded_variables.homeserver_url}/_synapse/admin/v1/send_server_notice"
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {hardcoded_variables.access_token}"
|
||||
}
|
||||
|
||||
# Construct the request body
|
||||
data = {
|
||||
"user_id": user_id,
|
||||
"content": {
|
||||
"msgtype": "m.text",
|
||||
"body": message
|
||||
}
|
||||
}
|
||||
|
||||
if event_type:
|
||||
data["type"] = event_type
|
||||
if state_key:
|
||||
data["state_key"] = state_key
|
||||
|
||||
# Send the request
|
||||
response = requests.put(url, headers=headers, json=data) if txnId else requests.post(url, headers=headers, json=data)
|
||||
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
print(f"Error sending server notice: {response.status_code}, {response.text}")
|
||||
return None
|
@@ -62,7 +62,7 @@ def deactivate_multiple_accounts():
|
||||
return
|
||||
#print(len(data[0]))
|
||||
#print(data[0][0])
|
||||
if delete_confirmation ["y", "Y", "yes", "Yes", "YES"]:
|
||||
if delete_confirmation in ["y", "Y", "yes", "Yes", "YES"]:
|
||||
x = 0
|
||||
while x <= (len(data) - 1):
|
||||
#print(data[0][x])
|
||||
|
Reference in New Issue
Block a user