Software /
code /
prosody
Comparison
plugins/mod_admin_telnet.lua @ 7074:3ff83773ffc0
Merge 0.10->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 10 Jan 2016 03:57:17 +0100 |
parent | 7036:f26debcae34e |
parent | 7070:aab022cb8e29 |
child | 7091:1c3b38f80571 |
comparison
equal
deleted
inserted
replaced
7063:bc1b375f379e | 7074:3ff83773ffc0 |
---|---|
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"); |
574 return table.concat(line, " "); | 574 return table.concat(line, " "); |
575 end | 575 end |
576 | 576 |
577 def_env.c2s = {}; | 577 def_env.c2s = {}; |
578 | 578 |
579 local function get_jid(session) | |
580 if session.username then | |
581 return session.full_jid or jid_join(session.username, session.host, session.resource); | |
582 end | |
583 | |
584 local conn = session.conn; | |
585 local ip = session.ip or "?"; | |
586 local clientport = conn and conn:clientport() or "?"; | |
587 local serverip = conn and conn.server and conn:server():ip() or "?"; | |
588 local serverport = conn and conn:serverport() or "?" | |
589 return jid_join("["..ip.."]:"..clientport, session.host or "["..serverip.."]:"..serverport); | |
590 end | |
591 | |
579 local function show_c2s(callback) | 592 local function show_c2s(callback) |
580 for hostname, host in pairs(hosts) do | 593 local c2s = array.collect(values(module:shared"/*/c2s/sessions")); |
581 for username, user in pairs(host.sessions or {}) do | 594 c2s:sort(function(a, b) |
582 for resource, session in pairs(user.sessions or {}) do | 595 if a.host == b.host then |
583 local jid = username.."@"..hostname.."/"..resource; | 596 if a.username == b.username then |
584 callback(jid, session); | 597 return a.resource or "" > b.resource or ""; |
585 end | 598 end |
586 end | 599 return a.username or "" > b.username or ""; |
587 end | 600 end |
601 return a.host or "" > b.host or ""; | |
602 end):map(function (session) | |
603 callback(get_jid(session), session) | |
604 end); | |
588 end | 605 end |
589 | 606 |
590 function def_env.c2s:count(match_jid) | 607 function def_env.c2s:count(match_jid) |
591 local count = 0; | 608 return true, "Total: ".. iterators.count(values(module:shared"/*/c2s/sessions")) .." clients"; |
592 show_c2s(function (jid, session) | |
593 if (not match_jid) or jid:match(match_jid) then | |
594 count = count + 1; | |
595 end | |
596 end); | |
597 return true, "Total: "..count.." clients"; | |
598 end | 609 end |
599 | 610 |
600 function def_env.c2s:show(match_jid, annotate) | 611 function def_env.c2s:show(match_jid, annotate) |
601 local print, count = self.session.print, 0; | 612 local print, count = self.session.print, 0; |
602 annotate = annotate or session_flags; | 613 annotate = annotate or session_flags; |
603 local curr_host; | 614 local curr_host = false; |
604 show_c2s(function (jid, session) | 615 show_c2s(function (jid, session) |
605 if curr_host ~= session.host then | 616 if curr_host ~= session.host then |
606 curr_host = session.host; | 617 curr_host = session.host; |
607 print(curr_host); | 618 print(curr_host or "(not connected to any host yet)"); |
608 end | 619 end |
609 if (not match_jid) or jid:match(match_jid) then | 620 if (not match_jid) or jid:match(match_jid) then |
610 count = count + 1; | 621 count = count + 1; |
611 print(annotate(session, { " ", jid })); | 622 print(annotate(session, { " ", jid })); |
612 end | 623 end |
1160 end | 1171 end |
1161 | 1172 |
1162 ------------- | 1173 ------------- |
1163 | 1174 |
1164 function printbanner(session) | 1175 function printbanner(session) |
1165 local option = module:get_option("console_banner"); | 1176 local option = module:get_option_string("console_banner", "full"); |
1166 if option == nil or option == "full" or option == "graphic" then | 1177 if option == "full" or option == "graphic" then |
1167 session.print [[ | 1178 session.print [[ |
1168 ____ \ / _ | 1179 ____ \ / _ |
1169 | _ \ _ __ ___ ___ _-_ __| |_ _ | 1180 | _ \ _ __ ___ ___ _-_ __| |_ _ |
1170 | |_) | '__/ _ \/ __|/ _ \ / _` | | | | | 1181 | |_) | '__/ _ \/ __|/ _ \ / _` | | | | |
1171 | __/| | | (_) \__ \ |_| | (_| | |_| | | 1182 | __/| | | (_) \__ \ |_| | (_| | |_| | |
1172 |_| |_| \___/|___/\___/ \__,_|\__, | | 1183 |_| |_| \___/|___/\___/ \__,_|\__, | |
1173 A study in simplicity |___/ | 1184 A study in simplicity |___/ |
1174 | 1185 |
1175 ]] | 1186 ]] |
1176 end | 1187 end |
1177 if option == nil or option == "short" or option == "full" then | 1188 if option == "short" or option == "full" then |
1178 session.print("Welcome to the Prosody administration console. For a list of commands, type: help"); | 1189 session.print("Welcome to the Prosody administration console. For a list of commands, type: help"); |
1179 session.print("You may find more help on using this console in our online documentation at "); | 1190 session.print("You may find more help on using this console in our online documentation at "); |
1180 session.print("http://prosody.im/doc/console\n"); | 1191 session.print("http://prosody.im/doc/console\n"); |
1181 end | 1192 end |
1182 if option and option ~= "short" and option ~= "full" and option ~= "graphic" then | 1193 if option ~= "short" and option ~= "full" and option ~= "graphic" then |
1183 if type(option) == "string" then | 1194 session.print(option); |
1184 session.print(option) | |
1185 elseif type(option) == "function" then | |
1186 module:log("warn", "Using functions as value for the console_banner option is no longer supported"); | |
1187 end | |
1188 end | 1195 end |
1189 end | 1196 end |
1190 | 1197 |
1191 module:provides("net", { | 1198 module:provides("net", { |
1192 name = "console"; | 1199 name = "console"; |