Mercurial > prosody-modules
comparison 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 |
comparison
equal
deleted
inserted
replaced
5535:eeccec0955a1 | 5536:96dec7681af8 |
---|---|
218 function action_handlers.UNMARK_ORIGIN(name) | 218 function action_handlers.UNMARK_ORIGIN(name) |
219 return [[session.firewall_marked_]]..idsafe(name)..[[ = nil;]] | 219 return [[session.firewall_marked_]]..idsafe(name)..[[ = nil;]] |
220 end | 220 end |
221 | 221 |
222 function action_handlers.MARK_USER(name) | 222 function action_handlers.MARK_USER(name) |
223 return [[if session.firewall_marks then session.firewall_marks.]]..idsafe(name)..[[ = current_timestamp; end]], { "timestamp" }; | 223 return ([[if session.firewall_marks then |
224 fire_event("firewall/marked/user", { | |
225 username = session.username; | |
226 mark = %q; | |
227 timestamp = current_timestamp; | |
228 }); | |
229 end]]):format(idsafe(name)), { "timestamp" }; | |
224 end | 230 end |
225 | 231 |
226 function action_handlers.UNMARK_USER(name) | 232 function action_handlers.UNMARK_USER(name) |
227 return [[if session.firewall_marks then session.firewall_marks.]]..idsafe(name)..[[ = nil; end]], { "timestamp" }; | 233 return ([[if session.firewall_marks then |
234 fire_event("firewall/unmarked/user", { | |
235 username = session.username; | |
236 mark = %q; | |
237 }); | |
238 end]]):format(idsafe(name)); | |
228 end | 239 end |
229 | 240 |
230 function action_handlers.ADD_TO(spec) | 241 function action_handlers.ADD_TO(spec) |
231 local list_name, value = spec:match("(%S+) (.+)"); | 242 local list_name, value = spec:match("(%S+) (.+)"); |
232 local meta_deps = {}; | 243 local meta_deps = {}; |