Protocol, Port as variables, '-k' parameter for curl

This commit is contained in:
DecaTec 2023-03-02 23:15:29 +01:00
parent 61dbb6bffc
commit 1be1f75a21
8 changed files with 46 additions and 33 deletions

2
.gitignore vendored
View File

@ -77,4 +77,4 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
!.idea/
/.idea/

View File

@ -13,16 +13,18 @@
#
token=""
protocol="http"
port="8008"
if [ -z "$token" ]
then
read -p "Enter your access token: " token
read -pr "Enter your access token: " token
echo ""
fi
read -p "Enter the user which should be activated: (e.g. @test:matrix.mydomain.com): " user_to_activate
read -pr "Enter the user which should be activated: (e.g. @test:matrix.mydomain.com): " user_to_activate
echo ""
read -sp "Enter the new passwort for user: " new_password
read -spr "Enter the new passwort for user: " new_password
echo ""
# User lower case only
@ -31,10 +33,10 @@ user_to_activate="${user_to_activate,,}"
# Activate user
echo "Activate user $user_to_activate..."
echo ""
curlUrl="http://localhost:8008/_synapse/admin/v2/users/$user_to_activate?access_token=$token"
curlUrl="$protocol://localhost:$port/_synapse/admin/v2/users/$user_to_activate?access_token=$token"
echo $curlUrl
curl -X PUT $curlUrl -H 'Content-Type: application/json' -d '{"deactivated": false, "password":"'"$new_password"'"}'
echo "$curlUrl"
curl -k -X PUT "$curlUrl" -H 'Content-Type: application/json' -d '{"deactivated": false, "password":"'"$new_password"'"}'
echo ""
echo "Done"
echo ""

View File

@ -13,6 +13,8 @@
#
token=""
protocol="http"
port="8008"
if [ -z "$token" ]
then
@ -20,16 +22,16 @@ then
echo ""
fi
read -p "Enter the user whose password should be changed: (e.g. @test:matrix.mydomain.com): " user_to_change_password
read -pr "Enter the user whose password should be changed: (e.g. @test:matrix.mydomain.com): " user_to_change_password
echo ""
read -sp "Enter the NEW password: " new_password
read -spr "Enter the NEW password: " new_password
echo ""
read -sp "Confirm the new password: " new_password2
read -spr "Confirm the new password: " new_password2
echo ""
if [ $new_password != $new_password2 ]; then
if [ "$new_password" != "$new_password2" ]; then
echo "Error: The passwords do not match"
echo "The password was NOT changed"!
exit 1
@ -41,8 +43,8 @@ user_to_change_password="${user_to_change_password,,}"
# Change users's password
echo "Change password for user $user_to_change_password..."
echo ""
curlUrl="http://localhost:8008/_synapse/admin/v2/users/$user_to_change_password?access_token=$token"
curl -X PUT $curlUrl -H 'Content-Type: application/json' -d '{"password": "'"$new_password"'"}'
curlUrl="$protocol://localhost:$port/_synapse/admin/v2/users/$user_to_change_password?access_token=$token"
curl -k -X PUT "$curlUrl" -H 'Content-Type: application/json' -d '{"password": "'"$new_password"'"}'
echo ""
echo "Done"
echo ""

View File

