on master help sign in
Merge pull request #2373 from kvch/display-https-engines

Display if an engine does not support HTTPS requests

commit820b468bfe96f693d60ce06f1e78af51f00deefc authorNoémi Ványi <kvch@users.noreply.github.com> dateWed 9 Dec 2020, 22:48 (6 years ago) parent42a19483a63dfb
10 files changed+46−11
searx/engines/__init__.py+32 searx/engines/acgsou.py+2−2 searx/engines/arxiv.py+1−1 searx/engines/currency_convert.py+1 searx/engines/dictzone.py+1 searx/engines/translated.py+1 searx/templates/oscar/macros.html+2−2 searx/templates/oscar/preferences.html+2−2 searx/templates/simple/macros.html+2−2 searx/templates/simple/preferences.html+2−2
searx/engines/__init__.py+32
@@ -20,6 +20,7 @@ import sys
2020import threading
2121from os.path import realpath, dirname
2222from babel.localedata import locale_identifiers
23+from urllib.parse import urlparse
2324from flask_babel import gettext
2425from operator import itemgetter
2526from searx import settings
@@ -289,3 +290,34 @@ def initialize_engines(engine_list):
289290 if init_fn:
290291 logger.debug('%s engine: Starting background initialization', engine_name)
291292 threading.Thread(target=engine_init, args=(engine_name, init_fn)).start()
293+
294+ _set_https_support_for_engine(engine)
295+
296+
297+def _set_https_support_for_engine(engine):
298+ # check HTTPS support if it is not disabled
299+ if not engine.offline and not hasattr(engine, 'https_support'):
300+ params = engine.request('http_test', {
301+ 'method': 'GET',
302+ 'headers': {},
303+ 'data': {},
304+ 'url': '',
305+ 'cookies': {},
306+ 'verify': True,
307+ 'auth': None,
308+ 'pageno': 1,
309+ 'time_range': None,
310+ 'language': '',
311+ 'safesearch': False,
312+ 'is_test': True,
313+ 'category': 'files',
314+ 'raise_for_status': True,
315+ })
316+
317+ if 'url' not in params:
318+ return
319+
320+ parsed_url = urlparse(params['url'])
321+ https_support = parsed_url.scheme == 'https'
322+
323+ setattr(engine, 'https_support', https_support)
searx/engines/acgsou.py+2−2
@@ -18,7 +18,7 @@ categories = ['files', 'images', 'videos', 'music']
1818paging = True
1919
2020# search-url
21−base_url = 'http://www.acgsou.com/'
21+base_url = 'https://www.acgsou.com/'
2222search_url = base_url + 'search.php?{query}&page={offset}'
2323# xpath queries
2424xpath_results = '//table[contains(@class, "list_style table_fixed")]//tr[not(th)]'
@@ -40,7 +40,7 @@ def response(resp):
4040 for result in eval_xpath_list(dom, xpath_results):
4141 # defaults
4242 filesize = 0
43− magnet_link = "magnet:?xt=urn:btih:{}&tr=http://tracker.acgsou.com:2710/announce"
43+ magnet_link = "magnet:?xt=urn:btih:{}&tr=https://tracker.acgsou.com:2710/announce"
4444
4545 category = extract_text(eval_xpath_getindex(result, xpath_category, 0, default=[]))
4646 page_a = eval_xpath_getindex(result, xpath_title, 0)
searx/engines/arxiv.py+1−1
@@ -19,7 +19,7 @@ from searx.utils import eval_xpath_list, eval_xpath_getindex
1919categories = ['science']
2020paging = True
2121
22−base_url = 'http://export.arxiv.org/api/query?search_query=all:'\
22+base_url = 'https://export.arxiv.org/api/query?search_query=all:'\
2323 + '{query}&start={offset}&max_results={number_of_results}'
2424
2525# engine dependent config
searx/engines/currency_convert.py+1
@@ -9,6 +9,7 @@ url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'
99weight = 100
1010
1111parser_re = re.compile('.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
12+https_support = True
1213
1314
1415def normalize_name(name):
searx/engines/dictzone.py+1
@@ -20,6 +20,7 @@ weight = 100
2020
2121parser_re = re.compile('.*?([a-z]+)-([a-z]+) ([^ ]+)$', re.I)
2222results_xpath = './/table[@id="r"]/tr'
23+https_support = True
2324
2425
2526def request(query, params):
searx/engines/translated.py+1
@@ -15,6 +15,7 @@ categories = ['general']
1515url = 'https://api.mymemory.translated.net/get?q={query}&langpair={from_lang}|{to_lang}{key}'
1616web_url = 'https://mymemory.translated.net/en/{from_lang}/{to_lang}/{query}'
1717weight = 100
18+https_support = True
1819
1920parser_re = re.compile('.*?([a-z]+)-([a-z]+) (.{2,})$', re.I)
2021api_key = ''
searx/templates/oscar/macros.html+2−2
@@ -1,6 +1,6 @@
11<!-- Draw glyphicon icon from bootstrap-theme -->
2−{% macro icon(action) -%}
3− <span class="glyphicon glyphicon-{{ action }}"></span>
2+{% macro icon(action, alt) -%}
3+ <span title="{{ alt }}" class="glyphicon glyphicon-{{ action }}"></span>
44{%- endmacro %}
55
66<!-- Draw favicon -->
searx/templates/oscar/preferences.html+2−2
@@ -230,8 +230,8 @@
230230 <td class="onoff-checkbox">
231231 {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in disabled_engines) }}
232232 </td>
233− <th scope="row">{{ search_engine.name }}</th>
234− <td class="name">{{ shortcuts[search_engine.name] }}</td>
233+ <th scope="row">{% if not search_engine.https_support %}{{ icon('exclamation-sign', 'No HTTPS') }}{% endif %} {{ search_engine.name }}</td></th>
234+ <td class="name">{{ shortcuts[search_engine.name] }}
235235 <td>{{ support_toggle(stats[search_engine.name].supports_selected_language) }}</td>
236236 <td>{{ support_toggle(search_engine.safesearch==True) }}</td>
237237 <td>{{ support_toggle(search_engine.time_range_support==True) }}</td>
searx/templates/simple/macros.html+2−2
@@ -1,6 +1,6 @@
11<!-- Draw glyphicon icon from bootstrap-theme -->
2−{% macro icon(action) -%}
3− <span class="ion-icon-big ion-{{ action }}"></span>
2+{% macro icon(action, alt) -%}
3+ <span title="{{ alt }}" class="ion-icon-big ion-{{ action }}"></span>
44{%- endmacro %}
55
66{% macro icon_small(action) -%}
searx/templates/simple/preferences.html+2−2
@@ -1,4 +1,4 @@
1−{% from 'simple/macros.html' import tabs_open, tabs_close, tab_header, tab_footer, checkbox_onoff, checkbox %}
1+{% from 'simple/macros.html' import icon, tabs_open, tabs_close, tab_header, tab_footer, checkbox_onoff, checkbox %}
22
33{% extends "simple/base.html" %}
44
@@ -121,7 +121,7 @@
121121 {% set engine_id = 'engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_') %}
122122 <tr>
123123 <td class="engine_checkbox">{{ checkbox_onoff(engine_id, (search_engine.name, categ) in disabled_engines) }}</td>
124− <th class="name">{{ search_engine.name }}</th>
124+ <th class="name">{% if not search_engine.https_support %}{{ icon('warning', 'No HTTPS') }}{% endif %} {{ search_engine.name }}</th>
125125 <td class="shortcut">{{ shortcuts[search_engine.name] }}</td>
126126 <td>{{ checkbox(engine_id + '_supported_languages', current_language == 'all' or current_language in search_engine.supported_languages or current_language.split('-')[0] in search_engine.supported_languages, true, true) }}</td>
127127 <td>{{ checkbox(engine_id + '_safesearch', search_engine.safesearch==True, true, true) }}</td>