New scripts, obtaining required information in a more convenient manner

This commit is contained in:
DecaTec 2021-10-06 12:30:15 +02:00
parent 647a406598
commit 9788b97524
2 changed files with 84 additions and 0 deletions

44
ActivateUser.sh Normal file
View File

@ -0,0 +1,44 @@
#!/bin/bash
#
# Activates a user
#
# Requirements:
# - You'll need the domain of your server (variable "serverDomain").
# - A new password for the user must be specified.
# - 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").
#
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
read -p "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
echo ""
# Activate user
echo "Activate user $user_to_activate..."
echo ""
curlUrl="http://localhost:8008/_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 ""
echo "Done"
echo ""

40
DeactivateUser.sh Normal file
View File

@ -0,0 +1,40 @@
#!/bin/bash
#
# Deactivates a user
#
# IMPORTANT: You cannot delete a user from a Matrix server, a user can just get deactivated.
# 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 "<click to reveal>" 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
read -p "Enter the user which should be deactivated: (e.g. @test:matrix.mydomain.com): " user_to_deactivate
echo ""
# 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}'
echo ""
echo "Done"
echo ""