Software /
code /
prosody
Annotate
plugins/mod_admin_telnet.lua @ 4550:1c41e4a846a2
mod_admin_telnet: Port to portmanager
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 23 Jan 2012 01:05:32 +0000 |
parent | 4540:ddce5b1bdfca |
child | 4571:32d532b95dc7 |
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 |
736 | 9 module.host = "*"; |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
461
diff
changeset
|
10 |
1342
947d94e3619f
mod_console: Redirect print() to console session when executing commands in global environment
Matthew Wild <mwild1@gmail.com>
parents:
1341
diff
changeset
|
11 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
|
12 |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
13 local prosody = _G.prosody; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
14 local hosts = prosody.hosts; |
736 | 15 |
4550
1c41e4a846a2
mod_admin_telnet: Port to portmanager
Matthew Wild <mwild1@gmail.com>
parents:
4540
diff
changeset
|
16 local console_listener = { default_port = 5582; default_mode = "*l"; interface = "127.0.0.1" }; |
736 | 17 |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
18 require "util.iterators"; |
1491
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
19 local jid_bare = require "util.jid".bare; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
20 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
|
21 local cert_verify_identity = require "util.x509".verify_identity; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
22 |
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
|
23 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
|
24 local def_env = module:shared("env"); |
736 | 25 local default_env_mt = { __index = def_env }; |
26 | |
1342
947d94e3619f
mod_console: Redirect print() to console session when executing commands in global environment
Matthew Wild <mwild1@gmail.com>
parents:
1341
diff
changeset
|
27 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
|
28 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
|
29 env.dofile = function(name) |
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
|
30 local f, err = loadfile(name); |
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
|
31 if not f then return f, err; 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
|
32 return setfenv(f, env)(); |
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
|
33 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
|
34 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
|
35 end |
947d94e3619f
mod_console: Redirect print() to console session when executing commands in global environment
Matthew Wild <mwild1@gmail.com>
parents:
1341
diff
changeset
|
36 |
736 | 37 console = {}; |
38 | |
39 function console:new_session(conn) | |
2145
daeb6ebf304c
mod_console: Update for new net.server API
Matthew Wild <mwild1@gmail.com>
parents:
2087
diff
changeset
|
40 local w = function(s) conn:write(s:gsub("\n", "\r\n")); end; |
736 | 41 local session = { conn = conn; |
42 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
|
43 print = function (...) |
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
44 local t = {}; |
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
45 for i=1,select("#", ...) do |
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
46 t[i] = tostring(select(i, ...)); |
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
47 end |
33c81ee280e3
mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents:
3044
diff
changeset
|
48 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
|
49 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
|
50 disconnect = function () conn:close(); end; |
736 | 51 }; |
52 session.env = setmetatable({}, default_env_mt); | |
53 | |
54 -- Load up environment with helper objects | |
55 for name, t in pairs(def_env) do | |
56 if type(t) == "table" then | |
57 session.env[name] = setmetatable({ session = session }, { __index = t }); | |
58 end | |
59 end | |
60 | |
61 return session; | |
62 end | |
63 | |
64 local sessions = {}; | |
65 | |
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
|
66 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
|
67 -- 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
|
68 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
|
69 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
|
70 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
|
71 session.send(string.char(0)); |
736 | 72 end |
73 | |
2145
daeb6ebf304c
mod_console: Update for new net.server API
Matthew Wild <mwild1@gmail.com>
parents:
2087
diff
changeset
|
74 function console_listener.onincoming(conn, data) |
736 | 75 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
|
76 |
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
|
77 -- Handle data |
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
|
78 (function(session, data) |
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
|
79 local useglobalenv; |
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
|
80 |
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
|
81 if data:match("^>") then |
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
|
82 data = data:gsub("^>", ""); |
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
|
83 useglobalenv = true; |
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
|
84 elseif data == "\004" then |
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
|
85 commands["bye"](session, data); |
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
|
86 return; |
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
|
87 else |
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
|
88 local command = data:lower(); |
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
|
89 command = data:match("^%w+") or data:match("%p"); |
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
|
90 if commands[command] then |
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
|
91 commands[command](session, data); |
1502
0f895c06e03f
mod_console: Check for commands when not executing in the global environment
Matthew Wild <mwild1@gmail.com>
parents:
1496
diff
changeset
|
92 return; |
0f895c06e03f
mod_console: Check for commands when not executing in the global environment
Matthew Wild <mwild1@gmail.com>
parents:
1496
diff
changeset
|
93 end |
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
|
94 end |
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
|
95 |
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
|
96 session.env._ = data; |
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
|
97 |
3028 | 98 local chunkname = "=console"; |
99 local chunk, err = loadstring("return "..data, chunkname); | |
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
|
100 if not chunk then |
3028 | 101 chunk, err = loadstring(data, chunkname); |
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
|
102 if not chunk then |
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
|
103 err = err:gsub("^%[string .-%]:%d+: ", ""); |
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
|
104 err = err:gsub("^:%d+: ", ""); |
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
|
105 err = err:gsub("'<eof>'", "the end of the line"); |
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
|
106 session.print("Sorry, I couldn't understand that... "..err); |
736 | 107 return; |
108 end | |
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
|
109 end |
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
|
110 |
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
|
111 setfenv(chunk, (useglobalenv and redirect_output(_G, session)) or session.env or nil); |
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
|
112 |
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
|
113 local ranok, taskok, message = pcall(chunk); |
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
|
114 |
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
|
115 if not (ranok or message or useglobalenv) and commands[data:lower()] then |
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
|
116 commands[data:lower()](session, data); |
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
|
117 return; |
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
|
118 end |
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
|
119 |
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
|
120 if not ranok then |
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
|
121 session.print("Fatal error while running command, it did not complete"); |
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
|
122 session.print("Error: "..taskok); |
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
|
123 return; |
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
|
124 end |
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
|
125 |
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
|
126 if not message then |
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
|
127 session.print("Result: "..tostring(taskok)); |
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
|
128 return; |
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
|
129 elseif (not taskok) and message then |
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
|
130 session.print("Command completed with a problem"); |
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
|
131 session.print("Message: "..tostring(message)); |
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
|
132 return; |
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
|
133 end |
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 |
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 session.print("OK: "..tostring(message)); |
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 end)(session, data); |
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 |
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
|
138 session.send(string.char(0)); |
736 | 139 end |
140 | |
2145
daeb6ebf304c
mod_console: Update for new net.server API
Matthew Wild <mwild1@gmail.com>
parents:
2087
diff
changeset
|
141 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
|
142 local session = sessions[conn]; |
a43aea9b0bd1
mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents:
2010
diff
changeset
|
143 if session then |
a43aea9b0bd1
mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents:
2010
diff
changeset
|
144 session.disconnect(); |
a43aea9b0bd1
mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents:
2010
diff
changeset
|
145 sessions[conn] = nil; |
a43aea9b0bd1
mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents:
2010
diff
changeset
|
146 end |
736 | 147 end |
148 | |
149 -- Console commands -- | |
150 -- These are simple commands, not valid standalone in Lua | |
151 | |
152 function commands.bye(session) | |
153 session.print("See you! :)"); | |
154 session.disconnect(); | |
155 end | |
1503
5970e06d9335
mod_console: Add quit and exit as aliases for 'bye' command
Matthew Wild <mwild1@gmail.com>
parents:
1502
diff
changeset
|
156 commands.quit, commands.exit = commands.bye, commands.bye; |
736 | 157 |
158 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
|
159 if data:match("^!!") and session.env._ then |
736 | 160 session.print("!> "..session.env._); |
2512
d04b0eeeb954
mod_console: Update !! shortcut for new connection API
Matthew Wild <mwild1@gmail.com>
parents:
2296
diff
changeset
|
161 return console_listener.onincoming(session.conn, session.env._); |
736 | 162 end |
163 local old, new = data:match("^!(.-[^\\])!(.-)!$"); | |
164 if old and new then | |
165 local ok, res = pcall(string.gsub, session.env._, old, new); | |
166 if not ok then | |
167 session.print(res) | |
168 return; | |
169 end | |
170 session.print("!> "..res); | |
2512
d04b0eeeb954
mod_console: Update !! shortcut for new connection API
Matthew Wild <mwild1@gmail.com>
parents:
2296
diff
changeset
|
171 return console_listener.onincoming(session.conn, res); |
736 | 172 end |
173 session.print("Sorry, not sure what you want"); | |
174 end | |
175 | |
3452
2d1a5d8893c2
mod_console: Add host:* commands to help (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
3407
diff
changeset
|
176 |
1616
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
177 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
|
178 local print = session.print; |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
179 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
|
180 if not section then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
181 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
|
182 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
|
183 print [[]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 print [[host - Commands to activate, deactivate and list virtual hosts]] |
1616
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
188 print [[server - Uptime, version, shutting down, etc.]] |
2009
3f9cce29c57d
mod_console: Added help text for config:reload().
Waqas Hussain <waqas20@gmail.com>
parents:
2007
diff
changeset
|
189 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
|
190 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
|
191 elseif section == "c2s" then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 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
|
196 elseif section == "s2s" then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
197 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
|
198 print [[s2s:close(from, to) - Close a connection from one domain to another]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
199 elseif section == "module" then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 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
|
204 elseif section == "host" then |
2d1a5d8893c2
mod_console: Add host:* commands to help (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
3407
diff
changeset
|
205 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
|
206 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
|
207 print [[host:list() - List the currently-activated hosts]] |
1616
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
208 elseif section == "server" then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
209 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
|
210 print [[server:uptime() - Show how long the server has been running]] |
2870
471c3acffb2a
mod_console: Uncomment the help for server:shutdown() - thanks darkrain
Matthew Wild <mwild1@gmail.com>
parents:
2087
diff
changeset
|
211 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] |
2009
3f9cce29c57d
mod_console: Added help text for config:reload().
Waqas Hussain <waqas20@gmail.com>
parents:
2007
diff
changeset
|
212 elseif section == "config" then |
3f9cce29c57d
mod_console: Added help text for config:reload().
Waqas Hussain <waqas20@gmail.com>
parents:
2007
diff
changeset
|
213 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
|
214 elseif section == "console" then |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
215 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
|
216 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
|
217 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
|
218 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
|
219 print [[]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
220 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
|
221 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
|
222 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
|
223 print [[]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 end |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
228 print [[]] |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
229 end |
80ea744f2643
mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents:
1575
diff
changeset
|
230 |
736 | 231 -- Session environment -- |
232 -- Anything in def_env will be accessible within the session as a global variable | |
233 | |
234 def_env.server = {}; | |
1558
e15917530285
mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents:
1556
diff
changeset
|
235 |
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
|
236 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
|
237 prosody.unlock_globals(); |
736 | 238 dofile "prosody" |
1316
28ae044f1aaf
mod_console: Some "improvements" to the useless server:reload() command :)
Matthew Wild <mwild1@gmail.com>
parents:
1315
diff
changeset
|
239 prosody = _G.prosody; |
736 | 240 return true, "Server reloaded"; |
241 end | |
242 | |
1496
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
243 function def_env.server:version() |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
244 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
|
245 end |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
246 |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
247 function def_env.server:uptime() |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
248 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
|
249 local seconds = t%60; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
250 t = (t - seconds)/60; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
251 local minutes = t%60; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
252 t = (t - minutes)/60; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
253 local hours = t%24; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
254 t = (t - hours)/24; |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
255 local days = t; |
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3452
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 end |
4fa337035f46
mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents:
1491
diff
changeset
|
260 |
1559
831649bb1922
mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents:
1558
diff
changeset
|
261 function def_env.server:shutdown(reason) |
831649bb1922
mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents:
1558
diff
changeset
|
262 prosody.shutdown(reason); |
831649bb1922
mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents:
1558
diff
changeset
|
263 return true, "Shutdown initiated"; |
831649bb1922
mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents:
1558
diff
changeset
|
264 end |
831649bb1922
mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents:
1558
diff
changeset
|
265 |
736 | 266 def_env.module = {}; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
267 |
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
|
268 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
|
269 if type(hosts) == "table" then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
270 if hosts[1] then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
271 return set.new(hosts); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
272 elseif hosts._items then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
273 return hosts; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
274 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
275 elseif type(hosts) == "string" then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
276 return set.new { hosts }; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
277 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
|
278 local mm = require "modulemanager"; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
279 return set.new(array.collect(keys(prosody.hosts))) |
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
|
280 / function (host) return prosody.hosts[host].type == "local" or module and mm.is_loaded(host, module); end; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
281 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
282 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
283 |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
284 function def_env.module:load(name, hosts, config) |
736 | 285 local mm = require "modulemanager"; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
286 |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
287 hosts = get_hosts_set(hosts); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
288 |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
289 -- Load the module for each host |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
290 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
|
291 for host in hosts do |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
292 if (not 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
|
293 ok, err = mm.load(host, name, config); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
294 if not ok then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
295 ok = false; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
296 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
|
297 else |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
298 count = count + 1; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
299 self.session.print("Loaded for "..host); |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
300 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
301 end |
736 | 302 end |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
303 |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
304 return ok, (ok and "Module loaded onto "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); |
736 | 305 end |
306 | |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
307 function def_env.module:unload(name, hosts) |
712
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
308 local mm = require "modulemanager"; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
309 |
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
|
310 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
|
311 |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
312 -- 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
|
313 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
|
314 for host in hosts do |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
315 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
|
316 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
|
317 if not ok then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
318 ok = false; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
319 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
|
320 else |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
321 count = count + 1; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
322 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
|
323 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
324 end |
712
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
325 end |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
326 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
|
327 end |
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
328 |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
329 function def_env.module:reload(name, hosts) |
712
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
330 local mm = require "modulemanager"; |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
331 |
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
|
332 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
|
333 |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
334 -- 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
|
335 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
|
336 for host in hosts do |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
337 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
|
338 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
|
339 if not ok then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
340 ok = false; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
341 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
|
342 else |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
343 count = count + 1; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
344 if ok == nil then |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
345 ok = true; |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
346 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
347 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
|
348 end |
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
349 end |
712
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
350 end |
1315
bfcd3f0a49df
mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents:
1241
diff
changeset
|
351 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
|
352 end |
56410c0cd846
mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents:
669
diff
changeset
|
353 |
1906
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
354 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
|
355 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
|
356 hosts = array.collect(keys(prosody.hosts)); |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
357 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
358 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
|
359 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
|
360 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
361 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
|
362 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
|
363 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
364 |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
365 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
|
366 for _, host in ipairs(hosts) do |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
367 print(host..":"); |
2010
1a4f14ea39b6
mod_console: Fixed traceback occuring on using module:list on unknown hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2009
diff
changeset
|
368 local modules = array.collect(keys(prosody.hosts[host] and prosody.hosts[host].modules 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
|
369 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
|
370 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
|
371 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
|
372 else |
1a4f14ea39b6
mod_console: Fixed traceback occuring on using module:list on unknown hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2009
diff
changeset
|
373 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
|
374 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
|
375 else |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
376 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
|
377 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
|
378 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
379 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
380 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
381 end |
88c61368e669
mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
1821
diff
changeset
|
382 |
736 | 383 def_env.config = {}; |
384 function def_env.config:load(filename, format) | |
385 local config_load = require "core.configmanager".load; | |
386 local ok, err = config_load(filename, format); | |
387 if not ok then | |
388 return false, err or "Unknown error loading config"; | |
389 end | |
390 return true, "Config loaded"; | |
391 end | |
392 | |
393 function def_env.config:get(host, section, key) | |
394 local config_get = require "core.configmanager".get | |
395 return true, tostring(config_get(host, section, key)); | |
396 end | |
397 | |
1558
e15917530285
mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents:
1556
diff
changeset
|
398 function def_env.config:reload() |
e15917530285
mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents:
1556
diff
changeset
|
399 local ok, err = prosody.reload_config(); |
e15917530285
mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents:
1556
diff
changeset
|
400 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
|
401 end |
e15917530285
mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents:
1556
diff
changeset
|
402 |
736 | 403 def_env.hosts = {}; |
404 function def_env.hosts:list() | |
405 for host, host_session in pairs(hosts) do | |
406 self.session.print(host); | |
407 end | |
408 return true, "Done"; | |
409 end | |
410 | |
411 function def_env.hosts:add(name) | |
412 end | |
413 | |
1241
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
414 def_env.c2s = {}; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
415 |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
416 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 callback(jid, session); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
422 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
423 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
424 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
425 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
426 |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
427 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
|
428 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
|
429 local curr_host; |
1798
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
430 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
|
431 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
|
432 curr_host = session.host; |
9e4ff3b66ed1
mod_console: c2s:show(): Group listed clients by host
Matthew Wild <mwild1@gmail.com>
parents:
1623
diff
changeset
|
433 print(curr_host); |
9e4ff3b66ed1
mod_console: c2s:show(): Group listed clients by host
Matthew Wild <mwild1@gmail.com>
parents:
1623
diff
changeset
|
434 end |
1241
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
435 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
|
436 count = count + 1; |
1798
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
437 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
|
438 if session.presence then |
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
439 status = session.presence:child_with_name("show"); |
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
440 if status then |
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
441 status = status:get_text() or "[invalid!]"; |
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
442 else |
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
443 status = "available"; |
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
444 end |
4c8f3fa9d926
mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents:
1616
diff
changeset
|
445 end |
1763
9e4ff3b66ed1
mod_console: c2s:show(): Group listed clients by host
Matthew Wild <mwild1@gmail.com>
parents:
1623
diff
changeset
|
446 print(" "..jid.." - "..status.."("..priority..")"); |
1241
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
447 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
448 end); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
449 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
|
450 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
451 |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
452 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
|
453 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
|
454 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
|
455 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
|
456 count = count + 1; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
457 print(jid); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
458 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
459 end); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
460 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
|
461 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
462 |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
463 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
|
464 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
|
465 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
|
466 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
|
467 count = count + 1; |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
468 print(jid); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
469 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
470 end); |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
471 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
|
472 end |
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
473 |
1491
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
474 function def_env.c2s:close(match_jid) |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
475 local print, count = self.session.print, 0; |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
476 show_c2s(function (jid, session) |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
477 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
|
478 count = count + 1; |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
479 session:close(); |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
480 end |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
481 end); |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
482 return true, "Total: "..count.." sessions closed"; |
694a0a00e1a5
mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents:
1483
diff
changeset
|
483 end |
1241
9c53fb182044
mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents:
1240
diff
changeset
|
484 |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
485 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
|
486 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
|
487 local _print = self.session.print; |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
488 local print = self.session.print; |
1322
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
489 |
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
490 local count_in, count_out = 0,0; |
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
491 |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
492 for host, host_session in pairs(hosts) do |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
493 print = function (...) _print(host); _print(...); print = _print; end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
494 for remotehost, session in pairs(host_session.s2sout) do |
1240
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
495 if (not match_jid) or remotehost:match(match_jid) or host:match(match_jid) then |
1322
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
496 count_out = count_out + 1; |
3652
8ae10787272a
mod_console: Denote services whose identity matches their (valid/trusted) certificate as 'secure'
Paul Aurich <paul@darkrain42.org>
parents:
3614
diff
changeset
|
497 print(" "..host.." -> "..remotehost..(session.cert_identity_status == "valid" and " (secure)" or "")..(session.secure and " (encrypted)" or "")..(session.compressed and " (compressed)" or "")); |
1240
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
498 if session.sendq then |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
499 print(" There are "..#session.sendq.." queued outgoing stanzas for this connection"); |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
500 end |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
501 if session.type == "s2sout_unauthed" then |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
502 if session.connecting then |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
503 print(" Connection not yet established"); |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
504 if not session.srv_hosts then |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
505 if not session.conn then |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
506 print(" We do not yet have a DNS answer for this host's SRV records"); |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
507 else |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
508 print(" This host has no SRV records, using A record instead"); |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
509 end |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
510 elseif session.srv_choice then |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
511 print(" We are on SRV record "..session.srv_choice.." of "..#session.srv_hosts); |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
512 local srv_choice = session.srv_hosts[session.srv_choice]; |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
513 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
|
514 end |
1240
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
515 elseif session.notopen then |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
516 print(" The <stream> has not yet been opened"); |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
517 elseif not session.dialback_key then |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
518 print(" Dialback has not been initiated yet"); |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
519 elseif session.dialback_key then |
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
520 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
|
521 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
522 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
523 end |
1240
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
524 end |
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3452
diff
changeset
|
525 local subhost_filter = function (h) |
1924
75e6ba240888
mod_console: Also search piggy-backed, er, multiplexed domains when passing a filter to s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1914
diff
changeset
|
526 return (match_jid and h:match(match_jid)); |
75e6ba240888
mod_console: Also search piggy-backed, er, multiplexed domains when passing a filter to s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1914
diff
changeset
|
527 end |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
528 for session in pairs(incoming_s2s) do |
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3452
diff
changeset
|
529 if session.to_host == host and ((not match_jid) or host:match(match_jid) |
1924
75e6ba240888
mod_console: Also search piggy-backed, er, multiplexed domains when passing a filter to s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1914
diff
changeset
|
530 or (session.from_host and session.from_host:match(match_jid)) |
75e6ba240888
mod_console: Also search piggy-backed, er, multiplexed domains when passing a filter to s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1914
diff
changeset
|
531 -- Pft! is what I say to list comprehensions |
75e6ba240888
mod_console: Also search piggy-backed, er, multiplexed domains when passing a filter to s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1914
diff
changeset
|
532 or (session.hosts and #array.collect(keys(session.hosts)):filter(subhost_filter)>0)) then |
1322
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
533 count_in = count_in + 1; |
3652
8ae10787272a
mod_console: Denote services whose identity matches their (valid/trusted) certificate as 'secure'
Paul Aurich <paul@darkrain42.org>
parents:
3614
diff
changeset
|
534 print(" "..host.." <- "..(session.from_host or "(unknown)")..(session.cert_identity_status == "valid" and " (secure)" or "")..(session.secure and " (encrypted)" or "")..(session.compressed and " (compressed)" or "")); |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
535 if session.type == "s2sin_unauthed" then |
1240
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
536 print(" Connection not yet authenticated"); |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
537 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
538 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
|
539 if name ~= session.from_host then |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
540 print(" also hosts "..tostring(name)); |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
541 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
542 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
543 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
544 end |
1240
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
545 |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
546 print = _print; |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
547 end |
1240
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
548 |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
549 for session in pairs(incoming_s2s) do |
1240
397b6e9c1568
mod_console: Allow restricting results to matching JIDs in s2s:show()
Matthew Wild <mwild1@gmail.com>
parents:
1085
diff
changeset
|
550 if not session.to_host and ((not match_jid) or session.from_host and session.from_host:match(match_jid)) then |
1322
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
551 count_in = count_in + 1; |
1085
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
552 print("Other incoming s2s connections"); |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
553 print(" (unknown) <- "..(session.from_host or "(unknown)")); |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
554 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
555 end |
1322
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
556 |
33d103b0283f
mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1317
diff
changeset
|
557 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
|
558 end |
1ac11fb753ca
mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
559 |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
560 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
|
561 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
|
562 print( |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
563 (" %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
|
564 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
|
565 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
|
566 ) |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
567 ); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
568 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
569 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
570 |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
571 -- 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
|
572 -- 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
|
573 -- break from that. |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
574 local function print_errors(print, errors) |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
575 for depth, t in ipairs(errors) do |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
576 print( |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
577 (" %d: %s"):format( |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
578 depth-1, |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
579 table.concat(t, "\n| ") |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
580 ) |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
581 ); |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
582 end |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
583 end |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
584 |
3669
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
585 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
|
586 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
|
587 local print = self.session.print; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
588 local domain_sessions = set.new(array.collect(keys(incoming_s2s))) |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
589 /function(session) return session.from_host == domain; end; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
590 for local_host in values(prosody.hosts) do |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
591 local s2sout = local_host.s2sout; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
592 if s2sout and s2sout[domain] then |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
593 domain_sessions:add(s2sout[domain]); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
594 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
595 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
596 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
|
597 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
|
598 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
|
599 conn = conn and conn:socket(); |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
600 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
|
601 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
|
602 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
|
603 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
604 else |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
605 local certs = conn:getpeerchain(); |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
606 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
|
607 if cert then |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
608 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
|
609 if not cert_set[digest] then |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
610 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
|
611 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
|
612 { |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
613 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
|
614 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
|
615 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
|
616 }; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
617 chain_valid = chain_valid; |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
618 chain_errors = chain_errors; |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
619 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
|
620 }; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
621 else |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
622 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
|
623 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
|
624 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
|
625 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
|
626 }); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
627 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
628 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
629 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
630 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
631 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
|
632 -- 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
|
633 local print = self.session.print; |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
634 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
|
635 |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
636 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
|
637 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
|
638 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
639 |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
640 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
|
641 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
|
642 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
643 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
|
644 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
|
645 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
646 |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
647 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
|
648 local certs = cert_info.certs; |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
649 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
|
650 print("---") |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
651 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
|
652 print(""); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
653 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
|
654 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
|
655 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
|
656 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
|
657 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
|
658 else |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
659 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
|
660 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
661 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
662 print(""); |
4328
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
663 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
|
664 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
|
665 if chain_valid then |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
666 print("Trusted certificate: Yes"); |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
667 else |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
668 print("Trusted certificate: No"); |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
669 print_errors(print, errors); |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
670 end |
c71777a8b9c7
mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents:
3899
diff
changeset
|
671 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
|
672 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
|
673 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
|
674 print(""); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
675 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
|
676 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
|
677 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
|
678 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
679 print("---"); |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
680 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
|
681 ..(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
|
682 .." 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
|
683 end |
4b56cd1302d4
mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents:
3652
diff
changeset
|
684 |
1340
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
685 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
|
686 local print, count = self.session.print, 0; |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
687 |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
688 if not (from and to) then |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
689 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
|
690 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
|
691 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
|
692 end |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
693 |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
694 if hosts[from] and not hosts[to] then |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
695 -- Is an outgoing connection |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
696 local session = hosts[from].s2sout[to]; |
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3452
diff
changeset
|
697 if not session then |
1340
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
698 print("No outgoing connection 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
|
699 else |
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
|
700 (session.close or s2smanager.destroy_session)(session); |
1340
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
701 count = count + 1; |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
702 print("Closed outgoing session 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
|
703 end |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
704 elseif hosts[to] and not hosts[from] then |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
705 -- Is an incoming connection |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
706 for session in pairs(incoming_s2s) do |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
707 if session.to_host == to and session.from_host == from then |
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
|
708 (session.close or s2smanager.destroy_session)(session); |
1340
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
709 count = count + 1; |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
710 end |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
711 end |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
712 |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
713 if count == 0 then |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
714 print("No incoming connections 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
|
715 else |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
716 print("Closed "..count.." incoming session"..((count == 1 and "") or "s").." 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
|
717 end |
1341
53decd1ee351
mod_console: Fix syntax error
Matthew Wild <mwild1@gmail.com>
parents:
1340
diff
changeset
|
718 elseif hosts[to] and hosts[from] then |
1340
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
719 return false, "Both of the hostnames you specified are local, there are no s2s sessions to close"; |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
720 else |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
721 return false, "Neither of the hostnames you specified are being used on this server"; |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
722 end |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
723 |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
724 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
|
725 end |
f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents:
1322
diff
changeset
|
726 |
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
|
727 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
|
728 |
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
|
729 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
|
730 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
|
731 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
|
732 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
|
733 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
|
734 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
|
735 |
2007
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
736 function def_env.host:list() |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
737 local print = self.session.print; |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
738 local i = 0; |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
739 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
|
740 i = i + 1; |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
741 print(host); |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
742 end |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
743 return true, i.." hosts"; |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
744 end |
b89d61db74d1
mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents:
1977
diff
changeset
|
745 |
736 | 746 ------------- |
747 | |
748 function printbanner(session) | |
1483
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
749 local option = config.get("*", "core", "console_banner"); |
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
750 if option == nil or option == "full" or option == "graphic" then |
736 | 751 session.print [[ |
752 ____ \ / _ | |
753 | _ \ _ __ ___ ___ _-_ __| |_ _ | |
754 | |_) | '__/ _ \/ __|/ _ \ / _` | | | | | |
755 | __/| | | (_) \__ \ |_| | (_| | |_| | | |
756 |_| |_| \___/|___/\___/ \__,_|\__, | | |
757 A study in simplicity |___/ | |
758 | |
759 ]] | |
1483
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
760 end |
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
761 if option == nil or option == "short" or option == "full" then |
736 | 762 session.print("Welcome to the Prosody administration console. For a list of commands, type: help"); |
763 session.print("You may find more help on using this console in our online documentation at "); | |
764 session.print("http://prosody.im/doc/console\n"); | |
765 end | |
1483
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
766 if option and option ~= "short" and option ~= "full" and option ~= "graphic" then |
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
767 if type(option) == "string" then |
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
768 session.print(option) |
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
769 elseif type(option) == "function" then |
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
770 setfenv(option, redirect_output(_G, session)); |
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
771 pcall(option, session); |
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
772 end |
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
773 end |
efd19cdda6ca
mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents:
1433
diff
changeset
|
774 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
|
775 |
4550
1c41e4a846a2
mod_admin_telnet: Port to portmanager
Matthew Wild <mwild1@gmail.com>
parents:
4540
diff
changeset
|
776 require "core.portmanager".register_service("console", { |
1c41e4a846a2
mod_admin_telnet: Port to portmanager
Matthew Wild <mwild1@gmail.com>
parents:
4540
diff
changeset
|
777 listener = console_listener; |
1c41e4a846a2
mod_admin_telnet: Port to portmanager
Matthew Wild <mwild1@gmail.com>
parents:
4540
diff
changeset
|
778 default_port = 5582; |
1c41e4a846a2
mod_admin_telnet: Port to portmanager
Matthew Wild <mwild1@gmail.com>
parents:
4540
diff
changeset
|
779 }); |