-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add blocklist feature integration
Implemented a new blocklist feature that triggers actions based on client IP checks against a specified blocklist. Updated the Dockerfile to use a new user group "blocklist" for security purposes, and modified the Telegram plugin to handle blocklist notifications. Signed-off-by: Christian Roessner <[email protected]>
- Loading branch information
Christian Roessner
committed
Sep 10, 2024
1 parent
907a4a9
commit d5151ec
Showing
3 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
local nauthilus_util = require("nauthilus_util") | ||
|
||
dynamic_loader("nauthilus_context") | ||
local nauthilus_context = require("nauthilus_context") | ||
|
||
dynamic_loader("nauthilus_gll_http") | ||
local http = require("http") | ||
|
||
dynamic_loader("nauthilus_gll_json") | ||
local json = require("json") | ||
|
||
local client = http.client({ | ||
timeout = 30, | ||
user_agent = "Nauthilus" | ||
}) | ||
|
||
local N = "feature_blocklist" | ||
|
||
function nauthilus_call_feature(request) | ||
if not request.client_ip then | ||
nauthilus_builtin.custom_log_add(N, "no client IP found") | ||
|
||
return nauthilus_builtin.FEATURE_TRIGGER_NO, nauthilus_builtin.FEATURES_ABORT_NO, nauthilus_builtin.FEATURE_RESULT_FAILURE | ||
end | ||
|
||
-- Get result table | ||
local rt = nauthilus_context.context_get("rt") | ||
if rt == nil then | ||
rt = {} | ||
end | ||
|
||
local t = {} | ||
|
||
t.ip = request.client_ip | ||
|
||
local payload, json_encode_err = json.encode(t) | ||
nauthilus_util.if_error_raise(json_encode_err) | ||
|
||
local blocklist_request = http.request("POST", os.getenv("BLOCKLIST_URL"), payload) | ||
blocklist_request:header_set("Content-Type", "application/json") | ||
|
||
local result, request_err = client:do_request(blocklist_request) | ||
nauthilus_util.if_error_raise(request_err) | ||
|
||
if result.code ~= 200 then | ||
nauthilus_util.if_error_raise(N .. "_status_code=" .. tostring(result.code)) | ||
end | ||
|
||
local response, err_jdec = json.decode(result.body) | ||
nauthilus_util.if_error_raise(err_jdec) | ||
|
||
if response.error then | ||
return nauthilus_builtin.FEATURE_TRIGGER_NO, nauthilus_builtin.FEATURES_ABORT_NO, nauthilus_builtin.FEATURE_RESULT_FAILURE | ||
end | ||
|
||
if response.found then | ||
if nauthilus_util.is_table(rt) then | ||
rt.feature_blocklist = true | ||
|
||
nauthilus_context.context_set("rt", rt) | ||
end | ||
|
||
nauthilus_builtin.custom_log_add(N .. "_ip", request.client_ip) | ||
nauthilus_builtin.status_message_set("IP address blocked") | ||
|
||
return nauthilus_builtin.FEATURE_TRIGGER_YES, nauthilus_builtin.FEATURES_ABORT_YES, nauthilus_builtin.FEATURE_RESULT_OK | ||
end | ||
|
||
return nauthilus_builtin.FEATURE_TRIGGER_NO, nauthilus_builtin.FEATURES_ABORT_NO, nauthilus_builtin.FEATURE_RESULT_OK | ||
end |