[mod] document server:public_instance & remove it out of the botdetection

- the option server:public_instance lacks some documentation
- the processing of this option belongs in the limiter and not
  in botdetection module

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2023-10-02 18:29:58 +02:00 committed by Markus Heiser
parent fd814aac86
commit d13a8f6453
4 changed files with 29 additions and 9 deletions

View file

@ -211,23 +211,33 @@ def pre_request():
def is_installed():
"""Returns ``True`` if limiter is active and a redis DB is available."""
return _INSTALLED
def initialize(app: flask.Flask, settings):
"""Instal the botlimiter aka limiter"""
"""Install the limiter"""
global _INSTALLED # pylint: disable=global-statement
if not settings['server']['limiter'] and not settings['server']['public_instance']:
if not (settings['server']['limiter'] or settings['server']['public_instance']):
return
redis_client = redisdb.client()
if not redis_client:
logger.error(
"The limiter requires Redis, please consult the documentation: "
+ "https://docs.searxng.org/admin/searx.botdetection.html#limiter"
"https://docs.searxng.org/admin/searx.limiter.html"
)
if settings['server']['public_instance']:
sys.exit(1)
return
botdetection.init(get_cfg(), redis_client)
app.before_request(pre_request)
_INSTALLED = True
cfg = get_cfg()
if settings['server']['public_instance']:
# overwrite limiter.toml setting
cfg.set('botdetection.ip_limit.link_token', True)
botdetection.init(cfg, redis_client)
app.before_request(pre_request)