Software /
code /
prosody
Annotate
plugins/mod_admin_shell.lua @ 12018:c65789f5004e
mod_admin_shell: Only check that local users exist locally
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 06 Dec 2021 22:23:38 +0100 |
parent | 12014:efbf288b529e |
child | 12019:a0b6896bb538 |
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"; |
11949
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11946
diff
changeset
|
38 local promise = require "util.promise"; |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
40 local t_insert = table.insert; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
41 local t_concat = table.concat; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
42 |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
43 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
|
44 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
|
45 |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
46 local function capitalize(s) |
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
47 if not s then return end |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
48 return (s:gsub("^%a", string.upper):gsub("_", " ")); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
49 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
50 |
11931
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
51 local function pre(prefix, str, alt) |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
52 if (str or "") == "" then return alt or ""; end |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
53 return prefix .. str; |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
54 end |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
55 |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
56 local function suf(str, suffix, alt) |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
57 if (str or "") == "" then return alt or ""; end |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
58 return str .. suffix; |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
59 end |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
60 |
10856
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 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
|
62 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
|
63 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
|
64 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 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
|
73 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 console = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 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
|
78 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 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
|
80 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
|
81 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 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
|
83 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
|
84 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 |
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
|
86 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
|
87 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
|
88 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 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
|
91 local session = { |
11950
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
92 send = function (t) |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
93 return send_repl_output(admin_session, t); |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
94 end; |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
95 print = function (...) |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
96 local t = {}; |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
97 for i=1,select("#", ...) do |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
98 t[i] = tostring(select(i, ...)); |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
99 end |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
100 return send_repl_output(admin_session, table.concat(t, "\t")); |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
101 end; |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
102 serialize = tostring; |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
103 disconnect = function () admin_session:close(); end; |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
104 }; |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 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
|
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 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
|
108 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
|
109 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
|
110 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 -- 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
|
112 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
|
113 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
|
114 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
|
115 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 end |
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 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
|
119 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 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
|
121 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
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 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
|
130 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
|
131 |
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
|
132 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
|
133 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 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
|
142 return; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 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
|
147 |
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 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
|
149 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
|
150 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
|
151 return; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 |
11736
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
154 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
|
155 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
|
156 end |
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
157 |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 local chunkname = "=console"; |
11736
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
159 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
|
160 -- 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 return; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 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
|
176 |
11949
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11946
diff
changeset
|
177 if promise.is_promise(taskok) then |
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11946
diff
changeset
|
178 taskok, message = async.wait_for(taskok); |
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11946
diff
changeset
|
179 end |
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11946
diff
changeset
|
180 |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 if not 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 |
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
|
193 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
|
194 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 |
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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 -- 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
|
204 -- 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
|
205 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 print [[]] |
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 - 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 elseif section == "c2s" then |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
228 print [[c2s:show(jid, columns) - Show all client sessions with the specified JID (or all if no JID given)]] |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
229 print [[c2s:show_tls(jid) - Show TLS cipher info for encrypted sessions]] |
10856
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 [[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
|
231 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
|
232 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
|
233 elseif section == "s2s" then |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
234 print [[s2s:show(domain, columns) - Show all s2s connections for the given domain (or all if no domain given)]] |
10856
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 [[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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 elseif section == "user" then |
12012
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11991
diff
changeset
|
251 print [[user:create(jid, password, roles) - Create the specified user account]] |
10856
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 [[user:password(jid, password) - Set the password for the specified user account]] |
12014
efbf288b529e
mod_admin_shell: Support setting roles on hosts other than the users'
Kim Alvefur <zash@zash.se>
parents:
12013
diff
changeset
|
253 print [[user:roles(jid, host, roles) - Set roles for an user (see 'help roles')]] |
10856
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 [[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
|
255 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
|
256 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
|
257 -- 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 -- 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 print [[]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
292 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
|
293 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
|
294 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
|
295 print [[]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
296 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
|
297 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
|
298 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
|
299 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
300 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
301 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
302 -- 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
|
303 -- 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
|
304 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
305 --luacheck: ignore 212/self |
11891
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
306 local serialize_defaults = module:get_option("console_prettyprint_settings", |
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
307 { fatal = false; unquoted = true; maxdepth = 2; table_iterator = "pairs" }) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
308 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
309 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
|
310 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
|
311 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
|
312 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
|
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 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
|
315 -- 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
|
316 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
|
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 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
|
319 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
|
320 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
|
321 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
322 end |
11891
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
323 if opts.table_iterator == "pairs" then |
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
324 opts.table_iterator = pairs; |
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
325 elseif type(opts.table_iterator) ~= "function" then |
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
326 opts.table_iterator = nil; -- rawpairs is the default |
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
327 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
|
328 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
|
329 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
330 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
331 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
|
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: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
|
334 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
|
335 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
|
336 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
|
337 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
|
338 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
339 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
340 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
|
341 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
|
342 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
343 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
357 |
11831
94cd363116a3
mod_admin_shell: Allow passing an exit code to server:shutdown()
Kim Alvefur <zash@zash.se>
parents:
11736
diff
changeset
|
358 function def_env.server:shutdown(reason, code) |
94cd363116a3
mod_admin_shell: Allow passing an exit code to server:shutdown()
Kim Alvefur <zash@zash.se>
parents:
11736
diff
changeset
|
359 prosody.shutdown(reason, code); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
360 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
|
361 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
362 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
363 local function human(kb) |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
364 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
|
365 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
366 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
367 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
|
368 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
|
369 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
|
370 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
371 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
|
372 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
|
373 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
|
374 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
|
375 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
|
376 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
|
377 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
378 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
379 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
|
380 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
381 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
388 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
|
389 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
|
390 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
|
391 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
|
392 end |
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 |
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 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
|
396 -- 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
|
397 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
|
398 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
|
399 / 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
|
400 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
|
401 -- 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
|
402 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
|
403 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
|
404 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
405 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
|
406 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
407 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
408 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
|
409 -- 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
|
410 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
|
411 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
|
412 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
413 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
|
414 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
415 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
416 -- 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
|
417 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
|
418 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
419 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
|
420 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
|
421 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
422 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
|
423 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
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 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
|
426 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
|
427 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
|
428 end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
429 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
|
430 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
|
431 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
|
432 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
|
433 end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
434 |
11932
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11931
diff
changeset
|
435 local function item_name(item) return item.name; end |
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11931
diff
changeset
|
436 |
11606
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
437 local friendly_descriptions = { |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
438 ["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
|
439 ["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
|
440 ["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
|
441 ["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
|
442 ["storage-provider"] = "Storage driver", |
11931
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
443 ["measure"] = "Legacy metrics", |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
444 ["metric"] = "Metrics", |
11991
bef2a59b00d1
mod_admin_shell: List periodic tasks in module:info
Kim Alvefur <zash@zash.se>
parents:
11954
diff
changeset
|
445 ["task"] = "Periodic task", |
11606
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
446 }; |
11607
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
447 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
|
448 ["feature"] = tostring, |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
449 ["identity"] = function(ident) return ident.type .. "/" .. ident.category; end, |
11932
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11931
diff
changeset
|
450 ["adhoc-provider"] = item_name, |
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11931
diff
changeset
|
451 ["auth-provider"] = item_name, |
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11931
diff
changeset
|
452 ["storage-provider"] = item_name, |
11943
cf47834d3698
mod_admin_shell: Fix showing default HTTP path in module:info
Kim Alvefur <zash@zash.se>
parents:
11932
diff
changeset
|
453 ["http-provider"] = function(item, mod) return mod:http_url(item.name, item.default_path); end, |
11932
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11931
diff
changeset
|
454 ["net-provider"] = item_name, |
11931
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
455 ["measure"] = function(item) return item.name .. " (" .. suf(item.conf and item.conf.unit, " ") .. item.type .. ")"; end, |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
456 ["metric"] = function(item) |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
457 return ("%s (%s%s)%s"):format(item.name, suf(item.mf.unit, " "), item.mf.type_, pre(": ", item.mf.description)); |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
458 end, |
11991
bef2a59b00d1
mod_admin_shell: List periodic tasks in module:info
Kim Alvefur <zash@zash.se>
parents:
11954
diff
changeset
|
459 ["task"] = function (item) return string.format("%s (%s)", item.name or item.id, item.when); end |
11607
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
460 }; |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
461 |
11601
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
462 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
|
463 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
|
464 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
|
465 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
|
466 else |
7466bf65d7c8
mod_admin_shell: module:info: Use existing host string representation
Kim Alvefur <zash@zash.se>
parents:
11603
diff
changeset
|
467 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
|
468 end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
469 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
|
470 if mod.module.status_message then |
78ec0741c2bc
mod_admin_shell: module:info: Show module status
Kim Alvefur <zash@zash.se>
parents:
11601
diff
changeset
|
471 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
|
472 end |
11605
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
473 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
|
474 print(" provides:"); |
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
475 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
|
476 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
|
477 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
|
478 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
|
479 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
|
480 for _, item in ipairs(items) do |
11850
bfa85965106e
mod_admin_shell: Show HTTP base-URLs in module:info()
Kim Alvefur <zash@zash.se>
parents:
11831
diff
changeset
|
481 print(" - " .. formatter(item, mod.module)); |
11607
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
482 end |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
483 end |
11605
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
484 end |
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
485 end |
11603
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
486 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
|
487 print(" dependencies:"); |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
488 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
|
489 print(" - mod_" .. dep); |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
490 end |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
491 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
|
492 end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
493 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
|
494 end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
495 |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
496 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
|
497 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
|
498 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
499 -- 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
|
500 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
|
501 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
|
502 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
|
503 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
|
504 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
|
505 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
|
506 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
|
507 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
|
508 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
|
509 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 break; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
511 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
512 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
|
513 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
514 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
|
515 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
|
516 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
517 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
518 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
519 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
520 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
|
521 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
522 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
523 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
|
524 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
|
525 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
526 -- 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
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 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
|
534 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
535 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
|
536 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
|
537 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
538 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
539 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
540 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
|
541 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
542 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
543 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
|
544 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
|
545 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
|
546 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
|
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
549 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
|
550 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
|
551 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
552 -- 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
|
553 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
|
554 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
|
555 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
|
556 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
|
557 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
|
558 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
|
559 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
|
560 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
561 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
|
562 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
|
563 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
|
564 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
565 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
|
566 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
567 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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
569 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
|
570 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
571 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
572 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
|
573 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
|
574 |
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 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
|
576 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
|
577 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
|
578 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
|
579 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
|
580 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
|
581 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
|
582 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
583 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
|
584 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
585 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
586 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
|
587 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
|
588 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
|
589 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
|
590 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
|
591 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
592 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
|
593 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
594 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
595 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
596 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
597 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
598 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
|
599 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
|
600 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
|
601 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
|
602 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
|
603 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
|
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 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
|
606 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
607 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
608 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
|
609 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
|
610 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
|
611 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
612 local 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
|
613 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
|
614 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
615 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
616 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
|
617 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
|
618 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
|
619 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
620 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
621 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
|
622 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
623 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
|
624 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
|
625 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
|
626 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
627 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
628 local 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 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
|
634 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
635 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
636 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
|
637 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
|
638 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
|
639 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
|
640 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
|
641 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
|
642 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
643 |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
644 local function _sort_by_jid(a, b) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
645 if a.host == b.host then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
646 if a.username == b.username then return (a.resource or "") > (b.resource or ""); end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
647 return (a.username or "") > (b.username or ""); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
648 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
649 return _sort_hosts(a.host or "", b.host or ""); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
650 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
651 |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
652 local function show_c2s(callback) |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
653 get_c2s():sort(_sort_by_jid):map(function (session) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
654 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
|
655 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
656 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
657 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
658 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
|
659 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
|
660 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
|
661 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
662 |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
663 local function get_s2s_hosts(session) --> local,remote |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
664 if session.direction == "outgoing" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
665 return session.host or session.from_host, session.to_host; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
666 elseif session.direction == "incoming" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
667 return session.host or session.to_host, session.from_host; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
668 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
|
669 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
670 |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
671 local available_columns = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
672 jid = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
673 title = "JID"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
674 width = 32; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
675 key = "full_jid"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
676 mapper = function(full_jid, session) return full_jid or get_jid(session) end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
677 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
678 host = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
679 title = "Host"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
680 key = "host"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
681 width = 22; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
682 mapper = function(host, session) |
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
683 return host or get_s2s_hosts(session) or "?"; |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
684 end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
685 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
686 remote = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
687 title = "Remote"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
688 width = 22; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
689 mapper = function(_, session) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
690 return select(2, get_s2s_hosts(session)); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
691 end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
692 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
693 dir = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
694 title = "Dir"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
695 width = 3; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
696 key = "direction"; |
11888
050c515fe9aa
mod_admin_shell: Indicate bi-directional s2s connections
Kim Alvefur <zash@zash.se>
parents:
11887
diff
changeset
|
697 mapper = function(dir, session) |
050c515fe9aa
mod_admin_shell: Indicate bi-directional s2s connections
Kim Alvefur <zash@zash.se>
parents:
11887
diff
changeset
|
698 if session.incoming and session.outgoing then return "<->"; end |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
699 if dir == "outgoing" then return "-->"; end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
700 if dir == "incoming" then return "<--"; end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
701 end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
702 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
703 id = { title = "Session ID"; width = 20; key = "id" }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
704 type = { title = "Type"; width = #"c2s_unauthed"; key = "type" }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
705 method = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
706 title = "Method"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
707 width = 10; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
708 mapper = function(_, session) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
709 if session.bosh_version then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
710 return "BOSH"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
711 elseif session.websocket_request then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
712 return "WebSocket"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
713 else |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
714 return "TCP"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
715 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
716 end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
717 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
718 ipv = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
719 title = "IPv"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
720 width = 4; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
721 key = "ip"; |
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
722 mapper = function(ip) if ip then return ip:find(":") and "IPv6" or "IPv4"; end end; |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
723 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
724 ip = { title = "IP address"; width = 40; key = "ip" }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
725 status = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
726 title = "Status"; |
11946
c0a01e5f5656
mod_admin_shell: Reduce width of 'Status' column
Kim Alvefur <zash@zash.se>
parents:
11945
diff
changeset
|
727 width = 6; |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
728 key = "presence"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
729 mapper = function(p) |
11946
c0a01e5f5656
mod_admin_shell: Reduce width of 'Status' column
Kim Alvefur <zash@zash.se>
parents:
11945
diff
changeset
|
730 if not p then return ""; end |
c0a01e5f5656
mod_admin_shell: Reduce width of 'Status' column
Kim Alvefur <zash@zash.se>
parents:
11945
diff
changeset
|
731 return p:get_child_text("show") or "online"; |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
732 end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
733 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
734 secure = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
735 title = "Security"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
736 key = "conn"; |
11945
142b9c4010fe
mod_admin_shell: Reduce width of 'Security' column (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
11943
diff
changeset
|
737 width = 8; |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
738 mapper = function(conn, session) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
739 if not session.secure then return "insecure"; end |
11905
bbfa707a4756
mod_admin_shell: Handle absence of connection in security column (thanks arcseconds)
Kim Alvefur <zash@zash.se>
parents:
11892
diff
changeset
|
740 if not conn or not conn:ssl() then return "secure" end |
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
741 local sock = conn and conn:socket(); |
11945
142b9c4010fe
mod_admin_shell: Reduce width of 'Security' column (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
11943
diff
changeset
|
742 if not sock then return "secure"; end |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
743 local tls_info = sock.info and sock:info(); |
11945
142b9c4010fe
mod_admin_shell: Reduce width of 'Security' column (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
11943
diff
changeset
|
744 return tls_info and tls_info.protocol or "secure"; |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
745 end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
746 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
747 encryption = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
748 title = "Encryption"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
749 width = 30; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
750 key = "conn"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
751 mapper = function(conn) |
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
752 local sock = conn:socket(); |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
753 local info = sock and sock.info and sock:info(); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
754 if info then return info.cipher end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
755 end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
756 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
757 cert = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
758 title = "Certificate"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
759 key = "cert_identity_status"; |
11889
df76802dc09c
mod_admin_shell: Specify a width for cert column
Kim Alvefur <zash@zash.se>
parents:
11888
diff
changeset
|
760 width = 13; |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
761 mapper = function(cert_status, session) |
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
762 if cert_status then return capitalize(cert_status); end |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
763 if session.cert_chain_status == "Invalid" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
764 local cert_errors = set.new(session.cert_chain_errors[1]); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
765 if cert_errors:contains("certificate has expired") then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
766 return "Expired"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
767 elseif cert_errors:contains("self signed certificate") then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
768 return "Self-signed"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
769 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
770 return "Untrusted"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
771 elseif session.cert_identity_status == "invalid" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
772 return "Mismatched"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
773 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
774 return "Not validated"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
775 end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
776 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
777 sni = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
778 title = "SNI"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
779 width = 22; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
780 mapper = function(_, session) |
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
781 if not session.conn then return end |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
782 local sock = session.conn:socket(); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
783 return sock and sock.getsniname and sock:getsniname() or ""; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
784 end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
785 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
786 alpn = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
787 title = "ALPN"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
788 width = 11; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
789 mapper = function(_, session) |
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
790 if not session.conn then return end |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
791 local sock = session.conn:socket(); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
792 return sock and sock.getalpn and sock:getalpn() or ""; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
793 end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
794 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
795 smacks = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
796 title = "SM"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
797 key = "smacks"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
798 width = 11; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
799 mapper = function(smacks_xmlns, session) |
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
800 if not smacks_xmlns then return "no"; end |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
801 if session.hibernating then return "hibernating"; end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
802 return "yes"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
803 end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
804 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
805 smacks_queue = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
806 title = "SM Queue"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
807 key = "outgoing_stanza_queue"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
808 width = 8; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
809 align = "right"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
810 mapper = function (queue) |
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
811 return queue and tostring(#queue); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
812 end |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
813 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
814 csi = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
815 title = "CSI State"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
816 key = "state"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
817 -- TODO include counter |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
818 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
819 s2s_sasl = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
820 title = "SASL"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
821 key = "external_auth"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
822 width = 10; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
823 mapper = capitalize |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
824 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
825 dialback = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
826 title = "Dialback"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
827 key = "dialback_key"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
828 width = 13; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
829 mapper = function (dialback_key, session) |
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
830 if not dialback_key then |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
831 if session.type == "s2sin" or session.type == "s2sout" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
832 return "Not used"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
833 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
834 return "Not initiated"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
835 elseif session.type == "s2sin_unauthed" or session.type == "s2sout_unauthed" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
836 return "Initiated"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
837 else |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
838 return "Completed"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
839 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
840 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
841 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
842 }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
843 |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
844 local function get_colspec(colspec, default) |
11887
b043e1bb8e8e
mod_admin_shell: Allow passing columns as a string for convenience
Kim Alvefur <zash@zash.se>
parents:
11886
diff
changeset
|
845 if type(colspec) == "string" then colspec = array(colspec:gmatch("%S+")); end |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
846 local columns = {}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
847 for i, col in pairs(colspec or default) do |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
848 if type(col) == "string" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
849 columns[i] = available_columns[col] or { title = capitalize(col); width = 20; key = col }; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
850 elseif type(col) ~= "table" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
851 return false, ("argument %d: expected string|table but got %s"):format(i, type(col)); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
852 else |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
853 columns[i] = col; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
854 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
855 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
856 |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
857 return columns; |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
858 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
859 |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
860 function def_env.c2s:show(match_jid, colspec) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
861 local print = self.session.print; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
862 local columns = get_colspec(colspec, { "id"; "jid"; "ipv"; "status"; "secure"; "smacks"; "csi" }); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
863 local row = format_table(columns, 120); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
864 |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
865 local function match(session) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
866 local jid = get_jid(session) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
867 return (not match_jid) or jid:match(match_jid) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
868 end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
869 |
11886
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
870 local group_by_host = true; |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
871 for _, col in ipairs(columns) do |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
872 if col.key == "full_jid" or col.key == "host" then |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
873 group_by_host = false; |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
874 break |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
875 end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
876 end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
877 |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
878 if not group_by_host then print(row()); end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
879 local currenthost = nil; |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
880 |
11917
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
881 local c2s_sessions = get_c2s(); |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
882 local total_count = #c2s_sessions; |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
883 c2s_sessions:filter(match):sort(_sort_by_jid); |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
884 local shown_count = #c2s_sessions; |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
885 for _, session in ipairs(c2s_sessions) do |
11886
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
886 if group_by_host and session.host ~= currenthost then |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
887 currenthost = session.host; |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
888 print("#",prosody.hosts[currenthost] or "Unknown host"); |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
889 print(row()); |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
890 end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
891 |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
892 print(row(session)); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
893 end |
11917
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
894 if total_count ~= shown_count then |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
895 return true, ("%d out of %d c2s sessions shown"):format(shown_count, total_count); |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
896 end |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
897 return true, ("%d c2s sessions shown"):format(total_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
|
898 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
899 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
900 function def_env.c2s:show_tls(match_jid) |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
901 return self:show(match_jid, { "jid"; "id"; "secure"; "encryption" }); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
902 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
903 |
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 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
|
905 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
|
906 return { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
907 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
|
908 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
911 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
912 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
913 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
|
914 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
|
915 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
|
916 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
|
917 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
|
918 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
|
919 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
920 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
921 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
|
922 end |
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 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
|
925 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
|
926 --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
|
927 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
|
928 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
|
929 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
|
930 end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
931 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
|
932 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
933 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
934 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
935 def_env.s2s = {}; |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
936 local function _sort_s2s(a, b) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
937 local a_local, a_remote = get_s2s_hosts(a); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
938 local b_local, b_remote = get_s2s_hosts(b); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
939 if (a_local or "") == (b_local or "") then return _sort_hosts(a_remote or "", b_remote or ""); end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
940 return _sort_hosts(a_local or "", b_local or ""); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
941 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
|
942 |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
943 function def_env.s2s:show(match_jid, colspec) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
944 local print = self.session.print; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
945 local columns = get_colspec(colspec, { "id"; "host"; "dir"; "remote"; "ipv"; "secure"; "s2s_sasl"; "dialback" }); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
946 local row = format_table(columns, 132); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
947 |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
948 local function match(session) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
949 local host, remote = get_s2s_hosts(session); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
950 return not match_jid or (host or ""):match(match_jid) or (remote or ""):match(match_jid); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
951 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
952 |
11886
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
953 local group_by_host = true; |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
954 local currenthost = nil; |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
955 for _, col in ipairs(columns) do |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
956 if col.key == "host" then |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
957 group_by_host = false; |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
958 break |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
959 end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
960 end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
961 |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
962 if not group_by_host then print(row()); end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
963 |
11917
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
964 local s2s_sessions = array(iterators.values(module:shared"/*/s2s/sessions")); |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
965 local total_count = #s2s_sessions; |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
966 s2s_sessions:filter(match):sort(_sort_s2s); |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
967 local shown_count = #s2s_sessions; |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
968 |
11886
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
969 for _, session in ipairs(s2s_sessions) do |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
970 if group_by_host and currenthost ~= get_s2s_hosts(session) then |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
971 currenthost = get_s2s_hosts(session); |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
972 print("#",prosody.hosts[currenthost] or "Unknown host"); |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
973 print(row()); |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
974 end |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
975 |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
976 print(row(session)); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
977 end |
11917
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
978 if total_count ~= shown_count then |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
979 return true, ("%d out of %d s2s connections shown"):format(shown_count, total_count); |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
980 end |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
981 return true, ("%d s2s connections shown"):format(total_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
|
982 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
983 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
984 function def_env.s2s:show_tls(match_jid) |
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
985 return self:show(match_jid, { "id"; "host"; "dir"; "remote"; "secure"; "encryption"; "cert" }); |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
986 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
987 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
988 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
|
989 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
|
990 print( |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
991 (" %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
|
992 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
|
993 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
|
994 ) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
995 ); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
996 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
997 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
998 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
999 -- 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
|
1000 -- 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
|
1001 -- 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
|
1002 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
|
1003 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
|
1004 print( |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1005 (" %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
|
1006 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
|
1007 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
|
1008 ) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1009 ); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1010 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1011 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1012 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1013 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
|
1014 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
|
1015 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
|
1016 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
|
1017 /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
|
1018 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
|
1019 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
|
1020 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
|
1021 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
|
1022 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
|
1023 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
|
1024 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
|
1025 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1026 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1027 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
|
1028 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
|
1029 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
|
1030 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
|
1031 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
|
1032 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
|
1033 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
|
1034 { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1035 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
|
1036 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
|
1037 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
|
1038 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1039 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
|
1040 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
|
1041 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
|
1042 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1043 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1044 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
|
1045 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
|
1046 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
|
1047 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
|
1048 }); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1049 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1050 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1051 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1052 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1053 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
|
1054 -- 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
|
1055 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
|
1056 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1057 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
|
1058 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
|
1059 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1060 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1061 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
|
1062 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
|
1063 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1064 local 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
|
1065 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
|
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 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
|
1069 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
|
1070 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
|
1071 print("---") |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1072 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
|
1073 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1074 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
|
1075 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
|
1076 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
|
1077 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
|
1078 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
|
1079 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1080 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
|
1081 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1082 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 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1084 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
|
1085 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
|
1086 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
|
1087 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
|
1088 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1089 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
|
1090 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
|
1091 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1092 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1093 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
|
1094 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
|
1095 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1096 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
|
1097 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
|
1098 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
|
1099 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1100 print("---"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1101 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
|
1102 ..(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
|
1103 .." 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
|
1104 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1105 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1106 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
|
1107 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
|
1108 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
|
1109 |
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 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
|
1111 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
|
1112 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
|
1113 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
|
1114 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
|
1115 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
|
1116 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
|
1117 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1118 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1119 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
|
1120 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
|
1121 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
|
1122 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
|
1123 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
|
1124 (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
|
1125 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
|
1126 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1127 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1128 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
|
1129 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1130 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1131 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
|
1132 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
|
1133 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
|
1134 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
|
1135 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
|
1136 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
|
1137 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
|
1138 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1139 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1140 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
|
1141 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
|
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1144 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
|
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 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
|
1147 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
|
1148 end |
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.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
|
1150 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
|
1151 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1152 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1153 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
|
1154 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
|
1155 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
|
1156 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
|
1157 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
|
1158 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
|
1159 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
|
1160 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
|
1161 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
|
1162 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1163 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
|
1164 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
|
1165 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
|
1166 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1167 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
|
1168 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1169 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1170 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
|
1171 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1172 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1173 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
|
1174 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1175 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
|
1176 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
|
1177 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
|
1178 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
|
1179 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
|
1180 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
|
1181 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
|
1182 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
|
1183 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
|
1184 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1187 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
|
1188 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
|
1189 end |
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 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
|
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1193 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
|
1194 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
|
1195 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
|
1196 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
|
1197 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
|
1198 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
|
1199 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
|
1200 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
|
1201 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
|
1202 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
|
1203 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
|
1204 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
|
1205 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1206 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
|
1207 end |
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 end |
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1212 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
|
1213 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1214 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1215 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
|
1216 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1217 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
|
1218 __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
|
1219 __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
|
1220 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
|
1221 end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1222 }; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1223 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1224 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
|
1225 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
|
1226 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
|
1227 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
|
1228 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
|
1229 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
|
1230 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1231 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
|
1232 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1233 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1234 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
|
1235 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
|
1236 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
|
1237 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
|
1238 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1239 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
|
1240 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
|
1241 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
|
1242 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
|
1243 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1244 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1245 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
|
1246 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
|
1247 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
|
1248 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
|
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 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
|
1251 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
|
1252 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
|
1253 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1254 return 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
|
1255 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1256 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1257 function def_env.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
|
1258 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
|
1259 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
|
1260 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
|
1261 end |
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 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
|
1263 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
|
1264 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
|
1265 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
|
1266 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
|
1267 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1268 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
|
1269 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1270 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1271 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
|
1272 |
12013
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1273 local function coerce_roles(roles) |
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1274 if roles == "admin" then roles = "prosody:admin"; end |
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1275 if type(roles) == "string" then roles = { [roles] = true }; end |
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1276 if roles[1] then for i, role in ipairs(roles) do roles[role], roles[i] = true, nil; end end |
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1277 return roles; |
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1278 end |
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1279 |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1280 def_env.user = {}; |
12012
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11991
diff
changeset
|
1281 function def_env.user:create(jid, password, roles) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1282 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
|
1283 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
|
1284 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
|
1285 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
|
1286 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
|
1287 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1288 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
|
1289 if ok then |
12012
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11991
diff
changeset
|
1290 if ok and roles then |
12013
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1291 roles = coerce_roles(roles); |
12012
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11991
diff
changeset
|
1292 local roles_ok, rerr = um.set_roles(jid, host, roles); |
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11991
diff
changeset
|
1293 if not roles_ok then return nil, "User created, but could not set roles: " .. tostring(rerr); end |
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11991
diff
changeset
|
1294 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
|
1295 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
|
1296 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1297 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
|
1298 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1299 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1300 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1301 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
|
1302 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
|
1303 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
|
1304 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
|
1305 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
|
1306 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
|
1307 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1308 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
|
1309 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
|
1310 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
|
1311 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1312 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
|
1313 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1314 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1315 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1316 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
|
1317 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
|
1318 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
|
1319 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
|
1320 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
|
1321 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
|
1322 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1323 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
|
1324 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
|
1325 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
|
1326 else |
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 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1330 |
12014
efbf288b529e
mod_admin_shell: Support setting roles on hosts other than the users'
Kim Alvefur <zash@zash.se>
parents:
12013
diff
changeset
|
1331 -- user:roles("someone@example.com", "example.com", {"prosody:admin"}) |
12013
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1332 -- user:roles("someone@example.com", {"prosody:admin"}) |
12014
efbf288b529e
mod_admin_shell: Support setting roles on hosts other than the users'
Kim Alvefur <zash@zash.se>
parents:
12013
diff
changeset
|
1333 function def_env.user:roles(jid, host, new_roles) |
efbf288b529e
mod_admin_shell: Support setting roles on hosts other than the users'
Kim Alvefur <zash@zash.se>
parents:
12013
diff
changeset
|
1334 local username, userhost = jid_split(jid); |
efbf288b529e
mod_admin_shell: Support setting roles on hosts other than the users'
Kim Alvefur <zash@zash.se>
parents:
12013
diff
changeset
|
1335 if new_roles == nil then host, new_roles = userhost, host; end |
12013
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1336 if not prosody.hosts[host] then |
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1337 return nil, "No such host: "..host; |
12018
c65789f5004e
mod_admin_shell: Only check that local users exist locally
Kim Alvefur <zash@zash.se>
parents:
12014
diff
changeset
|
1338 elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then |
12013
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1339 return nil, "No such user"; |
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1340 end |
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1341 return um.set_roles(jid, host, coerce_roles(new_roles)); |
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1342 end |
12012
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11991
diff
changeset
|
1343 |
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11991
diff
changeset
|
1344 -- TODO switch to table view, include roles |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1345 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
|
1346 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
|
1347 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
|
1348 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
|
1349 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
|
1350 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1351 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
|
1352 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
|
1353 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
|
1354 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
|
1355 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
|
1356 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
|
1357 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1358 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
|
1359 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1360 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
|
1361 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1362 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1363 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
|
1364 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1365 local new_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
|
1366 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
|
1367 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
|
1368 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
|
1369 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
|
1370 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
|
1371 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
|
1372 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
|
1373 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1374 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
|
1375 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
|
1376 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
|
1377 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
|
1378 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1379 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
|
1380 :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
|
1381 local time_start = time.now(); |
11953
848a522fd731
mod_admin_shell: Remove now redundant promise awaiting in xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
11950
diff
changeset
|
1382 return module:context(localhost):send_iq(iq, nil, timeout):next(function (pong) |
848a522fd731
mod_admin_shell: Remove now redundant promise awaiting in xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
11950
diff
changeset
|
1383 return ("pong from %s in %gs"):format(pong.stanza.attr.from, time.now() - time_start); |
848a522fd731
mod_admin_shell: Remove now redundant promise awaiting in xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
11950
diff
changeset
|
1384 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
|
1385 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1386 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1387 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
|
1388 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
|
1389 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1390 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
|
1391 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
|
1392 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
|
1393 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
|
1394 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
|
1395 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1396 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
|
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1399 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
|
1400 local resolver = get_resolver(self.session); |
11954
b963ac00c967
mod_admin_shell: Remove now redundant promise awaiting in dns:lookup()
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
1401 return 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
|
1402 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1403 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1404 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
|
1405 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
|
1406 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
|
1407 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
|
1408 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1409 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1410 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
|
1411 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
|
1412 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
|
1413 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
|
1414 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1415 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1416 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
|
1417 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
|
1418 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
|
1419 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
|
1420 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1421 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1422 function 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
|
1423 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
|
1424 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
|
1425 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1426 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1427 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
|
1428 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1429 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
|
1430 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
|
1431 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
|
1432 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
|
1433 { 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
|
1434 { 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
|
1435 }, 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
|
1436 |
11361
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
1437 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
|
1438 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
|
1439 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
|
1440 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
|
1441 if host == "*" then |
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
1442 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
|
1443 else |
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
1444 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
|
1445 end |
11364
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11363
diff
changeset
|
1446 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
|
1447 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
|
1448 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
|
1449 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
|
1450 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
|
1451 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
|
1452 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1453 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1454 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1455 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1456 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1457 local 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
|
1458 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
|
1459 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
|
1460 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1461 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
|
1462 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1463 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
|
1464 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1465 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1466 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
|
1467 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1468 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
|
1469 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
|
1470 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
|
1471 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1472 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1473 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
|
1474 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
|
1475 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
|
1476 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
|
1477 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
|
1478 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
|
1479 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
|
1480 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1481 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
|
1482 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1483 else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1484 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
|
1485 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1486 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
|
1487 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1488 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1489 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
|
1490 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
|
1491 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
|
1492 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
|
1493 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
|
1494 return t; |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1495 end |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
1496 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
|
1497 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
|
1498 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
|
1499 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
|
1500 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
|
1501 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
|
1502 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
|
1503 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
|
1504 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
|
1505 end |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1506 if h then |
11478
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
1507 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
|
1508 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
|
1509 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
|
1510 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
|
1511 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
|
1512 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
|
1513 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
|
1514 else |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1515 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
|
1516 end |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
1517 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
|
1518 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
|
1519 end |
11478
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
1520 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
|
1521 end |
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
1522 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
|
1523 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
|
1524 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
|
1525 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1526 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1527 if 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
|
1528 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
|
1529 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
|
1530 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
|
1531 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
|
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 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
|
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 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
|
1537 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
|
1538 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
|
1539 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
|
1540 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1541 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1542 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
|
1543 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1544 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1545 -- 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
|
1546 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
|
1547 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1548 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
|
1549 |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1550 local short_units = { |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1551 seconds = "s", |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1552 bytes = "B", |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1553 }; |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1554 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1555 local stats_methods = {}; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1556 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1557 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
|
1558 local creation_timestamp, sum, count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1559 local buckets = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1560 local prev_bucket_count = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1561 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
|
1562 if suffix == "_created" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1563 creation_timestamp = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1564 elseif suffix == "_sum" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1565 sum = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1566 elseif suffix == "_count" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1567 count = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1568 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1569 local bucket_threshold = extra_labels["le"] |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1570 local bucket_count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1571 if cumulative then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1572 bucket_count = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1573 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1574 bucket_count = value - prev_bucket_count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1575 prev_bucket_count = value |
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
1576 end |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1577 if bucket_threshold == "+Inf" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1578 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
|
1579 elseif bucket_threshold ~= nil then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1580 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
|
1581 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
|
1582 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1583 end |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1584 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1585 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
|
1586 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
|
1587 return false |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1588 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
|
1589 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1590 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
|
1591 if graph_width < 8 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1592 wscale = 8 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1593 elseif graph_width < 16 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1594 wscale = 4 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1595 elseif graph_width < 32 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1596 wscale = 2 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1597 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1598 local eighth_chars = " ▁▂▃▄▅▆▇█"; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1599 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1600 local max_bin_samples = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1601 for _, bucket in ipairs(buckets) do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1602 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
|
1603 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
|
1604 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1605 end |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1606 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1607 print(""); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1608 print(prefix) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1609 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
|
1610 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
|
1611 local row_chars = {}; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1612 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
|
1613 for i = 1, #buckets do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1614 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
|
1615 if char_eighths < min_eighths then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1616 min_eighths = char_eighths; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1617 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1618 if char_eighths > max_eighths then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1619 max_eighths = char_eighths; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1620 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1621 if char_eighths == 0 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1622 row_chars[i] = ("-"):rep(wscale); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1623 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1624 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
|
1625 row_chars[i] = char:rep(wscale); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1626 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1627 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1628 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
|
1629 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1630 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1631 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
|
1632 local row = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1633 for i = 1, #buckets do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1634 local threshold = buckets[i].threshold |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1635 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
|
1636 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1637 t_insert(row, " " .. metric_family.unit) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1638 print(t_concat(row, "/")) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1639 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1640 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
|
1641 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1642 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1643 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
|
1644 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
|
1645 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1646 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1647 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
|
1648 -- cf = cumulative frequency |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1649 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
|
1650 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1651 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1652 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
|
1653 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
|
1654 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
|
1655 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
|
1656 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
|
1657 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1658 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1659 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
|
1660 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
|
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 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1663 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
|
1664 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1665 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1666 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
|
1667 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
|
1668 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
|
1669 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
|
1670 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
|
1671 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1672 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1673 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
|
1674 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
|
1675 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1676 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1677 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
|
1678 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1679 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1680 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
|
1681 local created_timestamp, current_value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1682 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
|
1683 if suffix == "_created" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1684 created_timestamp = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1685 elseif suffix == "_total" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1686 current_value = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1687 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1688 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1689 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
|
1690 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
|
1691 local unit = base_unit .. "/s" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1692 local factor = 1 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1693 if base_unit == "s" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1694 -- be smart! |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1695 unit = "%" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1696 factor = 100 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1697 elseif base_unit == "" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1698 unit = "events/s" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1699 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1700 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
|
1701 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1702 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1703 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1704 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
|
1705 local current_value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1706 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
|
1707 current_value = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1708 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1709 if current_value then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1710 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
|
1711 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
|
1712 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1713 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1714 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1715 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
|
1716 local sum, count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1717 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
|
1718 if suffix == "_sum" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1719 sum = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1720 elseif suffix == "_count" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1721 count = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1722 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1723 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1724 if sum and count then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1725 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
|
1726 if count == 0 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1727 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
|
1728 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1729 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
|
1730 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1731 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1732 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1733 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1734 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
|
1735 local labelkeys = metric_family.label_keys |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1736 if #labelkeys > 0 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1737 print(family_name) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1738 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
|
1739 local labels = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1740 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
|
1741 local v = labelset[i] |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1742 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
|
1743 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1744 local prefix = " "..t_concat(labels, " ") |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1745 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
|
1746 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1747 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1748 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
|
1749 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
|
1750 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1751 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1752 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1753 |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1754 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
|
1755 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
|
1756 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
|
1757 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
|
1758 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
|
1759 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1760 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
|
1761 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
|
1762 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1763 print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1764 else |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1765 local metric_family = stat_info[2] |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1766 if metric_family.type_ == "counter" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1767 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
|
1768 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
|
1769 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
|
1770 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
|
1771 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
|
1772 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
|
1773 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1774 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1775 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
|
1776 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1777 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1778 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
|
1779 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
|
1780 -- 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
|
1781 -- 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
|
1782 -- 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
|
1783 -- the next sample and so on. |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1784 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
|
1785 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1786 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1787 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
|
1788 local statsman = require "core.statsmanager" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1789 local collect = statsman.collect |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1790 if collect then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1791 -- force collection if in manual mode |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1792 collect() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1793 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1794 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
|
1795 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
|
1796 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
|
1797 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
|
1798 table.insert(displayed_stats, { |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1799 family_name, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1800 metric_family, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1801 output = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
1802 }) |
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1803 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1804 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1805 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
|
1806 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1807 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1808 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1809 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1810 ------------- |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1811 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1812 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
|
1813 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
|
1814 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
|
1815 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
|
1816 ____ \ / _ |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1817 | _ \ _ __ ___ ___ _-_ __| |_ _ |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1818 | |_) | '__/ _ \/ __|/ _ \ / _` | | | | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1819 | __/| | | (_) \__ \ |_| | (_| | |_| | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1820 |_| |_| \___/|___/\___/ \__,_|\__, | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1821 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
|
1822 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1823 ]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1824 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1825 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
|
1826 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
|
1827 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
|
1828 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
|
1829 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1830 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
|
1831 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
|
1832 end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1833 end |