2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
13 local prosody = _G.prosody;
14 local hosts = prosody.hosts;
16 local console_listener = { default_port = 5582; default_mode = "*a"; interface = "127.0.0.1" };
18 local hostmanager = require "core.hostmanager";
19 local modulemanager = require "core.modulemanager";
21 local iterators = require "util.iterators";
22 local keys, values = iterators.keys, iterators.values;
23 local jid = require "util.jid";
24 local jid_bare, jid_split = jid.bare, jid.split;
25 local set, array = require "util.set", require "util.array";
26 local cert_verify_identity = require "util.x509".verify_identity;
27 local envload = require "util.envload".envload;
28 local envloadfile = require "util.envload".envloadfile;
30 local commands = module:shared("commands")
31 local def_env = module:shared("env");
32 local default_env_mt = { __index = def_env };
33 local core_post_stanza = prosody.core_post_stanza;
35 local function redirect_output(_G, session)
36 local env = setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end });
37 env.dofile = function(name)
38 local f, err = envloadfile(name, env);
39 if not f then return f, err; end
47 function console:new_session(conn)
48 local w = function(s) conn:write(s:gsub("\n", "\r\n")); end;
49 local session = { conn = conn;
50 send = function (t) w(tostring(t)); end;
51 print = function (...)
53 for i=1,select("#", ...) do
54 t[i] = tostring(select(i, ...));
56 w("| "..table.concat(t, "\t").."\n");
58 disconnect = function () conn:close(); end;
60 session.env = setmetatable({}, default_env_mt);
62 -- Load up environment with helper objects
63 for name, t in pairs(def_env) do
64 if type(t) == "table" then
65 session.env[name] = setmetatable({ session = session }, { __index = t });
74 function console_listener.onconnect(conn)
75 -- Handle new connection
76 local session = console:new_session(conn);
77 sessions[conn] = session;
79 session.send(string.char(0));
82 function console_listener.onincoming(conn, data)
83 local session = sessions[conn];
85 local partial = session.partial_data;
90 for line in data:gmatch("[^\n]*[\n\004]") do
91 -- Handle data (loop allows us to break to add \0 after response)
95 if line:match("^>") then
96 line = line:gsub("^>", "");
98 elseif line == "\004" then
99 commands["bye"](session, line);
102 local command = line:match("^%w+") or line:match("%p");
103 if commands[command] then
104 commands[command](session, line);
109 session.env._ = line;
111 local chunkname = "=console";
112 local env = (useglobalenv and redirect_output(_G, session)) or session.env or nil
113 local chunk, err = envload("return "..line, chunkname, env);
115 chunk, err = envload(line, chunkname, env);
117 err = err:gsub("^%[string .-%]:%d+: ", "");
118 err = err:gsub("^:%d+: ", "");
119 err = err:gsub("'<eof>'", "the end of the line");
120 session.print("Sorry, I couldn't understand that... "..err);
125 local ranok, taskok, message = pcall(chunk);
127 if not (ranok or message or useglobalenv) and commands[line:lower()] then
128 commands[line:lower()](session, line);
133 session.print("Fatal error while running command, it did not complete");
134 session.print("Error: "..taskok);
139 session.print("Result: "..tostring(taskok));
141 elseif (not taskok) and message then
142 session.print("Command completed with a problem");
143 session.print("Message: "..tostring(message));
147 session.print("OK: "..tostring(message));
150 session.send(string.char(0));
152 session.partial_data = data:match("[^\n]+$");
155 function console_listener.ondisconnect(conn, err)
156 local session = sessions[conn];
158 session.disconnect();
159 sessions[conn] = nil;
163 -- Console commands --
164 -- These are simple commands, not valid standalone in Lua
166 function commands.bye(session)
167 session.print("See you! :)");
168 session.disconnect();
170 commands.quit, commands.exit = commands.bye, commands.bye;
172 commands["!"] = function (session, data)
173 if data:match("^!!") and session.env._ then
174 session.print("!> "..session.env._);
175 return console_listener.onincoming(session.conn, session.env._);
177 local old, new = data:match("^!(.-[^\\])!(.-)!$");
179 local ok, res = pcall(string.gsub, session.env._, old, new);
184 session.print("!> "..res);
185 return console_listener.onincoming(session.conn, res);
187 session.print("Sorry, not sure what you want");
191 function commands.help(session, data)
192 local print = session.print;
193 local section = data:match("^help (%w+)");
195 print [[Commands are divided into multiple sections. For help on a particular section, ]]
196 print [[type: help SECTION (for example, 'help c2s'). Sections are: ]]
198 print [[c2s - Commands to manage local client-to-server sessions]]
199 print [[s2s - Commands to manage sessions between this server and others]]
200 print [[module - Commands to load/reload/unload modules/plugins]]
201 print [[host - Commands to activate, deactivate and list virtual hosts]]
202 print [[user - Commands to create and delete users, and change their passwords]]
203 print [[server - Uptime, version, shutting down, etc.]]
204 print [[config - Reloading the configuration, etc.]]
205 print [[console - Help regarding the console itself]]
206 elseif section == "c2s" then
207 print [[c2s:show(jid) - Show all client sessions with the specified JID (or all if no JID given)]]
208 print [[c2s:show_insecure() - Show all unencrypted client connections]]
209 print [[c2s:show_secure() - Show all encrypted client connections]]
210 print [[c2s:close(jid) - Close all sessions for the specified JID]]
211 elseif section == "s2s" then
212 print [[s2s:show(domain) - Show all s2s connections for the given domain (or all if no domain given)]]
213 print [[s2s:close(from, to) - Close a connection from one domain to another]]
214 print [[s2s:closeall(host) - Close all the incoming/outgoing s2s sessions to specified host]]
215 elseif section == "module" then
216 print [[module:load(module, host) - Load the specified module on the specified host (or all hosts if none given)]]
217 print [[module:reload(module, host) - The same, but unloads and loads the module (saving state if the module supports it)]]
218 print [[module:unload(module, host) - The same, but just unloads the module from memory]]
219 print [[module:list(host) - List the modules loaded on the specified host]]
220 elseif section == "host" then
221 print [[host:activate(hostname) - Activates the specified host]]
222 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]]
223 print [[host:list() - List the currently-activated hosts]]
224 elseif section == "user" then
225 print [[user:create(jid, password) - Create the specified user account]]
226 print [[user:password(jid, password) - Set the password for the specified user account]]
227 print [[user:delete(jid, password) - Permanently remove the specified user account]]
228 elseif section == "server" then
229 print [[server:version() - Show the server's version number]]
230 print [[server:uptime() - Show how long the server has been running]]
231 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]]
232 elseif section == "config" then
233 print [[config:reload() - Reload the server configuration. Modules may need to be reloaded for changes to take effect.]]
234 elseif section == "console" then
235 print [[Hey! Welcome to Prosody's admin console.]]
236 print [[First thing, if you're ever wondering how to get out, simply type 'quit'.]]
237 print [[Secondly, note that we don't support the full telnet protocol yet (it's coming)]]
238 print [[so you may have trouble using the arrow keys, etc. depending on your system.]]
240 print [[For now we offer a couple of handy shortcuts:]]
241 print [[!! - Repeat the last command]]
242 print [[!old!new! - repeat the last command, but with 'old' replaced by 'new']]
244 print [[For those well-versed in Prosody's internals, or taking instruction from those who are,]]
245 print [[you can prefix a command with > to escape the console sandbox, and access everything in]]
246 print [[the running server. Great fun, but be careful not to break anything :)]]
251 -- Session environment --
252 -- Anything in def_env will be accessible within the session as a global variable
256 function def_env.server:insane_reload()
257 prosody.unlock_globals();
259 prosody = _G.prosody;
260 return true, "Server reloaded";
263 function def_env.server:version()
264 return true, tostring(prosody.version or "unknown");
267 function def_env.server:uptime()
268 local t = os.time()-prosody.start_time;
269 local seconds = t%60;
270 t = (t - seconds)/60;
271 local minutes = t%60;
272 t = (t - minutes)/60;
276 return true, string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)",
277 days, (days ~= 1 and "s") or "", hours, (hours ~= 1 and "s") or "",
278 minutes, (minutes ~= 1 and "s") or "", os.date("%c", prosody.start_time));
281 function def_env.server:shutdown(reason)
282 prosody.shutdown(reason);
283 return true, "Shutdown initiated";
288 local function get_hosts_set(hosts, module)
289 if type(hosts) == "table" then
291 return set.new(hosts);
292 elseif hosts._items then
295 elseif type(hosts) == "string" then
296 return set.new { hosts };
297 elseif hosts == nil then
298 local mm = require "modulemanager";
299 local hosts_set = set.new(array.collect(keys(prosody.hosts)))
300 / function (host) return (prosody.hosts[host].type == "local" or module and mm.is_loaded(host, module)) and host or nil; end;
301 if module and mm.get_module("*", module) then
308 function def_env.module:load(name, hosts, config)
309 local mm = require "modulemanager";
311 hosts = get_hosts_set(hosts);
313 -- Load the module for each host
314 local ok, err, count, mod = true, nil, 0, nil;
316 if (not mm.is_loaded(host, name)) then
317 mod, err = mm.load(host, name, config);
320 if err == "global-module-already-loaded" then
322 ok, err, count = true, nil, 1;
326 self.session.print(err or "Unknown error loading module");
329 self.session.print("Loaded for "..mod.module.host);
334 return ok, (ok and "Module loaded onto "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err));
337 function def_env.module:unload(name, hosts)
338 local mm = require "modulemanager";
340 hosts = get_hosts_set(hosts, name);
342 -- Unload the module for each host
343 local ok, err, count = true, nil, 0;
345 if mm.is_loaded(host, name) then
346 ok, err = mm.unload(host, name);
349 self.session.print(err or "Unknown error unloading module");
352 self.session.print("Unloaded from "..host);
356 return ok, (ok and "Module unloaded from "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err));
359 function def_env.module:reload(name, hosts)
360 local mm = require "modulemanager";
362 hosts = array.collect(get_hosts_set(hosts, name)):sort(function (a, b)
363 if a == "*" then return true
364 elseif b == "*" then return false
365 else return a < b; end
368 -- Reload the module for each host
369 local ok, err, count = true, nil, 0;
370 for _, host in ipairs(hosts) do
371 if mm.is_loaded(host, name) then
372 ok, err = mm.reload(host, name);
375 self.session.print(err or "Unknown error reloading module");
381 self.session.print("Reloaded on "..host);
385 return ok, (ok and "Module reloaded on "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err));
388 function def_env.module:list(hosts)
390 hosts = array.collect(keys(prosody.hosts));
391 table.insert(hosts, 1, "*");
393 if type(hosts) == "string" then
396 if type(hosts) ~= "table" then
397 return false, "Please supply a host or a list of hosts you would like to see";
400 local print = self.session.print;
401 for _, host in ipairs(hosts) do
402 print((host == "*" and "Global" or host)..":");
403 local modules = array.collect(keys(modulemanager.get_modules(host) or {})):sort();
404 if #modules == 0 then
405 if prosody.hosts[host] then
406 print(" No modules loaded");
408 print(" Host not found");
411 for _, name in ipairs(modules) do
419 function def_env.config:load(filename, format)
420 local config_load = require "core.configmanager".load;
421 local ok, err = config_load(filename, format);
423 return false, err or "Unknown error loading config";
425 return true, "Config loaded";
428 function def_env.config:get(host, section, key)
429 local config_get = require "core.configmanager".get
430 return true, tostring(config_get(host, section, key));
433 function def_env.config:reload()
434 local ok, err = prosody.reload_config();
435 return ok, (ok and "Config reloaded (you may need to reload modules to take effect)") or tostring(err);
439 function def_env.hosts:list()
440 for host, host_session in pairs(hosts) do
441 self.session.print(host);
446 function def_env.hosts:add(name)
451 local function show_c2s(callback)
452 for hostname, host in pairs(hosts) do
453 for username, user in pairs(host.sessions or {}) do
454 for resource, session in pairs(user.sessions or {}) do
455 local jid = username.."@"..hostname.."/"..resource;
456 callback(jid, session);
462 function def_env.c2s:count(match_jid)
464 show_c2s(function (jid, session)
465 if (not match_jid) or jid:match(match_jid) then
469 return true, "Total: "..count.." clients";
472 function def_env.c2s:show(match_jid)
473 local print, count = self.session.print, 0;
475 show_c2s(function (jid, session)
476 if curr_host ~= session.host then
477 curr_host = session.host;
480 if (not match_jid) or jid:match(match_jid) then
482 local status, priority = "unavailable", tostring(session.priority or "-");
483 if session.presence then
484 status = session.presence:child_with_name("show");
486 status = status:get_text() or "[invalid!]";
488 status = "available";
491 print(" "..jid.." - "..status.."("..priority..")");
494 return true, "Total: "..count.." clients";
497 function def_env.c2s:show_insecure(match_jid)
498 local print, count = self.session.print, 0;
499 show_c2s(function (jid, session)
500 if ((not match_jid) or jid:match(match_jid)) and not session.secure then
505 return true, "Total: "..count.." insecure client connections";
508 function def_env.c2s:show_secure(match_jid)
509 local print, count = self.session.print, 0;
510 show_c2s(function (jid, session)
511 if ((not match_jid) or jid:match(match_jid)) and session.secure then
516 return true, "Total: "..count.." secure client connections";
519 function def_env.c2s:close(match_jid)
520 local print, count = self.session.print, 0;
521 show_c2s(function (jid, session)
522 if jid == match_jid or jid_bare(jid) == match_jid then
527 return true, "Total: "..count.." sessions closed";
530 local function session_flags(session, line)
531 if session.cert_identity_status == "valid" then
532 line[#line+1] = "(secure)";
533 elseif session.secure then
534 line[#line+1] = "(encrypted)";
536 if session.compressed then
537 line[#line+1] = "(compressed)";
539 if session.smacks then
540 line[#line+1] = "(sm)";
542 if session.conn and session.conn:ip():match(":") then
543 line[#line+1] = "(IPv6)";
545 return table.concat(line, " ");
549 function def_env.s2s:show(match_jid)
550 local _print = self.session.print;
551 local print = self.session.print;
553 local count_in, count_out = 0,0;
555 for host, host_session in pairs(hosts) do
556 print = function (...) _print(host); _print(...); print = _print; end
557 for remotehost, session in pairs(host_session.s2sout) do
558 if (not match_jid) or remotehost:match(match_jid) or host:match(match_jid) then
559 count_out = count_out + 1;
560 print(session_flags(session, {" ", host, "->", remotehost}));
561 if session.sendq then
562 print(" There are "..#session.sendq.." queued outgoing stanzas for this connection");
564 if session.type == "s2sout_unauthed" then
565 if session.connecting then
566 print(" Connection not yet established");
567 if not session.srv_hosts then
568 if not session.conn then
569 print(" We do not yet have a DNS answer for this host's SRV records");
571 print(" This host has no SRV records, using A record instead");
573 elseif session.srv_choice then
574 print(" We are on SRV record "..session.srv_choice.." of "..#session.srv_hosts);
575 local srv_choice = session.srv_hosts[session.srv_choice];
576 print(" Using "..(srv_choice.target or ".")..":"..(srv_choice.port or 5269));
578 elseif session.notopen then
579 print(" The <stream> has not yet been opened");
580 elseif not session.dialback_key then
581 print(" Dialback has not been initiated yet");
582 elseif session.dialback_key then
583 print(" Dialback has been requested, but no result received");
588 local subhost_filter = function (h)
589 return (match_jid and h:match(match_jid));
591 for session in pairs(incoming_s2s) do
592 if session.to_host == host and ((not match_jid) or host:match(match_jid)
593 or (session.from_host and session.from_host:match(match_jid))
594 -- Pft! is what I say to list comprehensions
595 or (session.hosts and #array.collect(keys(session.hosts)):filter(subhost_filter)>0)) then
596 count_in = count_in + 1;
597 print(session_flags(session, {" ", host, "<-", session.from_host or "(unknown)"}));
598 if session.type == "s2sin_unauthed" then
599 print(" Connection not yet authenticated");
601 for name in pairs(session.hosts) do
602 if name ~= session.from_host then
603 print(" also hosts "..tostring(name));
612 for session in pairs(incoming_s2s) do
613 if not session.to_host and ((not match_jid) or session.from_host and session.from_host:match(match_jid)) then
614 count_in = count_in + 1;
615 print("Other incoming s2s connections");
616 print(" (unknown) <- "..(session.from_host or "(unknown)"));
620 return true, "Total: "..count_out.." outgoing, "..count_in.." incoming connections";
623 local function print_subject(print, subject)
624 for _, entry in ipairs(subject) do
627 entry.name or entry.oid,
628 entry.value:gsub("[\r\n%z%c]", " ")
634 -- As much as it pains me to use the 0-based depths that OpenSSL does,
635 -- I think there's going to be more confusion among operators if we
637 local function print_errors(print, errors)
638 for depth, t in ipairs(errors) do
642 table.concat(t, "\n| ")
648 function def_env.s2s:showcert(domain)
649 local ser = require "util.serialization".serialize;
650 local print = self.session.print;
651 local domain_sessions = set.new(array.collect(keys(incoming_s2s)))
652 /function(session) return session.from_host == domain and session or nil; end;
653 for local_host in values(prosody.hosts) do
654 local s2sout = local_host.s2sout;
655 if s2sout and s2sout[domain] then
656 domain_sessions:add(s2sout[domain]);
660 for session in domain_sessions do
661 local conn = session.conn;
662 conn = conn and conn:socket();
663 if not conn.getpeerchain then
664 if conn.dohandshake then
665 error("This version of LuaSec does not support certificate viewing");
668 local certs = conn:getpeerchain();
669 local cert = certs[1];
671 local digest = cert:digest("sha1");
672 if not cert_set[digest] then
673 local chain_valid, chain_errors = conn:getpeerverification();
676 from = session.from_host,
677 to = session.to_host,
678 direction = session.direction
680 chain_valid = chain_valid;
681 chain_errors = chain_errors;
685 table.insert(cert_set[digest], {
686 from = session.from_host,
687 to = session.to_host,
688 direction = session.direction
694 local domain_certs = array.collect(values(cert_set));
695 -- Phew. We now have a array of unique certificates presented by domain.
696 local n_certs = #domain_certs;
699 return "No certificates found for "..domain;
702 local function _capitalize_and_colon(byte)
703 return string.upper(byte)..":";
705 local function pretty_fingerprint(hash)
706 return hash:gsub("..", _capitalize_and_colon):sub(1, -2);
709 for cert_info in values(domain_certs) do
710 local certs = cert_info.certs;
711 local cert = certs[1];
713 print("Fingerprint (SHA1): "..pretty_fingerprint(cert:digest("sha1")));
715 local n_streams = #cert_info;
716 print("Currently used on "..n_streams.." stream"..(n_streams==1 and "" or "s")..":");
717 for _, stream in ipairs(cert_info) do
718 if stream.direction == "incoming" then
719 print(" "..stream.to.." <- "..stream.from);
721 print(" "..stream.from.." -> "..stream.to);
725 local chain_valid, errors = cert_info.chain_valid, cert_info.chain_errors;
726 local valid_identity = cert_verify_identity(domain, "xmpp-server", cert);
728 print("Trusted certificate: Yes");
730 print("Trusted certificate: No");
731 print_errors(print, errors);
735 print_subject(print, cert:issuer());
737 print("Valid for "..domain..": "..(valid_identity and "Yes" or "No"));
739 print_subject(print, cert:subject());
742 return ("Showing "..n_certs.." certificate"
743 ..(n_certs==1 and "" or "s")
744 .." presented by "..domain..".");
747 function def_env.s2s:close(from, to)
748 local print, count = self.session.print, 0;
750 if not (from and to) then
751 return false, "Syntax: s2s:close('from', 'to') - Closes all s2s sessions from 'from' to 'to'";
752 elseif from == to then
753 return false, "Both from and to are the same... you can't do that :)";
756 if hosts[from] and not hosts[to] then
757 -- Is an outgoing connection
758 local session = hosts[from].s2sout[to];
760 print("No outgoing connection from "..from.." to "..to)
762 (session.close or s2smanager.destroy_session)(session);
764 print("Closed outgoing session from "..from.." to "..to);
766 elseif hosts[to] and not hosts[from] then
767 -- Is an incoming connection
768 for session in pairs(incoming_s2s) do
769 if session.to_host == to and session.from_host == from then
770 (session.close or s2smanager.destroy_session)(session);
776 print("No incoming connections from "..from.." to "..to);
778 print("Closed "..count.." incoming session"..((count == 1 and "") or "s").." from "..from.." to "..to);
780 elseif hosts[to] and hosts[from] then
781 return false, "Both of the hostnames you specified are local, there are no s2s sessions to close";
783 return false, "Neither of the hostnames you specified are being used on this server";
786 return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s");
789 function def_env.s2s:closeall(host)
792 if not host or type(host) ~= "string" then return false, "wrong syntax: please use s2s:closeall('hostname.tld')"; end
794 for session in pairs(incoming_s2s) do
795 if session.to_host == host then
796 (session.close or s2smanager.destroy_session)(session);
800 for _, session in pairs(hosts[host].s2sout) do
801 (session.close or s2smanager.destroy_session)(session);
805 for session in pairs(incoming_s2s) do
806 if session.from_host == host then
807 (session.close or s2smanager.destroy_session)(session);
811 for _, h in pairs(hosts) do
812 if h.s2sout[host] then
813 (h.s2sout[host].close or s2smanager.destroy_session)(h.s2sout[host]);
819 if count == 0 then return false, "No sessions to close.";
820 else return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); end
823 def_env.host = {}; def_env.hosts = def_env.host;
825 function def_env.host:activate(hostname, config)
826 return hostmanager.activate(hostname, config);
828 function def_env.host:deactivate(hostname, reason)
829 return hostmanager.deactivate(hostname, reason);
832 function def_env.host:list()
833 local print = self.session.print;
835 for host in values(array.collect(keys(prosody.hosts)):sort()) do
839 return true, i.." hosts";
844 function def_env.port:list()
845 local print = self.session.print;
846 local services = portmanager.get_active_services().data;
847 local ordered_services, n_ports = {}, 0;
848 for service, interfaces in pairs(services) do
849 table.insert(ordered_services, service);
851 table.sort(ordered_services);
852 for _, service in ipairs(ordered_services) do
853 local ports_list = {};
854 for interface, ports in pairs(services[service]) do
855 for port in pairs(ports) do
856 table.insert(ports_list, "["..interface.."]:"..port);
859 n_ports = n_ports + #ports_list;
860 print(service..": "..table.concat(ports_list, ", "));
862 return true, #ordered_services.." services listening on "..n_ports.." ports";
865 function def_env.port:close(close_port, close_interface)
866 close_port = assert(tonumber(close_port), "Invalid port number");
868 local services = portmanager.get_active_services().data;
869 for service, interfaces in pairs(services) do
870 for interface, ports in pairs(interfaces) do
871 if not close_interface or close_interface == interface then
872 if ports[close_port] then
873 self.session.print("Closing ["..interface.."]:"..close_port.."...");
874 local ok, err = portmanager.close(interface, close_port)
876 self.session.print("Failed to close "..interface.." "..port..": "..err);
878 n_closed = n_closed + 1;
884 return true, "Closed "..n_closed.." ports";
889 local console_room_mt = {
890 __index = function (self, k) return self.room[k]; end;
891 __tostring = function (self)
892 return "MUC room <"..self.room.jid..">";
896 function def_env.muc:room(room_jid)
897 local room_name, host = jid_split(room_jid);
898 if not hosts[host] then
899 return nil, "No such host: "..host;
900 elseif not hosts[host].modules.muc then
901 return nil, "Host '"..host.."' is not a MUC service";
903 local room_obj = hosts[host].modules.muc.rooms[room_jid];
905 return nil, "No such room: "..room_jid;
907 return setmetatable({ room = room_obj }, console_room_mt);
910 local um = require"core.usermanager";
913 function def_env.user:create(jid, password)
914 local username, host = jid_split(jid);
915 local ok, err = um.create_user(username, password, host);
917 return true, "User created";
919 return nil, "Could not create user: "..err;
923 function def_env.user:delete(jid)
924 local username, host = jid_split(jid);
925 local ok, err = um.delete_user(username, host);
927 return true, "User deleted";
929 return nil, "Could not delete user: "..err;
933 function def_env.user:passwd(jid, password)
934 local username, host = jid_split(jid);
935 local ok, err = um.set_password(username, password, host);
937 return true, "User created";
939 return nil, "Could not change password for user: "..err;
945 local st = require "util.stanza";
946 function def_env.xmpp:ping(localhost, remotehost)
947 if hosts[localhost] then
948 core_post_stanza(hosts[localhost],
949 st.iq{ from=localhost, to=remotehost, type="get", id="ping" }
950 :tag("ping", {xmlns="urn:xmpp:ping"}));
951 return true, "Sent ping";
953 return nil, "No such host";
959 function printbanner(session)
960 local option = module:get_option("console_banner");
961 if option == nil or option == "full" or option == "graphic" then
964 | _ \ _ __ ___ ___ _-_ __| |_ _
965 | |_) | '__/ _ \/ __|/ _ \ / _` | | | |
966 | __/| | | (_) \__ \ |_| | (_| | |_| |
967 |_| |_| \___/|___/\___/ \__,_|\__, |
968 A study in simplicity |___/
972 if option == nil or option == "short" or option == "full" then
973 session.print("Welcome to the Prosody administration console. For a list of commands, type: help");
974 session.print("You may find more help on using this console in our online documentation at ");
975 session.print("http://prosody.im/doc/console\n");
977 if option and option ~= "short" and option ~= "full" and option ~= "graphic" then
978 if type(option) == "string" then
979 session.print(option)
980 elseif type(option) == "function" then
981 module:log("warn", "Using functions as value for the console_banner option is no longer supported");
986 module:add_item("net-provider", {
988 listener = console_listener;