Software / code / prosody-modules
Comparison
mod_audit_auth/mod_audit_auth.lua @ 5856:75dee6127829
Merge upstream
| author | Trần H. Trung <xmpp:trần.h.trung@trung.fun> |
|---|---|
| date | Tue, 06 Feb 2024 18:32:01 +0700 |
| parent | 5803:f199bff16f1f |
| child | 5930:cc30c4b5f006 |
comparison
equal
deleted
inserted
replaced
| 5664:52db2da66680 | 5856:75dee6127829 |
|---|---|
| 1 local jid = require"util.jid"; | |
| 2 local st = require "util.stanza"; | |
| 3 | |
| 1 module:depends("audit"); | 4 module:depends("audit"); |
| 2 -- luacheck: read globals module.audit | 5 -- luacheck: read globals module.audit |
| 3 | 6 |
| 7 local only_passwords = module:get_option_boolean("audit_auth_passwords_only", true); | |
| 8 | |
| 4 module:hook("authentication-failure", function(event) | 9 module:hook("authentication-failure", function(event) |
| 5 local session = event.session; | 10 local session = event.session; |
| 6 module:audit(session.sasl_handler.username, "authentication-failure", { | 11 module:audit(jid.join(session.sasl_handler.username, module.host), "authentication-failure", { |
| 7 session = session, | 12 session = session, |
| 8 }); | 13 }); |
| 9 end) | 14 end) |
| 10 | 15 |
| 11 module:hook("authentication-success", function(event) | 16 module:hook("authentication-success", function(event) |
| 12 local session = event.session; | 17 local session = event.session; |
| 13 module:audit(session.sasl_handler.username, "authentication-success", { | 18 if only_passwords and session.sasl_handler.fast then |
| 19 return; | |
| 20 end | |
| 21 module:audit(jid.join(session.sasl_handler.username, module.host), "authentication-success", { | |
| 14 session = session, | 22 session = session, |
| 15 }); | 23 }); |
| 16 end) | 24 end) |
| 25 | |
| 26 module:hook("client_management/new-client", function (event) | |
| 27 local session, client = event.session, event.client; | |
| 28 | |
| 29 local client_info = st.stanza("client", { id = client.id }); | |
| 30 | |
| 31 if client.user_agent then | |
| 32 local user_agent = st.stanza("user-agent", { xmlns = "urn:xmpp:sasl:2" }) | |
| 33 if client.user_agent.software then | |
| 34 user_agent:text_tag("software", client.user_agent.software, { id = client.user_agent.software_id; version = client.user_agent.software_version }); | |
| 35 end | |
| 36 if client.user_agent.device then | |
| 37 user_agent:text_tag("device", client.user_agent.device); | |
| 38 end | |
| 39 if client.user_agent.uri then | |
| 40 user_agent:text_tag("uri", client.user_agent.uri); | |
| 41 end | |
| 42 client_info:add_child(user_agent); | |
| 43 end | |
| 44 | |
| 45 if client.legacy then | |
| 46 client_info:text_tag("legacy"); | |
| 47 end | |
| 48 | |
| 49 module:audit(jid.join(session.username, module.host), "new-client", { | |
| 50 session = session; | |
| 51 custom = { | |
| 52 }; | |
| 53 }); | |
| 54 end); |