Mercurial > prosody-modules
comparison mod_lastlog2/mod_lastlog2.lua @ 6168:1447f076c970
mod_lastlog2: Add a shell command
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 08 Feb 2025 14:39:17 +0100 |
| parents | 886c985ece61 |
| children |
comparison
equal
deleted
inserted
replaced
| 6167:886c985ece61 | 6168:1447f076c970 |
|---|---|
| 65 return latest; | 65 return latest; |
| 66 end | 66 end |
| 67 end | 67 end |
| 68 end | 68 end |
| 69 | 69 |
| 70 module:add_item("shell-command", { | |
| 71 section = "lastlog"; | |
| 72 section_desc = "View and manage user activity data"; | |
| 73 name = "show"; | |
| 74 desc = "View recorded user activity for user"; | |
| 75 args = { { name = "jid"; type = "string" } }; | |
| 76 host_selector = "jid"; | |
| 77 handler = function(self, userjid) | |
| 78 local kv_store = module:open_store(); | |
| 79 local username = jid.prepped_split(userjid); | |
| 80 local lastlog, err = kv_store:get(username); | |
| 81 if err then return false, err; end | |
| 82 if not lastlog then return true, "No record found"; end | |
| 83 local print = self.session.print; | |
| 84 for event, data in pairs(lastlog) do | |
| 85 print(("Last %s: %s"):format(event, | |
| 86 data.timestamp and os.date("%Y-%m-%d %H:%M:%S", data.timestamp) or "<unknown>")); | |
| 87 if data.ip then | |
| 88 print("IP address: "..data.ip); | |
| 89 end | |
| 90 end | |
| 91 return true, "Record shown" | |
| 92 end; | |
| 93 }); | |
| 94 | |
| 70 function module.command(arg) | 95 function module.command(arg) |
| 71 if not arg[1] or arg[1] == "--help" then | 96 if not arg[1] or arg[1] == "--help" then |
| 72 require"util.prosodyctl".show_usage([[mod_lastlog2 <user@host>]], [[Show when user last logged in or out]]); | 97 require"util.prosodyctl".show_usage([[mod_lastlog2 <user@host>]], [[Show when user last logged in or out]]); |
| 73 return 1; | 98 return 1; |
| 74 end | 99 end |
