Allow jumping instances via Farside when ratelimited

When instances are ratelimited (when a captcha is returned instead of
the user's search results) the user can now hop to a new instance via
Farside, a new backend service that redirects users to working instances
of a particular frontend. In this case, it presents a user with a
Farside link to a new Whoogle (or Searx) instance instead, so that the
user can resume their search.

For the generated Farside->Whoogle link, the generated link includes the
user's current Whoogle configuration settings as URL params, to ensure a
more seamless transition between instances. This doesn't translate to
the Farside->Searx link, but potentially could with some changes.
This commit is contained in:
Ben Busby 2021-11-30 21:17:14 -07:00
parent 849282748c
commit 12a6d8d711
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
8 changed files with 132 additions and 31 deletions

View File

@ -37,6 +37,8 @@ class Config:
'theme', 'theme',
'alts', 'alts',
'new_tab', 'new_tab',
'view_image',
'block',
'safe' 'safe'
] ]
@ -107,7 +109,14 @@ class Config:
for param_key in params.keys(): for param_key in params.keys():
if not self.is_safe_key(param_key): if not self.is_safe_key(param_key):
continue continue
self[param_key] = params.get(param_key) param_val = params.get(param_key)
if param_val == 'off':
param_val = False
elif param_val.isdigit():
param_val = int(param_val)
self[param_key] = param_val
return self return self
def to_params(self) -> str: def to_params(self) -> str:

View File

@ -310,7 +310,16 @@ def search():
translate_to = localization_lang.replace('lang_', '') translate_to = localization_lang.replace('lang_', '')
# Return 503 if temporarily blocked by captcha # Return 503 if temporarily blocked by captcha
resp_code = 503 if has_captcha(str(response)) else 200 if has_captcha(str(response)):
return render_template(
'error.html',
blocked=True,
error_message=translation['ratelimit'],
translation=translation,
farside='https://farside.link',
config=g.user_config,
query=urlparse.unquote(query),
params=g.user_config.to_params()), 503
response = bold_search_terms(response, query) response = bold_search_terms(response, query)
# Feature to display IP address # Feature to display IP address
@ -345,7 +354,7 @@ def search():
search_type=search_util.search_type, search_type=search_util.search_type,
mobile=g.user_request.mobile) mobile=g.user_request.mobile)
if 'isch' not in if 'isch' not in
search_util.search_type else '')), resp_code search_util.search_type else '')), 200
@app.route(f'/{Endpoint.config}', methods=['GET', 'POST', 'PUT']) @app.route(f'/{Endpoint.config}', methods=['GET', 'POST', 'PUT'])

View File

@ -138,10 +138,14 @@ select {
color: var(--whoogle-dark-contrast-text) !important; color: var(--whoogle-dark-contrast-text) !important;
} }
#gh-link { .link {
color: var(--whoogle-dark-contrast-text); color: var(--whoogle-dark-contrast-text);
} }
.link-color {
color: var(--whoogle-dark-result-url) !important;
}
.autocomplete-items { .autocomplete-items {
border: 1px solid var(--whoogle-dark-element-bg); border: 1px solid var(--whoogle-dark-element-bg);
} }

9
app/static/css/error.css Normal file
View File

@ -0,0 +1,9 @@
html {
font-size: 1.3rem;
}
@media (max-width: 1000px) {
html {
font-size: 3rem;
}
}

View File

@ -125,10 +125,14 @@ input {
color: var(--whoogle-contrast-text); color: var(--whoogle-contrast-text);
} }
#gh-link { .link {
color: var(--whoogle-element-bg); color: var(--whoogle-element-bg);
} }
.link-color {
color: var(--whoogle-result-url) !important;
}
.autocomplete-items { .autocomplete-items {
border: 1px solid var(--whoogle-element-bg); border: 1px solid var(--whoogle-element-bg);
} }

View File

