Step to reset a users password

This commit is contained in:
2020-10-13 23:54:59 +02:00
parent a8838fa5da
commit ec93e655f3

View File

@@ -4,6 +4,7 @@ toolName=synapse
toolDeps="build-essential python3-dev libffi-dev python3-pip python3-setuptools postgresql libssl-dev virtualenv libjpeg-dev libxslt1-dev libpq5 libpq-dev" toolDeps="build-essential python3-dev libffi-dev python3-pip python3-setuptools postgresql libssl-dev virtualenv libjpeg-dev libxslt1-dev libpq5 libpq-dev"
toolUser="synapse" toolUser="synapse"
toolGroup="synapse" toolGroup="synapse"
synapseHashTool="env/bin/hash_password"
# Filled by configuration # Filled by configuration
toolConfig= toolConfig=
@@ -166,23 +167,54 @@ step_14() {
} }
step_16_info() { echo "Create new user"; } step_16_info() { echo "Create new user"; }
step_16_alias() { ALIAS="newuser"; } step_16_alias() { ALIAS="adduser"; }
step_16() { step_16() {
exe /opt/synapse/env/bin/register_new_matrix_user -c "$MATRIX_HOME/homeserver.yaml" $toolUrl exe /opt/synapse/env/bin/register_new_matrix_user -c "$MATRIX_HOME/homeserver.yaml" $toolUrl
} }
step_18_info() { echo "Drop postgres database for $toolName"; } step_18_info() {
step_18_alias() { ALIAS="dropdb"; } shift
echo -n "Reset user password"
if [ -z $1 ]; then
echo " [USER NAME]"
else
echo " for $1"
fi
}
step_18_alias() { ALIAS="resetpw"; }
step_18() { step_18() {
shift
local user=
if [ ! -z $1 ]; then
user="$1"
else
exe read -p "User name: " user
fi
if [ -z $user ]; then
echoerr "No user name provided"
return 1
fi
local pw="$("${MATRIX_HOME}/${synapseHashTool}")"
# Escaping twice because password contains $ which would be treated as variables
local string="\"UPDATE users SET password_hash=\''${pw}'\' WHERE name=\''@${user}:${MATRIX_DOMAIN}'\'\""
exep "echo \"$string\" | su postgres -c 'psql -d synapse -f -'"
}
step_30_info() { echo "Drop postgres database for $toolName"; }
step_30_alias() { ALIAS="dropdb"; }
step_30() {
readDatabaseInfos readDatabaseInfos
exe cd ~postgres exe cd ~postgres
exe su -c "psql -c \"DROP DATABASE ${postgresDb};\"" - postgres exe su -c "psql -c \"DROP DATABASE ${postgresDb};\"" - postgres
} }
step_20_info() { echo "Backup postgres database"; } step_32_info() { echo "Backup postgres database"; }
step_20_alias() { ALIAS="backupdb"; } step_32_alias() { ALIAS="backupdb"; }
step_20() { step_32() {
local DELYEAR=$(($(date +%Y)-2)) local DELYEAR=$(($(date +%Y)-2))
if [ ! -s ~/.pgpass ] ; then if [ ! -s ~/.pgpass ] ; then
echo " [I] For unattended backup please define ~/.pgpass containing credentials" echo " [I] For unattended backup please define ~/.pgpass containing credentials"
@@ -195,9 +227,9 @@ step_20() {
toolDbBackupFolder=/root/backupdb toolDbBackupFolder=/root/backupdb
step_22_info() { echo "Postgres database restore"; } step_34_info() { echo "Postgres database restore"; }
step_22_alias() { ALIAS="restoredb"; } step_34_alias() { ALIAS="restoredb"; }
step_22() { step_34() {
echo " [I] Postgres database restore procedure" echo " [I] Postgres database restore procedure"
echo "1. Create a empty postgres database first (step 4)" echo "1. Create a empty postgres database first (step 4)"
echo "2. psql -h <host> -U <database user> -d <database name> -W -f <sql dump file>" echo "2. psql -h <host> -U <database user> -d <database name> -W -f <sql dump file>"