diff options
Diffstat (limited to 'searx/webapp.py')
| -rw-r--r-- | searx/webapp.py | 75 |
1 files changed, 10 insertions, 65 deletions
diff --git a/searx/webapp.py b/searx/webapp.py index 541975573..be7feee82 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -41,15 +41,12 @@ from searx.utils import ( UnicodeWriter, highlight_content, html_to_text, get_themes ) from searx.version import VERSION_STRING -from searx.https_rewrite import https_rules 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 backends as autocomplete_backends -from urlparse import urlparse -import re - static_path, templates_path, themes =\ get_themes(settings['themes_path'] @@ -68,9 +65,12 @@ app.secret_key = settings['server']['secret_key'] babel = Babel(app) -#TODO configurable via settings.yml -favicons = ['wikipedia', 'youtube', 'vimeo', 'dailymotion', 'soundcloud', - 'twitter', 'stackoverflow', 'github', 'deviantart'] +global_favicons = [] +for indice, theme in enumerate(themes): + global_favicons.append([]) + theme_img_path = searx_dir+"/static/"+theme+"/img/icons/" + for (dirpath, dirnames, filenames) in os.walk(theme_img_path): + global_favicons[indice].extend(filenames) cookie_max_age = 60 * 60 * 24 * 365 * 23 # 23 years @@ -215,59 +215,7 @@ def index(): if settings['server']['https_rewrite']\ and result['parsed_url'].scheme == 'http': - skip_https_rewrite = False - - # check if HTTPS rewrite is possible - for target, rules, exclusions in https_rules: - - # check if target regex match with url - if target.match(result['url']): - # process exclusions - for exclusion in exclusions: - # check if exclusion match with url - if exclusion.match(result['url']): - skip_https_rewrite = True - break - - # skip https rewrite if required - if skip_https_rewrite: - break - - # process rules - for rule in rules: - try: - # TODO, precompile rule - p = re.compile(rule[0]) - - # rewrite url if possible - new_result_url = p.sub(rule[1], result['url']) - except: - break - - # parse new url - new_parsed_url = urlparse(new_result_url) - - # continiue if nothing was rewritten - if result['url'] == new_result_url: - continue - - # get domainname from result - # TODO, does only work correct with TLD's like - # asdf.com, not for asdf.com.de - # TODO, using publicsuffix instead of this rewrite rule - old_result_domainname = '.'.join( - result['parsed_url'].hostname.split('.')[-2:]) - new_result_domainname = '.'.join( - new_parsed_url.hostname.split('.')[-2:]) - - # check if rewritten hostname is the same, - # to protect against wrong or malicious rewrite rules - if old_result_domainname == new_result_domainname: - # set new url - result['url'] = new_result_url - - # target has matched, do not search over the other rules - break + result = https_url_rewrite(result) if search.request_data.get('format', 'html') == 'html': if 'content' in result: @@ -288,10 +236,6 @@ def index(): else: result['pretty_url'] = result['url'] - for engine in result['engines']: - if engine in favicons: - result['favicon'] = engine - # TODO, check if timezone is calculated right if 'publishedDate' in result: result['pubdate'] = result['publishedDate'].strftime('%Y-%m-%d %H:%M:%S%z') @@ -344,7 +288,8 @@ def index(): suggestions=search.suggestions, answers=search.answers, infoboxes=search.infoboxes, - theme=get_current_theme_name() + theme=get_current_theme_name(), + favicons=global_favicons[themes.index(get_current_theme_name())] ) |