mirror of https://github.com/searxng/searxng.git
Compare commits
6 Commits
8a22ae5ee7
...
e956b25190
Author | SHA1 | Date |
---|---|---|
Markus Heiser | e956b25190 | |
Markus Heiser | 0f9694c90b | |
Markus Heiser | ccc4f30b20 | |
Markus Heiser | c4b874e9b0 | |
Markus Heiser | 7c4e4ebd40 | |
Markus Heiser | 1c9b28968d |
|
@ -4,22 +4,27 @@ Welcome to SearXNG
|
||||||
|
|
||||||
*Search without being tracked.*
|
*Search without being tracked.*
|
||||||
|
|
||||||
SearXNG is a free internet metasearch engine which aggregates results from more
|
.. jinja:: searx
|
||||||
than 70 search services. Users are neither tracked nor profiled. Additionally,
|
|
||||||
SearXNG can be used over Tor for online anonymity.
|
SearXNG is a free internet metasearch engine which aggregates results from up
|
||||||
|
to {{engines | length}} :ref:`search services <configured engines>`. Users
|
||||||
|
are neither tracked nor profiled. Additionally, SearXNG can be used over Tor
|
||||||
|
for online anonymity.
|
||||||
|
|
||||||
Get started with SearXNG by using one of the instances listed at searx.space_.
|
Get started with SearXNG by using one of the instances listed at searx.space_.
|
||||||
If you don't trust anyone, you can set up your own, see :ref:`installation`.
|
If you don't trust anyone, you can set up your own, see :ref:`installation`.
|
||||||
|
|
||||||
.. sidebar:: features
|
.. jinja:: searx
|
||||||
|
|
||||||
|
.. sidebar:: features
|
||||||
|
|
||||||
- :ref:`self hosted <installation>`
|
- :ref:`self hosted <installation>`
|
||||||
- :ref:`no user tracking / no profiling <SearXNG protect privacy>`
|
- :ref:`no user tracking / no profiling <SearXNG protect privacy>`
|
||||||
- script & cookies are optional
|
- script & cookies are optional
|
||||||
- secure, encrypted connections
|
- secure, encrypted connections
|
||||||
- :ref:`about 200 search engines <configured engines>`
|
- :ref:`{{engines | length}} search engines <configured engines>`
|
||||||
- `about 60 translations <https://translate.codeberg.org/projects/searxng/searxng/>`_
|
- `58 translations <https://translate.codeberg.org/projects/searxng/searxng/>`_
|
||||||
- about 100 `well maintained <https://uptime.searxng.org/>`__ instances on searx.space_
|
- about 70 `well maintained <https://uptime.searxng.org/>`__ instances on searx.space_
|
||||||
- :ref:`easy integration of search engines <demo online engine>`
|
- :ref:`easy integration of search engines <demo online engine>`
|
||||||
- professional development: `CI <https://github.com/searxng/searxng/actions>`_,
|
- professional development: `CI <https://github.com/searxng/searxng/actions>`_,
|
||||||
`quality assurance <https://dev.searxng.org/>`_ &
|
`quality assurance <https://dev.searxng.org/>`_ &
|
||||||
|
|
|
@ -53,6 +53,9 @@ Probe HTTP headers
|
||||||
.. automodule:: searx.botdetection.http_user_agent
|
.. automodule:: searx.botdetection.http_user_agent
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
.. automodule:: searx.botdetection.sec_fetch
|
||||||
|
:members:
|
||||||
|
|
||||||
.. _botdetection config:
|
.. _botdetection config:
|
||||||
|
|
||||||
Config
|
Config
|
||||||
|
|
|
@ -31,6 +31,9 @@ def dump_request(request: flask.Request):
|
||||||
+ " || Content-Length: %s" % request.headers.get('Content-Length')
|
+ " || Content-Length: %s" % request.headers.get('Content-Length')
|
||||||
+ " || Connection: %s" % request.headers.get('Connection')
|
+ " || Connection: %s" % request.headers.get('Connection')
|
||||||
+ " || User-Agent: %s" % request.headers.get('User-Agent')
|
+ " || User-Agent: %s" % request.headers.get('User-Agent')
|
||||||
|
+ " || Sec-Fetch-Site: %s" % request.headers.get('Sec-Fetch-Site')
|
||||||
|
+ " || Sec-Fetch-Mode: %s" % request.headers.get('Sec-Fetch-Mode')
|
||||||
|
+ " || Sec-Fetch-Dest: %s" % request.headers.get('Sec-Fetch-Dest')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
"""
|
||||||
|
Method ``http_sec_fetch``
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
The ``http_sec_fetch`` method protect resources from web attacks with `Fetch
|
||||||
|
Metadata`_. A request is filtered out in case of:
|
||||||
|
|
||||||
|
- http header Sec-Fetch-Mode_ is invalid
|
||||||
|
- http header Sec-Fetch-Dest_ is invalid
|
||||||
|
|
||||||
|
.. _Fetch Metadata:
|
||||||
|
https://developer.mozilla.org/en-US/docs/Glossary/Fetch_metadata_request_header
|
||||||
|
|
||||||
|
.. Sec-Fetch-Dest:
|
||||||
|
https://developer.mozilla.org/en-US/docs/Web/API/Request/destination
|
||||||
|
|
||||||
|
.. Sec-Fetch-Mode:
|
||||||
|
https://developer.mozilla.org/en-US/docs/Web/API/Request/mode
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
from ipaddress import (
|
||||||
|
IPv4Network,
|
||||||
|
IPv6Network,
|
||||||
|
)
|
||||||
|
|
||||||
|
import flask
|
||||||
|
import werkzeug
|
||||||
|
|
||||||
|
from . import config
|
||||||
|
from ._helpers import logger
|
||||||
|
|
||||||
|
|
||||||
|
def filter_request(
|
||||||
|
network: IPv4Network | IPv6Network,
|
||||||
|
request: flask.Request,
|
||||||
|
cfg: config.Config,
|
||||||
|
) -> werkzeug.Response | None:
|
||||||
|
|
||||||
|
val = request.headers.get("Sec-Fetch-Mode", "")
|
||||||
|
if val != "navigate":
|
||||||
|
logger.debug("invalid Sec-Fetch-Mode '%s'", val)
|
||||||
|
return flask.redirect(flask.url_for('index'), code=302)
|
||||||
|
|
||||||
|
val = request.headers.get("Sec-Fetch-Site", "")
|
||||||
|
if val not in ('same-origin', 'same-site', 'none'):
|
||||||
|
logger.debug("invalid Sec-Fetch-Site '%s'", val)
|
||||||
|
flask.redirect(flask.url_for('index'), code=302)
|
||||||
|
|
||||||
|
val = request.headers.get("Sec-Fetch-Dest", "")
|
||||||
|
if val != "document":
|
||||||
|
logger.debug("invalid Sec-Fetch-Dest '%s'", val)
|
||||||
|
flask.redirect(flask.url_for('index'), code=302)
|
||||||
|
|
||||||
|
return None
|
|
@ -1,71 +0,0 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
"""Internet Archive scholar(science)
|
|
||||||
"""
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from urllib.parse import urlencode
|
|
||||||
from searx.utils import html_to_text
|
|
||||||
|
|
||||||
about = {
|
|
||||||
"website": "https://scholar.archive.org/",
|
|
||||||
"wikidata_id": "Q115667709",
|
|
||||||
"official_api_documentation": "https://scholar.archive.org/api/redoc",
|
|
||||||
"use_official_api": True,
|
|
||||||
"require_api_key": False,
|
|
||||||
"results": "JSON",
|
|
||||||
}
|
|
||||||
categories = ['science', 'scientific publications']
|
|
||||||
paging = True
|
|
||||||
|
|
||||||
base_url = "https://scholar.archive.org"
|
|
||||||
results_per_page = 15
|
|
||||||
|
|
||||||
|
|
||||||
def request(query, params):
|
|
||||||
args = {
|
|
||||||
"q": query,
|
|
||||||
"limit": results_per_page,
|
|
||||||
"offset": (params["pageno"] - 1) * results_per_page,
|
|
||||||
}
|
|
||||||
params["url"] = f"{base_url}/search?{urlencode(args)}"
|
|
||||||
params["headers"]["Accept"] = "application/json"
|
|
||||||
return params
|
|
||||||
|
|
||||||
|
|
||||||
def response(resp):
|
|
||||||
results = []
|
|
||||||
|
|
||||||
json = resp.json()
|
|
||||||
|
|
||||||
for result in json["results"]:
|
|
||||||
publishedDate, content, doi = None, '', None
|
|
||||||
|
|
||||||
if result['biblio'].get('release_date'):
|
|
||||||
publishedDate = datetime.strptime(result['biblio']['release_date'], "%Y-%m-%d")
|
|
||||||
|
|
||||||
if len(result['abstracts']) > 0:
|
|
||||||
content = result['abstracts'][0].get('body')
|
|
||||||
elif len(result['_highlights']) > 0:
|
|
||||||
content = result['_highlights'][0]
|
|
||||||
|
|
||||||
if len(result['releases']) > 0:
|
|
||||||
doi = result['releases'][0].get('doi')
|
|
||||||
|
|
||||||
results.append(
|
|
||||||
{
|
|
||||||
'template': 'paper.html',
|
|
||||||
'url': result['fulltext']['access_url'],
|
|
||||||
'title': result['biblio'].get('title') or result['biblio'].get('container_name'),
|
|
||||||
'content': html_to_text(content),
|
|
||||||
'publisher': result['biblio'].get('publisher'),
|
|
||||||
'doi': doi,
|
|
||||||
'journal': result['biblio'].get('container_name'),
|
|
||||||
'authors': result['biblio'].get('contrib_names'),
|
|
||||||
'tags': result['tags'],
|
|
||||||
'publishedDate': publishedDate,
|
|
||||||
'issns': result['biblio'].get('issns'),
|
|
||||||
'pdf_url': result['fulltext'].get('access_url'),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return results
|
|
|
@ -27,7 +27,7 @@ categories = ['images']
|
||||||
paging = True
|
paging = True
|
||||||
|
|
||||||
endpoint = 'photos'
|
endpoint = 'photos'
|
||||||
base_url = 'https://loc.gov'
|
base_url = 'https://www.loc.gov'
|
||||||
search_string = "/{endpoint}/?sp={page}&{query}&fo=json"
|
search_string = "/{endpoint}/?sp={page}&{query}&fo=json"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,7 @@ from searx.botdetection import (
|
||||||
http_accept_encoding,
|
http_accept_encoding,
|
||||||
http_accept_language,
|
http_accept_language,
|
||||||
http_user_agent,
|
http_user_agent,
|
||||||
|
http_sec_fetch,
|
||||||
ip_limit,
|
ip_limit,
|
||||||
ip_lists,
|
ip_lists,
|
||||||
get_network,
|
get_network,
|
||||||
|
@ -178,16 +179,17 @@ def filter_request(request: flask.Request) -> werkzeug.Response | None:
|
||||||
logger.error("BLOCK %s: matched BLOCKLIST - %s", network.compressed, msg)
|
logger.error("BLOCK %s: matched BLOCKLIST - %s", network.compressed, msg)
|
||||||
return flask.make_response(('IP is on BLOCKLIST - %s' % msg, 429))
|
return flask.make_response(('IP is on BLOCKLIST - %s' % msg, 429))
|
||||||
|
|
||||||
# methods applied on /
|
# methods applied on all requests
|
||||||
|
|
||||||
for func in [
|
for func in [
|
||||||
http_user_agent,
|
http_user_agent,
|
||||||
]:
|
]:
|
||||||
val = func.filter_request(network, request, cfg)
|
val = func.filter_request(network, request, cfg)
|
||||||
if val is not None:
|
if val is not None:
|
||||||
|
logger.debug(f"NOT OK ({func.__name__}): {network}: %s", dump_request(flask.request))
|
||||||
return val
|
return val
|
||||||
|
|
||||||
# methods applied on /search
|
# methods applied on /search requests
|
||||||
|
|
||||||
if request.path == '/search':
|
if request.path == '/search':
|
||||||
|
|
||||||
|
@ -196,12 +198,15 @@ def filter_request(request: flask.Request) -> werkzeug.Response | None:
|
||||||
http_accept_encoding,
|
http_accept_encoding,
|
||||||
http_accept_language,
|
http_accept_language,
|
||||||
http_user_agent,
|
http_user_agent,
|
||||||
|
http_sec_fetch,
|
||||||
ip_limit,
|
ip_limit,
|
||||||
]:
|
]:
|
||||||
val = func.filter_request(network, request, cfg)
|
val = func.filter_request(network, request, cfg)
|
||||||
if val is not None:
|
if val is not None:
|
||||||
|
logger.debug(f"NOT OK ({func.__name__}): {network}: %s", dump_request(flask.request))
|
||||||
return val
|
return val
|
||||||
logger.debug(f"OK {network}: %s", dump_request(flask.request))
|
logger.debug(f"OK: {network}: %s", dump_request(flask.request))
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -233,8 +233,7 @@ class Network:
|
||||||
del kwargs['raise_for_httperror']
|
del kwargs['raise_for_httperror']
|
||||||
return do_raise_for_httperror
|
return do_raise_for_httperror
|
||||||
|
|
||||||
@staticmethod
|
def patch_response(self, response, do_raise_for_httperror):
|
||||||
def patch_response(response, do_raise_for_httperror):
|
|
||||||
if isinstance(response, httpx.Response):
|
if isinstance(response, httpx.Response):
|
||||||
# requests compatibility (response is not streamed)
|
# requests compatibility (response is not streamed)
|
||||||
# see also https://www.python-httpx.org/compatibility/#checking-for-4xx5xx-responses
|
# see also https://www.python-httpx.org/compatibility/#checking-for-4xx5xx-responses
|
||||||
|
@ -242,8 +241,11 @@ class Network:
|
||||||
|
|
||||||
# raise an exception
|
# raise an exception
|
||||||
if do_raise_for_httperror:
|
if do_raise_for_httperror:
|
||||||
|
try:
|
||||||
raise_for_httperror(response)
|
raise_for_httperror(response)
|
||||||
|
except:
|
||||||
|
self._logger.warning(f"HTTP Request failed: {response.request.method} {response.request.url}")
|
||||||
|
raise
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def is_valid_response(self, response):
|
def is_valid_response(self, response):
|
||||||
|
@ -269,7 +271,7 @@ class Network:
|
||||||
else:
|
else:
|
||||||
response = await client.request(method, url, **kwargs)
|
response = await client.request(method, url, **kwargs)
|
||||||
if self.is_valid_response(response) or retries <= 0:
|
if self.is_valid_response(response) or retries <= 0:
|
||||||
return Network.patch_response(response, do_raise_for_httperror)
|
return self.patch_response(response, do_raise_for_httperror)
|
||||||
except httpx.RemoteProtocolError as e:
|
except httpx.RemoteProtocolError as e:
|
||||||
if not was_disconnected:
|
if not was_disconnected:
|
||||||
# the server has closed the connection:
|
# the server has closed the connection:
|
||||||
|
|
|
@ -137,9 +137,6 @@ class OnlineProcessor(EngineProcessor):
|
||||||
self.engine.request(query, params)
|
self.engine.request(query, params)
|
||||||
|
|
||||||
# ignoring empty urls
|
# ignoring empty urls
|
||||||
if params['url'] is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
if not params['url']:
|
if not params['url']:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -1622,11 +1622,6 @@ engines:
|
||||||
api_site: 'askubuntu'
|
api_site: 'askubuntu'
|
||||||
categories: [it, q&a]
|
categories: [it, q&a]
|
||||||
|
|
||||||
- name: internetarchivescholar
|
|
||||||
engine: internet_archive_scholar
|
|
||||||
shortcut: ias
|
|
||||||
timeout: 15.0
|
|
||||||
|
|
||||||
- name: superuser
|
- name: superuser
|
||||||
engine: stackexchange
|
engine: stackexchange
|
||||||
shortcut: su
|
shortcut: su
|
||||||
|
|
Loading…
Reference in New Issue