2023-07-22 16:21:50 -04:00
import os
import json
2023-07-23 18:02:27 -04:00
import whois
2023-07-22 16:21:50 -04:00
import datetime
import zipfile
2023-07-23 14:59:49 -04:00
import smtplib
2023-07-23 18:02:27 -04:00
import requests
2023-07-29 11:46:32 -04:00
import asyncio
2023-07-23 14:59:49 -04:00
from email . mime . multipart import MIMEMultipart
from email . mime . base import MIMEBase
from email . mime . text import MIMEText
from email . utils import COMMASPACE
from email import encoders
2023-07-22 16:21:50 -04:00
import user_commands
import room_commands
import ipinfo_commands
2023-07-29 11:46:32 -04:00
import bot_commands
2023-07-22 16:21:50 -04:00
import hardcoded_variables
2023-07-29 11:46:32 -04:00
rdlist_tag_descriptions = {
" csam " : " Child Sexual Abuse Material " ,
" cfm " : " An abundance of content which would directly appeal to those seeking csam. " ,
" jailbait " : " Photos which contain underage individuals in questionable or suggestive situations. " ,
" tfm " : " An abundance of content which would directly appeal to those seeking jailbait. " ,
" beastiality " : " Self explanatory. " ,
" 3d_loli " : " Pornography which depicts photorealistic underage characters. " ,
" stylized_3d_loli " : " Pornography which depicts underage characters that are not depicted in a realistic style. " ,
" gore " : " Self explanatory. " ,
" snuff " : " Self explanatory. " ,
" degen_misc " : " Other types of coomers rooms. " ,
" degen_larp " : " Coomer larp rooms. " ,
" degen_meet " : " Coomer socializing rooms. " ,
" degen_porn " : " Rooms dedicated to pornography, excluding types which have dedicated tags. " ,
" bot_porn " : " Rooms which contain bots that spam pornographic content. " ,
" bot_spam " : " Rooms which contain bots that spam content. Primarily for malvertising and cryptospam " ,
" preban " : " Rooms which may not contain tagged content, however have clear intent. i.e: Rooms with names like ' CP Room ' , ' Child Porn ' , etc " ,
" hub_room_trade " : " Rooms which exist solely to trade illegal or questionable content. i.e: csam, jailbait " ,
" hub_room_sussy " : " A room which is sussy. This tag does not have a solid definition, see existing tagged rooms " ,
" abandoned " : " Similar to ' anarchy ' , primarily for rooms which have automated spam bots. " ,
" anarchy " : " Unmoderated rooms. " ,
" hub_room_underage " : " Rooms which contain a disproportionate amount of underage users. " ,
" hub_room_links " : " Rooms which exist to share links to other rooms. " ,
" toddlercon " : " Lolicon but younger. " ,
" loli " : " Rooms which exist to host lolicon. " ,
}
confidentiality_warning = f """ \n \n **********************************************************************
\t \tATTENTION ! CONFIDENTIALITY NOTICE !
\nThis electronic mail and any files linked to it may hold information
that is privileged , confidential , and intended exclusively for the use of
the designated recipient or entity . If you ' re not the expected recipient or
the individual tasked with delivering the electronic mail to the intended recipient ,
be aware that you ' ve received this mail in error. Any utilization, duplication,
distribution , forwarding , printing , or publicizing of this email or the attached files
is strictly prohibited , as is revealing the information contained within .
If you ' ve received this email in error, please promptly inform the sender and
remove it from your electronic mailbox .
\n * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
"""
2023-07-22 16:21:50 -04:00
def get_report_folder ( ) :
# Get report_folder from hardcoded_variables
report_folder = hardcoded_variables . report_folder
# If report_folder ends with a slash, remove it
if report_folder . endswith ( os . sep ) :
report_folder = report_folder [ : - 1 ]
return report_folder
2023-08-01 01:20:36 -04:00
def zip_report_folder ( user_report_folder , username ) :
2023-07-22 16:21:50 -04:00
# Get parent directory of user_report_folder
parent_directory = os . path . dirname ( os . path . abspath ( user_report_folder ) )
# Create the name of the .zip file including timestamp
zip_file_name = os . path . join ( parent_directory , username + " _ " + datetime . datetime . now ( ) . strftime ( " % Y- % m- %d _ % H- % M- % S " ) + " .zip " )
# Create a .zip file of the specified folder
with zipfile . ZipFile ( zip_file_name , ' w ' , zipfile . ZIP_DEFLATED ) as zip_file :
for root , dirs , files in os . walk ( user_report_folder ) :
for file in files :
zip_file . write ( os . path . join ( root , file ) , arcname = os . path . relpath ( os . path . join ( root , file ) , user_report_folder ) )
2023-08-01 01:20:36 -04:00
return zip_file_name
2023-07-22 16:21:50 -04:00
2023-07-26 15:39:48 -04:00
def generate_user_report ( preset_username , report_details ) :
2023-07-22 16:21:50 -04:00
if len ( preset_username ) == 0 :
username = input ( " \n Please enter the username to automatically generate a report: " )
username = user_commands . parse_username ( username )
else :
username = user_commands . parse_username ( preset_username )
# Check if user exists
2023-07-25 09:52:08 -04:00
if user_commands . check_user_account_exists ( username ) == False :
print ( " \n User does not exist, exiting report generation. " )
2023-07-22 16:21:50 -04:00
return
2023-07-25 09:52:08 -04:00
elif user_commands . check_user_account_exists ( username ) == True :
print ( f " \n Generating user report for { username } ... " )
2023-07-22 16:21:50 -04:00
# If report_folder ends in a slash, remove it
report_folder = get_report_folder ( )
# Create report folders
user_report_folder = report_folder + " / " + username + " / "
if os . path . exists ( report_folder ) == False :
os . mkdir ( report_folder )
if os . path . exists ( user_report_folder ) == False :
os . mkdir ( user_report_folder )
2023-07-26 15:39:48 -04:00
# Collect and write the report details to ./report/username/report_details.txt
if report_details == ' ' :
2023-08-01 09:29:38 -04:00
report_details = input ( " \n Please enter the details for this report. Include as much detail as possible, including: \n - A description of what happened. \n - Timestamps of events. \n - Whether this user was a repeat offender, if so include details about previous incidents. \n - Other user or rooms involved. \n - Other evidence you ' ve collected against this user. \n - Whether the offending users were deactivated. \n - Whether the offending rooms were shut down. \n \n " )
2023-07-26 15:39:48 -04:00
report_details_file = open ( user_report_folder + " report_details.txt " , " w " )
report_details_file . write ( report_details )
report_details_file . close ( )
2023-07-22 16:21:50 -04:00
# Get user account data and write to ./report/username/account_data.json
account_data = user_commands . collect_account_data ( username )
account_data_file = open ( user_report_folder + " account_data.json " , " w " )
account_data_file . write ( json . dumps ( account_data , indent = 4 , sort_keys = True ) )
account_data_file . close ( )
# Get user pushers and write to ./report/username/pushers.json
pushers_data = user_commands . list_account_pushers ( username )
pushers_file = open ( user_report_folder + " pushers.json " , " w " )
pushers_file . write ( json . dumps ( pushers_data , indent = 4 , sort_keys = True ) )
pushers_file . close ( )
# Get whois data and write to ./report/username/whois.json
whois_data = user_commands . whois_account ( username )
whois_file = open ( user_report_folder + " whois.json " , " w " )
whois_file . write ( json . dumps ( whois_data , indent = 4 , sort_keys = True ) )
whois_file . close ( )
# Get query data and write to ./report/username/query.json
query_data = user_commands . query_account ( username )
query_file = open ( user_report_folder + " query.json " , " w " )
query_file . write ( json . dumps ( query_data , indent = 4 , sort_keys = True ) )
query_file . close ( )
# Get user joined rooms and write to ./report/username/joined_rooms.json
joined_rooms_dict = user_commands . list_joined_rooms ( username )
joined_rooms_file = open ( user_report_folder + " joined_rooms.json " , " w " )
joined_rooms_file . write ( json . dumps ( joined_rooms_dict , indent = 4 , sort_keys = True ) )
joined_rooms_file . close ( )
# Get user ipinfo and write to ./report/username/ipinfo.json
ipinfo = ipinfo_commands . analyse_account_ip ( username )
ipinfo_file = open ( user_report_folder + " ipinfo.json " , " w " )
ipinfo_file . write ( json . dumps ( ipinfo , indent = 4 , sort_keys = True ) )
ipinfo_file . close ( )
2023-07-25 09:52:08 -04:00
# Prepare folder structures
room_folder = user_report_folder + " rooms/ "
dm_folder = user_report_folder + " dms/ "
2023-08-01 09:29:38 -04:00
forgotten_folder = user_report_folder + " forgotten/ "
2023-07-25 09:52:08 -04:00
details_folder = " details/ "
states_folder = " states/ "
2023-07-22 16:21:50 -04:00
2023-07-25 09:52:08 -04:00
# For each room the user is in, get the room state and write to ./report/username/rooms/states/
room_states_folder = room_folder + states_folder
if not os . path . exists ( room_states_folder ) :
os . makedirs ( room_states_folder , exist_ok = True )
2023-07-22 16:21:50 -04:00
2023-07-25 09:52:08 -04:00
# For each room the user is in, get the room details and write to ./report/username/rooms/details/
room_details_folder = room_folder + details_folder
if not os . path . exists ( room_details_folder ) :
os . makedirs ( room_details_folder , exist_ok = True )
# For DM, get the state and write to ./report/username/dms/states/
dm_states_folder = dm_folder + states_folder
if not os . path . exists ( dm_states_folder ) :
os . makedirs ( dm_states_folder , exist_ok = True )
2023-07-22 16:21:50 -04:00
2023-07-25 09:52:08 -04:00
# For DM, get the details and write to ./report/username/dms/details/
dm_details_folder = dm_folder + details_folder
if not os . path . exists ( dm_details_folder ) :
os . makedirs ( dm_details_folder , exist_ok = True )
2023-08-01 09:29:38 -04:00
# For forgotten rooms, get the state and write to ./report/username/forgotten/states/
forgotten_states_folder = forgotten_folder + states_folder
if not os . path . exists ( forgotten_states_folder ) :
os . makedirs ( forgotten_states_folder , exist_ok = True )
# For forgotten rooms, get the details and write to ./report/username/forgotten/details/
forgotten_details_folder = forgotten_folder + details_folder
if not os . path . exists ( forgotten_details_folder ) :
os . makedirs ( forgotten_details_folder , exist_ok = True )
room_list = list ( account_data [ ' account_data ' ] [ ' rooms ' ] . keys ( ) )
2023-07-22 16:21:50 -04:00
count = 0
for room in room_list :
count + = 1
room = room . split ( " " ) [ 0 ]
2023-07-26 15:39:48 -04:00
room_details = room_commands . get_room_details ( room )
2023-07-25 09:52:08 -04:00
# Check the room conditions to select the proper output folders
2023-08-01 09:29:38 -04:00
if room_details [ ' forgotten ' ] == True :
room_details_file = open ( forgotten_details_folder + room + " .json " , " w " )
room_commands . export_room_state ( room , forgotten_states_folder , True )
elif room_details [ ' joined_members ' ] == 2 and room_details [ ' public ' ] == False :
2023-07-25 09:52:08 -04:00
room_details_file = open ( dm_details_folder + room + " .json " , " w " )
2023-08-01 09:29:38 -04:00
room_commands . export_room_state ( room , dm_states_folder , True )
2023-07-25 09:52:08 -04:00
else :
room_details_file = open ( room_details_folder + room + " .json " , " w " )
2023-08-01 09:29:38 -04:00
room_commands . export_room_state ( room , room_states_folder , True )
2023-07-25 09:52:08 -04:00
room_details_file . write ( json . dumps ( room_details , indent = 4 , sort_keys = True ) )
2023-07-22 16:21:50 -04:00
room_details_file . close ( )
2023-07-25 09:52:08 -04:00
2023-08-01 09:29:38 -04:00
if count > 10 and hardcoded_variables . testing_mode == True :
2023-07-22 16:21:50 -04:00
break
# Generate a random password, then encrypt the ./report/username/ folder to a timestamped .zip file
2023-08-01 01:20:36 -04:00
zip_file_name = zip_report_folder ( user_report_folder , username )
2023-07-22 16:21:50 -04:00
# Measure the size of the encrypted .zip file in MB
2023-08-01 01:20:36 -04:00
zip_file_size = os . path . getsize ( zip_file_name ) / 1000000
2023-07-22 16:21:50 -04:00
# Print the password and the encrypted .zip file name
2023-08-01 12:27:12 -04:00
print ( " Report generated successfully on user: \" " + username + " \" \n \n You can send this .zip file when reporting a user to law enforcement. \n " )
2023-08-01 01:20:36 -04:00
print ( " .zip file location: " + zip_file_name )
print ( " .zip file size: " + str ( zip_file_size ) + " MB \n " )
return zip_file_name
2023-07-23 14:59:49 -04:00
2023-07-29 11:46:32 -04:00
def lookup_homeserver_admin ( preset_baseurl ) :
if hardcoded_variables . testing_mode == True :
baseurl = hardcoded_variables . base_url
elif preset_baseurl == ' ' :
2023-07-25 09:52:08 -04:00
baseurl = input ( " \n Enter the base URL to collect the admin contact details (Example: matrix.org): " )
elif preset_baseurl != ' ' :
baseurl = preset_baseurl
# If baseurl is matrix.org, return 'abuse@matrix.org' as a hardcoded response
if baseurl == " matrix.org " :
print ( " \n Admin contact email(s) for " + baseurl + " are: abuse@matrix.org " )
2023-07-29 11:46:32 -04:00
return { " admins " : { " email_address " : " abuse@matrix.org " } } , False
2023-07-25 09:52:08 -04:00
# Check target homserver for MSC1929 support email
url = f " https:// { baseurl } /.well-known/matrix/support "
try :
response = requests . get ( url )
except requests . exceptions . RequestException as e :
print ( f " Error: Unable to connect to server { baseurl } . Trying WHOIS data... " )
response = None
# If the request was successful, the status code will be 200
2023-07-29 11:46:32 -04:00
if response . status_code == 200 and ( " email_address " in response . text or " matrix_id " in response . text ) :
2023-07-25 09:52:08 -04:00
# Parse the response as JSON
data = json . loads ( response . text )
2023-07-29 11:46:32 -04:00
#print("\nAdmin contact details for " + baseurl + " are: " + str(data))
2023-07-25 09:52:08 -04:00
2023-07-29 11:46:32 -04:00
return data , False
2023-07-25 09:52:08 -04:00
else :
2023-07-29 11:46:32 -04:00
print ( f " Error: Unable to collect admin contact details from server { baseurl } " )
2023-07-25 09:52:08 -04:00
print ( " Attempting to collect admin email from WHOIS data... " )
# Get WHOIS data
try :
w = whois . whois ( baseurl )
if w . emails :
2023-07-29 11:46:32 -04:00
#print("\nAdmin contact email(s) for " + baseurl + " are: " + str(w.emails))
2023-07-25 09:52:08 -04:00
return { baseurl : list ( w . emails ) } , True
else :
print ( f " Error: Unable to collect admin email from WHOIS data for { baseurl } " )
return None , False
except :
print ( f " Error: Unable to collect WHOIS data for { baseurl } " )
return None , False
2023-07-23 18:02:27 -04:00
2023-07-23 14:59:49 -04:00
def send_email ( email_address , email_subject , email_content , email_attachments ) :
2023-07-25 09:52:08 -04:00
assert isinstance ( email_attachments , list )
msg = MIMEMultipart ( ) # Create a multipart message
msg [ ' From ' ] = hardcoded_variables . smtp_user
msg [ ' To ' ] = COMMASPACE . join ( [ email_address ] )
msg [ ' Subject ' ] = email_subject
msg . attach ( MIMEText ( email_content ) ) # Attach the email body
# Attach files
for file in email_attachments :
part = MIMEBase ( ' application ' , " octet-stream " )
with open ( file , ' rb ' ) as f :
part . set_payload ( f . read ( ) )
encoders . encode_base64 ( part )
part . add_header ( ' Content-Disposition ' , ' attachment ' , filename = os . path . basename ( file ) )
msg . attach ( part )
try :
# Send the email via SMTP server
smtp = smtplib . SMTP ( hardcoded_variables . smtp_server , hardcoded_variables . smtp_port )
smtp . starttls ( )
smtp . login ( hardcoded_variables . smtp_user , hardcoded_variables . smtp_password )
smtp . sendmail ( hardcoded_variables . smtp_user , email_address , msg . as_string ( ) )
smtp . close ( )
return True
except Exception as e :
print ( f " Failed to send email: { e } " )
return False
2023-07-23 14:59:49 -04:00
def test_send_email ( ) :
2023-07-25 09:52:08 -04:00
# Ask the user for the destination email address
2023-07-29 11:46:32 -04:00
email_address = hardcoded_variables . incident_report_return_email
2023-07-23 14:59:49 -04:00
2023-07-25 09:52:08 -04:00
# Example email parameters
2023-07-29 11:46:32 -04:00
email_subject = " Incident Report "
email_content = " Hello! This is a test email. Please ignore it. "
2023-07-25 09:52:08 -04:00
email_attachments = [ " ./test_data/evil_clown.jpeg " ] # List of file paths. Adjust this to the actual files you want to attach.
2023-07-23 18:02:27 -04:00
2023-07-25 09:52:08 -04:00
# Try to send the email
if send_email ( email_address , email_subject , email_content , email_attachments ) :
print ( " \n Email successfully sent. " )
else :
print ( " \n Failed to send email. " )
2023-07-23 18:02:27 -04:00
2023-07-31 09:36:44 -04:00
def generate_rdlist_report_summary ( room_dict , user_id ) :
2023-08-01 01:20:36 -04:00
#print(f"user_dict: {room_dict}")
2023-07-31 09:36:44 -04:00
report_content = f """ \n ~~~User Report~~~ \n \n Username: { user_id } \n """
for room_id , rdlist_tags in room_dict . items ( ) :
report_content + = f " \n Was a member of this room: { room_id } \n This room has been flagged with the following rdlist tags: \n "
for tag in rdlist_tags :
tag_description = rdlist_tag_descriptions . get ( tag , " No description available. " )
report_content + = f " - { tag } ( { tag_description } ) \n "
report_content
return report_content
2023-07-25 09:52:08 -04:00
def prepare_email_content ( user_dict , from_whois , baseurl ) :
email_content = f """ Dear Administrator,
2023-07-23 18:02:27 -04:00
2023-07-25 09:52:08 -04:00
We regret to inform you that there have been incidents involving the following users in your homeserver :
"""
2023-07-23 18:02:27 -04:00
2023-07-25 09:52:08 -04:00
for full_username , room_dict in user_dict . items ( ) :
email_content + = f " \n User: { full_username } \n "
for room_id , rdlist_tags in room_dict . items ( ) :
2023-07-29 11:46:32 -04:00
email_content + = f " \n Is in the room: { room_id } \n This room has been flagged with the following rdlist tags: \n "
for tag in rdlist_tags :
tag_description = rdlist_tag_descriptions . get ( tag , " No description available. " )
email_content + = f " - { tag } ( { tag_description } ) \n "
2023-07-23 18:02:27 -04:00
2023-07-25 09:52:08 -04:00
email_content + = f """
2023-07-23 18:02:27 -04:00
We request your immediate attention to this matter . It is recommended that you :
2023-07-25 09:52:08 -04:00
- Generate a report on these users ' accounts and send it to law enforcement.
- Block and purge these rooms from your homeserver .
2023-07-29 11:46:32 -04:00
- Deactivate these users ' accounts, or retain them for further observation.
2023-07-23 18:02:27 -04:00
All of these actions can be done automatically using this moderation tool :
https : / / github . com / PC - Admin / matrix - moderation - tool
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2023-07-25 09:52:08 -04:00
\tTHIS EMAIL IS UNMONITORED , PLEASE DO NOT REPLY TO IT
2023-07-23 18:02:27 -04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2023-07-29 11:46:32 -04:00
To contact us please email { hardcoded_variables . incident_report_return_email } .
2023-07-23 18:02:27 -04:00
Thank you for helping us make Matrix safer .
Best regards ,
2023-07-29 11:46:32 -04:00
Abuse Management Team
2023-07-23 18:02:27 -04:00
https : / / { hardcoded_variables . base_url }
2023-07-25 09:52:08 -04:00
"""
if from_whois :
email_content + = f """ \n \n **********************************************************************
\tATTENTION DOMAIN REGISTRAR , YOUR ACTION IS REQUIRED HERE
2023-07-23 18:02:27 -04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
\nThis email is intended for the owner of the domain { baseurl } , but they have not published their email address .
\nAs the recipient of this email , you have a legal obligation to ensure that this email reaches them .
\nTo avoid receiving these emails in the future , please ask them to configure MSC1929 for their Matrix server :
https : / / github . com / matrix - org / matrix - spec - proposals / pull / 1929
2023-07-25 09:52:08 -04:00
"""
email_content + = confidentiality_warning
return email_content
2023-07-29 11:46:32 -04:00
def prepare_message_content ( user_dict , baseurl ) :
message_content = f """ Dear Administrator,
2023-07-25 09:52:08 -04:00
2023-07-29 11:46:32 -04:00
We regret to inform you that there have been incidents involving the following users in your homeserver :
"""
for full_username , room_dict in user_dict . items ( ) :
message_content + = f " \n User: { full_username } \n "
for room_id , rdlist_tags in room_dict . items ( ) :
message_content + = f " \n Is in the room: { room_id } \n This room has been flagged with the following rdlist tags: \n "
for tag in rdlist_tags :
tag_description = rdlist_tag_descriptions . get ( tag , " No description available. " )
message_content + = f " - { tag } ( { tag_description } ) \n "
message_content + = f """
We request your immediate attention to this matter . It is recommended that you :
- Generate a report on these users ' accounts and send it to law enforcement.
- Block and purge these rooms from your homeserver .
- Deactivate these users ' accounts, or retain them for further observation.
All of these actions can be done automatically using this moderation tool :
https : / / github . com / PC - Admin / matrix - moderation - tool
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
\tTHIS ACCOUNT IS UNMONITORED , PLEASE DO NOT REPLY TO IT
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
To contact us please message { hardcoded_variables . incident_report_return_mxid } .
Thank you for helping us make Matrix safer .
Best regards ,
Abuse Management Team
https : / / { hardcoded_variables . base_url }
"""
return message_content
2023-08-01 12:27:12 -04:00
async def send_incident_reports ( incidents_dict ) :
2023-07-25 09:52:08 -04:00
success = True
homeserver_dict = { }
# Aggregate incidents by homeserver.
for full_username , room_dict in incidents_dict . items ( ) :
baseurl = full_username . split ( " : " ) [ 1 ]
if baseurl not in homeserver_dict :
homeserver_dict [ baseurl ] = { }
homeserver_dict [ baseurl ] [ full_username ] = room_dict
2023-07-29 11:46:32 -04:00
# Prepare and send one incident report per homeserver, including all users and rooms.
2023-07-25 09:52:08 -04:00
for baseurl , user_dict in homeserver_dict . items ( ) :
2023-07-29 11:46:32 -04:00
admin_contact_dict , from_whois = lookup_homeserver_admin ( baseurl )
if not admin_contact_dict or " admins " not in admin_contact_dict :
2023-07-25 09:52:08 -04:00
print ( f " Unable to find any admin emails for { baseurl } " )
success = False
continue
2023-07-29 11:46:32 -04:00
# Prepare and send one message or email per homeserver, including all users and rooms.
for admin in admin_contact_dict [ " admins " ] :
#print(f"DEBUG: {type(admin)}")
#print(f"DEBUG: {admin}") # this will print the content of each admin dict
if " matrix_id " in admin : # If matrix_id exists
message_content = prepare_message_content ( user_dict , baseurl )
try :
2023-08-01 12:27:12 -04:00
print ( f " \n Sending Incident Report for users from { baseurl } to { admin [ ' matrix_id ' ] } " )
2023-07-29 11:46:32 -04:00
await bot_commands . send_message ( admin [ " matrix_id " ] , message_content )
except Exception as e :
print ( f " Failed to send message to { admin [ ' matrix_id ' ] } : { str ( e ) } " )
success = False
# If email_address exists, or if message send failed, send Incident report via email
elif " email_address " in admin or success == False :
email_address = admin . get ( " email_address " )
if email_address : # If email_address exists
email_subject = f " Incident Report for users from { baseurl } "
email_content = prepare_email_content ( user_dict , from_whois , baseurl )
email_attachments = [ ]
2023-08-01 12:27:12 -04:00
print ( f " Sending Incident Report for users from { baseurl } to { admin [ ' email_address ' ] } " )
2023-07-29 11:46:32 -04:00
if not send_email ( email_address , email_subject , email_content , email_attachments ) :
print ( f " Failed to send email to { email_address } " )
success = False
2023-07-25 09:52:08 -04:00
return success
def test_send_incident_reports ( ) :
incidents_dict = {
f " @billybob:matrix.org " : {
2023-07-29 11:46:32 -04:00
" !dummyid1:matrix.org " : [ " csam " , " loli " , " beastiality " ] ,
2023-07-25 09:52:08 -04:00
" !dummyid2:matrix.org " : [ " csam " , " anarchy " ]
} ,
f " @johndoe:matrix.org " : {
2023-07-29 11:46:32 -04:00
" !dummyid3:matrix.org " : [ " csam " , " loli " , " toddlercon " ] ,
" !dummyid4:matrix.org " : [ " anarchy " , " terrorism " ]
2023-07-25 09:52:08 -04:00
} ,
f " @pedobear:perthchat.org " : {
2023-07-29 11:46:32 -04:00
" !dummyid5:matrix.org " : [ " csam " , " loli " , " jailbait " ] ,
2023-07-29 12:10:47 -04:00
" !dummyid6:matrix.org " : [ " csam " , " hublinks " ]
2023-07-25 09:52:08 -04:00
} ,
f " @randomcreep:perthchat.org " : {
" !dummyid7:matrix.org " : [ " csam " , " jailbait " ] ,
2023-07-29 11:46:32 -04:00
" !dummyid8:matrix.org " : [ " csam " , " preban " ]
2023-07-25 09:52:08 -04:00
} ,
f " @fatweeb:grin.hu " : {
2023-07-29 11:46:32 -04:00
" !dummyid9:matrix.org " : [ " csam " , " loli " ] ,
2023-07-29 12:10:47 -04:00
" !dummyid10:matrix.org " : [ " csam " , " degen_porn " ]
2023-07-25 09:52:08 -04:00
}
}
try :
if hardcoded_variables . testing_mode == True :
2023-07-29 11:46:32 -04:00
print ( " \n NOTE: Testing mode is enabled, sending Incident Reports to you! :) \n " )
2023-08-01 12:27:12 -04:00
if asyncio . run ( send_incident_reports ( incidents_dict ) ) :
2023-07-25 09:52:08 -04:00
print ( " \n Incident reports successfully sent. " )
else :
print ( " \n Failed to send the incident reports. " )
except Exception as e :
print ( f " \n Failed to send incident reports: { e } " )