@ -33,7 +33,9 @@
"translate": "translate", "translate": "translate",
"light": "light", "light": "light",
"dark": "dark", "dark": "dark",
"system": "system" "system": "system",
"ratelimit": "Instance has been ratelimited",
"continue-search": "Continue your search with "
}, },
"lang_nl": { "lang_nl": {
"search": "Zoeken", "search": "Zoeken",
@ -69,7 +71,9 @@
"translate": "vertalen", "translate": "vertalen",
"light": "helder", "light": "helder",
"dark": "donker", "dark": "donker",
"system": "systeeminstellingen" "system": "systeeminstellingen",
"ratelimit": "Instantie is beperkt in snelheid",
"continue-search": "Ga verder met zoeken met "
}, },
"lang_de": { "lang_de": {
"search": "Suchen", "search": "Suchen",
@ -105,7 +109,9 @@
"translate": "Übersetzen", "translate": "Übersetzen",
"light": "hell", "light": "hell",
"dark": "dunkel", "dark": "dunkel",
"system": "Systemeinstellung" "system": "Systemeinstellung",
"ratelimit": "Instanz wurde ratenbegrenzt",
"continue-search": "Setzen Sie Ihre Suche fort mit "
}, },
"lang_es": { "lang_es": {
"search": "Buscar", "search": "Buscar",
@ -141,7 +147,9 @@
"translate": "traducir", "translate": "traducir",
"light": "brillante", "light": "brillante",
"dark": "oscuro", "dark": "oscuro",
"system": "configuración del sistema" "system": "configuración del sistema",
"ratelimit": "La instancia ha sido ratelimited",
"continue-search": "Continúe su búsqueda con "
}, },
"lang_it": { "lang_it": {
"search": "Cerca", "search": "Cerca",
@ -177,7 +185,9 @@
"translate": "tradurre", "translate": "tradurre",
"light": "luminoso", "light": "luminoso",
"dark": "notte", "dark": "notte",
"system": "impostazioni di sistema" "system": "impostazioni di sistema",
"ratelimit": "L'istanza è stata limitata alla velocità",
"continue-search": "Continua la tua ricerca con "
}, },
"lang_pt": { "lang_pt": {
"search": "Pesquisar", "search": "Pesquisar",
@ -213,7 +223,9 @@
"translate": "traduzir", "translate": "traduzir",
"light": "brilhante", "light": "brilhante",
"dark": "escuro", "dark": "escuro",
"system": "configuração de sistema" "system": "configuração de sistema",
"ratelimit": "A instância foi limitada pela taxa",
"continue-search": "Continue sua pesquisa com "
}, },
"lang_ru": { "lang_ru": {
"search": "Поиск", "search": "Поиск",
@ -249,7 +261,9 @@
"translate": "перевести", "translate": "перевести",
"light": "светлое", "light": "светлое",
"dark": "темное", "dark": "темное",
"system": "системное" "system": "системное",
"ratelimit": "Число экземпляров ограничено",
"continue-search": "Продолжайте поиск с "
}, },
"lang_zh-CN": { "lang_zh-CN": {
"search": "搜索", "search": "搜索",
@ -285,7 +299,9 @@
"translate": "翻译", "translate": "翻译",
"light": "明亮的", "light": "明亮的",
"dark": "黑暗的", "dark": "黑暗的",
"system": "系统设置" "system": "系统设置",
"ratelimit": "实例已被限速",
"continue-search": "继续搜索 "
}, },
"lang_si": { "lang_si": {
"search": "සොයන්න", "search": "සොයන්න",
@ -321,7 +337,9 @@
"translate": "පරිවර්තනය කරන්න", "translate": "පරිවර්තනය කරන්න",
"light": "දීප්තිමත්", "light": "දීප්තිමත්",
"dark": "අඳුරු", "dark": "අඳුරු",
"system": "පද්ධතිය" "system": "පද්ධතිය",
"ratelimit": "උදාහරණය අනුපාත කර ඇත",
"continue-search": "සමඟ ඔබේ සෙවීම දිගටම කරගෙන යන්න"
}, },
"lang_fr": { "lang_fr": {
"search": "Chercher", "search": "Chercher",
@ -357,7 +375,9 @@
"translate": "Traduire", "translate": "Traduire",
"light": "clair", "light": "clair",
"dark": "sombre", "dark": "sombre",
"system": "système" "system": "système",
"ratelimit": "Le débit de l'instance a été limité",
"continue-search": "Continuez votre recherche avec "
}, },
"lang_fa": { "lang_fa": {
"search": "جستجو", "search": "جستجو",
@ -393,7 +413,9 @@
"translate": "ترجمه", "translate": "ترجمه",
"light": "روشن", "light": "روشن",
"dark": "تیره", "dark": "تیره",
"system": "سیستم" "system": "سیستم",
"ratelimit": "نمونه با نرخ محدود شده است",
"continue-search": "جستجوی خود را با "
}, },
"lang_cs": { "lang_cs": {
"search": "Hledat", "search": "Hledat",
@ -429,7 +451,9 @@
"translate": "Přeložit", "translate": "Přeložit",
"light": "Světlý", "light": "Světlý",
"dark": "Tmavý", "dark": "Tmavý",
"system": "Systémový" "system": "Systémový",
"ratelimit": "Instance byla omezena sazbou",
"continue-search": "Pokračujte ve vyhledávání pomocí "
}, },
"lang_zh-TW": { "lang_zh-TW": {
"search": "搜尋", "search": "搜尋",
@ -465,7 +489,9 @@
"translate": "翻譯", "translate": "翻譯",
"light": "明亮的", "light": "明亮的",
"dark": "黑暗的", "dark": "黑暗的",
"system": "依系統" "system": "依系統",
"ratelimit": "實例已被限速",
"continue-search": "繼續搜索 "
}, },
"lang_bg": { "lang_bg": {
"search": "Търсене", "search": "Търсене",
@ -501,7 +527,9 @@
"translate": "превод", "translate": "превод",
"light": "светла", "light": "светла",
"dark": "тъмна", "dark": "тъмна",
"system": "системна" "system": "системна",
"ratelimit": "Екземплярът е с ограничена скорост",
"continue-search": "Продължете търсенето си с "
}, },
"lang_hi": { "lang_hi": {
"search": "खोज", "search": "खोज",
@ -537,9 +565,11 @@
"translate": "अनुवाद करना", "translate": "अनुवाद करना",
"light": "रोशनी", "light": "रोशनी",
"dark": "अंधेरा", "dark": "अंधेरा",
"system": "प्रणाली" "system": "प्रणाली",
"ratelimit": "इंस्टेंस को सीमित कर दिया गया है",
"continue-search": "के साथ अपनी खोज जारी रखें "
}, },
"lang_ja": { "lang_ja": {
"search": "検索", "search": "検索",
"config": "設定", "config": "設定",
"config-country": "国を設定する", "config-country": "国を設定する",
@ -573,6 +603,8 @@
"translate": "翻訳", "translate": "翻訳",
"light": "ライト", "light": "ライト",
"dark": "ダーク", "dark": "ダーク",
"system": "自動" "system": "自動",
"ratelimit": "インスタンスはレート制限されています",
"continue-search": "で検索を続ける "
} }
} }

