Software /
code /
prosody
Annotate
plugins/mod_admin_shell.lua @ 11736:ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Makes it so that global values set in the environment are kept longer
than within one line, and thus can be used until the session ends. They
still don't pollute the global environment, which is an error anyway.
Thanks phryk for noticing.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 11 Aug 2021 14:55:59 +0200 |
parent | 11607:03eb4c0dca27 |
child | 11831:94cd363116a3 |
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 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
39 local t_insert = table.insert; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
40 local t_concat = table.concat; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
41 |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
42 local format_number = require "util.human.units".format; |
11364
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11363
diff
changeset
|
43 local format_table = require "util.human.io".table; |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
44 |
10856
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 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
|
46 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
|
47 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
|
48 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 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
|
57 end |
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 console = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 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
|
62 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 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
|
64 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
|
65 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 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
|
67 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
|
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 |
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
|
70 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
|
71 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
|
72 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 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
|
78 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 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
|
87 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
|
88 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 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
|
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 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
|
92 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
|
93 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
|
94 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 -- 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
|
96 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
|
97 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
|
98 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
|
99 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 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
|
103 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 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
|
105 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 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
|
114 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
|
115 |
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
|
116 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
|
117 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 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
|
126 return; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 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
|
131 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 return; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 |
11736
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
138 if useglobalenv and not session.globalenv then |
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
139 session.globalenv = redirect_output(_G, session); |
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
140 end |
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
141 |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 local chunkname = "=console"; |
11736
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
143 local env = (useglobalenv and session.globalenv) or session.env 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
|
144 -- 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 return; |
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 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
|
160 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 |
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
|
173 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
|
174 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 |
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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 -- 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
|
184 -- 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
|
185 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 print [[]] |
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 [[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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 print [[user - Commands to create and delete users, and change their passwords]] |
11365
5eb817cdd5cd
mod_admin_shell: Add help section with (top level) MUC commands
Kim Alvefur <zash@zash.se>
parents:
11364
diff
changeset
|
199 print [[muc - Commands to create, list and manage chat rooms]] |
10856
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 [[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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 elseif section == "module" then |
11601
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
223 print [[module:info(module, host) - Show information about a loaded module]] |
10856
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 [[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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] |
11365
5eb817cdd5cd
mod_admin_shell: Add help section with (top level) MUC commands
Kim Alvefur <zash@zash.se>
parents:
11364
diff
changeset
|
237 elseif section == "muc" then |
5eb817cdd5cd
mod_admin_shell: Add help section with (top level) MUC commands
Kim Alvefur <zash@zash.se>
parents:
11364
diff
changeset
|
238 -- TODO `muc:room():foo()` commands |
5eb817cdd5cd
mod_admin_shell: Add help section with (top level) MUC commands
Kim Alvefur <zash@zash.se>
parents:
11364
diff
changeset
|
239 print [[muc:create(roomjid, { config }) - Create the specified MUC room with the given config]] |
5eb817cdd5cd
mod_admin_shell: Add help section with (top level) MUC commands
Kim Alvefur <zash@zash.se>
parents:
11364
diff
changeset
|
240 print [[muc:list(host) - List rooms on the specified MUC component]] |
5eb817cdd5cd
mod_admin_shell: Add help section with (top level) MUC commands
Kim Alvefur <zash@zash.se>
parents:
11364
diff
changeset
|
241 print [[muc:room(roomjid) - Create the specified MUC room with the given config]] |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 -- 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 print [[]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 print [[]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
281 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
282 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
283 -- 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
|
284 -- 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
|
285 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
286 --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
|
287 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
|
288 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 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
|
293 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
294 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
|
295 -- 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
|
296 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
|
297 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
298 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
|
299 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
|
300 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
|
301 end |
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 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
|
304 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
305 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
306 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
|
307 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
314 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
315 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
|
316 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
|
317 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
318 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
332 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
333 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
|
334 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
|
335 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
|
336 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
337 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
338 local function human(kb) |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
339 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
|
340 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
341 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
346 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
354 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
|
355 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
369 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
370 -- 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
|
371 -- 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
|
372 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
|
373 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
|
374 / 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
|
375 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
|
376 -- 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
|
377 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
|
378 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
|
379 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
380 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
383 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
|
384 -- 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
|
385 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
|
386 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
|
387 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
388 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
|
389 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
390 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
391 -- 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
|
392 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
|
393 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
394 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
|
395 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
|
396 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
397 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
|
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 |
11601
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
400 function def_env.module:info(name, hosts) |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
401 if not name then |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
402 return nil, "module name expected"; |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
403 end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
404 local print = self.session.print; |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
405 hosts = get_hosts_with_module(hosts, name); |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
406 if hosts:empty() then |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
407 return false, "mod_" .. name .. " does not appear to be loaded on the specified hosts"; |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
408 end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
409 |
11606
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
410 local friendly_descriptions = { |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
411 ["adhoc-provider"] = "Ad-hoc commands", |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
412 ["auth-provider"] = "Authentication provider", |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
413 ["http-provider"] = "HTTP services", |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
414 ["net-provider"] = "Network service", |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
415 ["storage-provider"] = "Storage driver", |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
416 }; |
11607
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
417 local item_formatters = { |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
418 ["feature"] = tostring, |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
419 ["identity"] = function(ident) return ident.type .. "/" .. ident.category; end, |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
420 ["adhoc-provider"] = function(item) return item.name; end, |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
421 ["auth-provider"] = function(item) return item.name; end, |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
422 ["storage-provider"] = function(item) return item.name; end, |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
423 }; |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
424 |
11601
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
425 for host in hosts do |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
426 local mod = modulemanager.get_module(host, name); |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
427 if mod.module.host == "*" then |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
428 print("in global context"); |
11604
7466bf65d7c8
mod_admin_shell: module:info: Use existing host string representation
Kim Alvefur <zash@zash.se>
parents:
11603
diff
changeset
|
429 else |
7466bf65d7c8
mod_admin_shell: module:info: Use existing host string representation
Kim Alvefur <zash@zash.se>
parents:
11603
diff
changeset
|
430 print("on " .. tostring(prosody.hosts[mod.module.host])); |
11601
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
431 end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
432 print(" path: " .. (mod.module.path or "n/a")); |
11602
78ec0741c2bc
mod_admin_shell: module:info: Show module status
Kim Alvefur <zash@zash.se>
parents:
11601
diff
changeset
|
433 if mod.module.status_message then |
78ec0741c2bc
mod_admin_shell: module:info: Show module status
Kim Alvefur <zash@zash.se>
parents:
11601
diff
changeset
|
434 print(" status: [" .. mod.module.status_type .. "] " .. mod.module.status_message); |
78ec0741c2bc
mod_admin_shell: module:info: Show module status
Kim Alvefur <zash@zash.se>
parents:
11601
diff
changeset
|
435 end |
11605
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
436 if mod.module.items and next(mod.module.items) ~= nil then |
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
437 print(" provides:"); |
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
438 for kind, items in pairs(mod.module.items) do |
11606
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
439 local label = friendly_descriptions[kind] or kind:gsub("%-", " "):gsub("^%a", string.upper); |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
440 print(string.format(" - %s (%d item%s)", label, #items, #items > 1 and "s" or "")); |
11607
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
441 local formatter = item_formatters[kind]; |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
442 if formatter then |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
443 for _, item in ipairs(items) do |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
444 print(" - " .. formatter(item)); |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
445 end |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
446 end |
11605
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
447 end |
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
448 end |
11603
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
449 if mod.module.dependencies and next(mod.module.dependencies) ~= nil then |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
450 print(" dependencies:"); |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
451 for dep in pairs(mod.module.dependencies) do |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
452 print(" - mod_" .. dep); |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
453 end |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
454 end |
11601
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
455 end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
456 return true; |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
457 end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
458 |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
459 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
|
460 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
|
461 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
462 -- 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
|
463 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
|
464 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
|
465 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
|
466 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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
473 break; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
474 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
475 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
|
476 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
477 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
|
478 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
|
479 end |
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
482 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
483 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
|
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
486 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
|
487 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
|
488 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
489 -- 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
|
490 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
|
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 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
|
497 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
498 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
|
499 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
502 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
503 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
|
504 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
505 |
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 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
|
507 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
|
508 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
|
509 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
|
510 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
511 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
512 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
|
513 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
|
514 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
515 -- 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
|
516 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
|
517 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
|
518 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
|
519 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
|
520 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
|
521 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
|
522 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
|
523 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
524 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
|
525 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
|
526 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
|
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 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
|
529 end |
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
532 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
|
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
535 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
|
536 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
|
537 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
538 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
|
539 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
|
540 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
|
541 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
|
542 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
|
543 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
|
544 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
|
545 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
546 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
|
547 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
548 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
549 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
|
550 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
|
551 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
|
552 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
|
553 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
|
554 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
555 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
|
556 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
557 end |
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
560 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
561 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
|
562 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
|
563 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
|
564 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
|
565 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
|
566 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
|
567 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
568 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
|
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
571 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
|
572 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
|
573 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
|
574 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
575 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
|
576 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
|
577 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
578 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
579 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
|
580 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
|
581 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
|
582 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
583 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
584 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
|
585 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
|
586 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
|
587 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
588 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
|
589 end |
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
592 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
|
593 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
|
594 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
|
595 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
|
596 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
|
597 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
|
598 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
|
599 end |
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] = 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
|
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 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
|
603 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
|
604 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
605 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
|
606 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
|
607 end |
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.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
|
609 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
|
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 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
|
612 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
|
613 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
614 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
|
615 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
|
616 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
617 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
|
618 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
|
619 end |
11041
d00bfa75999d
mod_admin_shell: Report CSI state in c2s:show()
Kim Alvefur <zash@zash.se>
parents:
10988
diff
changeset
|
620 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
|
621 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
|
622 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
|
623 else |
8a243ab49cb5
mod_admin_shell: Report CSI queue length from mod_csi_simple
Kim Alvefur <zash@zash.se>
parents:
11041
diff
changeset
|
624 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
|
625 end |
11041
d00bfa75999d
mod_admin_shell: Report CSI state in c2s:show()
Kim Alvefur <zash@zash.se>
parents:
10988
diff
changeset
|
626 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
|
627 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
|
628 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
|
629 end |
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 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
|
631 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
|
632 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
633 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
|
634 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
|
635 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
|
636 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
|
637 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
638 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
|
639 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
|
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 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
|
642 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
|
643 end |
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 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
|
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 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
|
648 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
|
649 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
|
650 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
|
651 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
|
652 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
|
653 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
|
654 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
|
655 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
|
656 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
657 -- 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
|
658 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
|
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 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
|
661 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
|
662 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
|
663 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
|
664 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
665 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
666 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
|
667 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
|
668 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
|
669 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
673 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
674 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
|
675 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
676 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
|
677 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
678 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
679 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
|
680 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
681 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
|
682 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
|
683 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
|
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 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
|
687 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
|
688 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
|
689 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
|
690 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
|
691 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
|
692 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
693 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
694 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
|
695 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
|
696 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
|
697 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
|
698 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
|
699 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
|
700 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
701 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
702 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
|
703 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
|
704 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
|
705 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
|
706 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
|
707 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
708 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
|
709 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
710 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
|
711 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
|
712 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
|
713 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
714 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
715 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
716 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
|
717 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
|
718 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
|
719 end |
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 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
|
722 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
|
723 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
|
724 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
|
725 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
|
726 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
|
727 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
|
728 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
|
729 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
730 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
|
731 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
|
732 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
|
733 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
734 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
735 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
|
736 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
737 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
738 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
|
739 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
|
740 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
|
741 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
|
742 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
|
743 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
|
744 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
745 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
746 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
|
747 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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
749 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
|
750 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
|
751 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
|
752 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
|
753 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
|
754 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
|
755 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
756 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
757 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
|
758 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
759 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
760 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
|
761 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
|
762 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
763 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
764 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
|
765 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
|
766 return { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
767 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
|
768 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
|
769 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
770 end |
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
773 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
|
774 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
|
775 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
|
776 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
|
777 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
|
778 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
|
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 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
|
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
784 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
|
785 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
|
786 --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
|
787 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
|
788 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
|
789 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
|
790 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
791 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
|
792 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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
794 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
795 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
|
796 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
|
797 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
|
798 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
|
799 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
800 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
|
801 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
|
802 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
803 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
|
804 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
|
805 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
|
806 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
|
807 direction = "->"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
808 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
|
809 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
|
810 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
811 direction = "<-"; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
812 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
|
813 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
|
814 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
815 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
|
816 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
|
817 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
818 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
|
819 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
|
820 -- 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
|
821 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
|
822 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
|
823 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
|
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 if session.type == "s2sout_unauthed" then |
11504
1f700f5f62cb
mod_admin_shell: Remove obsolete checks related to s2sout.lib
Kim Alvefur <zash@zash.se>
parents:
11478
diff
changeset
|
826 if session.notopen 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
|
827 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
|
828 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
|
829 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
|
830 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
|
831 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
|
832 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
833 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
834 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
|
835 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
|
836 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
|
837 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
|
838 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
|
839 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
|
840 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
841 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
842 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
843 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
844 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
845 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
846 -- 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
|
847 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
|
848 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
|
849 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
|
850 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
851 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
|
852 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
|
853 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
|
854 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
|
855 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
856 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
|
857 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
858 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
859 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
|
860 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
|
861 end |
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 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
|
864 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
|
865 print( |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
866 (" %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
|
867 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
|
868 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
|
869 ) |
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
872 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
873 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
874 -- 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
|
875 -- 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
|
876 -- 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
|
877 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
|
878 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
|
879 print( |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
880 (" %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
|
881 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
|
882 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
|
883 ) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
884 ); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
885 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
886 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
887 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
888 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
|
889 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
|
890 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
|
891 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
|
892 /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
|
893 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
|
894 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
|
895 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
|
896 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
|
897 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
|
898 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
|
899 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
|
900 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
901 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
902 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
|
903 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
|
904 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
|
905 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
|
906 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
|
907 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
|
908 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
|
909 { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
910 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
|
911 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
|
912 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
|
913 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
914 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
|
915 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
|
916 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
|
917 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
918 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
919 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
|
920 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
|
921 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
|
922 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
925 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
926 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
927 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
928 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
|
929 -- 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
|
930 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
|
931 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
932 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
|
933 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
|
934 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
935 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
936 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
|
937 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
|
938 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
939 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
|
940 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
|
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
943 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
|
944 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
|
945 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
|
946 print("---") |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
947 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
|
948 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
949 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
|
950 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
|
951 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
|
952 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
|
953 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
|
954 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
955 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
958 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
959 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
|
960 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
|
961 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
|
962 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
|
963 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
964 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
|
965 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
|
966 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
967 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
968 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
|
969 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
|
970 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
971 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
|
972 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
|
973 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
|
974 end |
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("---"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
976 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
|
977 ..(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
|
978 .." 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
|
979 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
980 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
981 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
|
982 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
|
983 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
|
984 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
985 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
|
986 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
|
987 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
|
988 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
|
989 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
|
990 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
|
991 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
|
992 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
993 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
994 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
|
995 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
|
996 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
|
997 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
|
998 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
|
999 (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
|
1000 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
|
1001 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1002 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1003 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
|
1004 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1005 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1006 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
|
1007 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
|
1008 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
|
1009 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
|
1010 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
|
1011 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
|
1012 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
|
1013 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1014 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1015 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
|
1016 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
|
1017 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1018 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1019 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
|
1020 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1021 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
|
1022 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
|
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 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
|
1025 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
|
1026 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1027 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1028 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
|
1029 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
|
1030 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
|
1031 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
|
1032 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
|
1033 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
|
1034 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
|
1035 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
|
1036 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
|
1037 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1038 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
|
1039 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
|
1040 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
|
1041 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1042 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
|
1043 end |
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 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
|
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 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
|
1049 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1050 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
|
1051 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
|
1052 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
|
1053 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
|
1054 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
|
1055 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
|
1056 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
|
1057 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
|
1058 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
|
1059 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
|
1060 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1061 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1062 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
|
1063 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
|
1064 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1065 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
|
1066 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1067 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1068 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
|
1069 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
|
1070 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
|
1071 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
|
1072 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
|
1073 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
|
1074 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
|
1075 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
|
1076 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
|
1077 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
|
1078 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
|
1079 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
|
1080 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1081 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
|
1082 end |
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1085 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1086 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1087 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
|
1088 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1089 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1090 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
|
1091 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1092 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
|
1093 __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
|
1094 __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
|
1095 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
|
1096 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1097 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1098 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1099 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
|
1100 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
|
1101 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
|
1102 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
|
1103 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
|
1104 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
|
1105 end |
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 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
|
1107 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1108 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1109 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
|
1110 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
|
1111 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
|
1112 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
|
1113 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1114 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
|
1115 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
|
1116 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
|
1117 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
|
1118 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1119 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1120 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
|
1121 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
|
1122 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
|
1123 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
|
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 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
|
1126 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
|
1127 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
|
1128 end |
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 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
|
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1132 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
|
1133 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
|
1134 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
|
1135 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
|
1136 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1137 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
|
1138 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
|
1139 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
|
1140 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
|
1141 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
|
1142 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1143 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
|
1144 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1145 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1146 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
|
1147 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1148 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
|
1149 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
|
1150 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
|
1151 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
|
1152 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
|
1153 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
|
1154 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
|
1155 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1156 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
|
1157 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
|
1158 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
|
1159 else |
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, "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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1163 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1164 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
|
1165 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
|
1166 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
|
1167 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
|
1168 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
|
1169 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
|
1170 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1171 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
|
1172 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
|
1173 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
|
1174 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1175 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1178 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1179 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
|
1180 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
|
1181 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
|
1182 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
|
1183 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
|
1184 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
|
1185 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1186 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
|
1187 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
|
1188 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
|
1189 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1190 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
|
1191 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1192 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1193 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1194 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
|
1195 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
|
1196 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
|
1197 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
|
1198 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
|
1199 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1200 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
|
1201 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
|
1202 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
|
1203 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
|
1204 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
|
1205 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
|
1206 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1207 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
|
1208 end |
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, "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
|
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 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
|
1213 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1214 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
|
1215 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
|
1216 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
|
1217 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
|
1218 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
|
1219 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
|
1220 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
|
1221 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
|
1222 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1223 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
|
1224 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
|
1225 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
|
1226 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
|
1227 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1228 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
|
1229 :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
|
1230 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
|
1231 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
|
1232 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
|
1233 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
|
1234 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1235 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1238 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1239 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
|
1240 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
|
1241 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1242 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
|
1243 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
|
1244 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
|
1245 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
|
1246 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
|
1247 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1248 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
|
1249 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1250 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1251 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
|
1252 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
|
1253 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
|
1254 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
|
1255 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
|
1256 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
|
1257 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
|
1258 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1259 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1260 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1261 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
|
1262 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
|
1263 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
|
1264 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
|
1265 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1266 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1267 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
|
1268 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
|
1269 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
|
1270 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
|
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.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
|
1274 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
|
1275 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
|
1276 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
|
1277 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1278 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1279 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
|
1280 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
|
1281 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
|
1282 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1283 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1284 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
|
1285 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1286 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
|
1287 local print = self.session.print; |
11361
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
1288 hosts = array.collect(set.new({ not hosts and "*" or nil }) + get_hosts_set(hosts)):sort(_sort_hosts); |
11364
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11363
diff
changeset
|
1289 local output = format_table({ |
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11363
diff
changeset
|
1290 { title = "Module", width = "20%" }, |
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11363
diff
changeset
|
1291 { title = "URL", width = "80%" }, |
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11363
diff
changeset
|
1292 }, 132); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1293 |
11361
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
1294 for _, host in ipairs(hosts) do |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1295 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
|
1296 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
|
1297 local http_host = module:context(host):get_option_string("http_host"); |
11361
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
1298 if host == "*" then |
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
1299 print("Global HTTP endpoints available on all hosts:"); |
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
1300 else |
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
1301 print("HTTP endpoints on "..host..(http_host and (" (using "..http_host.."):") or ":")); |
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
1302 end |
11364
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11363
diff
changeset
|
1303 print(output()); |
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 for _, provider in ipairs(http_apps) do |
11362
52d93fba2ee1
mod_admin_shell: List modules providing each HTTP endpoint
Kim Alvefur <zash@zash.se>
parents:
11361
diff
changeset
|
1305 local mod = provider._provided_by; |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1306 local url = module:context(host):http_url(provider.name, provider.default_path); |
11362
52d93fba2ee1
mod_admin_shell: List modules providing each HTTP endpoint
Kim Alvefur <zash@zash.se>
parents:
11361
diff
changeset
|
1307 mod = mod and "mod_"..mod or "" |
11364
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11363
diff
changeset
|
1308 print(output{mod, url}); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1309 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1310 print(""); |
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1314 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
|
1315 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
|
1316 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
|
1317 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1318 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
|
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 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
|
1321 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1322 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1323 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
|
1324 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1325 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
|
1326 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
|
1327 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
|
1328 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1329 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1330 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
|
1331 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
|
1332 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
|
1333 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
|
1334 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
|
1335 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
|
1336 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
|
1337 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1338 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
|
1339 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1340 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1341 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
|
1342 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1343 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
|
1344 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1345 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1346 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
|
1347 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
|
1348 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
|
1349 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
|
1350 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
|
1351 return t; |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1352 end |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1353 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
|
1354 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
|
1355 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
|
1356 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
|
1357 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
|
1358 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
|
1359 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
|
1360 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
|
1361 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
|
1362 end |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1363 if h then |
11478
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
1364 local timers = {}; |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1365 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
|
1366 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
|
1367 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
|
1368 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
|
1369 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
|
1370 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
|
1371 else |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1372 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
|
1373 end |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1374 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
|
1375 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
|
1376 end |
11478
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
1377 table.insert(timers, { format_time(t), cb }); |
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
1378 end |
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
1379 table.sort(timers, function (a, b) return a[1] < b[1] end); |
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
1380 for _, t in ipairs(timers) do |
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
1381 print(t[1], t[2]) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1382 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1383 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1384 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
|
1385 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
|
1386 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
|
1387 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
|
1388 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
|
1389 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1390 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1391 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
|
1392 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1393 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
|
1394 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
|
1395 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
|
1396 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
|
1397 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1398 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1399 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
|
1400 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1401 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1402 -- 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
|
1403 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
|
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 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
|
1406 |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1407 local short_units = { |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1408 seconds = "s", |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1409 bytes = "B", |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1410 }; |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1411 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1412 local stats_methods = {}; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1413 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1414 function stats_methods:render_single_fancy_histogram_ex(print, prefix, metric_family, metric, cumulative) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1415 local creation_timestamp, sum, count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1416 local buckets = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1417 local prev_bucket_count = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1418 for suffix, extra_labels, value in metric:iter_samples() do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1419 if suffix == "_created" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1420 creation_timestamp = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1421 elseif suffix == "_sum" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1422 sum = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1423 elseif suffix == "_count" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1424 count = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1425 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1426 local bucket_threshold = extra_labels["le"] |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1427 local bucket_count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1428 if cumulative then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1429 bucket_count = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1430 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1431 bucket_count = value - prev_bucket_count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1432 prev_bucket_count = value |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1433 end |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1434 if bucket_threshold == "+Inf" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1435 t_insert(buckets, {threshold = 1/0, count = bucket_count}) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1436 elseif bucket_threshold ~= nil then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1437 t_insert(buckets, {threshold = tonumber(bucket_threshold), count = bucket_count}) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1438 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
|
1439 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1440 end |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1441 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1442 if #buckets == 0 or not creation_timestamp or not sum or not count then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1443 print("[no data or not a histogram]") |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1444 return false |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1445 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
|
1446 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1447 local graph_width, graph_height, wscale = #buckets, 10, 1; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1448 if graph_width < 8 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1449 wscale = 8 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1450 elseif graph_width < 16 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1451 wscale = 4 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1452 elseif graph_width < 32 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1453 wscale = 2 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1454 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1455 local eighth_chars = " ▁▂▃▄▅▆▇█"; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1456 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1457 local max_bin_samples = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1458 for _, bucket in ipairs(buckets) do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1459 if bucket.count > max_bin_samples then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1460 max_bin_samples = bucket.count |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1461 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1462 end |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1463 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1464 print(""); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1465 print(prefix) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1466 print(("_"):rep(graph_width*wscale).." "..max_bin_samples); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1467 for row = graph_height, 1, -1 do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1468 local row_chars = {}; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1469 local min_eighths, max_eighths = 8, 0; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1470 for i = 1, #buckets do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1471 local char_eighths = math.ceil(math.max(math.min((graph_height/(max_bin_samples/buckets[i].count))-(row-1), 1), 0)*8); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1472 if char_eighths < min_eighths then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1473 min_eighths = char_eighths; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1474 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1475 if char_eighths > max_eighths then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1476 max_eighths = char_eighths; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1477 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1478 if char_eighths == 0 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1479 row_chars[i] = ("-"):rep(wscale); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1480 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1481 local char = eighth_chars:sub(char_eighths*3+1, char_eighths*3+3); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1482 row_chars[i] = char:rep(wscale); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1483 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1484 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1485 print(table.concat(row_chars).."|- "..string.format("%.8g", math.ceil((max_bin_samples/graph_height)*(row-0.5)))); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1486 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1487 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1488 local legend_pat = string.format("%%%d.%dg", wscale-1, wscale-1) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1489 local row = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1490 for i = 1, #buckets do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1491 local threshold = buckets[i].threshold |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1492 t_insert(row, legend_pat:format(threshold)) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1493 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1494 t_insert(row, " " .. metric_family.unit) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1495 print(t_concat(row, "/")) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1496 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1497 return true |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1498 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1499 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1500 function stats_methods:render_single_fancy_histogram(print, prefix, metric_family, metric) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1501 return self:render_single_fancy_histogram_ex(print, prefix, metric_family, metric, false) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1502 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1503 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1504 function stats_methods:render_single_fancy_histogram_cf(print, prefix, metric_family, metric) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1505 -- cf = cumulative frequency |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1506 return self:render_single_fancy_histogram_ex(print, prefix, metric_family, metric, true) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1507 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1508 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1509 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
|
1510 for _, stat_info in ipairs(self) do |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1511 local family_name, metric_family = unpack(stat_info, 1, 2) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1512 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
|
1513 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
|
1514 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1515 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1516 if not self:render_family(print, family_name, metric_family, self.render_single_fancy_histogram_cf) then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1517 return self |
10856
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1520 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
|
1521 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1522 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1523 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
|
1524 for _, stat_info in ipairs(self) do |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1525 local family_name, metric_family = unpack(stat_info, 1, 2) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1526 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
|
1527 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
|
1528 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1529 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1530 if not self:render_family(print, family_name, metric_family, self.render_single_fancy_histogram) then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1531 return self |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1532 end |
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 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
|
1535 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1536 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1537 function stats_methods:render_single_counter(print, prefix, metric_family, metric) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1538 local created_timestamp, current_value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1539 for suffix, _, value in metric:iter_samples() do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1540 if suffix == "_created" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1541 created_timestamp = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1542 elseif suffix == "_total" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1543 current_value = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1544 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1545 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1546 if current_value and created_timestamp then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1547 local base_unit = short_units[metric_family.unit] or metric_family.unit |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1548 local unit = base_unit .. "/s" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1549 local factor = 1 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1550 if base_unit == "s" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1551 -- be smart! |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1552 unit = "%" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1553 factor = 100 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1554 elseif base_unit == "" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1555 unit = "events/s" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1556 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1557 print(("%-50s %s"):format(prefix, format_number(factor * current_value / (self.now - created_timestamp), unit.." [avg]"))); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1558 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1559 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1560 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1561 function stats_methods:render_single_gauge(print, prefix, metric_family, metric) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1562 local current_value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1563 for _, _, value in metric:iter_samples() do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1564 current_value = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1565 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1566 if current_value then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1567 local unit = short_units[metric_family.unit] or metric_family.unit |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1568 print(("%-50s %s"):format(prefix, format_number(current_value, unit))); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1569 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1570 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1571 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1572 function stats_methods:render_single_summary(print, prefix, metric_family, metric) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1573 local sum, count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1574 for suffix, _, value in metric:iter_samples() do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1575 if suffix == "_sum" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1576 sum = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1577 elseif suffix == "_count" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1578 count = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1579 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1580 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1581 if sum and count then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1582 local unit = short_units[metric_family.unit] or metric_family.unit |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1583 if count == 0 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1584 print(("%-50s %s"):format(prefix, "no obs.")); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1585 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1586 print(("%-50s %s"):format(prefix, format_number(sum / count, unit.."/event [avg]"))); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1587 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1588 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1589 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1590 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1591 function stats_methods:render_family(print, family_name, metric_family, render_func) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1592 local labelkeys = metric_family.label_keys |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1593 if #labelkeys > 0 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1594 print(family_name) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1595 for labelset, metric in metric_family:iter_metrics() do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1596 local labels = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1597 for i, k in ipairs(labelkeys) do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1598 local v = labelset[i] |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1599 t_insert(labels, ("%s=%s"):format(k, v)) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1600 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1601 local prefix = " "..t_concat(labels, " ") |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1602 render_func(self, print, prefix, metric_family, metric) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1603 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1604 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1605 for _, metric in metric_family:iter_metrics() do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1606 render_func(self, print, family_name, metric_family, metric) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1607 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1608 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1609 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1610 |
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 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
|
1612 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
|
1613 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
|
1614 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
|
1615 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
|
1616 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1617 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
|
1618 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
|
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 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1621 else |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1622 local metric_family = stat_info[2] |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1623 if metric_family.type_ == "counter" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1624 stats:render_family(print, stat_info[1], metric_family, stats.render_single_counter) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1625 elseif metric_family.type_ == "gauge" or metric_family.type_ == "unknown" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1626 stats:render_family(print, stat_info[1], metric_family, stats.render_single_gauge) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1627 elseif metric_family.type_ == "summary" or metric_family.type_ == "histogram" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1628 stats:render_family(print, stat_info[1], metric_family, stats.render_single_summary) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1629 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
|
1630 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1631 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1632 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
|
1633 end |
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 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
|
1636 local function new_stats_context(self) |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1637 -- TODO: instead of now(), it might be better to take the time of the last |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1638 -- interval, if the statistics backend is set to use periodic collection |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1639 -- Otherwise we get strange stuff like average cpu usage decreasing until |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1640 -- the next sample and so on. |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1641 return setmetatable({ session = self.session, stats = true, now = time.now() }, stats_mt); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1642 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1643 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1644 function def_env.stats:show(name_filter) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1645 local statsman = require "core.statsmanager" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1646 local collect = statsman.collect |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1647 if collect then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1648 -- force collection if in manual mode |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1649 collect() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1650 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1651 local metric_registry = statsman.get_metric_registry(); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1652 local displayed_stats = new_stats_context(self); |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1653 for family_name, metric_family in iterators.sorted_pairs(metric_registry:get_metric_families()) do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1654 if not name_filter or family_name:match(name_filter) 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
|
1655 table.insert(displayed_stats, { |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1656 family_name, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1657 metric_family, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1658 output = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1659 }) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1660 end |
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 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
|
1663 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1664 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1665 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1666 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1667 ------------- |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1668 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1669 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
|
1670 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
|
1671 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
|
1672 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
|
1673 ____ \ / _ |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1674 | _ \ _ __ ___ ___ _-_ __| |_ _ |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1675 | |_) | '__/ _ \/ __|/ _ \ / _` | | | | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1676 | __/| | | (_) \__ \ |_| | (_| | |_| | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1677 |_| |_| \___/|___/\___/ \__,_|\__, | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1678 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
|
1679 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1680 ]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1681 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1682 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
|
1683 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
|
1684 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
|
1685 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
|
1686 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1687 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
|
1688 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
|
1689 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1690 end |