add shadow ban function. ask if admin wants to shadow ban users before mass rdlist shutdowns. move example room/user lists into seperate folder.

This commit is contained in:
PC-Admin 2023-07-28 10:36:58 +08:00
parent 115caceaf7
commit 81739a456d
7 changed files with 32 additions and 2 deletions

View File

@ -54,10 +54,10 @@ while pass_token == False:
print("17) Set rate limit of a user account.\t\t66) Purge the event history of multiple rooms to a specific timestamp.")
print("18) Delete rate limit of a user account.\t67) Get blocked status for room.")
print("19) Check if user account exists.\t\t68) Block a room.")
print("\t\t\t\t\t\t69) Unblock a room.")
print("20) Shadow ban a user.\t\t\t\t69) Unblock a room.")
print("\n#### Server Commands ####\t\t\t\t\t#### Report Generation ####")
print("100) Delete and block a specific media.\t\t\t\t150) Generate user report.")
print("101) Purge remote media repository up to a certain date.\t\t151) Decrypt user report .zip file.")
print("101) Purge remote media repository up to a certain date.\t151) Decrypt user report .zip file.")
print("102) Prepare database for copying events of multiple rooms.\t152) Lookup homeserver admin contact email.")
print("\t\t\t\t\t\t\t\t153) Send a test email.")
print("#### rdlist ####\t\t\t\t\t\t154) Send test incident reports to yourself.")
@ -116,6 +116,9 @@ while pass_token == False:
print("\nUser account exists.\n")
elif user_account_exists == False:
print("\nUser account does not exist.\n")
elif menu_input == "20":
shadow_ban_dict = user_commands.shadow_ban_account('')
print(json.dumps(shadow_ban_dict, indent=4, sort_keys=True))
elif menu_input == "50":
room_details_dict = room_commands.get_room_details('')
print(json.dumps(room_details_dict, indent=4, sort_keys=True))

View File

@ -238,6 +238,13 @@ def block_all_rooms_with_rdlist_tags(rdlist_use_recommended,preset_user_ID,prese
num_rooms_purged = 0
if shutdown_confirmation.lower() in ['y', 'yes', 'Y', 'Yes']:
# Ask the user if they wish to shadow ban all local users in these rooms
shadow_ban_confirmation = input("\nDo you want to also shadow ban all your local users in these rooms before performing these shutdowns? (This is recommended as it prevents them from alerting others about these mass shutdown.) y/n? ")
# Perform shadow bans if admin confirms
if shadow_ban_confirmation in ['y', 'yes', 'Y', 'Yes']:
for user in all_local_users:
print(f"\nShadow banning user: {user}")
user_commands.shadow_ban_account(user)
for room_id in all_room_ids:
blocked_status = room_commands.get_block_status(room_id)
#print(f"\nroom_details_dict: {room_details_dict}")

View File

@ -505,3 +505,23 @@ def check_user_account_exists(preset_username):
# Example:
# $ curl -X GET /_synapse/admin/v1/username_available?username=dogpoo&access_token=ACCESS_TOKEN
def shadow_ban_account(preset_username):
if preset_username == '':
username = input("\nPlease enter the username you wish to shadow ban: ")
elif preset_username != '':
username = preset_username
username = parse_username(username)
url = f"https://{hardcoded_variables.homeserver_url}/_synapse/admin/v1/users/@{username}:{hardcoded_variables.base_url}/shadow_ban"
url += f"?access_token={hardcoded_variables.access_token}"
response = requests.post(url, verify=True)
if response.status_code != 200:
print(f"Error shadow banning account: {response.status_code}, {response.text}\n")
return json.loads(response.text)
# Example:
# curl -XPOST -H "Content-Type: application/json" 'https://matrix.perthchat.org/_synapse/admin/v1/users/@dogpoo:perthchat.org/shadow_ban?access_token=ACCESS_TOKEN'