Software /
code /
prosody-modules
Diff
mod_client_management/mod_client_management.lua @ 5856:75dee6127829 draft
Merge upstream
author | Trần H. Trung <xmpp:trần.h.trung@trung.fun> |
---|---|
date | Tue, 06 Feb 2024 18:32:01 +0700 |
parent | 5779:e199f33f7a2e |
child | 5902:13094c707414 |
line wrap: on
line diff
--- a/mod_client_management/mod_client_management.lua Tue Aug 29 23:51:17 2023 +0700 +++ b/mod_client_management/mod_client_management.lua Tue Feb 06 18:32:01 2024 +0700 @@ -79,7 +79,7 @@ client_store:set_key(username, client_id, client_state); if is_new_client then - module:fire_event("client_management/new-client", { client = client_state }); + module:fire_event("client_management/new-client", { client = client_state; session = session }); end end end); @@ -133,7 +133,7 @@ client_store:set_key(session.username, client_state.id, client_state); if is_new_client then - module:fire_event("client_management/new-client", { client = client_state }); + module:fire_event("client_management/new-client", { client = client_state; session = session }); end end); @@ -185,6 +185,9 @@ end local function is_client_active(client) + if not client.full_jid then + return nil; + end local username, host = jid.split(client.full_jid); local account_info = usermanager.get_account_info(username, host); local last_password_change = account_info and account_info.password_updated; @@ -252,6 +255,7 @@ type = "access"; first_seen = grant.created; last_seen = grant.accessed; + expires = grant.expires; active = { grant = grant; }; @@ -421,7 +425,7 @@ -- Command -module:once(function () +module:on_ready(function () local console_env = module:shared("/*/admin_shell/env"); if not console_env.user then return; end -- admin_shell probably not loaded @@ -438,9 +442,11 @@ end local function date_or_time(last_seen) - return last_seen and os.date(os.difftime(os.time(), last_seen) >= 86400 and "%Y-%m-%d" or "%H:%M:%S", last_seen); + return last_seen and os.date(math.abs(os.difftime(os.time(), last_seen)) >= 86400 and "%Y-%m-%d" or "%H:%M:%S", last_seen); end + local date_or_time_width = math.max(#os.date("%Y-%m-%d"), #os.date("%H:%M:%S")); + local colspec = { { title = "ID"; key = "id"; width = "1p" }; { @@ -452,18 +458,39 @@ { title = "First seen"; key = "first_seen"; - width = math.max(#os.date("%Y-%m-%d"), #os.date("%H:%M:%S")); + width = date_or_time_width; align = "right"; mapper = date_or_time; }; { title = "Last seen"; key = "last_seen"; - width = math.max(#os.date("%Y-%m-%d"), #os.date("%H:%M:%S")); + width = date_or_time_width; align = "right"; mapper = date_or_time; }; { + title = "Expires"; + key = "active"; + width = date_or_time_width; + align = "right"; + mapper = function(active, client) + local grant = active and active.grant; + local expires = client and client.expires; + local tokens = grant and grant.tokens; + if expires or not tokens then + return date_or_time(expires); + end + + for _, token in pairs(tokens) do + if token.expires and (not expires or token.expires > expires) then + expires = token.expires; + end + end + return date_or_time(expires); + end; + }; + { title = "Authentication"; key = "active"; width = "2p";