Skip to content

Commit

Permalink
frontend: Show warning when an analysis is outdated
Browse files Browse the repository at this point in the history
  • Loading branch information
maringuu committed Jul 10, 2023
1 parent 026c78a commit 86df387
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/install/requirements_frontend.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ bleach==5.0.1

# Used to start radare
docker-compose==1.29.2

# Figuring out if the analysis is outdated
semver==3.0.1
1 change: 1 addition & 0 deletions src/web_interface/components/jinja_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def _setup_filters(self): # pylint: disable=too-many-statements
self._app.jinja_env.filters['replace_uid_with_hid_link'] = self._filter_replace_uid_with_hid_link
self._app.jinja_env.filters['replace_uid_with_hid'] = self._filter_replace_uid_with_hid
self._app.jinja_env.filters['replace_underscore'] = flt.replace_underscore_filter
self._app.jinja_env.filters['semver_is_compatible'] = flt.semver_is_compatible
self._app.jinja_env.filters['sort_chart_list_by_name'] = flt.sort_chart_list_by_name
self._app.jinja_env.filters['sort_chart_list_by_value'] = flt.sort_chart_list_by_value
self._app.jinja_env.filters['sort_comments'] = flt.sort_comments
Expand Down
16 changes: 16 additions & 0 deletions src/web_interface/filter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import binascii
from typing import Union
import semver
import json
import logging
import random
Expand Down Expand Up @@ -422,3 +424,17 @@ def get_searchable_crypto_block(crypto_material: str) -> str:
'''crypto material plugin results contain spaces and line breaks -> get a contiguous block without those'''
blocks = crypto_material.replace(' ', '').split('\n')
return sorted(blocks, key=len, reverse=True)[0]


def semver_is_compatible(version: Union[str, semver.Version], other: Union[str, semver.Version]) -> bool:
"""A warpper around ``semver.Version.is_compatible``.
Always returns ``True`` if the versions are not semver"""
try:
if isinstance(version, str):
version = semver.Version.parse(version)
if isinstance(other, str):
other = semver.Version.parse(other)
except ValueError:
return True

return version.is_compatible(other)
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,36 @@
<td>{{ analysis_metadata['analysis_date'] | nice_unix_time }}</td>
</tr>
{% endif %}
{% if analysis_metadata['plugin_version'] %}
<tr>
<td class="table-head-light">Plugin Version</td>
<td>{{ analysis_metadata['plugin_version']}}</td>
</tr>
{% endif %}
{% if analysis_metadata['system_version'] %}
<tr>
<td class="table-head-light">System Version</td>
<td>{{ analysis_metadata['system_version']}}</td>
</tr>
{% endif %}
{% if analysis_result is not none and 'skipped' not in analysis_result %}
{% block analysis_result_details %}

{% endblock %}
{% set version_backend = analysis_plugin_dict[selected_analysis][3] %}
{% set version_database = analysis_metadata['plugin_version'] %}

{% if version_database | semver_is_compatible(version_backend) %}
{% if analysis_metadata['plugin_version'] %}
<tr>
<td class="table-head-light">Plugin Version</td>
<td>{{ analysis_metadata['plugin_version']}}</td>
</tr>
{% endif %}
{% if analysis_metadata['system_version'] %}
<tr>
<td class="table-head-light">System Version</td>
<td>{{ analysis_metadata['system_version']}}</td>
</tr>
{% endif %}
{% if analysis_result is not none and 'skipped' not in analysis_result %}
{% block analysis_result_details %}

{% endblock %}
{% endif %}
{% else %}
<tr>
<td class="table-warning">Analysis outdated</td>
<td>
Plugin version {{ version_backend | string }} is incompatible with {{ version_database | string }}.
Please update the analysis.
</td>
</tr>
{% endif %}
</tbody>
</table>
Expand Down

0 comments on commit 86df387

Please sign in to comment.