|
@@ -18,11 +18,22 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
18
|
18
|
import re
|
19
|
19
|
from urlparse import urlparse
|
20
|
20
|
from lxml import etree
|
21
|
|
-from os import listdir
|
|
21
|
+from os import listdir, environ
|
22
|
22
|
from os.path import isfile, isdir, join
|
23
|
|
-from searx import logger
|
|
23
|
+from searx.plugins import logger
|
|
24
|
+from flask.ext.babel import gettext
|
|
25
|
+from searx import searx_dir
|
24
|
26
|
|
25
|
27
|
|
|
28
|
+name = "HTTPS rewrite"
|
|
29
|
+description = gettext('Rewrite HTTP links to HTTPS if possible')
|
|
30
|
+default_on = True
|
|
31
|
+
|
|
32
|
+if 'SEARX_HTTPS_REWRITE_PATH' in environ:
|
|
33
|
+ rules_path = environ['SEARX_rules_path']
|
|
34
|
+else:
|
|
35
|
+ rules_path = join(searx_dir, 'plugins/https_rules')
|
|
36
|
+
|
26
|
37
|
logger = logger.getChild("https_rewrite")
|
27
|
38
|
|
28
|
39
|
# https://gitweb.torproject.org/\
|
|
@@ -33,7 +44,7 @@ https_rules = []
|
33
|
44
|
|
34
|
45
|
|
35
|
46
|
# load single ruleset from a xml file
|
36
|
|
-def load_single_https_ruleset(filepath):
|
|
47
|
+def load_single_https_ruleset(rules_path):
|
37
|
48
|
ruleset = ()
|
38
|
49
|
|
39
|
50
|
# init parser
|
|
@@ -41,7 +52,7 @@ def load_single_https_ruleset(filepath):
|
41
|
52
|
|
42
|
53
|
# load and parse xml-file
|
43
|
54
|
try:
|
44
|
|
- tree = etree.parse(filepath, parser)
|
|
55
|
+ tree = etree.parse(rules_path, parser)
|
45
|
56
|
except:
|
46
|
57
|
# TODO, error message
|
47
|
58
|
return ()
|
|
@@ -207,3 +218,10 @@ def https_url_rewrite(result):
|
207
|
218
|
# target has matched, do not search over the other rules
|
208
|
219
|
break
|
209
|
220
|
return result
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+def on_result(request, ctx):
|
|
224
|
+ result = ctx['result']
|
|
225
|
+ if result['parsed_url'].scheme == 'http':
|
|
226
|
+ https_url_rewrite(result)
|
|
227
|
+ return True
|