bundles/matrix-synapse: add scripts/synapse-purge-unused-rooms
All checks were successful
bundlewrap/pipeline/head This commit looks good
All checks were successful
bundlewrap/pipeline/head This commit looks good
This commit is contained in:
parent
b06532241b
commit
8ac9b2f204
2 changed files with 67 additions and 0 deletions
64
bundles/matrix-synapse/files/synapse-purge-unused-rooms
Normal file
64
bundles/matrix-synapse/files/synapse-purge-unused-rooms
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from os import environ
|
||||||
|
from requests import get, post
|
||||||
|
from sys import argv, exit
|
||||||
|
|
||||||
|
|
||||||
|
SYNAPSE_MAX_ROOMS_TO_GET = 20000
|
||||||
|
SYNAPSE_HOST = 'http://[::1]:20080/'
|
||||||
|
|
||||||
|
if 'MATRIX_AUTH_TOKEN' in environ:
|
||||||
|
SYNAPSE_AUTH_TOKEN = environ['MATRIX_AUTH_TOKEN']
|
||||||
|
else:
|
||||||
|
print('Usage: MATRIX_AUTH_TOKEN=\'your_token_here\' {}'.format(argv[0]))
|
||||||
|
exit(255)
|
||||||
|
|
||||||
|
json = get(
|
||||||
|
SYNAPSE_HOST + '_synapse/admin/v1/rooms?limit={}'.format(SYNAPSE_MAX_ROOMS_TO_GET),
|
||||||
|
headers={
|
||||||
|
'Authorization': 'Bearer {}'.format(SYNAPSE_AUTH_TOKEN),
|
||||||
|
},
|
||||||
|
).json()
|
||||||
|
|
||||||
|
if 'rooms' not in json:
|
||||||
|
print(json)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
print('Found a total of {} rooms on {}'.format(len(json['rooms']), SYNAPSE_HOST))
|
||||||
|
print()
|
||||||
|
|
||||||
|
for room in json['rooms']:
|
||||||
|
print(
|
||||||
|
'Checking {} ({}) ... '.format(
|
||||||
|
room['room_id'],
|
||||||
|
room['canonical_alias'],
|
||||||
|
),
|
||||||
|
end='',
|
||||||
|
)
|
||||||
|
|
||||||
|
if room['joined_local_members'] > 0:
|
||||||
|
print('room has local members!')
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
print('no local members')
|
||||||
|
|
||||||
|
print('Room info:')
|
||||||
|
print(' Name: {}'.format(room['name']))
|
||||||
|
print(' Members: {}'.format(room['joined_members']))
|
||||||
|
print(' Creator: {}'.format(room['creator']))
|
||||||
|
|
||||||
|
if input('Do you wish to remove this room? [yN]') in ['y', 'Y']:
|
||||||
|
print(post(
|
||||||
|
SYNAPSE_HOST + '_synapse/admin/v1/rooms/{}/delete'.format(room['room_id']),
|
||||||
|
headers={
|
||||||
|
'Authorization': 'Bearer {}'.format(SYNAPSE_AUTH_TOKEN),
|
||||||
|
},
|
||||||
|
json={
|
||||||
|
'purge': True,
|
||||||
|
},
|
||||||
|
).json())
|
||||||
|
else:
|
||||||
|
print('Declined.')
|
||||||
|
|
||||||
|
print()
|
|
@ -9,6 +9,9 @@ files = {
|
||||||
'svc_systemd:matrix-synapse:restart',
|
'svc_systemd:matrix-synapse:restart',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'/etc/matrix-synapse/scripts/synapse-purge-unused-rooms': {
|
||||||
|
'mode': '0755',
|
||||||
|
},
|
||||||
'/etc/systemd/system/matrix-synapse.service.d/override.conf': {
|
'/etc/systemd/system/matrix-synapse.service.d/override.conf': {
|
||||||
'needs': {
|
'needs': {
|
||||||
'pkg_apt:matrix-synapse-py3',
|
'pkg_apt:matrix-synapse-py3',
|
||||||
|
|
Loading…
Reference in a new issue