Browse Source

[enh] add result proxy support - #707

Adam Tauber 8 years ago
parent
commit
1be6e72d51
3 changed files with 28 additions and 0 deletions
  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 View File

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
+
21
 outgoing: # communication with search engines
27
 outgoing: # 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

+ 6
- 0
searx/templates/oscar/macros.html View File

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
         <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
 

+ 16
- 0
searx/webapp.py View File

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
+
246
 def image_proxify(url):
260
 def image_proxify(url):
247
 
261
 
248
     if url.startswith('//'):
262
     if url.startswith('//'):
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)