-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin-tools-v3.sh
executable file
·107 lines (79 loc) · 2.59 KB
/
admin-tools-v3.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
#Set these vars manually.
realm="matrix.local"
domain="https://matrix.local"
registration_secret="get it in config"
admin_user="someuser"
admin_pass="somepasswd"
#End vars section
function GetAccessToken() {
curl -s \
--request POST \
--header 'Content-Type: application/json' \
--data '{
"type": "m.login.password",
"identifier": {
"type": "m.id.user",
"user": "'$admin_user'"
},
"password": "'$admin_pass'"
}' \
${domain}/_matrix/client/r0/login |
jq -r ".access_token"
}
echo "Getting access token..."
access_token="$(GetAccessToken)"
if [[ $access_token == "null" ]]
then
echo "Can't get access token. Exiting." && exit 1 || return 1
fi
#Start menu
while [ "$done" != "true" ]
do
#Choose option
echo -e "\n\n\n\n\nWhat do you want to do?\n[1] – Deactivate user\n[2] – Delete Group\n[3] – Change user password\n[4] – Register new user\n[5] – Exit ";
read option
case "$option" in
"1")
#Deactivate user no delete
echo -e "Enter user you'd like to deactivate\n";
read user
curl -XPOST -s -H "Authorization: Bearer $access_token" "$domain/_synapse/admin/v1/deactivate/@$user:$realm" | jq
;;
"2")
#Remove group
echo -e "Enter Group ID you'd like to delete\n";
read user
curl -XPOST -s -H "Authorization: Bearer $access_token" "$domain/_synapse/admin/v1/delete_group/@$user:$realm" | jq
;;
"3")
#Reset user pass / Reactivate user
echo -e "Enter user you'd like to change password\n";
read user
echo -e "Enter new passs";
read pass
# curl -XPOST -H "Authorization: Bearer $access_token" -H "Content-Type: application/json" -d \
# '{"new_password":"'$pass'"}' "$domain/_synapse/admin/v1/reset_password/@$user:$realm"
curl --insecure -XPUT -s -H "Authorization: Bearer $access_token" -H "Content-Type: application/json" -d \
'{"password":"'$pass'","deactivated": false}' "$domain/_synapse/admin/v2/users/@$user:$realm" | jq
;;
"4")
python3 $(dirname "$0")/register_new_matrix_user.py -k $registration_secret $domain
;;
#Register new user
#Exit
"5") exit 1 || return 1;;
#Default
*) echo -e "Incorrect choise. \n"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
;;
esac
#Return to menu
read -p "Choose next operation? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
done
exit 0