瀏覽代碼

[enh] add result proxy support - #707

Adam Tauber 8 年之前
父節點
當前提交
1be6e72d51
共有 3 個文件被更改,包括 28 次插入0 次删除
  1. 6
    0
      searx/settings.yml
  2. 6
    0
      searx/templates/oscar/macros.html
  3. 16
    0
      searx/webapp.py

+ 6
- 0
searx/settings.yml 查看文件

@@ -18,6 +18,12 @@ ui:
18 18
     default_theme : oscar # ui theme
19 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
+
21 27
 outgoing: # communication with search engines
22 28
     request_timeout : 2.0 # seconds
23 29
     useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator

+ 6
- 0
searx/templates/oscar/macros.html 查看文件

@@ -33,6 +33,9 @@
33 33
         <span class="label label-default">{{ engine }}</span>
34 34
     {% endfor %}
35 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 39
 </div>
37 40
     <div class="text-muted"><small>{{ result.pretty_url }}</small></div>
38 41
 {%- endmacro %}
@@ -44,6 +47,9 @@
44 47
         <span class="label label-default">{{ engine }}</span>
45 48
     {% endfor %}
46 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 53
     <div class="text-muted"><small>{{ result.pretty_url }}</small></div>
48 54
 {%- endmacro %}
49 55
 

+ 16
- 0
searx/webapp.py 查看文件

@@ -243,6 +243,20 @@ def url_for_theme(endpoint, override_theme=None, **values):
243 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
+
246 260
 def image_proxify(url):
247 261
 
248 262
     if url.startswith('//'):
@@ -310,6 +324,8 @@ def render(template_name, override_theme=None, **kwargs):
310 324
 
311 325
     kwargs['image_proxify'] = image_proxify
312 326
 
327
+    kwargs['proxify'] = proxify if settings.get('result_proxy') else None
328
+
313 329
     kwargs['get_result_template'] = get_result_template
314 330
 
315 331
     kwargs['theme'] = get_current_theme_name(override=override_theme)