From 36b668d23ad0871b1b52246234a891bd1265a2ef Mon Sep 17 00:00:00 2001 From: DecaTec Date: Wed, 6 Oct 2021 12:31:32 +0200 Subject: [PATCH] New scripts, obtaining required information in a more convenient manner --- CleanupMedia.sh | 26 +++++++++++++++++++------- ListAllUsers.sh | 39 +++++++++++++++++++++++++++++++++++++++ README.md | 8 +++++++- UpdateRoomVersion.sh | 35 ++++++++++++++++++++++++++--------- 4 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 ListAllUsers.sh diff --git a/CleanupMedia.sh b/CleanupMedia.sh index ca061bd..8eec193 100644 --- a/CleanupMedia.sh +++ b/CleanupMedia.sh @@ -5,11 +5,10 @@ # # Requirements: -# You'll need the domain of your server (variable "serverDomain"). -# -# For authentication, you will need the access token of your (admin) account. -# You can obtain it in your Element client: "All settings" > "Help & About" > scroll down > click on "" to get your access token. -# Copy this token and paste it further down (variable "token"). +# - You'll need the domain of your server (variable "serverDomain"). +# - For authentication, you will need the access token of your (admin) account. +# You can obtain it in your Element client: "All settings" > "Help & About" > scroll down > click on "" to get your access token. +# Copy this token and paste it further down (variable "token"). # # You can also specify another time span for deleting media. # Default is media, which was not accessed over the last 60 days (variable "timestamp60DaysAgo") @@ -17,10 +16,23 @@ # You can automate this script via cron, e.g. cleanup every night: # 0 1 * * * /path/to/scripts/Matrix-Synapse-Helpers/CleanupMedia.sh > /dev/null 2>&1 -serverDomain="matrix.mydomain.com" -token="insert-token-here" +serverDomain="" +token="" +# You may to customize this time span to fit your needs. timestamp60DaysAgo=`date +%s000 --date "60 days ago"` +if [ -z "$serverDomain" ] +then + read -p "Enter the Matrix server domain: (e.g. matrix.mydomain.com): " serverDomain + echo "" +fi + +if [ -z "$token" ] +then + read -p "Enter your access token: " token + echo "" +fi + # Delete local media echo "Delete local media..." echo "" diff --git a/ListAllUsers.sh b/ListAllUsers.sh new file mode 100644 index 0000000..40eaa1e --- /dev/null +++ b/ListAllUsers.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# +# Lists all users of the given instance. +# + +# Requirements: +# - You'll need the domain of your server (variable "serverDomain"). +# - Python 2.6+ has to be installed on the system. +# - For authentication, you will need the access token of your (admin) account. +# You can obtain it in your Element client: "All settings" > "Help & About" > scroll down > click on "" to get your access token. +# Copy this token and paste it further down (variable "token"). +# + +serverDomain="" +token="" + +if [ -z "$serverDomain" ] +then + read -p "Enter the Matrix server domain: (e.g. matrix.mydomain.com): " serverDomain + echo "" +fi + +if [ -z "$token" ] +then + read -p "Enter your access token: " token + echo "" +fi + +# List users +echo "Retrieving users..." +echo "" +curlUrl="http://localhost:8008/_synapse/admin/v2/users?access_token=$token" +output=$(curl $curlUrl) +echo "" +echo $output | python -m json.tool +echo "" +echo "Done" +echo "" \ No newline at end of file diff --git a/README.md b/README.md index 17a31a3..f7163c9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ # Helper scripts for Matrix Synapse +Some useful scripts utilizing the API of Matrix Synapse in order to manage different tasks: + +* `ActivateUser.sh`: Activates the given user and assigns a new password. +* `CleanupMedia.sh`: Deletes old local and remote media. +* `DeactivateUser.sh`: Deactivates the given user. * `GetAccessToken.sh`: Gets the access token with curl. -* `CleanupMedia.sh`: Deletes old local and remote media. \ No newline at end of file +* `ListAllUsers.sh`: Lists all users. +* `UpdateRoomVersion.sh`: Updates a room to the given room version. \ No newline at end of file diff --git a/UpdateRoomVersion.sh b/UpdateRoomVersion.sh index 91f5479..cfcc0f3 100644 --- a/UpdateRoomVersion.sh +++ b/UpdateRoomVersion.sh @@ -5,17 +5,34 @@ # # Requirements: -# -# For authentication, you will need the access token of your (admin) account. -# You can obtain it in your Element client: "All settings" > "Help & About" > scroll down > click on "" to get your access token. -# Copy this token and paste it further down (variable "token"). -# -# You also need the room ID of the room to update. You can find it in the room's settings under "acvanced" (internal room ID). +# - You need the room ID of the room to update. You can find it in the room's settings under "acvanced" (internal room ID). +# - For authentication, you will need the access token of your (admin) account. +# You can obtain it in your Element client: "All settings" > "Help & About" > scroll down > click on "" to get your access token. +# Copy this token and paste it further down (variable "token"). # -token="insert-token-here" -roomId='insert-room-id-here' -newRoomVersion="insert-new-room-version-here" +serverDomain="" +token="" +newRoomVersion="" + +if [ -z "$serverDomain" ] +then + read -p "Enter the Matrix server domain: (e.g. matrix.mydomain.com): " serverDomain + echo "" +fi + +if [ -z "$newRoomVersion" ] +then + read -p "Enter the new room version (e.g. 6): " newRoomVersion + echo "" +fi + + +if [ -z "$token" ] +then + read -p "Enter your access token: " token + echo "" +fi # Delete local media echo "Update room version of room $roomId..."