From c52509614e11a15f613dfb2bbabdc48277c4ad9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 9 Jun 2021 17:59:24 -0700 Subject: [PATCH] new: get capture info API call --- lookyloo/lookyloo.py | 7 +++++++ website/web/__init__.py | 4 ++-- website/web/genericapi.py | 8 ++++++++ website/web/templates/tree.html | 12 ++++++------ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index 0f74c57e..3efc2200 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -324,6 +324,13 @@ class Lookyloo(): ct = self.get_crawled_tree(capture_uuid) return ct.root_hartree.stats + def get_info(self, capture_uuid: str, /) -> Dict[str, Any]: + '''Get basic information about the capture.''' + ct = self.get_crawled_tree(capture_uuid) + to_return = {'url': ct.root_url, 'title': ct.root_hartree.har.initial_title, + 'capture_time': ct.start_time.isoformat(), 'user_agent': ct.user_agent} + return to_return + def get_meta(self, capture_uuid: str, /) -> Dict[str, str]: '''Get the meta informations from a capture (mostly, details about the User Agent used.)''' capture_dir = self._get_capture_dir(capture_uuid) diff --git a/website/web/__init__.py b/website/web/__init__.py index 6638cd13..4f6df541 100644 --- a/website/web/__init__.py +++ b/website/web/__init__.py @@ -550,6 +550,7 @@ def tree(tree_uuid: str, node_uuid: Optional[str]=None): ct = lookyloo.get_crawled_tree(tree_uuid) b64_thumbnail = lookyloo.get_screenshot_thumbnail(tree_uuid, for_datauri=True) screenshot_size = lookyloo.get_screenshot(tree_uuid).getbuffer().nbytes + info = lookyloo.get_info(tree_uuid) meta = lookyloo.get_meta(tree_uuid) hostnode_to_highlight = None if node_uuid: @@ -567,8 +568,7 @@ def tree(tree_uuid: str, node_uuid: Optional[str]=None): print(e) pass return render_template('tree.html', tree_json=ct.to_json(), - start_time=ct.start_time.isoformat(), - user_agent=ct.user_agent, root_url=ct.root_url, + info=info, tree_uuid=tree_uuid, public_domain=lookyloo.public_domain, screenshot_thumbnail=b64_thumbnail, page_title=cache.title, screenshot_size=screenshot_size, diff --git a/website/web/genericapi.py b/website/web/genericapi.py index 7bb7bc24..6232020f 100644 --- a/website/web/genericapi.py +++ b/website/web/genericapi.py @@ -246,6 +246,14 @@ class CaptureStats(Resource): return lookyloo.get_statistics(capture_uuid) +@api.route('/json//info') +@api.doc(description='Get basic information about the capture.', + params={'capture_uuid': 'The UUID of the capture'}) +class CaptureInfo(Resource): + def get(self, capture_uuid: str): + return lookyloo.get_info(capture_uuid) + + @api.route('/json//cookies') @api.doc(description='Get the complete cookie jar created during the capture.', params={'capture_uuid': 'The UUID of the capture'}) diff --git a/website/web/templates/tree.html b/website/web/templates/tree.html index 856b8ad0..f4dd7663 100644 --- a/website/web/templates/tree.html +++ b/website/web/templates/tree.html @@ -3,14 +3,14 @@ {% from 'bootstrap/utils.html' import render_messages %} {% from "macros.html" import shorten_string %} -{% block title %}Capture of {{root_url}}{% endblock %} +{% block title %}Capture of {{info['url']}}{% endblock %} {% block card %} { document.getElementById("start_time").innerHTML = `${capture_starttime.getFullYear()}-${("0" + (capture_starttime.getMonth() + 1)).slice(-2)}-${("0" + capture_starttime.getDate()).slice(-2)} ${capture_starttime.toLocaleTimeString()}`; @@ -342,16 +342,16 @@