on master help sign in
[enh] add result proxy support - #707
commit1be6e72d517c1651fc466d3222a23dbda0a53c2c authorAdam Tauber <asciimoo@gmail.com> dateMon 17 Oct 2016, 00:22 (10 years ago) parent19a6ca0
3 files changed+28
searx/settings.yml+6 searx/templates/oscar/macros.html+6 searx/webapp.py+16
searx/settings.yml+6
@@ -18,6 +18,12 @@ ui:
1818 default_theme : oscar # ui theme
1919 default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section
2020
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+
2127outgoing: # communication with search engines
2228 request_timeout : 2.0 # seconds
2329 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 @@
3333 <span class="label label-default">{{ engine }}</span>
3434 {% endfor %}
3535 <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 %}
3639</div>
3740 <div class="text-muted"><small>{{ result.pretty_url }}</small></div>
3841{%- endmacro %}
@@ -44,6 +47,9 @@
4447 <span class="label label-default">{{ engine }}</span>
4548 {% endfor %}
4649 <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 %}
4753 <div class="text-muted"><small>{{ result.pretty_url }}</small></div>
4854{%- endmacro %}
4955
searx/webapp.py+16
@@ -243,6 +243,20 @@ def url_for_theme(endpoint, override_theme=None, **values):
243243 return url_for(endpoint, **values)
244244
245245
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+
246260def image_proxify(url):
247261
248262 if url.startswith('//'):
@@ -310,6 +324,8 @@ def render(template_name, override_theme=None, **kwargs):
310324
311325 kwargs['image_proxify'] = image_proxify
312326
327+ kwargs['proxify'] = proxify if settings.get('result_proxy') else None
328+
313329 kwargs['get_result_template'] = get_result_template
314330
315331 kwargs['theme'] = get_current_theme_name(override=override_theme)