From 283d33d9ae3962428ff3bffc017da4f20c139ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Stucke?= Date: Fri, 6 Oct 2023 12:28:41 +0200 Subject: [PATCH] made analysis tags clickable and link to the summary --- .../integration/web_interface/test_filter.py | 16 +++++++++++++--- src/web_interface/filter.py | 5 ++++- .../static/js/show_analysis_summary.js | 9 +++++++-- .../templates/generic_view/tags.html | 3 +++ src/web_interface/templates/show_analysis.html | 15 ++++++++++++--- src/web_interface/templates/summary.html | 2 +- 6 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/test/integration/web_interface/test_filter.py b/src/test/integration/web_interface/test_filter.py index ccaf88b36..8b1adba12 100644 --- a/src/test/integration/web_interface/test_filter.py +++ b/src/test/integration/web_interface/test_filter.py @@ -25,11 +25,11 @@ def test_list_group_collapse(frontend): @pytest.mark.parametrize( ('tag_dict', 'output'), [ - ({'a': 'danger'}, ' a'), + ({'a': 'danger'}, ' a'), ( {'a': 'danger', 'b': 'primary'}, - ' a' - ' b', + ' a' + ' b', ), (None, ''), ], @@ -51,6 +51,16 @@ def test_render_analysis_tags_success(frontend): assert '> wow<' in output +def test_render_analysis_tags_link(frontend): + plugin, uid, root_uid = 'plugin1', 'foo', 'bar' + tags = {plugin: {'tag': {'color': 'success', 'value': 'some_value'}}} + with frontend.app.app_context(): + output = render_analysis_tags(tags, uid=uid, root_uid=root_uid) + assert 'onclick' in output + link = f'/analysis/{uid}/{plugin}/ro/{root_uid}?load_summary=true' + assert link in output + + def test_render_analysis_tags_fix(frontend): tags = {'such plugin': {'tag': {'color': 'very color', 'value': 'wow'}}} with frontend.app.app_context(): diff --git a/src/web_interface/filter.py b/src/web_interface/filter.py index ae8694e45..fc0cbf266 100644 --- a/src/web_interface/filter.py +++ b/src/web_interface/filter.py @@ -281,7 +281,7 @@ def render_fw_tags(tag_dict, size=14): return output -def render_analysis_tags(tags, size=14): +def render_analysis_tags(tags, uid=None, root_uid=None, size=14): output = '' if tags: for plugin_name in tags: @@ -295,6 +295,9 @@ def render_analysis_tags(tags, size=14): value=tag['value'], tooltip=f'{plugin_name}: {key}', size=size, + plugin=plugin_name, + root_uid=root_uid, + uid=uid, ) return output diff --git a/src/web_interface/static/js/show_analysis_summary.js b/src/web_interface/static/js/show_analysis_summary.js index e5e240378..013502fed 100644 --- a/src/web_interface/static/js/show_analysis_summary.js +++ b/src/web_interface/static/js/show_analysis_summary.js @@ -1,9 +1,14 @@ -function load_summary(uid, selected_analysis){ +function load_summary(uid, selected_analysis, focus=false){ $("#summary-button").css("display", "none"); let summary_gif = $("#loading-summary-gif"); summary_gif.css("display", "block"); $("#summary-div").load( `/ajax_get_summary/${uid}/${selected_analysis}`, - () => {summary_gif.css("display", "none");} + () => { + summary_gif.css("display", "none"); + if (focus === true) { + location.href = "#summary-heading"; + } + } ); } diff --git a/src/web_interface/templates/generic_view/tags.html b/src/web_interface/templates/generic_view/tags.html index 63aaac7bf..c2ab3f65a 100644 --- a/src/web_interface/templates/generic_view/tags.html +++ b/src/web_interface/templates/generic_view/tags.html @@ -5,6 +5,9 @@ data-toggle="tooltip" title="{{ tooltip | replace_underscore }}" {%- endif %} + {% if uid -%} + onclick="location.href='http://localhost:5000/analysis/{{ uid }}/{{ plugin }}/ro/{{ root_uid }}?load_summary=true'" + {%- endif %} > {{ value }} diff --git a/src/web_interface/templates/show_analysis.html b/src/web_interface/templates/show_analysis.html index 1f8256c74..85eaf1608 100644 --- a/src/web_interface/templates/show_analysis.html +++ b/src/web_interface/templates/show_analysis.html @@ -114,7 +114,7 @@

{{ firmware.uid | replace_uid_with_hid(root_uid=root_uid) | safe }}
{% if firmware.analysis_tags or firmware.tags %} - {{ firmware.analysis_tags | render_analysis_tags | safe }}{{ firmware.tags | render_fw_tags | safe }}
+ {{ firmware.analysis_tags | render_analysis_tags(uid, root_uid) | safe }}{{ firmware.tags | render_fw_tags | safe }}
{% endif %} UID: {{ uid | safe }}

@@ -316,7 +316,7 @@ - + {%- endif -%} @@ -358,7 +358,7 @@ {%- set is_text_preview = firmware.processed_analysis["file_type"]["result"]['mime'][0:5] == "text/" or firmware.processed_analysis["file_type"]["result"]['mime'][0:6] == "image/" %} - + {% endblock %} diff --git a/src/web_interface/templates/summary.html b/src/web_interface/templates/summary.html index 7bed6f7d5..34643e3da 100644 --- a/src/web_interface/templates/summary.html +++ b/src/web_interface/templates/summary.html @@ -5,7 +5,7 @@ - Summary for Included Files + Summary for Included Files {% if summary_of_included_files %}