View File

@ -1,6 +1,40 @@
<h1>Error</h1> {% if config.theme %}
<hr> {% if config.theme == 'system' %}
<p> <style>
Error: "{{ error_message|safe }}" @import "{{ cb_url('light-theme.css') }}" screen;
</p> @import "{{ cb_url('dark-theme.css') }}" screen and (prefers-color-scheme: dark);
<a href="/">Return Home</a> </style>
{% else %}
<link rel="stylesheet" href="{{ cb_url(config.theme + '-theme.css') }}"/>
{% endif %}
{% else %}
<link rel="stylesheet" href="{{ cb_url(('dark' if config.dark else 'light') + '-theme.css') }}"/>
{% endif %}
<link rel="stylesheet" href="{{ cb_url('main.css') }}">
<link rel="stylesheet" href="{{ cb_url('error.css') }}">
<style>{{ config.style }}</style>
<div>
<h1>Error</h1>
<p>
{{ error_message|safe }}
</p>
<hr>
<p>
{% if blocked is defined %}
<h4>{{ translation['continue-search'] }} <a class="link" href="https://github.com/benbusby/farside">Farside</a>!</h4>
Whoogle:
<br>
<a class="link-color" href="{{farside}}/whoogle/search?q={{query}}{{params}}">
{{farside}}/whoogle/search?q={{query}}{{params}}
</a>
<br><br>
Searx:
<br>
<a class="link-color" href="{{farside}}/searx/search?q={{query}}">
{{farside}}/searx/search?q={{query}}
</a>
<hr>
{% endif %}
</p>
<a class="link" href="home">Return Home</a>
</div>

View File

@ -1,7 +1,7 @@
<footer> <footer>
<p class="footer"> <p class="footer">
Whoogle Search v{{ version_number }} || Whoogle Search v{{ version_number }} ||
<a id="gh-link" href="https://github.com/benbusby/whoogle-search">{{ translation['github-link'] }}</a> <a class="link" href="https://github.com/benbusby/whoogle-search">{{ translation['github-link'] }}</a>
{% if newest_version %} {% if newest_version %}
|| <span class="update_available">Update Available 🟢</span> || <span class="update_available">Update Available 🟢</span>
{% endif %} {% endif %}