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:
Emilien Devos 2023-09-24 11:02:29 +02:00 committed by Alexandre Flament
parent 1df4588279
commit 47721a3485
5 changed files with 14 additions and 4 deletions

View file

@ -47,6 +47,7 @@ from ipaddress import (
import flask import flask
import werkzeug import werkzeug
from searx.tools import config from searx.tools import config
from searx import settings
from searx import redisdb from searx import redisdb
from searx.redislib import incr_sliding_window, drop_counter from searx.redislib import incr_sliding_window, drop_counter
@ -109,7 +110,7 @@ def filter_request(
if c > API_MAX: if c > API_MAX:
return too_many_requests(network, "too many request in API_WINDOW") 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) suspicious = link_token.is_suspicious(network, request, True)

View file

@ -3,6 +3,7 @@
# pyright: basic # pyright: basic
"""see :ref:`limiter src`""" """see :ref:`limiter src`"""
import sys
import flask import flask
from searx import redisdb from searx import redisdb
@ -23,10 +24,15 @@ def pre_request():
def init(app: flask.Flask, settings) -> bool: 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 return False
if not redisdb.client(): 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 return False
app.before_request(pre_request) app.before_request(pre_request)
return True return True

View file

@ -74,6 +74,7 @@ server:
# by ${SEARXNG_URL}. # by ${SEARXNG_URL}.
base_url: false # "http://example.com/location" base_url: false # "http://example.com/location"
limiter: false # rate limit the number of request on the instance, block some bots 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 # If your instance owns a /etc/searxng/settings.yml file, then set the following
# values there. # values there.
@ -95,7 +96,7 @@ server:
redis: redis:
# URL to connect redis database. Is overwritten by ${SEARXNG_REDIS_URL}. # 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 url: false
ui: ui:

View file

@ -174,6 +174,7 @@ SCHEMA = {
'port': SettingsValue((int, str), 8888, 'SEARXNG_PORT'), 'port': SettingsValue((int, str), 8888, 'SEARXNG_PORT'),
'bind_address': SettingsValue(str, '127.0.0.1', 'SEARXNG_BIND_ADDRESS'), 'bind_address': SettingsValue(str, '127.0.0.1', 'SEARXNG_BIND_ADDRESS'),
'limiter': SettingsValue(bool, False), 'limiter': SettingsValue(bool, False),
'public_instance': SettingsValue(bool, False),
'secret_key': SettingsValue(str, environ_name='SEARXNG_SECRET'), 'secret_key': SettingsValue(str, environ_name='SEARXNG_SECRET'),
'base_url': SettingsValue((False, str), False, 'SEARXNG_BASE_URL'), 'base_url': SettingsValue((False, str), False, 'SEARXNG_BASE_URL'),
'image_proxy': SettingsValue(bool, False), 'image_proxy': SettingsValue(bool, False),

View file

@ -1294,6 +1294,7 @@ def config():
}, },
'doi_resolvers': list(settings['doi_resolvers'].keys()), 'doi_resolvers': list(settings['doi_resolvers'].keys()),
'default_doi_resolver': settings['default_doi_resolver'], 'default_doi_resolver': settings['default_doi_resolver'],
'public_instance': settings['server']['public_instance'],
} }
) )