Annotate

plugins/mod_admin_telnet.lua @ 10798:b81f4fd7f21a

mod_admin_telnet: Use tostring as fallback in pretty printing This has some nice effects such as functions, VirtualHosts and other things being printed using their `__tostring` metamethod.
author Kim Alvefur <zash@zash.se>
date Sat, 02 May 2020 20:41:35 +0200
parent 10797:1c61ef6a15ab
child 10845:785fa0112411
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
4 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 736
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 736
diff changeset
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 --
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
8 -- luacheck: ignore 212/self
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 461
diff changeset
9
4623
403b56b78018 mod_posix, mod_bosh, mod_admin_telnet: Use module:set_global()
Kim Alvefur <zash@zash.se>
parents: 4582
diff changeset
10 module:set_global();
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 461
diff changeset
11
5030
9962fc19f9e9 mod_admin_telnet: Import prosody.incoming_s2s
Matthew Wild <mwild1@gmail.com>
parents: 5029
diff changeset
12 local hostmanager = require "core.hostmanager";
9962fc19f9e9 mod_admin_telnet: Import prosody.incoming_s2s
Matthew Wild <mwild1@gmail.com>
parents: 5029
diff changeset
13 local modulemanager = require "core.modulemanager";
9962fc19f9e9 mod_admin_telnet: Import prosody.incoming_s2s
Matthew Wild <mwild1@gmail.com>
parents: 5029
diff changeset
14 local s2smanager = require "core.s2smanager";
9962fc19f9e9 mod_admin_telnet: Import prosody.incoming_s2s
Matthew Wild <mwild1@gmail.com>
parents: 5029
diff changeset
15 local portmanager = require "core.portmanager";
8921
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
16 local helpers = require "util.helpers";
9406
7f277975768d mod_admin_telnet: Import net.server instead of relying on global
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
17 local server = require "net.server";
5030
9962fc19f9e9 mod_admin_telnet: Import prosody.incoming_s2s
Matthew Wild <mwild1@gmail.com>
parents: 5029
diff changeset
18
1342
947d94e3619f mod_console: Redirect print() to console session when executing commands in global environment
Matthew Wild <mwild1@gmail.com>
parents: 1341
diff changeset
19 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
20
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
21 local prosody = _G.prosody;
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
22
4989
573123ff2ab0 mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents: 4979
diff changeset
23 local console_listener = { default_port = 5582; default_mode = "*a"; interface = "127.0.0.1" };
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
24
9691
e11e076f0eb8 various: Don't rely on _G.unpack existing
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
25 local unpack = table.unpack or unpack; -- luacheck: ignore 113
4582
542afb9c2ab1 mod_admin_telnet: Import util.iterators properly
Kim Alvefur <zash@zash.se>
parents: 4571
diff changeset
26 local iterators = require "util.iterators";
542afb9c2ab1 mod_admin_telnet: Import util.iterators properly
Kim Alvefur <zash@zash.se>
parents: 4571
diff changeset
27 local keys, values = iterators.keys, iterators.values;
7068
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
28 local jid_bare, jid_split, jid_join = import("util.jid", "bare", "prepped_split", "join");
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
29 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
30 local cert_verify_identity = require "util.x509".verify_identity;
5021
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4913
diff changeset
31 local envload = require "util.envload".envload;
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4913
diff changeset
32 local envloadfile = require "util.envload".envloadfile;
6503
8437058c4226 mod_admin_telnet: Soft-reqire util.pposix for server:memory()
Kim Alvefur <zash@zash.se>
parents: 6382
diff changeset
33 local has_pposix, pposix = pcall(require, "util.pposix");
9735
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
34 local async = require "util.async";
10787
459efb1afbfe mod_admin_telnet: Pretty-print values returned from commands
Kim Alvefur <zash@zash.se>
parents: 10701
diff changeset
35 local serialization = require "util.serialization";
459efb1afbfe mod_admin_telnet: Pretty-print values returned from commands
Kim Alvefur <zash@zash.se>
parents: 10701
diff changeset
36 local serialize_config = serialization.new ({ fatal = false, unquoted = true});
10310
b03065cd033a mod_admin_telnet: xmpp:ping: Log ping time
Kim Alvefur <zash@zash.se>
parents: 10292
diff changeset
37 local time = require "util.time";
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
38
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
39 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
40 local def_env = module:shared("env");
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
41 local default_env_mt = { __index = def_env };
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
42
9403
4416c1a96400 mod_admin_telnet: Rename variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9391
diff changeset
43 local function redirect_output(target, session)
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
44 local env = setmetatable({ print = session.print }, { __index = function (_, k) return rawget(target, 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
45 env.dofile = function(name)
5021
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4913
diff changeset
46 local f, err = envloadfile(name, env);
3407
15f633285755 mod_console: Override dofile() in the console environment (this lets print() print to the console session for example).
Waqas Hussain <waqas20@gmail.com>
parents: 3404
diff changeset
47 if not f then return f, err; end
5021
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4913
diff changeset
48 return f();
3407
15f633285755 mod_console: Override dofile() in the console environment (this lets print() print to the console session for example).
Waqas Hussain <waqas20@gmail.com>
parents: 3404
diff changeset
49 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
50 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
51 end
947d94e3619f mod_console: Redirect print() to console session when executing commands in global environment
Matthew Wild <mwild1@gmail.com>
parents: 1341
diff changeset
52
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
53 console = {};
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
54
9735
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
55 local runner_callbacks = {};
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
56
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
57 function runner_callbacks:ready()
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
58 self.data.conn:resume();
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
59 end
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
60
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
61 function runner_callbacks:waiting()
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
62 self.data.conn:pause();
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
63 end
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
64
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
65 function runner_callbacks:error(err)
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
66 module:log("error", "Traceback[telnet]: %s", err);
10068
73a8192058f9 mod_admin_telnet: Move error handling to thread callback (fixes #1391)
Kim Alvefur <zash@zash.se>
parents: 10067
diff changeset
67
73a8192058f9 mod_admin_telnet: Move error handling to thread callback (fixes #1391)
Kim Alvefur <zash@zash.se>
parents: 10067
diff changeset
68 self.data.print("Fatal error while running command, it did not complete");
73a8192058f9 mod_admin_telnet: Move error handling to thread callback (fixes #1391)
Kim Alvefur <zash@zash.se>
parents: 10067
diff changeset
69 self.data.print("Error: "..tostring(err));
9735
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
70 end
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
71
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
72
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
73 function console:new_session(conn)
2145
daeb6ebf304c mod_console: Update for new net.server API
Matthew Wild <mwild1@gmail.com>
parents: 2087
diff changeset
74 local w = function(s) conn:write(s:gsub("\n", "\r\n")); end;
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
75 local session = { conn = conn;
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
76 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
77 print = function (...)
33c81ee280e3 mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents: 3044
diff changeset
78 local t = {};
33c81ee280e3 mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents: 3044
diff changeset
79 for i=1,select("#", ...) do
33c81ee280e3 mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents: 3044
diff changeset
80 t[i] = tostring(select(i, ...));
33c81ee280e3 mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents: 3044
diff changeset
81 end
33c81ee280e3 mod_console: Added support for multiple arguments to print().
Waqas Hussain <waqas20@gmail.com>
parents: 3044
diff changeset
82 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
83 end;
10796
89d810a23ee0 mod_admin_telnet: Reuse existing pretty printing setup
Kim Alvefur <zash@zash.se>
parents: 10795
diff changeset
84 serialize = tostring;
2253
a3537266a916 mod_console: Update for new server API, fixes traceback when closing console sessions
Matthew Wild <mwild1@gmail.com>
parents: 2145
diff changeset
85 disconnect = function () conn:close(); end;
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
86 };
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
87 session.env = setmetatable({}, default_env_mt);
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
88
9735
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
89 session.thread = async.runner(function (line)
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
90 console:process_line(session, line);
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
91 session.send(string.char(0));
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
92 end, runner_callbacks, session);
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
93
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
94 -- Load up environment with helper objects
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
95 for name, t in pairs(def_env) do
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
96 if type(t) == "table" then
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
97 session.env[name] = setmetatable({ session = session }, { __index = t });
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
98 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
99 end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
100
10796
89d810a23ee0 mod_admin_telnet: Reuse existing pretty printing setup
Kim Alvefur <zash@zash.se>
parents: 10795
diff changeset
101 session.env.output:configure();
89d810a23ee0 mod_admin_telnet: Reuse existing pretty printing setup
Kim Alvefur <zash@zash.se>
parents: 10795
diff changeset
102
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
103 return session;
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
104 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
105
5186
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
106 function console:process_line(session, line)
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
107 local useglobalenv;
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
108
5186
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
109 if line:match("^>") then
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
110 line = line:gsub("^>", "");
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
111 useglobalenv = true;
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
112 elseif line == "\004" then
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
113 commands["bye"](session, line);
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
114 return;
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
115 else
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
116 local command = line:match("^%w+") or line:match("%p");
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
117 if commands[command] then
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
118 commands[command](session, line);
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
119 return;
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
120 end
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
121 end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
122
5186
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
123 session.env._ = line;
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
124
10067
598befab492e mod_admin_telnet: Check for simple commands before executing in sandbox
Kim Alvefur <zash@zash.se>
parents: 10044
diff changeset
125 if not useglobalenv and commands[line:lower()] then
598befab492e mod_admin_telnet: Check for simple commands before executing in sandbox
Kim Alvefur <zash@zash.se>
parents: 10044
diff changeset
126 commands[line:lower()](session, line);
598befab492e mod_admin_telnet: Check for simple commands before executing in sandbox
Kim Alvefur <zash@zash.se>
parents: 10044
diff changeset
127 return;
598befab492e mod_admin_telnet: Check for simple commands before executing in sandbox
Kim Alvefur <zash@zash.se>
parents: 10044
diff changeset
128 end
598befab492e mod_admin_telnet: Check for simple commands before executing in sandbox
Kim Alvefur <zash@zash.se>
parents: 10044
diff changeset
129
5186
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
130 local chunkname = "=console";
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
131 local env = (useglobalenv and redirect_output(_G, session)) or session.env or nil
10544
0bd408d93f9a mod_admin_telnet: Silence luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 10517
diff changeset
132 -- luacheck: ignore 311/err
5186
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
133 local chunk, err = envload("return "..line, chunkname, env);
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
134 if not chunk then
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
135 chunk, err = envload(line, chunkname, env);
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
136 if not chunk then
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
137 err = err:gsub("^%[string .-%]:%d+: ", "");
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
138 err = err:gsub("^:%d+: ", "");
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
139 err = err:gsub("'<eof>'", "the end of the line");
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
140 session.print("Sorry, I couldn't understand that... "..err);
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
141 return;
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
142 end
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
143 end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
144
10068
73a8192058f9 mod_admin_telnet: Move error handling to thread callback (fixes #1391)
Kim Alvefur <zash@zash.se>
parents: 10067
diff changeset
145 local taskok, message = chunk();
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
146
5186
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
147 if not message then
10797
1c61ef6a15ab mod_admin_telnet: Don't pretty-print the normal console stuff
Kim Alvefur <zash@zash.se>
parents: 10796
diff changeset
148 if type(taskok) ~= "string" and useglobalenv then
10787
459efb1afbfe mod_admin_telnet: Pretty-print values returned from commands
Kim Alvefur <zash@zash.se>
parents: 10701
diff changeset
149 taskok = session.serialize(taskok);
459efb1afbfe mod_admin_telnet: Pretty-print values returned from commands
Kim Alvefur <zash@zash.se>
parents: 10701
diff changeset
150 end
10797
1c61ef6a15ab mod_admin_telnet: Don't pretty-print the normal console stuff
Kim Alvefur <zash@zash.se>
parents: 10796
diff changeset
151 session.print("Result: "..tostring(taskok));
5186
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
152 return;
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
153 elseif (not taskok) and message then
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
154 session.print("Command completed with a problem");
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
155 session.print("Message: "..tostring(message));
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
156 return;
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
157 end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
158
10797
1c61ef6a15ab mod_admin_telnet: Don't pretty-print the normal console stuff
Kim Alvefur <zash@zash.se>
parents: 10796
diff changeset
159 session.print("OK: "..tostring(message));
5186
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
160 end
ad898e50b8f3 mod_admin_telnet: Refactor so that command processing is performed in a separate function (usable from other modules)
Matthew Wild <mwild1@gmail.com>
parents: 5168
diff changeset
161
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
162 local sessions = {};
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
163
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
164 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
165 -- 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
166 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
167 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
168 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
169 session.send(string.char(0));
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
170 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
171
2145
daeb6ebf304c mod_console: Update for new net.server API
Matthew Wild <mwild1@gmail.com>
parents: 2087
diff changeset
172 function console_listener.onincoming(conn, data)
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
173 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
174
4989
573123ff2ab0 mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents: 4979
diff changeset
175 local partial = session.partial_data;
573123ff2ab0 mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents: 4979
diff changeset
176 if partial then
573123ff2ab0 mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents: 4979
diff changeset
177 data = partial..data;
573123ff2ab0 mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents: 4979
diff changeset
178 end
573123ff2ab0 mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents: 4979
diff changeset
179
573123ff2ab0 mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents: 4979
diff changeset
180 for line in data:gmatch("[^\n]*[\n\004]") do
5278
f79be67e5666 mod_admin_telnet: Stop processing lines when session is closed
Kim Alvefur <zash@zash.se>
parents: 5270
diff changeset
181 if session.closed then return end
9735
2d8ca54ecbc6 mod_admin_telnet: Enable async processing using util.async
Kim Alvefur <zash@zash.se>
parents: 9734
diff changeset
182 session.thread:run(line);
4989
573123ff2ab0 mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents: 4979
diff changeset
183 end
573123ff2ab0 mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network
Matthew Wild <mwild1@gmail.com>
parents: 4979
diff changeset
184 session.partial_data = data:match("[^\n]+$");
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
185 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
186
6169
cb15eac75b50 mod_admin_telnet: Send NUL byte as keepalive on read timeouts
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
187 function console_listener.onreadtimeout(conn)
cb15eac75b50 mod_admin_telnet: Send NUL byte as keepalive on read timeouts
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
188 local session = sessions[conn];
cb15eac75b50 mod_admin_telnet: Send NUL byte as keepalive on read timeouts
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
189 if session then
cb15eac75b50 mod_admin_telnet: Send NUL byte as keepalive on read timeouts
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
190 session.send("\0");
cb15eac75b50 mod_admin_telnet: Send NUL byte as keepalive on read timeouts
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
191 return true;
cb15eac75b50 mod_admin_telnet: Send NUL byte as keepalive on read timeouts
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
192 end
cb15eac75b50 mod_admin_telnet: Send NUL byte as keepalive on read timeouts
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
193 end
cb15eac75b50 mod_admin_telnet: Send NUL byte as keepalive on read timeouts
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
194
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
195 function console_listener.ondisconnect(conn, err) -- luacheck: ignore 212/err
2054
a43aea9b0bd1 mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents: 2010
diff changeset
196 local session = sessions[conn];
a43aea9b0bd1 mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents: 2010
diff changeset
197 if session then
a43aea9b0bd1 mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents: 2010
diff changeset
198 session.disconnect();
a43aea9b0bd1 mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents: 2010
diff changeset
199 sessions[conn] = nil;
a43aea9b0bd1 mod_console: Added proper cleanup for disconnected console sessions.
Waqas Hussain <waqas20@gmail.com>
parents: 2010
diff changeset
200 end
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
201 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
202
6380
4220ffb87b22 net.http, net.http.server, mod_c2s, mod_s2s, mod_component, mod_admin_telnet, mod_net_multiplex: Add ondetach to release connection from 'sessions' table (or equivalent)
Matthew Wild <mwild1@gmail.com>
parents: 6311
diff changeset
203 function console_listener.ondetach(conn)
4220ffb87b22 net.http, net.http.server, mod_c2s, mod_s2s, mod_component, mod_admin_telnet, mod_net_multiplex: Add ondetach to release connection from 'sessions' table (or equivalent)
Matthew Wild <mwild1@gmail.com>
parents: 6311
diff changeset
204 sessions[conn] = nil;
4220ffb87b22 net.http, net.http.server, mod_c2s, mod_s2s, mod_component, mod_admin_telnet, mod_net_multiplex: Add ondetach to release connection from 'sessions' table (or equivalent)
Matthew Wild <mwild1@gmail.com>
parents: 6311
diff changeset
205 end
4220ffb87b22 net.http, net.http.server, mod_c2s, mod_s2s, mod_component, mod_admin_telnet, mod_net_multiplex: Add ondetach to release connection from 'sessions' table (or equivalent)
Matthew Wild <mwild1@gmail.com>
parents: 6311
diff changeset
206
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
207 -- Console commands --
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
208 -- These are simple commands, not valid standalone in Lua
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
209
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
210 function commands.bye(session)
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
211 session.print("See you! :)");
5278
f79be67e5666 mod_admin_telnet: Stop processing lines when session is closed
Kim Alvefur <zash@zash.se>
parents: 5270
diff changeset
212 session.closed = true;
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
213 session.disconnect();
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
214 end
1503
5970e06d9335 mod_console: Add quit and exit as aliases for 'bye' command
Matthew Wild <mwild1@gmail.com>
parents: 1502
diff changeset
215 commands.quit, commands.exit = commands.bye, commands.bye;
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
216
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
217 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
218 if data:match("^!!") and session.env._ then
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
219 session.print("!> "..session.env._);
2512
d04b0eeeb954 mod_console: Update !! shortcut for new connection API
Matthew Wild <mwild1@gmail.com>
parents: 2296
diff changeset
220 return console_listener.onincoming(session.conn, session.env._);
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
221 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
222 local old, new = data:match("^!(.-[^\\])!(.-)!$");
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
223 if old and new then
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
224 local ok, res = pcall(string.gsub, session.env._, old, new);
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
225 if not ok then
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
226 session.print(res)
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
227 return;
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
228 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
229 session.print("!> "..res);
2512
d04b0eeeb954 mod_console: Update !! shortcut for new connection API
Matthew Wild <mwild1@gmail.com>
parents: 2296
diff changeset
230 return console_listener.onincoming(session.conn, res);
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
231 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
232 session.print("Sorry, not sure what you want");
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
233 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
234
3452
2d1a5d8893c2 mod_console: Add host:* commands to help (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents: 3407
diff changeset
235
1616
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
236 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
237 local print = session.print;
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
238 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
239 if not section then
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
240 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
241 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
242 print [[]]
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
243 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
244 print [[s2s - Commands to manage sessions between this server and others]]
10789
e7eb33a5f8d9 mod_admin_telnet: Document HTTP command in internal help
Kim Alvefur <zash@zash.se>
parents: 10788
diff changeset
245 print [[http - Commands to inspect HTTP services]] -- XXX plural but there is only one so far
1616
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
246 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
247 print [[host - Commands to activate, deactivate and list virtual hosts]]
4974
1574f18b0ca4 mod_admin_telnet: Add info about user management commands to the help
Kim Alvefur <zash@zash.se>
parents: 4973
diff changeset
248 print [[user - Commands to create and delete users, and change their passwords]]
1616
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
249 print [[server - Uptime, version, shutting down, etc.]]
5270
20e14961f630 mod_admin_telnet: Add info about port commands to help
Kim Alvefur <zash@zash.se>
parents: 5227
diff changeset
250 print [[port - Commands to manage ports the server is listening on]]
5567
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
251 print [[dns - Commands to manage and inspect the internal DNS resolver]]
10087
36d3709603d1 mod_admin_telnet: Add xmpp:ping to help
Kim Alvefur <zash@zash.se>
parents: 10086
diff changeset
252 print [[xmpp - Commands for sending XMPP stanzas]]
10788
3fc4863227a9 mod_admin_telnet: Document (in the internal help) debug commands
Kim Alvefur <zash@zash.se>
parents: 10787
diff changeset
253 print [[debug - Commands for debugging the server]]
2009
3f9cce29c57d mod_console: Added help text for config:reload().
Waqas Hussain <waqas20@gmail.com>
parents: 2007
diff changeset
254 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
255 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
256 elseif section == "c2s" then
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
257 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
258 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
259 print [[c2s:show_secure() - Show all encrypted client connections]]
6174
513ea94761b2 mod_admin_telnet: Add c2s:show_tls(), behaves like s2s:show_tls()
Kim Alvefur <zash@zash.se>
parents: 6173
diff changeset
260 print [[c2s:show_tls() - Show TLS cipher info for encrypted sessions]]
10086
4ade3674baf0 mod_admin_telnet: Add c2s:count() to help
Kim Alvefur <zash@zash.se>
parents: 10085
diff changeset
261 print [[c2s:count() - Count sessions without listing them]]
1616
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
262 print [[c2s:close(jid) - Close all sessions for the specified JID]]
9974
c30933aa0242 mod_admin_telnet: Adds c2s:closeall() (Fixes #1315)
João Duarte <jvsDuarte08@gmail.com>
parents: 9868
diff changeset
263 print [[c2s:closeall() - Close all active c2s connections ]]
1616
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
264 elseif section == "s2s" then
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
265 print [[s2s:show(domain) - Show all s2s connections for the given domain (or all if no domain given)]]
6172
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
266 print [[s2s:show_tls(domain) - Show TLS cipher info for encrypted sessions]]
1616
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
267 print [[s2s:close(from, to) - Close a connection from one domain to another]]
4978
0b9e86302de4 mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents: 4913
diff changeset
268 print [[s2s:closeall(host) - Close all the incoming/outgoing s2s sessions to specified host]]
10789
e7eb33a5f8d9 mod_admin_telnet: Document HTTP command in internal help
Kim Alvefur <zash@zash.se>
parents: 10788
diff changeset
269 elseif section == "http" then
e7eb33a5f8d9 mod_admin_telnet: Document HTTP command in internal help
Kim Alvefur <zash@zash.se>
parents: 10788
diff changeset
270 print [[http:list(hosts) - Show HTTP endpoints]]
1616
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
271 elseif section == "module" then
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
272 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
273 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
274 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
275 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
276 elseif section == "host" then
2d1a5d8893c2 mod_console: Add host:* commands to help (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents: 3407
diff changeset
277 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
278 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
279 print [[host:list() - List the currently-activated hosts]]
4974
1574f18b0ca4 mod_admin_telnet: Add info about user management commands to the help
Kim Alvefur <zash@zash.se>
parents: 4973
diff changeset
280 elseif section == "user" then
1574f18b0ca4 mod_admin_telnet: Add info about user management commands to the help
Kim Alvefur <zash@zash.se>
parents: 4973
diff changeset
281 print [[user:create(jid, password) - Create the specified user account]]
1574f18b0ca4 mod_admin_telnet: Add info about user management commands to the help
Kim Alvefur <zash@zash.se>
parents: 4973
diff changeset
282 print [[user:password(jid, password) - Set the password for the specified user account]]
5128
834ab74585ec mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents: 5030
diff changeset
283 print [[user:delete(jid) - Permanently remove the specified user account]]
5168
46fc0eff10b4 mod_admin_telnet: user:list(): Allow filtering the set of users
Kim Alvefur <zash@zash.se>
parents: 5167
diff changeset
284 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]]
1616
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
285 elseif section == "server" then
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
286 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
287 print [[server:uptime() - Show how long the server has been running]]
5672
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
288 print [[server:memory() - Show details about the server's memory usage]]
2870
471c3acffb2a mod_console: Uncomment the help for server:shutdown() - thanks darkrain
Matthew Wild <mwild1@gmail.com>
parents: 2087
diff changeset
289 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]]
5270
20e14961f630 mod_admin_telnet: Add info about port commands to help
Kim Alvefur <zash@zash.se>
parents: 5227
diff changeset
290 elseif section == "port" then
20e14961f630 mod_admin_telnet: Add info about port commands to help
Kim Alvefur <zash@zash.se>
parents: 5227
diff changeset
291 print [[port:list() - Lists all network ports prosody currently listens on]]
20e14961f630 mod_admin_telnet: Add info about port commands to help
Kim Alvefur <zash@zash.se>
parents: 5227
diff changeset
292 print [[port:close(port, interface) - Close a port]]
5567
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
293 elseif section == "dns" then
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
294 print [[dns:lookup(name, type, class) - Do a DNS lookup]]
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
295 print [[dns:addnameserver(nameserver) - Add a nameserver to the list]]
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
296 print [[dns:setnameserver(nameserver) - Replace the list of name servers with the supplied one]]
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
297 print [[dns:purge() - Clear the DNS cache]]
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
298 print [[dns:cache() - Show cached records]]
10087
36d3709603d1 mod_admin_telnet: Add xmpp:ping to help
Kim Alvefur <zash@zash.se>
parents: 10086
diff changeset
299 elseif section == "xmpp" then
36d3709603d1 mod_admin_telnet: Add xmpp:ping to help
Kim Alvefur <zash@zash.se>
parents: 10086
diff changeset
300 print [[xmpp:ping(localhost, remotehost) -- Sends a ping to a remote XMPP server and reports the response]]
2009
3f9cce29c57d mod_console: Added help text for config:reload().
Waqas Hussain <waqas20@gmail.com>
parents: 2007
diff changeset
301 elseif section == "config" then
3f9cce29c57d mod_console: Added help text for config:reload().
Waqas Hussain <waqas20@gmail.com>
parents: 2007
diff changeset
302 print [[config:reload() - Reload the server configuration. Modules may need to be reloaded for changes to take effect.]]
10517
6e1163fa2cd2 mod_admin_telnet: Include config:get() in help text
Kim Alvefur <zash@zash.se>
parents: 10510
diff changeset
303 print [[config:get([host,] option) - Show the value of a config option.]]
10792
ef2bd183f660 mod_admin_telnet: Silence luacheck
Kim Alvefur <zash@zash.se>
parents: 10791
diff changeset
304 elseif section == "stats" then -- luacheck: ignore 542
ef2bd183f660 mod_admin_telnet: Silence luacheck
Kim Alvefur <zash@zash.se>
parents: 10791
diff changeset
305 -- TODO describe how stats:show() works
10788
3fc4863227a9 mod_admin_telnet: Document (in the internal help) debug commands
Kim Alvefur <zash@zash.se>
parents: 10787
diff changeset
306 elseif section == "debug" then
3fc4863227a9 mod_admin_telnet: Document (in the internal help) debug commands
Kim Alvefur <zash@zash.se>
parents: 10787
diff changeset
307 print [[debug:logevents(host) - Enable logging of fired events on host]]
3fc4863227a9 mod_admin_telnet: Document (in the internal help) debug commands
Kim Alvefur <zash@zash.se>
parents: 10787
diff changeset
308 print [[debug:events(host, event) - Show registered event handlers]]
3fc4863227a9 mod_admin_telnet: Document (in the internal help) debug commands
Kim Alvefur <zash@zash.se>
parents: 10787
diff changeset
309 print [[debug:timers() - Show information about scheduled timers]]
1616
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
310 elseif section == "console" then
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
311 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
312 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
313 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
314 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
315 print [[]]
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
316 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
317 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
318 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
319 print [[]]
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
320 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
321 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
322 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
323 end
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
324 print [[]]
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
325 end
80ea744f2643 mod_console: Finally add in the missing 'help' command \o/
Matthew Wild <mwild1@gmail.com>
parents: 1575
diff changeset
326
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
327 -- Session environment --
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
328 -- Anything in def_env will be accessible within the session as a global variable
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
329
6987
06696882d972 mod_admin_telnet: Add http:list() command to get info about current HTTP endpoints on the server
Matthew Wild <mwild1@gmail.com>
parents: 6927
diff changeset
330 --luacheck: ignore 212/self
10795
4c90f06f2247 mod_admin_telnet: Allow configuring pretty printing defaults
Kim Alvefur <zash@zash.se>
parents: 10792
diff changeset
331 local serialize_defaults = module:get_option("console_prettyprint_settings", { fatal = false, unquoted = true, maxdepth = 2})
6987
06696882d972 mod_admin_telnet: Add http:list() command to get info about current HTTP endpoints on the server
Matthew Wild <mwild1@gmail.com>
parents: 6927
diff changeset
332
10791
f46c5e3c97ee mod_admin_telnet: Add a command to configure pretty-printing settings
Kim Alvefur <zash@zash.se>
parents: 10790
diff changeset
333 def_env.output = {};
f46c5e3c97ee mod_admin_telnet: Add a command to configure pretty-printing settings
Kim Alvefur <zash@zash.se>
parents: 10790
diff changeset
334 function def_env.output:configure(opts)
10795
4c90f06f2247 mod_admin_telnet: Allow configuring pretty printing defaults
Kim Alvefur <zash@zash.se>
parents: 10792
diff changeset
335 if type(opts) ~= "table" then
4c90f06f2247 mod_admin_telnet: Allow configuring pretty printing defaults
Kim Alvefur <zash@zash.se>
parents: 10792
diff changeset
336 opts = { preset = opts };
4c90f06f2247 mod_admin_telnet: Allow configuring pretty printing defaults
Kim Alvefur <zash@zash.se>
parents: 10792
diff changeset
337 end
10798
b81f4fd7f21a mod_admin_telnet: Use tostring as fallback in pretty printing
Kim Alvefur <zash@zash.se>
parents: 10797
diff changeset
338 if not opts.fallback then
b81f4fd7f21a mod_admin_telnet: Use tostring as fallback in pretty printing
Kim Alvefur <zash@zash.se>
parents: 10797
diff changeset
339 -- XXX Error message passed to fallback is lost, does it matter?
b81f4fd7f21a mod_admin_telnet: Use tostring as fallback in pretty printing
Kim Alvefur <zash@zash.se>
parents: 10797
diff changeset
340 opts.fallback = tostring;
b81f4fd7f21a mod_admin_telnet: Use tostring as fallback in pretty printing
Kim Alvefur <zash@zash.se>
parents: 10797
diff changeset
341 end
10795
4c90f06f2247 mod_admin_telnet: Allow configuring pretty printing defaults
Kim Alvefur <zash@zash.se>
parents: 10792
diff changeset
342 for k,v in pairs(serialize_defaults) do
4c90f06f2247 mod_admin_telnet: Allow configuring pretty printing defaults
Kim Alvefur <zash@zash.se>
parents: 10792
diff changeset
343 if opts[k] == nil then
4c90f06f2247 mod_admin_telnet: Allow configuring pretty printing defaults
Kim Alvefur <zash@zash.se>
parents: 10792
diff changeset
344 opts[k] = v;
4c90f06f2247 mod_admin_telnet: Allow configuring pretty printing defaults
Kim Alvefur <zash@zash.se>
parents: 10792
diff changeset
345 end
4c90f06f2247 mod_admin_telnet: Allow configuring pretty printing defaults
Kim Alvefur <zash@zash.se>
parents: 10792
diff changeset
346 end
10791
f46c5e3c97ee mod_admin_telnet: Add a command to configure pretty-printing settings
Kim Alvefur <zash@zash.se>
parents: 10790
diff changeset
347 self.session.serialize = serialization.new(opts);
f46c5e3c97ee mod_admin_telnet: Add a command to configure pretty-printing settings
Kim Alvefur <zash@zash.se>
parents: 10790
diff changeset
348 end
f46c5e3c97ee mod_admin_telnet: Add a command to configure pretty-printing settings
Kim Alvefur <zash@zash.se>
parents: 10790
diff changeset
349
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
350 def_env.server = {};
1558
e15917530285 mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents: 1556
diff changeset
351
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
352 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
353 prosody.unlock_globals();
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
354 dofile "prosody"
1316
28ae044f1aaf mod_console: Some "improvements" to the useless server:reload() command :)
Matthew Wild <mwild1@gmail.com>
parents: 1315
diff changeset
355 prosody = _G.prosody;
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
356 return true, "Server reloaded";
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
357 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
358
1496
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
359 function def_env.server:version()
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
360 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
361 end
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
362
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
363 function def_env.server:uptime()
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
364 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
365 local seconds = t%60;
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
366 t = (t - seconds)/60;
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
367 local minutes = t%60;
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
368 t = (t - minutes)/60;
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
369 local hours = t%24;
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
370 t = (t - hours)/24;
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
371 local days = t;
3540
bc139431830b Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents: 3452
diff changeset
372 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
373 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
374 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
375 end
4fa337035f46 mod_console: server:version() and server:uptime() commands
Matthew Wild <mwild1@gmail.com>
parents: 1491
diff changeset
376
1559
831649bb1922 mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents: 1558
diff changeset
377 function def_env.server:shutdown(reason)
831649bb1922 mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents: 1558
diff changeset
378 prosody.shutdown(reason);
831649bb1922 mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents: 1558
diff changeset
379 return true, "Shutdown initiated";
831649bb1922 mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents: 1558
diff changeset
380 end
831649bb1922 mod_console: Add server:shutdown() command
Matthew Wild <mwild1@gmail.com>
parents: 1558
diff changeset
381
5672
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
382 local function human(kb)
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
383 local unit = "K";
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
384 if kb > 1024 then
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
385 kb, unit = kb/1024, "M";
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
386 end
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
387 return ("%0.2f%sB"):format(kb, unit);
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
388 end
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
389
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
390 function def_env.server:memory()
6503
8437058c4226 mod_admin_telnet: Soft-reqire util.pposix for server:memory()
Kim Alvefur <zash@zash.se>
parents: 6382
diff changeset
391 if not has_pposix or not pposix.meminfo then
8126
60f6f7ddd2ce mod_admin_telnet: Output human-friendly memory usage when meminfo is unavailable (thanks nbastin)
Kim Alvefur <zash@zash.se>
parents: 7977
diff changeset
392 return true, "Lua is using "..human(collectgarbage("count"));
5672
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
393 end
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
394 local mem, lua_mem = pposix.meminfo(), collectgarbage("count");
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
395 local print = self.session.print;
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
396 print("Process: "..human((mem.allocated+mem.allocated_mmap)/1024));
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
397 print(" Used: "..human(mem.used/1024).." ("..human(lua_mem).." by Lua)");
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
398 print(" Free: "..human(mem.unused/1024).." ("..human(mem.returnable/1024).." returnable)");
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
399 return true, "OK";
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
400 end
0c68cea74d5d mod_admin_telnet: Add server:memory() command to view details of Prosody's memory usage
Matthew Wild <mwild1@gmail.com>
parents: 5665
diff changeset
401
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
402 def_env.module = {};
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
403
10507
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
404 local function get_hosts_set(hosts)
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
405 if type(hosts) == "table" then
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
406 if hosts[1] then
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
407 return set.new(hosts);
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
408 elseif hosts._items then
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
409 return hosts;
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
410 end
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
411 elseif type(hosts) == "string" then
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
412 return set.new { hosts };
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
413 elseif hosts == nil then
10507
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
414 return set.new(array.collect(keys(prosody.hosts)));
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
415 end
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
416 end
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
417
10507
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
418 -- Hosts with a module or all virtualhosts if no module given
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
419 -- matching modules_enabled in the global section
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
420 local function get_hosts_with_module(hosts, module)
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
421 local hosts_set = get_hosts_set(hosts)
10657
197ba9539390 mod_admin_telnet: Reflow hosts filter for readability
Kim Alvefur <zash@zash.se>
parents: 10644
diff changeset
422 / function (host)
10658
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
423 if module then
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
424 -- Module given, filter in hosts with this module loaded
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
425 if modulemanager.is_loaded(host, module) then
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
426 return host;
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
427 else
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
428 return nil;
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
429 end
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
430 end
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
431 if not hosts then
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
432 -- No hosts given, filter in VirtualHosts
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
433 if prosody.hosts[host].type == "local" then
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
434 return host;
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
435 else
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
436 return nil
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
437 end
10657
197ba9539390 mod_admin_telnet: Reflow hosts filter for readability
Kim Alvefur <zash@zash.se>
parents: 10644
diff changeset
438 end;
10658
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
439 -- No module given, but hosts are, don't filter at all
52c6dfa04dba mod_admin_telnet: Fix host selection filter, fixes loading on components
Kim Alvefur <zash@zash.se>
parents: 10657
diff changeset
440 return host;
10657
197ba9539390 mod_admin_telnet: Reflow hosts filter for readability
Kim Alvefur <zash@zash.se>
parents: 10644
diff changeset
441 end;
10507
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
442 if module and modulemanager.get_module("*", module) then
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
443 hosts_set:add("*");
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
444 end
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
445 return hosts_set;
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
446 end
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
447
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
448 function def_env.module:load(name, hosts, config)
10507
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
449 hosts = get_hosts_with_module(hosts);
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
450
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
451 -- Load the module for each host
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
452 local ok, err, count, mod = true, nil, 0;
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
453 for host in hosts do
6781
05cd80ec107c mod_admin_telnet: Remove now broken importing of modulemanager from various commands, use upvalue defined at top of file (thanks daurnimator)
Kim Alvefur <zash@zash.se>
parents: 6580
diff changeset
454 if (not modulemanager.is_loaded(host, name)) then
05cd80ec107c mod_admin_telnet: Remove now broken importing of modulemanager from various commands, use upvalue defined at top of file (thanks daurnimator)
Kim Alvefur <zash@zash.se>
parents: 6580
diff changeset
455 mod, err = modulemanager.load(host, name, config);
4647
57a4f863e48f mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents: 4646
diff changeset
456 if not mod then
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
457 ok = false;
4647
57a4f863e48f mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents: 4646
diff changeset
458 if err == "global-module-already-loaded" then
57a4f863e48f mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents: 4646
diff changeset
459 if count > 0 then
57a4f863e48f mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents: 4646
diff changeset
460 ok, err, count = true, nil, 1;
57a4f863e48f mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents: 4646
diff changeset
461 end
57a4f863e48f mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents: 4646
diff changeset
462 break;
57a4f863e48f mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents: 4646
diff changeset
463 end
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
464 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
465 else
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
466 count = count + 1;
4647
57a4f863e48f mod_admin_telnet: module:load(): Fix 'global-module-already-loaded' errors when successfully loading a global module (fixes #228)
Matthew Wild <mwild1@gmail.com>
parents: 4646
diff changeset
467 self.session.print("Loaded for "..mod.module.host);
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
468 end
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
469 end
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
470 end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
471
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
472 return ok, (ok and "Module loaded onto "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err));
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
473 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
474
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
475 function def_env.module:unload(name, hosts)
10507
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
476 hosts = get_hosts_with_module(hosts, name);
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
477
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
478 -- 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
479 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
480 for host in hosts do
6781
05cd80ec107c mod_admin_telnet: Remove now broken importing of modulemanager from various commands, use upvalue defined at top of file (thanks daurnimator)
Kim Alvefur <zash@zash.se>
parents: 6580
diff changeset
481 if modulemanager.is_loaded(host, name) then
05cd80ec107c mod_admin_telnet: Remove now broken importing of modulemanager from various commands, use upvalue defined at top of file (thanks daurnimator)
Kim Alvefur <zash@zash.se>
parents: 6580
diff changeset
482 ok, err = modulemanager.unload(host, name);
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
483 if not ok then
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
484 ok = false;
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
485 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
486 else
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
487 count = count + 1;
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
488 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
489 end
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
490 end
712
56410c0cd846 mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents: 669
diff changeset
491 end
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
492 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
493 end
56410c0cd846 mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents: 669
diff changeset
494
9332
048389a9bbd4 mod_admin_telnet: Split out sort function for clarity
Matthew Wild <mwild1@gmail.com>
parents: 9330
diff changeset
495 local function _sort_hosts(a, b)
048389a9bbd4 mod_admin_telnet: Split out sort function for clarity
Matthew Wild <mwild1@gmail.com>
parents: 9330
diff changeset
496 if a == "*" then return true
048389a9bbd4 mod_admin_telnet: Split out sort function for clarity
Matthew Wild <mwild1@gmail.com>
parents: 9330
diff changeset
497 elseif b == "*" then return false
10506
af214e2739f5 mod_admin_telnet: Merge hostname comparison functions
Kim Alvefur <zash@zash.se>
parents: 10505
diff changeset
498 else return a:gsub("[^.]+", string.reverse):reverse() < b:gsub("[^.]+", string.reverse):reverse(); end
9332
048389a9bbd4 mod_admin_telnet: Split out sort function for clarity
Matthew Wild <mwild1@gmail.com>
parents: 9330
diff changeset
499 end
048389a9bbd4 mod_admin_telnet: Split out sort function for clarity
Matthew Wild <mwild1@gmail.com>
parents: 9330
diff changeset
500
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
501 function def_env.module:reload(name, hosts)
10507
4d3549e64489 mod_admin_telnet: Refactor internal function for listing hosts
Kim Alvefur <zash@zash.se>
parents: 10506
diff changeset
502 hosts = array.collect(get_hosts_with_module(hosts, name)):sort(_sort_hosts)
4645
4539e99be743 mod_admin_telnet: module:reload(): If module is loaded on *, reload it there first (ensuring shared module code is reloaded before per-host children of that module)
Matthew Wild <mwild1@gmail.com>
parents: 4644
diff changeset
503
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
504 -- 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
505 local ok, err, count = true, nil, 0;
4645
4539e99be743 mod_admin_telnet: module:reload(): If module is loaded on *, reload it there first (ensuring shared module code is reloaded before per-host children of that module)
Matthew Wild <mwild1@gmail.com>
parents: 4644
diff changeset
506 for _, host in ipairs(hosts) do
6781
05cd80ec107c mod_admin_telnet: Remove now broken importing of modulemanager from various commands, use upvalue defined at top of file (thanks daurnimator)
Kim Alvefur <zash@zash.se>
parents: 6580
diff changeset
507 if modulemanager.is_loaded(host, name) then
05cd80ec107c mod_admin_telnet: Remove now broken importing of modulemanager from various commands, use upvalue defined at top of file (thanks daurnimator)
Kim Alvefur <zash@zash.se>
parents: 6580
diff changeset
508 ok, err = modulemanager.reload(host, name);
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
509 if not ok then
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
510 ok = false;
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
511 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
512 else
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
513 count = count + 1;
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
514 if ok == nil then
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
515 ok = true;
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
516 end
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
517 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
518 end
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
519 end
712
56410c0cd846 mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents: 669
diff changeset
520 end
1315
bfcd3f0a49df mod_console: Much improved module load/unload/reload commands
Matthew Wild <mwild1@gmail.com>
parents: 1241
diff changeset
521 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
522 end
56410c0cd846 mod_console: Added module:reload
Waqas Hussain <waqas20@gmail.com>
parents: 669
diff changeset
523
1906
88c61368e669 mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents: 1821
diff changeset
524 function def_env.module:list(hosts)
10508
edd323b30de1 mod_admin_telnet: Sort hosts in module:list
Kim Alvefur <zash@zash.se>
parents: 10507
diff changeset
525 hosts = array.collect(set.new({ not hosts and "*" or nil }) + get_hosts_set(hosts)):sort(_sort_hosts);
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
526
1906
88c61368e669 mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents: 1821
diff changeset
527 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
528 for _, host in ipairs(hosts) do
4646
e0bd8587f2fb mod_admin_telnet: module:list(): List global modules (part-fixes #228)
Matthew Wild <mwild1@gmail.com>
parents: 4645
diff changeset
529 print((host == "*" and "Global" or host)..":");
e0bd8587f2fb mod_admin_telnet: module:list(): List global modules (part-fixes #228)
Matthew Wild <mwild1@gmail.com>
parents: 4645
diff changeset
530 local modules = array.collect(keys(modulemanager.get_modules(host) or {})):sort();
1906
88c61368e669 mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents: 1821
diff changeset
531 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
532 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
533 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
534 else
1a4f14ea39b6 mod_console: Fixed traceback occuring on using module:list on unknown hosts.
Waqas Hussain <waqas20@gmail.com>
parents: 2009
diff changeset
535 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
536 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
537 else
88c61368e669 mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents: 1821
diff changeset
538 for _, name in ipairs(modules) do
9868
0361e3379dd1 mod_admin_telnet: Show module status in module:list()
Matthew Wild <mwild1@gmail.com>
parents: 9786
diff changeset
539 local status, status_text = modulemanager.get_module(host, name).module:get_status();
0361e3379dd1 mod_admin_telnet: Show module status in module:list()
Matthew Wild <mwild1@gmail.com>
parents: 9786
diff changeset
540 local status_summary = "";
0361e3379dd1 mod_admin_telnet: Show module status in module:list()
Matthew Wild <mwild1@gmail.com>
parents: 9786
diff changeset
541 if status == "warn" or status == "error" then
0361e3379dd1 mod_admin_telnet: Show module status in module:list()
Matthew Wild <mwild1@gmail.com>
parents: 9786
diff changeset
542 status_summary = (" (%s: %s)"):format(status, status_text);
0361e3379dd1 mod_admin_telnet: Show module status in module:list()
Matthew Wild <mwild1@gmail.com>
parents: 9786
diff changeset
543 end
0361e3379dd1 mod_admin_telnet: Show module status in module:list()
Matthew Wild <mwild1@gmail.com>
parents: 9786
diff changeset
544 print((" %s%s"):format(name, status_summary));
1906
88c61368e669 mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents: 1821
diff changeset
545 end
88c61368e669 mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents: 1821
diff changeset
546 end
88c61368e669 mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents: 1821
diff changeset
547 end
88c61368e669 mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents: 1821
diff changeset
548 end
88c61368e669 mod_console: Add module:list() command to show modules loaded on a host
Matthew Wild <mwild1@gmail.com>
parents: 1821
diff changeset
549
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
550 def_env.config = {};
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
551 function def_env.config:load(filename, format)
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
552 local config_load = require "core.configmanager".load;
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
553 local ok, err = config_load(filename, format);
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
554 if not ok then
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
555 return false, err or "Unknown error loading config";
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
556 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
557 return true, "Config loaded";
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
558 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
559
9753
3a14815f5430 mod_admin_telnet: Remove the long gone 'section' argument in the undocumented config:get command
Kim Alvefur <zash@zash.se>
parents: 9748
diff changeset
560 function def_env.config:get(host, key)
9754
cbbc6fefd07d mod_admin_telnet: config:get: Assume the global section if only one argument is given
Kim Alvefur <zash@zash.se>
parents: 9753
diff changeset
561 if key == nil then
cbbc6fefd07d mod_admin_telnet: config:get: Assume the global section if only one argument is given
Kim Alvefur <zash@zash.se>
parents: 9753
diff changeset
562 host, key = "*", host;
cbbc6fefd07d mod_admin_telnet: config:get: Assume the global section if only one argument is given
Kim Alvefur <zash@zash.se>
parents: 9753
diff changeset
563 end
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
564 local config_get = require "core.configmanager".get
10787
459efb1afbfe mod_admin_telnet: Pretty-print values returned from commands
Kim Alvefur <zash@zash.se>
parents: 10701
diff changeset
565 return true, serialize_config(config_get(host, key));
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
566 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
567
1558
e15917530285 mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents: 1556
diff changeset
568 function def_env.config:reload()
e15917530285 mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents: 1556
diff changeset
569 local ok, err = prosody.reload_config();
e15917530285 mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents: 1556
diff changeset
570 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
571 end
e15917530285 mod_console: Add config:reload() command
Matthew Wild <mwild1@gmail.com>
parents: 1556
diff changeset
572
6173
1600438c0c14 mod_admin_telnet: Move generation of log tag for s2s:show() (adds it to c2s:show() too)
Kim Alvefur <zash@zash.se>
parents: 6172
diff changeset
573 local function common_info(session, line)
1600438c0c14 mod_admin_telnet: Move generation of log tag for s2s:show() (adds it to c2s:show() too)
Kim Alvefur <zash@zash.se>
parents: 6172
diff changeset
574 if session.id then
1600438c0c14 mod_admin_telnet: Move generation of log tag for s2s:show() (adds it to c2s:show() too)
Kim Alvefur <zash@zash.se>
parents: 6172
diff changeset
575 line[#line+1] = "["..session.id.."]"
1600438c0c14 mod_admin_telnet: Move generation of log tag for s2s:show() (adds it to c2s:show() too)
Kim Alvefur <zash@zash.se>
parents: 6172
diff changeset
576 else
1600438c0c14 mod_admin_telnet: Move generation of log tag for s2s:show() (adds it to c2s:show() too)
Kim Alvefur <zash@zash.se>
parents: 6172
diff changeset
577 line[#line+1] = "["..session.type..(tostring(session):match("%x*$")).."]"
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
578 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
579 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
580
5586
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
581 local function session_flags(session, line)
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
582 line = line or {};
6173
1600438c0c14 mod_admin_telnet: Move generation of log tag for s2s:show() (adds it to c2s:show() too)
Kim Alvefur <zash@zash.se>
parents: 6172
diff changeset
583 common_info(session, line);
6171
c69fca37f338 mod_admin_telnet: Move extraction of c2s presence info into session_flags()
Kim Alvefur <zash@zash.se>
parents: 6170
diff changeset
584 if session.type == "c2s" then
c69fca37f338 mod_admin_telnet: Move extraction of c2s presence info into session_flags()
Kim Alvefur <zash@zash.se>
parents: 6170
diff changeset
585 local status, priority = "unavailable", tostring(session.priority or "-");
c69fca37f338 mod_admin_telnet: Move extraction of c2s presence info into session_flags()
Kim Alvefur <zash@zash.se>
parents: 6170
diff changeset
586 if session.presence then
c69fca37f338 mod_admin_telnet: Move extraction of c2s presence info into session_flags()
Kim Alvefur <zash@zash.se>
parents: 6170
diff changeset
587 status = session.presence:get_child_text("show") or "available";
c69fca37f338 mod_admin_telnet: Move extraction of c2s presence info into session_flags()
Kim Alvefur <zash@zash.se>
parents: 6170
diff changeset
588 end
c69fca37f338 mod_admin_telnet: Move extraction of c2s presence info into session_flags()
Kim Alvefur <zash@zash.se>
parents: 6170
diff changeset
589 line[#line+1] = status.."("..priority..")";
c69fca37f338 mod_admin_telnet: Move extraction of c2s presence info into session_flags()
Kim Alvefur <zash@zash.se>
parents: 6170
diff changeset
590 end
5586
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
591 if session.cert_identity_status == "valid" then
6170
1dff425ffe84 mod_admin_telnet: Split (secure) into (authenticated) + (secure)
Kim Alvefur <zash@zash.se>
parents: 6169
diff changeset
592 line[#line+1] = "(authenticated)";
1dff425ffe84 mod_admin_telnet: Split (secure) into (authenticated) + (secure)
Kim Alvefur <zash@zash.se>
parents: 6169
diff changeset
593 end
10383
496248e48a1d mod_admin_telnet: Show s2s authentication method (probably) used
Kim Alvefur <zash@zash.se>
parents: 10310
diff changeset
594 if session.dialback_key then
496248e48a1d mod_admin_telnet: Show s2s authentication method (probably) used
Kim Alvefur <zash@zash.se>
parents: 10310
diff changeset
595 line[#line+1] = "(dialback)";
496248e48a1d mod_admin_telnet: Show s2s authentication method (probably) used
Kim Alvefur <zash@zash.se>
parents: 10310
diff changeset
596 end
496248e48a1d mod_admin_telnet: Show s2s authentication method (probably) used
Kim Alvefur <zash@zash.se>
parents: 10310
diff changeset
597 if session.external_auth then
496248e48a1d mod_admin_telnet: Show s2s authentication method (probably) used
Kim Alvefur <zash@zash.se>
parents: 10310
diff changeset
598 line[#line+1] = "(SASL)";
496248e48a1d mod_admin_telnet: Show s2s authentication method (probably) used
Kim Alvefur <zash@zash.se>
parents: 10310
diff changeset
599 end
6170
1dff425ffe84 mod_admin_telnet: Split (secure) into (authenticated) + (secure)
Kim Alvefur <zash@zash.se>
parents: 6169
diff changeset
600 if session.secure then
5586
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
601 line[#line+1] = "(encrypted)";
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
602 end
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
603 if session.compressed then
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
604 line[#line+1] = "(compressed)";
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
605 end
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
606 if session.smacks then
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
607 line[#line+1] = "(sm)";
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
608 end
5662
685d46ec352b mod_admin_telnet: Simplify IPv6 detection, fixes rare traceback
Kim Alvefur <zash@zash.se>
parents: 5645
diff changeset
609 if session.ip and session.ip:match(":") then
5586
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
610 line[#line+1] = "(IPv6)";
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
611 end
6927
566e1cfcb814 mod_admin_telnet: c2s:show(): Add flag to indicate remote sessions
Matthew Wild <mwild1@gmail.com>
parents: 6838
diff changeset
612 if session.remote then
566e1cfcb814 mod_admin_telnet: c2s:show(): Add flag to indicate remote sessions
Matthew Wild <mwild1@gmail.com>
parents: 6838
diff changeset
613 line[#line+1] = "(remote)";
566e1cfcb814 mod_admin_telnet: c2s:show(): Add flag to indicate remote sessions
Matthew Wild <mwild1@gmail.com>
parents: 6838
diff changeset
614 end
10252
aa3f98853816 mod_admin_telnet: Identify native bidi sessions
Kim Alvefur <zash@zash.se>
parents: 10239
diff changeset
615 if session.incoming and session.outgoing then
aa3f98853816 mod_admin_telnet: Identify native bidi sessions
Kim Alvefur <zash@zash.se>
parents: 10239
diff changeset
616 line[#line+1] = "(bidi)";
aa3f98853816 mod_admin_telnet: Identify native bidi sessions
Kim Alvefur <zash@zash.se>
parents: 10239
diff changeset
617 elseif session.is_bidi or session.bidi_session then
9711
39dc037875e1 admin_telnet: show when bidi is used on s2s
Maxime “pep” Buquet <pep@bouah.net>
parents: 9691
diff changeset
618 line[#line+1] = "(bidi)";
39dc037875e1 admin_telnet: show when bidi is used on s2s
Maxime “pep” Buquet <pep@bouah.net>
parents: 9691
diff changeset
619 end
9988
cdf0b63a0d61 mod_admin_telnet: added "(bosh)" and "(websocket)" connection flags (#998)
Arc Riley <arcriley@gmail.com>
parents: 9987
diff changeset
620 if session.bosh_version then
cdf0b63a0d61 mod_admin_telnet: added "(bosh)" and "(websocket)" connection flags (#998)
Arc Riley <arcriley@gmail.com>
parents: 9987
diff changeset
621 line[#line+1] = "(bosh)";
cdf0b63a0d61 mod_admin_telnet: added "(bosh)" and "(websocket)" connection flags (#998)
Arc Riley <arcriley@gmail.com>
parents: 9987
diff changeset
622 end
cdf0b63a0d61 mod_admin_telnet: added "(bosh)" and "(websocket)" connection flags (#998)
Arc Riley <arcriley@gmail.com>
parents: 9987
diff changeset
623 if session.websocket_request then
cdf0b63a0d61 mod_admin_telnet: added "(bosh)" and "(websocket)" connection flags (#998)
Arc Riley <arcriley@gmail.com>
parents: 9987
diff changeset
624 line[#line+1] = "(websocket)";
cdf0b63a0d61 mod_admin_telnet: added "(bosh)" and "(websocket)" connection flags (#998)
Arc Riley <arcriley@gmail.com>
parents: 9987
diff changeset
625 end
5586
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
626 return table.concat(line, " ");
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
627 end
7e1264bf7af8 mod_admin_telnet: List session flags (encryption, compression etc) the same way for c2s as s2s
Kim Alvefur <zash@zash.se>
parents: 5579
diff changeset
628
6172
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
629 local function tls_info(session, line)
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
630 line = line or {};
6173
1600438c0c14 mod_admin_telnet: Move generation of log tag for s2s:show() (adds it to c2s:show() too)
Kim Alvefur <zash@zash.se>
parents: 6172
diff changeset
631 common_info(session, line);
6172
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
632 if session.secure then
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
633 local sock = session.conn and session.conn.socket and session.conn:socket();
10699
fd77b6cec38d mod_admin_telnet: Handle unavailable cipher info (fixes #1510)
Kim Alvefur <zash@zash.se>
parents: 10618
diff changeset
634 if sock then
fd77b6cec38d mod_admin_telnet: Handle unavailable cipher info (fixes #1510)
Kim Alvefur <zash@zash.se>
parents: 10618
diff changeset
635 local info = sock.info and sock:info();
fd77b6cec38d mod_admin_telnet: Handle unavailable cipher info (fixes #1510)
Kim Alvefur <zash@zash.se>
parents: 10618
diff changeset
636 if info then
fd77b6cec38d mod_admin_telnet: Handle unavailable cipher info (fixes #1510)
Kim Alvefur <zash@zash.se>
parents: 10618
diff changeset
637 line[#line+1] = ("(%s with %s)"):format(info.protocol, info.cipher);
fd77b6cec38d mod_admin_telnet: Handle unavailable cipher info (fixes #1510)
Kim Alvefur <zash@zash.se>
parents: 10618
diff changeset
638 else
fd77b6cec38d mod_admin_telnet: Handle unavailable cipher info (fixes #1510)
Kim Alvefur <zash@zash.se>
parents: 10618
diff changeset
639 -- TLS session might not be ready yet
fd77b6cec38d mod_admin_telnet: Handle unavailable cipher info (fixes #1510)
Kim Alvefur <zash@zash.se>
parents: 10618
diff changeset
640 line[#line+1] = "(cipher info unavailable)";
fd77b6cec38d mod_admin_telnet: Handle unavailable cipher info (fixes #1510)
Kim Alvefur <zash@zash.se>
parents: 10618
diff changeset
641 end
10644
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
642 if sock.getsniname then
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
643 local name = sock:getsniname();
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
644 if name then
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
645 line[#line+1] = ("(SNI:%q)"):format(name);
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
646 end
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
647 end
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
648 if sock.getalpn then
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
649 local proto = sock:getalpn();
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
650 if proto then
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
651 line[#line+1] = ("(ALPN:%q)"):format(proto);
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
652 end
6c4ab1b87588 mod_admin_telnet: Avoid indexing missing socket (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents: 10620
diff changeset
653 end
6172
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
654 end
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
655 else
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
656 line[#line+1] = "(insecure)";
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
657 end
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
658 return table.concat(line, " ");
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
659 end
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
660
1241
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
661 def_env.c2s = {};
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
662
7068
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
663 local function get_jid(session)
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
664 if session.username then
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
665 return session.full_jid or jid_join(session.username, session.host, session.resource);
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
666 end
7069
eae5d2f1311d mod_admin_telnet: Show unauthenticated clients identified by local/remote IP and port
Kim Alvefur <zash@zash.se>
parents: 7068
diff changeset
667
eae5d2f1311d mod_admin_telnet: Show unauthenticated clients identified by local/remote IP and port
Kim Alvefur <zash@zash.se>
parents: 7068
diff changeset
668 local conn = session.conn;
eae5d2f1311d mod_admin_telnet: Show unauthenticated clients identified by local/remote IP and port
Kim Alvefur <zash@zash.se>
parents: 7068
diff changeset
669 local ip = session.ip or "?";
eae5d2f1311d mod_admin_telnet: Show unauthenticated clients identified by local/remote IP and port
Kim Alvefur <zash@zash.se>
parents: 7068
diff changeset
670 local clientport = conn and conn:clientport() or "?";
eae5d2f1311d mod_admin_telnet: Show unauthenticated clients identified by local/remote IP and port
Kim Alvefur <zash@zash.se>
parents: 7068
diff changeset
671 local serverip = conn and conn.server and conn:server():ip() or "?";
eae5d2f1311d mod_admin_telnet: Show unauthenticated clients identified by local/remote IP and port
Kim Alvefur <zash@zash.se>
parents: 7068
diff changeset
672 local serverport = conn and conn:serverport() or "?"
eae5d2f1311d mod_admin_telnet: Show unauthenticated clients identified by local/remote IP and port
Kim Alvefur <zash@zash.se>
parents: 7068
diff changeset
673 return jid_join("["..ip.."]:"..clientport, session.host or "["..serverip.."]:"..serverport);
7068
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
674 end
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
675
10084
e4043e3928f2 mod_admin_telnet: Factor out function for collecting all c2s sessions for easier reuse
Kim Alvefur <zash@zash.se>
parents: 10083
diff changeset
676 local function get_c2s()
10083
f30d505e755b mod_admin_telnet: Include both c2s connections and sessions in c2s:show()
Kim Alvefur <zash@zash.se>
parents: 10068
diff changeset
677 local c2s = array.collect(values(prosody.full_sessions));
f30d505e755b mod_admin_telnet: Include both c2s connections and sessions in c2s:show()
Kim Alvefur <zash@zash.se>
parents: 10068
diff changeset
678 c2s:append(array.collect(values(module:shared"/*/c2s/sessions")));
10044
4fd27023224a mod_admin_telnet: Collect array from Bosh connections when appending to connection list
Michel Le Bihan <michel@lebihan.pl>
parents: 9989
diff changeset
679 c2s:append(array.collect(values(module:shared"/*/bosh/sessions")));
10083
f30d505e755b mod_admin_telnet: Include both c2s connections and sessions in c2s:show()
Kim Alvefur <zash@zash.se>
parents: 10068
diff changeset
680 c2s:unique();
10084
e4043e3928f2 mod_admin_telnet: Factor out function for collecting all c2s sessions for easier reuse
Kim Alvefur <zash@zash.se>
parents: 10083
diff changeset
681 return c2s;
e4043e3928f2 mod_admin_telnet: Factor out function for collecting all c2s sessions for easier reuse
Kim Alvefur <zash@zash.se>
parents: 10083
diff changeset
682 end
e4043e3928f2 mod_admin_telnet: Factor out function for collecting all c2s sessions for easier reuse
Kim Alvefur <zash@zash.se>
parents: 10083
diff changeset
683
1241
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
684 local function show_c2s(callback)
10084
e4043e3928f2 mod_admin_telnet: Factor out function for collecting all c2s sessions for easier reuse
Kim Alvefur <zash@zash.se>
parents: 10083
diff changeset
685 get_c2s():sort(function(a, b)
7068
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
686 if a.host == b.host then
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
687 if a.username == b.username then
7090
7aa37d70944b mod_admin_telnet: Fix sorting of JIDs in c2s:show() family of functions (thanks lookshe and Zash)
Matthew Wild <mwild1@gmail.com>
parents: 7070
diff changeset
688 return (a.resource or "") > (b.resource or "");
1241
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
689 end
7090
7aa37d70944b mod_admin_telnet: Fix sorting of JIDs in c2s:show() family of functions (thanks lookshe and Zash)
Matthew Wild <mwild1@gmail.com>
parents: 7070
diff changeset
690 return (a.username or "") > (b.username or "");
1241
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
691 end
10509
0aa0fd1adbb0 mod_admin_telnet: Use existing host comparison when comparing JIDs
Kim Alvefur <zash@zash.se>
parents: 10508
diff changeset
692 return _sort_hosts(a.host or "", b.host or "");
7068
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
693 end):map(function (session)
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
694 callback(get_jid(session), session)
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
695 end);
1241
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
696 end
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
697
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
698 function def_env.c2s:count()
10085
bf51a08a94a7 mod_admin_telnet: Make c2s:count() consistent with c2s:show()
Kim Alvefur <zash@zash.se>
parents: 10084
diff changeset
699 local c2s = get_c2s();
bf51a08a94a7 mod_admin_telnet: Make c2s:count() consistent with c2s:show()
Kim Alvefur <zash@zash.se>
parents: 10084
diff changeset
700 return true, "Total: ".. #c2s .." clients";
4779
9f2639b3d9b1 mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents: 4684
diff changeset
701 end
9f2639b3d9b1 mod_admin_telnet: Add c2s:count() which shows number of connected users.
Kim Alvefur <zash@zash.se>
parents: 4684
diff changeset
702
6174
513ea94761b2 mod_admin_telnet: Add c2s:show_tls(), behaves like s2s:show_tls()
Kim Alvefur <zash@zash.se>
parents: 6173
diff changeset
703 function def_env.c2s:show(match_jid, annotate)
1241
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
704 local print, count = self.session.print, 0;
6174
513ea94761b2 mod_admin_telnet: Add c2s:show_tls(), behaves like s2s:show_tls()
Kim Alvefur <zash@zash.se>
parents: 6173
diff changeset
705 annotate = annotate or session_flags;
7068
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
706 local curr_host = false;
1798
4c8f3fa9d926 mod_console: Show status and priority of clients
Matthew Wild <mwild1@gmail.com>
parents: 1616
diff changeset
707 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
708 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
709 curr_host = session.host;
7068
0c494bca43cb mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened
Kim Alvefur <zash@zash.se>
parents: 7067
diff changeset
710 print(curr_host or "(not connected to any host yet)");
1763
9e4ff3b66ed1 mod_console: c2s:show(): Group listed clients by host
Matthew Wild <mwild1@gmail.com>
parents: 1623
diff changeset
711 end
1241
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
712 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
713 count = count + 1;
6174
513ea94761b2 mod_admin_telnet: Add c2s:show_tls(), behaves like s2s:show_tls()
Kim Alvefur <zash@zash.se>
parents: 6173
diff changeset
714 print(annotate(session, { " ", jid }));
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
715 end
1241
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
716 end);
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
717 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
718 end
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
719
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
720 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
721 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
722 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
723 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
724 count = count + 1;
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
725 print(jid);
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
726 end
1241
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
727 end);
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
728 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
729 end
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
730
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
731 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
732 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
733 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
734 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
735 count = count + 1;
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
736 print(jid);
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
737 end
1241
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
738 end);
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
739 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
740 end
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
741
6174
513ea94761b2 mod_admin_telnet: Add c2s:show_tls(), behaves like s2s:show_tls()
Kim Alvefur <zash@zash.se>
parents: 6173
diff changeset
742 function def_env.c2s:show_tls(match_jid)
513ea94761b2 mod_admin_telnet: Add c2s:show_tls(), behaves like s2s:show_tls()
Kim Alvefur <zash@zash.se>
parents: 6173
diff changeset
743 return self:show(match_jid, tls_info);
513ea94761b2 mod_admin_telnet: Add c2s:show_tls(), behaves like s2s:show_tls()
Kim Alvefur <zash@zash.se>
parents: 6173
diff changeset
744 end
513ea94761b2 mod_admin_telnet: Add c2s:show_tls(), behaves like s2s:show_tls()
Kim Alvefur <zash@zash.se>
parents: 6173
diff changeset
745
10094
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
746 local function build_reason(text, condition)
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
747 if text or condition then
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
748 return {
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
749 text = text,
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
750 condition = condition or "undefined-condition",
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
751 };
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
752 end
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
753 end
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
754
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
755 function def_env.c2s:close(match_jid, text, condition)
5028
10a69a7e4545 mod_admin_telnet: Remove unused variable
Matthew Wild <mwild1@gmail.com>
parents: 5027
diff changeset
756 local count = 0;
1491
694a0a00e1a5 mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents: 1483
diff changeset
757 show_c2s(function (jid, session)
694a0a00e1a5 mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents: 1483
diff changeset
758 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
759 count = count + 1;
10094
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
760 session:close(build_reason(text, condition));
1491
694a0a00e1a5 mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents: 1483
diff changeset
761 end
694a0a00e1a5 mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents: 1483
diff changeset
762 end);
694a0a00e1a5 mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents: 1483
diff changeset
763 return true, "Total: "..count.." sessions closed";
694a0a00e1a5 mod_console: Add c2s:close() command
Matthew Wild <mwild1@gmail.com>
parents: 1483
diff changeset
764 end
1241
9c53fb182044 mod_console: c2s:show(), c2s:show_secure(), c2s:show_insecure()
Matthew Wild <mwild1@gmail.com>
parents: 1240
diff changeset
765
10094
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
766 function def_env.c2s:closeall(text, condition)
9974
c30933aa0242 mod_admin_telnet: Adds c2s:closeall() (Fixes #1315)
João Duarte <jvsDuarte08@gmail.com>
parents: 9868
diff changeset
767 local count = 0;
c30933aa0242 mod_admin_telnet: Adds c2s:closeall() (Fixes #1315)
João Duarte <jvsDuarte08@gmail.com>
parents: 9868
diff changeset
768 --luacheck: ignore 212/jid
c30933aa0242 mod_admin_telnet: Adds c2s:closeall() (Fixes #1315)
João Duarte <jvsDuarte08@gmail.com>
parents: 9868
diff changeset
769 show_c2s(function (jid, session)
c30933aa0242 mod_admin_telnet: Adds c2s:closeall() (Fixes #1315)
João Duarte <jvsDuarte08@gmail.com>
parents: 9868
diff changeset
770 count = count + 1;
10094
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
771 session:close(build_reason(text, condition));
9974
c30933aa0242 mod_admin_telnet: Adds c2s:closeall() (Fixes #1315)
João Duarte <jvsDuarte08@gmail.com>
parents: 9868
diff changeset
772 end);
c30933aa0242 mod_admin_telnet: Adds c2s:closeall() (Fixes #1315)
João Duarte <jvsDuarte08@gmail.com>
parents: 9868
diff changeset
773 return true, "Total: "..count.." sessions closed";
c30933aa0242 mod_admin_telnet: Adds c2s:closeall() (Fixes #1315)
João Duarte <jvsDuarte08@gmail.com>
parents: 9868
diff changeset
774 end
c30933aa0242 mod_admin_telnet: Adds c2s:closeall() (Fixes #1315)
João Duarte <jvsDuarte08@gmail.com>
parents: 9868
diff changeset
775
4514
ae48e0abc233 mod_admin_telnet: Commond and flexible way to show stream properties.
Kim Alvefur <zash@zash.se>
parents: 4328
diff changeset
776
1085
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
777 def_env.s2s = {};
6172
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
778 function def_env.s2s:show(match_jid, annotate)
1085
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
779 local print = self.session.print;
6172
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
780 annotate = annotate or session_flags;
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
781
1322
33d103b0283f mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1317
diff changeset
782 local count_in, count_out = 0,0;
5710
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
783 local s2s_list = { };
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
784
5710
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
785 local s2s_sessions = module:shared"/*/s2s/sessions";
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
786 for _, session in pairs(s2s_sessions) do
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
787 local remotehost, localhost, direction;
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
788 if session.direction == "outgoing" then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
789 direction = "->";
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
790 count_out = count_out + 1;
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
791 remotehost, localhost = session.to_host or "?", session.from_host or "?";
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
792 else
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
793 direction = "<-";
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
794 count_in = count_in + 1;
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
795 remotehost, localhost = session.from_host or "?", session.to_host or "?";
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
796 end
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
797 local sess_lines = { l = localhost, r = remotehost,
6173
1600438c0c14 mod_admin_telnet: Move generation of log tag for s2s:show() (adds it to c2s:show() too)
Kim Alvefur <zash@zash.se>
parents: 6172
diff changeset
798 annotate(session, { "", direction, remotehost or "?" })};
5710
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
799
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
800 if (not match_jid) or remotehost:match(match_jid) or localhost:match(match_jid) then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
801 table.insert(s2s_list, sess_lines);
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
802 -- luacheck: ignore 421/print
5710
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
803 local print = function (s) table.insert(sess_lines, " "..s); end
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
804 if session.sendq then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
805 print("There are "..#session.sendq.." queued outgoing stanzas for this connection");
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
806 end
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
807 if session.type == "s2sout_unauthed" then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
808 if session.connecting then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
809 print("Connection not yet established");
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
810 if not session.srv_hosts then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
811 if not session.conn then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
812 print("We do not yet have a DNS answer for this host's SRV records");
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
813 else
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
814 print("This host has no SRV records, using A record instead");
1085
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
815 end
5710
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
816 elseif session.srv_choice then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
817 print("We are on SRV record "..session.srv_choice.." of "..#session.srv_hosts);
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
818 local srv_choice = session.srv_hosts[session.srv_choice];
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
819 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
820 end
5710
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
821 elseif session.notopen then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
822 print("The <stream> has not yet been opened");
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
823 elseif not session.dialback_key then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
824 print("Dialback has not been initiated yet");
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
825 elseif session.dialback_key then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
826 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
827 end
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
828 end
5710
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
829 if session.type == "s2sin_unauthed" then
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
830 print("Connection not yet authenticated");
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
831 elseif session.type == "s2sin" then
1085
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
832 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
833 if name ~= session.from_host then
5710
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
834 print("also hosts "..tostring(name));
1085
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
835 end
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
836 end
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
837 end
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
838 end
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
839 end
5710
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
840
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
841 -- Sort by local host, then remote host
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
842 table.sort(s2s_list, function(a,b)
10510
fe0884ddb4f8 mod_admin_telnet: Use common sort function in s2s:show
Kim Alvefur <zash@zash.se>
parents: 10509
diff changeset
843 if a.l == b.l then return _sort_hosts(a.r, b.r); end
fe0884ddb4f8 mod_admin_telnet: Use common sort function in s2s:show
Kim Alvefur <zash@zash.se>
parents: 10509
diff changeset
844 return _sort_hosts(a.l, b.l);
5710
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
845 end);
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
846 local lasthost;
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
847 for _, sess_lines in ipairs(s2s_list) do
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
848 if sess_lines.l ~= lasthost then print(sess_lines.l); lasthost=sess_lines.l end
e66bbfdf588e mod_admin_telnet: Refactor s2s:show()
Kim Alvefur <zash@zash.se>
parents: 5709
diff changeset
849 for _, line in ipairs(sess_lines) do print(line); end
1085
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
850 end
1322
33d103b0283f mod_console: Show total incoming/outgoing s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1317
diff changeset
851 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
852 end
1ac11fb753ca mod_console: Add s2s:show() command to list s2s connections
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
853
6172
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
854 function def_env.s2s:show_tls(match_jid)
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
855 return self:show(match_jid, tls_info);
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
856 end
0205b97bb355 mod_admin_telnet: Add s2s:show_tls() for showing ciphers used on s2s connections
Kim Alvefur <zash@zash.se>
parents: 6171
diff changeset
857
3669
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
858 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
859 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
860 print(
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
861 (" %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
862 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
863 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
864 )
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
865 );
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
866 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
867 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
868
4328
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
869 -- 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
870 -- 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
871 -- break from that.
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
872 local function print_errors(print, errors)
5769
f6ea5b3739c9 mod_admin_telnet, mod_s2s: Fix reporting of certificate chain validation details
Kim Alvefur <zash@zash.se>
parents: 5672
diff changeset
873 for depth, t in pairs(errors) do
4328
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
874 print(
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
875 (" %d: %s"):format(
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
876 depth-1,
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
877 table.concat(t, "\n| ")
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
878 )
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
879 );
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
880 end
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
881 end
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
882
3669
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
883 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
884 local print = self.session.print;
5706
896094da72e4 mod_admin_telnet: Refactor s2s:showcert()
Kim Alvefur <zash@zash.se>
parents: 5674
diff changeset
885 local s2s_sessions = module:shared"/*/s2s/sessions";
896094da72e4 mod_admin_telnet: Refactor s2s:showcert()
Kim Alvefur <zash@zash.se>
parents: 5674
diff changeset
886 local domain_sessions = set.new(array.collect(values(s2s_sessions)))
896094da72e4 mod_admin_telnet: Refactor s2s:showcert()
Kim Alvefur <zash@zash.se>
parents: 5674
diff changeset
887 /function(session) return (session.to_host == domain or session.from_host == domain) and session or nil; end;
3669
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
888 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
889 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
890 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
891 conn = conn and conn:socket();
4328
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
892 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
893 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
894 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
895 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
896 else
5596
73fea1a87afd mod_admin_telnet: Don't rely on getpeerchain returning an empty list
Kim Alvefur <zash@zash.se>
parents: 5567
diff changeset
897 local cert = conn:getpeercertificate();
3669
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
898 if cert then
5596
73fea1a87afd mod_admin_telnet: Don't rely on getpeerchain returning an empty list
Kim Alvefur <zash@zash.se>
parents: 5567
diff changeset
899 local certs = conn:getpeerchain();
3669
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
900 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
901 if not cert_set[digest] then
4328
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
902 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
903 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
904 {
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
905 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
906 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
907 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
908 };
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
909 chain_valid = chain_valid;
4328
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
910 chain_errors = chain_errors;
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
911 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
912 };
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
913 else
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
914 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
915 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
916 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
917 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
918 });
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
919 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
920 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
921 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
922 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
923 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
924 -- 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
925 local n_certs = #domain_certs;
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
926
3669
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
927 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
928 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
929 end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
930
3669
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
931 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
932 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
933 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
934 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
935 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
936 end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
937
3669
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
938 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
939 local certs = cert_info.certs;
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
940 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
941 print("---")
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
942 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
943 print("");
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
944 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
945 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
946 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
947 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
948 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
949 else
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
950 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
951 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
952 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
953 print("");
4328
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
954 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
955 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
956 if chain_valid then
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
957 print("Trusted certificate: Yes");
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
958 else
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
959 print("Trusted certificate: No");
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
960 print_errors(print, errors);
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
961 end
c71777a8b9c7 mod_admin_telnet: Update to newer luasec.
Paul Aurich <paul@darkrain42.org>
parents: 3899
diff changeset
962 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
963 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
964 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
965 print("");
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
966 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
967 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
968 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
969 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
970 print("---");
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
971 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
972 ..(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
973 .." 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
974 end
4b56cd1302d4 mod_console: Add s2s:showcert() command to show the certificate for a domain
Matthew Wild <mwild1@gmail.com>
parents: 3652
diff changeset
975
10094
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
976 function def_env.s2s:close(from, to, text, condition)
1340
f707d0957155 mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents: 1322
diff changeset
977 local print, count = self.session.print, 0;
5708
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
978 local s2s_sessions = module:shared"/*/s2s/sessions";
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
979
5708
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
980 local match_id;
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
981 if from and not to then
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
982 match_id, from = from, nil;
5708
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
983 elseif not to then
1340
f707d0957155 mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents: 1322
diff changeset
984 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
985 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
986 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
987 end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
988
5708
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
989 for _, session in pairs(s2s_sessions) do
10095
a3c66d0294e1 mod_admin_telnet: Use already generated session id
Kim Alvefur <zash@zash.se>
parents: 10094
diff changeset
990 local id = session.id or (session.type..tostring(session):match("[a-f0-9]+$"));
5708
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
991 if (match_id and match_id == id)
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
992 or (session.from_host == from and session.to_host == to) then
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
993 print(("Closing connection from %s to %s [%s]"):format(session.from_host, session.to_host, id));
10094
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
994 (session.close or s2smanager.destroy_session)(session, build_reason(text, condition));
5708
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
995 count = count + 1 ;
1340
f707d0957155 mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents: 1322
diff changeset
996 end
f707d0957155 mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents: 1322
diff changeset
997 end
f707d0957155 mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents: 1322
diff changeset
998 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
999 end
f707d0957155 mod_console: Add s2s:close() to close s2s sessions between two hosts
Matthew Wild <mwild1@gmail.com>
parents: 1322
diff changeset
1000
10094
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
1001 function def_env.s2s:closeall(host, text, condition)
6838
229e95aecf41 mod_admin_telnet: Fix indentation
Kim Alvefur <zash@zash.se>
parents: 6781
diff changeset
1002 local count = 0;
5708
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
1003 local s2s_sessions = module:shared"/*/s2s/sessions";
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
1004 for _,session in pairs(s2s_sessions) do
667cf4e45356 mod_admin_telnet: Refactor s2s:close and s2s:closeall
Kim Alvefur <zash@zash.se>
parents: 5706
diff changeset
1005 if not host or session.from_host == host or session.to_host == host then
10094
6b1e89868328 mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
Kim Alvefur <zash@zash.se>
parents: 10087
diff changeset
1006 session:close(build_reason(text, condition));
6838
229e95aecf41 mod_admin_telnet: Fix indentation
Kim Alvefur <zash@zash.se>
parents: 6781
diff changeset
1007 count = count + 1;
4978
0b9e86302de4 mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents: 4913
diff changeset
1008 end
6838
229e95aecf41 mod_admin_telnet: Fix indentation
Kim Alvefur <zash@zash.se>
parents: 6781
diff changeset
1009 end
4978
0b9e86302de4 mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents: 4913
diff changeset
1010 if count == 0 then return false, "No sessions to close.";
0b9e86302de4 mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents: 4913
diff changeset
1011 else return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); end
0b9e86302de4 mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents: 4913
diff changeset
1012 end
0b9e86302de4 mod_admin_telnet: add s2s:closeall command and relative help entry.
Marco Cirillo <maranda@lightwitch.org>
parents: 4913
diff changeset
1013
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
1014 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
1015
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
1016 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
1017 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
1018 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
1019 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
1020 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
1021 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
1022
2007
b89d61db74d1 mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents: 1977
diff changeset
1023 function def_env.host:list()
b89d61db74d1 mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents: 1977
diff changeset
1024 local print = self.session.print;
b89d61db74d1 mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents: 1977
diff changeset
1025 local i = 0;
6175
50ddaec11f2a mod_admin_telnet: Show which hosts are components and what type of component in host:list()
Kim Alvefur <zash@zash.se>
parents: 6174
diff changeset
1026 local type;
10506
af214e2739f5 mod_admin_telnet: Merge hostname comparison functions
Kim Alvefur <zash@zash.se>
parents: 10505
diff changeset
1027 for host, host_session in iterators.sorted_pairs(prosody.hosts, _sort_hosts) do
2007
b89d61db74d1 mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents: 1977
diff changeset
1028 i = i + 1;
9330
36badabc85ce mod_admin_telnet: Make use of util.iterators.sorted_pairs()
Matthew Wild <mwild1@gmail.com>
parents: 9009
diff changeset
1029 type = host_session.type;
6175
50ddaec11f2a mod_admin_telnet: Show which hosts are components and what type of component in host:list()
Kim Alvefur <zash@zash.se>
parents: 6174
diff changeset
1030 if type == "local" then
50ddaec11f2a mod_admin_telnet: Show which hosts are components and what type of component in host:list()
Kim Alvefur <zash@zash.se>
parents: 6174
diff changeset
1031 print(host);
50ddaec11f2a mod_admin_telnet: Show which hosts are components and what type of component in host:list()
Kim Alvefur <zash@zash.se>
parents: 6174
diff changeset
1032 else
50ddaec11f2a mod_admin_telnet: Show which hosts are components and what type of component in host:list()
Kim Alvefur <zash@zash.se>
parents: 6174
diff changeset
1033 type = module:context(host):get_option_string("component_module", type);
50ddaec11f2a mod_admin_telnet: Show which hosts are components and what type of component in host:list()
Kim Alvefur <zash@zash.se>
parents: 6174
diff changeset
1034 if type ~= "component" then
50ddaec11f2a mod_admin_telnet: Show which hosts are components and what type of component in host:list()
Kim Alvefur <zash@zash.se>
parents: 6174
diff changeset
1035 type = type .. " component";
50ddaec11f2a mod_admin_telnet: Show which hosts are components and what type of component in host:list()
Kim Alvefur <zash@zash.se>
parents: 6174
diff changeset
1036 end
50ddaec11f2a mod_admin_telnet: Show which hosts are components and what type of component in host:list()
Kim Alvefur <zash@zash.se>
parents: 6174
diff changeset
1037 print(("%s (%s)"):format(host, type));
50ddaec11f2a mod_admin_telnet: Show which hosts are components and what type of component in host:list()
Kim Alvefur <zash@zash.se>
parents: 6174
diff changeset
1038 end
2007
b89d61db74d1 mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents: 1977
diff changeset
1039 end
b89d61db74d1 mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents: 1977
diff changeset
1040 return true, i.." hosts";
b89d61db74d1 mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents: 1977
diff changeset
1041 end
b89d61db74d1 mod_console: Add missing hosts:list() command
Matthew Wild <mwild1@gmail.com>
parents: 1977
diff changeset
1042
4674
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1043 def_env.port = {};
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1044
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1045 function def_env.port:list()
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1046 local print = self.session.print;
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1047 local services = portmanager.get_active_services().data;
9330
36badabc85ce mod_admin_telnet: Make use of util.iterators.sorted_pairs()
Matthew Wild <mwild1@gmail.com>
parents: 9009
diff changeset
1048 local n_services, n_ports = 0, 0;
9391
4001eb3f465a mod_admin_telnet: Fix local reference to util.iterator
Kim Alvefur <zash@zash.se>
parents: 9332
diff changeset
1049 for service, interfaces in iterators.sorted_pairs(services) do
9330
36badabc85ce mod_admin_telnet: Make use of util.iterators.sorted_pairs()
Matthew Wild <mwild1@gmail.com>
parents: 9009
diff changeset
1050 n_services = n_services + 1;
4674
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1051 local ports_list = {};
9330
36badabc85ce mod_admin_telnet: Make use of util.iterators.sorted_pairs()
Matthew Wild <mwild1@gmail.com>
parents: 9009
diff changeset
1052 for interface, ports in pairs(interfaces) do
4674
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1053 for port in pairs(ports) do
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1054 table.insert(ports_list, "["..interface.."]:"..port);
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1055 end
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1056 end
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1057 n_ports = n_ports + #ports_list;
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1058 print(service..": "..table.concat(ports_list, ", "));
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1059 end
9330
36badabc85ce mod_admin_telnet: Make use of util.iterators.sorted_pairs()
Matthew Wild <mwild1@gmail.com>
parents: 9009
diff changeset
1060 return true, n_services.." services listening on "..n_ports.." ports";
4674
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1061 end
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1062
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1063 function def_env.port:close(close_port, close_interface)
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1064 close_port = assert(tonumber(close_port), "Invalid port number");
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1065 local n_closed = 0;
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1066 local services = portmanager.get_active_services().data;
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
1067 for service, interfaces in pairs(services) do -- luacheck: ignore 213
4674
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1068 for interface, ports in pairs(interfaces) do
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1069 if not close_interface or close_interface == interface then
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1070 if ports[close_port] then
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1071 self.session.print("Closing ["..interface.."]:"..close_port.."...");
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1072 local ok, err = portmanager.close(interface, close_port)
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1073 if not ok then
5029
7bcd79631492 mod_admin_telnet: Fix usage of incorrect variable
Matthew Wild <mwild1@gmail.com>
parents: 5028
diff changeset
1074 self.session.print("Failed to close "..interface.." "..close_port..": "..err);
4674
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1075 else
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1076 n_closed = n_closed + 1;
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1077 end
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1078 end
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1079 end
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1080 end
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1081 end
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1082 return true, "Closed "..n_closed.." ports";
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1083 end
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1084
4807
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1085 def_env.muc = {};
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1086
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1087 local console_room_mt = {
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1088 __index = function (self, k) return self.room[k]; end;
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1089 __tostring = function (self)
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1090 return "MUC room <"..self.room.jid..">";
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1091 end;
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1092 };
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1093
5520
75230be5be58 mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents: 5278
diff changeset
1094 local function check_muc(jid)
75230be5be58 mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents: 5278
diff changeset
1095 local room_name, host = jid_split(jid);
9405
86e3e37f25ff mod_admin_telnet: Use prosody.hosts to be more explicit and avoid name clash with 'hosts' arguments [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9404
diff changeset
1096 if not prosody.hosts[host] then
4807
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1097 return nil, "No such host: "..host;
9405
86e3e37f25ff mod_admin_telnet: Use prosody.hosts to be more explicit and avoid name clash with 'hosts' arguments [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9404
diff changeset
1098 elseif not prosody.hosts[host].modules.muc then
4807
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1099 return nil, "Host '"..host.."' is not a MUC service";
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1100 end
5520
75230be5be58 mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents: 5278
diff changeset
1101 return room_name, host;
75230be5be58 mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents: 5278
diff changeset
1102 end
75230be5be58 mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents: 5278
diff changeset
1103
8876
9e72e63819dc console: Allow passing a config when creating a room
Kim Alvefur <zash@zash.se>
parents: 8591
diff changeset
1104 function def_env.muc:create(room_jid, config)
7471
3631d259bb85 mod_admin_telnet: rename variable to make it defined (room -> room_name)
Anton Shestakov <av6@dwimlabs.net>
parents: 7090
diff changeset
1105 local room_name, host = check_muc(room_jid);
6064
c4a3222165c4 mod_admin_telnet: muc:*: Fix nil index error when a room JID is passed with a non-existent host
Matthew Wild <mwild1@gmail.com>
parents: 6016
diff changeset
1106 if not room_name then
c4a3222165c4 mod_admin_telnet: muc:*: Fix nil index error when a room JID is passed with a non-existent host
Matthew Wild <mwild1@gmail.com>
parents: 6016
diff changeset
1107 return room_name, host;
c4a3222165c4 mod_admin_telnet: muc:*: Fix nil index error when a room JID is passed with a non-existent host
Matthew Wild <mwild1@gmail.com>
parents: 6016
diff changeset
1108 end
7471
3631d259bb85 mod_admin_telnet: rename variable to make it defined (room -> room_name)
Anton Shestakov <av6@dwimlabs.net>
parents: 7090
diff changeset
1109 if not room_name then return nil, host end
8876
9e72e63819dc console: Allow passing a config when creating a room
Kim Alvefur <zash@zash.se>
parents: 8591
diff changeset
1110 if config ~= nil and type(config) ~= "table" then return nil, "Config must be a table"; end
9405
86e3e37f25ff mod_admin_telnet: Use prosody.hosts to be more explicit and avoid name clash with 'hosts' arguments [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9404
diff changeset
1111 if prosody.hosts[host].modules.muc.get_room_from_jid(room_jid) then return nil, "Room exists already" end
86e3e37f25ff mod_admin_telnet: Use prosody.hosts to be more explicit and avoid name clash with 'hosts' arguments [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9404
diff changeset
1112 return prosody.hosts[host].modules.muc.create_room(room_jid, config);
5520
75230be5be58 mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents: 5278
diff changeset
1113 end
75230be5be58 mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents: 5278
diff changeset
1114
75230be5be58 mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents: 5278
diff changeset
1115 function def_env.muc:room(room_jid)
75230be5be58 mod_admin_telnet: Add muc:create(room) (thanks SkyBlue)
Matthew Wild <mwild1@gmail.com>
parents: 5278
diff changeset
1116 local room_name, host = check_muc(room_jid);
6064
c4a3222165c4 mod_admin_telnet: muc:*: Fix nil index error when a room JID is passed with a non-existent host
Matthew Wild <mwild1@gmail.com>
parents: 6016
diff changeset
1117 if not room_name then
c4a3222165c4 mod_admin_telnet: muc:*: Fix nil index error when a room JID is passed with a non-existent host
Matthew Wild <mwild1@gmail.com>
parents: 6016
diff changeset
1118 return room_name, host;
c4a3222165c4 mod_admin_telnet: muc:*: Fix nil index error when a room JID is passed with a non-existent host
Matthew Wild <mwild1@gmail.com>
parents: 6016
diff changeset
1119 end
9405
86e3e37f25ff mod_admin_telnet: Use prosody.hosts to be more explicit and avoid name clash with 'hosts' arguments [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9404
diff changeset
1120 local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
4807
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1121 if not room_obj then
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1122 return nil, "No such room: "..room_jid;
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1123 end
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1124 return setmetatable({ room = room_obj }, console_room_mt);
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1125 end
2999f0fd1347 mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
Matthew Wild <mwild1@gmail.com>
parents: 4779
diff changeset
1126
6260
6986ca575568 mod_admin_telnet: Add command to list MUC rooms
Matthew Wild <mwild1@gmail.com>
parents: 6176
diff changeset
1127 function def_env.muc:list(host)
9405
86e3e37f25ff mod_admin_telnet: Use prosody.hosts to be more explicit and avoid name clash with 'hosts' arguments [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9404
diff changeset
1128 local host_session = prosody.hosts[host];
6260
6986ca575568 mod_admin_telnet: Add command to list MUC rooms
Matthew Wild <mwild1@gmail.com>
parents: 6176
diff changeset
1129 if not host_session or not host_session.modules.muc then
6986ca575568 mod_admin_telnet: Add command to list MUC rooms
Matthew Wild <mwild1@gmail.com>
parents: 6176
diff changeset
1130 return nil, "Please supply the address of a local MUC component";
6986ca575568 mod_admin_telnet: Add command to list MUC rooms
Matthew Wild <mwild1@gmail.com>
parents: 6176
diff changeset
1131 end
6533
5da544e97bea mod_admin_telnet: Use the session-specific print function
Kim Alvefur <zash@zash.se>
parents: 6503
diff changeset
1132 local print = self.session.print;
6260
6986ca575568 mod_admin_telnet: Add command to list MUC rooms
Matthew Wild <mwild1@gmail.com>
parents: 6176
diff changeset
1133 local c = 0;
6270
ee2d5b2a263d mod_admin_telnet: Update muc:room(jid) and muc:list(host) to use the new MUC API
Waqas Hussain <waqas20@gmail.com>
parents: 6260
diff changeset
1134 for room in host_session.modules.muc.each_room() do
ee2d5b2a263d mod_admin_telnet: Update muc:room(jid) and muc:list(host) to use the new MUC API
Waqas Hussain <waqas20@gmail.com>
parents: 6260
diff changeset
1135 print(room.jid);
6260
6986ca575568 mod_admin_telnet: Add command to list MUC rooms
Matthew Wild <mwild1@gmail.com>
parents: 6176
diff changeset
1136 c = c + 1;
6986ca575568 mod_admin_telnet: Add command to list MUC rooms
Matthew Wild <mwild1@gmail.com>
parents: 6176
diff changeset
1137 end
6986ca575568 mod_admin_telnet: Add command to list MUC rooms
Matthew Wild <mwild1@gmail.com>
parents: 6176
diff changeset
1138 return true, c.." rooms";
6986ca575568 mod_admin_telnet: Add command to list MUC rooms
Matthew Wild <mwild1@gmail.com>
parents: 6176
diff changeset
1139 end
6986ca575568 mod_admin_telnet: Add command to list MUC rooms
Matthew Wild <mwild1@gmail.com>
parents: 6176
diff changeset
1140
5006
af7e563cf453 mod_admin_telnet: Add missing import of usermanager
Kim Alvefur <zash@zash.se>
parents: 5005
diff changeset
1141 local um = require"core.usermanager";
af7e563cf453 mod_admin_telnet: Add missing import of usermanager
Kim Alvefur <zash@zash.se>
parents: 5005
diff changeset
1142
4973
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1143 def_env.user = {};
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1144 function def_env.user:create(jid, password)
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1145 local username, host = jid_split(jid);
9405
86e3e37f25ff mod_admin_telnet: Use prosody.hosts to be more explicit and avoid name clash with 'hosts' arguments [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9404
diff changeset
1146 if not prosody.hosts[host] then
5598
3bb8aefd8ce0 mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
Kim Alvefur <zash@zash.se>
parents: 5596
diff changeset
1147 return nil, "No such host: "..host;
3bb8aefd8ce0 mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
Kim Alvefur <zash@zash.se>
parents: 5596
diff changeset
1148 elseif um.user_exists(username, host) then
5128
834ab74585ec mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents: 5030
diff changeset
1149 return nil, "User exists";
834ab74585ec mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents: 5030
diff changeset
1150 end
4973
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1151 local ok, err = um.create_user(username, password, host);
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1152 if ok then
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1153 return true, "User created";
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1154 else
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1155 return nil, "Could not create user: "..err;
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1156 end
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1157 end
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1158
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1159 function def_env.user:delete(jid)
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1160 local username, host = jid_split(jid);
9405
86e3e37f25ff mod_admin_telnet: Use prosody.hosts to be more explicit and avoid name clash with 'hosts' arguments [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9404
diff changeset
1161 if not prosody.hosts[host] then
5598
3bb8aefd8ce0 mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
Kim Alvefur <zash@zash.se>
parents: 5596
diff changeset
1162 return nil, "No such host: "..host;
5643
e612e1887e39 mod_admin_telnet: Fix inverted boolean logic
Kim Alvefur <zash@zash.se>
parents: 5630
diff changeset
1163 elseif not um.user_exists(username, host) then
5128
834ab74585ec mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents: 5030
diff changeset
1164 return nil, "No such user";
834ab74585ec mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents: 5030
diff changeset
1165 end
4973
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1166 local ok, err = um.delete_user(username, host);
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1167 if ok then
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1168 return true, "User deleted";
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1169 else
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1170 return nil, "Could not delete user: "..err;
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1171 end
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1172 end
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1173
5128
834ab74585ec mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents: 5030
diff changeset
1174 function def_env.user:password(jid, password)
4973
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1175 local username, host = jid_split(jid);
9405
86e3e37f25ff mod_admin_telnet: Use prosody.hosts to be more explicit and avoid name clash with 'hosts' arguments [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9404
diff changeset
1176 if not prosody.hosts[host] then
5598
3bb8aefd8ce0 mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
Kim Alvefur <zash@zash.se>
parents: 5596
diff changeset
1177 return nil, "No such host: "..host;
5665
da1881e1b35b mod_admin_telnet: Fix another wrong boolean expression
Kim Alvefur <zash@zash.se>
parents: 5643
diff changeset
1178 elseif not um.user_exists(username, host) then
5128
834ab74585ec mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents: 5030
diff changeset
1179 return nil, "No such user";
834ab74585ec mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents: 5030
diff changeset
1180 end
8192
4354f556c5db core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents: 8126
diff changeset
1181 local ok, err = um.set_password(username, password, host, nil);
4973
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1182 if ok then
5128
834ab74585ec mod_admin_telnet: Fix user:*, correct names, docs, do validation
Kim Alvefur <zash@zash.se>
parents: 5030
diff changeset
1183 return true, "User password changed";
4973
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1184 else
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1185 return nil, "Could not change password for user: "..err;
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1186 end
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1187 end
3f7248ac1a3b mod_admin_telnet: Add some user management commands.
Kim Alvefur <zash@zash.se>
parents: 4913
diff changeset
1188
5168
46fc0eff10b4 mod_admin_telnet: user:list(): Allow filtering the set of users
Kim Alvefur <zash@zash.se>
parents: 5167
diff changeset
1189 function def_env.user:list(host, pat)
5158
c363e7e77f79 mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents: 5133
diff changeset
1190 if not host then
c363e7e77f79 mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents: 5133
diff changeset
1191 return nil, "No host given";
9405
86e3e37f25ff mod_admin_telnet: Use prosody.hosts to be more explicit and avoid name clash with 'hosts' arguments [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9404
diff changeset
1192 elseif not prosody.hosts[host] then
5167
ecd9e300ec94 mod_admin_telnet: user:list() check that the given host exists
Kim Alvefur <zash@zash.se>
parents: 5159
diff changeset
1193 return nil, "No such host";
5158
c363e7e77f79 mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents: 5133
diff changeset
1194 end
c363e7e77f79 mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents: 5133
diff changeset
1195 local print = self.session.print;
5227
97f395938028 mod_admin_telnet: Improve wording when listing users
Kim Alvefur <zash@zash.se>
parents: 5186
diff changeset
1196 local total, matches = 0, 0;
5158
c363e7e77f79 mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents: 5133
diff changeset
1197 for user in um.users(host) do
5168
46fc0eff10b4 mod_admin_telnet: user:list(): Allow filtering the set of users
Kim Alvefur <zash@zash.se>
parents: 5167
diff changeset
1198 if not pat or user:match(pat) then
46fc0eff10b4 mod_admin_telnet: user:list(): Allow filtering the set of users
Kim Alvefur <zash@zash.se>
parents: 5167
diff changeset
1199 print(user.."@"..host);
5227
97f395938028 mod_admin_telnet: Improve wording when listing users
Kim Alvefur <zash@zash.se>
parents: 5186
diff changeset
1200 matches = matches + 1;
5168
46fc0eff10b4 mod_admin_telnet: user:list(): Allow filtering the set of users
Kim Alvefur <zash@zash.se>
parents: 5167
diff changeset
1201 end
5227
97f395938028 mod_admin_telnet: Improve wording when listing users
Kim Alvefur <zash@zash.se>
parents: 5186
diff changeset
1202 total = total + 1;
5158
c363e7e77f79 mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents: 5133
diff changeset
1203 end
5227
97f395938028 mod_admin_telnet: Improve wording when listing users
Kim Alvefur <zash@zash.se>
parents: 5186
diff changeset
1204 return true, "Showing "..(pat and (matches.." of ") or "all " )..total.." users";
5158
c363e7e77f79 mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents: 5133
diff changeset
1205 end
c363e7e77f79 mod_admin_telnet: Add support for listing users
Kim Alvefur <zash@zash.se>
parents: 5133
diff changeset
1206
5011
83b4d3727b4f mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents: 5007
diff changeset
1207 def_env.xmpp = {};
83b4d3727b4f mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents: 5007
diff changeset
1208
83b4d3727b4f mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents: 5007
diff changeset
1209 local st = require "util.stanza";
9736
a5ae3f4e1a40 mod_admin_telnet: Make xmpp:ping command wait and report the reply
Kim Alvefur <zash@zash.se>
parents: 9735
diff changeset
1210 local new_id = require "util.id".medium;
a5ae3f4e1a40 mod_admin_telnet: Make xmpp:ping command wait and report the reply
Kim Alvefur <zash@zash.se>
parents: 9735
diff changeset
1211 function def_env.xmpp:ping(localhost, remotehost, timeout)
9741
d46c376dfe2c mod_admin_telnet: Validate hostnames in xmpp:ping command
Kim Alvefur <zash@zash.se>
parents: 9736
diff changeset
1212 localhost = select(2, jid_split(localhost));
d46c376dfe2c mod_admin_telnet: Validate hostnames in xmpp:ping command
Kim Alvefur <zash@zash.se>
parents: 9736
diff changeset
1213 remotehost = select(2, jid_split(remotehost));
d46c376dfe2c mod_admin_telnet: Validate hostnames in xmpp:ping command
Kim Alvefur <zash@zash.se>
parents: 9736
diff changeset
1214 if not localhost then
d46c376dfe2c mod_admin_telnet: Validate hostnames in xmpp:ping command
Kim Alvefur <zash@zash.se>
parents: 9736
diff changeset
1215 return nil, "Invalid sender hostname";
d46c376dfe2c mod_admin_telnet: Validate hostnames in xmpp:ping command
Kim Alvefur <zash@zash.se>
parents: 9736
diff changeset
1216 elseif not prosody.hosts[localhost] then
d46c376dfe2c mod_admin_telnet: Validate hostnames in xmpp:ping command
Kim Alvefur <zash@zash.se>
parents: 9736
diff changeset
1217 return nil, "No such local host";
d46c376dfe2c mod_admin_telnet: Validate hostnames in xmpp:ping command
Kim Alvefur <zash@zash.se>
parents: 9736
diff changeset
1218 end
d46c376dfe2c mod_admin_telnet: Validate hostnames in xmpp:ping command
Kim Alvefur <zash@zash.se>
parents: 9736
diff changeset
1219 if not remotehost then
d46c376dfe2c mod_admin_telnet: Validate hostnames in xmpp:ping command
Kim Alvefur <zash@zash.se>
parents: 9736
diff changeset
1220 return nil, "Invalid destination hostname";
d46c376dfe2c mod_admin_telnet: Validate hostnames in xmpp:ping command
Kim Alvefur <zash@zash.se>
parents: 9736
diff changeset
1221 elseif prosody.hosts[remotehost] then
d46c376dfe2c mod_admin_telnet: Validate hostnames in xmpp:ping command
Kim Alvefur <zash@zash.se>
parents: 9736
diff changeset
1222 return nil, "Both hosts are local";
5011
83b4d3727b4f mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents: 5007
diff changeset
1223 end
9736
a5ae3f4e1a40 mod_admin_telnet: Make xmpp:ping command wait and report the reply
Kim Alvefur <zash@zash.se>
parents: 9735
diff changeset
1224 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()}
a5ae3f4e1a40 mod_admin_telnet: Make xmpp:ping command wait and report the reply
Kim Alvefur <zash@zash.se>
parents: 9735
diff changeset
1225 :tag("ping", {xmlns="urn:xmpp:ping"});
10310
b03065cd033a mod_admin_telnet: xmpp:ping: Log ping time
Kim Alvefur <zash@zash.se>
parents: 10292
diff changeset
1226 local time_start = time.now();
10292
8fb546e40756 mod_admin_telnet: Use new compact function for waiting on promises
Kim Alvefur <zash@zash.se>
parents: 10252
diff changeset
1227 local ret, err = async.wait(module:context(localhost):send_iq(iq, nil, timeout));
9736
a5ae3f4e1a40 mod_admin_telnet: Make xmpp:ping command wait and report the reply
Kim Alvefur <zash@zash.se>
parents: 9735
diff changeset
1228 if ret then
10310
b03065cd033a mod_admin_telnet: xmpp:ping: Log ping time
Kim Alvefur <zash@zash.se>
parents: 10292
diff changeset
1229 return true, ("pong from %s in %gs"):format(ret.stanza.attr.from, time.now() - time_start);
5011
83b4d3727b4f mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents: 5007
diff changeset
1230 else
9736
a5ae3f4e1a40 mod_admin_telnet: Make xmpp:ping command wait and report the reply
Kim Alvefur <zash@zash.se>
parents: 9735
diff changeset
1231 return false, tostring(err);
5011
83b4d3727b4f mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents: 5007
diff changeset
1232 end
83b4d3727b4f mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents: 5007
diff changeset
1233 end
83b4d3727b4f mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections
Kim Alvefur <zash@zash.se>
parents: 5007
diff changeset
1234
5567
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1235 def_env.dns = {};
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1236 local adns = require"net.adns";
10618
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1237
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1238 local function get_resolver(session)
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1239 local resolver = session.dns_resolver;
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1240 if not resolver then
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1241 resolver = adns.resolver();
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1242 session.dns_resolver = resolver;
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1243 end
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1244 return resolver;
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1245 end
5567
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1246
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1247 function def_env.dns:lookup(name, typ, class)
10618
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1248 local resolver = get_resolver(self.session);
10620
09d98cd38fe2 mod_admin_telnet: Use promise based DNS resolving
Kim Alvefur <zash@zash.se>
parents: 10619
diff changeset
1249 local ret, err = async.wait(resolver:lookup_promise(name, typ, class));
09d98cd38fe2 mod_admin_telnet: Use promise based DNS resolving
Kim Alvefur <zash@zash.se>
parents: 10619
diff changeset
1250 if ret then
09d98cd38fe2 mod_admin_telnet: Use promise based DNS resolving
Kim Alvefur <zash@zash.se>
parents: 10619
diff changeset
1251 return true, ret;
09d98cd38fe2 mod_admin_telnet: Use promise based DNS resolving
Kim Alvefur <zash@zash.se>
parents: 10619
diff changeset
1252 elseif err then
09d98cd38fe2 mod_admin_telnet: Use promise based DNS resolving
Kim Alvefur <zash@zash.se>
parents: 10619
diff changeset
1253 return false, err;
5567
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1254 end
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1255 end
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1256
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1257 function def_env.dns:addnameserver(...)
10618
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1258 local resolver = get_resolver(self.session);
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1259 resolver._resolver:addnameserver(...)
5567
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1260 return true
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1261 end
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1262
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1263 function def_env.dns:setnameserver(...)
10618
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1264 local resolver = get_resolver(self.session);
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1265 resolver._resolver:setnameserver(...)
5567
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1266 return true
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1267 end
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1268
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1269 function def_env.dns:purge()
10618
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1270 local resolver = get_resolver(self.session);
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1271 resolver._resolver:purge()
5567
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1272 return true
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1273 end
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1274
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1275 function def_env.dns:cache()
10618
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1276 local resolver = get_resolver(self.session);
232841373711 mod_admin_telnet: Create a DNS resolver per console session (fixes #1492)
Kim Alvefur <zash@zash.se>
parents: 9454
diff changeset
1277 return true, "Cache:\n"..tostring(resolver._resolver.cache)
5567
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1278 end
c4ab25b35a55 mod_admin_telnet: Add some DNS commands.
Kim Alvefur <zash@zash.se>
parents: 5520
diff changeset
1279
7029
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1280 def_env.http = {};
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1281
10663
fd651ba2317f mod_admin_telnet: Allow passing list of hosts to http:list()
Kim Alvefur <zash@zash.se>
parents: 10658
diff changeset
1282 function def_env.http:list(hosts)
7029
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1283 local print = self.session.print;
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1284
10663
fd651ba2317f mod_admin_telnet: Allow passing list of hosts to http:list()
Kim Alvefur <zash@zash.se>
parents: 10658
diff changeset
1285 for host in get_hosts_set(hosts) do
7029
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1286 local http_apps = modulemanager.get_items("http-provider", host);
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1287 if #http_apps > 0 then
7977
01d6298de991 plugins/various: Use type-specific config API
Kim Alvefur <zash@zash.se>
parents: 7911
diff changeset
1288 local http_host = module:context(host):get_option_string("http_host");
7029
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1289 print("HTTP endpoints on "..host..(http_host and (" (using "..http_host.."):") or ":"));
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1290 for _, provider in ipairs(http_apps) do
8589
4e475ef4b569 mod_admin_telnet: Include the default path property in URL calculation (fixes #1099)
Kim Alvefur <zash@zash.se>
parents: 7029
diff changeset
1291 local url = module:context(host):http_url(provider.name, provider.default_path);
7029
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1292 print("", url);
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1293 end
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1294 print("");
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1295 end
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1296 end
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1297
7977
01d6298de991 plugins/various: Use type-specific config API
Kim Alvefur <zash@zash.se>
parents: 7911
diff changeset
1298 local default_host = module:get_option_string("http_default_host");
7029
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1299 if not default_host then
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1300 print("HTTP requests to unknown hosts will return 404 Not Found");
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1301 else
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1302 print("HTTP requests to unknown hosts will be handled by "..default_host);
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1303 end
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1304 return true;
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1305 end
b2d160baa957 mod_admin_telnet: Backport 06696882d972 from 0.10 (this command greatly helps with debugging HTTP issues)
Matthew Wild <mwild1@gmail.com>
parents: 6578
diff changeset
1306
8921
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1307 def_env.debug = {};
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1308
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1309 function def_env.debug:logevents(host)
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1310 helpers.log_host_events(host);
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1311 return true;
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1312 end
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1313
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1314 function def_env.debug:events(host, event)
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1315 local events_obj;
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1316 if host and host ~= "*" then
9454
6780049be177 mod_admin_telnet: Allow viewing HTTP event listeners via debug:events('http')
Matthew Wild <mwild1@gmail.com>
parents: 9411
diff changeset
1317 if host == "http" then
6780049be177 mod_admin_telnet: Allow viewing HTTP event listeners via debug:events('http')
Matthew Wild <mwild1@gmail.com>
parents: 9411
diff changeset
1318 events_obj = require "net.http.server"._events;
6780049be177 mod_admin_telnet: Allow viewing HTTP event listeners via debug:events('http')
Matthew Wild <mwild1@gmail.com>
parents: 9411
diff changeset
1319 elseif not prosody.hosts[host] then
8921
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1320 return false, "Unknown host: "..host;
9454
6780049be177 mod_admin_telnet: Allow viewing HTTP event listeners via debug:events('http')
Matthew Wild <mwild1@gmail.com>
parents: 9411
diff changeset
1321 else
6780049be177 mod_admin_telnet: Allow viewing HTTP event listeners via debug:events('http')
Matthew Wild <mwild1@gmail.com>
parents: 9411
diff changeset
1322 events_obj = prosody.hosts[host].events;
8921
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1323 end
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1324 else
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1325 events_obj = prosody.events;
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1326 end
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1327 return true, helpers.show_events(events_obj, event);
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1328 end
1c2925376315 mod_admin_telnet: Add debug:events() and debug:logevents()
Matthew Wild <mwild1@gmail.com>
parents: 8590
diff changeset
1329
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
1330 function def_env.debug:timers()
9009
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1331 local print = self.session.print;
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1332 local add_task = require"util.timer".add_task;
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1333 local h, params = add_task.h, add_task.params;
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1334 if h then
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1335 print("-- util.timer");
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1336 for i, id in ipairs(h.ids) do
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1337 if not params[id] then
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1338 print(os.date("%F %T", h.priorities[i]), h.items[id]);
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1339 elseif not params[id].callback then
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1340 print(os.date("%F %T", h.priorities[i]), h.items[id], unpack(params[id]));
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1341 else
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1342 print(os.date("%F %T", h.priorities[i]), params[id].callback, unpack(params[id]));
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1343 end
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1344 end
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1345 end
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1346 if server.event_base then
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1347 local count = 0;
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
1348 for _, v in pairs(debug.getregistry()) do
9009
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1349 if type(v) == "function" and v.callback and v.callback == add_task._on_timer then
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1350 count = count + 1;
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1351 end
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1352 end
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1353 print(count .. " libevent callbacks");
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1354 end
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1355 if h then
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1356 local next_time = h:peek();
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1357 if next_time then
10489
fabe50ea39f2 mod_admin_telnet: Avoid using LuaSocket for timestamps
Kim Alvefur <zash@zash.se>
parents: 10470
diff changeset
1358 return true, os.date("Next event at %F %T (in %%.6fs)", next_time):format(next_time - time.now());
9009
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1359 end
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1360 end
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1361 return true;
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1362 end
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1363
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1364 -- COMPAT: debug:timers() was timer:info() for some time in trunk
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1365 def_env.timer = { info = def_env.debug.timers };
4c745d42c974 mod_admin_telnet: Rename timer:info() -> debug:timers()
Matthew Wild <mwild1@gmail.com>
parents: 8964
diff changeset
1366
7911
e528d848a185 mod_admin_telnet: Print a message to open sessions when shutting down, including the reason
Kim Alvefur <zash@zash.se>
parents: 7722
diff changeset
1367 module:hook("server-stopping", function(event)
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
1368 for _, session in pairs(sessions) do
7911
e528d848a185 mod_admin_telnet: Print a message to open sessions when shutting down, including the reason
Kim Alvefur <zash@zash.se>
parents: 7722
diff changeset
1369 session.print("Shutting down: "..(event.reason or "unknown reason"));
e528d848a185 mod_admin_telnet: Print a message to open sessions when shutting down, including the reason
Kim Alvefur <zash@zash.se>
parents: 7722
diff changeset
1370 end
e528d848a185 mod_admin_telnet: Print a message to open sessions when shutting down, including the reason
Kim Alvefur <zash@zash.se>
parents: 7722
diff changeset
1371 end);
e528d848a185 mod_admin_telnet: Print a message to open sessions when shutting down, including the reason
Kim Alvefur <zash@zash.se>
parents: 7722
diff changeset
1372
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1373 def_env.stats = {};
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1374
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1375 local function format_stat(type, value, ref_value)
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1376 ref_value = ref_value or value;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1377 --do return tostring(value) end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1378 if type == "duration" then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1379 if ref_value < 0.001 then
9786
00f7af0be849 mod_admin_telnet: sttas:show: Use format option that allows float numbers
Kim Alvefur <zash@zash.se>
parents: 9756
diff changeset
1380 return ("%g µs"):format(value*1000000);
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1381 elseif ref_value < 0.9 then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1382 return ("%0.2f ms"):format(value*1000);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1383 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1384 return ("%0.2f"):format(value);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1385 elseif type == "size" then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1386 if ref_value > 1048576 then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1387 return ("%d MB"):format(value/1048576);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1388 elseif ref_value > 1024 then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1389 return ("%d KB"):format(value/1024);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1390 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1391 return ("%d bytes"):format(value);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1392 elseif type == "rate" then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1393 if ref_value < 0.9 then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1394 return ("%0.2f/min"):format(value*60);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1395 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1396 return ("%0.2f/sec"):format(value);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1397 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1398 return tostring(value);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1399 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1400
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1401 local stats_methods = {};
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1402 function stats_methods:bounds(_lower, _upper)
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1403 for _, stat_info in ipairs(self) do
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1404 local data = stat_info[4];
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1405 if data then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1406 local lower = _lower or data.min;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1407 local upper = _upper or data.max;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1408 local new_data = {
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1409 min = lower;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1410 max = upper;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1411 samples = {};
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1412 sample_count = 0;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1413 count = data.count;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1414 units = data.units;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1415 };
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1416 local sum = 0;
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
1417 for _, v in ipairs(data.samples) do
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1418 if v > upper then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1419 break;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1420 elseif v>=lower then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1421 table.insert(new_data.samples, v);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1422 sum = sum + v;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1423 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1424 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1425 new_data.sample_count = #new_data.samples;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1426 stat_info[4] = new_data;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1427 stat_info[3] = sum/new_data.sample_count;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1428 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1429 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1430 return self;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1431 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1432
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1433 function stats_methods:trim(lower, upper)
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1434 upper = upper or (100-lower);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1435 local statistics = require "util.statistics";
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1436 for _, stat_info in ipairs(self) do
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1437 -- Strip outliers
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1438 local data = stat_info[4];
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1439 if data then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1440 local new_data = {
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1441 min = statistics.get_percentile(data, lower);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1442 max = statistics.get_percentile(data, upper);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1443 samples = {};
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1444 sample_count = 0;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1445 count = data.count;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1446 units = data.units;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1447 };
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1448 local sum = 0;
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
1449 for _, v in ipairs(data.samples) do
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1450 if v > new_data.max then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1451 break;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1452 elseif v>=new_data.min then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1453 table.insert(new_data.samples, v);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1454 sum = sum + v;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1455 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1456 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1457 new_data.sample_count = #new_data.samples;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1458 stat_info[4] = new_data;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1459 stat_info[3] = sum/new_data.sample_count;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1460 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1461 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1462 return self;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1463 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1464
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1465 function stats_methods:max(upper)
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1466 return self:bounds(nil, upper);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1467 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1468
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1469 function stats_methods:min(lower)
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1470 return self:bounds(lower, nil);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1471 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1472
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1473 function stats_methods:summary()
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1474 local statistics = require "util.statistics";
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1475 for _, stat_info in ipairs(self) do
9408
b4a82b726495 mod_admin_telnet: Remove unused variable [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9406
diff changeset
1476 local type, value, data = stat_info[2], stat_info[3], stat_info[4];
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1477 if data and data.samples then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1478 table.insert(stat_info.output, string.format("Count: %d (%d captured)",
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1479 data.count,
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1480 data.sample_count
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1481 ));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1482 table.insert(stat_info.output, string.format("Min: %s Mean: %s Max: %s",
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1483 format_stat(type, data.min),
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1484 format_stat(type, value),
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1485 format_stat(type, data.max)
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1486 ));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1487 table.insert(stat_info.output, string.format("Q1: %s Median: %s Q3: %s",
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1488 format_stat(type, statistics.get_percentile(data, 25)),
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1489 format_stat(type, statistics.get_percentile(data, 50)),
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1490 format_stat(type, statistics.get_percentile(data, 75))
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1491 ));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1492 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1493 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1494 return self;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1495 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1496
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1497 function stats_methods:cfgraph()
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1498 for _, stat_info in ipairs(self) do
10544
0bd408d93f9a mod_admin_telnet: Silence luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 10517
diff changeset
1499 local name, type, value, data = unpack(stat_info, 1, 4); -- luacheck: ignore 211
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1500 local function print(s)
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1501 table.insert(stat_info.output, s);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1502 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1503
9411
62c876e333e4 mod_admin_telnet: Guard against missing table field
Kim Alvefur <zash@zash.se>
parents: 9410
diff changeset
1504 if data and data.sample_count and data.sample_count > 0 then
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1505 local raw_histogram = require "util.statistics".get_histogram(data);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1506
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1507 local graph_width, graph_height = 50, 10;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1508 local eighth_chars = " ▁▂▃▄▅▆▇█";
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1509
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1510 local range = data.max - data.min;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1511
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1512 if range > 0 then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1513 local x_scaling = #raw_histogram/graph_width;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1514 local histogram = {};
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1515 for i = 1, graph_width do
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1516 histogram[i] = math.max(raw_histogram[i*x_scaling-1] or 0, raw_histogram[i*x_scaling] or 0);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1517 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1518
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1519 print("");
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1520 print(("_"):rep(52)..format_stat(type, data.max));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1521 for row = graph_height, 1, -1 do
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1522 local row_chars = {};
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1523 local min_eighths, max_eighths = 8, 0;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1524 for i = 1, #histogram do
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1525 local char_eighths = math.ceil(math.max(math.min((graph_height/(data.max/histogram[i]))-(row-1), 1), 0)*8);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1526 if char_eighths < min_eighths then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1527 min_eighths = char_eighths;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1528 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1529 if char_eighths > max_eighths then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1530 max_eighths = char_eighths;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1531 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1532 if char_eighths == 0 then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1533 row_chars[i] = "-";
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1534 else
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1535 local char = eighth_chars:sub(char_eighths*3+1, char_eighths*3+3);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1536 row_chars[i] = char;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1537 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1538 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1539 print(table.concat(row_chars).."|-"..format_stat(type, data.max/(graph_height/(row-0.5))));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1540 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1541 print(("\\ "):rep(11));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1542 local x_labels = {};
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1543 for i = 1, 11 do
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1544 local s = ("%-4s"):format((i-1)*10);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1545 if #s > 4 then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1546 s = s:sub(1, 3).."…";
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1547 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1548 x_labels[i] = s;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1549 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1550 print(" "..table.concat(x_labels, " "));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1551 local units = "%";
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1552 local margin = math.floor((graph_width-#units)/2);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1553 print((" "):rep(margin)..units);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1554 else
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1555 print("[range too small to graph]");
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1556 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1557 print("");
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1558 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1559 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1560 return self;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1561 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1562
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1563 function stats_methods:histogram()
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1564 for _, stat_info in ipairs(self) do
10544
0bd408d93f9a mod_admin_telnet: Silence luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 10517
diff changeset
1565 local name, type, value, data = unpack(stat_info, 1, 4); -- luacheck: ignore 211
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1566 local function print(s)
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1567 table.insert(stat_info.output, s);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1568 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1569
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1570 if not data then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1571 print("[no data]");
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1572 return self;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1573 elseif not data.sample_count then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1574 print("[not a sampled metric type]");
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1575 return self;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1576 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1577
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1578 local graph_width, graph_height = 50, 10;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1579 local eighth_chars = " ▁▂▃▄▅▆▇█";
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1580
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1581 local range = data.max - data.min;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1582
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1583 if range > 0 then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1584 local n_buckets = graph_width;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1585
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1586 local histogram = {};
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1587 for i = 1, n_buckets do
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1588 histogram[i] = 0;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1589 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1590 local max_bin_samples = 0;
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
1591 for _, d in ipairs(data.samples) do
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1592 local bucket = math.floor(1+(n_buckets-1)/(range/(d-data.min)));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1593 histogram[bucket] = histogram[bucket] + 1;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1594 if histogram[bucket] > max_bin_samples then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1595 max_bin_samples = histogram[bucket];
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1596 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1597 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1598
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1599 print("");
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1600 print(("_"):rep(52)..max_bin_samples);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1601 for row = graph_height, 1, -1 do
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1602 local row_chars = {};
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1603 local min_eighths, max_eighths = 8, 0;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1604 for i = 1, #histogram do
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1605 local char_eighths = math.ceil(math.max(math.min((graph_height/(max_bin_samples/histogram[i]))-(row-1), 1), 0)*8);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1606 if char_eighths < min_eighths then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1607 min_eighths = char_eighths;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1608 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1609 if char_eighths > max_eighths then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1610 max_eighths = char_eighths;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1611 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1612 if char_eighths == 0 then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1613 row_chars[i] = "-";
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1614 else
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1615 local char = eighth_chars:sub(char_eighths*3+1, char_eighths*3+3);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1616 row_chars[i] = char;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1617 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1618 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1619 print(table.concat(row_chars).."|-"..math.ceil((max_bin_samples/graph_height)*(row-0.5)));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1620 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1621 print(("\\ "):rep(11));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1622 local x_labels = {};
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1623 for i = 1, 11 do
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1624 local s = ("%-4s"):format(format_stat(type, data.min+range*i/11, data.min):match("^%S+"));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1625 if #s > 4 then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1626 s = s:sub(1, 3).."…";
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1627 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1628 x_labels[i] = s;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1629 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1630 print(" "..table.concat(x_labels, " "));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1631 local units = format_stat(type, data.min):match("%s+(.+)$") or data.units or "";
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1632 local margin = math.floor((graph_width-#units)/2);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1633 print((" "):rep(margin)..units);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1634 else
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1635 print("[range too small to graph]");
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1636 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1637 print("");
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1638 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1639 return self;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1640 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1641
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1642 local function stats_tostring(stats)
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1643 local print = stats.session.print;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1644 for _, stat_info in ipairs(stats) do
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1645 if #stat_info.output > 0 then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1646 print("\n#"..stat_info[1]);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1647 print("");
9404
f40b0cd41a87 mod_admin_telnet: Remove or rename various unused arguments and variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
1648 for _, v in ipairs(stat_info.output) do
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1649 print(v);
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1650 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1651 print("");
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1652 else
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1653 print(("%-50s %s"):format(stat_info[1], format_stat(stat_info[2], stat_info[3])));
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1654 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1655 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1656 return #stats.." statistics displayed";
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1657 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1658
9410
7355b2d0067c mod_admin_telnet: Create metatable only once
Kim Alvefur <zash@zash.se>
parents: 9409
diff changeset
1659 local stats_mt = {__index = stats_methods, __tostring = stats_tostring }
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1660 local function new_stats_context(self)
9410
7355b2d0067c mod_admin_telnet: Create metatable only once
Kim Alvefur <zash@zash.se>
parents: 9409
diff changeset
1661 return setmetatable({ session = self.session, stats = true }, stats_mt);
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1662 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1663
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1664 function def_env.stats:show(filter)
10544
0bd408d93f9a mod_admin_telnet: Silence luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 10517
diff changeset
1665 -- luacheck: ignore 211/changed
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1666 local stats, changed, extra = require "core.statsmanager".get_stats();
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1667 local available, displayed = 0, 0;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1668 local displayed_stats = new_stats_context(self);
9756
38f7bde4cfe0 mod_admin_telnet: Sort stats by name
Kim Alvefur <zash@zash.se>
parents: 9755
diff changeset
1669 for name, value in iterators.sorted_pairs(stats) do
8964
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1670 available = available + 1;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1671 if not filter or name:match(filter) then
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1672 displayed = displayed + 1;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1673 local type = name:match(":(%a+)$");
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1674 table.insert(displayed_stats, {
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1675 name, type, value, extra[name];
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1676 output = {};
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1677 });
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1678 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1679 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1680 return displayed_stats;
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1681 end
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1682
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1683
76780f37028d mod_admin_telnet: Add some experimental commands for inspecting stats
Matthew Wild <mwild1@gmail.com>
parents: 8922
diff changeset
1684
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
1685 -------------
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
1686
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
1687 function printbanner(session)
7067
4c0ec9bd5168 mod_admin_telnet: Remove compat warning about 'console_banner' as a function
Kim Alvefur <zash@zash.se>
parents: 7031
diff changeset
1688 local option = module:get_option_string("console_banner", "full");
4c0ec9bd5168 mod_admin_telnet: Remove compat warning about 'console_banner' as a function
Kim Alvefur <zash@zash.se>
parents: 7031
diff changeset
1689 if option == "full" or option == "graphic" then
5026
c86a14414922 mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents: 5025
diff changeset
1690 session.print [[
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
1691 ____ \ / _
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
1692 | _ \ _ __ ___ ___ _-_ __| |_ _
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
1693 | |_) | '__/ _ \/ __|/ _ \ / _` | | | |
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
1694 | __/| | | (_) \__ \ |_| | (_| | |_| |
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
1695 |_| |_| \___/|___/\___/ \__,_|\__, |
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5770
diff changeset
1696 A study in simplicity |___/
736
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
1697
7cbae2d16fd6 mod_console: Make global
Matthew Wild <mwild1@gmail.com>
parents: 712
diff changeset
1698 ]]
5026
c86a14414922 mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents: 5025
diff changeset
1699 end
7067
4c0ec9bd5168 mod_admin_telnet: Remove compat warning about 'console_banner' as a function
Kim Alvefur <zash@zash.se>
parents: 7031
diff changeset
1700 if option == "short" or option == "full" then
5026
c86a14414922 mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents: 5025
diff changeset
1701 session.print("Welcome to the Prosody administration console. For a list of commands, type: help");
c86a14414922 mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents: 5025
diff changeset
1702 session.print("You may find more help on using this console in our online documentation at ");
7359
a5a080c12c96 Update every link to the documentation to use HTTPS
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7091
diff changeset
1703 session.print("https://prosody.im/doc/console\n");
1483
efd19cdda6ca mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents: 1433
diff changeset
1704 end
7067
4c0ec9bd5168 mod_admin_telnet: Remove compat warning about 'console_banner' as a function
Kim Alvefur <zash@zash.se>
parents: 7031
diff changeset
1705 if option ~= "short" and option ~= "full" and option ~= "graphic" then
4c0ec9bd5168 mod_admin_telnet: Remove compat warning about 'console_banner' as a function
Kim Alvefur <zash@zash.se>
parents: 7031
diff changeset
1706 session.print(option);
5026
c86a14414922 mod_admin_telnet: Fix broken indentation
Matthew Wild <mwild1@gmail.com>
parents: 5025
diff changeset
1707 end
1483
efd19cdda6ca mod_console: Allow customisation/suppression of the banner
Matthew Wild <mwild1@gmail.com>
parents: 1433
diff changeset
1708 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
1709
5120
bcabea740c00 mod_{admin_telnet,c2s,component,http,net_multiplex,s2s}: Use module:provides() instead of module:add_item().
Waqas Hussain <waqas20@gmail.com>
parents: 5030
diff changeset
1710 module:provides("net", {
4674
f44726a910a0 mod_admin_telnet: Add initial port:list() and port:close() commands
Matthew Wild <mwild1@gmail.com>
parents: 4647
diff changeset
1711 name = "console";
4550
1c41e4a846a2 mod_admin_telnet: Port to portmanager
Matthew Wild <mwild1@gmail.com>
parents: 4540
diff changeset
1712 listener = console_listener;
1c41e4a846a2 mod_admin_telnet: Port to portmanager
Matthew Wild <mwild1@gmail.com>
parents: 4540
diff changeset
1713 default_port = 5582;
4571
32d532b95dc7 mod_admin_telnet: make service private.
Marco Cirillo <maranda@lightwitch.org>
parents: 4550
diff changeset
1714 private = true;
4550
1c41e4a846a2 mod_admin_telnet: Port to portmanager
Matthew Wild <mwild1@gmail.com>
parents: 4540
diff changeset
1715 });