synapse/madmin.sh
author Peter Gervai <grin@grin.hu>
Fri, 04 Mar 2022 11:01:00 +0100
changeset 9 c636ea2e8ee1
parent 6 85afc1496738
permissions -rwxr-xr-x
cmd.sh: I dislike shell escaping, and it doesn't like me either. (fix escaped ')

#!/bin/bash
# $Id: madmin.sh,v fc290d860b42 2022/01/24 09:19:54 grin $
#(c)Peter Gervai, 2019-21
#
# A simple tool to query the admin API
#
# Require token.sh with a content:
#  export T="MDAxNWxvY2F0aW..."
#

. ./_config.sh

MODE="$1"
CMD="$2"
JSON="$3" || '{}'


if [ "x" = "x$CMD" ]; then
	echo "Usage: $0 <METHOD> <CMD> [<json>]"
	echo "Example: $0 GET /_matrix/client/r0/admin/whois/@grin:grin.hu"
	echo "         $0 GET /_synapse/admin/v1/reset_password/@example:grin.hu '{ \"new_password\": \"12345\" }'"
	echo "         $0 POST /_synapse/admin/v1/send_server_notice '{\"user_id\": \"@grin:matrix.org\", \"content\":{\"msgtype\":\"m.text\",\"body\": \"Hello from server!\"}}'"
	echo "         $0 POST /_synapse/admin/v1/deactivate/@spammer:grin.hu"
	echo "         $0 DELETE '/_synapse/admin/v2/rooms/!YDqJPFEKtBIEGBHqZE:matrix.org' '{ \"block\": true, \"purge\": true }'"
	echo "         $0 GET '/_synapse/admin/v2/rooms/!YDqJPFEKtBIEGBHqZE:matrix.org/delete_status'  | jq"

	exit
fi


#set -x
curl -d "$JSON" -X${MODE} "${SRV}${CMD}?access_token=$T"
#set +x
echo ' '