synapse/madmin.sh
author Peter Gervai <grin@grin.hu>
Fri, 21 Jan 2022 10:22:39 +0100
changeset 4 721d4af9fdd7
child 6 85afc1496738
permissions -rwxr-xr-x
Add synapse/madmin.sh: simple program to call admin API with curl.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     1
#!/bin/bash
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     2
# $Id$
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     3
#(c)Peter Gervai, 2019-21
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     4
#
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     5
# A simple tool to query the admin API
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     6
#
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     7
# Require token.sh with a content:
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     8
#  export T="MDAxNWxvY2F0aW..."
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     9
#
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    10
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    11
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    12
. ./token.sh
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    13
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    14
U="https://matrix.example.mars:8448"
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    15
MODE="$1"
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    16
CMD="$2"
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    17
JSON="$3" || '{}'
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    18
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    19
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    20
if [ "x" = "x$CMD" ]; then
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    21
	echo "Usage: $0 <METHOD> <CMD> [<json>]"
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    22
	echo "Example: $0 GET /_matrix/client/r0/admin/whois/@grin:grin.hu"
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    23
	echo "Example: $0 GET /_synapse/admin/v1/reset_password/@example:grin.hu '{ \"new_password\": \"12345\" }'"
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    24
	echo "Example: $0 POST /_synapse/admin/v1/send_server_notice '{\"user_id\": \"@grin:matrix.org\", \"content\":{\"msgtype\":\"m.text\",\"body\": \"Hello from server!\"}}'"
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    25
	echo "         $0 POST /_synapse/admin/v1/deactivate/@spammer:grin.hu"
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    26
	exit
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    27
fi
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    28
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    29
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    30
#set -x
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    31
curl -d "$JSON" -X${MODE} "${U}${CMD}?access_token=$T"
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    32
#set +x
721d4af9fdd7 Add synapse/madmin.sh: simple program to call admin API with curl.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    33
echo ' '