2023-07-08 05:55:48 -04:00
|
|
|
|
2023-07-25 09:52:08 -04:00
|
|
|
import json
|
2023-07-08 05:55:48 -04:00
|
|
|
import user_commands
|
|
|
|
import room_commands
|
|
|
|
import server_commands
|
2023-07-22 16:21:50 -04:00
|
|
|
import ipinfo_commands
|
2023-07-08 05:55:48 -04:00
|
|
|
import rdlist_commands
|
2023-07-22 16:21:50 -04:00
|
|
|
import report_commands
|
2023-07-08 05:55:48 -04:00
|
|
|
import hardcoded_variables
|
|
|
|
|
|
|
|
# check if homeserver url is hard coded, if not set it
|
|
|
|
|
|
|
|
if hardcoded_variables.homeserver_url == "matrix.example.org":
|
|
|
|
homeserver_url = input("What is the URL of your server? Eg: matrix.example.org ")
|
|
|
|
|
|
|
|
# check if base url is hard coded, if not set it
|
|
|
|
|
|
|
|
if hardcoded_variables.base_url == "example.org":
|
|
|
|
base_url = input("What is the URL of your server? Eg: example.org ")
|
|
|
|
|
|
|
|
# check if access token is hard coded, if not set it
|
|
|
|
|
|
|
|
length_access_token = len(hardcoded_variables.access_token)
|
|
|
|
|
|
|
|
if length_access_token == 0:
|
|
|
|
access_token = input("Please enter access token for server admin account: ")
|
|
|
|
|
|
|
|
# loop menu for various moderation actions
|
|
|
|
|
|
|
|
pass_token = False
|
|
|
|
while pass_token == False:
|
2023-07-18 18:01:40 -04:00
|
|
|
print("\n##########################")
|
|
|
|
print("# MATRIX MODERATION TOOL #")
|
|
|
|
print("##########################")
|
|
|
|
print("\nA tool for making common Synapse moderation tasks easier. Created by @PC-Admin.")
|
|
|
|
print("\n----------------------------------------------")
|
|
|
|
print("\n#### User Account Commands ####\t\t\t#### Room Commands ####")
|
2023-07-20 15:15:08 -04:00
|
|
|
print("1) Deactivate a user account.\t\t\t20) List details of a room.")
|
2023-07-25 09:52:08 -04:00
|
|
|
print("2) Deactivate multiple user accounts.\t\t21) List the members of a room.")
|
|
|
|
print("3) Create a user account.\t\t\t22) Export the state events of a target room.")
|
|
|
|
print("4) Create multiple user accounts.\t\t23) List rooms in public directory.")
|
|
|
|
print("5) Reset a users password.\t\t\t24) Remove a room from the public directory.")
|
|
|
|
print("6) Whois user account.\t\t\t\t25) Remove multiple rooms from the public directory.")
|
|
|
|
print("7) Whois multiple user accounts.\t\t26) Redact a room event.")
|
|
|
|
print("8) Query user account.\t\t\t\t27) List/Download all media in a room.")
|
|
|
|
print("9) Query multiple user accounts.\t\t28) Download media from multiple rooms.")
|
|
|
|
print("10) List room memberships of user.\t\t29) Quarantine all media in a room.")
|
|
|
|
print("11) Promote a user to server admin.\t\t30) Shutdown a room.")
|
|
|
|
print("12) List all user accounts.\t\t\t31) Shutdown multiple rooms.")
|
|
|
|
print("13) Quarantine all media a users uploaded.\t32) Delete a room.")
|
|
|
|
print("14) Collect account data.\t\t\t33) Delete multiple rooms.")
|
|
|
|
print("15) List account pushers.\t\t\t34) Purge the event history of a room to a specific timestamp.")
|
|
|
|
print("16) Get rate limit of a user account.\t\t35) Purge the event history of multiple rooms to a specific timestamp.")
|
2023-07-20 15:15:08 -04:00
|
|
|
print("17) Set rate limit of a user account.")
|
|
|
|
print("18) Delete rate limit of a user account.")
|
|
|
|
print("19) Check if user account exists.")
|
2023-07-22 16:21:50 -04:00
|
|
|
print("\n#### Server Commands ####\t\t\t\t\t#### Report Generation ####")
|
|
|
|
print("40) Delete and block a specific media.\t\t\t\t70) Generate user report.")
|
|
|
|
print("41) Purge remote media repository up to a certain date.\t\t71) Decrypt user report .zip file.")
|
2023-07-23 18:57:58 -04:00
|
|
|
print("42) Prepare database for copying events of multiple rooms.\t72) Lookup homeserver admin contact email.")
|
2023-07-23 19:01:41 -04:00
|
|
|
print("\t\t\t\t\t\t\t\t73) Send a test email.")
|
2023-07-25 09:52:08 -04:00
|
|
|
print("#### rdlist ####\t\t\t\t\t\t74) Send test incident reports to yourself.")
|
2023-07-20 15:15:08 -04:00
|
|
|
print("50) Block all rooms with specific rdlist tags.")
|
|
|
|
print("51) Block all rooms with recommended rdlist tags.")
|
2023-07-18 18:01:40 -04:00
|
|
|
print("\n#### ipinfo.io ####")
|
2023-07-20 15:15:08 -04:00
|
|
|
print("60) Analyse a users country of origin.")
|
|
|
|
print("61) Analyse multiple users country of origin.")
|
2023-07-18 18:01:40 -04:00
|
|
|
print("\nPlease enter a number from the above menu, or enter 'q' or 'e' to exit.\n")
|
|
|
|
menu_input = input()
|
2023-07-08 05:55:48 -04:00
|
|
|
if menu_input == "1":
|
|
|
|
user_commands.deactivate_account('')
|
|
|
|
elif menu_input == "2":
|
2023-07-09 16:48:14 -04:00
|
|
|
user_commands.deactivate_multiple_accounts()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "3":
|
2023-07-09 16:48:14 -04:00
|
|
|
user_commands.create_account('','')
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "4":
|
2023-07-09 16:48:14 -04:00
|
|
|
user_commands.create_multiple_accounts()
|
2023-07-14 11:18:31 -04:00
|
|
|
elif menu_input == "5":
|
2023-07-09 16:48:14 -04:00
|
|
|
user_commands.reset_password('','')
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "6":
|
2023-07-25 09:52:08 -04:00
|
|
|
whois_account_dict = user_commands.whois_account('')
|
|
|
|
print(json.dumps(whois_account_dict, indent=4, sort_keys=True))
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "7":
|
2023-07-09 16:48:14 -04:00
|
|
|
user_commands.whois_multiple_accounts()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "8":
|
2023-07-25 09:52:08 -04:00
|
|
|
query_account_dict = user_commands.query_account()
|
|
|
|
print(json.dumps(query_account_dict, indent=4, sort_keys=True))
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "9":
|
2023-07-14 11:18:31 -04:00
|
|
|
user_commands.query_multiple_accounts()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "10":
|
2023-07-25 09:52:08 -04:00
|
|
|
joined_rooms_dict = user_commands.list_joined_rooms('')
|
|
|
|
print(json.dumps(joined_rooms_dict, indent=4, sort_keys=True))
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "11":
|
2023-07-25 09:52:08 -04:00
|
|
|
set_user_server_admin_dict = user_commands.set_user_server_admin('')
|
|
|
|
print(json.dumps(set_user_server_admin_dict, indent=4, sort_keys=True))
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "12":
|
2023-07-14 11:18:31 -04:00
|
|
|
user_commands.list_accounts()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "13":
|
2023-07-14 11:18:31 -04:00
|
|
|
user_commands.quarantine_users_media()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "14":
|
2023-07-25 09:52:08 -04:00
|
|
|
account_data_dict = user_commands.collect_account_data('')
|
|
|
|
print(json.dumps(account_data_dict, indent=4, sort_keys=True))
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "15":
|
2023-07-20 15:15:08 -04:00
|
|
|
user_commands.list_account_pushers('')
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "16":
|
2023-07-20 15:15:08 -04:00
|
|
|
user_commands.get_rate_limit()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "17":
|
2023-07-20 15:15:08 -04:00
|
|
|
user_commands.set_rate_limit()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "18":
|
2023-07-20 15:15:08 -04:00
|
|
|
user_commands.delete_rate_limit()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "19":
|
2023-07-25 09:52:08 -04:00
|
|
|
user_account_exists = user_commands.check_user_account_exists('')
|
|
|
|
if user_account_exists == True:
|
|
|
|
print("\nUser account exists.\n")
|
|
|
|
elif user_account_exists == False:
|
|
|
|
print("\nUser account does not exist.\n")
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "20":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_details_dict = room_commands.list_room_details('')
|
|
|
|
print(json.dumps(room_details_dict, indent=4, sort_keys=True))
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "21":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_members_dict = room_commands.get_room_members('',False)
|
|
|
|
print(json.dumps(room_members_dict, indent=4, sort_keys=True))
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "22":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.export_room_state('','',True)
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "23":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.public_directory_rooms()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "24":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.remove_room_from_directory('')
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "25":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.remove_multiple_rooms_from_directory()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "26":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.redact_room_event()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "27":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.list_and_download_media_in_room('','','','./')
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "28":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.download_media_from_multiple_rooms()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "29":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.quarantine_media_in_room()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "30":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.shutdown_room('','','','','','')
|
2023-07-14 11:18:31 -04:00
|
|
|
elif menu_input == "31":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.shutdown_multiple_rooms()
|
2023-07-14 11:18:31 -04:00
|
|
|
elif menu_input == "32":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.delete_room('')
|
2023-07-20 15:15:08 -04:00
|
|
|
elif menu_input == "33":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.delete_multiple_rooms()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "34":
|
2023-07-25 09:52:08 -04:00
|
|
|
room_commands.purge_room_to_timestamp('','')
|
|
|
|
elif menu_input == "35":
|
2023-07-20 15:15:08 -04:00
|
|
|
room_commands.purge_multiple_rooms_to_timestamp()
|
2023-07-14 11:18:31 -04:00
|
|
|
elif menu_input == "40":
|
2023-07-20 15:15:08 -04:00
|
|
|
server_commands.delete_block_media()
|
2023-07-14 11:18:31 -04:00
|
|
|
elif menu_input == "41":
|
2023-07-20 15:15:08 -04:00
|
|
|
server_commands.purge_remote_media_repo()
|
|
|
|
elif menu_input == "42":
|
|
|
|
server_commands.prepare_database_copy_of_multiple_rooms()
|
|
|
|
elif menu_input == "50":
|
2023-07-25 09:52:08 -04:00
|
|
|
rdlist_commands.block_all_rooms_with_rdlist_tags(False,'','','')
|
2023-07-20 15:15:08 -04:00
|
|
|
elif menu_input == "51":
|
|
|
|
rdlist_commands.block_recommended_rdlist_tags()
|
|
|
|
elif menu_input == "60":
|
2023-07-22 16:21:50 -04:00
|
|
|
ipinfo_commands.analyse_account_ip('')
|
2023-07-20 15:15:08 -04:00
|
|
|
elif menu_input == "61":
|
2023-07-22 16:21:50 -04:00
|
|
|
ipinfo_commands.analyse_multiple_account_ips()
|
|
|
|
elif menu_input == "70":
|
|
|
|
report_commands.generate_user_report('')
|
|
|
|
elif menu_input == "71":
|
|
|
|
report_commands.decrypt_zip_file()
|
2023-07-23 14:59:49 -04:00
|
|
|
elif menu_input == "72":
|
2023-07-23 18:57:58 -04:00
|
|
|
report_commands.lookup_homeserver_admin_email('')
|
2023-07-23 18:02:27 -04:00
|
|
|
elif menu_input == "73":
|
2023-07-23 18:57:58 -04:00
|
|
|
report_commands.test_send_email()
|
|
|
|
elif menu_input == "74":
|
2023-07-25 09:52:08 -04:00
|
|
|
report_commands.test_send_incident_reports()
|
2023-07-08 05:55:48 -04:00
|
|
|
elif menu_input == "q" or menu_input == "Q" or menu_input == "e" or menu_input == "E":
|
|
|
|
print("\nExiting...\n")
|
|
|
|
pass_token = True
|
|
|
|
else:
|
2023-07-25 09:52:08 -04:00
|
|
|
print("\nIncorrect input detected, please select a number from 1 to 74!\n")
|
2023-07-08 05:55:48 -04:00
|
|
|
|