From aadf53ee717ef5caf2099508d1a622fcaaf81d69 Mon Sep 17 00:00:00 2001 From: he2ss Date: Tue, 8 Feb 2022 16:42:27 +0100 Subject: [PATCH 1/5] improve configuration mgmt code --- lib/plugins/crowdsec/utils.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/plugins/crowdsec/utils.lua b/lib/plugins/crowdsec/utils.lua index 0c0248c..aa7ec9c 100644 --- a/lib/plugins/crowdsec/utils.lua +++ b/lib/plugins/crowdsec/utils.lua @@ -25,6 +25,9 @@ function M.read_file(path) end function M.file_exist(path) + if path ~= nil then + return false + end local f = io.open(path, "r") if f ~= nil then io.close(f) From c1ec091034a848adf805f9287671e17a28cfd3be Mon Sep 17 00:00:00 2001 From: he2ss Date: Tue, 8 Feb 2022 16:49:41 +0100 Subject: [PATCH 2/5] fix typo --- lib/plugins/crowdsec/utils.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/crowdsec/utils.lua b/lib/plugins/crowdsec/utils.lua index aa7ec9c..9d73237 100644 --- a/lib/plugins/crowdsec/utils.lua +++ b/lib/plugins/crowdsec/utils.lua @@ -25,8 +25,8 @@ function M.read_file(path) end function M.file_exist(path) - if path ~= nil then - return false + if path == nil then + return nil end local f = io.open(path, "r") if f ~= nil then From 7a6e1912f7d9974e1b6f89d73432245920a68046 Mon Sep 17 00:00:00 2001 From: he2ss Date: Tue, 8 Feb 2022 17:44:41 +0100 Subject: [PATCH 3/5] improve code --- lib/plugins/crowdsec/ban.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/plugins/crowdsec/ban.lua b/lib/plugins/crowdsec/ban.lua index ff900cd..e52c279 100644 --- a/lib/plugins/crowdsec/ban.lua +++ b/lib/plugins/crowdsec/ban.lua @@ -9,6 +9,9 @@ M.ret_code = ngx.HTTP_FORBIDDEN function M.new(template_path, redirect_location, ret_code) + if template_path == nil then + return "ban template file variable is empty, will ban without template" + end if utils.file_exist(template_path) == false then return "ban template file doesn't exist, will ban without template" else From 6f689d54ec2962089ce61be9cb6fe546909740d9 Mon Sep 17 00:00:00 2001 From: he2ss Date: Tue, 8 Feb 2022 17:48:03 +0100 Subject: [PATCH 4/5] fix error message --- lib/plugins/crowdsec/ban.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/crowdsec/ban.lua b/lib/plugins/crowdsec/ban.lua index e52c279..108d855 100644 --- a/lib/plugins/crowdsec/ban.lua +++ b/lib/plugins/crowdsec/ban.lua @@ -10,7 +10,7 @@ M.ret_code = ngx.HTTP_FORBIDDEN function M.new(template_path, redirect_location, ret_code) if template_path == nil then - return "ban template file variable is empty, will ban without template" + return "BAN_TEMPLATE_PATH variable is empty, will ban without template" end if utils.file_exist(template_path) == false then return "ban template file doesn't exist, will ban without template" From 4313d97ba691183b06f4412d39add648ca79cf5e Mon Sep 17 00:00:00 2001 From: he2ss Date: Tue, 8 Feb 2022 17:50:28 +0100 Subject: [PATCH 5/5] improve captcha template path verif --- lib/plugins/crowdsec/recaptcha.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/plugins/crowdsec/recaptcha.lua b/lib/plugins/crowdsec/recaptcha.lua index 362d9b0..dd94ccf 100644 --- a/lib/plugins/crowdsec/recaptcha.lua +++ b/lib/plugins/crowdsec/recaptcha.lua @@ -45,6 +45,9 @@ function M.New(siteKey, secretKey, TemplateFilePath) M.SecretKey = secretKey + if TemplateFilePath == nil then + return "CAPTCHA_TEMPLATE_PATH variable is empty, will ban without template" + end if utils.file_exist(TemplateFilePath) == false then return "captcha template file doesn't exist, can't use recaptcha" end