mirror of
https://github.com/PC-Admin/matrix-moderation-tool.git
synced 2024-12-19 23:20:26 -05:00
84 lines
2.9 KiB
Markdown
84 lines
2.9 KiB
Markdown
|
|
# Server Commands Guide
|
|
|
|
This guide provides detailed steps for server-side operations that use the database and SSH. The commands and scripts are essential for handling specific server operations related to Matrix's Synapse server.
|
|
|
|
## Table of Contents
|
|
|
|
- [1. Delete and Block Specific Media](#1-delete-and-block-specific-media)
|
|
- [2. Purge Remote Media Repository](#2-purge-remote-media-repository)
|
|
- [3. Prepare Database for Copying Events of Multiple Rooms](#3-prepare-database-for-copying-events-of-multiple-rooms)
|
|
|
|
---
|
|
|
|
### 1. 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.
|
|
|
|
#### Process Flow:
|
|
|
|
1. Take `media_id` and remote server URL from the user.
|
|
2. Use SSH to query the Synapse PostgreSQL database for the associated `filesystem_id`.
|
|
3. Locate the target media files and thumbnails on the server's file system.
|
|
4. Zero out (empty) each file and make them immutable, meaning they cannot be modified or deleted.
|
|
|
|
#### Example:
|
|
|
|
For a media with ID `eDmjusOjnHyFPOYGxlrOsULJ`, the process would involve:
|
|
|
|
```bash
|
|
$ ssh matrix.perthchat.org "... SQL query to get filesystem_id..."
|
|
$ ssh matrix.perthchat.org "... command to locate files ..."
|
|
$ ssh matrix.perthchat.org "true > ...path to file..."
|
|
$ ssh matrix.perthchat.org "chattr +i ...path to file..."
|
|
```
|
|
|
|
### 2. Purge Remote Media Repository
|
|
|
|
This command purges the remote media repository for a certain range of days.
|
|
Process Flow:
|
|
|
|
Ask the user for the range of days to purge.
|
|
Calculate the epoch timestamp for each day in the range.
|
|
Send a request to the Synapse server to purge media for that day.
|
|
Repeat for each day in the range.
|
|
|
|
Example:
|
|
```bash
|
|
$ 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
|
|
|
|
This command prepares the PostgreSQL database to export events from multiple Matrix rooms.
|
|
Process Flow:
|
|
|
|
Prompt for a list of room IDs.
|
|
Create a RAM disk on the server to store the export.
|
|
For each room ID:
|
|
Create a SQL query to extract room events.
|
|
Write the query to a file on the RAM disk.
|
|
Provide instructions for running the queries in the PostgreSQL container.
|
|
|
|
Notes:
|
|
|
|
This function is compatible with Spantaleev's Matrix deploy script.
|
|
Ensure proper permissions and consider the impact on the server when copying a large amount of data.
|
|
|
|
Example:
|
|
```bash
|
|
# As the root user on the target server:
|
|
$ mkdir /matrix/postgres/data/ramdisk
|
|
$ ... commands to set up RAM disk ...
|
|
$ ... commands to generate SQL queries for each room ...
|
|
$ docker exec -it matrix-postgres /bin/bash
|
|
bash-5.0$ ... commands to execute SQL queries ...
|
|
```
|
|
|
|
After copying the data, ensure to clean up the RAM disk:
|
|
|
|
```bash
|
|
$ rm -r /matrix/postgres/data/ramdisk/*
|
|
$ umount /matrix/postgres/data/ramdisk
|
|
``` |