diff mod_firewall/actions.lib.lua @ 5536:96dec7681af8

mod_firewall: Update user marks to store instantly via map store The original approach was to keep marks in memory only, and persist them at shutdown. That saves I/O, at the cost of potentially losing marks on an unclean shutdown. This change persists marks instantly, which may have some performance overhead but should be more "correct". It also splits the marking/unmarking into an event which may be watched or even fired by other modules.
author Matthew Wild <mwild1@gmail.com>
date Thu, 08 Jun 2023 16:20:42 +0100
parents d0d251abf595
children 4b9a7684ae02
line wrap: on
line diff
--- a/mod_firewall/actions.lib.lua	Thu Jun 08 16:17:25 2023 +0100
+++ b/mod_firewall/actions.lib.lua	Thu Jun 08 16:20:42 2023 +0100
@@ -220,11 +220,22 @@
 end
 
 function action_handlers.MARK_USER(name)
-	return [[if session.firewall_marks then session.firewall_marks.]]..idsafe(name)..[[ = current_timestamp; end]], { "timestamp" };
+	return ([[if session.firewall_marks then
+			fire_event("firewall/marked/user", {
+				username = session.username;
+				mark = %q;
+				timestamp = current_timestamp;
+			});
+		end]]):format(idsafe(name)), { "timestamp" };
 end
 
 function action_handlers.UNMARK_USER(name)
-	return [[if session.firewall_marks then session.firewall_marks.]]..idsafe(name)..[[ = nil; end]], { "timestamp" };
+	return ([[if session.firewall_marks then
+			fire_event("firewall/unmarked/user", {
+				username = session.username;
+				mark = %q;
+			});
+		end]]):format(idsafe(name));
 end
 
 function action_handlers.ADD_TO(spec)