Add ability to enabled/disable bouncer from config.
This commit is contained in:
parent
f8eac632a9
commit
d65ae46067
3 changed files with 11 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
ENABLED=true
|
||||||
API_URL=${CROWDSEC_LAPI_URL}
|
API_URL=${CROWDSEC_LAPI_URL}
|
||||||
API_KEY=${API_KEY}
|
API_KEY=${API_KEY}
|
||||||
CACHE_EXPIRATION=1
|
CACHE_EXPIRATION=1
|
||||||
|
|
|
@ -32,6 +32,9 @@ function csmod.init(configFile, userAgent)
|
||||||
runtime.cache = ngx.shared.crowdsec_cache
|
runtime.cache = ngx.shared.crowdsec_cache
|
||||||
runtime.fallback = runtime.conf["FALLBACK_REMEDIATION"]
|
runtime.fallback = runtime.conf["FALLBACK_REMEDIATION"]
|
||||||
|
|
||||||
|
if runtime.conf["ENABLED"] == "false" then
|
||||||
|
return "Disabled", nil
|
||||||
|
end
|
||||||
|
|
||||||
if runtime.conf["REDIRECT_LOCATION"] == "/" then
|
if runtime.conf["REDIRECT_LOCATION"] == "/" then
|
||||||
ngx.log(ngx.ERR, "redirect location is set to '/' this will lead into infinite redirection")
|
ngx.log(ngx.ERR, "redirect location is set to '/' this will lead into infinite redirection")
|
||||||
|
@ -382,6 +385,11 @@ end
|
||||||
|
|
||||||
|
|
||||||
function csmod.Allow(ip)
|
function csmod.Allow(ip)
|
||||||
|
|
||||||
|
if runtime.conf["ENABLED"] == "false" then
|
||||||
|
return "Disabled", nil
|
||||||
|
end
|
||||||
|
|
||||||
if utils.table_len(runtime.conf["EXCLUDE_LOCATION"]) > 0 then
|
if utils.table_len(runtime.conf["EXCLUDE_LOCATION"]) > 0 then
|
||||||
for k, v in pairs(runtime.conf["EXCLUDE_LOCATION"]) do
|
for k, v in pairs(runtime.conf["EXCLUDE_LOCATION"]) do
|
||||||
if ngx.var.uri == v then
|
if ngx.var.uri == v then
|
||||||
|
|
|
@ -35,10 +35,11 @@ function config.loadConfig(file)
|
||||||
return nil, "File ".. file .." doesn't exist"
|
return nil, "File ".. file .." doesn't exist"
|
||||||
end
|
end
|
||||||
local conf = {}
|
local conf = {}
|
||||||
local valid_params = {'API_URL', 'API_KEY', 'BOUNCING_ON_TYPE', 'MODE', 'SECRET_KEY', 'SITE_KEY', 'BAN_TEMPLATE_PATH' ,'CAPTCHA_TEMPLATE_PATH', 'REDIRECT_LOCATION', 'RET_CODE', 'EXCLUDE_LOCATION', 'FALLBACK_REMEDIATION'}
|
local valid_params = {'ENABLED','API_URL', 'API_KEY', 'BOUNCING_ON_TYPE', 'MODE', 'SECRET_KEY', 'SITE_KEY', 'BAN_TEMPLATE_PATH' ,'CAPTCHA_TEMPLATE_PATH', 'REDIRECT_LOCATION', 'RET_CODE', 'EXCLUDE_LOCATION', 'FALLBACK_REMEDIATION'}
|
||||||
local valid_int_params = {'CACHE_EXPIRATION', 'CACHE_SIZE', 'REQUEST_TIMEOUT', 'UPDATE_FREQUENCY', 'CAPTCHA_EXPIRATION'}
|
local valid_int_params = {'CACHE_EXPIRATION', 'CACHE_SIZE', 'REQUEST_TIMEOUT', 'UPDATE_FREQUENCY', 'CAPTCHA_EXPIRATION'}
|
||||||
local valid_bouncing_on_type_values = {'ban', 'captcha', 'all'}
|
local valid_bouncing_on_type_values = {'ban', 'captcha', 'all'}
|
||||||
local default_values = {
|
local default_values = {
|
||||||
|
['ENABLED'] = "true",
|
||||||
['REQUEST_TIMEOUT'] = 0.2,
|
['REQUEST_TIMEOUT'] = 0.2,
|
||||||
['BOUNCING_ON_TYPE'] = "ban",
|
['BOUNCING_ON_TYPE'] = "ban",
|
||||||
['MODE'] = "stream",
|
['MODE'] = "stream",
|
||||||
|
|
Loading…
Add table
Reference in a new issue