Browse Source

add matrix password reset script

Cullum Smith 2 years ago
parent
commit
77c644c481
1 changed files with 37 additions and 0 deletions
  1. 37
    0
      scripts/reset_matrix_password.sh

+ 37
- 0
scripts/reset_matrix_password.sh View File

@@ -0,0 +1,37 @@
1
+#!/bin/ksh
2
+
3
+set -eu
4
+
5
+DOMAIN=$(hostname | cut -d. -f2-)
6
+
7
+die() {
8
+  >&2 echo "$@"
9
+  exit 1
10
+}
11
+
12
+[ $# -lt 1 ] && die "usage: $0 USERNAME [EMAIL]"
13
+
14
+USERNAME=$1
15
+PASSWORD=$(pwgen 32 1)
16
+EMAIL=${2:-}
17
+
18
+cd /tmp
19
+
20
+HASH=$(doas -u _synapse /bin/ksh -c ". /usr/local/share/synapse/bin/activate && hash_password -p '$PASSWORD'")
21
+
22
+doas -u _synapse psql synapse -c "UPDATE users SET password_hash='$HASH' WHERE name='@$USERNAME:$DOMAIN'"
23
+
24
+if [ -n "$EMAIL" ] ; then
25
+  mail -s "Your $DOMAIN Matrix password has been reset" -r "matrix-noreply@$DOMAIN" "$EMAIL" << EOF
26
+Your Matrix account password for $DOMAIN has been reset.
27
+
28
+username: @$USERNAME:$DOMAIN
29
+password: $PASSWORD
30
+
31
+CHANGE YOUR PASSWORD IN THE SETTINGS PANEL IMMEDIATELY AFTER YOUR FIRST LOGIN!
32
+EOF
33
+
34
+  echo "password for $USERNAME reset. email sent to $EMAIL"
35
+else
36
+  echo "password for $USERNAME reset: $PASSWORD"
37
+fi

Loading…
Cancel
Save