diff --git a/website/web/__init__.py b/website/web/__init__.py index 124cc37d..fb7beda3 100644 --- a/website/web/__init__.py +++ b/website/web/__init__.py @@ -279,6 +279,7 @@ def get_icon(icon_id: str) -> Icon | None: app.jinja_env.globals.update(get_icon=get_icon) +app.jinja_env.globals.update(generic_type=mimetype_to_generic) def get_tz_info() -> tuple[str | None, str, set[str]]: @@ -366,8 +367,7 @@ def get_all_body_hashes(capture_uuid: str, /) -> dict[str, dict[str, int | str | continue if node.body_hash not in to_return: total_captures = get_indexing(flask_login.current_user).get_captures_body_hash_count(node.body_hash) - generic_type = mimetype_to_generic(node.mimetype) - to_return[node.body_hash] = {'total_captures': total_captures, 'generic_type': generic_type, 'nodes': []} + to_return[node.body_hash] = {'total_captures': total_captures, 'mimetype': node.mimetype, 'nodes': []} to_return[node.body_hash]['nodes'].append((node, False)) # type: ignore[union-attr] # get embedded retources (if any) - need their type too if 'embedded_ressources' in node.features: @@ -375,8 +375,7 @@ def get_all_body_hashes(capture_uuid: str, /) -> dict[str, dict[str, int | str | for h, blob in blobs: if h not in to_return: total_captures = get_indexing(flask_login.current_user).get_captures_body_hash_count(h) - generic_type = mimetype_to_generic(mimetype) - to_return[h] = {'total_captures': total_captures, 'generic_type': generic_type, 'nodes': []} + to_return[h] = {'total_captures': total_captures, 'mimetype': mimetype, 'nodes': []} to_return[h]['nodes'].append((node, True)) # type: ignore[union-attr] return to_return @@ -548,7 +547,7 @@ def get_hostnode_investigator(capture_uuid: str, /, node_uuid: str) -> tuple[Hos # Index lookup # %%% Full body %%% if freq := get_indexing(flask_login.current_user).get_captures_body_hash_count(url.body_hash): - to_append['body_hash_details'] = {'hash_freq': freq} + to_append['body_hash_freq'] = freq # %%% Embedded ressources %%% if hasattr(url, 'embedded_ressources') and url.embedded_ressources: @@ -1778,7 +1777,18 @@ def favicon_detail(favicon_sha512: str) -> str: @app.route('/body_hashes/', methods=['GET']) def body_hash_details(body_hash: str) -> str: from_popup = True if (request.args.get('from_popup') and request.args.get('from_popup') == 'True') else False - return render_template('body_hash.html', body_hash=body_hash, from_popup=from_popup) + filename = '' + mimetype = '' + b64 = '' + if uuids := get_indexing(flask_login.current_user).get_hash_uuids(body_hash): + # got UUIDs for this hash + capture_uuid, urlnode_uuid = uuids + if ressource := lookyloo.get_ressource(capture_uuid, urlnode_uuid, body_hash): + filename, body, mimetype = ressource + if mimetype_to_generic(mimetype) == 'image': + b64 = base64.b64encode(body.read()).decode() + return render_template('body_hash.html', body_hash=body_hash, from_popup=from_popup, + filename=filename, mimetype=mimetype, b64=b64) @app.route('/urls/', methods=['GET']) diff --git a/website/web/helpers.py b/website/web/helpers.py index 64beeefe..f2b9bd36 100644 --- a/website/web/helpers.py +++ b/website/web/helpers.py @@ -128,8 +128,10 @@ def get_indexing(user: User | None) -> Indexing: return get_indexing_cache(full=bool(user and user.is_authenticated)) -def mimetype_to_generic(mimetype: str) -> str: - if 'javascript' in mimetype or 'ecmascript' in mimetype or mimetype.startswith('js'): +def mimetype_to_generic(mimetype: str | None) -> str: + if not mimetype or mimetype == 'none': + return 'unset_mimetype' + elif 'javascript' in mimetype or 'ecmascript' in mimetype or mimetype.startswith('js'): return 'js' elif (mimetype.startswith('image') or mimetype.startswith('img') @@ -180,7 +182,5 @@ def mimetype_to_generic(mimetype: str) -> str: elif ('application/gzip' in mimetype or 'application/zip' in mimetype): return 'archive' - elif not mimetype or mimetype == 'none': - return 'unset_mimetype' else: return 'unknown_mimetype' diff --git a/website/web/templates/body_hash.html b/website/web/templates/body_hash.html index dcccb1e4..8bb31ef8 100644 --- a/website/web/templates/body_hash.html +++ b/website/web/templates/body_hash.html @@ -17,8 +17,24 @@ {%endif%}
-
{{ body_hash }}
- Download +

+ {% if filename %} + Filename: {{ filename }}
+ {% endif %} + {% if mimetype %} + Mimetype: {{ mimetype }}
+ {% endif %} + Hash:
{{ body_hash }}
+ {% if b64 %} + Preview:
+ + + + {% else %} + Download + {% endif %} +

diff --git a/website/web/templates/hostname_popup.html b/website/web/templates/hostname_popup.html index 15b53b6a..5c2a4834 100644 --- a/website/web/templates/hostname_popup.html +++ b/website/web/templates/hostname_popup.html @@ -2,11 +2,12 @@ {% from "macros.html" import known_content_details %} {% from "macros.html" import ressource_legitimacy_details %} {% from "macros.html" import indexed_cookies %} -{% from "macros.html" import popup_icons_request %} -{% from "macros.html" import popup_icons_response %} +{% from "macros.html" import request_cookies_icon %} +{% from "macros.html" import response_cookies_icon %} +{% from "macros.html" import hash_info%} +{% from "macros.html" import redirect_response %} {% from "macros.html" import shorten_string %} {% from "macros.html" import other_captures_table %} -{% from "macros.html" import get_ressource_button %} {% from "macros.html" import context_form %} {% from "macros.html" import pandora_submit %} @@ -127,7 +128,7 @@
{# Start list of URLs #} -
{{ shorten_string(h, 10) }}
- {{ get_ressource_button(capture_uuid, urlnode_uuid, h, 'Download sample', mimetype and mimetype.startswith('image')) }} + {{ hash_icon(capture_uuid, urlnode_uuid, mimetype, h) }}
{{ freq }} {{ context['type'] }} - {{ context['details'] }}
diff --git a/website/web/templates/tree_body_hashes.html b/website/web/templates/tree_body_hashes.html index a784c52e..bd67992a 100644 --- a/website/web/templates/tree_body_hashes.html +++ b/website/web/templates/tree_body_hashes.html @@ -14,7 +14,7 @@
{{ info['total_captures'] }} - {{hash_icon(tree_uuid, info['nodes'][0][0].uuid, info['generic_type'], body_hash)}} + {{hash_icon(tree_uuid, info['nodes'][0][0].uuid, info['mimetype'], body_hash)}}
    diff --git a/website/web/templates/tree_hostnames.html b/website/web/templates/tree_hostnames.html index 597ce490..45dadd4a 100644 --- a/website/web/templates/tree_hostnames.html +++ b/website/web/templates/tree_hostnames.html @@ -1,5 +1,3 @@ -{% from "macros.html" import popup_icons_response %} -