Software /
code /
prosody
Annotate
plugins/mod_admin_telnet.lua @ 5710:e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 20 Jun 2013 21:47:38 +0200 |
parent | 5709:5557b4a4cb49 |
child | 5770:7722372aa087 |
rev | line source |
---|---|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1506
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2870
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2870
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
461
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
461
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
461
diff
changeset
|
8 |
4623
403b56b78018
mod_posix, mod_bosh, mod_admin_telnet: Use module:set_global()
Kim Alvefur <zash@zash.se>
parents:
4582
diff
changeset
|
9 module:set_global(); |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
461
diff
changeset
|
10 |
5030
9962fc19f9e9
mod_admin_telnet: Import prosody.incoming_s2s
Matthew Wild <mwild1@gmail.com>
parents:
5029
diff
changeset
|
11 local hostmanager = require "core.hostmanager"; |
9962fc19f9e9
mod_admin_telnet: Import prosody.incoming_s2s
Matthew Wild <mwild1@gmail.com>
parents:
5029
diff
changeset
|
12 local modulemanager = require "core.modulemanager"; |
9962fc19f9e9
mod_admin_telnet: Import prosody.incoming_s2s
Matthew Wild <mwild1@gmail.com>
parents:
5029
diff
changeset
|
13 local s2smanager = require "core.s2smanager"; |
9962fc19f9e9
mod_admin_telnet: Import prosody.incoming_s2s
Matthew Wild <mwild1@gmail.com>
parents:
5029
diff
changeset
|
14 local portmanager = require "core.portmanager"; |
9962fc19f9e9
mod_admin_telnet: Import prosody.incoming_s2s
Matthew Wild <mwild1@gmail.com>
parents:
5029
diff
changeset
|
15 |
1342
947d94e3619f
mod_console: Redirect print() to console session when executing commands in global environment
Matthew Wild <mwild1@gmail.com>
parents:
1341
diff
changeset
|
16 local _G = _G; |
947d94e3619f
mod_console: Redirect print() to console session when executing commands in global environment
Matthew Wild <mwild1@gmail.com>
parents:
1341
diff
changeset
|
17 |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
18 local prosody = _G.prosody; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
19 local hosts = prosody.hosts; |
736 | 20 |
4989
573123ff2ab0
mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents:
4979
diff
changeset
|
21 local console_listener = { default_port = 5582; default_mode = "*a"; interface = "127.0.0.1" }; |
736 | 22 |
4582
542afb9c2ab1
mod_admin_telnet: Import util.iterators properly
Kim Alvefur <zash@zash.se>
parents:
4571
diff
changeset
|
23 local iterators = require "util.iterators"; |
542afb9c2ab1
mod_admin_telnet: Import util.iterators properly
Kim Alvefur <zash@zash.se>
parents:
4571
diff
changeset
|
24 local keys, values = iterators.keys, iterators.values; |
4807
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
25 local jid = require "util.jid"; |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
26 local jid_bare, jid_split = jid.bare, jid.split; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
27 local set, array = require "util.set", require "util.array"; |
3733
26571a99f6e6
core.s2smanager, mod_console, mod_saslauth, util.certverification: rename util.certverification to util.x509
Kim Alvefur <zash@zash.se>
parents:
3718
diff
changeset
|
28 local cert_verify_identity = require "util.x509".verify_identity; |
5021
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4913
diff
changeset
|
29 local envload = require "util.envload".envload; |
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4913
diff
changeset
|
30 local envloadfile = require "util.envload".envloadfile; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
31 |
4540
ddce5b1bdfca
mod_admin_telnet: Use module:shared() to expose commands table and default console environment
Matthew Wild <mwild1@gmail.com>
parents:
4328
diff
changeset
|
32 local commands = module:shared("commands") |
ddce5b1bdfca
mod_admin_telnet: Use module:shared() to expose commands table and default console environment
Matthew Wild <mwild1@gmail.com>
parents:
4328
diff
changeset
|
33 local def_env = module:shared("env"); |
736 | 34 local default_env_mt = { __index = def_env }; |
5013
ab693eea0869
mod_admin_adhoc, mod_admin_telnet, mod_bosh, mod_c2s, mod_component, mod_pep, mod_presence, mod_roster, mod_s2s: Import core_post_stanza from the global prosody table.
Kim Alvefur <zash@zash.se>
parents:
5011
diff
changeset
|
35 local core_post_stanza = prosody.core_post_stanza; |
736 | 36 |
1342
947d94e3619f
mod_console: Redirect print() to console session when executing commands in global environment
Matthew Wild <mwild1@gmail.com>
parents:
1341
diff
changeset
|
37 local function redirect_output(_G, session) |
3557
58ab7e61d220
mod_console: Keep global variable assignments sandboxed by default.
Waqas Hussain <waqas20@gmail.com>
parents:
3540
diff
changeset
|
38 local env = setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end }); |
3407
15f633285755
mod_console: Override dofile() in the console environment (this lets print() print to the console session for example).
Waqas Hussain <waqas20@gmail.com>
parents:
3404
diff
changeset
|
39 env.dofile = function(name) |
5021
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4913
diff
changeset
|
40 local f, err = envloadfile(name, env); |
3407
15f633285755
mod_console: Override dofile() in the console environment (this lets print() print to the console session for example).
Waqas Hussain <waqas20@gmail.com>
parents:
3404
diff
changeset
|
41 if not f then return f, err; end |
5021
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4913
diff
changeset
|
42 return f(); |
3407
15f633285755
mod_console: Override dofile() in the console environment (this lets print() print to the console session for example).
Waqas Hussain <waqas20@gmail.com>
parents:
3404
diff
changeset
|
43 end; |
15f633285755
mod_console: Override dofile() in the console environment (this lets print() print to the console session for example).
Waqas Hussain <waqas20@gmail.com>
parents:
3404
diff
changeset
|
44 return env; |
1342
947d94e3619f
mod_console: Redirect print() to console session when executing commands in global environment
Matthew Wild <mwild1@gmail.com>
parents:
1341
diff
changeset
|
45 end |
947d94e3619f
mod_console: Redirect print() to console session when executing commands in global environment
Matthew Wild <mwild1@gmail.com>
parents:
1341
diff
changeset
|
46 |
736 | 47 console = {}; |
48 | |
49 function console:new_session(conn) | |
2145
daeb6ebf304c
mod_console: Update for new net.server API
Matthew Wild <mwild1@gmail.com>
parents:
2087
diff
changeset
|
50 local w = function(s) conn:write(s:gsub("\n", "\r\n")); end; |
736 | 51 local session = { conn = conn; |
52 send = function (t) w(tostring(t)); end; | |
3404
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
53 print = function (...) |
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
54 local t = {}; |
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
55 for i=1,select("#", ...) do |
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
56 t[i] = tostring(select(i, ...)); |
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
57 end |
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
58 w("| "..table.concat(t, "\t").."\n"); |
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
59 end; |
2253
a3537266a916
mod_console: Update for new server API, fixes traceback when closing console sessions
Matthew Wild <mwild1@gmail.com>
parents:
2145
diff
changeset
|
60 disconnect = function () conn:close(); end; |
736 | 61 }; |
62 session.env = setmetatable({}, default_env_mt); | |
63 | |
64 -- Load up environment with helper objects | |
65 for name, t in pairs(def_env) do | |
66 if type(t) == "table" then | |
67 session.env[name] = setmetatable({ session = session }, { __index = t }); | |
68 end | |
69 end | |
70 | |
71 return session; | |
72 end | |
73 | |
5186
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
74 function console:process_line(session, line) |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
75 local useglobalenv; |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
76 |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
77 if line:match("^>") then |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
78 line = line:gsub("^>", ""); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
79 useglobalenv = true; |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
80 elseif line == "\004" then |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
81 commands["bye"](session, line); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
82 return; |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
83 else |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
84 local command = line:match("^%w+") or line:match("%p"); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
85 if commands[command] then |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
86 commands[command](session, line); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
87 return; |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
88 end |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
89 end |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
90 |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
91 session.env._ = line; |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
92 |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
93 local chunkname = "=console"; |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
94 local env = (useglobalenv and redirect_output(_G, session)) or session.env or nil |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
95 local chunk, err = envload("return "..line, chunkname, env); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
96 if not chunk then |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
97 chunk, err = envload(line, chunkname, env); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
98 if not chunk then |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
99 err = err:gsub("^%[string .-%]:%d+: ", ""); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
100 err = err:gsub("^:%d+: ", ""); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
101 err = err:gsub("'<eof>'", "the end of the line"); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
102 session.print("Sorry, I couldn't understand that... "..err); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
103 return; |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
104 end |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
105 end |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
106 |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
107 local ranok, taskok, message = pcall(chunk); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
108 |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
109 if not (ranok or message or useglobalenv) and commands[line:lower()] then |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
110 commands[line:lower()](session, line); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
111 return; |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
112 end |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
113 |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
114 if not ranok then |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
115 session.print("Fatal error while running command, it did not complete"); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
116 session.print("Error: "..taskok); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
117 return; |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
118 end |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
119 |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
120 if not message then |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
121 session.print("Result: "..tostring(taskok)); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
122 return; |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
123 elseif (not taskok) and message then |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
124 session.print("Command completed with a problem"); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
125 session.print("Message: "..tostring(message)); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
126 return; |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
127 end |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
128 |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
129 session.print("OK: "..tostring(message)); |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
130 end |
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
131 |
736 | 132 local sessions = {}; |
133 | |
3009
06f7d8054065
mod_console: Make use of the new onconnect callback to initialise session and send banner
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
134 function console_listener.onconnect(conn) |
06f7d8054065
mod_console: Make use of the new onconnect callback to initialise session and send banner
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
135 -- Handle new connection |
06f7d8054065
mod_console: Make use of the new onconnect callback to initialise session and send banner
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
136 local session = console:new_session(conn); |
06f7d8054065
mod_console: Make use of the new onconnect callback to initialise session and send banner
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
137 sessions[conn] = session; |
06f7d8054065
mod_console: Make use of the new onconnect callback to initialise session and send banner
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
138 printbanner(session); |
669
9255abbb3068
mod_console: replace all \n with \r\n in the output, and send \0 as a marker character after every response
Waqas Hussain <waqas20@gmail.com>
parents:
615
diff
changeset
|
139 session.send(string.char(0)); |
736 | 140 end |
141 | |
2145
daeb6ebf304c
mod_console: Update for new net.server API
Matthew Wild <mwild1@gmail.com>
parents:
2087
diff
changeset
|
142 function console_listener.onincoming(conn, data) |
736 | 143 local session = sessions[conn]; |
1317
f6e56a555c37
mod_console: Allow running code in the global environment by prefixing with '>'
Matthew Wild <mwild1@gmail.com>
parents:
1316
diff
changeset
|
144 |
4989
573123ff2ab0
mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents:
4979
diff
changeset
|
145 local partial = session.partial_data; |
573123ff2ab0
mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents:
4979
diff
changeset
|
146 if partial then |
573123ff2ab0
mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents:
4979
diff
changeset
|
147 data = partial..data; |
573123ff2ab0
mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents:
4979
diff
changeset
|
148 end |
573123ff2ab0
mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents:
4979
diff
changeset
|
149 |
573123ff2ab0
mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents:
4979
diff
changeset
|
150 for line in data:gmatch("[^\n]*[\n\004]") do |
5278
f79be67e5666
mod_admin_telnet: Stop processing lines when session is closed
Kim Alvefur <zash@zash.se>
parents:
5270
diff
changeset
|
151 if session.closed then return end |
5186
ad898e50b8f3
mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents:
5168
diff
changeset
|
152 console:process_line(session, line); |
4989
573123ff2ab0
mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents:
4979
diff
changeset
|
153 session.send(string.char(0)); |
573123ff2ab0
mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents:
4979
diff
changeset
|
154 end |
573123ff2ab0
mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents:
4979
diff
changeset
|
155 session.partial_data = data:match("[^\n]+$"); |
736 | 156 end |
157 | |
2145
daeb6ebf304c
mod_console: Update for new net.server API
Matthew Wild <mwild1@gmail.com>
parents:
2087
diff
changeset
|
158 function console_listener.ondisconnect(conn, err) |
2054
a43aea9b0bd1
mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents:
2010
diff
changeset
|
159 local session = sessions[conn]; |
a43aea9b0bd1
mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents:
2010
diff
changeset
|
160 if session then |
a43aea9b0bd1
mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents:
2010
diff
changeset
|
161 session.disconnect(); |
a43aea9b0bd1
mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents:
2010
diff
changeset
|
162 sessions[conn] = nil; |
a43aea9b0bd1
mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents:
2010
diff
changeset
|
163 end |
736 | 164 end |
165 | |
166 -- Console commands -- | |
167 -- These are simple commands, not valid standalone in Lua | |
168 | |
169 function commands.bye(session) | |
170 session.print("See you! :)"); | |
5278
f79be67e5666
mod_admin_telnet: Stop processing lines when session is closed
Kim Alvefur <zash@zash.se>
parents:
5270
diff
changeset
|
171 session.closed = true; |
736 | 172 session.disconnect(); |
173 end | |
1503
5970e06d9335
mod_console: Add quit and exit as aliases for 'bye' command
Matthew Wild <mwild1@gmail.com>
parents:
1502
diff
changeset
|
174 commands.quit, commands.exit = commands.bye, commands.bye; |
736 | 175 |
176 commands["!"] = function (session, data) | |
3614
8b436cc88c0e
mod_console: Don't allow bang bang as the first command in a session, or when the last command is unknown (fixes #218)
Matthew Wild <mwild1@gmail.com>
parents:
3557
diff
changeset
|
177 if data:match("^!!") and session.env._ then |
736 | 178 session.print("!> "..session.env._); |
2512
d04b0eeeb954
mod_console: Update !! shortcut for new connection API
Matthew Wild <mwild1@gmail.com>
parents:
2296
diff
changeset
|
179 return console_listener.onincoming(session.conn, session.env._); |
736 | 180 end |
181 local old, new = data:match("^!(.-[^\\])!(.-)!$"); | |
182 if old and new then | |
183 local ok, res = pcall(string.gsub, session.env._, old, new); | |
184 if not ok then | |
185 session.print(res) | |
186 return; | |
187 end | |
188 session.print("!> "..res); | |
2512
d04b0eeeb954
mod_console: Update !! shortcut for new connection API
Matthew Wild <mwild1@gmail.com>
parents:
2296
diff
changeset
|
189 return console_listener.onincoming(session.conn, res); |
736 | 190 end |
191 session.print("Sorry, not sure what you want"); | |
192 end | |
193 | |
3452
2d1a5d8893c2
mod_console: Add host:* commands to help (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
3407
diff
changeset
|
194 |
1616
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
195 function commands.help(session, data) |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
196 local print = session.print; |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
197 local section = data:match("^help (%w+)"); |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
198 if not section then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
199 print [[Commands are divided into multiple sections. For help on a particular section, ]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
200 print [[type: help SECTION (for example, 'help c2s'). Sections are: ]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
201 print [[]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
202 print [[c2s - Commands to manage local client-to-server sessions]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
203 print [[s2s - Commands to manage sessions between this server and others]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
204 print [[module - Commands to load/reload/unload modules/plugins]] |
3452
2d1a5d8893c2
mod_console: Add host:* commands to help (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
3407
diff
changeset
|
205 print [[host - Commands to activate, deactivate and list virtual hosts]] |
4974
1574f18b0ca4
mod_admin_telnet: Add info about user management commands to the help
Kim Alvefur <zash@zash.se>
parents:
4973
diff
changeset
|
206 print [[user - Commands to create and delete users, and change their passwords]] |
1616
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
207 print [[server - Uptime, version, shutting down, etc.]] |
5270
20e14961f630
mod_admin_telnet: Add info about port commands to help
Kim Alvefur <zash@zash.se>
parents:
5227
diff
changeset
|
208 print [[port - Commands to manage ports the server is listening on]] |
5567
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
209 print [[dns - Commands to manage and inspect the internal DNS resolver]] |
2009
3f9cce29c57d
mod_console: Added help text for config:reload().
Waqas Hussain <waqas20@gmail.com>
parents:
2007
diff
changeset
|
210 print [[config - Reloading the configuration, etc.]] |
1616
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
211 print [[console - Help regarding the console itself]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
212 elseif section == "c2s" then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
213 print [[c2s:show(jid) - Show all client sessions with the specified JID (or all if no JID given)]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
214 print [[c2s:show_insecure() - Show all unencrypted client connections]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
215 print [[c2s:show_secure() - Show all encrypted client connections]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
216 print [[c2s:close(jid) - Close all sessions for the specified JID]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
217 elseif section == "s2s" then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
218 print [[s2s:show(domain) - Show all s2s connections for the given domain (or all if no domain given)]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
219 print [[s2s:close(from, to) - Close a connection from one domain to another]] |
4978
0b9e86302de4
mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents:
4913
diff
changeset
|
220 print [[s2s:closeall(host) - Close all the incoming/outgoing s2s sessions to specified host]] |
1616
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
221 elseif section == "module" then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
222 print [[module:load(module, host) - Load the specified module on the specified host (or all hosts if none given)]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
223 print [[module:reload(module, host) - The same, but unloads and loads the module (saving state if the module supports it)]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
224 print [[module:unload(module, host) - The same, but just unloads the module from memory]] |
1907
1dd4443e7d93
mod_console: Add module:list() to help
Matthew Wild <mwild1@gmail.com>
parents:
1906
diff
changeset
|
225 print [[module:list(host) - List the modules loaded on the specified host]] |
3452
2d1a5d8893c2
mod_console: Add host:* commands to help (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
3407
diff
changeset
|
226 elseif section == "host" then |
2d1a5d8893c2
mod_console: Add host:* commands to help (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
3407
diff
changeset
|
227 print [[host:activate(hostname) - Activates the specified host]] |
2d1a5d8893c2
mod_console: Add host:* commands to help (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
3407
diff
changeset
|
228 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]] |
2d1a5d8893c2
mod_console: Add host:* commands to help (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
3407
diff
changeset
|
229 print [[host:list() - List the currently-activated hosts]] |
4974
1574f18b0ca4
mod_admin_telnet: Add info about user management commands to the help
Kim Alvefur <zash@zash.se>
parents:
4973
diff
changeset
|
230 elseif section == "user" then |
1574f18b0ca4
mod_admin_telnet: Add info about user management commands to the help
Kim Alvefur <zash@zash.se>
parents:
4973
diff
changeset
|
231 print [[user:create(jid, password) - Create the specified user account]] |
1574f18b0ca4
mod_admin_telnet: Add info about user management commands to the help
Kim Alvefur <zash@zash.se>
parents:
4973
diff
changeset
|
232 print [[user:password(jid, password) - Set the password for the specified user account]] |
5128
834ab74585ec
mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents:
5030
diff
changeset
|
233 print [[user:delete(jid) - Permanently remove the specified user account]] |
5168
46fc0eff10b4
mod_admin_telnet: user:list(): Allow filtering the set of users
Kim Alvefur <zash@zash.se>
parents:
5167
diff
changeset
|
234 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] |
1616
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
235 elseif section == "server" then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
236 print [[server:version() - Show the server's version number]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
237 print [[server:uptime() - Show how long the server has been running]] |
5672
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
238 print [[server:memory() - Show details about the server's memory usage]] |
2870
471c3acffb2a
mod_console: Uncomment the help for server:shutdown() - thanks darkrain
Matthew Wild <mwild1@gmail.com>
parents:
2087
diff
changeset
|
239 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] |
5270
20e14961f630
mod_admin_telnet: Add info about port commands to help
Kim Alvefur <zash@zash.se>
parents:
5227
diff
changeset
|
240 elseif section == "port" then |
20e14961f630
mod_admin_telnet: Add info about port commands to help
Kim Alvefur <zash@zash.se>
parents:
5227
diff
changeset
|
241 print [[port:list() - Lists all network ports prosody currently listens on]] |
20e14961f630
mod_admin_telnet: Add info about port commands to help
Kim Alvefur <zash@zash.se>
parents:
5227
diff
changeset
|
242 print [[port:close(port, interface) - Close a port]] |
5567
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
243 elseif section == "dns" then |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
244 print [[dns:lookup(name, type, class) - Do a DNS lookup]] |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
245 print [[dns:addnameserver(nameserver) - Add a nameserver to the list]] |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
246 print [[dns:setnameserver(nameserver) - Replace the list of name servers with the supplied one]] |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
247 print [[dns:purge() - Clear the DNS cache]] |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
248 print [[dns:cache() - Show cached records]] |
2009
3f9cce29c57d
mod_console: Added help text for config:reload().
Waqas Hussain <waqas20@gmail.com>
parents:
2007
diff
changeset
|
249 elseif section == "config" then |
3f9cce29c57d
mod_console: Added help text for config:reload().
Waqas Hussain <waqas20@gmail.com>
parents:
2007
diff
changeset
|
250 print [[config:reload() - Reload the server configuration. Modules may need to be reloaded for changes to take effect.]] |
1616
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
251 elseif section == "console" then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
252 print [[Hey! Welcome to Prosody's admin console.]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
253 print [[First thing, if you're ever wondering how to get out, simply type 'quit'.]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
254 print [[Secondly, note that we don't support the full telnet protocol yet (it's coming)]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
255 print [[so you may have trouble using the arrow keys, etc. depending on your system.]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
256 print [[]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
257 print [[For now we offer a couple of handy shortcuts:]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
258 print [[!! - Repeat the last command]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
259 print [[!old!new! - repeat the last command, but with 'old' replaced by 'new']] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
260 print [[]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
261 print [[For those well-versed in Prosody's internals, or taking instruction from those who are,]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
262 print [[you can prefix a command with > to escape the console sandbox, and access everything in]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
263 print [[the running server. Great fun, but be careful not to break anything :)]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
264 end |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
265 print [[]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
266 end |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
267 |
736 | 268 -- Session environment -- |
269 -- Anything in def_env will be accessible within the session as a global variable | |
270 | |
271 def_env.server = {}; | |
1558
e15917530285
mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents:
1556
diff
changeset
|
272 |
1556
8154aa1fbe6c
mod_console: Rename server:reload() to server:insane_reload() (basically no-one should use it except me...)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
273 function def_env.server:insane_reload() |
1316
28ae044f1aaf
mod_console: Some "improvements" to the useless server:reload() command :)
Matthew Wild <mwild1@gmail.com>
parents:
1315
diff
changeset
|
274 prosody.unlock_globals(); |
736 | 275 dofile "prosody" |
1316
28ae044f1aaf
mod_console: Some "improvements" to the useless server:reload() command :)
Matthew Wild <mwild1@gmail.com>
parents:
1315
diff
changeset
|
276 prosody = _G.prosody; |
736 | 277 return true, "Server reloaded"; |
278 end | |
279 | |
1496
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
280 function def_env.server:version() |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
281 return true, tostring(prosody.version or "unknown"); |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
282 end |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
283 |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
284 function def_env.server:uptime() |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
285 local t = os.time()-prosody.start_time; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
286 local seconds = t%60; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
287 t = (t - seconds)/60; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
288 local minutes = t%60; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
289 t = (t - minutes)/60; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
290 local hours = t%24; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
291 t = (t - hours)/24; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
292 local days = t; |
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3452
diff
changeset
|
293 return true, string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)", |
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3452
diff
changeset
|
294 days, (days ~= 1 and "s") or "", hours, (hours ~= 1 and "s") or "", |
1496
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
295 minutes, (minutes ~= 1 and "s") or "", os.date("%c", prosody.start_time)); |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
296 end |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
297 |
1559
831649bb1922
mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents:
1558
diff
changeset
|
298 function def_env.server:shutdown(reason) |
831649bb1922
mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents:
1558
diff
changeset
|
299 prosody.shutdown(reason); |
831649bb1922
mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents:
1558
diff
changeset
|
300 return true, "Shutdown initiated"; |
831649bb1922
mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents:
1558
diff
changeset
|
301 end |
831649bb1922
mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents:
1558
diff
changeset
|
302 |
5672
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
303 local function human(kb) |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
304 local unit = "K"; |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
305 if kb > 1024 then |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
306 kb, unit = kb/1024, "M"; |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
307 end |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
308 return ("%0.2f%sB"):format(kb, unit); |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
309 end |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
310 |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
311 function def_env.server:memory() |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
312 if not pposix.meminfo then |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
313 return true, "Lua is using "..collectgarbage("count"); |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
314 end |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
315 local mem, lua_mem = pposix.meminfo(), collectgarbage("count"); |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
316 local print = self.session.print; |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
317 print("Process: "..human((mem.allocated+mem.allocated_mmap)/1024)); |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
318 print(" Used: "..human(mem.used/1024).." ("..human(lua_mem).." by Lua)"); |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
319 print(" Free: "..human(mem.unused/1024).." ("..human(mem.returnable/1024).." returnable)"); |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
320 return true, "OK"; |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
321 end |
0c68cea74d5d
mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents:
5665
diff
changeset
|
322 |
736 | 323 def_env.module = {}; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
324 |
1433
e7bd00e70973
mod_console: Reload/unload a module on a component host if it is loaded there
Matthew Wild <mwild1@gmail.com>
parents:
1342
diff
changeset
|
325 local function get_hosts_set(hosts, module) |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
326 if type(hosts) == "table" then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
327 if hosts[1] then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
328 return set.new(hosts); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
329 elseif hosts._items then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
330 return hosts; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
331 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
332 elseif type(hosts) == "string" then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
333 return set.new { hosts }; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
334 elseif hosts == nil then |
1433
e7bd00e70973
mod_console: Reload/unload a module on a component host if it is loaded there
Matthew Wild <mwild1@gmail.com>
parents:
1342
diff
changeset
|
335 local mm = require "modulemanager"; |
4644
fb067c8a8d2e
mod_admin_telnet: get_host_set(): Include '*' in the set if no specific hosts are specified and the module is loaded there
Matthew Wild <mwild1@gmail.com>
parents:
4623
diff
changeset
|
336 local hosts_set = set.new(array.collect(keys(prosody.hosts))) |
4912
8d0643281fe2
mod_admin_telnet: Code found and updated, which depended on pre-8c5b5ebaacb0 behaviour.
Kim Alvefur <zash@zash.se>
parents:
4807
diff
changeset
|
337 / function (host) return (prosody.hosts[host].type == "local" or module and mm.is_loaded(host, module)) and host or nil; end; |
4644
fb067c8a8d2e
mod_admin_telnet: get_host_set(): Include '*' in the set if no specific hosts are specified and the module is loaded there
Matthew Wild <mwild1@gmail.com>
parents:
4623
diff
changeset
|
338 if module and mm.get_module("*", module) then |
fb067c8a8d2e
mod_admin_telnet: get_host_set(): Include '*' in the set if no specific hosts are specified and the module is loaded there
Matthew Wild <mwild1@gmail.com>
parents:
4623
diff
changeset
|
339 hosts_set:add("*"); |
fb067c8a8d2e
mod_admin_telnet: get_host_set(): Include '*' in the set if no specific hosts are specified and the module is loaded there
Matthew Wild <mwild1@gmail.com>
parents:
4623
diff
changeset
|
340 end |
fb067c8a8d2e
mod_admin_telnet: get_host_set(): Include '*' in the set if no specific hosts are specified and the module is loaded there
Matthew Wild <mwild1@gmail.com>
parents:
4623
diff
changeset
|
341 return hosts_set; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
342 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
343 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
344 |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
345 function def_env.module:load(name, hosts, config) |
736 | 346 local mm = require "modulemanager"; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
347 |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
348 hosts = get_hosts_set(hosts); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
349 |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
350 -- Load the module for each host |
4647
57a4f863e48f
mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4646
diff
changeset
|
351 local ok, err, count, mod = true, nil, 0, nil; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
352 for host in hosts do |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
353 if (not mm.is_loaded(host, name)) then |
4647
57a4f863e48f
mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4646
diff
changeset
|
354 mod, err = mm.load(host, name, config); |
57a4f863e48f
mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4646
diff
changeset
|
355 if not mod then |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
356 ok = false; |
4647
57a4f863e48f
mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4646
diff
changeset
|
357 if err == "global-module-already-loaded" then |
57a4f863e48f
mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4646
diff
changeset
|
358 if count > 0 then |
57a4f863e48f
mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4646
diff
changeset
|
359 ok, err, count = true, nil, 1; |
57a4f863e48f
mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4646
diff
changeset
|
360 end |
57a4f863e48f
mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4646
diff
changeset
|
361 break; |
57a4f863e48f
mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4646
diff
changeset
|
362 end |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
363 self.session.print(err or "Unknown error loading module"); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
364 else |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
365 count = count + 1; |
4647
57a4f863e48f
mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4646
diff
changeset
|
366 self.session.print("Loaded for "..mod.module.host); |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
367 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
368 end |
736 | 369 end |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
370 |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
371 return ok, (ok and "Module loaded onto "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); |
736 | 372 end |
373 | |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
374 function def_env.module:unload(name, hosts) |
712
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
375 local mm = require "modulemanager"; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
376 |
1433
e7bd00e70973
mod_console: Reload/unload a module on a component host if it is loaded there
Matthew Wild <mwild1@gmail.com>
parents:
1342
diff
changeset
|
377 hosts = get_hosts_set(hosts, name); |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
378 |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
379 -- Unload the module for each host |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
380 local ok, err, count = true, nil, 0; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
381 for host in hosts do |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
382 if mm.is_loaded(host, name) then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
383 ok, err = mm.unload(host, name); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
384 if not ok then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
385 ok = false; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
386 self.session.print(err or "Unknown error unloading module"); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
387 else |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
388 count = count + 1; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
389 self.session.print("Unloaded from "..host); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
390 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
391 end |
712
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
392 end |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
393 return ok, (ok and "Module unloaded from "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); |
712
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
394 end |
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
395 |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
396 function def_env.module:reload(name, hosts) |
712
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
397 local mm = require "modulemanager"; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
398 |
4645
4539e99be743
mod_admin_telnet: module:reload(): If module is loaded on *, reload it there first (ensuring shared module code is reloaded before per-host children of that module)
Matthew Wild <mwild1@gmail.com>
parents:
4644
diff
changeset
|
399 hosts = array.collect(get_hosts_set(hosts, name)):sort(function (a, b) |
4539e99be743
mod_admin_telnet: module:reload(): If module is loaded on *, reload it there first (ensuring shared module code is reloaded before per-host children of that module)
Matthew Wild <mwild1@gmail.com>
parents:
4644
diff
changeset
|
400 if a == "*" then return true |
4539e99be743
mod_admin_telnet: module:reload(): If module is loaded on *, reload it there first (ensuring shared module code is reloaded before per-host children of that module)
Matthew Wild <mwild1@gmail.com>
parents:
4644
diff
changeset
|
401 elseif b == "*" then return false |
4539e99be743
mod_admin_telnet: module:reload(): If module is loaded on *, reload it there first (ensuring shared module code is reloaded before per-host children of that module)
Matthew Wild <mwild1@gmail.com>
parents:
4644
diff
changeset
|
402 else return a < b; end |
4539e99be743
mod_admin_telnet: module:reload(): If module is loaded on *, reload it there first (ensuring shared module code is reloaded before per-host children of that module)
Matthew Wild <mwild1@gmail.com>
parents:
4644
diff
changeset
|
403 end); |
4539e99be743
mod_admin_telnet: module:reload(): If module is loaded on *, reload it there first (ensuring shared module code is reloaded before per-host children of that module)
Matthew Wild <mwild1@gmail.com>
parents:
4644
diff
changeset
|
404 |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
405 -- Reload the module for each host |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
406 local ok, err, count = true, nil, 0; |
4645
4539e99be743
mod_admin_telnet: module:reload(): If module is loaded on *, reload it there first (ensuring shared module code is reloaded before per-host children of that module)
Matthew Wild <mwild1@gmail.com>
parents:
4644
diff
changeset
|
407 for _, host in ipairs(hosts) do |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
408 if mm.is_loaded(host, name) then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
409 ok, err = mm.reload(host, name); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
410 if not ok then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
411 ok = false; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
412 self.session.print(err or "Unknown error reloading module"); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
413 else |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
414 count = count + 1; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
415 if ok == nil then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
416 ok = true; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
417 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
418 self.session.print("Reloaded on "..host); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
419 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
420 end |
712
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
421 end |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
422 return ok, (ok and "Module reloaded on "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); |
712
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
423 end |
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
424 |
1906
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
425 function def_env.module:list(hosts) |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
426 if hosts == nil then |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
427 hosts = array.collect(keys(prosody.hosts)); |
4646
e0bd8587f2fb
mod_admin_telnet: module:list(): List global modules (part-fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4645
diff
changeset
|
428 table.insert(hosts, 1, "*"); |
1906
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
429 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
430 if type(hosts) == "string" then |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
431 hosts = { hosts }; |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
432 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
433 if type(hosts) ~= "table" then |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
434 return false, "Please supply a host or a list of hosts you would like to see"; |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
435 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
436 |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
437 local print = self.session.print; |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
438 for _, host in ipairs(hosts) do |
4646
e0bd8587f2fb
mod_admin_telnet: module:list(): List global modules (part-fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4645
diff
changeset
|
439 print((host == "*" and "Global" or host)..":"); |
e0bd8587f2fb
mod_admin_telnet: module:list(): List global modules (part-fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4645
diff
changeset
|
440 local modules = array.collect(keys(modulemanager.get_modules(host) or {})):sort(); |
1906
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
441 if #modules == 0 then |
2010
1a4f14ea39b6
mod_console: Fixed traceback occuring on using module:list on unknown hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2009
diff
changeset
|
442 if prosody.hosts[host] then |
1a4f14ea39b6
mod_console: Fixed traceback occuring on using module:list on unknown hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2009
diff
changeset
|
443 print(" No modules loaded"); |
1a4f14ea39b6
mod_console: Fixed traceback occuring on using module:list on unknown hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2009
diff
changeset
|
444 else |
1a4f14ea39b6
mod_console: Fixed traceback occuring on using module:list on unknown hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2009
diff
changeset
|
445 print(" Host not found"); |
1a4f14ea39b6
mod_console: Fixed traceback occuring on using module:list on unknown hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2009
diff
changeset
|
446 end |
1906
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
447 else |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
448 for _, name in ipairs(modules) do |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
449 print(" "..name); |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
450 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
451 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
452 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
453 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
454 |
736 | 455 def_env.config = {}; |
456 function def_env.config:load(filename, format) | |
457 local config_load = require "core.configmanager".load; | |
458 local ok, err = config_load(filename, format); | |
459 if not ok then | |
460 return false, err or "Unknown error loading config"; | |
461 end | |
462 return true, "Config loaded"; | |
463 end | |
464 | |
465 function def_env.config:get(host, section, key) | |
466 local config_get = require "core.configmanager".get | |
467 return true, tostring(config_get(host, section, key)); | |
468 end | |
469 | |
1558
e15917530285
mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents:
1556
diff
changeset
|
470 function def_env.config:reload() |
e15917530285
mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents:
1556
diff
changeset
|
471 local ok, err = prosody.reload_config(); |
e15917530285
mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents:
1556
diff
changeset
|
472 return ok, (ok and "Config reloaded (you may need to reload modules to take effect)") or tostring(err); |
e15917530285
mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents:
1556
diff
changeset
|
473 end |
e15917530285
mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents:
1556
diff
changeset
|
474 |
736 | 475 def_env.hosts = {}; |
476 function def_env.hosts:list() | |
477 for host, host_session in pairs(hosts) do | |
478 self.session.print(host); | |
479 end | |
480 return true, "Done"; | |
481 end | |
482 | |
483 function def_env.hosts:add(name) | |
484 end | |
485 | |
5586
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
486 local function session_flags(session, line) |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
487 line = line or {}; |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
488 if session.cert_identity_status == "valid" then |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
489 line[#line+1] = "(secure)"; |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
490 elseif session.secure then |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
491 line[#line+1] = "(encrypted)"; |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
492 end |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
493 if session.compressed then |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
494 line[#line+1] = "(compressed)"; |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
495 end |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
496 if session.smacks then |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
497 line[#line+1] = "(sm)"; |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
498 end |
5662
685d46ec352b
mod_admin_telnet: Simplify IPv6 detection, fixes rare traceback
Kim Alvefur <zash@zash.se>
parents:
5645
diff
changeset
|
499 if session.ip and session.ip:match(":") then |
5586
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
500 line[#line+1] = "(IPv6)"; |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
501 end |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
502 return table.concat(line, " "); |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
503 end |
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
504 |
1241
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
505 def_env.c2s = {}; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
506 |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
507 local function show_c2s(callback) |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
508 for hostname, host in pairs(hosts) do |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
509 for username, user in pairs(host.sessions or {}) do |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
510 for resource, session in pairs(user.sessions or {}) do |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
511 local jid = username.."@"..hostname.."/"..resource; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
512 callback(jid, session); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
513 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
514 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
515 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
516 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
517 |
4779
9f2639b3d9b1
mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents:
4684
diff
changeset
|
518 function def_env.c2s:count(match_jid) |
9f2639b3d9b1
mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents:
4684
diff
changeset
|
519 local count = 0; |
9f2639b3d9b1
mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents:
4684
diff
changeset
|
520 show_c2s(function (jid, session) |
9f2639b3d9b1
mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents:
4684
diff
changeset
|
521 if (not match_jid) or jid:match(match_jid) then |
9f2639b3d9b1
mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents:
4684
diff
changeset
|
522 count = count + 1; |
9f2639b3d9b1
mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents:
4684
diff
changeset
|
523 end |
9f2639b3d9b1
mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents:
4684
diff
changeset
|
524 end); |
9f2639b3d9b1
mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents:
4684
diff
changeset
|
525 return true, "Total: "..count.." clients"; |
9f2639b3d9b1
mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents:
4684
diff
changeset
|
526 end |
9f2639b3d9b1
mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents:
4684
diff
changeset
|
527 |
1241
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
528 function def_env.c2s:show(match_jid) |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
529 local print, count = self.session.print, 0; |
1763
9e4ff3b66ed1
mod_console: c2s:show(): Group listed clients by host
Matthew Wild <mwild1@gmail.com>
parents:
1623
diff
changeset
|
530 local curr_host; |
1798
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
531 show_c2s(function (jid, session) |
1763
9e4ff3b66ed1
mod_console: c2s:show(): Group listed clients by host
Matthew Wild <mwild1@gmail.com>
parents:
1623
diff
changeset
|
532 if curr_host ~= session.host then |
9e4ff3b66ed1
mod_console: c2s:show(): Group listed clients by host
Matthew Wild <mwild1@gmail.com>
parents:
1623
diff
changeset
|
533 curr_host = session.host; |
9e4ff3b66ed1
mod_console: c2s:show(): Group listed clients by host
Matthew Wild <mwild1@gmail.com>
parents:
1623
diff
changeset
|
534 print(curr_host); |
9e4ff3b66ed1
mod_console: c2s:show(): Group listed clients by host
Matthew Wild <mwild1@gmail.com>
parents:
1623
diff
changeset
|
535 end |
1241
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
536 if (not match_jid) or jid:match(match_jid) then |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
537 count = count + 1; |
1798
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
538 local status, priority = "unavailable", tostring(session.priority or "-"); |
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
539 if session.presence then |
5593
98a485212592
mod_admin_telnet: Use stanza:get_child_text()
Kim Alvefur <zash@zash.se>
parents:
5586
diff
changeset
|
540 status = session.presence:get_child_text("show") or "available"; |
1798
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
541 end |
5586
7e1264bf7af8
mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents:
5579
diff
changeset
|
542 print(session_flags(session, { " "..jid.." - "..status.."("..priority..")" })); |
1241
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
543 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
544 end); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
545 return true, "Total: "..count.." clients"; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
546 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
547 |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
548 function def_env.c2s:show_insecure(match_jid) |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
549 local print, count = self.session.print, 0; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
550 show_c2s(function (jid, session) |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
551 if ((not match_jid) or jid:match(match_jid)) and not session.secure then |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
552 count = count + 1; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
553 print(jid); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
554 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
555 end); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
556 return true, "Total: "..count.." insecure client connections"; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
557 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
558 |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
559 function def_env.c2s:show_secure(match_jid) |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
560 local print, count = self.session.print, 0; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
561 show_c2s(function (jid, session) |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
562 if ((not match_jid) or jid:match(match_jid)) and session.secure then |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
563 count = count + 1; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
564 print(jid); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
565 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
566 end); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
567 return true, "Total: "..count.." secure client connections"; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
568 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
569 |
1491
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
570 function def_env.c2s:close(match_jid) |
5028
10a69a7e4545
mod_admin_telnet: Remove unused variable
Matthew Wild <mwild1@gmail.com>
parents:
5027
diff
changeset
|
571 local count = 0; |
1491
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
572 show_c2s(function (jid, session) |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
573 if jid == match_jid or jid_bare(jid) == match_jid then |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
574 count = count + 1; |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
575 session:close(); |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
576 end |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
577 end); |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
578 return true, "Total: "..count.." sessions closed"; |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
579 end |
1241
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
580 |
4514
ae48e0abc233
mod_admin_telnet: Commond and flexible way to show stream properties.
Kim Alvefur <zash@zash.se>
parents:
4328
diff
changeset
|
581 |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
582 def_env.s2s = {}; |
1240
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
583 function def_env.s2s:show(match_jid) |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
584 local print = self.session.print; |
1322
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
585 |
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
586 local count_in, count_out = 0,0; |
5710
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
587 local s2s_list = { }; |
1322
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
588 |
5710
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
589 local s2s_sessions = module:shared"/*/s2s/sessions"; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
590 for _, session in pairs(s2s_sessions) do |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
591 local remotehost, localhost, direction; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
592 if session.direction == "outgoing" then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
593 direction = "->"; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
594 count_out = count_out + 1; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
595 remotehost, localhost = session.to_host or "?", session.from_host or "?"; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
596 else |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
597 direction = "<-"; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
598 count_in = count_in + 1; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
599 remotehost, localhost = session.from_host or "?", session.to_host or "?"; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
600 end |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
601 local sess_lines = { l = localhost, r = remotehost, |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
602 session_flags(session, { "", direction, remotehost or "?", |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
603 "["..session.type..tostring(session):match("[a-f0-9]*$").."]" })}; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
604 |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
605 if (not match_jid) or remotehost:match(match_jid) or localhost:match(match_jid) then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
606 table.insert(s2s_list, sess_lines); |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
607 local print = function (s) table.insert(sess_lines, " "..s); end |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
608 if session.sendq then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
609 print("There are "..#session.sendq.." queued outgoing stanzas for this connection"); |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
610 end |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
611 if session.type == "s2sout_unauthed" then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
612 if session.connecting then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
613 print("Connection not yet established"); |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
614 if not session.srv_hosts then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
615 if not session.conn then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
616 print("We do not yet have a DNS answer for this host's SRV records"); |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
617 else |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
618 print("This host has no SRV records, using A record instead"); |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
619 end |
5710
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
620 elseif session.srv_choice then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
621 print("We are on SRV record "..session.srv_choice.." of "..#session.srv_hosts); |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
622 local srv_choice = session.srv_hosts[session.srv_choice]; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
623 print("Using "..(srv_choice.target or ".")..":"..(srv_choice.port or 5269)); |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
624 end |
5710
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
625 elseif session.notopen then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
626 print("The <stream> has not yet been opened"); |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
627 elseif not session.dialback_key then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
628 print("Dialback has not been initiated yet"); |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
629 elseif session.dialback_key then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
630 print("Dialback has been requested, but no result received"); |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
631 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
632 end |
5710
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
633 if session.type == "s2sin_unauthed" then |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
634 print("Connection not yet authenticated"); |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
635 elseif session.type == "s2sin" then |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
636 for name in pairs(session.hosts) do |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
637 if name ~= session.from_host then |
5710
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
638 print("also hosts "..tostring(name)); |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
639 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
640 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
641 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
642 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
643 end |
5710
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
644 |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
645 -- Sort by local host, then remote host |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
646 table.sort(s2s_list, function(a,b) |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
647 if a.l == b.l then return a.r < b.r; end |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
648 return a.l < b.l; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
649 end); |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
650 local lasthost; |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
651 for _, sess_lines in ipairs(s2s_list) do |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
652 if sess_lines.l ~= lasthost then print(sess_lines.l); lasthost=sess_lines.l end |
e66bbfdf588e
mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents:
5709
diff
changeset
|
653 for _, line in ipairs(sess_lines) do print(line); end |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
654 end |
1322
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
655 return true, "Total: "..count_out.." outgoing, "..count_in.." incoming connections"; |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
656 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
657 |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
658 local function print_subject(print, subject) |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
659 for _, entry in ipairs(subject) do |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
660 print( |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
661 (" %s: %q"):format( |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
662 entry.name or entry.oid, |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
663 entry.value:gsub("[\r\n%z%c]", " ") |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
664 ) |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
665 ); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
666 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
667 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
668 |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
669 -- As much as it pains me to use the 0-based depths that OpenSSL does, |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
670 -- I think there's going to be more confusion among operators if we |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
671 -- break from that. |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
672 local function print_errors(print, errors) |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
673 for depth, t in ipairs(errors) do |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
674 print( |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
675 (" %d: %s"):format( |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
676 depth-1, |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
677 table.concat(t, "\n| ") |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
678 ) |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
679 ); |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
680 end |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
681 end |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
682 |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
683 function def_env.s2s:showcert(domain) |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
684 local ser = require "util.serialization".serialize; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
685 local print = self.session.print; |
5706
896094da72e4
mod_admin_telnet: Refactor s2s:showcert()
Kim Alvefur <zash@zash.se>
parents:
5674
diff
changeset
|
686 local s2s_sessions = module:shared"/*/s2s/sessions"; |
896094da72e4
mod_admin_telnet: Refactor s2s:showcert()
Kim Alvefur <zash@zash.se>
parents:
5674
diff
changeset
|
687 local domain_sessions = set.new(array.collect(values(s2s_sessions))) |
896094da72e4
mod_admin_telnet: Refactor s2s:showcert()
Kim Alvefur <zash@zash.se>
parents:
5674
diff
changeset
|
688 /function(session) return (session.to_host == domain or session.from_host == domain) and session or nil; end; |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
689 local cert_set = {}; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
690 for session in domain_sessions do |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
691 local conn = session.conn; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
692 conn = conn and conn:socket(); |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
693 if not conn.getpeerchain then |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
694 if conn.dohandshake then |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
695 error("This version of LuaSec does not support certificate viewing"); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
696 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
697 else |
5596
73fea1a87afd
mod_admin_telnet: Don't rely on getpeerchain returning an empty list
Kim Alvefur <zash@zash.se>
parents:
5567
diff
changeset
|
698 local cert = conn:getpeercertificate(); |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
699 if cert then |
5596
73fea1a87afd
mod_admin_telnet: Don't rely on getpeerchain returning an empty list
Kim Alvefur <zash@zash.se>
parents:
5567
diff
changeset
|
700 local certs = conn:getpeerchain(); |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
701 local digest = cert:digest("sha1"); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
702 if not cert_set[digest] then |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
703 local chain_valid, chain_errors = conn:getpeerverification(); |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
704 cert_set[digest] = { |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
705 { |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
706 from = session.from_host, |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
707 to = session.to_host, |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
708 direction = session.direction |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
709 }; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
710 chain_valid = chain_valid; |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
711 chain_errors = chain_errors; |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
712 certs = certs; |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
713 }; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
714 else |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
715 table.insert(cert_set[digest], { |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
716 from = session.from_host, |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
717 to = session.to_host, |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
718 direction = session.direction |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
719 }); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
720 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
721 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
722 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
723 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
724 local domain_certs = array.collect(values(cert_set)); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
725 -- Phew. We now have a array of unique certificates presented by domain. |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
726 local n_certs = #domain_certs; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
727 |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
728 if n_certs == 0 then |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
729 return "No certificates found for "..domain; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
730 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
731 |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
732 local function _capitalize_and_colon(byte) |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
733 return string.upper(byte)..":"; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
734 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
735 local function pretty_fingerprint(hash) |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
736 return hash:gsub("..", _capitalize_and_colon):sub(1, -2); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
737 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
738 |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
739 for cert_info in values(domain_certs) do |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
740 local certs = cert_info.certs; |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
741 local cert = certs[1]; |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
742 print("---") |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
743 print("Fingerprint (SHA1): "..pretty_fingerprint(cert:digest("sha1"))); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
744 print(""); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
745 local n_streams = #cert_info; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
746 print("Currently used on "..n_streams.." stream"..(n_streams==1 and "" or "s")..":"); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
747 for _, stream in ipairs(cert_info) do |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
748 if stream.direction == "incoming" then |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
749 print(" "..stream.to.." <- "..stream.from); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
750 else |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
751 print(" "..stream.from.." -> "..stream.to); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
752 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
753 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
754 print(""); |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
755 local chain_valid, errors = cert_info.chain_valid, cert_info.chain_errors; |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
756 local valid_identity = cert_verify_identity(domain, "xmpp-server", cert); |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
757 if chain_valid then |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
758 print("Trusted certificate: Yes"); |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
759 else |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
760 print("Trusted certificate: No"); |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
761 print_errors(print, errors); |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
762 end |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
763 print(""); |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
764 print("Issuer: "); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
765 print_subject(print, cert:issuer()); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
766 print(""); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
767 print("Valid for "..domain..": "..(valid_identity and "Yes" or "No")); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
768 print("Subject:"); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
769 print_subject(print, cert:subject()); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
770 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
771 print("---"); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
772 return ("Showing "..n_certs.." certificate" |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
773 ..(n_certs==1 and "" or "s") |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
774 .." presented by "..domain.."."); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
775 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
776 |
1340
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
777 function def_env.s2s:close(from, to) |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
778 local print, count = self.session.print, 0; |
5708
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
779 local s2s_sessions = module:shared"/*/s2s/sessions"; |
1340
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
780 |
5708
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
781 local match_id; |
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
782 if from and not to then |
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
783 match_id, from = from; |
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
784 elseif not to then |
1340
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
785 return false, "Syntax: s2s:close('from', 'to') - Closes all s2s sessions from 'from' to 'to'"; |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
786 elseif from == to then |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
787 return false, "Both from and to are the same... you can't do that :)"; |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
788 end |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
789 |
5708
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
790 for _, session in pairs(s2s_sessions) do |
5709
5557b4a4cb49
mod_admin_telnet: Generate session names the same way as in s2smanager
Kim Alvefur <zash@zash.se>
parents:
5708
diff
changeset
|
791 local id = session.type..tostring(session):match("[a-f0-9]+$"); |
5708
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
792 if (match_id and match_id == id) |
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
793 or (session.from_host == from and session.to_host == to) then |
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
794 print(("Closing connection from %s to %s [%s]"):format(session.from_host, session.to_host, id)); |
1821
05ed826da89b
mod_console: s2s:close: Use session:close() if that exists, otherwise just destroy the session
Matthew Wild <mwild1@gmail.com>
parents:
1798
diff
changeset
|
795 (session.close or s2smanager.destroy_session)(session); |
5708
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
796 count = count + 1 ; |
1340
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
797 end |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
798 end |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
799 return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
800 end |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
801 |
4978
0b9e86302de4
mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents:
4913
diff
changeset
|
802 function def_env.s2s:closeall(host) |
0b9e86302de4
mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents:
4913
diff
changeset
|
803 local count = 0; |
5708
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
804 local s2s_sessions = module:shared"/*/s2s/sessions"; |
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
805 for _,session in pairs(s2s_sessions) do |
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
806 if not host or session.from_host == host or session.to_host == host then |
667cf4e45356
mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents:
5706
diff
changeset
|
807 session:close(); |
4978
0b9e86302de4
mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents:
4913
diff
changeset
|
808 count = count + 1; |
0b9e86302de4
mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents:
4913
diff
changeset
|
809 end |
0b9e86302de4
mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents:
4913
diff
changeset
|
810 end |
0b9e86302de4
mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents:
4913
diff
changeset
|
811 if count == 0 then return false, "No sessions to close."; |
0b9e86302de4
mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents:
4913
diff
changeset
|
812 else return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); end |
0b9e86302de4
mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents:
4913
diff
changeset
|
813 end |
0b9e86302de4
mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents:
4913
diff
changeset
|
814 |
1977
325a49f8edab
mod_console: Add commands host:activate(host, config) and host:deactivate(host, reason) to add/remove hosts at runtime
Matthew Wild <mwild1@gmail.com>
parents:
1927
diff
changeset
|
815 def_env.host = {}; def_env.hosts = def_env.host; |
3840
abcbce5e4240
mod_console: Removed redundant code for host:activate() and host:deactivate(), now that hostmanager has error checking.
Waqas Hussain <waqas20@gmail.com>
parents:
3614
diff
changeset
|
816 |
1977
325a49f8edab
mod_console: Add commands host:activate(host, config) and host:deactivate(host, reason) to add/remove hosts at runtime
Matthew Wild <mwild1@gmail.com>
parents:
1927
diff
changeset
|
817 function def_env.host:activate(hostname, config) |
3840
abcbce5e4240
mod_console: Removed redundant code for host:activate() and host:deactivate(), now that hostmanager has error checking.
Waqas Hussain <waqas20@gmail.com>
parents:
3614
diff
changeset
|
818 return hostmanager.activate(hostname, config); |
1977
325a49f8edab
mod_console: Add commands host:activate(host, config) and host:deactivate(host, reason) to add/remove hosts at runtime
Matthew Wild <mwild1@gmail.com>
parents:
1927
diff
changeset
|
819 end |
325a49f8edab
mod_console: Add commands host:activate(host, config) and host:deactivate(host, reason) to add/remove hosts at runtime
Matthew Wild <mwild1@gmail.com>
parents:
1927
diff
changeset
|
820 function def_env.host:deactivate(hostname, reason) |
3840
abcbce5e4240
mod_console: Removed redundant code for host:activate() and host:deactivate(), now that hostmanager has error checking.
Waqas Hussain <waqas20@gmail.com>
parents:
3614
diff
changeset
|
821 return hostmanager.deactivate(hostname, reason); |
1977
325a49f8edab
mod_console: Add commands host:activate(host, config) and host:deactivate(host, reason) to add/remove hosts at runtime
Matthew Wild <mwild1@gmail.com>
parents:
1927
diff
changeset
|
822 end |
325a49f8edab
mod_console: Add commands host:activate(host, config) and host:deactivate(host, reason) to add/remove hosts at runtime
Matthew Wild <mwild1@gmail.com>
parents:
1927
diff
changeset
|
823 |
2007
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
824 function def_env.host:list() |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
825 local print = self.session.print; |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
826 local i = 0; |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
827 for host in values(array.collect(keys(prosody.hosts)):sort()) do |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
828 i = i + 1; |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
829 print(host); |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
830 end |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
831 return true, i.." hosts"; |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
832 end |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
833 |
4674
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
834 def_env.port = {}; |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
835 |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
836 function def_env.port:list() |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
837 local print = self.session.print; |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
838 local services = portmanager.get_active_services().data; |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
839 local ordered_services, n_ports = {}, 0; |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
840 for service, interfaces in pairs(services) do |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
841 table.insert(ordered_services, service); |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
842 end |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
843 table.sort(ordered_services); |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
844 for _, service in ipairs(ordered_services) do |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
845 local ports_list = {}; |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
846 for interface, ports in pairs(services[service]) do |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
847 for port in pairs(ports) do |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
848 table.insert(ports_list, "["..interface.."]:"..port); |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
849 end |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
850 end |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
851 n_ports = n_ports + #ports_list; |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
852 print(service..": "..table.concat(ports_list, ", ")); |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
853 end |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
854 return true, #ordered_services.." services listening on "..n_ports.." ports"; |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
855 end |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
856 |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
857 function def_env.port:close(close_port, close_interface) |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
858 close_port = assert(tonumber(close_port), "Invalid port number"); |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
859 local n_closed = 0; |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
860 local services = portmanager.get_active_services().data; |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
861 for service, interfaces in pairs(services) do |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
862 for interface, ports in pairs(interfaces) do |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
863 if not close_interface or close_interface == interface then |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
864 if ports[close_port] then |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
865 self.session.print("Closing ["..interface.."]:"..close_port.."..."); |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
866 local ok, err = portmanager.close(interface, close_port) |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
867 if not ok then |
5029
7bcd79631492
mod_admin_telnet: Fix usage of incorrect variable
Matthew Wild <mwild1@gmail.com>
parents:
5028
diff
changeset
|
868 self.session.print("Failed to close "..interface.." "..close_port..": "..err); |
4674
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
869 else |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
870 n_closed = n_closed + 1; |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
871 end |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
872 end |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
873 end |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
874 end |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
875 end |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
876 return true, "Closed "..n_closed.." ports"; |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
877 end |
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
878 |
4807
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
879 def_env.muc = {}; |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
880 |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
881 local console_room_mt = { |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
882 __index = function (self, k) return self.room[k]; end; |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
883 __tostring = function (self) |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
884 return "MUC room <"..self.room.jid..">"; |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
885 end; |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
886 }; |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
887 |
5520
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
888 local function check_muc(jid) |
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
889 local room_name, host = jid_split(jid); |
4807
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
890 if not hosts[host] then |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
891 return nil, "No such host: "..host; |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
892 elseif not hosts[host].modules.muc then |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
893 return nil, "Host '"..host.."' is not a MUC service"; |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
894 end |
5520
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
895 return room_name, host; |
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
896 end |
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
897 |
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
898 function def_env.muc:create(room_jid) |
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
899 local room, host = check_muc(room_jid); |
5630
5f3c0b11aa88
mod_admin_telnet: Make the muc:create() command complain if the room already exists
Kim Alvefur <zash@zash.se>
parents:
5598
diff
changeset
|
900 if not room then return nil, host end |
5f3c0b11aa88
mod_admin_telnet: Make the muc:create() command complain if the room already exists
Kim Alvefur <zash@zash.se>
parents:
5598
diff
changeset
|
901 if hosts[host].modules.muc.rooms[room_jid] then return nil, "Room exists already" end |
5520
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
902 return hosts[host].modules.muc.create_room(room_jid); |
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
903 end |
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
904 |
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
905 function def_env.muc:room(room_jid) |
75230be5be58
mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents:
5278
diff
changeset
|
906 local room_name, host = check_muc(room_jid); |
4807
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
907 local room_obj = hosts[host].modules.muc.rooms[room_jid]; |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
908 if not room_obj then |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
909 return nil, "No such room: "..room_jid; |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
910 end |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
911 return setmetatable({ room = room_obj }, console_room_mt); |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
912 end |
2999f0fd1347
mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents:
4779
diff
changeset
|
913 |
5006
af7e563cf453
mod_admin_telnet: Add missing import of usermanager
Kim Alvefur <zash@zash.se>
parents:
5005
diff
changeset
|
914 local um = require"core.usermanager"; |
af7e563cf453
mod_admin_telnet: Add missing import of usermanager
Kim Alvefur <zash@zash.se>
parents:
5005
diff
changeset
|
915 |
4973
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
916 def_env.user = {}; |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
917 function def_env.user:create(jid, password) |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
918 local username, host = jid_split(jid); |
5598
3bb8aefd8ce0
mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
Kim Alvefur <zash@zash.se>
parents:
5596
diff
changeset
|
919 if not hosts[host] then |
3bb8aefd8ce0
mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
Kim Alvefur <zash@zash.se>
parents:
5596
diff
changeset
|
920 return nil, "No such host: "..host; |
3bb8aefd8ce0
mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
Kim Alvefur <zash@zash.se>
parents:
5596
diff
changeset
|
921 elseif um.user_exists(username, host) then |
5128
834ab74585ec
mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents:
5030
diff
changeset
|
922 return nil, "User exists"; |
834ab74585ec
mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents:
5030
diff
changeset
|
923 end |
4973
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
924 local ok, err = um.create_user(username, password, host); |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
925 if ok then |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
926 return true, "User created"; |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
927 else |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
928 return nil, "Could not create user: "..err; |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
929 end |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
930 end |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
931 |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
932 function def_env.user:delete(jid) |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
933 local username, host = jid_split(jid); |
5598
3bb8aefd8ce0
mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
Kim Alvefur <zash@zash.se>
parents:
5596
diff
changeset
|
934 if not hosts[host] then |
3bb8aefd8ce0
mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
Kim Alvefur <zash@zash.se>
parents:
5596
diff
changeset
|
935 return nil, "No such host: "..host; |
5643
e612e1887e39
mod_admin_telnet: Fix inverted boolean logic
Kim Alvefur <zash@zash.se>
parents:
5630
diff
changeset
|
936 elseif not um.user_exists(username, host) then |
5128
834ab74585ec
mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents:
5030
diff
changeset
|
937 return nil, "No such user"; |
834ab74585ec
mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents:
5030
diff
changeset
|
938 end |
4973
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
939 local ok, err = um.delete_user(username, host); |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
940 if ok then |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
941 return true, "User deleted"; |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
942 else |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
943 return nil, "Could not delete user: "..err; |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
944 end |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
945 end |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
946 |
5128
834ab74585ec
mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents:
5030
diff
changeset
|
947 function def_env.user:password(jid, password) |
4973
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
948 local username, host = jid_split(jid); |
5598
3bb8aefd8ce0
mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
Kim Alvefur <zash@zash.se>
parents:
5596
diff
changeset
|
949 if not hosts[host] then |
3bb8aefd8ce0
mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
Kim Alvefur <zash@zash.se>
parents:
5596
diff
changeset
|
950 return nil, "No such host: "..host; |
5665
da1881e1b35b
mod_admin_telnet: Fix another wrong boolean expression
Kim Alvefur <zash@zash.se>
parents:
5643
diff
changeset
|
951 elseif not um.user_exists(username, host) then |
5128
834ab74585ec
mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents:
5030
diff
changeset
|
952 return nil, "No such user"; |
834ab74585ec
mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents:
5030
diff
changeset
|
953 end |
4973
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
954 local ok, err = um.set_password(username, password, host); |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
955 if ok then |
5128
834ab74585ec
mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents:
5030
diff
changeset
|
956 return true, "User password changed"; |
4973
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
957 else |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
958 return nil, "Could not change password for user: "..err; |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
959 end |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
960 end |
3f7248ac1a3b
mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents:
4913
diff
changeset
|
961 |
5168
46fc0eff10b4
mod_admin_telnet: user:list(): Allow filtering the set of users
Kim Alvefur <zash@zash.se>
parents:
5167
diff
changeset
|
962 function def_env.user:list(host, pat) |
5158
c363e7e77f79
mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
963 if not host then |
c363e7e77f79
mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
964 return nil, "No host given"; |
5167
ecd9e300ec94
mod_admin_telnet: user:list() check that the given host exists
Kim Alvefur <zash@zash.se>
parents:
5159
diff
changeset
|
965 elseif not hosts[host] then |
ecd9e300ec94
mod_admin_telnet: user:list() check that the given host exists
Kim Alvefur <zash@zash.se>
parents:
5159
diff
changeset
|
966 return nil, "No such host"; |
5158
c363e7e77f79
mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
967 end |
c363e7e77f79
mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
968 local print = self.session.print; |
5227
97f395938028
mod_admin_telnet: Improve wording when listing users
Kim Alvefur <zash@zash.se>
parents:
5186
diff
changeset
|
969 local total, matches = 0, 0; |
5158
c363e7e77f79
mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
970 for user in um.users(host) do |
5168
46fc0eff10b4
mod_admin_telnet: user:list(): Allow filtering the set of users
Kim Alvefur <zash@zash.se>
parents:
5167
diff
changeset
|
971 if not pat or user:match(pat) then |
46fc0eff10b4
mod_admin_telnet: user:list(): Allow filtering the set of users
Kim Alvefur <zash@zash.se>
parents:
5167
diff
changeset
|
972 print(user.."@"..host); |
5227
97f395938028
mod_admin_telnet: Improve wording when listing users
Kim Alvefur <zash@zash.se>
parents:
5186
diff
changeset
|
973 matches = matches + 1; |
5168
46fc0eff10b4
mod_admin_telnet: user:list(): Allow filtering the set of users
Kim Alvefur <zash@zash.se>
parents:
5167
diff
changeset
|
974 end |
5227
97f395938028
mod_admin_telnet: Improve wording when listing users
Kim Alvefur <zash@zash.se>
parents:
5186
diff
changeset
|
975 total = total + 1; |
5158
c363e7e77f79
mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
976 end |
5227
97f395938028
mod_admin_telnet: Improve wording when listing users
Kim Alvefur <zash@zash.se>
parents:
5186
diff
changeset
|
977 return true, "Showing "..(pat and (matches.." of ") or "all " )..total.." users"; |
5158
c363e7e77f79
mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
978 end |
c363e7e77f79
mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents:
5133
diff
changeset
|
979 |
5011
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
980 def_env.xmpp = {}; |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
981 |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
982 local st = require "util.stanza"; |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
983 function def_env.xmpp:ping(localhost, remotehost) |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
984 if hosts[localhost] then |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
985 core_post_stanza(hosts[localhost], |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
986 st.iq{ from=localhost, to=remotehost, type="get", id="ping" } |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
987 :tag("ping", {xmlns="urn:xmpp:ping"})); |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
988 return true, "Sent ping"; |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
989 else |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
990 return nil, "No such host"; |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
991 end |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
992 end |
83b4d3727b4f
mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents:
5007
diff
changeset
|
993 |
5567
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
994 def_env.dns = {}; |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
995 local adns = require"net.adns"; |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
996 local dns = require"net.dns"; |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
997 |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
998 function def_env.dns:lookup(name, typ, class) |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
999 local ret = "Query sent"; |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1000 local print = self.session.print; |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1001 local function handler(...) |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1002 ret = "Got response"; |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1003 print(...); |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1004 end |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1005 adns.lookup(handler, name, typ, class); |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1006 return true, ret; |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1007 end |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1008 |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1009 function def_env.dns:addnameserver(...) |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1010 dns.addnameserver(...) |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1011 return true |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1012 end |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1013 |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1014 function def_env.dns:setnameserver(...) |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1015 dns.setnameserver(...) |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1016 return true |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1017 end |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1018 |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1019 function def_env.dns:purge() |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1020 dns.purge() |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1021 return true |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1022 end |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1023 |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1024 function def_env.dns:cache() |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1025 return true, "Cache:\n"..tostring(dns.cache()) |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1026 end |
c4ab25b35a55
mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents:
5520
diff
changeset
|
1027 |
736 | 1028 ------------- |
1029 | |
1030 function printbanner(session) | |
5025
e68d1b85ee3a
mod_admin_telnet: Use module:get_option() instead of configmanager directly
Matthew Wild <mwild1@gmail.com>
parents:
5024
diff
changeset
|
1031 local option = module:get_option("console_banner"); |
5026
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1032 if option == nil or option == "full" or option == "graphic" then |
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1033 session.print [[ |
736 | 1034 ____ \ / _ |
1035 | _ \ _ __ ___ ___ _-_ __| |_ _ | |
1036 | |_) | '__/ _ \/ __|/ _ \ / _` | | | | | |
1037 | __/| | | (_) \__ \ |_| | (_| | |_| | | |
1038 |_| |_| \___/|___/\___/ \__,_|\__, | | |
1039 A study in simplicity |___/ | |
1040 | |
1041 ]] | |
5026
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1042 end |
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1043 if option == nil or option == "short" or option == "full" then |
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1044 session.print("Welcome to the Prosody administration console. For a list of commands, type: help"); |
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1045 session.print("You may find more help on using this console in our online documentation at "); |
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1046 session.print("http://prosody.im/doc/console\n"); |
1483
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
1047 end |
5026
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1048 if option and option ~= "short" and option ~= "full" and option ~= "graphic" then |
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1049 if type(option) == "string" then |
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1050 session.print(option) |
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1051 elseif type(option) == "function" then |
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1052 module:log("warn", "Using functions as value for the console_banner option is no longer supported"); |
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1053 end |
c86a14414922
mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents:
5025
diff
changeset
|
1054 end |
1483
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
1055 end |
2087
5efd79871205
mod_console: Moved activation of the console port from the main file to mod_console.
Waqas Hussain <waqas20@gmail.com>
parents:
2054
diff
changeset
|
1056 |
5120
bcabea740c00
mod_{admin_telnet,c2s,component,http,net_multiplex,s2s}: Use module:provides() instead of module:add_item().
Waqas Hussain <waqas20@gmail.com>
parents:
5030
diff
changeset
|
1057 module:provides("net", { |
4674
f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents:
4647
diff
changeset
|
1058 name = "console"; |
4550
1c41e4a846a2
mod_admin_telnet: Port to portmanager
Matthew Wild <mwild1@gmail.com>
parents:
4540
diff
changeset
|
1059 listener = console_listener; |
1c41e4a846a2
mod_admin_telnet: Port to portmanager
Matthew Wild <mwild1@gmail.com>
parents:
4540
diff
changeset
|
1060 default_port = 5582; |
4571
32d532b95dc7
mod_admin_telnet: make service private.
Marco Cirillo <maranda@lightwitch.org>
parents:
4550
diff
changeset
|
1061 private = true; |
4550
1c41e4a846a2
mod_admin_telnet: Port to portmanager
Matthew Wild <mwild1@gmail.com>
parents:
4540
diff
changeset
|
1062 }); |