# HG changeset patch # User Kim Alvefur # Date 1739021957 -3600 # Node ID 1447f076c970e14b6d10a522a1911c81010782a7 # Parent 886c985ece61d65a4e1b20931d7cddb0f6ea9fe8 mod_lastlog2: Add a shell command diff -r 886c985ece61 -r 1447f076c970 mod_lastlog2/README.md --- a/mod_lastlog2/README.md Sat Feb 08 14:12:18 2025 +0100 +++ b/mod_lastlog2/README.md Sat Feb 08 14:39:17 2025 +0100 @@ -36,6 +36,10 @@ prosodyctl mod_lastlog2 username@example.com +With Prosody trunk the command can be used via the shell: + + prosodyctl shell lastlog show username@example.com + # Compatibility Version State diff -r 886c985ece61 -r 1447f076c970 mod_lastlog2/mod_lastlog2.lua --- a/mod_lastlog2/mod_lastlog2.lua Sat Feb 08 14:12:18 2025 +0100 +++ b/mod_lastlog2/mod_lastlog2.lua Sat Feb 08 14:39:17 2025 +0100 @@ -67,6 +67,31 @@ end end +module:add_item("shell-command", { + section = "lastlog"; + section_desc = "View and manage user activity data"; + name = "show"; + desc = "View recorded user activity for user"; + args = { { name = "jid"; type = "string" } }; + host_selector = "jid"; + handler = function(self, userjid) + local kv_store = module:open_store(); + local username = jid.prepped_split(userjid); + local lastlog, err = kv_store:get(username); + if err then return false, err; end + if not lastlog then return true, "No record found"; end + local print = self.session.print; + for event, data in pairs(lastlog) do + print(("Last %s: %s"):format(event, + data.timestamp and os.date("%Y-%m-%d %H:%M:%S", data.timestamp) or "")); + if data.ip then + print("IP address: "..data.ip); + end + end + return true, "Record shown" + end; +}); + function module.command(arg) if not arg[1] or arg[1] == "--help" then require"util.prosodyctl".show_usage([[mod_lastlog2 ]], [[Show when user last logged in or out]]);