on master help sign in
Merge pull request #2373 from kvch/display-https-engines
820b468Noémi Ványi
searx/engines/__init__.py+32
@@ -20,6 +20,7 @@ import sys
20import threading
20import threading
21from os.path import realpath, dirname
21from os.path import realpath, dirname
22from babel.localedata import locale_identifiers
22from babel.localedata import locale_identifiers
23+from urllib.parse import urlparse
23from flask_babel import gettext
24from flask_babel import gettext
24from operator import itemgetter
25from operator import itemgetter
25from searx import settings
26from searx import settings
@@ -289,3 +290,34 @@ def initialize_engines(engine_list):
289 if init_fn:
290 if init_fn:
290 logger.debug('%s engine: Starting background initialization', engine_name)
291 logger.debug('%s engine: Starting background initialization', engine_name)
291 threading.Thread(target=engine_init, args=(engine_name, init_fn)).start()
292 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']
18paging = True
18paging = True
19
19
20# search-url
20# search-url
21−base_url = 'http://www.acgsou.com/'
21+base_url = 'https://www.acgsou.com/'
22search_url = base_url + 'search.php?{query}&page={offset}'
22search_url = base_url + 'search.php?{query}&page={offset}'
23# xpath queries
23# xpath queries
24xpath_results = '//table[contains(@class, "list_style table_fixed")]//tr[not(th)]'
24xpath_results = '//table[contains(@class, "list_style table_fixed")]//tr[not(th)]'
@@ -40,7 +40,7 @@ def response(resp):
40 for result in eval_xpath_list(dom, xpath_results):
40 for result in eval_xpath_list(dom, xpath_results):
41 # defaults
41 # defaults
42 filesize = 0
42 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"
44
44
45 category = extract_text(eval_xpath_getindex(result, xpath_category, 0, default=[]))
45 category = extract_text(eval_xpath_getindex(result, xpath_category, 0, default=[]))
46 page_a = eval_xpath_getindex(result, xpath_title, 0)
46 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
19categories = ['science']
19categories = ['science']
20paging = True
20paging = True
21
21
22−base_url = 'http://export.arxiv.org/api/query?search_query=all:'\
22+base_url = 'https://export.arxiv.org/api/query?search_query=all:'\
23 + '{query}&start={offset}&max_results={number_of_results}'
23 + '{query}&start={offset}&max_results={number_of_results}'
24
24
25# engine dependent config
25# engine dependent config
searx/engines/currency_convert.py+1
@@ -9,6 +9,7 @@ url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'
9weight = 100
9weight = 100
10
10
11parser_re = re.compile('.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
11parser_re = re.compile('.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
12+https_support = True
12
13
13
14
14def normalize_name(name):
15def normalize_name(name):
searx/engines/dictzone.py+1
@@ -20,6 +20,7 @@ weight = 100
20
20
21parser_re = re.compile('.*?([a-z]+)-([a-z]+) ([^ ]+)$', re.I)
21parser_re = re.compile('.*?([a-z]+)-([a-z]+) ([^ ]+)$', re.I)
22results_xpath = './/table[@id="r"]/tr'
22results_xpath = './/table[@id="r"]/tr'
23+https_support = True
23
24
24
25
25def request(query, params):
26def request(query, params):
searx/engines/translated.py+1
@@ -15,6 +15,7 @@ categories = ['general']
15url = 'https://api.mymemory.translated.net/get?q={query}&langpair={from_lang}|{to_lang}{key}'
15url = 'https://api.mymemory.translated.net/get?q={query}&langpair={from_lang}|{to_lang}{key}'
16web_url = 'https://mymemory.translated.net/en/{from_lang}/{to_lang}/{query}'
16web_url = 'https://mymemory.translated.net/en/{from_lang}/{to_lang}/{query}'
17weight = 100
17weight = 100
18+https_support = True
18
19
19parser_re = re.compile('.*?([a-z]+)-([a-z]+) (.{2,})$', re.I)
20parser_re = re.compile('.*?([a-z]+)-([a-z]+) (.{2,})$', re.I)
20api_key = ''
21api_key = ''
searx/templates/oscar/macros.html+2−2
@@ -1,6 +1,6 @@
1<!-- Draw glyphicon icon from bootstrap-theme -->
1<!-- Draw glyphicon icon from bootstrap-theme -->
2−{% macro icon(action) -%}
2+{% macro icon(action, alt) -%}
3− <span class="glyphicon glyphicon-{{ action }}"></span>
3+ <span title="{{ alt }}" class="glyphicon glyphicon-{{ action }}"></span>
4{%- endmacro %}
4{%- endmacro %}
5
5
6<!-- Draw favicon -->
6<!-- Draw favicon -->
searx/templates/oscar/preferences.html+2−2
@@ -230,8 +230,8 @@
230 <td class="onoff-checkbox">
230 <td class="onoff-checkbox">
231 {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in disabled_engines) }}
231 {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in disabled_engines) }}
232 </td>
232 </td>
233− <th scope="row">{{ search_engine.name }}</th>
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] }}</td>
234+ <td class="name">{{ shortcuts[search_engine.name] }}
235 <td>{{ support_toggle(stats[search_engine.name].supports_selected_language) }}</td>
235 <td>{{ support_toggle(stats[search_engine.name].supports_selected_language) }}</td>
236 <td>{{ support_toggle(search_engine.safesearch==True) }}</td>
236 <td>{{ support_toggle(search_engine.safesearch==True) }}</td>
237 <td>{{ support_toggle(search_engine.time_range_support==True) }}</td>
237 <td>{{ support_toggle(search_engine.time_range_support==True) }}</td>
searx/templates/simple/macros.html+2−2
@@ -1,6 +1,6 @@
1<!-- Draw glyphicon icon from bootstrap-theme -->
1<!-- Draw glyphicon icon from bootstrap-theme -->
2−{% macro icon(action) -%}
2+{% macro icon(action, alt) -%}
3− <span class="ion-icon-big ion-{{ action }}"></span>
3+ <span title="{{ alt }}" class="ion-icon-big ion-{{ action }}"></span>
4{%- endmacro %}
4{%- endmacro %}
5
5
6{% macro icon_small(action) -%}
6{% 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 %}
2
2
3{% extends "simple/base.html" %}
3{% extends "simple/base.html" %}
4
4
@@ -121,7 +121,7 @@
121 {% set engine_id = 'engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_') %}
121 {% set engine_id = 'engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_') %}
122 <tr>
122 <tr>
123 <td class="engine_checkbox">{{ checkbox_onoff(engine_id, (search_engine.name, categ) in disabled_engines) }}</td>
123 <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>
125 <td class="shortcut">{{ shortcuts[search_engine.name] }}</td>
125 <td class="shortcut">{{ shortcuts[search_engine.name] }}</td>
126 <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>
126 <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>
127 <td>{{ checkbox(engine_id + '_safesearch', search_engine.safesearch==True, true, true) }}</td>
127 <td>{{ checkbox(engine_id + '_safesearch', search_engine.safesearch==True, true, true) }}</td>