diff options
author | Adam Tauber <asciimoo@gmail.com> | 2016-10-17 00:22:41 +0200 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2016-10-17 00:23:15 +0200 |
commit | 1be6e72d517c1651fc466d3222a23dbda0a53c2c (patch) | |
tree | f4b25094ada5fafbf08f0d6506b267fb182d24ba | |
parent | 19a6ca0b68839e8d8903e99c336e1c1b1df624e1 (diff) | |
download | searxng-1be6e72d517c1651fc466d3222a23dbda0a53c2c.tar.gz searxng-1be6e72d517c1651fc466d3222a23dbda0a53c2c.zip |
[enh] add result proxy support - #707
-rw-r--r-- | searx/settings.yml | 6 | ||||
-rw-r--r-- | searx/templates/oscar/macros.html | 6 | ||||
-rw-r--r-- | searx/webapp.py | 16 |
3 files changed, 28 insertions, 0 deletions
diff --git a/searx/settings.yml b/searx/settings.yml index e83f5aea7..6b1233324 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -18,6 +18,12 @@ ui: default_theme : oscar # ui theme default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section +# searx supports result proxification using an external service: https://github.com/asciimoo/morty +# uncomment below section if you have running morty proxy +#result_proxy: +# url : http://127.0.0.1:3000/ +# key : your_morty_proxy_key + outgoing: # communication with search engines request_timeout : 2.0 # seconds useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator diff --git a/searx/templates/oscar/macros.html b/searx/templates/oscar/macros.html index 06881db02..221300fe4 100644 --- a/searx/templates/oscar/macros.html +++ b/searx/templates/oscar/macros.html @@ -33,6 +33,9 @@ <span class="label label-default">{{ engine }}</span>
{% endfor %}
<small>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}</small>
+ {% if proxify %}
+ <small>{{ result_link(proxify(result.url), icon('sort') + _('proxied'), "text-info") }}</small>
+ {% endif %}
</div>
<div class="text-muted"><small>{{ result.pretty_url }}</small></div>
{%- endmacro %}
@@ -44,6 +47,9 @@ <span class="label label-default">{{ engine }}</span>
{% endfor %}
<small>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}</small>
+ {% if proxify %}
+ <small>{{ result_link(proxify(result.url), icon('sort') + _('proxied'), "text-info") }}</small>
+ {% endif %}
<div class="text-muted"><small>{{ result.pretty_url }}</small></div>
{%- endmacro %}
diff --git a/searx/webapp.py b/searx/webapp.py index 962367c84..b8d79b56c 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -243,6 +243,20 @@ def url_for_theme(endpoint, override_theme=None, **values): return url_for(endpoint, **values) +def proxify(url): + if url.startswith('//'): + url = 'https:' + url + + if not settings.get('result_proxy'): + return url + + h = hmac.new(settings['result_proxy']['key'], url, hashlib.sha256).hexdigest() + + return '{0}?{1}'.format(settings['result_proxy']['url'], + urlencode(dict(mortyurl=url.encode('utf-8'), + mortyhash=h))) + + def image_proxify(url): if url.startswith('//'): @@ -310,6 +324,8 @@ def render(template_name, override_theme=None, **kwargs): kwargs['image_proxify'] = image_proxify + kwargs['proxify'] = proxify if settings.get('result_proxy') else None + kwargs['get_result_template'] = get_result_template kwargs['theme'] = get_current_theme_name(override=override_theme) |