[fix] make /stats more CSP compliant - oscar theme

Replace oscar theme's *styles* (see below) by CSP compliant implementation in
``searx/static/themes/__common__/less/stats.less`` ::

    ./oscar/stats.html:29:  <th scope="col" style="width:20rem;">{{ th_sort('name', _("Engine name")) }}</th>
    ./oscar/stats.html:30:  <th scope="col" style="width:7rem; text-align: right;">{{ th_sort('score', _('Scores')) }}</th>
    ./oscar/stats.html:33:  <th scope="col" style="text-align: right;">{{ th_sort('reliability', _('Reliability')) }}</th>
    ./oscar/stats.html:38:  <td style="text-align: right;">
    ./oscar/stats.html:91:  <td style="text-align: right;"> {{ engine_reliabilities.get(engine_stat.name, {}).get('reliablity') }}</td>
    ./oscar/stats.html:109: <tbody style="padding-top: 1rem;">
    ./oscar/stats.html:112: <th scope="row" style="width: 10rem">{{ _('Exception') }}</th><td>{{ error.exception_classname }}</td>
    ./oscar/stats.html:114: <th scope="row" style="width: 10rem">{{ _('Message') }}</th><td>{{ error.log_message }}</td>
    ./oscar/stats.html:116: <th scope="row" style="width: 10rem">{{ _('Percentage') }}</th><td style="width: 10rem">{{ error.percentage }}</td>
    ./oscar/stats.html:121: <span style="border-right: 1px solid gray; padding: 0 1rem 0 0; margin: 0 0 0 0.5rem;">{{ param }}</span>
    ./oscar/stats.html:138: <th scope="col" style="width: 10rem">{{ _('Failed test') }}</th>

Reported-by: https://github.com/searxng/searxng/issues/57
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2021-05-16 17:57:04 +02:00
parent 0a6c488417
commit 34859d0e58

View file

