SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[mod] https rewrite pluginification
Adam Tauberd2a636f75d24
diff --git a/searx/__init__.py b/searx/__init__.pyindex 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 settingswith 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__.pyindex 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, <[email protected]>'''-from searx.plugins import (self_ip,- search_on_category_select)-from searx import loggerfrom sys import exit+from searx import loggerlogger = 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.pysimilarity index 91%rename from searx/https_rewrite.pyrename to searx/plugins/https_rewrite.pyindex 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 refrom urlparse import urlparsefrom lxml import etree-from os import listdir+from os import listdir, environfrom 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-filetry:- tree = etree.parse(filepath, parser)+ tree = etree.parse(rules_path, parser)except:# TODO, error messagereturn ()@@ -207,3 +218,10 @@ def https_url_rewrite(result):# target has matched, do not search over the other rulesbreakreturn result+++def on_result(request, ctx):+ result = ctx['result']+ if result['parsed_url'].scheme == 'http':+ https_url_rewrite(result)+ return Truediff --git a/searx/https_rules/00README b/searx/plugins/https_rules/00READMEsimilarity index 100%rename from searx/https_rules/00READMErename to searx/plugins/https_rules/00READMEdiff --git a/searx/https_rules/Bing.xml b/searx/plugins/https_rules/Bing.xmlsimilarity index 100%rename from searx/https_rules/Bing.xmlrename to searx/plugins/https_rules/Bing.xmldiff --git a/searx/https_rules/Dailymotion.xml b/searx/plugins/https_rules/Dailymotion.xmlsimilarity index 100%rename from searx/https_rules/Dailymotion.xmlrename to searx/plugins/https_rules/Dailymotion.xmldiff --git a/searx/https_rules/Deviantart.xml b/searx/plugins/https_rules/Deviantart.xmlsimilarity index 100%rename from searx/https_rules/Deviantart.xmlrename to searx/plugins/https_rules/Deviantart.xmldiff --git a/searx/https_rules/DuckDuckGo.xml b/searx/plugins/https_rules/DuckDuckGo.xmlsimilarity index 100%rename from searx/https_rules/DuckDuckGo.xmlrename to searx/plugins/https_rules/DuckDuckGo.xmldiff --git a/searx/https_rules/Flickr.xml b/searx/plugins/https_rules/Flickr.xmlsimilarity index 100%rename from searx/https_rules/Flickr.xmlrename to searx/plugins/https_rules/Flickr.xmldiff --git a/searx/https_rules/Github-Pages.xml b/searx/plugins/https_rules/Github-Pages.xmlsimilarity index 100%rename from searx/https_rules/Github-Pages.xmlrename to searx/plugins/https_rules/Github-Pages.xmldiff --git a/searx/https_rules/Github.xml b/searx/plugins/https_rules/Github.xmlsimilarity index 100%rename from searx/https_rules/Github.xmlrename to searx/plugins/https_rules/Github.xmldiff --git a/searx/https_rules/Google-mismatches.xml b/searx/plugins/https_rules/Google-mismatches.xmlsimilarity index 100%rename from searx/https_rules/Google-mismatches.xmlrename to searx/plugins/https_rules/Google-mismatches.xmldiff --git a/searx/https_rules/Google.org.xml b/searx/plugins/https_rules/Google.org.xmlsimilarity index 100%rename from searx/https_rules/Google.org.xmlrename to searx/plugins/https_rules/Google.org.xmldiff --git a/searx/https_rules/GoogleAPIs.xml b/searx/plugins/https_rules/GoogleAPIs.xmlsimilarity index 100%rename from searx/https_rules/GoogleAPIs.xmlrename to searx/plugins/https_rules/GoogleAPIs.xmldiff --git a/searx/https_rules/GoogleCanada.xml b/searx/plugins/https_rules/GoogleCanada.xmlsimilarity index 100%rename from searx/https_rules/GoogleCanada.xmlrename to searx/plugins/https_rules/GoogleCanada.xmldiff --git a/searx/https_rules/GoogleImages.xml b/searx/plugins/https_rules/GoogleImages.xmlsimilarity index 100%rename from searx/https_rules/GoogleImages.xmlrename to searx/plugins/https_rules/GoogleImages.xmldiff --git a/searx/https_rules/GoogleMainSearch.xml b/searx/plugins/https_rules/GoogleMainSearch.xmlsimilarity index 100%rename from searx/https_rules/GoogleMainSearch.xmlrename to searx/plugins/https_rules/GoogleMainSearch.xmldiff --git a/searx/https_rules/GoogleMaps.xml b/searx/plugins/https_rules/GoogleMaps.xmlsimilarity index 100%rename from searx/https_rules/GoogleMaps.xmlrename to searx/plugins/https_rules/GoogleMaps.xmldiff --git a/searx/https_rules/GoogleMelange.xml b/searx/plugins/https_rules/GoogleMelange.xmlsimilarity index 100%rename from searx/https_rules/GoogleMelange.xmlrename to searx/plugins/https_rules/GoogleMelange.xmldiff --git a/searx/https_rules/GoogleSearch.xml b/searx/plugins/https_rules/GoogleSearch.xmlsimilarity index 100%rename from searx/https_rules/GoogleSearch.xmlrename to searx/plugins/https_rules/GoogleSearch.xmldiff --git a/searx/https_rules/GoogleServices.xml b/searx/plugins/https_rules/GoogleServices.xmlsimilarity index 100%rename from searx/https_rules/GoogleServices.xmlrename to searx/plugins/https_rules/GoogleServices.xmldiff --git a/searx/https_rules/GoogleShopping.xml b/searx/plugins/https_rules/GoogleShopping.xmlsimilarity index 100%rename from searx/https_rules/GoogleShopping.xmlrename to searx/plugins/https_rules/GoogleShopping.xmldiff --git a/searx/https_rules/GoogleSorry.xml b/searx/plugins/https_rules/GoogleSorry.xmlsimilarity index 100%rename from searx/https_rules/GoogleSorry.xmlrename to searx/plugins/https_rules/GoogleSorry.xmldiff --git a/searx/https_rules/GoogleTranslate.xml b/searx/plugins/https_rules/GoogleTranslate.xmlsimilarity index 100%rename from searx/https_rules/GoogleTranslate.xmlrename to searx/plugins/https_rules/GoogleTranslate.xmldiff --git a/searx/https_rules/GoogleVideos.xml b/searx/plugins/https_rules/GoogleVideos.xmlsimilarity index 100%rename from searx/https_rules/GoogleVideos.xmlrename to searx/plugins/https_rules/GoogleVideos.xmldiff --git a/searx/https_rules/GoogleWatchBlog.xml b/searx/plugins/https_rules/GoogleWatchBlog.xmlsimilarity index 100%rename from searx/https_rules/GoogleWatchBlog.xmlrename to searx/plugins/https_rules/GoogleWatchBlog.xmldiff --git a/searx/https_rules/Google_App_Engine.xml b/searx/plugins/https_rules/Google_App_Engine.xmlsimilarity index 100%rename from searx/https_rules/Google_App_Engine.xmlrename to searx/plugins/https_rules/Google_App_Engine.xmldiff --git a/searx/https_rules/Googleplex.com.xml b/searx/plugins/https_rules/Googleplex.com.xmlsimilarity index 100%rename from searx/https_rules/Googleplex.com.xmlrename to searx/plugins/https_rules/Googleplex.com.xmldiff --git a/searx/https_rules/OpenStreetMap.xml b/searx/plugins/https_rules/OpenStreetMap.xmlsimilarity index 100%rename from searx/https_rules/OpenStreetMap.xmlrename to searx/plugins/https_rules/OpenStreetMap.xmldiff --git a/searx/https_rules/Rawgithub.com.xml b/searx/plugins/https_rules/Rawgithub.com.xmlsimilarity index 100%rename from searx/https_rules/Rawgithub.com.xmlrename to searx/plugins/https_rules/Rawgithub.com.xmldiff --git a/searx/https_rules/Soundcloud.xml b/searx/plugins/https_rules/Soundcloud.xmlsimilarity index 100%rename from searx/https_rules/Soundcloud.xmlrename to searx/plugins/https_rules/Soundcloud.xmldiff --git a/searx/https_rules/ThePirateBay.xml b/searx/plugins/https_rules/ThePirateBay.xmlsimilarity index 100%rename from searx/https_rules/ThePirateBay.xmlrename to searx/plugins/https_rules/ThePirateBay.xmldiff --git a/searx/https_rules/Torproject.xml b/searx/plugins/https_rules/Torproject.xmlsimilarity index 100%rename from searx/https_rules/Torproject.xmlrename to searx/plugins/https_rules/Torproject.xmldiff --git a/searx/https_rules/Twitter.xml b/searx/plugins/https_rules/Twitter.xmlsimilarity index 100%rename from searx/https_rules/Twitter.xmlrename to searx/plugins/https_rules/Twitter.xmldiff --git a/searx/https_rules/Vimeo.xml b/searx/plugins/https_rules/Vimeo.xmlsimilarity index 100%rename from searx/https_rules/Vimeo.xmlrename to searx/plugins/https_rules/Vimeo.xmldiff --git a/searx/https_rules/WikiLeaks.xml b/searx/plugins/https_rules/WikiLeaks.xmlsimilarity index 100%rename from searx/https_rules/WikiLeaks.xmlrename to searx/plugins/https_rules/WikiLeaks.xmldiff --git a/searx/https_rules/Wikimedia.xml b/searx/plugins/https_rules/Wikimedia.xmlsimilarity index 100%rename from searx/https_rules/Wikimedia.xmlrename to searx/plugins/https_rules/Wikimedia.xmldiff --git a/searx/https_rules/Yahoo.xml b/searx/plugins/https_rules/Yahoo.xmlsimilarity index 100%rename from searx/https_rules/Yahoo.xmlrename to searx/plugins/https_rules/Yahoo.xmldiff --git a/searx/https_rules/YouTube.xml b/searx/plugins/https_rules/YouTube.xmlsimilarity index 100%rename from searx/https_rules/YouTube.xmlrename to searx/plugins/https_rules/YouTube.xmldiff --git a/searx/settings.yml b/searx/settings.ymlindex 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 changedefault_theme : oscar # ui theme- https_rewrite : True # Force rewrite result urls. See searx/https_rewrite.pyuseragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administratorimage_proxy : False # Proxying image results through searxdefault_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config sectiondiff --git a/searx/webapp.py b/searx/webapp.pyindex 89ab9b543..52ced1363 100644--- a/searx/webapp.py+++ b/searx/webapp.py@@ -59,7 +59,6 @@ from searx.utils import ()from searx.version import VERSION_STRINGfrom searx.languages import language_codes-from searx.https_rewrite import https_url_rewritefrom searx.search import Searchfrom searx.query import Queryfrom 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'],