From 8e991853358c344080565fe5c174a7cad8c7b906 Mon Sep 17 00:00:00 2001 From: MeaTLoTioN Date: Wed, 27 Apr 2022 09:51:00 +0100 Subject: [PATCH] initial commit --- auth | 3 +++ check_user | 24 ++++++++++++++++++++++++ deactivate_user | 29 +++++++++++++++++++++++++++++ delete_room | 24 ++++++++++++++++++++++++ edit_auth | 2 ++ list_rooms | 35 +++++++++++++++++++++++++++++++++++ reactivate_user | 28 ++++++++++++++++++++++++++++ 7 files changed, 145 insertions(+) create mode 100755 auth create mode 100755 check_user create mode 100755 deactivate_user create mode 100755 delete_room create mode 100755 edit_auth create mode 100755 list_rooms create mode 100755 reactivate_user diff --git a/auth b/auth new file mode 100755 index 0000000..646b5ab --- /dev/null +++ b/auth @@ -0,0 +1,3 @@ +#!/bin/bash + +TOKEN="your_extremely_long_and_secure_token_goes_here" diff --git a/check_user b/check_user new file mode 100755 index 0000000..a85ab3f --- /dev/null +++ b/check_user @@ -0,0 +1,24 @@ +#!/bin/bash + +usage() { + echo "Not enough arguments supplied." + echo "Syntax: $(basename $0) {username}" + echo +} + +if [[ $# -lt 1 ]]; then + usage + exit 1 +fi + +. $(dirname $0)/auth + +USER=$1 + +curl -s --insecure -X GET \ + -H "Authorization: Bearer $TOKEN" \ + -H "Content-Type: application/json" \ + -d '{}' "http://localhost:8008/_synapse/admin/v2/users/@$USER:matrix.erb.pw" | \ + sed 's/,/,\n /g; s/{/{\n /g; s/}/\n}/g' + +echo diff --git a/deactivate_user b/deactivate_user new file mode 100755 index 0000000..fe04a04 --- /dev/null +++ b/deactivate_user @@ -0,0 +1,29 @@ +#!/bin/bash + +usage() { + echo "Not enough arguments supplied." + echo + echo "Syntax: $(basename $0) {username} {new name}" + echo "Example:" + echo " $(basename $0) ktulu dis-Ktulu-dis" +} + +if [[ $# -lt 2 ]]; then + usage + exit 1 +fi + +. $(dirname $0)/auth + +USER=$1 +NEWNAME=$2 +NEWPASS="$(apg -MNC -m64 -n1)" + +curl -s --insecure -X PUT \ + -H "Authorization: Bearer $TOKEN" \ + -H "Content-Type: application/json" \ + --data '{"deactivated": true, "displayname":"'$NEWNAME'", "password":"'$NEWPASS'"}' \ + "http://localhost:8008/_synapse/admin/v2/users/@$USER:matrix.erb.pw" | \ + sed 's/,/,\n /g; s/{/{\n /g; s/}/\n}/g' + +echo diff --git a/delete_room b/delete_room new file mode 100755 index 0000000..65aa624 --- /dev/null +++ b/delete_room @@ -0,0 +1,24 @@ +#!/bin/bash + +usage() { + echo "Not enough arguments supplied." + echo "Syntax: $(basename $0) {roomid}" + echo +} + +if [[ $# -lt 1 ]]; then + usage + exit 1 +fi + +. $(dirname $0)/auth + +ROOM=$1 + +curl -s --insecure -X DELETE \ + -H "Authorization: Bearer $TOKEN" \ + -H "Content-Type: application/json" \ + -d '{"block":true, "purge":true, "force_purge":true}' "http://localhost:8008/_synapse/admin/v1/rooms/$ROOM" | \ + sed 's/,/,\n /g; s/{/{\n /g; s/}/\n}/g' + +echo diff --git a/edit_auth b/edit_auth new file mode 100755 index 0000000..95b4661 --- /dev/null +++ b/edit_auth @@ -0,0 +1,2 @@ +#!/bin/sh +vim /root/api_calls/auth diff --git a/list_rooms b/list_rooms new file mode 100755 index 0000000..43e9735 --- /dev/null +++ b/list_rooms @@ -0,0 +1,35 @@ +#!/bin/bash + +usage() { + echo "Not enough arguments supplied." + echo "Syntax: $(basename $0) {roomname||all}" + echo +} + +if [[ $# -lt 1 ]]; then + usage + exit 1 +fi + +. $(dirname $0)/auth + +ROOM=$1 + +if [[ "${ROOM^^}" == "ALL" ]]; then + # show all rooms + curl -s --insecure -X GET \ + -H "Authorization: Bearer $TOKEN" \ + -H "Content-Type: application/json" \ + -d '{}' "http://localhost:8008/_synapse/admin/v1/rooms" | \ + sed 's/,/,\n /g; s/{/{\n /g; s/}/\n}/g' +else + # filter by room name + curl -s --insecure -X GET \ + -H "Authorization: Bearer $TOKEN" \ + -H "Content-Type: application/json" \ + -d '{}' "http://localhost:8008/_synapse/admin/v1/rooms?search_term=$ROOM" | \ + sed 's/,/,\n /g; s/{/{\n /g; s/}/\n}/g' +fi + + +echo diff --git a/reactivate_user b/reactivate_user new file mode 100755 index 0000000..d512c6a --- /dev/null +++ b/reactivate_user @@ -0,0 +1,28 @@ +#!/bin/bash + +usage() { + echo "Not enough arguments supplied." + echo "Syntax: $(basename $0) {username} {new name} {new password} {isadmin 0=no 1=yes}" + echo +} + +if [[ $# -lt 4 ]]; then + usage + exit 1 +fi + +. $(dirname $0)/auth + +USER=$1 +NEWNAME=$2 +NEWPASS=$3 +ISADMIN=$4 + +curl -s --insecure -X PUT \ + -H "Authorization: Bearer $TOKEN" \ + -H "Content-Type: application/json" \ + --data '{"deactivated": false, "admin":'$ISADMIN', "displayname":"'$NEWNAME'", "password":"'$NEWPASS'"}' \ + "http://localhost:8008/_synapse/admin/v2/users/@$USER:matrix.erb.pw" | \ + sed 's/,/,\n /g; s/{/{\n /g; s/}/\n}/g' + +echo