adapt send_mail for API

pull/899/head
AntoniaBK 2024-03-27 12:21:23 +01:00
parent 4d5beef79e
commit 78c0089413
2 changed files with 6 additions and 8 deletions

View File

@ -761,10 +761,10 @@ class Lookyloo():
result.append(self.takedown_details(rendered_hostnode))
return result
def send_mail(self, capture_uuid: str, /, email: str='', comment: str | None=None) -> None:
def send_mail(self, capture_uuid: str, /, email: str='', comment: str | None=None) -> True | dict[str, Any]:
'''Send an email notification regarding a specific capture'''
if not get_config('generic', 'enable_mail_notification'):
return
return {"error": "Unable to send mail: mail notification disabled"}
email_config = get_config('generic', 'email')
smtp_auth = get_config('generic', 'email_smtp_auth')
@ -828,6 +828,8 @@ class Lookyloo():
except Exception as e:
self.logger.exception(e)
self.logger.warning(msg.as_string())
return {"error": "Unable to send mail"}
return True
def _get_raw(self, capture_uuid: str, /, extension: str='*', all_files: bool=True) -> BytesIO:
'''Get file(s) from the capture directory'''

View File

@ -386,13 +386,9 @@ class CaptureCookies(Resource): # type: ignore[misc]
class CaptureReport(Resource): # type: ignore[misc]
@api.param('email', 'Email of the reporter, used by the analyst to get in touch.') # type: ignore[misc]
@api.param('comment', 'Description of the URL, will be given to the analyst.') # type: ignore[misc]
def post(self, capture_uuid) -> str:
def post(self, capture_uuid) -> True | dict[str, Any]:
parameters: dict[str, Any] = request.get_json(force=True)
answer = lookyloo.send_mail(capture_uuid, parameters.get('email'), parameters.get('comment'))
if answer is None:
return "Successfully sent an email to the investigation"
else:
return "Error: " + str(answer)
return lookyloo.send_mail(capture_uuid, parameters.get('email'), parameters.get('comment'))
# Just text
auto_report_model = api.model('AutoReportModel', {