From 4d5beef79e1315baf7117ad532b456a4d8167aff Mon Sep 17 00:00:00 2001 From: AntoniaBK Date: Wed, 27 Mar 2024 10:29:52 +0100 Subject: [PATCH 1/3] Made send_email available from the API --- website/web/genericapi.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/website/web/genericapi.py b/website/web/genericapi.py index 0e1a29f..144778e 100644 --- a/website/web/genericapi.py +++ b/website/web/genericapi.py @@ -380,7 +380,19 @@ class CaptureCookies(Resource): # type: ignore[misc] def get(self, capture_uuid: str) -> dict[str, Any]: return json.loads(lookyloo.get_cookies(capture_uuid).read()) - +@api.route('/json//report') +@api.doc(description='Reports the url by sending an email to the investigation team', + params={'capture_uuid': 'The UUID of the capture'}) +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: + 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) # Just text auto_report_model = api.model('AutoReportModel', { From 78c0089413c5b5e45e926424b519581f0f7e268d Mon Sep 17 00:00:00 2001 From: AntoniaBK Date: Wed, 27 Mar 2024 12:21:23 +0100 Subject: [PATCH 2/3] adapt send_mail for API --- lookyloo/lookyloo.py | 6 ++++-- website/web/genericapi.py | 8 ++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index 40c97c3..4331515 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -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''' diff --git a/website/web/genericapi.py b/website/web/genericapi.py index 144778e..fbc5371 100644 --- a/website/web/genericapi.py +++ b/website/web/genericapi.py @@ -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', { From 0eaea852040a6c3f5bd5bb0493ae5b5fbc23a73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 27 Mar 2024 13:44:35 +0100 Subject: [PATCH 3/3] fix: Typing, make mypy happy --- lookyloo/lookyloo.py | 2 +- website/web/genericapi.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index 4331515..204d833 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -761,7 +761,7 @@ class Lookyloo(): result.append(self.takedown_details(rendered_hostnode)) return result - def send_mail(self, capture_uuid: str, /, email: str='', comment: str | None=None) -> True | dict[str, Any]: + def send_mail(self, capture_uuid: str, /, email: str='', comment: str | None=None) -> bool | dict[str, Any]: '''Send an email notification regarding a specific capture''' if not get_config('generic', 'enable_mail_notification'): return {"error": "Unable to send mail: mail notification disabled"} diff --git a/website/web/genericapi.py b/website/web/genericapi.py index fbc5371..5a2dfc4 100644 --- a/website/web/genericapi.py +++ b/website/web/genericapi.py @@ -380,16 +380,17 @@ class CaptureCookies(Resource): # type: ignore[misc] def get(self, capture_uuid: str) -> dict[str, Any]: return json.loads(lookyloo.get_cookies(capture_uuid).read()) + @api.route('/json//report') @api.doc(description='Reports the url by sending an email to the investigation team', params={'capture_uuid': 'The UUID of the capture'}) 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) -> True | dict[str, Any]: + def post(self, capture_uuid: str) -> bool | dict[str, Any]: parameters: dict[str, Any] = request.get_json(force=True) - return lookyloo.send_mail(capture_uuid, parameters.get('email'), parameters.get('comment')) -# Just text + return lookyloo.send_mail(capture_uuid, parameters.get('email', ''), parameters.get('comment')) + auto_report_model = api.model('AutoReportModel', { 'email': fields.String(description="Email of the reporter, used by the analyst to get in touch.", example=''),