@ -19,26 +19,28 @@
serverDomain=""
token=""
protocol="http"
port="8008"
# You may to customize this time span to fit your needs.
timestamp60DaysAgo=`date +%s000 --date "60 days ago"`
timestamp60DaysAgo=$(date +%s000 --date "60 days ago")
if [ -z "$serverDomain" ]
then
read -p "Enter the Matrix server domain: (e.g. matrix.mydomain.com): " serverDomain
read -pr "Enter the Matrix server domain: (e.g. matrix.mydomain.com): " serverDomain
echo ""
fi
if [ -z "$token" ]
then
read -p "Enter your access token: " token
read -pr "Enter your access token: " token
echo ""
fi
# Delete local media
echo "Delete local media..."
echo ""
curlUrl="http://localhost:8008/_synapse/admin/v1/media/$serverDomain/delete?before_ts=$timestamp60DaysAgo&access_token=$token"
curl -XPOST $curlUrl
curlUrl="$protocol://localhost:$port/_synapse/admin/v1/media/$serverDomain/delete?before_ts=$timestamp60DaysAgo&access_token=$token"
curl -k -X POST "$curlUrl"
echo ""
echo "Done"
echo ""
@ -46,8 +48,8 @@ echo ""
# Purge remote media
echo "Purge remote media..."
echo ""
curlUrl="http://localhost:8008/_synapse/admin/v1/purge_media_cache?before_ts=$timestamp60DaysAgo&access_token=$token"
curl -XPOST $curlUrl
curlUrl="$protocol://localhost:$port/_synapse/admin/v1/purge_media_cache?before_ts=$timestamp60DaysAgo&access_token=$token"
curl -k -X POST "$curlUrl"
echo ""
echo "Done"
echo ""

View File

@ -13,6 +13,8 @@
#
token=""
protocol="http"
port="8008"
if [ -z "$token" ]
then
@ -20,7 +22,7 @@ then
echo ""
fi
read -p "Enter the user which should be deactivated: (e.g. @test:matrix.mydomain.com): " user_to_deactivate
read -pr "Enter the user which should be deactivated: (e.g. @test:matrix.mydomain.com): " user_to_deactivate
echo ""
# User lower case only
@ -29,8 +31,8 @@ user_to_deactivate="${user_to_deactivate,,}"
# Deactivate user
echo "Deactivate user $user_to_deactivate..."
echo ""
curlUrl="http://localhost:8008/_synapse/admin/v1/deactivate/$user_to_deactivate?access_token=$token"
curl -X POST $curlUrl -H 'Content-Type: application/json' -d '{"erase": true}'
curlUrl="$protocol://localhost:$port/_synapse/admin/v1/deactivate/$user_to_deactivate?access_token=$token"
curl -k -X POST "$curlUrl" -H 'Content-Type: application/json' -d '{"erase": true}'
echo ""
echo "Done"
echo ""

View File

@ -23,7 +23,7 @@ echo ""
echo "Your access token:"
echo ""
echo $content
echo "$content"
echo ""
echo ""

View File

@ -13,20 +13,22 @@
#
token=""
protocol="http"
ort="8008"
if [ -z "$token" ]
then
read -p "Enter your access token: " token
read -pr "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)
curlUrl="$protocol://localhost:$port/_synapse/admin/v2/users?access_token=$token"
output=$(curl -k "$curlUrl")
echo ""
echo $output | python -m json.tool
echo "$output" | python -m json.tool
echo ""
echo "Done"
echo ""

View File

@ -6,7 +6,7 @@
# Requirements:
# - The script has to be executed on the same machine where Matrix Synapse is installed.
# - You 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 "advanced" (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 "<click to reveal>" to get your access token.
# Copy this token and paste it further down (variable "token").
@ -14,25 +14,28 @@
token=""
newRoomVersion=""
roomId=""
protocol="http"
port="8008"
if [ -z "$newRoomVersion" ]
then
read -p "Enter the new room version (e.g. 6): " newRoomVersion
read -pr "Enter the new room version (e.g. 6): " newRoomVersion
echo ""
fi
if [ -z "$token" ]
then
read -p "Enter your access token: " token
read -pr "Enter your access token: " token
echo ""
fi
# Delete local media
echo "Update room version of room $roomId..."
echo ""
curlUrl="http://localhost:8008/_matrix/client/r0/rooms/$roomId/upgrade?access_token=$token"
curl -X POST $curlUrl -H 'Content-Type: application/json' -d '{"new_version": "'"$newRoomVersion"'"}'
curlUrl="$protocol://localhost:$port/_matrix/client/r0/rooms/$roomId/upgrade?access_token=$token"
curl -k -X POST "$curlUrl" -H 'Content-Type: application/json' -d '{"new_version": "'"$newRoomVersion"'"}'
echo ""
echo "Done"
echo ""