Merge remote-tracking branch 'origin/main' into heroku-app
This commit is contained in:
commit
0ebe688ae9
|
@ -1,3 +1,4 @@
|
||||||
|
from app.filter import clean_query
|
||||||
from app.request import send_tor_signal
|
from app.request import send_tor_signal
|
||||||
from app.utils.session import generate_user_key
|
from app.utils.session import generate_user_key
|
||||||
from app.utils.bangs import gen_bangs_json
|
from app.utils.bangs import gen_bangs_json
|
||||||
|
@ -60,6 +61,9 @@ app.config['CSP'] = 'default-src \'none\';' \
|
||||||
'connect-src \'self\';' \
|
'connect-src \'self\';' \
|
||||||
'form-action \'self\';'
|
'form-action \'self\';'
|
||||||
|
|
||||||
|
# Templating functions
|
||||||
|
app.jinja_env.globals.update(clean_query=clean_query)
|
||||||
|
|
||||||
if not os.path.exists(app.config['CONFIG_PATH']):
|
if not os.path.exists(app.config['CONFIG_PATH']):
|
||||||
os.makedirs(app.config['CONFIG_PATH'])
|
os.makedirs(app.config['CONFIG_PATH'])
|
||||||
|
|
||||||
|
|
|
@ -9,19 +9,6 @@ import urllib.parse as urlparse
|
||||||
from urllib.parse import parse_qs
|
from urllib.parse import parse_qs
|
||||||
|
|
||||||
|
|
||||||
def strip_blocked_sites(query: str) -> str:
|
|
||||||
"""Strips the blocked site list from the query, if one is being
|
|
||||||
used.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
query: The query string
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: The query string without any "-site:..." filters
|
|
||||||
"""
|
|
||||||
return query[:query.find('-site:')] if '-site:' in query else query
|
|
||||||
|
|
||||||
|
|
||||||
def extract_q(q_str: str, href: str) -> str:
|
def extract_q(q_str: str, href: str) -> str:
|
||||||
"""Extracts the 'q' element from a result link. This is typically
|
"""Extracts the 'q' element from a result link. This is typically
|
||||||
either the link to a result's website, or a string.
|
either the link to a result's website, or a string.
|
||||||
|
@ -37,6 +24,19 @@ def extract_q(q_str: str, href: str) -> str:
|
||||||
return parse_qs(q_str)['q'][0] if ('&q=' in href or '?q=' in href) else ''
|
return parse_qs(q_str)['q'][0] if ('&q=' in href or '?q=' in href) else ''
|
||||||
|
|
||||||
|
|
||||||
|
def clean_query(query: str) -> str:
|
||||||
|
"""Strips the blocked site list from the query, if one is being
|
||||||
|
used.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
query: The query string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The query string without any "-site:..." filters
|
||||||
|
"""
|
||||||
|
return query[:query.find('-site:')] if '-site:' in query else query
|
||||||
|
|
||||||
|
|
||||||
class Filter:
|
class Filter:
|
||||||
def __init__(self, user_key: str, mobile=False, config=None) -> None:
|
def __init__(self, user_key: str, mobile=False, config=None) -> None:
|
||||||
if config is None:
|
if config is None:
|
||||||
|
@ -268,7 +268,7 @@ class Filter:
|
||||||
else:
|
else:
|
||||||
if href.startswith(MAPS_URL):
|
if href.startswith(MAPS_URL):
|
||||||
# Maps links don't work if a site filter is applied
|
# Maps links don't work if a site filter is applied
|
||||||
link['href'] = MAPS_URL + "?q=" + strip_blocked_sites(q)
|
link['href'] = MAPS_URL + "?q=" + clean_query(q)
|
||||||
else:
|
else:
|
||||||
link['href'] = href
|
link['href'] = href
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,9 @@ DESKTOP_UA = '{}/5.0 (X11; {} x86_64; rv:75.0) Gecko/20100101 {}/75.0'
|
||||||
# Valid query params
|
# Valid query params
|
||||||
VALID_PARAMS = ['tbs', 'tbm', 'start', 'near', 'source', 'nfpr']
|
VALID_PARAMS = ['tbs', 'tbm', 'start', 'near', 'source', 'nfpr']
|
||||||
|
|
||||||
|
# Fallback language if none have been configured
|
||||||
|
DEFAULT_LANG = 'lang_en'
|
||||||
|
|
||||||
|
|
||||||
class TorError(Exception):
|
class TorError(Exception):
|
||||||
"""Exception raised for errors in Tor requests.
|
"""Exception raised for errors in Tor requests.
|
||||||
|
@ -108,23 +111,28 @@ def gen_query(query, args, config, near_city=None) -> str:
|
||||||
[_ for _ in lang if not _.isdigit()]
|
[_ for _ in lang if not _.isdigit()]
|
||||||
)) if lang else ''
|
)) if lang else ''
|
||||||
else:
|
else:
|
||||||
param_dict['lr'] = (
|
param_dict['lr'] = '&lr=' + (
|
||||||
'&lr=' + config.lang_search
|
config.lang_search if config.lang_search else DEFAULT_LANG
|
||||||
) if config.lang_search else ''
|
)
|
||||||
|
|
||||||
# 'nfpr' defines the exclusion of results from an auto-corrected query
|
# 'nfpr' defines the exclusion of results from an auto-corrected query
|
||||||
if 'nfpr' in args:
|
if 'nfpr' in args:
|
||||||
param_dict['nfpr'] = '&nfpr=' + args.get('nfpr')
|
param_dict['nfpr'] = '&nfpr=' + args.get('nfpr')
|
||||||
|
|
||||||
param_dict['cr'] = ('&cr=' + config.ctry) if config.ctry else ''
|
param_dict['cr'] = ('&cr=' + config.ctry) if config.ctry else ''
|
||||||
param_dict['hl'] = (
|
param_dict['hl'] = '&hl=' + (
|
||||||
'&hl=' + config.lang_interface.replace('lang_', '')
|
config.lang_interface.replace('lang_', '')
|
||||||
) if config.lang_interface else ''
|
if config.lang_interface else DEFAULT_LANG.replace('lang_', '')
|
||||||
|
)
|
||||||
param_dict['safe'] = '&safe=' + ('active' if config.safe else 'off')
|
param_dict['safe'] = '&safe=' + ('active' if config.safe else 'off')
|
||||||
|
|
||||||
# Block all sites specified in the user config
|
# Block all sites specified in the user config
|
||||||
for blocked in config.block.split(','):
|
unquoted_query = urlparse.unquote(query)
|
||||||
query += (' -site:' + blocked) if blocked else ''
|
for blocked_site in config.block.replace(' ', '').split(','):
|
||||||
|
if not blocked_site:
|
||||||
|
continue
|
||||||
|
block = (' -site:' + blocked_site)
|
||||||
|
query += block if block not in unquoted_query else ''
|
||||||
|
|
||||||
for val in param_dict.values():
|
for val in param_dict.values():
|
||||||
if not val:
|
if not val:
|
||||||
|
@ -149,7 +157,9 @@ class Request:
|
||||||
# enable Tor for future requests
|
# enable Tor for future requests
|
||||||
send_tor_signal(Signal.HEARTBEAT)
|
send_tor_signal(Signal.HEARTBEAT)
|
||||||
|
|
||||||
self.language = config.lang_search
|
self.language = (
|
||||||
|
config.lang_search if config.lang_search else DEFAULT_LANG
|
||||||
|
)
|
||||||
self.mobile = 'Android' in normal_ua or 'iPhone' in normal_ua
|
self.mobile = 'Android' in normal_ua or 'iPhone' in normal_ua
|
||||||
self.modified_user_agent = gen_user_agent(self.mobile)
|
self.modified_user_agent = gen_user_agent(self.mobile)
|
||||||
if not self.mobile:
|
if not self.mobile:
|
||||||
|
@ -210,6 +220,8 @@ class Request:
|
||||||
query: The optional query string for the request
|
query: The optional query string for the request
|
||||||
attempt: The number of attempts made for the request
|
attempt: The number of attempts made for the request
|
||||||
(used for cycling through Tor identities, if enabled)
|
(used for cycling through Tor identities, if enabled)
|
||||||
|
force_mobile: Optional flag to enable a mobile user agent
|
||||||
|
(used for fetching full size images in search results)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Response: The Response object returned by the requests call
|
Response: The Response object returned by the requests call
|
||||||
|
|
|
@ -13,7 +13,6 @@ from flask import jsonify, make_response, request, redirect, render_template, \
|
||||||
from requests import exceptions
|
from requests import exceptions
|
||||||
|
|
||||||
from app import app
|
from app import app
|
||||||
from app.filter import strip_blocked_sites
|
|
||||||
from app.models.config import Config
|
from app.models.config import Config
|
||||||
from app.request import Request, TorError
|
from app.request import Request, TorError
|
||||||
from app.utils.bangs import resolve_bang
|
from app.utils.bangs import resolve_bang
|
||||||
|
@ -248,7 +247,7 @@ def search():
|
||||||
'header.html',
|
'header.html',
|
||||||
config=g.user_config,
|
config=g.user_config,
|
||||||
logo=render_template('logo.html', dark=g.user_config.dark),
|
logo=render_template('logo.html', dark=g.user_config.dark),
|
||||||
query=strip_blocked_sites(urlparse.unquote(query)),
|
query=urlparse.unquote(query),
|
||||||
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 search_util.search_type else '')), resp_code
|
if 'isch' not in search_util.search_type else '')), resp_code
|
||||||
|
|
|
@ -138,5 +138,33 @@
|
||||||
"apply": "Applica",
|
"apply": "Applica",
|
||||||
"save-as": "Salva Come...",
|
"save-as": "Salva Come...",
|
||||||
"github-link": "Guarda su GitHub"
|
"github-link": "Guarda su GitHub"
|
||||||
|
},
|
||||||
|
"lang_pt": {
|
||||||
|
"search": "Buscar",
|
||||||
|
"config": "Configuração",
|
||||||
|
"config-country": "Filtrar Resultados por País",
|
||||||
|
"config-country-help": "Observação: Se ativado, um site só aparecerá nos resultados da pesquisa se estiver *hospedado* no país selecionado.",
|
||||||
|
"config-lang": "Idioma da Interface",
|
||||||
|
"config-lang-search": "Idioma da Busca",
|
||||||
|
"config-near": "Perto",
|
||||||
|
"config-near-help": "Nome da Cidade",
|
||||||
|
"config-block": "Bloquear",
|
||||||
|
"config-block-help": "Lista de sites separados por vírgulas",
|
||||||
|
"config-nojs": "Mostrar Links NoJS",
|
||||||
|
"config-dark": "Modo Escuro",
|
||||||
|
"config-safe": "Busca Segura",
|
||||||
|
"config-alts": "Substituir Links de Redes Sociais",
|
||||||
|
"config-alts-help": "Substitui os links do Twitter/YouTube/Instagram/etc. por alternativas que respeitam sua privacidade.",
|
||||||
|
"config-new-tab": "Abrir Links em Nova Aba",
|
||||||
|
"config-images": "Busca de Imagem em Tamanho Real",
|
||||||
|
"config-images-help": "(Experimental) Adiciona a opção 'Exibir Imagem' às buscas de imagens no modo 'para computador'. Isso fará com que as miniaturas do resultado da imagem sejam de menor resolução.",
|
||||||
|
"config-tor": "Usar Tor",
|
||||||
|
"config-get-only": "Apenas Solicitações GET",
|
||||||
|
"config-url": "URL Fonte",
|
||||||
|
"config-css": "CSS Personalizado",
|
||||||
|
"load": "Carregar",
|
||||||
|
"apply": "Aplicar",
|
||||||
|
"save-as": "Salvar Como...",
|
||||||
|
"github-link": "Ver no GitHub"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<link rel="stylesheet" href="static/css/header.css">
|
<link rel="stylesheet" href="static/css/header.css">
|
||||||
<link rel="stylesheet" href="static/css/{{ 'dark' if config.dark else 'light' }}-theme.css"/>
|
<link rel="stylesheet" href="static/css/{{ 'dark' if config.dark else 'light' }}-theme.css"/>
|
||||||
<style>{{ config.style }}</style>
|
<style>{{ config.style }}</style>
|
||||||
<title>{{ query }} - Whoogle Search</title>
|
<title>{{ clean_query(query) }} - Whoogle Search</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{{ search_header|safe }}
|
{{ search_header|safe }}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
style="background-color: {{ 'var(--whoogle-dark-result-bg)' if config.dark else 'var(--whoogle-result-bg)' }} !important;
|
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)' }};"
|
color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }};"
|
||||||
type="text"
|
type="text"
|
||||||
value="{{ query }}">
|
value="{{ clean_query(query) }}">
|
||||||
<input style="color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }}" id="search-reset" type="reset" value="x">
|
<input style="color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }}" id="search-reset" type="reset" value="x">
|
||||||
<input name="tbm" value="{{ search_type }}" style="display: none">
|
<input name="tbm" value="{{ search_type }}" style="display: none">
|
||||||
<input type="submit" style="display: none;">
|
<input type="submit" style="display: none;">
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
name="q"
|
name="q"
|
||||||
spellcheck="false"
|
spellcheck="false"
|
||||||
type="text"
|
type="text"
|
||||||
value="{{ query }}"
|
value="{{ clean_query(query) }}"
|
||||||
style="background-color: {{ 'var(--whoogle-dark-result-bg)' if config.dark else 'var(--whoogle-result-bg)' }} !important;
|
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)' }};
|
color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }};
|
||||||
border-bottom: {{ '2px solid var(--whoogle-dark-element-bg)' if config.dark else '0px' }};">
|
border-bottom: {{ '2px solid var(--whoogle-dark-element-bg)' if config.dark else '0px' }};">
|
||||||
|
|
|
@ -158,7 +158,7 @@
|
||||||
spellcheck="false"
|
spellcheck="false"
|
||||||
autocorrect="off"
|
autocorrect="off"
|
||||||
value="">
|
value="">
|
||||||
{{ config.style }}
|
{{ config.style.replace('\t', '') }}
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="config-div">
|
<div class="config-div">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user