diff options
author | Kim Alvefur <zash@zash.se> | 2016-01-09 23:58:43 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2016-01-09 23:58:43 +0100 |
commit | 4ad60283f8f36dcf5ec29c7bd97cd089df46a5d6 (patch) | |
tree | 7b2a938c1c856f816b6c2d8891094bfe651a5750 | |
parent | 6876deedcd6fb44398ae198f1dc2d8c456fc275c (diff) | |
download | prosody-4ad60283f8f36dcf5ec29c7bd97cd089df46a5d6.tar.gz prosody-4ad60283f8f36dcf5ec29c7bd97cd089df46a5d6.zip |
mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
-rw-r--r-- | plugins/mod_admin_telnet.lua | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index e4dcf080..c3434d33 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -22,7 +22,7 @@ local console_listener = { default_port = 5582; default_mode = "*a"; interface = local iterators = require "util.iterators"; local keys, values = iterators.keys, iterators.values; -local jid_bare, jid_split = import("util.jid", "bare", "prepped_split"); +local jid_bare, jid_split, jid_join = import("util.jid", "bare", "prepped_split", "join"); local set, array = require "util.set", require "util.array"; local cert_verify_identity = require "util.x509".verify_identity; local envload = require "util.envload".envload; @@ -539,15 +539,26 @@ end def_env.c2s = {}; +local function get_jid(session) + if session.username then + return session.full_jid or jid_join(session.username, session.host, session.resource); + end + return "(unknown)"; +end + local function show_c2s(callback) - for hostname, host in pairs(hosts) do - for username, user in pairs(host.sessions or {}) do - for resource, session in pairs(user.sessions or {}) do - local jid = username.."@"..hostname.."/"..resource; - callback(jid, session); + local c2s = array.collect(values(module:shared"/*/c2s/sessions")); + c2s:sort(function(a, b) + if a.host == b.host then + if a.username == b.username then + return a.resource or "" > b.resource or ""; end + return a.username or "" > b.username or ""; end - end + return a.host or "" > b.host or ""; + end):map(function (session) + callback(get_jid(session), session) + end); end function def_env.c2s:count(match_jid) @@ -563,11 +574,11 @@ end function def_env.c2s:show(match_jid, annotate) local print, count = self.session.print, 0; annotate = annotate or session_flags; - local curr_host; + local curr_host = false; show_c2s(function (jid, session) if curr_host ~= session.host then curr_host = session.host; - print(curr_host); + print(curr_host or "(not connected to any host yet)"); end if (not match_jid) or jid:match(match_jid) then count = count + 1; |