new: Add contacts as attachmetn to notification mail

pull/636/head
Raphaël Vinot 2023-03-09 12:55:45 +02:00
parent 5c188d05e9
commit 53d9a6ba7a
2 changed files with 16 additions and 11 deletions

View File

@ -652,6 +652,15 @@ class Lookyloo():
to_return['all_emails'] = list(to_return['all_emails'])
return to_return
def contacts(self, capture_uuid: str, /) -> List[Dict[str, Any]]:
capture = self.get_crawled_tree(capture_uuid)
rendered_hostnode = self.get_hostnode_from_tree(capture_uuid, capture.root_hartree.rendered_node.hostnode_uuid)
result = []
for node in reversed(rendered_hostnode.get_ancestors()):
result.append(self.takedown_details(node))
result.append(self.takedown_details(rendered_hostnode))
return result
def send_mail(self, capture_uuid: str, /, email: str='', comment: str='') -> None:
'''Send an email notification regarding a specific capture'''
if not get_config('generic', 'enable_mail_notification'):
@ -692,6 +701,11 @@ class Lookyloo():
sender=msg['From'].addresses[0].display_name,
)
msg.set_content(body)
try:
contact_for_takedown = self.contacts(capture_uuid)
msg.add_attachment(json.dumps(contact_for_takedown, indent=2), maintype='application', subtype='json', filename='contacts.json')
except Exception as e:
self.logger.warning(f'Unable to get the contacts: {e}')
try:
s = smtplib.SMTP(email_config['smtp_host'], email_config['smtp_port'])
s.send_message(msg)

View File

@ -486,17 +486,8 @@ class Takedown(Resource):
parameters: Dict = request.get_json(force=True)
capture_uuid = parameters.get('capture_uuid')
if not capture_uuid:
return {'error': f'Invalid UUID: {capture_uuid}'}
capture = lookyloo.get_crawled_tree(capture_uuid)
if not capture:
return {'error': f'Unknown capture {capture_uuid}'}
rendered_hostnode = lookyloo.get_hostnode_from_tree(capture_uuid, capture.root_hartree.rendered_node.hostnode_uuid)
result = []
for node in reversed(rendered_hostnode.get_ancestors()):
result.append(lookyloo.takedown_details(node))
result.append(lookyloo.takedown_details(rendered_hostnode))
return result
return {'error': f'Invalid request: {parameters}'}
return lookyloo.contacts(capture_uuid)
# Admin stuff