summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--searx/__init__.py11
-rw-r--r--searx/plugins/__init__.py9
-rw-r--r--searx/plugins/https_rewrite.py (renamed from searx/https_rewrite.py)26
-rw-r--r--searx/plugins/https_rules/00README (renamed from searx/https_rules/00README)0
-rw-r--r--searx/plugins/https_rules/Bing.xml (renamed from searx/https_rules/Bing.xml)0
-rw-r--r--searx/plugins/https_rules/Dailymotion.xml (renamed from searx/https_rules/Dailymotion.xml)0
-rw-r--r--searx/plugins/https_rules/Deviantart.xml (renamed from searx/https_rules/Deviantart.xml)0
-rw-r--r--searx/plugins/https_rules/DuckDuckGo.xml (renamed from searx/https_rules/DuckDuckGo.xml)0
-rw-r--r--searx/plugins/https_rules/Flickr.xml (renamed from searx/https_rules/Flickr.xml)0
-rw-r--r--searx/plugins/https_rules/Github-Pages.xml (renamed from searx/https_rules/Github-Pages.xml)0
-rw-r--r--searx/plugins/https_rules/Github.xml (renamed from searx/https_rules/Github.xml)0
-rw-r--r--searx/plugins/https_rules/Google-mismatches.xml (renamed from searx/https_rules/Google-mismatches.xml)0
-rw-r--r--searx/plugins/https_rules/Google.org.xml (renamed from searx/https_rules/Google.org.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleAPIs.xml (renamed from searx/https_rules/GoogleAPIs.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleCanada.xml (renamed from searx/https_rules/GoogleCanada.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleImages.xml (renamed from searx/https_rules/GoogleImages.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleMainSearch.xml (renamed from searx/https_rules/GoogleMainSearch.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleMaps.xml (renamed from searx/https_rules/GoogleMaps.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleMelange.xml (renamed from searx/https_rules/GoogleMelange.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleSearch.xml (renamed from searx/https_rules/GoogleSearch.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleServices.xml (renamed from searx/https_rules/GoogleServices.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleShopping.xml (renamed from searx/https_rules/GoogleShopping.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleSorry.xml (renamed from searx/https_rules/GoogleSorry.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleTranslate.xml (renamed from searx/https_rules/GoogleTranslate.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleVideos.xml (renamed from searx/https_rules/GoogleVideos.xml)0
-rw-r--r--searx/plugins/https_rules/GoogleWatchBlog.xml (renamed from searx/https_rules/GoogleWatchBlog.xml)0
-rw-r--r--searx/plugins/https_rules/Google_App_Engine.xml (renamed from searx/https_rules/Google_App_Engine.xml)0
-rw-r--r--searx/plugins/https_rules/Googleplex.com.xml (renamed from searx/https_rules/Googleplex.com.xml)0
-rw-r--r--searx/plugins/https_rules/OpenStreetMap.xml (renamed from searx/https_rules/OpenStreetMap.xml)0
-rw-r--r--searx/plugins/https_rules/Rawgithub.com.xml (renamed from searx/https_rules/Rawgithub.com.xml)0
-rw-r--r--searx/plugins/https_rules/Soundcloud.xml (renamed from searx/https_rules/Soundcloud.xml)0
-rw-r--r--searx/plugins/https_rules/ThePirateBay.xml (renamed from searx/https_rules/ThePirateBay.xml)0
-rw-r--r--searx/plugins/https_rules/Torproject.xml (renamed from searx/https_rules/Torproject.xml)0
-rw-r--r--searx/plugins/https_rules/Twitter.xml (renamed from searx/https_rules/Twitter.xml)0
-rw-r--r--searx/plugins/https_rules/Vimeo.xml (renamed from searx/https_rules/Vimeo.xml)0
-rw-r--r--searx/plugins/https_rules/WikiLeaks.xml (renamed from searx/https_rules/WikiLeaks.xml)0
-rw-r--r--searx/plugins/https_rules/Wikimedia.xml (renamed from searx/https_rules/Wikimedia.xml)0
-rw-r--r--searx/plugins/https_rules/Yahoo.xml (renamed from searx/https_rules/Yahoo.xml)0
-rw-r--r--searx/plugins/https_rules/YouTube.xml (renamed from searx/https_rules/YouTube.xml)0
-rw-r--r--searx/settings.yml1
-rw-r--r--searx/webapp.py8
41 files changed, 29 insertions, 26 deletions
diff --git a/searx/__init__.py b/searx/__init__.py
index 110f46af8..2d545a809 100644
--- a/searx/__init__.py
+++ b/searx/__init__.py
@@ -36,11 +36,6 @@ if 'SEARX_SETTINGS_PATH' in environ:
else:
settings_path = join(searx_dir, 'settings.yml')
-if 'SEARX_HTTPS_REWRITE_PATH' in environ:
- https_rewrite_path = environ['SEARX_HTTPS_REWRITE_PATH']
-else:
- https_rewrite_path = join(searx_dir, 'https_rules')
-
# load settings
with open(settings_path) as settings_yaml:
settings = load(settings_yaml)
@@ -52,10 +47,4 @@ else:
logger = logging.getLogger('searx')
-# load https rules only if https rewrite is enabled
-if settings.get('server', {}).get('https_rewrite'):
- # loade https rules
- from searx.https_rewrite import load_https_rules
- load_https_rules(https_rewrite_path)
-
logger.info('Initialisation done')
diff --git a/searx/plugins/__init__.py b/searx/plugins/__init__.py
index a8e400c93..5ac3f447c 100644
--- a/searx/plugins/__init__.py
+++ b/searx/plugins/__init__.py
@@ -14,13 +14,15 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
(C) 2015 by Adam Tauber, <asciimoo@gmail.com>
'''
-from searx.plugins import (self_ip,
- search_on_category_select)
-from searx import logger
from sys import exit
+from searx import logger
logger = logger.getChild('plugins')
+from searx.plugins import (https_rewrite,
+ self_ip,
+ search_on_category_select)
+
required_attrs = (('name', str),
('description', str),
('default_on', bool))
@@ -68,5 +70,6 @@ class PluginStore():
plugins = PluginStore()
+plugins.register(https_rewrite)
plugins.register(self_ip)
plugins.register(search_on_category_select)
diff --git a/searx/https_rewrite.py b/searx/plugins/https_rewrite.py
index 71aec1c9b..409b122e6 100644
--- a/searx/https_rewrite.py
+++ b/searx/plugins/https_rewrite.py
@@ -18,11 +18,22 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
import re
from urlparse import urlparse
from lxml import etree
-from os import listdir
+from os import listdir, environ
from os.path import isfile, isdir, join
-from searx import logger
+from searx.plugins import logger
+from flask.ext.babel import gettext
+from searx import searx_dir
+name = "HTTPS rewrite"
+description = gettext('Rewrite HTTP links to HTTPS if possible')
+default_on = True
+
+if 'SEARX_HTTPS_REWRITE_PATH' in environ:
+ rules_path = environ['SEARX_rules_path']
+else:
+ rules_path = join(searx_dir, 'plugins/https_rules')
+
logger = logger.getChild("https_rewrite")
# https://gitweb.torproject.org/\
@@ -33,7 +44,7 @@ https_rules = []
# load single ruleset from a xml file
-def load_single_https_ruleset(filepath):
+def load_single_https_ruleset(rules_path):
ruleset = ()
# init parser
@@ -41,7 +52,7 @@ def load_single_https_ruleset(filepath):
# load and parse xml-file
try:
- tree = etree.parse(filepath, parser)
+ tree = etree.parse(rules_path, parser)
except:
# TODO, error message
return ()
@@ -207,3 +218,10 @@ def https_url_rewrite(result):
# target has matched, do not search over the other rules
break
return result
+
+
+def on_result(request, ctx):
+ result = ctx['result']
+ if result['parsed_url'].scheme == 'http':
+ https_url_rewrite(result)
+ return True
diff --git a/searx/https_rules/00README b/searx/plugins/https_rules/00README
index fcd8a7724..fcd8a7724 100644
--- a/searx/https_rules/00README
+++ b/searx/plugins/https_rules/00README
diff --git a/searx/https_rules/Bing.xml b/searx/plugins/https_rules/Bing.xml
index 8b403f108..8b403f108 100644
--- a/searx/https_rules/Bing.xml
+++ b/searx/plugins/https_rules/Bing.xml
diff --git a/searx/https_rules/Dailymotion.xml b/searx/plugins/https_rules/Dailymotion.xml
index 743100cb7..743100cb7 100644
--- a/searx/https_rules/Dailymotion.xml
+++ b/searx/plugins/https_rules/Dailymotion.xml
diff --git a/searx/https_rules/Deviantart.xml b/searx/plugins/https_rules/Deviantart.xml
index 7830fc20f..7830fc20f 100644
--- a/searx/https_rules/Deviantart.xml
+++ b/searx/plugins/https_rules/Deviantart.xml
diff --git a/searx/https_rules/DuckDuckGo.xml b/searx/plugins/https_rules/DuckDuckGo.xml
index 173a9ad9f..173a9ad9f 100644
--- a/searx/https_rules/DuckDuckGo.xml
+++ b/searx/plugins/https_rules/DuckDuckGo.xml
diff --git a/searx/https_rules/Flickr.xml b/searx/plugins/https_rules/Flickr.xml
index 85c6e8065..85c6e8065 100644
--- a/searx/https_rules/Flickr.xml
+++ b/searx/plugins/https_rules/Flickr.xml
diff --git a/searx/https_rules/Github-Pages.xml b/searx/plugins/https_rules/Github-Pages.xml
index d3be58a4c..d3be58a4c 100644
--- a/searx/https_rules/Github-Pages.xml
+++ b/searx/plugins/https_rules/Github-Pages.xml
diff --git a/searx/https_rules/Github.xml b/searx/plugins/https_rules/Github.xml
index a9a3a1e53..a9a3a1e53 100644
--- a/searx/https_rules/Github.xml
+++ b/searx/plugins/https_rules/Github.xml
diff --git a/searx/https_rules/Google-mismatches.xml b/searx/plugins/https_rules/Google-mismatches.xml
index de9d3eb18..de9d3eb18 100644
--- a/searx/https_rules/Google-mismatches.xml
+++ b/searx/plugins/https_rules/Google-mismatches.xml
diff --git a/searx/https_rules/Google.org.xml b/searx/plugins/https_rules/Google.org.xml
index d6cc47881..d6cc47881 100644
--- a/searx/https_rules/Google.org.xml
+++ b/searx/plugins/https_rules/Google.org.xml
diff --git a/searx/https_rules/GoogleAPIs.xml b/searx/plugins/https_rules/GoogleAPIs.xml
index 85a5a8081..85a5a8081 100644
--- a/searx/https_rules/GoogleAPIs.xml
+++ b/searx/plugins/https_rules/GoogleAPIs.xml
diff --git a/searx/https_rules/GoogleCanada.xml b/searx/plugins/https_rules/GoogleCanada.xml
index d5eefe816..d5eefe816 100644
--- a/searx/https_rules/GoogleCanada.xml
+++ b/searx/plugins/https_rules/GoogleCanada.xml
diff --git a/searx/https_rules/GoogleImages.xml b/searx/plugins/https_rules/GoogleImages.xml
index 0112001e0..0112001e0 100644
--- a/searx/https_rules/GoogleImages.xml
+++ b/searx/plugins/https_rules/GoogleImages.xml
diff --git a/searx/https_rules/GoogleMainSearch.xml b/searx/plugins/https_rules/GoogleMainSearch.xml
index df504d90c..df504d90c 100644
--- a/searx/https_rules/GoogleMainSearch.xml
+++ b/searx/plugins/https_rules/GoogleMainSearch.xml
diff --git a/searx/https_rules/GoogleMaps.xml b/searx/plugins/https_rules/GoogleMaps.xml
index 0f82c5267..0f82c5267 100644
--- a/searx/https_rules/GoogleMaps.xml
+++ b/searx/plugins/https_rules/GoogleMaps.xml
diff --git a/searx/https_rules/GoogleMelange.xml b/searx/plugins/https_rules/GoogleMelange.xml
index ec23cd45f..ec23cd45f 100644
--- a/searx/https_rules/GoogleMelange.xml
+++ b/searx/plugins/https_rules/GoogleMelange.xml
diff --git a/searx/https_rules/GoogleSearch.xml b/searx/plugins/https_rules/GoogleSearch.xml
index 66b7ffdb0..66b7ffdb0 100644
--- a/searx/https_rules/GoogleSearch.xml
+++ b/searx/plugins/https_rules/GoogleSearch.xml
diff --git a/searx/https_rules/GoogleServices.xml b/searx/plugins/https_rules/GoogleServices.xml
index 704646b53..704646b53 100644
--- a/searx/https_rules/GoogleServices.xml
+++ b/searx/plugins/https_rules/GoogleServices.xml
diff --git a/searx/https_rules/GoogleShopping.xml b/searx/plugins/https_rules/GoogleShopping.xml
index 6ba69a91d..6ba69a91d 100644
--- a/searx/https_rules/GoogleShopping.xml
+++ b/searx/plugins/https_rules/GoogleShopping.xml
diff --git a/searx/https_rules/GoogleSorry.xml b/searx/plugins/https_rules/GoogleSorry.xml
index 72a19210d..72a19210d 100644
--- a/searx/https_rules/GoogleSorry.xml
+++ b/searx/plugins/https_rules/GoogleSorry.xml
diff --git a/searx/https_rules/GoogleTranslate.xml b/searx/plugins/https_rules/GoogleTranslate.xml
index a004025ae..a004025ae 100644
--- a/searx/https_rules/GoogleTranslate.xml
+++ b/searx/plugins/https_rules/GoogleTranslate.xml
diff --git a/searx/https_rules/GoogleVideos.xml b/searx/plugins/https_rules/GoogleVideos.xml
index a5e88fcf0..a5e88fcf0 100644
--- a/searx/https_rules/GoogleVideos.xml
+++ b/searx/plugins/https_rules/GoogleVideos.xml
diff --git a/searx/https_rules/GoogleWatchBlog.xml b/searx/plugins/https_rules/GoogleWatchBlog.xml
index afec70c97..afec70c97 100644
--- a/searx/https_rules/GoogleWatchBlog.xml
+++ b/searx/plugins/https_rules/GoogleWatchBlog.xml
diff --git a/searx/https_rules/Google_App_Engine.xml b/searx/plugins/https_rules/Google_App_Engine.xml
index 851e051d1..851e051d1 100644
--- a/searx/https_rules/Google_App_Engine.xml
+++ b/searx/plugins/https_rules/Google_App_Engine.xml
diff --git a/searx/https_rules/Googleplex.com.xml b/searx/plugins/https_rules/Googleplex.com.xml
index 7ddbb5ba9..7ddbb5ba9 100644
--- a/searx/https_rules/Googleplex.com.xml
+++ b/searx/plugins/https_rules/Googleplex.com.xml
diff --git a/searx/https_rules/OpenStreetMap.xml b/searx/plugins/https_rules/OpenStreetMap.xml
index 58a661823..58a661823 100644
--- a/searx/https_rules/OpenStreetMap.xml
+++ b/searx/plugins/https_rules/OpenStreetMap.xml
diff --git a/searx/https_rules/Rawgithub.com.xml b/searx/plugins/https_rules/Rawgithub.com.xml
index 3868f332a..3868f332a 100644
--- a/searx/https_rules/Rawgithub.com.xml
+++ b/searx/plugins/https_rules/Rawgithub.com.xml
diff --git a/searx/https_rules/Soundcloud.xml b/searx/plugins/https_rules/Soundcloud.xml
index 6958e8cbc..6958e8cbc 100644
--- a/searx/https_rules/Soundcloud.xml
+++ b/searx/plugins/https_rules/Soundcloud.xml
diff --git a/searx/https_rules/ThePirateBay.xml b/searx/plugins/https_rules/ThePirateBay.xml
index 010387b6b..010387b6b 100644
--- a/searx/https_rules/ThePirateBay.xml
+++ b/searx/plugins/https_rules/ThePirateBay.xml
diff --git a/searx/https_rules/Torproject.xml b/searx/plugins/https_rules/Torproject.xml
index 69269af7e..69269af7e 100644
--- a/searx/https_rules/Torproject.xml
+++ b/searx/plugins/https_rules/Torproject.xml
diff --git a/searx/https_rules/Twitter.xml b/searx/plugins/https_rules/Twitter.xml
index 3285f44e0..3285f44e0 100644
--- a/searx/https_rules/Twitter.xml
+++ b/searx/plugins/https_rules/Twitter.xml
diff --git a/searx/https_rules/Vimeo.xml b/searx/plugins/https_rules/Vimeo.xml
index f2a3e5764..f2a3e5764 100644
--- a/searx/https_rules/Vimeo.xml
+++ b/searx/plugins/https_rules/Vimeo.xml
diff --git a/searx/https_rules/WikiLeaks.xml b/searx/plugins/https_rules/WikiLeaks.xml
index 977709d2d..977709d2d 100644
--- a/searx/https_rules/WikiLeaks.xml
+++ b/searx/plugins/https_rules/WikiLeaks.xml
diff --git a/searx/https_rules/Wikimedia.xml b/searx/plugins/https_rules/Wikimedia.xml
index 9f25831a2..9f25831a2 100644
--- a/searx/https_rules/Wikimedia.xml
+++ b/searx/plugins/https_rules/Wikimedia.xml
diff --git a/searx/https_rules/Yahoo.xml b/searx/plugins/https_rules/Yahoo.xml
index 33548c4ab..33548c4ab 100644
--- a/searx/https_rules/Yahoo.xml
+++ b/searx/plugins/https_rules/Yahoo.xml
diff --git a/searx/https_rules/YouTube.xml b/searx/plugins/https_rules/YouTube.xml
index bddc2a5f3..bddc2a5f3 100644
--- a/searx/https_rules/YouTube.xml
+++ b/searx/plugins/https_rules/YouTube.xml
diff --git a/searx/settings.yml b/searx/settings.yml
index 5594c54c5..f37c56b26 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -6,7 +6,6 @@ server:
base_url : False # Set custom base_url. Possible values: False or "https://your.custom.host/location/"
themes_path : "" # Custom ui themes path - leave it blank if you didn't change
default_theme : oscar # ui theme
- https_rewrite : True # Force rewrite result urls. See searx/https_rewrite.py
useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator
image_proxy : False # Proxying image results through searx
default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section
diff --git a/searx/webapp.py b/searx/webapp.py
index 89ab9b543..52ced1363 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -59,7 +59,6 @@ from searx.utils import (
)
from searx.version import VERSION_STRING
from searx.languages import language_codes
-from searx.https_rewrite import https_url_rewrite
from searx.search import Search
from searx.query import Query
from searx.autocomplete import searx_bang, backends as autocomplete_backends
@@ -359,15 +358,10 @@ def index():
for result in search.results:
+ plugins.call('on_result', request, locals())
if not search.paging and engines[result['engine']].paging:
search.paging = True
- # check if HTTPS rewrite is required
- if settings['server']['https_rewrite']\
- and result['parsed_url'].scheme == 'http':
-
- result = https_url_rewrite(result)
-
if search.request_data.get('format', 'html') == 'html':
if 'content' in result:
result['content'] = highlight_content(result['content'],