Software /
code /
prosody
Annotate
plugins/mod_admin_shell.lua @ 11196:f243836c449a
util.dbuffer: Add __name to metatable
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 30 Oct 2020 13:53:39 +0000 |
parent | 11042:8a243ab49cb5 |
child | 11361:dab1a6e46087 |
rev | line source |
---|---|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Prosody IM |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 -- COPYING file in the source package for more information. |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 -- |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 -- luacheck: ignore 212/self |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 module:set_global(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 module:depends("admin_socket"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local hostmanager = require "core.hostmanager"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local modulemanager = require "core.modulemanager"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local s2smanager = require "core.s2smanager"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local portmanager = require "core.portmanager"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local helpers = require "util.helpers"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local server = require "net.server"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local st = require "util.stanza"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 local _G = _G; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local prosody = _G.prosody; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local unpack = table.unpack or unpack; -- luacheck: ignore 113 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 local iterators = require "util.iterators"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 local keys, values = iterators.keys, iterators.values; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 local jid_bare, jid_split, jid_join = import("util.jid", "bare", "prepped_split", "join"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 local set, array = require "util.set", require "util.array"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local cert_verify_identity = require "util.x509".verify_identity; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 local envload = require "util.envload".envload; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 local envloadfile = require "util.envload".envloadfile; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 local has_pposix, pposix = pcall(require, "util.pposix"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local async = require "util.async"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local serialization = require "util.serialization"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local serialize_config = serialization.new ({ fatal = false, unquoted = true}); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 local time = require "util.time"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
39 local format_number = require "util.human.units".format; |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
40 |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 local commands = module:shared("commands") |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 local def_env = module:shared("env"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 local default_env_mt = { __index = def_env }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 local function redirect_output(target, session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 local env = setmetatable({ print = session.print }, { __index = function (_, k) return rawget(target, k); end }); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 env.dofile = function(name) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 local f, err = envloadfile(name, env); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 if not f then return f, err; end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 return f(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 return env; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 console = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 local runner_callbacks = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 function runner_callbacks:error(err) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 module:log("error", "Traceback[shell]: %s", err); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 self.data.print("Fatal error while running command, it did not complete"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 self.data.print("Error: "..tostring(err)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
66 local function send_repl_output(session, line) |
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
67 return session.send(st.stanza("repl-output"):text(tostring(line))); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 function console:new_session(admin_session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 local session = { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 send = function (t) |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
73 return send_repl_output(admin_session, t); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 print = function (...) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 local t = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 for i=1,select("#", ...) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 t[i] = tostring(select(i, ...)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 end |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
80 return send_repl_output(admin_session, table.concat(t, "\t")); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 serialize = tostring; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 disconnect = function () admin_session:close(); end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 session.env = setmetatable({}, default_env_mt); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 session.thread = async.runner(function (line) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 console:process_line(session, line); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 end, runner_callbacks, session); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 -- Load up environment with helper objects |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 for name, t in pairs(def_env) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 if type(t) == "table" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 session.env[name] = setmetatable({ session = session }, { __index = t }); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 session.env.output:configure(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 return session; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 local function handle_line(event) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 local session = event.origin.shell_session; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 if not session then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 session = console:new_session(event.origin); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 event.origin.shell_session = session; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 local line = event.stanza:get_text(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 local useglobalenv; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
112 local result = st.stanza("repl-result"); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 if line:match("^>") then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 line = line:gsub("^>", ""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 useglobalenv = true; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 local command = line:match("^%w+") or line:match("%p"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 if commands[command] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 commands[command](session, line); |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
121 event.origin.send(result); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 return; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 session.env._ = line; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 if not useglobalenv and commands[line:lower()] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 commands[line:lower()](session, line); |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
130 event.origin.send(result); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 return; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 local chunkname = "=console"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 local env = (useglobalenv and redirect_output(_G, session)) or session.env or nil |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 -- luacheck: ignore 311/err |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 local chunk, err = envload("return "..line, chunkname, env); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 if not chunk then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 chunk, err = envload(line, chunkname, env); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 if not chunk then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 err = err:gsub("^%[string .-%]:%d+: ", ""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 err = err:gsub("^:%d+: ", ""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 err = err:gsub("'<eof>'", "the end of the line"); |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
144 result.attr.type = "error"; |
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
145 result:text("Sorry, I couldn't understand that... "..err); |
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
146 event.origin.send(result); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 return; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 local taskok, message = chunk(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 if not message then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 if type(taskok) ~= "string" and useglobalenv then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 taskok = session.serialize(taskok); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 end |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
157 result:text("Result: "..tostring(taskok)); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 elseif (not taskok) and message then |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
159 result.attr.type = "error"; |
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
160 result:text("Error: "..tostring(message)); |
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
161 else |
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
162 result:text("OK: "..tostring(message)); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
165 event.origin.send(result); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
168 module:hook("admin/repl-input", function (event) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 local ok, err = pcall(handle_line, event); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 if not ok then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 event.origin.send(st.stanza("repl-result", { type = "error" }):text(err)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 -- Console commands -- |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 -- These are simple commands, not valid standalone in Lua |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 function commands.help(session, data) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 local print = session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 local section = data:match("^help (%w+)"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 if not section then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 print [[Commands are divided into multiple sections. For help on a particular section, ]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 print [[type: help SECTION (for example, 'help c2s'). Sections are: ]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 print [[]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 print [[c2s - Commands to manage local client-to-server sessions]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 print [[s2s - Commands to manage sessions between this server and others]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 print [[http - Commands to inspect HTTP services]] -- XXX plural but there is only one so far |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 print [[module - Commands to load/reload/unload modules/plugins]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 print [[host - Commands to activate, deactivate and list virtual hosts]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 print [[user - Commands to create and delete users, and change their passwords]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 print [[server - Uptime, version, shutting down, etc.]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 print [[port - Commands to manage ports the server is listening on]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 print [[dns - Commands to manage and inspect the internal DNS resolver]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 print [[xmpp - Commands for sending XMPP stanzas]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 print [[debug - Commands for debugging the server]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 print [[config - Reloading the configuration, etc.]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 print [[console - Help regarding the console itself]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 elseif section == "c2s" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 print [[c2s:show(jid) - Show all client sessions with the specified JID (or all if no JID given)]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 print [[c2s:show_insecure() - Show all unencrypted client connections]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 print [[c2s:show_secure() - Show all encrypted client connections]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 print [[c2s:show_tls() - Show TLS cipher info for encrypted sessions]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 print [[c2s:count() - Count sessions without listing them]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 print [[c2s:close(jid) - Close all sessions for the specified JID]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 print [[c2s:closeall() - Close all active c2s connections ]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 elseif section == "s2s" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 print [[s2s:show(domain) - Show all s2s connections for the given domain (or all if no domain given)]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 print [[s2s:show_tls(domain) - Show TLS cipher info for encrypted sessions]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 print [[s2s:close(from, to) - Close a connection from one domain to another]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 print [[s2s:closeall(host) - Close all the incoming/outgoing s2s sessions to specified host]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 elseif section == "http" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 print [[http:list(hosts) - Show HTTP endpoints]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 elseif section == "module" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 print [[module:load(module, host) - Load the specified module on the specified host (or all hosts if none given)]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 print [[module:reload(module, host) - The same, but unloads and loads the module (saving state if the module supports it)]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 print [[module:unload(module, host) - The same, but just unloads the module from memory]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 print [[module:list(host) - List the modules loaded on the specified host]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 elseif section == "host" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 print [[host:activate(hostname) - Activates the specified host]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 print [[host:list() - List the currently-activated hosts]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 elseif section == "user" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 print [[user:create(jid, password) - Create the specified user account]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 print [[user:password(jid, password) - Set the password for the specified user account]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 print [[user:delete(jid) - Permanently remove the specified user account]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 elseif section == "server" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 print [[server:version() - Show the server's version number]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 print [[server:uptime() - Show how long the server has been running]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
230 print [[server:memory() - Show details about the server's memory usage]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 elseif section == "port" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 print [[port:list() - Lists all network ports prosody currently listens on]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 print [[port:close(port, interface) - Close a port]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 elseif section == "dns" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 print [[dns:lookup(name, type, class) - Do a DNS lookup]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 print [[dns:addnameserver(nameserver) - Add a nameserver to the list]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 print [[dns:setnameserver(nameserver) - Replace the list of name servers with the supplied one]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 print [[dns:purge() - Clear the DNS cache]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 print [[dns:cache() - Show cached records]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 elseif section == "xmpp" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
242 print [[xmpp:ping(localhost, remotehost) -- Sends a ping to a remote XMPP server and reports the response]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
243 elseif section == "config" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
244 print [[config:reload() - Reload the server configuration. Modules may need to be reloaded for changes to take effect.]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
245 print [[config:get([host,] option) - Show the value of a config option.]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
246 elseif section == "stats" then -- luacheck: ignore 542 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 -- TODO describe how stats:show() works |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
248 elseif section == "debug" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
249 print [[debug:logevents(host) - Enable logging of fired events on host]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
250 print [[debug:events(host, event) - Show registered event handlers]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
251 print [[debug:timers() - Show information about scheduled timers]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
252 elseif section == "console" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
253 print [[Hey! Welcome to Prosody's admin console.]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
254 print [[First thing, if you're ever wondering how to get out, simply type 'quit'.]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
255 print [[Secondly, note that we don't support the full telnet protocol yet (it's coming)]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
256 print [[so you may have trouble using the arrow keys, etc. depending on your system.]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
257 print [[]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
258 print [[For now we offer a couple of handy shortcuts:]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
259 print [[!! - Repeat the last command]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
260 print [[!old!new! - repeat the last command, but with 'old' replaced by 'new']] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
261 print [[]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
262 print [[For those well-versed in Prosody's internals, or taking instruction from those who are,]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
263 print [[you can prefix a command with > to escape the console sandbox, and access everything in]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
264 print [[the running server. Great fun, but be careful not to break anything :)]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
265 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
266 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
267 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
268 -- Session environment -- |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
269 -- Anything in def_env will be accessible within the session as a global variable |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
270 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
271 --luacheck: ignore 212/self |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
272 local serialize_defaults = module:get_option("console_prettyprint_settings", { fatal = false, unquoted = true, maxdepth = 2}) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
273 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
274 def_env.output = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
275 function def_env.output:configure(opts) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
276 if type(opts) ~= "table" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
277 opts = { preset = opts }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
278 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
279 if not opts.fallback then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
280 -- XXX Error message passed to fallback is lost, does it matter? |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
281 opts.fallback = tostring; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
282 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
283 for k,v in pairs(serialize_defaults) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
284 if opts[k] == nil then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
285 opts[k] = v; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
286 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
287 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
288 self.session.serialize = serialization.new(opts); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
289 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
290 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
291 def_env.server = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
292 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
293 function def_env.server:insane_reload() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
294 prosody.unlock_globals(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
295 dofile "prosody" |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
296 prosody = _G.prosody; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
297 return true, "Server reloaded"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
298 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
299 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
300 function def_env.server:version() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
301 return true, tostring(prosody.version or "unknown"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
302 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
303 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
304 function def_env.server:uptime() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
305 local t = os.time()-prosody.start_time; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
306 local seconds = t%60; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
307 t = (t - seconds)/60; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
308 local minutes = t%60; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
309 t = (t - minutes)/60; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
310 local hours = t%24; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
311 t = (t - hours)/24; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
312 local days = t; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
313 return true, string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)", |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
314 days, (days ~= 1 and "s") or "", hours, (hours ~= 1 and "s") or "", |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
315 minutes, (minutes ~= 1 and "s") or "", os.date("%c", prosody.start_time)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
316 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
317 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
318 function def_env.server:shutdown(reason) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
319 prosody.shutdown(reason); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
320 return true, "Shutdown initiated"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
321 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
322 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
323 local function human(kb) |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
324 return format_number(kb*1024, "B", "b"); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
325 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
326 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
327 function def_env.server:memory() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
328 if not has_pposix or not pposix.meminfo then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
329 return true, "Lua is using "..human(collectgarbage("count")); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
330 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
331 local mem, lua_mem = pposix.meminfo(), collectgarbage("count"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
332 local print = self.session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
333 print("Process: "..human((mem.allocated+mem.allocated_mmap)/1024)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
334 print(" Used: "..human(mem.used/1024).." ("..human(lua_mem).." by Lua)"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
335 print(" Free: "..human(mem.unused/1024).." ("..human(mem.returnable/1024).." returnable)"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
336 return true, "OK"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
337 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
338 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
339 def_env.module = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
340 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
341 local function get_hosts_set(hosts) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
342 if type(hosts) == "table" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
343 if hosts[1] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
344 return set.new(hosts); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
345 elseif hosts._items then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
346 return hosts; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
347 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
348 elseif type(hosts) == "string" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
349 return set.new { hosts }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
350 elseif hosts == nil then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
351 return set.new(array.collect(keys(prosody.hosts))); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
352 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
353 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
354 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
355 -- Hosts with a module or all virtualhosts if no module given |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
356 -- matching modules_enabled in the global section |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
357 local function get_hosts_with_module(hosts, module) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
358 local hosts_set = get_hosts_set(hosts) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
359 / function (host) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
360 if module then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
361 -- Module given, filter in hosts with this module loaded |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
362 if modulemanager.is_loaded(host, module) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
363 return host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
364 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
365 return nil; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
366 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
367 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
368 if not hosts then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
369 -- No hosts given, filter in VirtualHosts |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
370 if prosody.hosts[host].type == "local" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
371 return host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
372 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
373 return nil |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
374 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
375 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
376 -- No module given, but hosts are, don't filter at all |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
377 return host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
378 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
379 if module and modulemanager.get_module("*", module) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
380 hosts_set:add("*"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
381 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
382 return hosts_set; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
383 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
384 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
385 function def_env.module:load(name, hosts, config) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
386 hosts = get_hosts_with_module(hosts); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
387 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
388 -- Load the module for each host |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
389 local ok, err, count, mod = true, nil, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
390 for host in hosts do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
391 if (not modulemanager.is_loaded(host, name)) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
392 mod, err = modulemanager.load(host, name, config); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
393 if not mod then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
394 ok = false; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
395 if err == "global-module-already-loaded" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
396 if count > 0 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
397 ok, err, count = true, nil, 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
398 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
399 break; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
400 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
401 self.session.print(err or "Unknown error loading module"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
402 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
403 count = count + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
404 self.session.print("Loaded for "..mod.module.host); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
405 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
406 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
407 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
408 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
409 return ok, (ok and "Module loaded onto "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
410 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
411 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
412 function def_env.module:unload(name, hosts) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
413 hosts = get_hosts_with_module(hosts, name); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
414 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
415 -- Unload the module for each host |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
416 local ok, err, count = true, nil, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
417 for host in hosts do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
418 if modulemanager.is_loaded(host, name) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
419 ok, err = modulemanager.unload(host, name); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
420 if not ok then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
421 ok = false; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
422 self.session.print(err or "Unknown error unloading module"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
423 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
424 count = count + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
425 self.session.print("Unloaded from "..host); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
426 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
427 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
428 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
429 return ok, (ok and "Module unloaded from "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
430 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
431 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
432 local function _sort_hosts(a, b) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
433 if a == "*" then return true |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
434 elseif b == "*" then return false |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
435 else return a:gsub("[^.]+", string.reverse):reverse() < b:gsub("[^.]+", string.reverse):reverse(); end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
436 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
437 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
438 function def_env.module:reload(name, hosts) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
439 hosts = array.collect(get_hosts_with_module(hosts, name)):sort(_sort_hosts) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
440 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
441 -- Reload the module for each host |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
442 local ok, err, count = true, nil, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
443 for _, host in ipairs(hosts) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
444 if modulemanager.is_loaded(host, name) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
445 ok, err = modulemanager.reload(host, name); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
446 if not ok then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
447 ok = false; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
448 self.session.print(err or "Unknown error reloading module"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
449 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
450 count = count + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
451 if ok == nil then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
452 ok = true; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
453 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
454 self.session.print("Reloaded on "..host); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
455 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
456 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
457 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
458 return ok, (ok and "Module reloaded on "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
459 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
460 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
461 function def_env.module:list(hosts) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
462 hosts = array.collect(set.new({ not hosts and "*" or nil }) + get_hosts_set(hosts)):sort(_sort_hosts); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
463 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
464 local print = self.session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
465 for _, host in ipairs(hosts) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
466 print((host == "*" and "Global" or host)..":"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
467 local modules = array.collect(keys(modulemanager.get_modules(host) or {})):sort(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
468 if #modules == 0 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
469 if prosody.hosts[host] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
470 print(" No modules loaded"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
471 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
472 print(" Host not found"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
473 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
474 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
475 for _, name in ipairs(modules) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
476 local status, status_text = modulemanager.get_module(host, name).module:get_status(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
477 local status_summary = ""; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
478 if status == "warn" or status == "error" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
479 status_summary = (" (%s: %s)"):format(status, status_text); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
480 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
481 print((" %s%s"):format(name, status_summary)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
482 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
483 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
484 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
485 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
486 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
487 def_env.config = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
488 function def_env.config:load(filename, format) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
489 local config_load = require "core.configmanager".load; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
490 local ok, err = config_load(filename, format); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
491 if not ok then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
492 return false, err or "Unknown error loading config"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
493 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
494 return true, "Config loaded"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
495 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
496 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
497 function def_env.config:get(host, key) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
498 if key == nil then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
499 host, key = "*", host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
500 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
501 local config_get = require "core.configmanager".get |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
502 return true, serialize_config(config_get(host, key)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
503 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
504 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
505 function def_env.config:reload() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
506 local ok, err = prosody.reload_config(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
507 return ok, (ok and "Config reloaded (you may need to reload modules to take effect)") or tostring(err); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
508 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
509 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
510 local function common_info(session, line) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
511 if session.id then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
512 line[#line+1] = "["..session.id.."]" |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
513 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
514 line[#line+1] = "["..session.type..(tostring(session):match("%x*$")).."]" |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
515 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
516 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
517 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
518 local function session_flags(session, line) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
519 line = line or {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
520 common_info(session, line); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
521 if session.type == "c2s" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
522 local status, priority = "unavailable", tostring(session.priority or "-"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
523 if session.presence then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
524 status = session.presence:get_child_text("show") or "available"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
525 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
526 line[#line+1] = status.."("..priority..")"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
527 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
528 if session.cert_identity_status == "valid" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
529 line[#line+1] = "(authenticated)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
530 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
531 if session.dialback_key then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
532 line[#line+1] = "(dialback)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
533 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
534 if session.external_auth then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
535 line[#line+1] = "(SASL)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
536 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
537 if session.secure then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
538 line[#line+1] = "(encrypted)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
539 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
540 if session.compressed then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
541 line[#line+1] = "(compressed)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
542 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
543 if session.smacks then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
544 line[#line+1] = "(sm)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
545 end |
11041
d00bfa75999d
mod_admin_shell: Report CSI state in c2s:show()
Kim Alvefur <zash@zash.se>
parents:
10988
diff
changeset
|
546 if session.state then |
11042
8a243ab49cb5
mod_admin_shell: Report CSI queue length from mod_csi_simple
Kim Alvefur <zash@zash.se>
parents:
11041
diff
changeset
|
547 if type(session.csi_counter) == "number" then |
8a243ab49cb5
mod_admin_shell: Report CSI queue length from mod_csi_simple
Kim Alvefur <zash@zash.se>
parents:
11041
diff
changeset
|
548 line[#line+1] = string.format("(csi:%s queue #%d)", session.state, session.csi_counter); |
8a243ab49cb5
mod_admin_shell: Report CSI queue length from mod_csi_simple
Kim Alvefur <zash@zash.se>
parents:
11041
diff
changeset
|
549 else |
8a243ab49cb5
mod_admin_shell: Report CSI queue length from mod_csi_simple
Kim Alvefur <zash@zash.se>
parents:
11041
diff
changeset
|
550 line[#line+1] = string.format("(csi:%s)", session.state); |
8a243ab49cb5
mod_admin_shell: Report CSI queue length from mod_csi_simple
Kim Alvefur <zash@zash.se>
parents:
11041
diff
changeset
|
551 end |
11041
d00bfa75999d
mod_admin_shell: Report CSI state in c2s:show()
Kim Alvefur <zash@zash.se>
parents:
10988
diff
changeset
|
552 end |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
553 if session.ip and session.ip:match(":") then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
554 line[#line+1] = "(IPv6)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
555 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
556 if session.remote then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
557 line[#line+1] = "(remote)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
558 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
559 if session.incoming and session.outgoing then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
560 line[#line+1] = "(bidi)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
561 elseif session.is_bidi or session.bidi_session then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
562 line[#line+1] = "(bidi)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
563 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
564 if session.bosh_version then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
565 line[#line+1] = "(bosh)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
566 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
567 if session.websocket_request then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
568 line[#line+1] = "(websocket)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
569 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
570 return table.concat(line, " "); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
571 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
572 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
573 local function tls_info(session, line) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
574 line = line or {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
575 common_info(session, line); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
576 if session.secure then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
577 local sock = session.conn and session.conn.socket and session.conn:socket(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
578 if sock then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
579 local info = sock.info and sock:info(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
580 if info then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
581 line[#line+1] = ("(%s with %s)"):format(info.protocol, info.cipher); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
582 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
583 -- TLS session might not be ready yet |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
584 line[#line+1] = "(cipher info unavailable)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
585 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
586 if sock.getsniname then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
587 local name = sock:getsniname(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
588 if name then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
589 line[#line+1] = ("(SNI:%q)"):format(name); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
590 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
591 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
592 if sock.getalpn then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
593 local proto = sock:getalpn(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
594 if proto then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
595 line[#line+1] = ("(ALPN:%q)"):format(proto); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
596 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
597 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
598 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
599 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
600 line[#line+1] = "(insecure)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
601 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
602 return table.concat(line, " "); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
603 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
604 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
605 def_env.c2s = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
606 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
607 local function get_jid(session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
608 if session.username then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
609 return session.full_jid or jid_join(session.username, session.host, session.resource); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
610 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
611 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
612 local conn = session.conn; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
613 local ip = session.ip or "?"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
614 local clientport = conn and conn:clientport() or "?"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
615 local serverip = conn and conn.server and conn:server():ip() or "?"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
616 local serverport = conn and conn:serverport() or "?" |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
617 return jid_join("["..ip.."]:"..clientport, session.host or "["..serverip.."]:"..serverport); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
618 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
619 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
620 local function get_c2s() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
621 local c2s = array.collect(values(prosody.full_sessions)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
622 c2s:append(array.collect(values(module:shared"/*/c2s/sessions"))); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
623 c2s:append(array.collect(values(module:shared"/*/bosh/sessions"))); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
624 c2s:unique(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
625 return c2s; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
626 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
627 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
628 local function show_c2s(callback) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
629 get_c2s():sort(function(a, b) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
630 if a.host == b.host then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
631 if a.username == b.username then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
632 return (a.resource or "") > (b.resource or ""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
633 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
634 return (a.username or "") > (b.username or ""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
635 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
636 return _sort_hosts(a.host or "", b.host or ""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
637 end):map(function (session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
638 callback(get_jid(session), session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
639 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
640 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
641 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
642 function def_env.c2s:count() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
643 local c2s = get_c2s(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
644 return true, "Total: ".. #c2s .." clients"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
645 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
646 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
647 function def_env.c2s:show(match_jid, annotate) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
648 local print, count = self.session.print, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
649 annotate = annotate or session_flags; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
650 local curr_host = false; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
651 show_c2s(function (jid, session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
652 if curr_host ~= session.host then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
653 curr_host = session.host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
654 print(curr_host or "(not connected to any host yet)"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
655 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
656 if (not match_jid) or jid:match(match_jid) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
657 count = count + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
658 print(annotate(session, { " ", jid })); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
659 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
660 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
661 return true, "Total: "..count.." clients"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
662 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
663 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
664 function def_env.c2s:show_insecure(match_jid) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
665 local print, count = self.session.print, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
666 show_c2s(function (jid, session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
667 if ((not match_jid) or jid:match(match_jid)) and not session.secure then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
668 count = count + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
669 print(jid); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
670 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
671 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
672 return true, "Total: "..count.." insecure client connections"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
673 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
674 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
675 function def_env.c2s:show_secure(match_jid) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
676 local print, count = self.session.print, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
677 show_c2s(function (jid, session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
678 if ((not match_jid) or jid:match(match_jid)) and session.secure then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
679 count = count + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
680 print(jid); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
681 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
682 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
683 return true, "Total: "..count.." secure client connections"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
684 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
685 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
686 function def_env.c2s:show_tls(match_jid) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
687 return self:show(match_jid, tls_info); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
688 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
689 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
690 local function build_reason(text, condition) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
691 if text or condition then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
692 return { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
693 text = text, |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
694 condition = condition or "undefined-condition", |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
695 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
696 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
697 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
698 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
699 function def_env.c2s:close(match_jid, text, condition) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
700 local count = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
701 show_c2s(function (jid, session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
702 if jid == match_jid or jid_bare(jid) == match_jid then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
703 count = count + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
704 session:close(build_reason(text, condition)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
705 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
706 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
707 return true, "Total: "..count.." sessions closed"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
708 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
709 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
710 function def_env.c2s:closeall(text, condition) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
711 local count = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
712 --luacheck: ignore 212/jid |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
713 show_c2s(function (jid, session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
714 count = count + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
715 session:close(build_reason(text, condition)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
716 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
717 return true, "Total: "..count.." sessions closed"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
718 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
719 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
720 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
721 def_env.s2s = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
722 function def_env.s2s:show(match_jid, annotate) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
723 local print = self.session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
724 annotate = annotate or session_flags; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
725 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
726 local count_in, count_out = 0,0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
727 local s2s_list = { }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
728 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
729 local s2s_sessions = module:shared"/*/s2s/sessions"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
730 for _, session in pairs(s2s_sessions) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
731 local remotehost, localhost, direction; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
732 if session.direction == "outgoing" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
733 direction = "->"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
734 count_out = count_out + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
735 remotehost, localhost = session.to_host or "?", session.from_host or "?"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
736 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
737 direction = "<-"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
738 count_in = count_in + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
739 remotehost, localhost = session.from_host or "?", session.to_host or "?"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
740 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
741 local sess_lines = { l = localhost, r = remotehost, |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
742 annotate(session, { "", direction, remotehost or "?" })}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
743 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
744 if (not match_jid) or remotehost:match(match_jid) or localhost:match(match_jid) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
745 table.insert(s2s_list, sess_lines); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
746 -- luacheck: ignore 421/print |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
747 local print = function (s) table.insert(sess_lines, " "..s); end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
748 if session.sendq then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
749 print("There are "..#session.sendq.." queued outgoing stanzas for this connection"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
750 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
751 if session.type == "s2sout_unauthed" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
752 if session.connecting then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
753 print("Connection not yet established"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
754 if not session.srv_hosts then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
755 if not session.conn then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
756 print("We do not yet have a DNS answer for this host's SRV records"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
757 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
758 print("This host has no SRV records, using A record instead"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
759 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
760 elseif session.srv_choice then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
761 print("We are on SRV record "..session.srv_choice.." of "..#session.srv_hosts); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
762 local srv_choice = session.srv_hosts[session.srv_choice]; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
763 print("Using "..(srv_choice.target or ".")..":"..(srv_choice.port or 5269)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
764 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
765 elseif session.notopen then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
766 print("The <stream> has not yet been opened"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
767 elseif not session.dialback_key then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
768 print("Dialback has not been initiated yet"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
769 elseif session.dialback_key then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
770 print("Dialback has been requested, but no result received"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
771 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
772 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
773 if session.type == "s2sin_unauthed" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
774 print("Connection not yet authenticated"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
775 elseif session.type == "s2sin" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
776 for name in pairs(session.hosts) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
777 if name ~= session.from_host then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
778 print("also hosts "..tostring(name)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
779 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
780 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
781 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
782 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
783 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
784 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
785 -- Sort by local host, then remote host |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
786 table.sort(s2s_list, function(a,b) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
787 if a.l == b.l then return _sort_hosts(a.r, b.r); end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
788 return _sort_hosts(a.l, b.l); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
789 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
790 local lasthost; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
791 for _, sess_lines in ipairs(s2s_list) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
792 if sess_lines.l ~= lasthost then print(sess_lines.l); lasthost=sess_lines.l end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
793 for _, line in ipairs(sess_lines) do print(line); end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
794 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
795 return true, "Total: "..count_out.." outgoing, "..count_in.." incoming connections"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
796 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
797 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
798 function def_env.s2s:show_tls(match_jid) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
799 return self:show(match_jid, tls_info); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
800 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
801 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
802 local function print_subject(print, subject) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
803 for _, entry in ipairs(subject) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
804 print( |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
805 (" %s: %q"):format( |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
806 entry.name or entry.oid, |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
807 entry.value:gsub("[\r\n%z%c]", " ") |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
808 ) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
809 ); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
810 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
811 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
812 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
813 -- As much as it pains me to use the 0-based depths that OpenSSL does, |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
814 -- I think there's going to be more confusion among operators if we |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
815 -- break from that. |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
816 local function print_errors(print, errors) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
817 for depth, t in pairs(errors) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
818 print( |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
819 (" %d: %s"):format( |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
820 depth-1, |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
821 table.concat(t, "\n| ") |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
822 ) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
823 ); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
824 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
825 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
826 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
827 function def_env.s2s:showcert(domain) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
828 local print = self.session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
829 local s2s_sessions = module:shared"/*/s2s/sessions"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
830 local domain_sessions = set.new(array.collect(values(s2s_sessions))) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
831 /function(session) return (session.to_host == domain or session.from_host == domain) and session or nil; end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
832 local cert_set = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
833 for session in domain_sessions do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
834 local conn = session.conn; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
835 conn = conn and conn:socket(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
836 if not conn.getpeerchain then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
837 if conn.dohandshake then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
838 error("This version of LuaSec does not support certificate viewing"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
839 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
840 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
841 local cert = conn:getpeercertificate(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
842 if cert then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
843 local certs = conn:getpeerchain(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
844 local digest = cert:digest("sha1"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
845 if not cert_set[digest] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
846 local chain_valid, chain_errors = conn:getpeerverification(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
847 cert_set[digest] = { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
848 { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
849 from = session.from_host, |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
850 to = session.to_host, |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
851 direction = session.direction |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
852 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
853 chain_valid = chain_valid; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
854 chain_errors = chain_errors; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
855 certs = certs; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
856 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
857 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
858 table.insert(cert_set[digest], { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
859 from = session.from_host, |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
860 to = session.to_host, |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
861 direction = session.direction |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
862 }); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
863 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
864 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
865 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
866 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
867 local domain_certs = array.collect(values(cert_set)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
868 -- Phew. We now have a array of unique certificates presented by domain. |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
869 local n_certs = #domain_certs; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
870 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
871 if n_certs == 0 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
872 return "No certificates found for "..domain; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
873 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
874 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
875 local function _capitalize_and_colon(byte) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
876 return string.upper(byte)..":"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
877 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
878 local function pretty_fingerprint(hash) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
879 return hash:gsub("..", _capitalize_and_colon):sub(1, -2); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
880 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
881 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
882 for cert_info in values(domain_certs) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
883 local certs = cert_info.certs; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
884 local cert = certs[1]; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
885 print("---") |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
886 print("Fingerprint (SHA1): "..pretty_fingerprint(cert:digest("sha1"))); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
887 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
888 local n_streams = #cert_info; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
889 print("Currently used on "..n_streams.." stream"..(n_streams==1 and "" or "s")..":"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
890 for _, stream in ipairs(cert_info) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
891 if stream.direction == "incoming" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
892 print(" "..stream.to.." <- "..stream.from); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
893 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
894 print(" "..stream.from.." -> "..stream.to); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
895 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
896 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
897 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
898 local chain_valid, errors = cert_info.chain_valid, cert_info.chain_errors; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
899 local valid_identity = cert_verify_identity(domain, "xmpp-server", cert); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
900 if chain_valid then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
901 print("Trusted certificate: Yes"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
902 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
903 print("Trusted certificate: No"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
904 print_errors(print, errors); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
905 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
906 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
907 print("Issuer: "); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
908 print_subject(print, cert:issuer()); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
909 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
910 print("Valid for "..domain..": "..(valid_identity and "Yes" or "No")); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
911 print("Subject:"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
912 print_subject(print, cert:subject()); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
913 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
914 print("---"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
915 return ("Showing "..n_certs.." certificate" |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
916 ..(n_certs==1 and "" or "s") |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
917 .." presented by "..domain.."."); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
918 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
919 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
920 function def_env.s2s:close(from, to, text, condition) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
921 local print, count = self.session.print, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
922 local s2s_sessions = module:shared"/*/s2s/sessions"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
923 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
924 local match_id; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
925 if from and not to then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
926 match_id, from = from, nil; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
927 elseif not to then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
928 return false, "Syntax: s2s:close('from', 'to') - Closes all s2s sessions from 'from' to 'to'"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
929 elseif from == to then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
930 return false, "Both from and to are the same... you can't do that :)"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
931 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
932 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
933 for _, session in pairs(s2s_sessions) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
934 local id = session.id or (session.type..tostring(session):match("[a-f0-9]+$")); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
935 if (match_id and match_id == id) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
936 or (session.from_host == from and session.to_host == to) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
937 print(("Closing connection from %s to %s [%s]"):format(session.from_host, session.to_host, id)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
938 (session.close or s2smanager.destroy_session)(session, build_reason(text, condition)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
939 count = count + 1 ; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
940 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
941 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
942 return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
943 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
944 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
945 function def_env.s2s:closeall(host, text, condition) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
946 local count = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
947 local s2s_sessions = module:shared"/*/s2s/sessions"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
948 for _,session in pairs(s2s_sessions) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
949 if not host or session.from_host == host or session.to_host == host then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
950 session:close(build_reason(text, condition)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
951 count = count + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
952 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
953 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
954 if count == 0 then return false, "No sessions to close."; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
955 else return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
956 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
957 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
958 def_env.host = {}; def_env.hosts = def_env.host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
959 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
960 function def_env.host:activate(hostname, config) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
961 return hostmanager.activate(hostname, config); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
962 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
963 function def_env.host:deactivate(hostname, reason) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
964 return hostmanager.deactivate(hostname, reason); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
965 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
966 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
967 function def_env.host:list() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
968 local print = self.session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
969 local i = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
970 local type; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
971 for host, host_session in iterators.sorted_pairs(prosody.hosts, _sort_hosts) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
972 i = i + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
973 type = host_session.type; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
974 if type == "local" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
975 print(host); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
976 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
977 type = module:context(host):get_option_string("component_module", type); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
978 if type ~= "component" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
979 type = type .. " component"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
980 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
981 print(("%s (%s)"):format(host, type)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
982 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
983 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
984 return true, i.." hosts"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
985 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
986 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
987 def_env.port = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
988 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
989 function def_env.port:list() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
990 local print = self.session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
991 local services = portmanager.get_active_services().data; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
992 local n_services, n_ports = 0, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
993 for service, interfaces in iterators.sorted_pairs(services) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
994 n_services = n_services + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
995 local ports_list = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
996 for interface, ports in pairs(interfaces) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
997 for port in pairs(ports) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
998 table.insert(ports_list, "["..interface.."]:"..port); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
999 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1000 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1001 n_ports = n_ports + #ports_list; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1002 print(service..": "..table.concat(ports_list, ", ")); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1003 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1004 return true, n_services.." services listening on "..n_ports.." ports"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1005 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1006 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1007 function def_env.port:close(close_port, close_interface) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1008 close_port = assert(tonumber(close_port), "Invalid port number"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1009 local n_closed = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1010 local services = portmanager.get_active_services().data; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1011 for service, interfaces in pairs(services) do -- luacheck: ignore 213 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1012 for interface, ports in pairs(interfaces) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1013 if not close_interface or close_interface == interface then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1014 if ports[close_port] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1015 self.session.print("Closing ["..interface.."]:"..close_port.."..."); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1016 local ok, err = portmanager.close(interface, close_port) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1017 if not ok then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1018 self.session.print("Failed to close "..interface.." "..close_port..": "..err); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1019 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1020 n_closed = n_closed + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1021 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1022 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1023 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1024 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1025 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1026 return true, "Closed "..n_closed.." ports"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1027 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1028 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1029 def_env.muc = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1030 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1031 local console_room_mt = { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1032 __index = function (self, k) return self.room[k]; end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1033 __tostring = function (self) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1034 return "MUC room <"..self.room.jid..">"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1035 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1036 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1037 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1038 local function check_muc(jid) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1039 local room_name, host = jid_split(jid); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1040 if not prosody.hosts[host] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1041 return nil, "No such host: "..host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1042 elseif not prosody.hosts[host].modules.muc then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1043 return nil, "Host '"..host.."' is not a MUC service"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1044 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1045 return room_name, host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1046 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1047 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1048 function def_env.muc:create(room_jid, config) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1049 local room_name, host = check_muc(room_jid); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1050 if not room_name then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1051 return room_name, host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1052 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1053 if not room_name then return nil, host end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1054 if config ~= nil and type(config) ~= "table" then return nil, "Config must be a table"; end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1055 if prosody.hosts[host].modules.muc.get_room_from_jid(room_jid) then return nil, "Room exists already" end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1056 return prosody.hosts[host].modules.muc.create_room(room_jid, config); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1057 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1058 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1059 function def_env.muc:room(room_jid) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1060 local room_name, host = check_muc(room_jid); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1061 if not room_name then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1062 return room_name, host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1063 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1064 local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1065 if not room_obj then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1066 return nil, "No such room: "..room_jid; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1067 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1068 return setmetatable({ room = room_obj }, console_room_mt); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1069 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1070 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1071 function def_env.muc:list(host) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1072 local host_session = prosody.hosts[host]; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1073 if not host_session or not host_session.modules.muc then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1074 return nil, "Please supply the address of a local MUC component"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1075 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1076 local print = self.session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1077 local c = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1078 for room in host_session.modules.muc.each_room() do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1079 print(room.jid); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1080 c = c + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1081 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1082 return true, c.." rooms"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1083 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1084 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1085 local um = require"core.usermanager"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1086 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1087 def_env.user = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1088 function def_env.user:create(jid, password) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1089 local username, host = jid_split(jid); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1090 if not prosody.hosts[host] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1091 return nil, "No such host: "..host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1092 elseif um.user_exists(username, host) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1093 return nil, "User exists"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1094 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1095 local ok, err = um.create_user(username, password, host); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1096 if ok then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1097 return true, "User created"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1098 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1099 return nil, "Could not create user: "..err; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1100 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1101 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1102 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1103 function def_env.user:delete(jid) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1104 local username, host = jid_split(jid); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1105 if not prosody.hosts[host] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1106 return nil, "No such host: "..host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1107 elseif not um.user_exists(username, host) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1108 return nil, "No such user"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1109 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1110 local ok, err = um.delete_user(username, host); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1111 if ok then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1112 return true, "User deleted"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1113 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1114 return nil, "Could not delete user: "..err; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1115 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1116 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1117 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1118 function def_env.user:password(jid, password) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1119 local username, host = jid_split(jid); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1120 if not prosody.hosts[host] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1121 return nil, "No such host: "..host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1122 elseif not um.user_exists(username, host) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1123 return nil, "No such user"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1124 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1125 local ok, err = um.set_password(username, password, host, nil); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1126 if ok then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1127 return true, "User password changed"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1128 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1129 return nil, "Could not change password for user: "..err; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1130 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1131 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1132 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1133 function def_env.user:list(host, pat) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1134 if not host then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1135 return nil, "No host given"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1136 elseif not prosody.hosts[host] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1137 return nil, "No such host"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1138 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1139 local print = self.session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1140 local total, matches = 0, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1141 for user in um.users(host) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1142 if not pat or user:match(pat) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1143 print(user.."@"..host); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1144 matches = matches + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1145 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1146 total = total + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1147 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1148 return true, "Showing "..(pat and (matches.." of ") or "all " )..total.." users"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1149 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1150 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1151 def_env.xmpp = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1152 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1153 local new_id = require "util.id".medium; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1154 function def_env.xmpp:ping(localhost, remotehost, timeout) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1155 localhost = select(2, jid_split(localhost)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1156 remotehost = select(2, jid_split(remotehost)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1157 if not localhost then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1158 return nil, "Invalid sender hostname"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1159 elseif not prosody.hosts[localhost] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1160 return nil, "No such local host"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1161 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1162 if not remotehost then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1163 return nil, "Invalid destination hostname"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1164 elseif prosody.hosts[remotehost] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1165 return nil, "Both hosts are local"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1166 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1167 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()} |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1168 :tag("ping", {xmlns="urn:xmpp:ping"}); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1169 local time_start = time.now(); |
10929
ad5e373b1419
mod_admin_shell: Update for async.wait_for rename
Kim Alvefur <zash@zash.se>
parents:
10918
diff
changeset
|
1170 local ret, err = async.wait_for(module:context(localhost):send_iq(iq, nil, timeout)); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1171 if ret then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1172 return true, ("pong from %s in %gs"):format(ret.stanza.attr.from, time.now() - time_start); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1173 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1174 return false, tostring(err); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1175 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1176 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1177 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1178 def_env.dns = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1179 local adns = require"net.adns"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1180 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1181 local function get_resolver(session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1182 local resolver = session.dns_resolver; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1183 if not resolver then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1184 resolver = adns.resolver(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1185 session.dns_resolver = resolver; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1186 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1187 return resolver; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1188 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1189 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1190 function def_env.dns:lookup(name, typ, class) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1191 local resolver = get_resolver(self.session); |
10929
ad5e373b1419
mod_admin_shell: Update for async.wait_for rename
Kim Alvefur <zash@zash.se>
parents:
10918
diff
changeset
|
1192 local ret, err = async.wait_for(resolver:lookup_promise(name, typ, class)); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1193 if ret then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1194 return true, ret; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1195 elseif err then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1196 return false, err; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1197 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1198 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1199 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1200 function def_env.dns:addnameserver(...) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1201 local resolver = get_resolver(self.session); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1202 resolver._resolver:addnameserver(...) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1203 return true |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1204 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1205 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1206 function def_env.dns:setnameserver(...) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1207 local resolver = get_resolver(self.session); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1208 resolver._resolver:setnameserver(...) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1209 return true |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1210 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1211 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1212 function def_env.dns:purge() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1213 local resolver = get_resolver(self.session); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1214 resolver._resolver:purge() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1215 return true |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1216 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1217 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1218 function def_env.dns:cache() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1219 local resolver = get_resolver(self.session); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1220 return true, "Cache:\n"..tostring(resolver._resolver.cache) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1221 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1222 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1223 def_env.http = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1224 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1225 function def_env.http:list(hosts) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1226 local print = self.session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1227 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1228 for host in get_hosts_set(hosts) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1229 local http_apps = modulemanager.get_items("http-provider", host); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1230 if #http_apps > 0 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1231 local http_host = module:context(host):get_option_string("http_host"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1232 print("HTTP endpoints on "..host..(http_host and (" (using "..http_host.."):") or ":")); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1233 for _, provider in ipairs(http_apps) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1234 local url = module:context(host):http_url(provider.name, provider.default_path); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1235 print("", url); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1236 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1237 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1238 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1239 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1240 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1241 local default_host = module:get_option_string("http_default_host"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1242 if not default_host then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1243 print("HTTP requests to unknown hosts will return 404 Not Found"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1244 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1245 print("HTTP requests to unknown hosts will be handled by "..default_host); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1246 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1247 return true; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1248 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1249 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1250 def_env.debug = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1251 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1252 function def_env.debug:logevents(host) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1253 helpers.log_host_events(host); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1254 return true; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1255 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1256 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1257 function def_env.debug:events(host, event) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1258 local events_obj; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1259 if host and host ~= "*" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1260 if host == "http" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1261 events_obj = require "net.http.server"._events; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1262 elseif not prosody.hosts[host] then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1263 return false, "Unknown host: "..host; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1264 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1265 events_obj = prosody.hosts[host].events; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1266 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1267 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1268 events_obj = prosody.events; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1269 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1270 return true, helpers.show_events(events_obj, event); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1271 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1272 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1273 function def_env.debug:timers() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1274 local print = self.session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1275 local add_task = require"util.timer".add_task; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1276 local h, params = add_task.h, add_task.params; |
10988
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1277 local function normalize_time(t) |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1278 return t; |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1279 end |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1280 local function format_time(t) |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1281 return os.date("%F %T", math.floor(normalize_time(t))); |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1282 end |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1283 if h then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1284 print("-- util.timer"); |
10986
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1285 elseif server.timer then |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1286 print("-- net.server.timer"); |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1287 h = server.timer.add_task.timers; |
10988
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1288 normalize_time = server.timer.to_absolute_time or normalize_time; |
10986
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1289 end |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1290 if h then |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1291 for i, id in ipairs(h.ids) do |
10986
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1292 local t, cb = h.priorities[i], h.items[id]; |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1293 if not params then |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1294 local param = cb.param; |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1295 if param then |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1296 cb = param.callback; |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1297 else |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1298 cb = cb.timer_callback or cb; |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1299 end |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1300 elseif params[id] then |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1301 cb = params[id].callback or cb; |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1302 end |
10988
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1303 print(format_time(t), cb); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1304 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1305 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1306 if server.event_base then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1307 local count = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1308 for _, v in pairs(debug.getregistry()) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1309 if type(v) == "function" and v.callback and v.callback == add_task._on_timer then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1310 count = count + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1311 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1312 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1313 print(count .. " libevent callbacks"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1314 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1315 if h then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1316 local next_time = h:peek(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1317 if next_time then |
10988
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1318 return true, ("Next event at %s (in %.6fs)"):format(format_time(next_time), normalize_time(next_time) - time.now()); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1319 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1320 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1321 return true; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1322 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1323 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1324 -- COMPAT: debug:timers() was timer:info() for some time in trunk |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1325 def_env.timer = { info = def_env.debug.timers }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1326 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1327 def_env.stats = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1328 |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1329 local short_units = { |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1330 seconds = "s", |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1331 bytes = "B", |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1332 }; |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1333 |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1334 local function format_stat(type, unit, value, ref_value) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1335 ref_value = ref_value or value; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1336 --do return tostring(value) end |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1337 if not unit then |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1338 if type == "duration" then |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1339 unit = "seconds" |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1340 elseif type == "size" then |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1341 unit = "bytes"; |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1342 elseif type == "rate" then |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1343 unit = " events/sec" |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1344 if ref_value < 0.9 then |
10902
5d113332855c
mod_admin_shell: Skip multiplier adjustment for rates
Kim Alvefur <zash@zash.se>
parents:
10887
diff
changeset
|
1345 unit = "events/min" |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1346 value = value*60; |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1347 if ref_value < 0.6/60 then |
10902
5d113332855c
mod_admin_shell: Skip multiplier adjustment for rates
Kim Alvefur <zash@zash.se>
parents:
10887
diff
changeset
|
1348 unit = "events/h" |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1349 value = value*60; |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1350 end |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1351 end |
10902
5d113332855c
mod_admin_shell: Skip multiplier adjustment for rates
Kim Alvefur <zash@zash.se>
parents:
10887
diff
changeset
|
1352 return ("%.3g %s"):format(value, unit); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1353 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1354 end |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1355 return format_number(value, short_units[unit] or unit or "", unit == "bytes" and 'b' or nil); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1356 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1357 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1358 local stats_methods = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1359 function stats_methods:bounds(_lower, _upper) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1360 for _, stat_info in ipairs(self) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1361 local data = stat_info[4]; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1362 if data then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1363 local lower = _lower or data.min; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1364 local upper = _upper or data.max; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1365 local new_data = { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1366 min = lower; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1367 max = upper; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1368 samples = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1369 sample_count = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1370 count = data.count; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1371 units = data.units; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1372 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1373 local sum = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1374 for _, v in ipairs(data.samples) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1375 if v > upper then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1376 break; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1377 elseif v>=lower then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1378 table.insert(new_data.samples, v); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1379 sum = sum + v; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1380 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1381 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1382 new_data.sample_count = #new_data.samples; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1383 stat_info[4] = new_data; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1384 stat_info[3] = sum/new_data.sample_count; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1385 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1386 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1387 return self; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1388 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1389 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1390 function stats_methods:trim(lower, upper) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1391 upper = upper or (100-lower); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1392 local statistics = require "util.statistics"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1393 for _, stat_info in ipairs(self) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1394 -- Strip outliers |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1395 local data = stat_info[4]; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1396 if data then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1397 local new_data = { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1398 min = statistics.get_percentile(data, lower); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1399 max = statistics.get_percentile(data, upper); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1400 samples = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1401 sample_count = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1402 count = data.count; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1403 units = data.units; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1404 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1405 local sum = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1406 for _, v in ipairs(data.samples) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1407 if v > new_data.max then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1408 break; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1409 elseif v>=new_data.min then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1410 table.insert(new_data.samples, v); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1411 sum = sum + v; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1412 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1413 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1414 new_data.sample_count = #new_data.samples; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1415 stat_info[4] = new_data; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1416 stat_info[3] = sum/new_data.sample_count; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1417 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1418 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1419 return self; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1420 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1421 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1422 function stats_methods:max(upper) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1423 return self:bounds(nil, upper); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1424 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1425 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1426 function stats_methods:min(lower) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1427 return self:bounds(lower, nil); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1428 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1429 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1430 function stats_methods:summary() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1431 local statistics = require "util.statistics"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1432 for _, stat_info in ipairs(self) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1433 local type, value, data = stat_info[2], stat_info[3], stat_info[4]; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1434 if data and data.samples then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1435 table.insert(stat_info.output, string.format("Count: %d (%d captured)", |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1436 data.count, |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1437 data.sample_count |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1438 )); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1439 table.insert(stat_info.output, string.format("Min: %s Mean: %s Max: %s", |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1440 format_stat(type, data.units, data.min), |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1441 format_stat(type, data.units, value), |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1442 format_stat(type, data.units, data.max) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1443 )); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1444 table.insert(stat_info.output, string.format("Q1: %s Median: %s Q3: %s", |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1445 format_stat(type, data.units, statistics.get_percentile(data, 25)), |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1446 format_stat(type, data.units, statistics.get_percentile(data, 50)), |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1447 format_stat(type, data.units, statistics.get_percentile(data, 75)) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1448 )); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1449 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1450 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1451 return self; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1452 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1453 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1454 function stats_methods:cfgraph() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1455 for _, stat_info in ipairs(self) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1456 local name, type, value, data = unpack(stat_info, 1, 4); -- luacheck: ignore 211 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1457 local function print(s) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1458 table.insert(stat_info.output, s); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1459 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1460 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1461 if data and data.sample_count and data.sample_count > 0 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1462 local raw_histogram = require "util.statistics".get_histogram(data); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1463 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1464 local graph_width, graph_height = 50, 10; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1465 local eighth_chars = " ▁▂▃▄▅▆▇█"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1466 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1467 local range = data.max - data.min; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1468 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1469 if range > 0 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1470 local x_scaling = #raw_histogram/graph_width; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1471 local histogram = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1472 for i = 1, graph_width do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1473 histogram[i] = math.max(raw_histogram[i*x_scaling-1] or 0, raw_histogram[i*x_scaling] or 0); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1474 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1475 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1476 print(""); |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1477 print(("_"):rep(52)..format_stat(type, data.units, data.max)); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1478 for row = graph_height, 1, -1 do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1479 local row_chars = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1480 local min_eighths, max_eighths = 8, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1481 for i = 1, #histogram do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1482 local char_eighths = math.ceil(math.max(math.min((graph_height/(data.max/histogram[i]))-(row-1), 1), 0)*8); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1483 if char_eighths < min_eighths then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1484 min_eighths = char_eighths; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1485 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1486 if char_eighths > max_eighths then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1487 max_eighths = char_eighths; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1488 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1489 if char_eighths == 0 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1490 row_chars[i] = "-"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1491 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1492 local char = eighth_chars:sub(char_eighths*3+1, char_eighths*3+3); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1493 row_chars[i] = char; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1494 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1495 end |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1496 print(table.concat(row_chars).."|-"..format_stat(type, data.units, data.max/(graph_height/(row-0.5)))); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1497 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1498 print(("\\ "):rep(11)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1499 local x_labels = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1500 for i = 1, 11 do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1501 local s = ("%-4s"):format((i-1)*10); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1502 if #s > 4 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1503 s = s:sub(1, 3).."…"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1504 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1505 x_labels[i] = s; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1506 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1507 print(" "..table.concat(x_labels, " ")); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1508 local units = "%"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1509 local margin = math.floor((graph_width-#units)/2); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1510 print((" "):rep(margin)..units); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1511 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1512 print("[range too small to graph]"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1513 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1514 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1515 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1516 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1517 return self; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1518 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1519 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1520 function stats_methods:histogram() |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1521 for _, stat_info in ipairs(self) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1522 local name, type, value, data = unpack(stat_info, 1, 4); -- luacheck: ignore 211 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1523 local function print(s) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1524 table.insert(stat_info.output, s); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1525 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1526 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1527 if not data then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1528 print("[no data]"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1529 return self; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1530 elseif not data.sample_count then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1531 print("[not a sampled metric type]"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1532 return self; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1533 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1534 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1535 local graph_width, graph_height = 50, 10; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1536 local eighth_chars = " ▁▂▃▄▅▆▇█"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1537 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1538 local range = data.max - data.min; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1539 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1540 if range > 0 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1541 local n_buckets = graph_width; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1542 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1543 local histogram = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1544 for i = 1, n_buckets do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1545 histogram[i] = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1546 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1547 local max_bin_samples = 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1548 for _, d in ipairs(data.samples) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1549 local bucket = math.floor(1+(n_buckets-1)/(range/(d-data.min))); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1550 histogram[bucket] = histogram[bucket] + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1551 if histogram[bucket] > max_bin_samples then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1552 max_bin_samples = histogram[bucket]; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1553 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1554 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1555 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1556 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1557 print(("_"):rep(52)..max_bin_samples); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1558 for row = graph_height, 1, -1 do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1559 local row_chars = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1560 local min_eighths, max_eighths = 8, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1561 for i = 1, #histogram do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1562 local char_eighths = math.ceil(math.max(math.min((graph_height/(max_bin_samples/histogram[i]))-(row-1), 1), 0)*8); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1563 if char_eighths < min_eighths then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1564 min_eighths = char_eighths; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1565 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1566 if char_eighths > max_eighths then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1567 max_eighths = char_eighths; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1568 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1569 if char_eighths == 0 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1570 row_chars[i] = "-"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1571 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1572 local char = eighth_chars:sub(char_eighths*3+1, char_eighths*3+3); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1573 row_chars[i] = char; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1574 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1575 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1576 print(table.concat(row_chars).."|-"..math.ceil((max_bin_samples/graph_height)*(row-0.5))); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1577 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1578 print(("\\ "):rep(11)); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1579 local x_labels = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1580 for i = 1, 11 do |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1581 local s = ("%-4s"):format(format_stat(type, data.units, data.min+range*i/11, data.min):match("^%S+")); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1582 if #s > 4 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1583 s = s:sub(1, 3).."…"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1584 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1585 x_labels[i] = s; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1586 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1587 print(" "..table.concat(x_labels, " ")); |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1588 local units = format_stat(type, data.units, data.min):match("%s+(.+)$") or data.units or ""; |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1589 local margin = math.floor((graph_width-#units)/2); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1590 print((" "):rep(margin)..units); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1591 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1592 print("[range too small to graph]"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1593 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1594 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1595 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1596 return self; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1597 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1598 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1599 local function stats_tostring(stats) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1600 local print = stats.session.print; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1601 for _, stat_info in ipairs(stats) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1602 if #stat_info.output > 0 then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1603 print("\n#"..stat_info[1]); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1604 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1605 for _, v in ipairs(stat_info.output) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1606 print(v); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1607 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1608 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1609 else |
10918
b0038e404e0e
mod_admin_shell: Fix display of units for some statistics
Kim Alvefur <zash@zash.se>
parents:
10902
diff
changeset
|
1610 print(("%-50s %s"):format(stat_info[1], format_stat(stat_info[2], (stat_info[4] or {}).units, stat_info[3]))); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1611 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1612 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1613 return #stats.." statistics displayed"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1614 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1615 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1616 local stats_mt = {__index = stats_methods, __tostring = stats_tostring } |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1617 local function new_stats_context(self) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1618 return setmetatable({ session = self.session, stats = true }, stats_mt); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1619 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1620 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1621 function def_env.stats:show(filter) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1622 -- luacheck: ignore 211/changed |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1623 local stats, changed, extra = require "core.statsmanager".get_stats(); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1624 local available, displayed = 0, 0; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1625 local displayed_stats = new_stats_context(self); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1626 for name, value in iterators.sorted_pairs(stats) do |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1627 available = available + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1628 if not filter or name:match(filter) then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1629 displayed = displayed + 1; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1630 local type = name:match(":(%a+)$"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1631 table.insert(displayed_stats, { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1632 name, type, value, extra[name]; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1633 output = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1634 }); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1635 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1636 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1637 return displayed_stats; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1638 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1639 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1640 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1641 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1642 ------------- |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1643 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1644 function printbanner(session) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1645 local option = module:get_option_string("console_banner", "full"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1646 if option == "full" or option == "graphic" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1647 session.print [[ |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1648 ____ \ / _ |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1649 | _ \ _ __ ___ ___ _-_ __| |_ _ |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1650 | |_) | '__/ _ \/ __|/ _ \ / _` | | | | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1651 | __/| | | (_) \__ \ |_| | (_| | |_| | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1652 |_| |_| \___/|___/\___/ \__,_|\__, | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1653 A study in simplicity |___/ |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1654 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1655 ]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1656 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1657 if option == "short" or option == "full" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1658 session.print("Welcome to the Prosody administration console. For a list of commands, type: help"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1659 session.print("You may find more help on using this console in our online documentation at "); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1660 session.print("https://prosody.im/doc/console\n"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1661 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1662 if option ~= "short" and option ~= "full" and option ~= "graphic" then |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1663 session.print(option); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1664 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1665 end |