on master help sign in
[enh] add result proxy support - #707
1be6e72Adam Tauber
searx/settings.yml+6
@@ -18,6 +18,12 @@ ui:
18 default_theme : oscar # ui theme
18 default_theme : oscar # ui theme
19 default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section
19 default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section
20
20
21+# searx supports result proxification using an external service: https://github.com/asciimoo/morty
22+# uncomment below section if you have running morty proxy
23+#result_proxy:
24+# url : http://127.0.0.1:3000/
25+# key : your_morty_proxy_key
26+
21outgoing: # communication with search engines
27outgoing: # communication with search engines
22 request_timeout : 2.0 # seconds
28 request_timeout : 2.0 # seconds
23 useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator
29 useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator
searx/templates/oscar/macros.html+6
@@ -33,6 +33,9 @@
33 <span class="label label-default">{{ engine }}</span>
33 <span class="label label-default">{{ engine }}</span>
34 {% endfor %}
34 {% endfor %}
35 <small>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}</small>
35 <small>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}</small>
36+ {% if proxify %}
37+ <small>{{ result_link(proxify(result.url), icon('sort') + _('proxied'), "text-info") }}</small>
38+ {% endif %}
36</div>
39</div>
37 <div class="text-muted"><small>{{ result.pretty_url }}</small></div>
40 <div class="text-muted"><small>{{ result.pretty_url }}</small></div>
38{%- endmacro %}
41{%- endmacro %}
@@ -44,6 +47,9 @@
44 <span class="label label-default">{{ engine }}</span>
47 <span class="label label-default">{{ engine }}</span>
45 {% endfor %}
48 {% endfor %}
46 <small>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}</small>
49 <small>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}</small>
50+ {% if proxify %}
51+ <small>{{ result_link(proxify(result.url), icon('sort') + _('proxied'), "text-info") }}</small>
52+ {% endif %}
47 <div class="text-muted"><small>{{ result.pretty_url }}</small></div>
53 <div class="text-muted"><small>{{ result.pretty_url }}</small></div>
48{%- endmacro %}
54{%- endmacro %}
49
55
searx/webapp.py+16
@@ -243,6 +243,20 @@ def url_for_theme(endpoint, override_theme=None, **values):
243 return url_for(endpoint, **values)
243 return url_for(endpoint, **values)
244
244
245
245
246+def proxify(url):
247+ if url.startswith('//'):
248+ url = 'https:' + url
249+
250+ if not settings.get('result_proxy'):
251+ return url
252+
253+ h = hmac.new(settings['result_proxy']['key'], url, hashlib.sha256).hexdigest()
254+
255+ return '{0}?{1}'.format(settings['result_proxy']['url'],
256+ urlencode(dict(mortyurl=url.encode('utf-8'),
257+ mortyhash=h)))
258+
259+
246def image_proxify(url):
260def image_proxify(url):
247
261
248 if url.startswith('//'):
262 if url.startswith('//'):
@@ -310,6 +324,8 @@ def render(template_name, override_theme=None, **kwargs):
310
324
311 kwargs['image_proxify'] = image_proxify
325 kwargs['image_proxify'] = image_proxify
312
326
327+ kwargs['proxify'] = proxify if settings.get('result_proxy') else None
328+
313 kwargs['get_result_template'] = get_result_template
329 kwargs['get_result_template'] = get_result_template
314
330
315 kwargs['theme'] = get_current_theme_name(override=override_theme)
331 kwargs['theme'] = get_current_theme_name(override=override_theme)