@ -24,18 +24,18 @@
{% include 'oscar/messages/no_data_available.html' %} {% include 'oscar/messages/no_data_available.html' %}
</div> </div>
{% else %} {% else %}
<table class="table table-hover table-condensed table-striped"> <table class="table table-hover table-condensed table-striped engine-stats">
<tr> <tr>
<th scope="col" style="width:20rem;">{{ th_sort('name', _("Engine name")) }}</th> <th scope="col" class="engine-name">{{ th_sort('name', _("Engine name")) }}</th>
<th scope="col" style="width:7rem; text-align: right;">{{ th_sort('score', _('Scores')) }}</th> <th scope="col" class="engine-scores">{{ th_sort('score', _('Scores')) }}</th>
<th scope="col">{{ th_sort('result_count', _('Result count')) }}</th> <th scope="col" class="result-count">{{ th_sort('result_count', _('Result count')) }}</th>
<th scope="col">{{ th_sort('time', _('Response time')) }}</th> <th scope="col" class="response-time">{{ th_sort('time', _('Response time')) }}</th>
<th scope="col" style="text-align: right;">{{ th_sort('reliability', _('Reliability')) }}</th> <th scope="col" class="engine-reliability">{{ th_sort('reliability', _('Reliability')) }}</th>
</tr> </tr>
{% for engine_stat in engine_stats.get('time', []) %} {% for engine_stat in engine_stats.get('time', []) %}
<tr> <tr>
<td><a href="{{ url_for('stats', engine=engine_stat.name|e) }}">{{ engine_stat.name }}</a></td> <td class="engine-name"><a href="{{ url_for('stats', engine=engine_stat.name|e) }}">{{ engine_stat.name }}</a></td>
<td style="text-align: right;"> <td class="engine-scores">
{%- if engine_stat.score -%} {%- if engine_stat.score -%}
<span aria-labelledby="{{engine_stat.name}}_score" >{{ engine_stat.score|round(1) }}</span> <span aria-labelledby="{{engine_stat.name}}_score" >{{ engine_stat.score|round(1) }}</span>
<div class="engine-tooltip text-left" role="tooltip" id="{{engine_stat.name}}_score">{{- "" -}} <div class="engine-tooltip text-left" role="tooltip" id="{{engine_stat.name}}_score">{{- "" -}}
@ -43,7 +43,7 @@
</div> </div>
{%- endif -%} {%- endif -%}
</td> </td>
<td> <td class="result-count">
{%- if engine_stat.result_count -%} {%- if engine_stat.result_count -%}
<div class="bar-chart-value">{{- engine_stat.result_count | int -}}</div>{{- "" -}} <div class="bar-chart-value">{{- engine_stat.result_count | int -}}</div>{{- "" -}}
<div class="bar-chart-graph" aria-hidden="true"> <div class="bar-chart-graph" aria-hidden="true">
@ -51,7 +51,7 @@
</div> </div>
{%- endif -%} {%- endif -%}
</td> </td>
<td> <td class="response-time">
{%- if engine_stat.total -%} {%- if engine_stat.total -%}
<div class="bar-chart-value">{{- engine_stat.total | round(1) -}}</div>{{- "" -}} <div class="bar-chart-value">{{- engine_stat.total | round(1) -}}</div>{{- "" -}}
<div class="bar-chart-graph" aria-labelledby="{{engine_stat.name}}_time" aria-hidden="true"> <div class="bar-chart-graph" aria-labelledby="{{engine_stat.name}}_time" aria-hidden="true">
@ -88,7 +88,7 @@
</div> </div>
{%- endif -%} {%- endif -%}
</td> </td>
<td style="text-align: right;"> {{ engine_reliabilities.get(engine_stat.name, {}).get('reliablity') }}</td> <td class="engine-reliability"> {{ engine_reliabilities.get(engine_stat.name, {}).get('reliablity') }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
@ -105,20 +105,20 @@
{% set ns.first = false %} {% set ns.first = false %}
<h3>{% if secondary %}{{ _('Warnings') }}{% else %}{{ _('Errors and exceptions') }}{% endif %}</h3> <h3>{% if secondary %}{{ _('Warnings') }}{% else %}{{ _('Errors and exceptions') }}{% endif %}</h3>
{% endif %} {% endif %}
<table class="table table-striped table-bordered"> <table class="table table-striped table-bordered engine-error">
<tbody style="padding-top: 1rem;"> <tbody>
<tr> <tr>
{%- if error.exception_classname -%} {%- if error.exception_classname -%}
<th scope="row" style="width: 10rem">{{ _('Exception') }}</th><td>{{ error.exception_classname }}</td> <th scope="row" class="engine-error-type">{{ _('Exception') }}</th><td>{{ error.exception_classname }}</td>
{%- elif error.log_message -%} {%- elif error.log_message -%}
<th scope="row" style="width: 10rem">{{ _('Message') }}</th><td>{{ error.log_message }}</td> <th scope="row" class="engine-error-type">{{ _('Message') }}</th><td>{{ error.log_message }}</td>
{%- endif -%} {%- endif -%}
<th scope="row" style="width: 10rem">{{ _('Percentage') }}</th><td style="width: 10rem">{{ error.percentage }}</td> <th scope="row" class="engine-error-type">{{ _('Percentage') }}</th><td class="engine-error-type">{{ error.percentage }}</td>
</tr> </tr>
{% if error.log_parameters and error.log_parameters != (None, None, None) %}<tr><th scope="row">{{ _('Parameter') }}</th>{{- '' -}} {% if error.log_parameters and error.log_parameters != (None, None, None) %}<tr><th scope="row">{{ _('Parameter') }}</th>{{- '' -}}
<td colspan="3"> <td colspan="3">
{%- for param in error.log_parameters -%} {%- for param in error.log_parameters -%}
<span style="border-right: 1px solid gray; padding: 0 1rem 0 0; margin: 0 0 0 0.5rem;">{{ param }}</span> <span class="log_parameters">{{ param }}</span>
{%- endfor -%} {%- endfor -%}
</td> </td>
</tr> </tr>
@ -135,7 +135,7 @@
<h3>{{ _('Checker') }}</h3> <h3>{{ _('Checker') }}</h3>
<table class="table table-striped table-bordered"> <table class="table table-striped table-bordered">
<tr> <tr>
<th scope="col" style="width: 10rem">{{ _('Failed test') }}</th> <th scope="col" class="failed-test">{{ _('Failed test') }}</th>
<th scope="col">{{ _('Comment(s)') }}</th> <th scope="col">{{ _('Comment(s)') }}</th>
</tr> </tr>
{% for test_name, results in engine_reliabilities[selected_engine_name].checker.items() %} {% for test_name, results in engine_reliabilities[selected_engine_name].checker.items() %}