diff --git a/app/routes.py b/app/routes.py index 10336ed..006be07 100644 --- a/app/routes.py +++ b/app/routes.py @@ -229,6 +229,9 @@ def search(): # the element key can be regenerated app.user_elements[session['uuid']] = elements + # Return 503 if temporarily blocked by captcha + resp_code = 503 if has_captcha(str(response)) else 200 + return render_template( 'display.html', query=urlparse.unquote(query), @@ -242,7 +245,7 @@ def search(): query=urlparse.unquote(query), search_type=search_util.search_type, mobile=g.user_request.mobile) - if 'isch' not in search_util.search_type else '')) + if 'isch' not in search_util.search_type else '')), resp_code @app.route('/config', methods=['GET', 'POST', 'PUT']) diff --git a/app/static/css/dark-theme.css b/app/static/css/dark-theme.css index 940f646..8fc9455 100644 --- a/app/static/css/dark-theme.css +++ b/app/static/css/dark-theme.css @@ -67,7 +67,6 @@ select { #search-bar { border: 2px solid var(--whoogle-dark-accent) !important; - border-radius: 8px; color: var(--whoogle-dark-text) !important; } diff --git a/app/templates/header.html b/app/templates/header.html index 9833861..cd07589 100644 --- a/app/templates/header.html +++ b/app/templates/header.html @@ -12,7 +12,7 @@ @@ -37,7 +37,7 @@ spellcheck="false" type="text" value="{{ query }}" style="background-color: {{ 'var(--whoogle-dark-result-bg)' if config.dark else 'var(--whoogle-result-bg)' }} !important; color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }}; - border: {{ '2px solid var(--whoogle-dark-accent)' if config.dark else '' }};"> + border: {{ '2px solid var(--whoogle-dark-accent)' if config.dark else '' }}; border-radius: 8px;">
diff --git a/app/utils/search.py b/app/utils/search.py index 84a457e..ee75f3f 100644 --- a/app/utils/search.py +++ b/app/utils/search.py @@ -8,6 +8,7 @@ from typing import Any, Tuple import os TOR_BANNER = '

You are using Tor


' +CAPTCHA = 'div class="g-recaptcha"' def needs_https(url: str) -> bool: @@ -30,6 +31,10 @@ def needs_https(url: str) -> bool: return (is_heroku and is_http) or (https_only and is_http) +def has_captcha(site_contents: str) -> bool: + return CAPTCHA in site_contents + + class Search: """Search query preprocessor - used before submitting the query or redirecting to another site