diff --git a/config_example.conf b/config_example.conf index ae1cb5c..ce758b8 100644 --- a/config_example.conf +++ b/config_example.conf @@ -1,3 +1,4 @@ +ENABLED=true API_URL=${CROWDSEC_LAPI_URL} API_KEY=${API_KEY} CACHE_EXPIRATION=1 diff --git a/lib/crowdsec.lua b/lib/crowdsec.lua index 0b47fad..c788543 100644 --- a/lib/crowdsec.lua +++ b/lib/crowdsec.lua @@ -32,6 +32,9 @@ function csmod.init(configFile, userAgent) runtime.cache = ngx.shared.crowdsec_cache runtime.fallback = runtime.conf["FALLBACK_REMEDIATION"] + if runtime.conf["ENABLED"] == "false" then + return "Disabled", nil + end if runtime.conf["REDIRECT_LOCATION"] == "/" then ngx.log(ngx.ERR, "redirect location is set to '/' this will lead into infinite redirection") @@ -382,6 +385,11 @@ end function csmod.Allow(ip) + + if runtime.conf["ENABLED"] == "false" then + return "Disabled", nil + end + if utils.table_len(runtime.conf["EXCLUDE_LOCATION"]) > 0 then for k, v in pairs(runtime.conf["EXCLUDE_LOCATION"]) do if ngx.var.uri == v then diff --git a/lib/plugins/crowdsec/config.lua b/lib/plugins/crowdsec/config.lua index 0837f7c..e3b458c 100644 --- a/lib/plugins/crowdsec/config.lua +++ b/lib/plugins/crowdsec/config.lua @@ -35,10 +35,11 @@ function config.loadConfig(file) return nil, "File ".. file .." doesn't exist" end 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_bouncing_on_type_values = {'ban', 'captcha', 'all'} local default_values = { + ['ENABLED'] = "true", ['REQUEST_TIMEOUT'] = 0.2, ['BOUNCING_ON_TYPE'] = "ban", ['MODE'] = "stream",