Allow setting fallback search engine (#1184)

Allow setting a fallback Search Engine URL when there is internal server error
or instance is rate-limited. Search query is appended to the end of the URL
(eg. https://duckduckgo.com/?k1=-1&q=).
This commit is contained in:
Roman Štefko 2024-11-01 00:06:47 +01:00 committed by GitHub
parent c54f4a79a6
commit 1b9f7990b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -445,6 +445,7 @@ There are a few optional environment variables available for customizing a Whoog
| WHOOGLE_TOR_CONF | The absolute path to the config file containing the password for the tor control port. Default: ./misc/tor/control.conf WHOOGLE_TOR_PASS must be 1 for this to work.| | WHOOGLE_TOR_CONF | The absolute path to the config file containing the password for the tor control port. Default: ./misc/tor/control.conf WHOOGLE_TOR_PASS must be 1 for this to work.|
| WHOOGLE_SHOW_FAVICONS | Show/hide favicons next to search result URLs. Default on. | | WHOOGLE_SHOW_FAVICONS | Show/hide favicons next to search result URLs. Default on. |
| WHOOGLE_UPDATE_CHECK | Enable/disable the automatic daily check for new versions of Whoogle. Default on. | | WHOOGLE_UPDATE_CHECK | Enable/disable the automatic daily check for new versions of Whoogle. Default on. |
| WHOOGLE_FALLBACK_ENGINE_URL | Set a fallback Search Engine URL when there is internal server error or instance is rate-limited. Search query is appended to the end of the URL (eg. https://duckduckgo.com/?k1=-1&q=). |
### Config Environment Variables ### Config Environment Variables
These environment variables allow setting default config values, but can be overwritten manually by using the home page config menu. These allow a shortcut for destroying/rebuilding an instance to the same config state every time. These environment variables allow setting default config values, but can be overwritten manually by using the home page config menu. These allow a shortcut for destroying/rebuilding an instance to the same config state every time.

View File

@ -339,6 +339,10 @@ def search():
# Return 503 if temporarily blocked by captcha # Return 503 if temporarily blocked by captcha
if has_captcha(str(response)): if has_captcha(str(response)):
app.logger.error('503 (CAPTCHA)') app.logger.error('503 (CAPTCHA)')
fallback_engine = os.environ.get('WHOOGLE_FALLBACK_ENGINE_URL', '')
if (fallback_engine):
return redirect(fallback_engine + query)
return render_template( return render_template(
'error.html', 'error.html',
blocked=True, blocked=True,
@ -619,6 +623,10 @@ def internal_error(e):
print(traceback.format_exc(), file=sys.stderr) print(traceback.format_exc(), file=sys.stderr)
fallback_engine = os.environ.get('WHOOGLE_FALLBACK_ENGINE_URL', '')
if (fallback_engine):
return redirect(fallback_engine + query)
localization_lang = g.user_config.get_localization_lang() localization_lang = g.user_config.get_localization_lang()
translation = app.config['TRANSLATIONS'][localization_lang] translation = app.config['TRANSLATIONS'][localization_lang]
return render_template( return render_template(