Procházet zdrojové kódy

Script to remove users from matrix

Bob Mottram před 7 roky
rodič
revize
ace9d9c5f9
1 změnil soubory, kde provedl 17 přidání a 1 odebrání
  1. 17
    1
      src/freedombone-app-matrix

+ 17
- 1
src/freedombone-app-matrix Zobrazit soubor

@@ -334,7 +334,23 @@ function remove_user_matrix {
334 334
 
335 335
     ${PROJECT_NAME}-pass -u $remove_username --rmapp matrix
336 336
 
337
-    # TODO: There is no user removal script within synapse
337
+    read_config_param MY_USERNAME
338
+    read_config_param MATRIX_DOMAIN_NAME
339
+
340
+    matrix_remove_user=/usr/bin/matrix-remove-user
341
+    echo '#!/bin/bash' > $matrix_remove_user
342
+    echo "cd $MATRIX_DATA_DIR" >> $matrix_remove_user
343
+    echo 'remove_username=$1' >> $matrix_remove_user
344
+    echo "ADMIN=\"@${MY_USERNAME}:$MATRIX_DOMAIN_NAME\"" >> $matrix_remove_user
345
+    echo 'BUSY="pragma busy_timeout=20000"' >> $matrix_remove_user
346
+    echo "BUFFER=\$(sqlite3 homeserver.db \"\$BUSY;select token from access_tokens where user_id like '\$ADMIN' order by id desc limit 1;\")" >> $matrix_remove_user
347
+    echo "TOKEN=\$(echo \$BUFFER|awk '{print \$2}')" >> $matrix_remove_user
348
+    echo 'set -x' >> $matrix_remove_user
349
+    echo "curl -X POST 'https://$MATRIX_DOMAIN_NAME/_matrix/client/r0/admin/deactivate/%40\$remove_username%3A$MATRIX_DOMAIN_NAME?access_token=\$TOKEN' --data '{}'" >> $matrix_remove_user
350
+
351
+    chmod +x $matrix_remove_user
352
+
353
+    $matrix_remove_user "$remove_username"
338 354
 }
339 355
 
340 356
 function add_user_matrix {