diff --git a/ActivateUser.sh b/ActivateUser.sh index 07af5c4..8d145e3 100644 --- a/ActivateUser.sh +++ b/ActivateUser.sh @@ -5,22 +5,14 @@ # # 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 "" 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 @@ -32,6 +24,9 @@ echo "" read -sp "Enter the new passwort for user: " new_password echo "" +# User lower case only +user_to_activate="${user_to_activate,,}" + # Activate user echo "Activate user $user_to_activate..." echo "" diff --git a/ChangeUserPassword.sh b/ChangeUserPassword.sh new file mode 100644 index 0000000..0ae152d --- /dev/null +++ b/ChangeUserPassword.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# +# Changes a password for a user +# + +# 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"). +# - The user (@username:mydomain.com) whose password should be changed +# + +token="" + +if [ -z "$token" ] +then + read -p "Enter your access token: " token + echo "" +fi + +read -p "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 +echo "" + +read -sp "Confirm the new password: " new_password2 +echo "" + +if [ $new_password != $new_password2 ]; then + echo "Error: The passwords do not match" + echo "The password was NOT changed"! + exit 1 +fi + +# User lower case only +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"'"}' +echo "" +echo "Done" +echo "" \ No newline at end of file diff --git a/DeactivateUser.sh b/DeactivateUser.sh index 62c2236..400fadb 100644 --- a/DeactivateUser.sh +++ b/DeactivateUser.sh @@ -6,21 +6,13 @@ # 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 "" 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 @@ -30,6 +22,9 @@ fi read -p "Enter the user which should be deactivated: (e.g. @test:matrix.mydomain.com): " user_to_deactivate echo "" +# User lower case only +user_to_deactivate="${user_to_deactivate,,}" + # Deactivate user echo "Deactivate user $user_to_deactivate..." echo "" diff --git a/GetAllUsers.sh b/GetAllUsers.sh index 40eaa1e..50d2e1b 100644 --- a/GetAllUsers.sh +++ b/GetAllUsers.sh @@ -5,22 +5,14 @@ # # 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 diff --git a/README.md b/README.md index ada065c..cd79bf9 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ 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. +* `ChangeUserPassword.sh`: Changes the password of the given user. * `CleanupMedia.sh`: Deletes old local and remote media. * `DeactivateUser.sh`: Deactivates the given user. * `GetAccessToken.sh`: Gets the access token with curl.