Mercurial > prosody-modules
comparison mod_list_inactive/mod_list_inactive.lua @ 3891:38504ec4c89b
mod_list_inactive: report last action timestamp
| author | Georg Lukas <georg@op-co.de> |
|---|---|
| date | Mon, 17 Feb 2020 16:42:24 +0100 |
| parents | e4c3d335b07f |
| children |
comparison
equal
deleted
inserted
replaced
| 3890:117a979ef930 | 3891:38504ec4c89b |
|---|---|
| 12 y = 31556952, -- year | 12 y = 31556952, -- year |
| 13 } | 13 } |
| 14 | 14 |
| 15 local output_formats = { | 15 local output_formats = { |
| 16 default = "%s", | 16 default = "%s", |
| 17 event = "%s %s", | 17 event = "%s %s %s", |
| 18 delete = "user:delete%q -- %s" | 18 delete = "user:delete%q -- %s -- %s" |
| 19 } | 19 } |
| 20 | 20 |
| 21 function module.command(arg) | 21 function module.command(arg) |
| 22 if #arg < 2 then | 22 if #arg < 2 then |
| 23 print("usage: prosodyctl mod_list_inactive example.net time [format]"); | 23 print("usage: prosodyctl mod_list_inactive example.net time [format]"); |
| 24 print("time is a number followed by 'day', 'week', 'month' or 'year'"); | 24 print("time is a number followed by 'day', 'week', 'month' or 'year'"); |
| 25 print("formats are:"); | 25 print("formats are:"); |
| 26 for name, fmt in pairs(output_formats) do | 26 for name, fmt in pairs(output_formats) do |
| 27 print(name, fmt:format("user@example.com", "last action")) | 27 print(name, fmt:format("user@example.com", "<last action>", "<last action timestamp>")) |
| 28 end | 28 end |
| 29 return; | 29 return; |
| 30 end | 30 end |
| 31 local items = {}; | 31 local items = {}; |
| 32 local host = arg[1]; | 32 local host = arg[1]; |
| 42 for user in um.users(host) do | 42 for user in um.users(host) do |
| 43 local last_active = dm_load(user, host, "lastlog"); | 43 local last_active = dm_load(user, host, "lastlog"); |
| 44 local last_action = last_active and last_active.event or "?" | 44 local last_action = last_active and last_active.event or "?" |
| 45 last_active = last_active and last_active.timestamp or 0; | 45 last_active = last_active and last_active.timestamp or 0; |
| 46 if last_active < max_age then | 46 if last_active < max_age then |
| 47 print(output:format(jid_join(user, host), last_action)); | 47 print(output:format(jid_join(user, host), last_action, os.date('%Y-%m-%d %H:%M:%S', last_active))); |
| 48 end | 48 end |
| 49 end | 49 end |
| 50 end | 50 end |
| 51 | 51 |
