Software /
code /
prosody-modules
Changeset
6196:1447f076c970
mod_lastlog2: Add a shell command
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 08 Feb 2025 14:39:17 +0100 |
parents | 6195:886c985ece61 |
children | 6197:ba8f5cdc1676 |
files | mod_lastlog2/README.md mod_lastlog2/mod_lastlog2.lua |
diffstat | 2 files changed, 29 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 "<unknown>")); + 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 <user@host>]], [[Show when user last logged in or out]]);