mod_s2s: Handle authentication of s2sin and s2sout the same way
[prosody.git] / plugins / mod_admin_telnet.lua
blobc184924c014866c9243826d5b265ae3d94f01d02
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 --
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8 -- luacheck: ignore 212/self
10 module:set_global();
12 local hostmanager = require "core.hostmanager";
13 local modulemanager = require "core.modulemanager";
14 local s2smanager = require "core.s2smanager";
15 local portmanager = require "core.portmanager";
16 local helpers = require "util.helpers";
17 local server = require "net.server";
19 local _G = _G;
21 local prosody = _G.prosody;
23 local console_listener = { default_port = 5582; default_mode = "*a"; interface = "127.0.0.1" };
25 local unpack = table.unpack or unpack; -- luacheck: ignore 113
26 local iterators = require "util.iterators";
27 local keys, values = iterators.keys, iterators.values;
28 local jid_bare, jid_split, jid_join = import("util.jid", "bare", "prepped_split", "join");
29 local set, array = require "util.set", require "util.array";
30 local cert_verify_identity = require "util.x509".verify_identity;
31 local envload = require "util.envload".envload;
32 local envloadfile = require "util.envload".envloadfile;
33 local has_pposix, pposix = pcall(require, "util.pposix");
34 local async = require "util.async";
35 local serialize = require "util.serialization".new({ fatal = false, unquoted = true});
37 local commands = module:shared("commands")
38 local def_env = module:shared("env");
39 local default_env_mt = { __index = def_env };
41 local function redirect_output(target, session)
42 local env = setmetatable({ print = session.print }, { __index = function (_, k) return rawget(target, k); end });
43 env.dofile = function(name)
44 local f, err = envloadfile(name, env);
45 if not f then return f, err; end
46 return f();
47 end;
48 return env;
49 end
51 console = {};
53 local runner_callbacks = {};
55 function runner_callbacks:ready()
56 self.data.conn:resume();
57 end
59 function runner_callbacks:waiting()
60 self.data.conn:pause();
61 end
63 function runner_callbacks:error(err)
64 module:log("error", "Traceback[telnet]: %s", err);
66 self.data.print("Fatal error while running command, it did not complete");
67 self.data.print("Error: "..tostring(err));
68 end
71 function console:new_session(conn)
72 local w = function(s) conn:write(s:gsub("\n", "\r\n")); end;
73 local session = { conn = conn;
74 send = function (t) w(tostring(t)); end;
75 print = function (...)
76 local t = {};
77 for i=1,select("#", ...) do
78 t[i] = tostring(select(i, ...));
79 end
80 w("| "..table.concat(t, "\t").."\n");
81 end;
82 disconnect = function () conn:close(); end;
84 session.env = setmetatable({}, default_env_mt);
86 session.thread = async.runner(function (line)
87 console:process_line(session, line);
88 session.send(string.char(0));
89 end, runner_callbacks, session);
91 -- Load up environment with helper objects
92 for name, t in pairs(def_env) do
93 if type(t) == "table" then
94 session.env[name] = setmetatable({ session = session }, { __index = t });
95 end
96 end
98 return session;
99 end
101 function console:process_line(session, line)
102 local useglobalenv;
104 if line:match("^>") then
105 line = line:gsub("^>", "");
106 useglobalenv = true;
107 elseif line == "\004" then
108 commands["bye"](session, line);
109 return;
110 else
111 local command = line:match("^%w+") or line:match("%p");
112 if commands[command] then
113 commands[command](session, line);
114 return;
118 session.env._ = line;
120 if not useglobalenv and commands[line:lower()] then
121 commands[line:lower()](session, line);
122 return;
125 local chunkname = "=console";
126 local env = (useglobalenv and redirect_output(_G, session)) or session.env or nil
127 local chunk, err = envload("return "..line, chunkname, env);
128 if not chunk then
129 chunk, err = envload(line, chunkname, env);
130 if not chunk then
131 err = err:gsub("^%[string .-%]:%d+: ", "");
132 err = err:gsub("^:%d+: ", "");
133 err = err:gsub("'<eof>'", "the end of the line");
134 session.print("Sorry, I couldn't understand that... "..err);
135 return;
139 local taskok, message = chunk();
141 if not message then
142 session.print("Result: "..tostring(taskok));
143 return;
144 elseif (not taskok) and message then
145 session.print("Command completed with a problem");
146 session.print("Message: "..tostring(message));
147 return;
150 session.print("OK: "..tostring(message));
153 local sessions = {};
155 function console_listener.onconnect(conn)
156 -- Handle new connection
157 local session = console:new_session(conn);
158 sessions[conn] = session;
159 printbanner(session);
160 session.send(string.char(0));
163 function console_listener.onincoming(conn, data)
164 local session = sessions[conn];
166 local partial = session.partial_data;
167 if partial then
168 data = partial..data;
171 for line in data:gmatch("[^\n]*[\n\004]") do
172 if session.closed then return end
173 session.thread:run(line);
175 session.partial_data = data:match("[^\n]+$");
178 function console_listener.onreadtimeout(conn)
179 local session = sessions[conn];
180 if session then
181 session.send("\0");
182 return true;
186 function console_listener.ondisconnect(conn, err) -- luacheck: ignore 212/err
187 local session = sessions[conn];
188 if session then
189 session.disconnect();
190 sessions[conn] = nil;
194 function console_listener.ondetach(conn)
195 sessions[conn] = nil;
198 -- Console commands --
199 -- These are simple commands, not valid standalone in Lua
201 function commands.bye(session)
202 session.print("See you! :)");
203 session.closed = true;
204 session.disconnect();
206 commands.quit, commands.exit = commands.bye, commands.bye;
208 commands["!"] = function (session, data)
209 if data:match("^!!") and session.env._ then
210 session.print("!> "..session.env._);
211 return console_listener.onincoming(session.conn, session.env._);
213 local old, new = data:match("^!(.-[^\\])!(.-)!$");
214 if old and new then
215 local ok, res = pcall(string.gsub, session.env._, old, new);
216 if not ok then
217 session.print(res)
218 return;
220 session.print("!> "..res);
221 return console_listener.onincoming(session.conn, res);
223 session.print("Sorry, not sure what you want");
227 function commands.help(session, data)
228 local print = session.print;
229 local section = data:match("^help (%w+)");
230 if not section then
231 print [[Commands are divided into multiple sections. For help on a particular section, ]]
232 print [[type: help SECTION (for example, 'help c2s'). Sections are: ]]
233 print [[]]
234 print [[c2s - Commands to manage local client-to-server sessions]]
235 print [[s2s - Commands to manage sessions between this server and others]]
236 print [[module - Commands to load/reload/unload modules/plugins]]
237 print [[host - Commands to activate, deactivate and list virtual hosts]]
238 print [[user - Commands to create and delete users, and change their passwords]]
239 print [[server - Uptime, version, shutting down, etc.]]
240 print [[port - Commands to manage ports the server is listening on]]
241 print [[dns - Commands to manage and inspect the internal DNS resolver]]
242 print [[xmpp - Commands for sending XMPP stanzas]]
243 print [[config - Reloading the configuration, etc.]]
244 print [[console - Help regarding the console itself]]
245 elseif section == "c2s" then
246 print [[c2s:show(jid) - Show all client sessions with the specified JID (or all if no JID given)]]
247 print [[c2s:show_insecure() - Show all unencrypted client connections]]
248 print [[c2s:show_secure() - Show all encrypted client connections]]
249 print [[c2s:show_tls() - Show TLS cipher info for encrypted sessions]]
250 print [[c2s:count() - Count sessions without listing them]]
251 print [[c2s:close(jid) - Close all sessions for the specified JID]]
252 print [[c2s:closeall() - Close all active c2s connections ]]
253 elseif section == "s2s" then
254 print [[s2s:show(domain) - Show all s2s connections for the given domain (or all if no domain given)]]
255 print [[s2s:show_tls(domain) - Show TLS cipher info for encrypted sessions]]
256 print [[s2s:close(from, to) - Close a connection from one domain to another]]
257 print [[s2s:closeall(host) - Close all the incoming/outgoing s2s sessions to specified host]]
258 elseif section == "module" then
259 print [[module:load(module, host) - Load the specified module on the specified host (or all hosts if none given)]]
260 print [[module:reload(module, host) - The same, but unloads and loads the module (saving state if the module supports it)]]
261 print [[module:unload(module, host) - The same, but just unloads the module from memory]]
262 print [[module:list(host) - List the modules loaded on the specified host]]
263 elseif section == "host" then
264 print [[host:activate(hostname) - Activates the specified host]]
265 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]]
266 print [[host:list() - List the currently-activated hosts]]
267 elseif section == "user" then
268 print [[user:create(jid, password) - Create the specified user account]]
269 print [[user:password(jid, password) - Set the password for the specified user account]]
270 print [[user:delete(jid) - Permanently remove the specified user account]]
271 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]]
272 elseif section == "server" then
273 print [[server:version() - Show the server's version number]]
274 print [[server:uptime() - Show how long the server has been running]]
275 print [[server:memory() - Show details about the server's memory usage]]
276 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]]
277 elseif section == "port" then
278 print [[port:list() - Lists all network ports prosody currently listens on]]
279 print [[port:close(port, interface) - Close a port]]
280 elseif section == "dns" then
281 print [[dns:lookup(name, type, class) - Do a DNS lookup]]
282 print [[dns:addnameserver(nameserver) - Add a nameserver to the list]]
283 print [[dns:setnameserver(nameserver) - Replace the list of name servers with the supplied one]]
284 print [[dns:purge() - Clear the DNS cache]]
285 print [[dns:cache() - Show cached records]]
286 elseif section == "xmpp" then
287 print [[xmpp:ping(localhost, remotehost) -- Sends a ping to a remote XMPP server and reports the response]]
288 elseif section == "config" then
289 print [[config:reload() - Reload the server configuration. Modules may need to be reloaded for changes to take effect.]]
290 elseif section == "console" then
291 print [[Hey! Welcome to Prosody's admin console.]]
292 print [[First thing, if you're ever wondering how to get out, simply type 'quit'.]]
293 print [[Secondly, note that we don't support the full telnet protocol yet (it's coming)]]
294 print [[so you may have trouble using the arrow keys, etc. depending on your system.]]
295 print [[]]
296 print [[For now we offer a couple of handy shortcuts:]]
297 print [[!! - Repeat the last command]]
298 print [[!old!new! - repeat the last command, but with 'old' replaced by 'new']]
299 print [[]]
300 print [[For those well-versed in Prosody's internals, or taking instruction from those who are,]]
301 print [[you can prefix a command with > to escape the console sandbox, and access everything in]]
302 print [[the running server. Great fun, but be careful not to break anything :)]]
304 print [[]]
307 -- Session environment --
308 -- Anything in def_env will be accessible within the session as a global variable
310 --luacheck: ignore 212/self
312 def_env.server = {};
314 function def_env.server:insane_reload()
315 prosody.unlock_globals();
316 dofile "prosody"
317 prosody = _G.prosody;
318 return true, "Server reloaded";
321 function def_env.server:version()
322 return true, tostring(prosody.version or "unknown");
325 function def_env.server:uptime()
326 local t = os.time()-prosody.start_time;
327 local seconds = t%60;
328 t = (t - seconds)/60;
329 local minutes = t%60;
330 t = (t - minutes)/60;
331 local hours = t%24;
332 t = (t - hours)/24;
333 local days = t;
334 return true, string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)",
335 days, (days ~= 1 and "s") or "", hours, (hours ~= 1 and "s") or "",
336 minutes, (minutes ~= 1 and "s") or "", os.date("%c", prosody.start_time));
339 function def_env.server:shutdown(reason)
340 prosody.shutdown(reason);
341 return true, "Shutdown initiated";
344 local function human(kb)
345 local unit = "K";
346 if kb > 1024 then
347 kb, unit = kb/1024, "M";
349 return ("%0.2f%sB"):format(kb, unit);
352 function def_env.server:memory()
353 if not has_pposix or not pposix.meminfo then
354 return true, "Lua is using "..human(collectgarbage("count"));
356 local mem, lua_mem = pposix.meminfo(), collectgarbage("count");
357 local print = self.session.print;
358 print("Process: "..human((mem.allocated+mem.allocated_mmap)/1024));
359 print(" Used: "..human(mem.used/1024).." ("..human(lua_mem).." by Lua)");
360 print(" Free: "..human(mem.unused/1024).." ("..human(mem.returnable/1024).." returnable)");
361 return true, "OK";
364 def_env.module = {};
366 local function get_hosts_set(hosts, module)
367 if type(hosts) == "table" then
368 if hosts[1] then
369 return set.new(hosts);
370 elseif hosts._items then
371 return hosts;
373 elseif type(hosts) == "string" then
374 return set.new { hosts };
375 elseif hosts == nil then
376 local hosts_set = set.new(array.collect(keys(prosody.hosts)))
377 / function (host) return (prosody.hosts[host].type == "local" or module and modulemanager.is_loaded(host, module)) and host or nil; end;
378 if module and modulemanager.get_module("*", module) then
379 hosts_set:add("*");
381 return hosts_set;
385 function def_env.module:load(name, hosts, config)
386 hosts = get_hosts_set(hosts);
388 -- Load the module for each host
389 local ok, err, count, mod = true, nil, 0;
390 for host in hosts do
391 if (not modulemanager.is_loaded(host, name)) then
392 mod, err = modulemanager.load(host, name, config);
393 if not mod then
394 ok = false;
395 if err == "global-module-already-loaded" then
396 if count > 0 then
397 ok, err, count = true, nil, 1;
399 break;
401 self.session.print(err or "Unknown error loading module");
402 else
403 count = count + 1;
404 self.session.print("Loaded for "..mod.module.host);
409 return ok, (ok and "Module loaded onto "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err));
412 function def_env.module:unload(name, hosts)
413 hosts = get_hosts_set(hosts, name);
415 -- Unload the module for each host
416 local ok, err, count = true, nil, 0;
417 for host in hosts do
418 if modulemanager.is_loaded(host, name) then
419 ok, err = modulemanager.unload(host, name);
420 if not ok then
421 ok = false;
422 self.session.print(err or "Unknown error unloading module");
423 else
424 count = count + 1;
425 self.session.print("Unloaded from "..host);
429 return ok, (ok and "Module unloaded from "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err));
432 local function _sort_hosts(a, b)
433 if a == "*" then return true
434 elseif b == "*" then return false
435 else return a < b; end
438 function def_env.module:reload(name, hosts)
439 hosts = array.collect(get_hosts_set(hosts, name)):sort(_sort_hosts)
441 -- Reload the module for each host
442 local ok, err, count = true, nil, 0;
443 for _, host in ipairs(hosts) do
444 if modulemanager.is_loaded(host, name) then
445 ok, err = modulemanager.reload(host, name);
446 if not ok then
447 ok = false;
448 self.session.print(err or "Unknown error reloading module");
449 else
450 count = count + 1;
451 if ok == nil then
452 ok = true;
454 self.session.print("Reloaded on "..host);
458 return ok, (ok and "Module reloaded on "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err));
461 function def_env.module:list(hosts)
462 if hosts == nil then
463 hosts = array.collect(keys(prosody.hosts));
464 table.insert(hosts, 1, "*");
466 if type(hosts) == "string" then
467 hosts = { hosts };
469 if type(hosts) ~= "table" then
470 return false, "Please supply a host or a list of hosts you would like to see";
473 local print = self.session.print;
474 for _, host in ipairs(hosts) do
475 print((host == "*" and "Global" or host)..":");
476 local modules = array.collect(keys(modulemanager.get_modules(host) or {})):sort();
477 if #modules == 0 then
478 if prosody.hosts[host] then
479 print(" No modules loaded");
480 else
481 print(" Host not found");
483 else
484 for _, name in ipairs(modules) do
485 local status, status_text = modulemanager.get_module(host, name).module:get_status();
486 local status_summary = "";
487 if status == "warn" or status == "error" then
488 status_summary = (" (%s: %s)"):format(status, status_text);
490 print((" %s%s"):format(name, status_summary));
496 def_env.config = {};
497 function def_env.config:load(filename, format)
498 local config_load = require "core.configmanager".load;
499 local ok, err = config_load(filename, format);
500 if not ok then
501 return false, err or "Unknown error loading config";
503 return true, "Config loaded";
506 function def_env.config:get(host, key)
507 if key == nil then
508 host, key = "*", host;
510 local config_get = require "core.configmanager".get
511 return true, serialize(config_get(host, key));
514 function def_env.config:reload()
515 local ok, err = prosody.reload_config();
516 return ok, (ok and "Config reloaded (you may need to reload modules to take effect)") or tostring(err);
519 local function common_info(session, line)
520 if session.id then
521 line[#line+1] = "["..session.id.."]"
522 else
523 line[#line+1] = "["..session.type..(tostring(session):match("%x*$")).."]"
527 local function session_flags(session, line)
528 line = line or {};
529 common_info(session, line);
530 if session.type == "c2s" then
531 local status, priority = "unavailable", tostring(session.priority or "-");
532 if session.presence then
533 status = session.presence:get_child_text("show") or "available";
535 line[#line+1] = status.."("..priority..")";
537 if session.cert_identity_status == "valid" then
538 line[#line+1] = "(authenticated)";
540 if session.secure then
541 line[#line+1] = "(encrypted)";
543 if session.compressed then
544 line[#line+1] = "(compressed)";
546 if session.smacks then
547 line[#line+1] = "(sm)";
549 if session.ip and session.ip:match(":") then
550 line[#line+1] = "(IPv6)";
552 if session.remote then
553 line[#line+1] = "(remote)";
555 if session.is_bidi or session.bidi_session then
556 line[#line+1] = "(bidi)";
558 if session.bosh_version then
559 line[#line+1] = "(bosh)";
561 if session.websocket_request then
562 line[#line+1] = "(websocket)";
564 return table.concat(line, " ");
567 local function tls_info(session, line)
568 line = line or {};
569 common_info(session, line);
570 if session.secure then
571 local sock = session.conn and session.conn.socket and session.conn:socket();
572 if sock and sock.info then
573 local info = sock:info();
574 line[#line+1] = ("(%s with %s)"):format(info.protocol, info.cipher);
575 else
576 line[#line+1] = "(cipher info unavailable)";
578 else
579 line[#line+1] = "(insecure)";
581 return table.concat(line, " ");
584 def_env.c2s = {};
586 local function get_jid(session)
587 if session.username then
588 return session.full_jid or jid_join(session.username, session.host, session.resource);
591 local conn = session.conn;
592 local ip = session.ip or "?";
593 local clientport = conn and conn:clientport() or "?";
594 local serverip = conn and conn.server and conn:server():ip() or "?";
595 local serverport = conn and conn:serverport() or "?"
596 return jid_join("["..ip.."]:"..clientport, session.host or "["..serverip.."]:"..serverport);
599 local function get_c2s()
600 local c2s = array.collect(values(prosody.full_sessions));
601 c2s:append(array.collect(values(module:shared"/*/c2s/sessions")));
602 c2s:append(array.collect(values(module:shared"/*/bosh/sessions")));
603 c2s:unique();
604 return c2s;
607 local function show_c2s(callback)
608 get_c2s():sort(function(a, b)
609 if a.host == b.host then
610 if a.username == b.username then
611 return (a.resource or "") > (b.resource or "");
613 return (a.username or "") > (b.username or "");
615 return (a.host or "") > (b.host or "");
616 end):map(function (session)
617 callback(get_jid(session), session)
618 end);
621 function def_env.c2s:count()
622 local c2s = get_c2s();
623 return true, "Total: ".. #c2s .." clients";
626 function def_env.c2s:show(match_jid, annotate)
627 local print, count = self.session.print, 0;
628 annotate = annotate or session_flags;
629 local curr_host = false;
630 show_c2s(function (jid, session)
631 if curr_host ~= session.host then
632 curr_host = session.host;
633 print(curr_host or "(not connected to any host yet)");
635 if (not match_jid) or jid:match(match_jid) then
636 count = count + 1;
637 print(annotate(session, { " ", jid }));
639 end);
640 return true, "Total: "..count.." clients";
643 function def_env.c2s:show_insecure(match_jid)
644 local print, count = self.session.print, 0;
645 show_c2s(function (jid, session)
646 if ((not match_jid) or jid:match(match_jid)) and not session.secure then
647 count = count + 1;
648 print(jid);
650 end);
651 return true, "Total: "..count.." insecure client connections";
654 function def_env.c2s:show_secure(match_jid)
655 local print, count = self.session.print, 0;
656 show_c2s(function (jid, session)
657 if ((not match_jid) or jid:match(match_jid)) and session.secure then
658 count = count + 1;
659 print(jid);
661 end);
662 return true, "Total: "..count.." secure client connections";
665 function def_env.c2s:show_tls(match_jid)
666 return self:show(match_jid, tls_info);
669 local function build_reason(text, condition)
670 if text or condition then
671 return {
672 text = text,
673 condition = condition or "undefined-condition",
678 function def_env.c2s:close(match_jid, text, condition)
679 local count = 0;
680 show_c2s(function (jid, session)
681 if jid == match_jid or jid_bare(jid) == match_jid then
682 count = count + 1;
683 session:close(build_reason(text, condition));
685 end);
686 return true, "Total: "..count.." sessions closed";
689 function def_env.c2s:closeall(text, condition)
690 local count = 0;
691 --luacheck: ignore 212/jid
692 show_c2s(function (jid, session)
693 count = count + 1;
694 session:close(build_reason(text, condition));
695 end);
696 return true, "Total: "..count.." sessions closed";
700 def_env.s2s = {};
701 function def_env.s2s:show(match_jid, annotate)
702 local print = self.session.print;
703 annotate = annotate or session_flags;
705 local count_in, count_out = 0,0;
706 local s2s_list = { };
708 local s2s_sessions = module:shared"/*/s2s/sessions";
709 for _, session in pairs(s2s_sessions) do
710 local remotehost, localhost, direction;
711 if session.direction == "outgoing" then
712 direction = "->";
713 count_out = count_out + 1;
714 remotehost, localhost = session.to_host or "?", session.from_host or "?";
715 else
716 direction = "<-";
717 count_in = count_in + 1;
718 remotehost, localhost = session.from_host or "?", session.to_host or "?";
720 local sess_lines = { l = localhost, r = remotehost,
721 annotate(session, { "", direction, remotehost or "?" })};
723 if (not match_jid) or remotehost:match(match_jid) or localhost:match(match_jid) then
724 table.insert(s2s_list, sess_lines);
725 -- luacheck: ignore 421/print
726 local print = function (s) table.insert(sess_lines, " "..s); end
727 if session.sendq then
728 print("There are "..#session.sendq.." queued outgoing stanzas for this connection");
730 if session.type == "s2sout_unauthed" then
731 if session.connecting then
732 print("Connection not yet established");
733 if not session.srv_hosts then
734 if not session.conn then
735 print("We do not yet have a DNS answer for this host's SRV records");
736 else
737 print("This host has no SRV records, using A record instead");
739 elseif session.srv_choice then
740 print("We are on SRV record "..session.srv_choice.." of "..#session.srv_hosts);
741 local srv_choice = session.srv_hosts[session.srv_choice];
742 print("Using "..(srv_choice.target or ".")..":"..(srv_choice.port or 5269));
744 elseif session.notopen then
745 print("The <stream> has not yet been opened");
746 elseif not session.dialback_key then
747 print("Dialback has not been initiated yet");
748 elseif session.dialback_key then
749 print("Dialback has been requested, but no result received");
752 if session.type == "s2sin_unauthed" then
753 print("Connection not yet authenticated");
754 elseif session.type == "s2sin" then
755 for name in pairs(session.hosts) do
756 if name ~= session.from_host then
757 print("also hosts "..tostring(name));
764 -- Sort by local host, then remote host
765 table.sort(s2s_list, function(a,b)
766 if a.l == b.l then return a.r < b.r; end
767 return a.l < b.l;
768 end);
769 local lasthost;
770 for _, sess_lines in ipairs(s2s_list) do
771 if sess_lines.l ~= lasthost then print(sess_lines.l); lasthost=sess_lines.l end
772 for _, line in ipairs(sess_lines) do print(line); end
774 return true, "Total: "..count_out.." outgoing, "..count_in.." incoming connections";
777 function def_env.s2s:show_tls(match_jid)
778 return self:show(match_jid, tls_info);
781 local function print_subject(print, subject)
782 for _, entry in ipairs(subject) do
783 print(
784 (" %s: %q"):format(
785 entry.name or entry.oid,
786 entry.value:gsub("[\r\n%z%c]", " ")
792 -- As much as it pains me to use the 0-based depths that OpenSSL does,
793 -- I think there's going to be more confusion among operators if we
794 -- break from that.
795 local function print_errors(print, errors)
796 for depth, t in pairs(errors) do
797 print(
798 (" %d: %s"):format(
799 depth-1,
800 table.concat(t, "\n| ")
806 function def_env.s2s:showcert(domain)
807 local print = self.session.print;
808 local s2s_sessions = module:shared"/*/s2s/sessions";
809 local domain_sessions = set.new(array.collect(values(s2s_sessions)))
810 /function(session) return (session.to_host == domain or session.from_host == domain) and session or nil; end;
811 local cert_set = {};
812 for session in domain_sessions do
813 local conn = session.conn;
814 conn = conn and conn:socket();
815 if not conn.getpeerchain then
816 if conn.dohandshake then
817 error("This version of LuaSec does not support certificate viewing");
819 else
820 local cert = conn:getpeercertificate();
821 if cert then
822 local certs = conn:getpeerchain();
823 local digest = cert:digest("sha1");
824 if not cert_set[digest] then
825 local chain_valid, chain_errors = conn:getpeerverification();
826 cert_set[digest] = {
828 from = session.from_host,
829 to = session.to_host,
830 direction = session.direction
832 chain_valid = chain_valid;
833 chain_errors = chain_errors;
834 certs = certs;
836 else
837 table.insert(cert_set[digest], {
838 from = session.from_host,
839 to = session.to_host,
840 direction = session.direction
846 local domain_certs = array.collect(values(cert_set));
847 -- Phew. We now have a array of unique certificates presented by domain.
848 local n_certs = #domain_certs;
850 if n_certs == 0 then
851 return "No certificates found for "..domain;
854 local function _capitalize_and_colon(byte)
855 return string.upper(byte)..":";
857 local function pretty_fingerprint(hash)
858 return hash:gsub("..", _capitalize_and_colon):sub(1, -2);
861 for cert_info in values(domain_certs) do
862 local certs = cert_info.certs;
863 local cert = certs[1];
864 print("---")
865 print("Fingerprint (SHA1): "..pretty_fingerprint(cert:digest("sha1")));
866 print("");
867 local n_streams = #cert_info;
868 print("Currently used on "..n_streams.." stream"..(n_streams==1 and "" or "s")..":");
869 for _, stream in ipairs(cert_info) do
870 if stream.direction == "incoming" then
871 print(" "..stream.to.." <- "..stream.from);
872 else
873 print(" "..stream.from.." -> "..stream.to);
876 print("");
877 local chain_valid, errors = cert_info.chain_valid, cert_info.chain_errors;
878 local valid_identity = cert_verify_identity(domain, "xmpp-server", cert);
879 if chain_valid then
880 print("Trusted certificate: Yes");
881 else
882 print("Trusted certificate: No");
883 print_errors(print, errors);
885 print("");
886 print("Issuer: ");
887 print_subject(print, cert:issuer());
888 print("");
889 print("Valid for "..domain..": "..(valid_identity and "Yes" or "No"));
890 print("Subject:");
891 print_subject(print, cert:subject());
893 print("---");
894 return ("Showing "..n_certs.." certificate"
895 ..(n_certs==1 and "" or "s")
896 .." presented by "..domain..".");
899 function def_env.s2s:close(from, to, text, condition)
900 local print, count = self.session.print, 0;
901 local s2s_sessions = module:shared"/*/s2s/sessions";
903 local match_id;
904 if from and not to then
905 match_id, from = from, nil;
906 elseif not to then
907 return false, "Syntax: s2s:close('from', 'to') - Closes all s2s sessions from 'from' to 'to'";
908 elseif from == to then
909 return false, "Both from and to are the same... you can't do that :)";
912 for _, session in pairs(s2s_sessions) do
913 local id = session.id or (session.type..tostring(session):match("[a-f0-9]+$"));
914 if (match_id and match_id == id)
915 or (session.from_host == from and session.to_host == to) then
916 print(("Closing connection from %s to %s [%s]"):format(session.from_host, session.to_host, id));
917 (session.close or s2smanager.destroy_session)(session, build_reason(text, condition));
918 count = count + 1 ;
921 return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s");
924 function def_env.s2s:closeall(host, text, condition)
925 local count = 0;
926 local s2s_sessions = module:shared"/*/s2s/sessions";
927 for _,session in pairs(s2s_sessions) do
928 if not host or session.from_host == host or session.to_host == host then
929 session:close(build_reason(text, condition));
930 count = count + 1;
933 if count == 0 then return false, "No sessions to close.";
934 else return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); end
937 def_env.host = {}; def_env.hosts = def_env.host;
939 function def_env.host:activate(hostname, config)
940 return hostmanager.activate(hostname, config);
942 function def_env.host:deactivate(hostname, reason)
943 return hostmanager.deactivate(hostname, reason);
946 function def_env.host:list()
947 local print = self.session.print;
948 local i = 0;
949 local type;
950 for host, host_session in iterators.sorted_pairs(prosody.hosts) do
951 i = i + 1;
952 type = host_session.type;
953 if type == "local" then
954 print(host);
955 else
956 type = module:context(host):get_option_string("component_module", type);
957 if type ~= "component" then
958 type = type .. " component";
960 print(("%s (%s)"):format(host, type));
963 return true, i.." hosts";
966 def_env.port = {};
968 function def_env.port:list()
969 local print = self.session.print;
970 local services = portmanager.get_active_services().data;
971 local n_services, n_ports = 0, 0;
972 for service, interfaces in iterators.sorted_pairs(services) do
973 n_services = n_services + 1;
974 local ports_list = {};
975 for interface, ports in pairs(interfaces) do
976 for port in pairs(ports) do
977 table.insert(ports_list, "["..interface.."]:"..port);
980 n_ports = n_ports + #ports_list;
981 print(service..": "..table.concat(ports_list, ", "));
983 return true, n_services.." services listening on "..n_ports.." ports";
986 function def_env.port:close(close_port, close_interface)
987 close_port = assert(tonumber(close_port), "Invalid port number");
988 local n_closed = 0;
989 local services = portmanager.get_active_services().data;
990 for service, interfaces in pairs(services) do -- luacheck: ignore 213
991 for interface, ports in pairs(interfaces) do
992 if not close_interface or close_interface == interface then
993 if ports[close_port] then
994 self.session.print("Closing ["..interface.."]:"..close_port.."...");
995 local ok, err = portmanager.close(interface, close_port)
996 if not ok then
997 self.session.print("Failed to close "..interface.." "..close_port..": "..err);
998 else
999 n_closed = n_closed + 1;
1005 return true, "Closed "..n_closed.." ports";
1008 def_env.muc = {};
1010 local console_room_mt = {
1011 __index = function (self, k) return self.room[k]; end;
1012 __tostring = function (self)
1013 return "MUC room <"..self.room.jid..">";
1014 end;
1017 local function check_muc(jid)
1018 local room_name, host = jid_split(jid);
1019 if not prosody.hosts[host] then
1020 return nil, "No such host: "..host;
1021 elseif not prosody.hosts[host].modules.muc then
1022 return nil, "Host '"..host.."' is not a MUC service";
1024 return room_name, host;
1027 function def_env.muc:create(room_jid, config)
1028 local room_name, host = check_muc(room_jid);
1029 if not room_name then
1030 return room_name, host;
1032 if not room_name then return nil, host end
1033 if config ~= nil and type(config) ~= "table" then return nil, "Config must be a table"; end
1034 if prosody.hosts[host].modules.muc.get_room_from_jid(room_jid) then return nil, "Room exists already" end
1035 return prosody.hosts[host].modules.muc.create_room(room_jid, config);
1038 function def_env.muc:room(room_jid)
1039 local room_name, host = check_muc(room_jid);
1040 if not room_name then
1041 return room_name, host;
1043 local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
1044 if not room_obj then
1045 return nil, "No such room: "..room_jid;
1047 return setmetatable({ room = room_obj }, console_room_mt);
1050 function def_env.muc:list(host)
1051 local host_session = prosody.hosts[host];
1052 if not host_session or not host_session.modules.muc then
1053 return nil, "Please supply the address of a local MUC component";
1055 local print = self.session.print;
1056 local c = 0;
1057 for room in host_session.modules.muc.each_room() do
1058 print(room.jid);
1059 c = c + 1;
1061 return true, c.." rooms";
1064 local um = require"core.usermanager";
1066 def_env.user = {};
1067 function def_env.user:create(jid, password)
1068 local username, host = jid_split(jid);
1069 if not prosody.hosts[host] then
1070 return nil, "No such host: "..host;
1071 elseif um.user_exists(username, host) then
1072 return nil, "User exists";
1074 local ok, err = um.create_user(username, password, host);
1075 if ok then
1076 return true, "User created";
1077 else
1078 return nil, "Could not create user: "..err;
1082 function def_env.user:delete(jid)
1083 local username, host = jid_split(jid);
1084 if not prosody.hosts[host] then
1085 return nil, "No such host: "..host;
1086 elseif not um.user_exists(username, host) then
1087 return nil, "No such user";
1089 local ok, err = um.delete_user(username, host);
1090 if ok then
1091 return true, "User deleted";
1092 else
1093 return nil, "Could not delete user: "..err;
1097 function def_env.user:password(jid, password)
1098 local username, host = jid_split(jid);
1099 if not prosody.hosts[host] then
1100 return nil, "No such host: "..host;
1101 elseif not um.user_exists(username, host) then
1102 return nil, "No such user";
1104 local ok, err = um.set_password(username, password, host, nil);
1105 if ok then
1106 return true, "User password changed";
1107 else
1108 return nil, "Could not change password for user: "..err;
1112 function def_env.user:list(host, pat)
1113 if not host then
1114 return nil, "No host given";
1115 elseif not prosody.hosts[host] then
1116 return nil, "No such host";
1118 local print = self.session.print;
1119 local total, matches = 0, 0;
1120 for user in um.users(host) do
1121 if not pat or user:match(pat) then
1122 print(user.."@"..host);
1123 matches = matches + 1;
1125 total = total + 1;
1127 return true, "Showing "..(pat and (matches.." of ") or "all " )..total.." users";
1130 def_env.xmpp = {};
1132 local st = require "util.stanza";
1133 local new_id = require "util.id".medium;
1134 function def_env.xmpp:ping(localhost, remotehost, timeout)
1135 localhost = select(2, jid_split(localhost));
1136 remotehost = select(2, jid_split(remotehost));
1137 if not localhost then
1138 return nil, "Invalid sender hostname";
1139 elseif not prosody.hosts[localhost] then
1140 return nil, "No such local host";
1142 if not remotehost then
1143 return nil, "Invalid destination hostname";
1144 elseif prosody.hosts[remotehost] then
1145 return nil, "Both hosts are local";
1147 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()}
1148 :tag("ping", {xmlns="urn:xmpp:ping"});
1149 local ret, err;
1150 local wait, done = async.waiter();
1151 module:context(localhost):send_iq(iq, nil, timeout)
1152 :next(function (ret_) ret = ret_; end,
1153 function (err_) err = err_; end)
1154 :finally(done);
1155 wait();
1156 if ret then
1157 return true, "pong from " .. ret.stanza.attr.from;
1158 else
1159 return false, tostring(err);
1163 def_env.dns = {};
1164 local adns = require"net.adns";
1165 local dns = require"net.dns";
1167 function def_env.dns:lookup(name, typ, class)
1168 local ret = "Query sent";
1169 local print = self.session.print;
1170 local function handler(...)
1171 ret = "Got response";
1172 print(...);
1174 adns.lookup(handler, name, typ, class);
1175 return true, ret;
1178 function def_env.dns:addnameserver(...)
1179 dns._resolver:addnameserver(...)
1180 return true
1183 function def_env.dns:setnameserver(...)
1184 dns._resolver:setnameserver(...)
1185 return true
1188 function def_env.dns:purge()
1189 dns.purge()
1190 return true
1193 function def_env.dns:cache()
1194 return true, "Cache:\n"..tostring(dns.cache())
1197 def_env.http = {};
1199 function def_env.http:list()
1200 local print = self.session.print;
1202 for host in pairs(prosody.hosts) do
1203 local http_apps = modulemanager.get_items("http-provider", host);
1204 if #http_apps > 0 then
1205 local http_host = module:context(host):get_option_string("http_host");
1206 print("HTTP endpoints on "..host..(http_host and (" (using "..http_host.."):") or ":"));
1207 for _, provider in ipairs(http_apps) do
1208 local url = module:context(host):http_url(provider.name, provider.default_path);
1209 print("", url);
1211 print("");
1215 local default_host = module:get_option_string("http_default_host");
1216 if not default_host then
1217 print("HTTP requests to unknown hosts will return 404 Not Found");
1218 else
1219 print("HTTP requests to unknown hosts will be handled by "..default_host);
1221 return true;
1224 def_env.debug = {};
1226 function def_env.debug:logevents(host)
1227 helpers.log_host_events(host);
1228 return true;
1231 function def_env.debug:events(host, event)
1232 local events_obj;
1233 if host and host ~= "*" then
1234 if host == "http" then
1235 events_obj = require "net.http.server"._events;
1236 elseif not prosody.hosts[host] then
1237 return false, "Unknown host: "..host;
1238 else
1239 events_obj = prosody.hosts[host].events;
1241 else
1242 events_obj = prosody.events;
1244 return true, helpers.show_events(events_obj, event);
1247 function def_env.debug:timers()
1248 local socket = require "socket";
1249 local print = self.session.print;
1250 local add_task = require"util.timer".add_task;
1251 local h, params = add_task.h, add_task.params;
1252 if h then
1253 print("-- util.timer");
1254 for i, id in ipairs(h.ids) do
1255 if not params[id] then
1256 print(os.date("%F %T", h.priorities[i]), h.items[id]);
1257 elseif not params[id].callback then
1258 print(os.date("%F %T", h.priorities[i]), h.items[id], unpack(params[id]));
1259 else
1260 print(os.date("%F %T", h.priorities[i]), params[id].callback, unpack(params[id]));
1264 if server.event_base then
1265 local count = 0;
1266 for _, v in pairs(debug.getregistry()) do
1267 if type(v) == "function" and v.callback and v.callback == add_task._on_timer then
1268 count = count + 1;
1271 print(count .. " libevent callbacks");
1273 if h then
1274 local next_time = h:peek();
1275 if next_time then
1276 return true, os.date("Next event at %F %T (in %%.6fs)", next_time):format(next_time - socket.gettime());
1279 return true;
1282 -- COMPAT: debug:timers() was timer:info() for some time in trunk
1283 def_env.timer = { info = def_env.debug.timers };
1285 module:hook("server-stopping", function(event)
1286 for _, session in pairs(sessions) do
1287 session.print("Shutting down: "..(event.reason or "unknown reason"));
1289 end);
1291 def_env.stats = {};
1293 local function format_stat(type, value, ref_value)
1294 ref_value = ref_value or value;
1295 --do return tostring(value) end
1296 if type == "duration" then
1297 if ref_value < 0.001 then
1298 return ("%g µs"):format(value*1000000);
1299 elseif ref_value < 0.9 then
1300 return ("%0.2f ms"):format(value*1000);
1302 return ("%0.2f"):format(value);
1303 elseif type == "size" then
1304 if ref_value > 1048576 then
1305 return ("%d MB"):format(value/1048576);
1306 elseif ref_value > 1024 then
1307 return ("%d KB"):format(value/1024);
1309 return ("%d bytes"):format(value);
1310 elseif type == "rate" then
1311 if ref_value < 0.9 then
1312 return ("%0.2f/min"):format(value*60);
1314 return ("%0.2f/sec"):format(value);
1316 return tostring(value);
1319 local stats_methods = {};
1320 function stats_methods:bounds(_lower, _upper)
1321 for _, stat_info in ipairs(self) do
1322 local data = stat_info[4];
1323 if data then
1324 local lower = _lower or data.min;
1325 local upper = _upper or data.max;
1326 local new_data = {
1327 min = lower;
1328 max = upper;
1329 samples = {};
1330 sample_count = 0;
1331 count = data.count;
1332 units = data.units;
1334 local sum = 0;
1335 for _, v in ipairs(data.samples) do
1336 if v > upper then
1337 break;
1338 elseif v>=lower then
1339 table.insert(new_data.samples, v);
1340 sum = sum + v;
1343 new_data.sample_count = #new_data.samples;
1344 stat_info[4] = new_data;
1345 stat_info[3] = sum/new_data.sample_count;
1348 return self;
1351 function stats_methods:trim(lower, upper)
1352 upper = upper or (100-lower);
1353 local statistics = require "util.statistics";
1354 for _, stat_info in ipairs(self) do
1355 -- Strip outliers
1356 local data = stat_info[4];
1357 if data then
1358 local new_data = {
1359 min = statistics.get_percentile(data, lower);
1360 max = statistics.get_percentile(data, upper);
1361 samples = {};
1362 sample_count = 0;
1363 count = data.count;
1364 units = data.units;
1366 local sum = 0;
1367 for _, v in ipairs(data.samples) do
1368 if v > new_data.max then
1369 break;
1370 elseif v>=new_data.min then
1371 table.insert(new_data.samples, v);
1372 sum = sum + v;
1375 new_data.sample_count = #new_data.samples;
1376 stat_info[4] = new_data;
1377 stat_info[3] = sum/new_data.sample_count;
1380 return self;
1383 function stats_methods:max(upper)
1384 return self:bounds(nil, upper);
1387 function stats_methods:min(lower)
1388 return self:bounds(lower, nil);
1391 function stats_methods:summary()
1392 local statistics = require "util.statistics";
1393 for _, stat_info in ipairs(self) do
1394 local type, value, data = stat_info[2], stat_info[3], stat_info[4];
1395 if data and data.samples then
1396 table.insert(stat_info.output, string.format("Count: %d (%d captured)",
1397 data.count,
1398 data.sample_count
1400 table.insert(stat_info.output, string.format("Min: %s Mean: %s Max: %s",
1401 format_stat(type, data.min),
1402 format_stat(type, value),
1403 format_stat(type, data.max)
1405 table.insert(stat_info.output, string.format("Q1: %s Median: %s Q3: %s",
1406 format_stat(type, statistics.get_percentile(data, 25)),
1407 format_stat(type, statistics.get_percentile(data, 50)),
1408 format_stat(type, statistics.get_percentile(data, 75))
1412 return self;
1415 function stats_methods:cfgraph()
1416 for _, stat_info in ipairs(self) do
1417 local name, type, value, data = unpack(stat_info, 1, 4);
1418 local function print(s)
1419 table.insert(stat_info.output, s);
1422 if data and data.sample_count and data.sample_count > 0 then
1423 local raw_histogram = require "util.statistics".get_histogram(data);
1425 local graph_width, graph_height = 50, 10;
1426 local eighth_chars = " ▁▂▃▄▅▆▇█";
1428 local range = data.max - data.min;
1430 if range > 0 then
1431 local x_scaling = #raw_histogram/graph_width;
1432 local histogram = {};
1433 for i = 1, graph_width do
1434 histogram[i] = math.max(raw_histogram[i*x_scaling-1] or 0, raw_histogram[i*x_scaling] or 0);
1437 print("");
1438 print(("_"):rep(52)..format_stat(type, data.max));
1439 for row = graph_height, 1, -1 do
1440 local row_chars = {};
1441 local min_eighths, max_eighths = 8, 0;
1442 for i = 1, #histogram do
1443 local char_eighths = math.ceil(math.max(math.min((graph_height/(data.max/histogram[i]))-(row-1), 1), 0)*8);
1444 if char_eighths < min_eighths then
1445 min_eighths = char_eighths;
1447 if char_eighths > max_eighths then
1448 max_eighths = char_eighths;
1450 if char_eighths == 0 then
1451 row_chars[i] = "-";
1452 else
1453 local char = eighth_chars:sub(char_eighths*3+1, char_eighths*3+3);
1454 row_chars[i] = char;
1457 print(table.concat(row_chars).."|-"..format_stat(type, data.max/(graph_height/(row-0.5))));
1459 print(("\\ "):rep(11));
1460 local x_labels = {};
1461 for i = 1, 11 do
1462 local s = ("%-4s"):format((i-1)*10);
1463 if #s > 4 then
1464 s = s:sub(1, 3).."…";
1466 x_labels[i] = s;
1468 print(" "..table.concat(x_labels, " "));
1469 local units = "%";
1470 local margin = math.floor((graph_width-#units)/2);
1471 print((" "):rep(margin)..units);
1472 else
1473 print("[range too small to graph]");
1475 print("");
1478 return self;
1481 function stats_methods:histogram()
1482 for _, stat_info in ipairs(self) do
1483 local name, type, value, data = unpack(stat_info, 1, 4);
1484 local function print(s)
1485 table.insert(stat_info.output, s);
1488 if not data then
1489 print("[no data]");
1490 return self;
1491 elseif not data.sample_count then
1492 print("[not a sampled metric type]");
1493 return self;
1496 local graph_width, graph_height = 50, 10;
1497 local eighth_chars = " ▁▂▃▄▅▆▇█";
1499 local range = data.max - data.min;
1501 if range > 0 then
1502 local n_buckets = graph_width;
1504 local histogram = {};
1505 for i = 1, n_buckets do
1506 histogram[i] = 0;
1508 local max_bin_samples = 0;
1509 for _, d in ipairs(data.samples) do
1510 local bucket = math.floor(1+(n_buckets-1)/(range/(d-data.min)));
1511 histogram[bucket] = histogram[bucket] + 1;
1512 if histogram[bucket] > max_bin_samples then
1513 max_bin_samples = histogram[bucket];
1517 print("");
1518 print(("_"):rep(52)..max_bin_samples);
1519 for row = graph_height, 1, -1 do
1520 local row_chars = {};
1521 local min_eighths, max_eighths = 8, 0;
1522 for i = 1, #histogram do
1523 local char_eighths = math.ceil(math.max(math.min((graph_height/(max_bin_samples/histogram[i]))-(row-1), 1), 0)*8);
1524 if char_eighths < min_eighths then
1525 min_eighths = char_eighths;
1527 if char_eighths > max_eighths then
1528 max_eighths = char_eighths;
1530 if char_eighths == 0 then
1531 row_chars[i] = "-";
1532 else
1533 local char = eighth_chars:sub(char_eighths*3+1, char_eighths*3+3);
1534 row_chars[i] = char;
1537 print(table.concat(row_chars).."|-"..math.ceil((max_bin_samples/graph_height)*(row-0.5)));
1539 print(("\\ "):rep(11));
1540 local x_labels = {};
1541 for i = 1, 11 do
1542 local s = ("%-4s"):format(format_stat(type, data.min+range*i/11, data.min):match("^%S+"));
1543 if #s > 4 then
1544 s = s:sub(1, 3).."…";
1546 x_labels[i] = s;
1548 print(" "..table.concat(x_labels, " "));
1549 local units = format_stat(type, data.min):match("%s+(.+)$") or data.units or "";
1550 local margin = math.floor((graph_width-#units)/2);
1551 print((" "):rep(margin)..units);
1552 else
1553 print("[range too small to graph]");
1555 print("");
1557 return self;
1560 local function stats_tostring(stats)
1561 local print = stats.session.print;
1562 for _, stat_info in ipairs(stats) do
1563 if #stat_info.output > 0 then
1564 print("\n#"..stat_info[1]);
1565 print("");
1566 for _, v in ipairs(stat_info.output) do
1567 print(v);
1569 print("");
1570 else
1571 print(("%-50s %s"):format(stat_info[1], format_stat(stat_info[2], stat_info[3])));
1574 return #stats.." statistics displayed";
1577 local stats_mt = {__index = stats_methods, __tostring = stats_tostring }
1578 local function new_stats_context(self)
1579 return setmetatable({ session = self.session, stats = true }, stats_mt);
1582 function def_env.stats:show(filter)
1583 local stats, changed, extra = require "core.statsmanager".get_stats();
1584 local available, displayed = 0, 0;
1585 local displayed_stats = new_stats_context(self);
1586 for name, value in iterators.sorted_pairs(stats) do
1587 available = available + 1;
1588 if not filter or name:match(filter) then
1589 displayed = displayed + 1;
1590 local type = name:match(":(%a+)$");
1591 table.insert(displayed_stats, {
1592 name, type, value, extra[name];
1593 output = {};
1597 return displayed_stats;
1602 -------------
1604 function printbanner(session)
1605 local option = module:get_option_string("console_banner", "full");
1606 if option == "full" or option == "graphic" then
1607 session.print [[
1608 ____ \ / _
1609 | _ \ _ __ ___ ___ _-_ __| |_ _
1610 | |_) | '__/ _ \/ __|/ _ \ / _` | | | |
1611 | __/| | | (_) \__ \ |_| | (_| | |_| |
1612 |_| |_| \___/|___/\___/ \__,_|\__, |
1613 A study in simplicity |___/
1617 if option == "short" or option == "full" then
1618 session.print("Welcome to the Prosody administration console. For a list of commands, type: help");
1619 session.print("You may find more help on using this console in our online documentation at ");
1620 session.print("https://prosody.im/doc/console\n");
1622 if option ~= "short" and option ~= "full" and option ~= "graphic" then
1623 session.print(option);
1627 module:provides("net", {
1628 name = "console";
1629 listener = console_listener;
1630 default_port = 5582;
1631 private = true;