forked from zaclys/searxng
add new parameter called server.public_instance
for enabling by default advanced limiter functions in the future allow us to add features just for the public instances
This commit is contained in:
parent
7722a9b40e
commit
078d4a4d9c
@ -47,6 +47,7 @@ from ipaddress import (
|
||||
import flask
|
||||
import werkzeug
|
||||
from searx.tools import config
|
||||
from searx import settings
|
||||
|
||||
from searx import redisdb
|
||||
from searx.redislib import incr_sliding_window, drop_counter
|
||||
@ -109,7 +110,7 @@ def filter_request(
|
||||
if c > API_MAX:
|
||||
return too_many_requests(network, "too many request in API_WINDOW")
|
||||
|
||||
if cfg['botdetection.ip_limit.link_token']:
|
||||
if settings['server']['public_instance'] or cfg['botdetection.ip_limit.link_token']:
|
||||
|
||||
suspicious = link_token.is_suspicious(network, request, True)
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
# pyright: basic
|
||||
"""see :ref:`limiter src`"""
|
||||
|
||||
import sys
|
||||
import flask
|
||||
|
||||
from searx import redisdb
|
||||
@ -23,10 +24,15 @@ def pre_request():
|
||||
|
||||
|
||||
def init(app: flask.Flask, settings) -> bool:
|
||||
if not settings['server']['limiter']:
|
||||
if not settings['server']['limiter'] and not settings['server']['public_instance']:
|
||||
return False
|
||||
if not redisdb.client():
|
||||
logger.error("The limiter requires Redis")
|
||||
logger.error(
|
||||
"The limiter requires Redis, please consult the documentation: "
|
||||
+ "https://docs.searxng.org/admin/searx.botdetection.html#limiter"
|
||||
)
|
||||
if settings['server']['public_instance']:
|
||||
sys.exit(1)
|
||||
return False
|
||||
app.before_request(pre_request)
|
||||
return True
|
||||
|
@ -74,6 +74,7 @@ server:
|
||||
# by ${SEARXNG_URL}.
|
||||
base_url: false # "http://example.com/location"
|
||||
limiter: false # rate limit the number of request on the instance, block some bots
|
||||
public_instance: false # enable features designed only for public instances
|
||||
|
||||
# If your instance owns a /etc/searxng/settings.yml file, then set the following
|
||||
# values there.
|
||||
@ -95,7 +96,7 @@ server:
|
||||
|
||||
redis:
|
||||
# URL to connect redis database. Is overwritten by ${SEARXNG_REDIS_URL}.
|
||||
# https://redis-py.readthedocs.io/en/stable/connections.html#redis.client.Redis.from_url
|
||||
# https://docs.searxng.org/admin/settings/settings_redis.html#settings-redis
|
||||
url: false
|
||||
|
||||
ui:
|
||||
|
@ -174,6 +174,7 @@ SCHEMA = {
|
||||
'port': SettingsValue((int, str), 8888, 'SEARXNG_PORT'),
|
||||
'bind_address': SettingsValue(str, '127.0.0.1', 'SEARXNG_BIND_ADDRESS'),
|
||||
'limiter': SettingsValue(bool, False),
|
||||
'public_instance': SettingsValue(bool, False),
|
||||
'secret_key': SettingsValue(str, environ_name='SEARXNG_SECRET'),
|
||||
'base_url': SettingsValue((False, str), False, 'SEARXNG_BASE_URL'),
|
||||
'image_proxy': SettingsValue(bool, False),
|
||||
|
@ -1294,6 +1294,7 @@ def config():
|
||||
},
|
||||
'doi_resolvers': list(settings['doi_resolvers'].keys()),
|
||||
'default_doi_resolver': settings['default_doi_resolver'],
|
||||
'public_instance': settings['server']['public_instance'],
|
||||
}
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user