new: simplified version to automatically report url

pull/912/head
Adrian Maraj 2024-04-30 15:32:14 +02:00
parent cafa9c1502
commit ae0c9e3449
7 changed files with 42 additions and 20 deletions

View File

@ -116,7 +116,7 @@ class AsyncCapture(AbstractManager):
if send_report: if send_report:
self.lookyloo.send_mail(uuid, email=settings.get('email', ''), self.lookyloo.send_mail(uuid, email=settings.get('email', ''),
comment=settings.get('comment')) comment=settings.get('comment'), email_prio= settings["email"] if settings["email"] else None)
lazy_cleanup = self.lookyloo.redis.pipeline() lazy_cleanup = self.lookyloo.redis.pipeline()
if queue and self.lookyloo.redis.zscore('queues', queue): if queue and self.lookyloo.redis.zscore('queues', queue):

View File

@ -0,0 +1,3 @@
{
"email" : "analyst@test.de"
}

View File

@ -57,6 +57,10 @@ def load_configs(path_to_config_files: str | Path | None=None) -> None:
for path in config_path.glob('*.json'): for path in config_path.glob('*.json'):
with path.open() as _c: with path.open() as _c:
configs[path.stem] = json.load(_c) configs[path.stem] = json.load(_c)
user_path = config_path / 'users'
for path in user_path.glob('*.json'):
with path.open() as _c:
configs[path.stem] = json.load(_c)
@lru_cache(64) @lru_cache(64)

View File

@ -864,7 +864,7 @@ class Lookyloo():
return f"Malicious capture according to {len(modules)} module(s): {', '.join(modules)}" return f"Malicious capture according to {len(modules)} module(s): {', '.join(modules)}"
def send_mail(self, capture_uuid: str, /, email: str='', comment: str | None=None) -> bool | dict[str, Any]: def send_mail(self, capture_uuid: str, /, email: str='', comment: str | None=None, email_prio: str | None = None) -> bool | dict[str, Any]:
'''Send an email notification regarding a specific capture''' '''Send an email notification regarding a specific capture'''
if not get_config('generic', 'enable_mail_notification'): if not get_config('generic', 'enable_mail_notification'):
return {"error": "Unable to send mail: mail notification disabled"} return {"error": "Unable to send mail: mail notification disabled"}
@ -913,7 +913,7 @@ class Lookyloo():
msg['From'] = email_config['from'] msg['From'] = email_config['from']
if email: if email:
msg['Reply-To'] = email msg['Reply-To'] = email
msg['To'] = email_config['to'] msg['To'] = email_config['to'] if not email_prio else email_prio
msg['Subject'] = email_config['subject'] msg['Subject'] = email_config['subject']
body = get_email_template() body = get_email_template()
body = body.format( body = body.format(

6
poetry.lock generated
View File

@ -737,13 +737,13 @@ tests = ["asttokens (>=2.1.0)", "coverage", "coverage-enable-subprocess", "ipyth
[[package]] [[package]]
name = "filelock" name = "filelock"
version = "3.13.4" version = "3.14.0"
description = "A platform independent file lock." description = "A platform independent file lock."
optional = false optional = false
python-versions = ">=3.8" python-versions = ">=3.8"
files = [ files = [
{file = "filelock-3.13.4-py3-none-any.whl", hash = "sha256:404e5e9253aa60ad457cae1be07c0f0ca90a63931200a47d9b6a6af84fd7b45f"}, {file = "filelock-3.14.0-py3-none-any.whl", hash = "sha256:43339835842f110ca7ae60f1e1c160714c5a6afd15a2873419ab185334975c0f"},
{file = "filelock-3.13.4.tar.gz", hash = "sha256:d13f466618bfde72bd2c18255e269f72542c6e70e7bac83a0232d6b1cc5c8cf4"}, {file = "filelock-3.14.0.tar.gz", hash = "sha256:6ea72da3be9b8c82afd3edcf99f2fffbb5076335a5ae4d03248bb5b6c3eae78a"},
] ]
[package.extras] [package.extras]

View File

@ -41,7 +41,7 @@ from werkzeug.wrappers.response import Response as WerkzeugResponse
from lookyloo import Lookyloo, CaptureSettings, Indexing from lookyloo import Lookyloo, CaptureSettings, Indexing
from lookyloo.capturecache import CaptureCache from lookyloo.capturecache import CaptureCache
from lookyloo.default import get_config from lookyloo.default import get_config, get_homedir
from lookyloo.exceptions import MissingUUID, NoValidHarFile from lookyloo.exceptions import MissingUUID, NoValidHarFile
from lookyloo.helpers import get_taxonomies, UserAgents, load_cookies from lookyloo.helpers import get_taxonomies, UserAgents, load_cookies
@ -1644,15 +1644,32 @@ def simple_capture() -> str | Response | WerkzeugResponse:
flash('Invalid submission: please submit at least a URL.', 'error') flash('Invalid submission: please submit at least a URL.', 'error')
return render_template('simple_capture.html') return render_template('simple_capture.html')
capture_query: CaptureSettings = {} capture_query: CaptureSettings = {}
if request.form.get('auto_report'):
path = get_homedir() /'config'/ 'users' / (user + ".json")
if os.path.isfile(path):
email = get_config(user, 'email')
capture_query['auto_report'] = {"email": email}
else:
capture_query['auto_report'] = True
if request.form.get('url'):
capture_query['url'] = request.form['url'] capture_query['url'] = request.form['url']
perma_uuid = lookyloo.enqueue_capture(capture_query, source='web', user=user, perma_uuid = lookyloo.enqueue_capture(capture_query, source='web', user=user,
authenticated=flask_login.current_user.is_authenticated) authenticated=flask_login.current_user.is_authenticated)
time.sleep(2)
if perma_uuid: if perma_uuid:
flash('Recording is in progress and is reported automatically.', 'success') flash('Recording is in progress and is reported automatically.', 'success')
time.sleep(2)
return redirect(url_for('simple_capture')) return redirect(url_for('simple_capture'))
elif request.form.get('urls'):
for url in request.form['urls'].strip().split('\n'):
if not url:
continue
query = capture_query.copy()
query['url'] = url
new_capture_uuid = lookyloo.enqueue_capture(query, source='web', user=user,
authenticated=flask_login.current_user.is_authenticated)
if new_capture_uuid:
flash('Recording is in progress and is reported automatically.', 'success')
return redirect(url_for('simple_capture'))
# render template # render template
return render_template('simple_capture.html') return render_template('simple_capture.html')

View File

@ -122,6 +122,4 @@
} }
}) })
</script> </script>
{% endblock %} {% endblock %}