comparison mod_audit_register/mod_audit_register.lua @ 5744:b4607c5dfcac

mod_audit_register: Support for deregister and enable/disable events
author Matthew Wild <mwild1@gmail.com>
date Thu, 30 Nov 2023 17:51:27 +0000
parents dde83f6043e6
children
comparison
equal deleted inserted replaced
5743:9944c6c3e914 5744:b4607c5dfcac
1 module:depends("audit"); 1 module:depends("audit");
2 -- luacheck: read globals module.audit 2 -- luacheck: read globals module.audit
3 3
4 local dt = require "util.datetime";
4 local jid = require "util.jid"; 5 local jid = require "util.jid";
5 local st = require "util.stanza"; 6 local st = require "util.stanza";
6 7
7 module:hook("user-registered", function(event) 8 local function audit_basic_event(name, custom_handler)
8 local session = event.session; 9 module:hook(name, function (event)
9 local custom = {}; 10 local custom;
11 if custom_handler then
12 custom = custom_handler(event);
13 end
14 module:audit(jid.join(event.username, module.host), name, {
15 session = event.session;
16 custom = custom;
17 });
18 end);
19 end
20
21 audit_basic_event("user-registered", function (event)
10 local invite = event.validated_invite or (event.session and event.session.validated_invite); 22 local invite = event.validated_invite or (event.session and event.session.validated_invite);
11 if invite then 23 if not invite then return; end
12 table.insert(custom, st.stanza( 24 return {
25 st.stanza(
13 "invite-used", 26 "invite-used",
14 { 27 {
15 xmlns = "xmpp:prosody.im/audit", 28 xmlns = "xmpp:prosody.im/audit",
16 token = invite.token, 29 token = invite.token,
17 } 30 }
18 )) 31 );
32 };
33 end);
34
35 audit_basic_event("user-deregistered-pending");
36 audit_basic_event("user-deregistered");
37
38 audit_basic_event("user-enabled");
39 audit_basic_event("user-disabled", function (event)
40 local meta = event.meta;
41 if not meta then return end
42
43 local meta_st = st.stanza("disabled", {
44 xmlns = "xmpp:prosody.im/audit";
45 reason = meta.reason;
46 when = meta.when and dt.datetime(meta.when) or nil;
47 });
48 if meta.comment then
49 meta_st:text_tag("comment", meta.comment);
19 end 50 end
20 module:audit(jid.join(event.username, module.host), "user-registered", { 51
21 session = session, 52 return { meta_st };
22 custom = custom,
23 });
24 end); 53 end);