Software /
code /
prosody
Comparison
plugins/mod_admin_telnet.lua @ 7068:0c494bca43cb
mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 09 Jan 2016 23:58:43 +0100 |
parent | 7067:4c0ec9bd5168 |
child | 7069:eae5d2f1311d |
comparison
equal
deleted
inserted
replaced
7067:4c0ec9bd5168 | 7068:0c494bca43cb |
---|---|
20 | 20 |
21 local console_listener = { default_port = 5582; default_mode = "*a"; interface = "127.0.0.1" }; | 21 local console_listener = { default_port = 5582; default_mode = "*a"; interface = "127.0.0.1" }; |
22 | 22 |
23 local iterators = require "util.iterators"; | 23 local iterators = require "util.iterators"; |
24 local keys, values = iterators.keys, iterators.values; | 24 local keys, values = iterators.keys, iterators.values; |
25 local jid_bare, jid_split = import("util.jid", "bare", "prepped_split"); | 25 local jid_bare, jid_split, jid_join = import("util.jid", "bare", "prepped_split", "join"); |
26 local set, array = require "util.set", require "util.array"; | 26 local set, array = require "util.set", require "util.array"; |
27 local cert_verify_identity = require "util.x509".verify_identity; | 27 local cert_verify_identity = require "util.x509".verify_identity; |
28 local envload = require "util.envload".envload; | 28 local envload = require "util.envload".envload; |
29 local envloadfile = require "util.envload".envloadfile; | 29 local envloadfile = require "util.envload".envloadfile; |
30 local has_pposix, pposix = pcall(require, "util.pposix"); | 30 local has_pposix, pposix = pcall(require, "util.pposix"); |
537 return table.concat(line, " "); | 537 return table.concat(line, " "); |
538 end | 538 end |
539 | 539 |
540 def_env.c2s = {}; | 540 def_env.c2s = {}; |
541 | 541 |
542 local function get_jid(session) | |
543 if session.username then | |
544 return session.full_jid or jid_join(session.username, session.host, session.resource); | |
545 end | |
546 return "(unknown)"; | |
547 end | |
548 | |
542 local function show_c2s(callback) | 549 local function show_c2s(callback) |
543 for hostname, host in pairs(hosts) do | 550 local c2s = array.collect(values(module:shared"/*/c2s/sessions")); |
544 for username, user in pairs(host.sessions or {}) do | 551 c2s:sort(function(a, b) |
545 for resource, session in pairs(user.sessions or {}) do | 552 if a.host == b.host then |
546 local jid = username.."@"..hostname.."/"..resource; | 553 if a.username == b.username then |
547 callback(jid, session); | 554 return a.resource or "" > b.resource or ""; |
548 end | 555 end |
549 end | 556 return a.username or "" > b.username or ""; |
550 end | 557 end |
558 return a.host or "" > b.host or ""; | |
559 end):map(function (session) | |
560 callback(get_jid(session), session) | |
561 end); | |
551 end | 562 end |
552 | 563 |
553 function def_env.c2s:count(match_jid) | 564 function def_env.c2s:count(match_jid) |
554 local count = 0; | 565 local count = 0; |
555 show_c2s(function (jid, session) | 566 show_c2s(function (jid, session) |
561 end | 572 end |
562 | 573 |
563 function def_env.c2s:show(match_jid, annotate) | 574 function def_env.c2s:show(match_jid, annotate) |
564 local print, count = self.session.print, 0; | 575 local print, count = self.session.print, 0; |
565 annotate = annotate or session_flags; | 576 annotate = annotate or session_flags; |
566 local curr_host; | 577 local curr_host = false; |
567 show_c2s(function (jid, session) | 578 show_c2s(function (jid, session) |
568 if curr_host ~= session.host then | 579 if curr_host ~= session.host then |
569 curr_host = session.host; | 580 curr_host = session.host; |
570 print(curr_host); | 581 print(curr_host or "(not connected to any host yet)"); |
571 end | 582 end |
572 if (not match_jid) or jid:match(match_jid) then | 583 if (not match_jid) or jid:match(match_jid) then |
573 count = count + 1; | 584 count = count + 1; |
574 print(annotate(session, { " ", jid })); | 585 print(annotate(session, { " ", jid })); |
575 end | 586 end |