-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdyra.sh
executable file
·333 lines (329 loc) · 9.05 KB
/
dyra.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#!/usr/bin/env bash
read -e -p "enter hostname: " -i "http://127.0.0.1:8008" host
echo $host
echo -n "enter access_token: "
read access_token
## host can be changed to different host ip/port (or FQDN, if api endpoint is exposed there)
# more api commands here https://matrix-org.github.io/synapse/latest/usage/administration/admin_api/index.html
submenu-users() {
echo -ne "
SUBMENU
1) list all users
2) list specific user
3) purge user media
4) admin/deadmin
5) set user email addresse (primary)
6) reset password/logout sessions
7) deactivate account (also mark erased) ## read https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#deactivate-account
8) re-activate account
b) back
e) exit
Choose an option: "
read -r ans
case $ans in
1)
while true; do
read -p "save output file? '(y/n)'" yn
case $yn in
[Yy]* ) curl --header "Authorization: Bearer ${access_token}" -XGET $host/_synapse/admin/v2/users | python3 -mjson.tool >> userlist.txt; echo output saved as ./userlist.txt; break;;
[Nn]* ) curl --header "Authorization: Bearer ${access_token}" -XGET $host/_synapse/admin/v2/users | python3 -mjson.tool; break;;
* ) echo "Please answer yes or no.";;
esac
done
submenu-users
;;
2)
echo user_id:
read userid
curl --header "Authorization: Bearer ${access_token}" -XGET $host/_synapse/admin/v2/users/$userid | python3 -mjson.tool
submenu-users
;;
3)
echo user id:
read user_id
curl --header "Authorization: Bearer ${access_token}" -XDELETE $host/_synapse/admin/v1/users/$user_id/media | python3 -mjson.tool
submenu-users
;;
4)
echo user id:
read user_id
while true; do
read -p "make admin? 'y/n'" yn
case $yn in
[Yy]* ) curl --header "Authorization: Bearer ${access_token}" -XPUT -d '{"admin": true}' $host/_synapse/admin/v1/users/$user_id/admin | python3 -mjson.tool; break;;
[Nn]* ) curl --header "Authorization: Bearer ${access_token}" -XPUT -d '{"admin": false}' $host/_synapse/admin/v1/users/$user_id/admin | python3 -mjson.tool; break;;
* ) echo "Please answer yes or no.";;
esac
done
submenu-users
;;
5)
echo user id:
read user_id
echo email addresse:
read email_id
curl --header "Authorization: Bearer ${access_token}" -XPUT -d '{"threepids": [{"medium": "email","address": "'$email_id'"}]}' $host/_synapse/admin/v2/users/$user_id | python3 -mjson.tool
submenu-users
;;
6)
echo user id:
read user_id
echo new password:
read new_pass
curl --header "Authorization: Bearer ${access_token}" -XPOST -d '{"new_password": "'$new_pass'", "logout_devices": true}' $host/_synapse/admin/v1/reset_password/$user_id | python3 -mjson.tool
submenu-users
;;
7)
echo user id:
read user_id
curl --header "Authorization: Bearer ${access_token}" -XPOST -d '{"erase": true }' $host/_synapse/admin/v1/deactivate/$user_id | python3 -mjson.tool
submenu-users
;;
8)
echo user id:
read user_id
echo new_password:
read new_pass
curl --header "Authorization: Bearer ${access_token}" -XPUT -d '{"deactivated": false, "password": "'$new_pass'"}' $host/_synapse/admin/v2/users/$user_id | python3 -mjson.tool
;;
b)
mainmenu
;;
e)
echo "have a nice day :-)"
exit 0
;;
*)
echo "Wrong option."
exit 1
;;
esac
}
submenu-rooms() {
echo -ne "
SUBMENU
1) list all rooms
2) list room details
3) purge room history
4) purge status
5) move/rename room
6) delete room
7) delete status
b) back
e) exit
Choose an option: "
read -r ans
case $ans in
1)
while true; do
read -p "save output file? 'y/n'" yn
case $yn in
[Yy]* ) curl --header "Authorization: Bearer ${access_token}" -XGET $host/_synapse/admin/v1/rooms?order_by=size | python3 -mjson.tool >> roomlist.txt; echo output saved as roomlist.txt; break;;
[Nn]* ) curl --header "Authorization: Bearer ${access_token}" -XGET $host/_synapse/admin/v1/rooms?order_by=size | python3 -mjson.tool; break;;
* ) echo "Please answer yes or no.";;
esac
done
submenu-rooms
;;
2)
echo room id:
read room_id
curl --header "Authorization: Bearer ${access_token}" -XGET $host/_synapse/admin/v1/rooms/$room_id | python3 -mjson.tool
submenu-rooms
;;
3)
echo room id:
read room_id
echo event id:
read event_id
curl --header "Authorization: Bearer ${access_token}" -XPOST -d '{"delete_local_events": true}' $host/_synapse/admin/v1/purge_history/\{$room_id}/\{$event_id} | python3 -mjson.tool
submenu-rooms
;;
4)
echo purge id:
read purge_id
curl --header "Authorization: Bearer ${access_token}" -X GET $host/_synapse/admin/v1/purge_history_status/{$purge_id} | python3 -mjson.tool
submenu-rooms
;;
5)
echo room id:
read room_id
echo new room owner:
read new_room_owner
echo new room name:
read new_room_name
curl --header "Authorization: Bearer ${access_token}" -XDELETE -d '{"new_room_user_id":"'"${new_room_owner}"'","room_name":"'"${new_room_name}"'", "block": true, "purge": true }' $host/_synapse/admin/v1/rooms/\{$room_id} | python3 -mjson.tool
submenu-rooms
;;
6)
echo room id:
read room_id
curl --header "Authorization: Bearer ${access_token}" -XDELETE -d '{"block": true, "purge": true}' $host/_synapse/admin/v2/rooms/\{$room_id} | python3 -mjson.tool
submenu-rooms
;;
7)
echo delete id:
read delete_id
curl --header "Authorization: Bearer ${access_token}" -X GET $host/_synapse/admin/v2/rooms/delete_status/{$delete_id} | python3 -mjson.tool
;;
b)
mainmenu
;;
e)
echo "have a nice day :-)"
exit 0
;;
*)
echo "Wrong option."
exit 1
;;
esac
}
submenu-tokens() {
echo -ne "
SUBMENU
1) get user access token
2) list all registration tokens
3) create new registration token
4) delete registration token
b) back
e) exit
Choose an option: "
read -r ans
case $ans in
1)
echo user id:
read user_id
echo password:
read user_pass
curl -XPOST -d '{"type":"m.login.password", "user":"'"${user_id}"'", "password":"'"${user_pass}"'"}' $host/_matrix/client/r0/login | python3 -mjson.tool
submenu-tokens
;;
2)
curl --header "Authorization: Bearer ${access_token}" -X GET $host/_synapse/admin/v1/registration_tokens | python3 -mjson.tool
submenu-tokens
;;
3)
curl --header "Authorization: Bearer ${access_token}" -X POST -H "Content-Type: application/json" -d {} $host/_synapse/admin/v1/registration_tokens/new | python3 -mjson.tool
submenu-tokens
;;
4)
echo token id:
read token_id
curl --header "Authorization: Bearer ${access_token}" -X DELETE $host/_synapse/admin/v1/registration_tokens/\{$token_id} | python3 -mjson.tool
submenu-tokens
;;
b)
mainmenu
;;
e)
echo "have a nice day :-)"
exit 0
;;
*)
echo "Wrong option."
exit 1
;;
esac
}
submenu-misc() {
echo -ne "
SUBMENU
1) server version
2) event reports
3) delete report
4) purge remote media
5) purge local media
6) redact event
b) back
e) exit
Choose an option: "
read -r ans
case $ans in
1)
curl -XGET $host/_synapse/admin/v1/server_version | python3 -mjson.tool
submenu-misc
;;
2)
curl --header "Authorization: Bearer ${access_token}" -XGET "$host/_synapse/admin/v1/event_reports?from=0&limit=10" | python3 -mjson.tool
submenu-misc
;;
3)
echo report id:
read report_id
curl --header "Authorization: Bearer ${access_token}" -X DELETE $host/_synapse/admin/v1/event_reports/\{$report_id} | python3 -mjson.tool
submenu-misc
;;
4)
echo epoch timestamp: '(see https://www.epochconverter.com)'
read epochms
curl --header "Authorization: Bearer ${access_token}" -XPOST $host/_synapse/admin/v1/purge_media_cache?before_ts=$epochms | python3 -mjson.tool
submenu-misc
;;
5)
echo server name:
read server_name
echo epoch timestamp: '(in milliseconds ,see https://www.epochconverter.com)'
read epochms
curl --header "Authorization: Bearer ${access_token}" -XPOST $host/_synapse/admin/v1/media/$server_name/delete?before_ts=$epochms | python3 -mjson.tool
submenu-misc
;;
6)
echo room id:
read room_id
echo event id:
read event_id
curl --header "Authorization: Bearer ${access_token}" -XPUT -d '{"reason": "spamming"}' $host/_matrix/client/v3/rooms/${room_id}/redact/$event_id/{$RANDOM} | python3 -mjson.tool
submenu-misc
;;
b)
mainmenu
;;
e)
echo "have a nice day :-)"
exit 0
;;
*)
echo "Wrong option."
exit 1
;;
esac
}
mainmenu() {
echo -ne "
MAIN MENU
1) users
2) rooms
3) tokens
4) misc
e) exit
Choose an option: "
read -r ans
case $ans in
1)
submenu-users
mainmenu
;;
2)
submenu-rooms
mainmenu
;;
3)
submenu-tokens
mainmenu
;;
4)
submenu-misc
mainmenu
;;
e)
echo "have a nice day :-)"
exit 0
;;
*)
echo "Wrong option."
exit 1
;;
esac
}
mainmenu