summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2016-10-22 14:25:50 +0200
committerGitHub <noreply@github.com>2016-10-22 14:25:50 +0200
commita88768efd8ee6b832febda8508cb1ba3c8778b94 (patch)
treea42f1078ce421a69edb7088c642461b6c05f7022 /searx/webapp.py
parentf90eb428c679d3852d9738f6279d045283340562 (diff)
parent85c7237a4f26cea523d5c3b8a863058e459ca07a (diff)
downloadsearxng-a88768efd8ee6b832febda8508cb1ba3c8778b94.tar.gz
searxng-a88768efd8ee6b832febda8508cb1ba3c8778b94.zip
Merge branch 'master' into http1.1
Diffstat (limited to 'searx/webapp.py')
-rw-r--r--searx/webapp.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index b69003297..960d6133c 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -22,10 +22,11 @@ if __name__ == '__main__':
from os.path import realpath, dirname
path.append(realpath(dirname(realpath(__file__)) + '/../'))
-import json
import cStringIO
-import os
import hashlib
+import hmac
+import json
+import os
import requests
from searx import logger
@@ -245,6 +246,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.encode('utf-8'), 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('//'):
@@ -253,8 +268,7 @@ def image_proxify(url):
if not request.preferences.get_value('image_proxy'):
return url
- hash_string = url + settings['server']['secret_key']
- h = hashlib.sha256(hash_string.encode('utf-8')).hexdigest()
+ h = hmac.new(settings['server']['secret_key'], url.encode('utf-8'), hashlib.sha256).hexdigest()
return '{0}?{1}'.format(url_for('image_proxy'),
urlencode(dict(url=url.encode('utf-8'), h=h)))
@@ -313,6 +327,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)
@@ -602,7 +618,7 @@ def image_proxy():
if not url:
return '', 400
- h = hashlib.sha256(url + settings['server']['secret_key'].encode('utf-8')).hexdigest()
+ h = hmac.new(settings['server']['secret_key'], url, hashlib.sha256).hexdigest()
if h != request.args.get('h'):
return '', 400
@@ -660,6 +676,7 @@ Allow: /
Allow: /about
Disallow: /stats
Disallow: /preferences
+Disallow: /*?*q=*
""", mimetype='text/plain')