author | Matthew Wild <mwild1@gmail.com> |
Thu, 18 Aug 2022 16:46:07 +0100 | |
changeset 12672 | 5d85de8b0723 |
parent 12664 | e8f57970ced5 |
child 12674 | 4a00c8811ea8 |
permissions | -rw-r--r-- |
10860
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 |
|
12593
39ae08180c81
compat: Remove handling of Lua 5.1 location of 'unpack' function
Kim Alvefur <zash@zash.se>
parents:
12555
diff
changeset
|
25 |
local unpack = table.unpack; |
10860
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"; |
11953
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11950
diff
changeset
|
38 |
local promise = require "util.promise"; |
12403
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
39 |
local logger = require "util.logger"; |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
|
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
41 |
local t_insert = table.insert; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
42 |
local t_concat = table.concat; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
43 |
|
10891
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10882
diff
changeset
|
44 |
local format_number = require "util.human.units".format; |
11368
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11367
diff
changeset
|
45 |
local format_table = require "util.human.io".table; |
10891
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10882
diff
changeset
|
46 |
|
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
47 |
local function capitalize(s) |
11896
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11895
diff
changeset
|
48 |
if not s then return end |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
49 |
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:
11854
diff
changeset
|
50 |
end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
51 |
|
11935
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
52 |
local function pre(prefix, str, alt) |
12509
604bb5b8362d
mod_admin_shell: Tighten up type checks to fix #1754 (thanks clouded)
Kim Alvefur <zash@zash.se>
parents:
12308
diff
changeset
|
53 |
if type(str) ~= "string" or str == "" then return alt or ""; end |
11935
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
54 |
return prefix .. str; |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
55 |
end |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
56 |
|
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
57 |
local function suf(str, suffix, alt) |
12509
604bb5b8362d
mod_admin_shell: Tighten up type checks to fix #1754 (thanks clouded)
Kim Alvefur <zash@zash.se>
parents:
12308
diff
changeset
|
58 |
if type(str) ~= "string" or str == "" then return alt or ""; end |
11935
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
59 |
return str .. suffix; |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
60 |
end |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
61 |
|
10860
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 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
|
63 |
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
|
64 |
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
|
65 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 |
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
|
74 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 |
console = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 |
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
|
79 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 |
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
|
81 |
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
|
82 |
|
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("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
|
84 |
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
|
85 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 |
|
12401
ddf02f2a3354
mod_admin_shell: Add session.write() method to write data to client with no \n
Matthew Wild <mwild1@gmail.com>
parents:
12308
diff
changeset
|
87 |
local function send_repl_output(session, line, attr) |
ddf02f2a3354
mod_admin_shell: Add session.write() method to write data to client with no \n
Matthew Wild <mwild1@gmail.com>
parents:
12308
diff
changeset
|
88 |
return session.send(st.stanza("repl-output", attr):text(tostring(line))); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 |
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
|
92 |
local session = { |
11954
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
93 |
send = function (t) |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
94 |
return send_repl_output(admin_session, t); |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
95 |
end; |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
96 |
print = function (...) |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
97 |
local t = {}; |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
98 |
for i=1,select("#", ...) do |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
99 |
t[i] = tostring(select(i, ...)); |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
100 |
end |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
101 |
return send_repl_output(admin_session, table.concat(t, "\t")); |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
102 |
end; |
12401
ddf02f2a3354
mod_admin_shell: Add session.write() method to write data to client with no \n
Matthew Wild <mwild1@gmail.com>
parents:
12308
diff
changeset
|
103 |
write = function (t) |
ddf02f2a3354
mod_admin_shell: Add session.write() method to write data to client with no \n
Matthew Wild <mwild1@gmail.com>
parents:
12308
diff
changeset
|
104 |
return send_repl_output(admin_session, t, { eol = "0" }); |
ddf02f2a3354
mod_admin_shell: Add session.write() method to write data to client with no \n
Matthew Wild <mwild1@gmail.com>
parents:
12308
diff
changeset
|
105 |
end; |
11954
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
106 |
serialize = tostring; |
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
107 |
disconnect = function () admin_session:close(); end; |
12402
478fff93ac37
mod_admin_shell: Add session.is_connected() method
Matthew Wild <mwild1@gmail.com>
parents:
12401
diff
changeset
|
108 |
is_connected = function () |
478fff93ac37
mod_admin_shell: Add session.is_connected() method
Matthew Wild <mwild1@gmail.com>
parents:
12401
diff
changeset
|
109 |
return not not admin_session.conn; |
478fff93ac37
mod_admin_shell: Add session.is_connected() method
Matthew Wild <mwild1@gmail.com>
parents:
12401
diff
changeset
|
110 |
end |
11954
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
111 |
}; |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 |
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
|
113 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 |
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
|
115 |
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
|
116 |
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
|
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 |
-- 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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 |
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
|
126 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 |
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
|
128 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
end |
12533
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12510
diff
changeset
|
136 |
|
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12510
diff
changeset
|
137 |
local default_width = 132; -- The common default of 80 is a bit too narrow for e.g. s2s:show(), 132 was another common width for hardware terminals |
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12510
diff
changeset
|
138 |
local margin = 2; -- To account for '| ' when lines are printed |
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12510
diff
changeset
|
139 |
session.width = (tonumber(event.stanza.attr.width) or default_width)-margin; |
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12510
diff
changeset
|
140 |
|
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 |
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
|
142 |
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
|
143 |
|
10863
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10860
diff
changeset
|
144 |
local result = st.stanza("repl-result"); |
10860
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 |
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
|
147 |
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
|
148 |
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
|
149 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 |
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
|
151 |
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
|
152 |
commands[command](session, line); |
10863
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10860
diff
changeset
|
153 |
event.origin.send(result); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 |
return; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 |
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
|
159 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 |
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
|
161 |
commands[line:lower()](session, line); |
10863
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10860
diff
changeset
|
162 |
event.origin.send(result); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 |
return; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 |
|
11740
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11611
diff
changeset
|
166 |
if useglobalenv and not session.globalenv then |
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11611
diff
changeset
|
167 |
session.globalenv = redirect_output(_G, session); |
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11611
diff
changeset
|
168 |
end |
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11611
diff
changeset
|
169 |
|
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 |
local chunkname = "=console"; |
11740
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11611
diff
changeset
|
171 |
local env = (useglobalenv and session.globalenv) or session.env or nil |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 |
-- 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
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
err = err:gsub("'<eof>'", "the end of the line"); |
10863
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10860
diff
changeset
|
180 |
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:
10860
diff
changeset
|
181 |
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:
10860
diff
changeset
|
182 |
event.origin.send(result); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 |
return; |
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 |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 |
local 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
|
188 |
|
11953
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11950
diff
changeset
|
189 |
if promise.is_promise(taskok) then |
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11950
diff
changeset
|
190 |
taskok, message = async.wait_for(taskok); |
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11950
diff
changeset
|
191 |
end |
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11950
diff
changeset
|
192 |
|
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 |
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
|
194 |
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
|
195 |
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
|
196 |
end |
10863
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10860
diff
changeset
|
197 |
result:text("Result: "..tostring(taskok)); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 |
elseif (not taskok) and message then |
10863
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10860
diff
changeset
|
199 |
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:
10860
diff
changeset
|
200 |
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:
10860
diff
changeset
|
201 |
else |
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10860
diff
changeset
|
202 |
result:text("OK: "..tostring(message)); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 |
|
10863
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10860
diff
changeset
|
205 |
event.origin.send(result); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 |
|
10863
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10860
diff
changeset
|
208 |
module:hook("admin/repl-input", function (event) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 |
end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 |
-- 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
|
216 |
-- 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
|
217 |
|
12228
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
218 |
local available_columns; --forward declaration so it is reachable from the help |
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
219 |
|
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 |
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
|
221 |
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
|
222 |
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
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
print [[]] |
12533
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12510
diff
changeset
|
227 |
local row = format_table({ { title = "Section", width = 7 }, { title = "Description", width = "100%" } }, session.width) |
12308
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
228 |
print(row()) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
229 |
print(row { "c2s"; "Commands to manage local client-to-server sessions" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
230 |
print(row { "s2s"; "Commands to manage sessions between this server and others" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
231 |
print(row { "http"; "Commands to inspect HTTP services" }) -- XXX plural but there is only one so far |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
232 |
print(row { "module"; "Commands to load/reload/unload modules/plugins" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
233 |
print(row { "host"; "Commands to activate, deactivate and list virtual hosts" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
234 |
print(row { "user"; "Commands to create and delete users, and change their passwords" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
235 |
print(row { "roles"; "Show information about user roles" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
236 |
print(row { "muc"; "Commands to create, list and manage chat rooms" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
237 |
print(row { "stats"; "Commands to show internal statistics" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
238 |
print(row { "server"; "Uptime, version, shutting down, etc." }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
239 |
print(row { "port"; "Commands to manage ports the server is listening on" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
240 |
print(row { "dns"; "Commands to manage and inspect the internal DNS resolver" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
241 |
print(row { "xmpp"; "Commands for sending XMPP stanzas" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
242 |
print(row { "debug"; "Commands for debugging the server" }) |
12540
a8cb1d7a98db
mod_admin_shell: Document the 'watch' section in the built-in help
Kim Alvefur <zash@zash.se>
parents:
12533
diff
changeset
|
243 |
print(row { "watch"; "Commands for watching live logs from the server" }) |
12308
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
244 |
print(row { "config"; "Reloading the configuration, etc." }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
245 |
print(row { "columns"; "Information about customizing session listings" }) |
8210c2a52e9c
mod_admin_shell: Use a table to show help sections
Kim Alvefur <zash@zash.se>
parents:
12297
diff
changeset
|
246 |
print(row { "console"; "Help regarding the console itself" }) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 |
elseif section == "c2s" then |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
248 |
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:
11854
diff
changeset
|
249 |
print [[c2s:show_tls(jid) - Show TLS cipher info for encrypted sessions]] |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
250 |
print [[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
|
251 |
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
|
252 |
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
|
253 |
elseif section == "s2s" then |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
254 |
print [[s2s:show(domain, columns) - Show all s2s connections for the given domain (or all if no domain given)]] |
10860
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 [[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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
elseif section == "module" then |
11605
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
261 |
print [[module:info(module, host) - Show information about a loaded module]] |
10860
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 [[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
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
elseif section == "user" then |
12016
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11995
diff
changeset
|
271 |
print [[user:create(jid, password, roles) - Create the specified user account]] |
10860
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 [[user:password(jid, password) - Set the password for the specified user account]] |
12641
2200f0c6b3f1
mod_admin_shell: Switch names for user role management commands
Kim Alvefur <zash@zash.se>
parents:
12509
diff
changeset
|
273 |
print [[user:roles(jid, host) - Show current roles for an user]] |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
274 |
print [[user:setrole(jid, host, role) - Set primary role of a user (see 'help roles')]] |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
275 |
print [[user:addrole(jid, host, role) - Add a secondary role to a user]] |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
276 |
print [[user:delrole(jid, host, role) - Remove a secondary role from a user]] |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
277 |
print [[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
|
278 |
print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] |
12212
3edf1a38fb15
mod_admin_shell: Add help section about roles
Kim Alvefur <zash@zash.se>
parents:
12130
diff
changeset
|
279 |
elseif section == "roles" then |
3edf1a38fb15
mod_admin_shell: Add help section about roles
Kim Alvefur <zash@zash.se>
parents:
12130
diff
changeset
|
280 |
print [[Roles may grant access or restrict users from certain operations]] |
3edf1a38fb15
mod_admin_shell: Add help section about roles
Kim Alvefur <zash@zash.se>
parents:
12130
diff
changeset
|
281 |
print [[Built-in roles are:]] |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
282 |
print [[ prosody:user - Normal user (default)]] |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
283 |
print [[ prosody:admin - Host administrator]] |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
284 |
print [[ prosody:operator - Server administrator]] |
12212
3edf1a38fb15
mod_admin_shell: Add help section about roles
Kim Alvefur <zash@zash.se>
parents:
12130
diff
changeset
|
285 |
print [[]] |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
286 |
print [[Roles can be assigned using the user management commands (see 'help user').]] |
11369
5eb817cdd5cd
mod_admin_shell: Add help section with (top level) MUC commands
Kim Alvefur <zash@zash.se>
parents:
11368
diff
changeset
|
287 |
elseif section == "muc" then |
5eb817cdd5cd
mod_admin_shell: Add help section with (top level) MUC commands
Kim Alvefur <zash@zash.se>
parents:
11368
diff
changeset
|
288 |
-- TODO `muc:room():foo()` commands |
5eb817cdd5cd
mod_admin_shell: Add help section with (top level) MUC commands
Kim Alvefur <zash@zash.se>
parents:
11368
diff
changeset
|
289 |
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:
11368
diff
changeset
|
290 |
print [[muc:list(host) - List rooms on the specified MUC component]] |
12295
ec16fb706247
mod_admin_shell: Fix description of muc:room() (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
12285
diff
changeset
|
291 |
print [[muc:room(roomjid) - Reference the specified MUC room to access MUC API methods]] |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
292 |
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
|
293 |
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
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
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
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
elseif section == "stats" then -- luacheck: ignore 542 |
12229
e9f34a04067e
mod_admin_shell: Add help section about stats
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
312 |
print [[stats:show(pattern) - Show internal statistics, optionally filtering by name with a pattern]] |
e9f34a04067e
mod_admin_shell: Add help section about stats
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
313 |
print [[stats:show():cfgraph() - Show a cumulative frequency graph]] |
e9f34a04067e
mod_admin_shell: Add help section about stats
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
314 |
print [[stats:show():histogram() - Show a histogram of selected metric]] |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
315 |
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
|
316 |
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
|
317 |
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
|
318 |
print [[debug:timers() - Show information about scheduled timers]] |
12540
a8cb1d7a98db
mod_admin_shell: Document the 'watch' section in the built-in help
Kim Alvefur <zash@zash.se>
parents:
12533
diff
changeset
|
319 |
elseif section == "watch" then |
a8cb1d7a98db
mod_admin_shell: Document the 'watch' section in the built-in help
Kim Alvefur <zash@zash.se>
parents:
12533
diff
changeset
|
320 |
print [[watch:log() - Follow debug logs]] |
a8cb1d7a98db
mod_admin_shell: Document the 'watch' section in the built-in help
Kim Alvefur <zash@zash.se>
parents:
12533
diff
changeset
|
321 |
print [[watch:stanzas(target, filter) - Watch live stanzas matching the specified target and filter]] |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
322 |
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
|
323 |
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
|
324 |
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
|
325 |
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
|
326 |
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
|
327 |
print [[]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
328 |
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
|
329 |
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
|
330 |
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
|
331 |
print [[]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
332 |
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
|
333 |
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
|
334 |
print [[the running server. Great fun, but be careful not to break anything :)]] |
12228
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
335 |
elseif section == "columns" then |
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
336 |
print [[The columns shown by c2s:show() and s2s:show() can be customizied via the]] |
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
337 |
print [['columns' argument as described here.]] |
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
338 |
print [[]] |
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
339 |
print [[Columns can be specified either as "id jid ipv" or as {"id", "jid", "ipv"}.]] |
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
340 |
print [[Available columns are:]] |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
341 |
local meta_columns = { |
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
342 |
{ title = "ID"; width = 5 }; |
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
343 |
{ title = "Column Title"; width = 12 }; |
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
344 |
{ title = "Description"; width = 12 }; |
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
345 |
}; |
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
346 |
-- auto-adjust widths |
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
347 |
for column, spec in pairs(available_columns) do |
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
348 |
meta_columns[1].width = math.max(meta_columns[1].width or 0, #column); |
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
349 |
meta_columns[2].width = math.max(meta_columns[2].width or 0, #(spec.title or "")); |
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
350 |
meta_columns[3].width = math.max(meta_columns[3].width or 0, #(spec.description or "")); |
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
351 |
end |
12533
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12510
diff
changeset
|
352 |
local row = format_table(meta_columns, session.width) |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
353 |
print(row()); |
12228
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
354 |
for column, spec in iterators.sorted_pairs(available_columns) do |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
355 |
print(row({ column, spec.title, spec.description })); |
12228
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
356 |
end |
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
357 |
print [[]] |
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
358 |
print [[Most fields on the internal session structures can also be used as columns]] |
12262
99560987ea19
mod_admin_shell: Fix typo in comment [codespell]
Kim Alvefur <zash@zash.se>
parents:
12233
diff
changeset
|
359 |
-- Also, you can pass a table column specification directly, with mapper callback and all |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
360 |
end |
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 |
-- 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
|
364 |
-- 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
|
365 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
366 |
--luacheck: ignore 212/self |
11895
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11893
diff
changeset
|
367 |
local serialize_defaults = module:get_option("console_prettyprint_settings", |
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11893
diff
changeset
|
368 |
{ fatal = false; unquoted = true; maxdepth = 2; table_iterator = "pairs" }) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
369 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
370 |
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
|
371 |
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
|
372 |
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
|
373 |
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
|
374 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
375 |
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
|
376 |
-- 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
|
377 |
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
|
378 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
379 |
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
|
380 |
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
|
381 |
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
|
382 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
383 |
end |
11895
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11893
diff
changeset
|
384 |
if opts.table_iterator == "pairs" then |
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11893
diff
changeset
|
385 |
opts.table_iterator = pairs; |
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11893
diff
changeset
|
386 |
elseif type(opts.table_iterator) ~= "function" then |
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11893
diff
changeset
|
387 |
opts.table_iterator = nil; -- rawpairs is the default |
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11893
diff
changeset
|
388 |
end |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
389 |
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
|
390 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
391 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
392 |
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
|
393 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
394 |
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
|
395 |
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
|
396 |
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
|
397 |
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
|
398 |
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
|
399 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
400 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
401 |
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
|
402 |
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
|
403 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
404 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
405 |
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
|
406 |
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
|
407 |
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
|
408 |
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
|
409 |
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
|
410 |
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
|
411 |
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
|
412 |
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
|
413 |
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
|
414 |
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
|
415 |
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
|
416 |
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
|
417 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
418 |
|
11835
94cd363116a3
mod_admin_shell: Allow passing an exit code to server:shutdown()
Kim Alvefur <zash@zash.se>
parents:
11740
diff
changeset
|
419 |
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:
11740
diff
changeset
|
420 |
prosody.shutdown(reason, code); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
421 |
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
|
422 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
423 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
424 |
local function human(kb) |
10891
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10882
diff
changeset
|
425 |
return format_number(kb*1024, "B", "b"); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
426 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
427 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
428 |
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
|
429 |
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
|
430 |
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
|
431 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
432 |
local 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
|
433 |
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
|
434 |
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
|
435 |
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
|
436 |
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
|
437 |
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
|
438 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
439 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
440 |
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
|
441 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
442 |
local 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
|
443 |
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
|
444 |
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
|
445 |
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
|
446 |
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
|
447 |
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
|
448 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
449 |
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
|
450 |
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
|
451 |
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
|
452 |
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
|
453 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
454 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
455 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
456 |
-- 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
|
457 |
-- 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
|
458 |
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
|
459 |
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
|
460 |
/ 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
|
461 |
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
|
462 |
-- 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
|
463 |
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
|
464 |
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
|
465 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
466 |
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
|
467 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
468 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
469 |
if 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
|
470 |
-- 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
|
471 |
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
|
472 |
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
|
473 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
474 |
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
|
475 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
476 |
end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
477 |
-- 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
|
478 |
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
|
479 |
end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
480 |
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
|
481 |
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
|
482 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
483 |
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
|
484 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
485 |
|
11605
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
486 |
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:
11527
diff
changeset
|
487 |
if not name then |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
488 |
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:
11527
diff
changeset
|
489 |
end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
490 |
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:
11527
diff
changeset
|
491 |
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:
11527
diff
changeset
|
492 |
if hosts:empty() then |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
493 |
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:
11527
diff
changeset
|
494 |
end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
495 |
|
11936
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11935
diff
changeset
|
496 |
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:
11935
diff
changeset
|
497 |
|
12544
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12542
diff
changeset
|
498 |
local function task_timefmt(t) |
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12542
diff
changeset
|
499 |
if not t then |
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12542
diff
changeset
|
500 |
return "no last run time" |
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12542
diff
changeset
|
501 |
elseif os.difftime(os.time(), t) < 86400 then |
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12542
diff
changeset
|
502 |
return os.date("last run today at %H:%M", t); |
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12542
diff
changeset
|
503 |
else |
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12542
diff
changeset
|
504 |
return os.date("last run %A at %H:%M", t); |
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12542
diff
changeset
|
505 |
end |
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12542
diff
changeset
|
506 |
end |
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12542
diff
changeset
|
507 |
|
11610
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11609
diff
changeset
|
508 |
local friendly_descriptions = { |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11609
diff
changeset
|
509 |
["adhoc-provider"] = "Ad-hoc commands", |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11609
diff
changeset
|
510 |
["auth-provider"] = "Authentication provider", |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11609
diff
changeset
|
511 |
["http-provider"] = "HTTP services", |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11609
diff
changeset
|
512 |
["net-provider"] = "Network service", |
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11609
diff
changeset
|
513 |
["storage-provider"] = "Storage driver", |
11935
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
514 |
["measure"] = "Legacy metrics", |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
515 |
["metric"] = "Metrics", |
11995
bef2a59b00d1
mod_admin_shell: List periodic tasks in module:info
Kim Alvefur <zash@zash.se>
parents:
11958
diff
changeset
|
516 |
["task"] = "Periodic task", |
11610
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11609
diff
changeset
|
517 |
}; |
11611
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11610
diff
changeset
|
518 |
local item_formatters = { |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11610
diff
changeset
|
519 |
["feature"] = tostring, |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11610
diff
changeset
|
520 |
["identity"] = function(ident) return ident.type .. "/" .. ident.category; end, |
11936
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11935
diff
changeset
|
521 |
["adhoc-provider"] = item_name, |
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11935
diff
changeset
|
522 |
["auth-provider"] = item_name, |
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11935
diff
changeset
|
523 |
["storage-provider"] = item_name, |
11947
cf47834d3698
mod_admin_shell: Fix showing default HTTP path in module:info
Kim Alvefur <zash@zash.se>
parents:
11936
diff
changeset
|
524 |
["http-provider"] = function(item, mod) return mod:http_url(item.name, item.default_path); end, |
12542
0f56587bb37f
mod_admin_shell: Drop unused argument [luacheck]
Kim Alvefur <zash@zash.se>
parents:
12541
diff
changeset
|
525 |
["net-provider"] = function(item) |
12541
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12540
diff
changeset
|
526 |
local service_name = item.name; |
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12540
diff
changeset
|
527 |
local ports_list = {}; |
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12540
diff
changeset
|
528 |
for _, interface, port in portmanager.get_active_services():iter(service_name, nil, nil) do |
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12540
diff
changeset
|
529 |
table.insert(ports_list, "["..interface.."]:"..port); |
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12540
diff
changeset
|
530 |
end |
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12540
diff
changeset
|
531 |
if not ports_list[1] then |
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12540
diff
changeset
|
532 |
return service_name..": not listening on any ports"; |
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12540
diff
changeset
|
533 |
end |
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12540
diff
changeset
|
534 |
return service_name..": "..table.concat(ports_list, ", "); |
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12540
diff
changeset
|
535 |
end, |
11935
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
536 |
["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:
11934
diff
changeset
|
537 |
["metric"] = function(item) |
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11934
diff
changeset
|
538 |
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:
11934
diff
changeset
|
539 |
end, |
12544
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12542
diff
changeset
|
540 |
["task"] = function (item) return string.format("%s (%s, %s)", item.name or item.id, item.when, task_timefmt(item.last)); end |
11611
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11610
diff
changeset
|
541 |
}; |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11610
diff
changeset
|
542 |
|
11605
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
543 |
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:
11527
diff
changeset
|
544 |
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:
11527
diff
changeset
|
545 |
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:
11527
diff
changeset
|
546 |
print("in global context"); |
11608
7466bf65d7c8
mod_admin_shell: module:info: Use existing host string representation
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
547 |
else |
7466bf65d7c8
mod_admin_shell: module:info: Use existing host string representation
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
548 |
print("on " .. tostring(prosody.hosts[mod.module.host])); |
11605
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
549 |
end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
550 |
print(" path: " .. (mod.module.path or "n/a")); |
11606
78ec0741c2bc
mod_admin_shell: module:info: Show module status
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
551 |
if mod.module.status_message then |
78ec0741c2bc
mod_admin_shell: module:info: Show module status
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
552 |
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:
11605
diff
changeset
|
553 |
end |
11609
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
554 |
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:
11608
diff
changeset
|
555 |
print(" provides:"); |
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
556 |
for kind, items in pairs(mod.module.items) do |
11610
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11609
diff
changeset
|
557 |
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:
11609
diff
changeset
|
558 |
print(string.format(" - %s (%d item%s)", label, #items, #items > 1 and "s" or "")); |
11611
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11610
diff
changeset
|
559 |
local formatter = item_formatters[kind]; |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11610
diff
changeset
|
560 |
if formatter then |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11610
diff
changeset
|
561 |
for _, item in ipairs(items) do |
11854
bfa85965106e
mod_admin_shell: Show HTTP base-URLs in module:info()
Kim Alvefur <zash@zash.se>
parents:
11835
diff
changeset
|
562 |
print(" - " .. formatter(item, mod.module)); |
11611
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11610
diff
changeset
|
563 |
end |
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11610
diff
changeset
|
564 |
end |
11609
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
565 |
end |
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
566 |
end |
11607
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
567 |
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:
11606
diff
changeset
|
568 |
print(" dependencies:"); |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
569 |
for dep in pairs(mod.module.dependencies) do |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
570 |
print(" - mod_" .. dep); |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
571 |
end |
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
572 |
end |
11605
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
573 |
end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
574 |
return true; |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
575 |
end |
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11527
diff
changeset
|
576 |
|
12607
05ca75309fa0
mod_admin_shell: Remove obsolete module:load() argument from 0.8 time
Kim Alvefur <zash@zash.se>
parents:
12593
diff
changeset
|
577 |
function def_env.module:load(name, hosts) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
578 |
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
|
579 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
580 |
-- 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
|
581 |
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
|
582 |
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
|
583 |
if (not modulemanager.is_loaded(host, name)) then |
12607
05ca75309fa0
mod_admin_shell: Remove obsolete module:load() argument from 0.8 time
Kim Alvefur <zash@zash.se>
parents:
12593
diff
changeset
|
584 |
mod, err = modulemanager.load(host, name); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
585 |
if 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
|
586 |
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
|
587 |
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
|
588 |
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
|
589 |
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
|
590 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
591 |
break; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
592 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
593 |
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
|
594 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
595 |
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
|
596 |
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
|
597 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
598 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
599 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
600 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
601 |
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
|
602 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
603 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
604 |
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
|
605 |
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
|
606 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
607 |
-- 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
|
608 |
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
|
609 |
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
|
610 |
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
|
611 |
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
|
612 |
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
|
613 |
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
|
614 |
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
|
615 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
616 |
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
|
617 |
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
|
618 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
619 |
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 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
621 |
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
|
622 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
623 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
624 |
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
|
625 |
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
|
626 |
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
|
627 |
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
|
628 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
629 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
630 |
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
|
631 |
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
|
632 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
633 |
-- 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
|
634 |
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
|
635 |
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
|
636 |
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
|
637 |
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
|
638 |
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
|
639 |
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
|
640 |
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
|
641 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
642 |
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
|
643 |
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
|
644 |
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
|
645 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
646 |
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
|
647 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
648 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
649 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
650 |
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
|
651 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
652 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
653 |
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
|
654 |
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
|
655 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
656 |
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
|
657 |
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
|
658 |
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
|
659 |
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
|
660 |
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
|
661 |
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
|
662 |
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
|
663 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
664 |
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
|
665 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
666 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
667 |
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
|
668 |
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
|
669 |
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
|
670 |
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
|
671 |
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
|
672 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
673 |
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
|
674 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
675 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
676 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
677 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
678 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
679 |
def_env.config = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
680 |
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
|
681 |
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
|
682 |
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
|
683 |
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
|
684 |
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
|
685 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
686 |
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
|
687 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
688 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
689 |
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
|
690 |
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
|
691 |
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
|
692 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
693 |
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
|
694 |
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
|
695 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
696 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
697 |
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
|
698 |
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
|
699 |
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
|
700 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
701 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
702 |
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
|
703 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
704 |
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
|
705 |
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
|
706 |
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
|
707 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
708 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
709 |
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
|
710 |
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
|
711 |
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
|
712 |
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
|
713 |
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
|
714 |
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
|
715 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
716 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
717 |
local 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
|
718 |
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
|
719 |
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
|
720 |
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
|
721 |
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
|
722 |
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
|
723 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
724 |
|
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
725 |
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:
11854
diff
changeset
|
726 |
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:
11854
diff
changeset
|
727 |
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:
11854
diff
changeset
|
728 |
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:
11854
diff
changeset
|
729 |
end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
730 |
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:
11854
diff
changeset
|
731 |
end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
732 |
|
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
733 |
local function show_c2s(callback) |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
734 |
get_c2s():sort(_sort_by_jid):map(function (session) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
735 |
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
|
736 |
end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
737 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
738 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
739 |
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
|
740 |
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
|
741 |
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
|
742 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
743 |
|
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
744 |
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:
11854
diff
changeset
|
745 |
if session.direction == "outgoing" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
746 |
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:
11854
diff
changeset
|
747 |
elseif session.direction == "incoming" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
748 |
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:
11854
diff
changeset
|
749 |
end |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
750 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
751 |
|
12228
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12213
diff
changeset
|
752 |
available_columns = { |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
753 |
jid = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
754 |
title = "JID"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
755 |
description = "Full JID of user session"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
756 |
width = 32; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
757 |
key = "full_jid"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
758 |
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:
11854
diff
changeset
|
759 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
760 |
host = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
761 |
title = "Host"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
762 |
description = "Local hostname"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
763 |
key = "host"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
764 |
width = 22; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
765 |
mapper = function(host, session) |
11896
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11895
diff
changeset
|
766 |
return host or get_s2s_hosts(session) or "?"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
767 |
end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
768 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
769 |
remote = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
770 |
title = "Remote"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
771 |
description = "Remote hostname"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
772 |
width = 22; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
773 |
mapper = function(_, session) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
774 |
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:
11854
diff
changeset
|
775 |
end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
776 |
}; |
12027
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12023
diff
changeset
|
777 |
port = { |
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12023
diff
changeset
|
778 |
title = "Port"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
779 |
description = "Server port used"; |
12027
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12023
diff
changeset
|
780 |
width = 5; |
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12023
diff
changeset
|
781 |
align = "right"; |
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12023
diff
changeset
|
782 |
key = "conn"; |
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12023
diff
changeset
|
783 |
mapper = function(conn) return conn:serverport(); end; |
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12023
diff
changeset
|
784 |
}; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
785 |
dir = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
786 |
title = "Dir"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
787 |
description = "Direction of server-to-server connection"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
788 |
width = 3; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
789 |
key = "direction"; |
11892
050c515fe9aa
mod_admin_shell: Indicate bi-directional s2s connections
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
790 |
mapper = function(dir, session) |
050c515fe9aa
mod_admin_shell: Indicate bi-directional s2s connections
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
791 |
if session.incoming and session.outgoing then return "<->"; end |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
792 |
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:
11854
diff
changeset
|
793 |
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:
11854
diff
changeset
|
794 |
end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
795 |
}; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
796 |
id = { title = "Session ID"; description = "Internal session ID used in logging"; width = 20; key = "id" }; |
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
797 |
type = { title = "Type"; description = "Session type"; width = #"c2s_unauthed"; key = "type" }; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
798 |
method = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
799 |
title = "Method"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
800 |
description = "Connection method"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
801 |
width = 10; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
802 |
mapper = function(_, session) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
803 |
if session.bosh_version then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
804 |
return "BOSH"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
805 |
elseif session.websocket_request then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
806 |
return "WebSocket"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
807 |
else |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
808 |
return "TCP"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
809 |
end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
810 |
end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
811 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
812 |
ipv = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
813 |
title = "IPv"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
814 |
description = "Internet Protocol version (4 or 6)"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
815 |
width = 4; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
816 |
key = "ip"; |
11896
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11895
diff
changeset
|
817 |
mapper = function(ip) if ip then return ip:find(":") and "IPv6" or "IPv4"; end end; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
818 |
}; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
819 |
ip = { title = "IP address"; description = "IP address the session connected from"; width = 40; key = "ip" }; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
820 |
status = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
821 |
title = "Status"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
822 |
description = "Presence status"; |
11950
c0a01e5f5656
mod_admin_shell: Reduce width of 'Status' column
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
823 |
width = 6; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
824 |
key = "presence"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
825 |
mapper = function(p) |
11950
c0a01e5f5656
mod_admin_shell: Reduce width of 'Status' column
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
826 |
if not p then return ""; end |
c0a01e5f5656
mod_admin_shell: Reduce width of 'Status' column
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
827 |
return p:get_child_text("show") or "online"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
828 |
end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
829 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
830 |
secure = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
831 |
title = "Security"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
832 |
description = "TLS version or security status"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
833 |
key = "conn"; |
11949
142b9c4010fe
mod_admin_shell: Reduce width of 'Security' column (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
11947
diff
changeset
|
834 |
width = 8; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
835 |
mapper = function(conn, session) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
836 |
if not session.secure then return "insecure"; end |
11909
bbfa707a4756
mod_admin_shell: Handle absence of connection in security column (thanks arcseconds)
Kim Alvefur <zash@zash.se>
parents:
11896
diff
changeset
|
837 |
if not conn or not conn:ssl() then return "secure" end |
12484
7e9ebdc75ce4
net: isolate LuaSec-specifics
Jonas Schäfer <jonas@wielicki.name>
parents:
12468
diff
changeset
|
838 |
local tls_info = conn.ssl_info and conn:ssl_info(); |
11949
142b9c4010fe
mod_admin_shell: Reduce width of 'Security' column (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
11947
diff
changeset
|
839 |
return tls_info and tls_info.protocol or "secure"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
840 |
end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
841 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
842 |
encryption = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
843 |
title = "Encryption"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
844 |
description = "Encryption algorithm used (TLS cipher suite)"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
845 |
width = 30; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
846 |
key = "conn"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
847 |
mapper = function(conn) |
12484
7e9ebdc75ce4
net: isolate LuaSec-specifics
Jonas Schäfer <jonas@wielicki.name>
parents:
12468
diff
changeset
|
848 |
local info = conn and conn.ssl_info and conn:ssl_info(); |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
849 |
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:
11854
diff
changeset
|
850 |
end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
851 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
852 |
cert = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
853 |
title = "Certificate"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
854 |
description = "Validation status of certificate"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
855 |
key = "cert_identity_status"; |
12297
145cb8305c67
mod_admin_shell: Squeeze some characters out of the Certificate column
Kim Alvefur <zash@zash.se>
parents:
12295
diff
changeset
|
856 |
width = 11; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
857 |
mapper = function(cert_status, session) |
11896
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11895
diff
changeset
|
858 |
if cert_status then return capitalize(cert_status); end |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
859 |
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:
11854
diff
changeset
|
860 |
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:
11854
diff
changeset
|
861 |
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:
11854
diff
changeset
|
862 |
return "Expired"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
863 |
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:
11854
diff
changeset
|
864 |
return "Self-signed"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
865 |
end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
866 |
return "Untrusted"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
867 |
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:
11854
diff
changeset
|
868 |
return "Mismatched"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
869 |
end |
12297
145cb8305c67
mod_admin_shell: Squeeze some characters out of the Certificate column
Kim Alvefur <zash@zash.se>
parents:
12295
diff
changeset
|
870 |
return "Unknown"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
871 |
end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
872 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
873 |
sni = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
874 |
title = "SNI"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
875 |
description = "Hostname requested in TLS"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
876 |
width = 22; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
877 |
mapper = function(_, session) |
11896
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11895
diff
changeset
|
878 |
if not session.conn then return end |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
879 |
local sock = session.conn:socket(); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
880 |
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:
11854
diff
changeset
|
881 |
end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
882 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
883 |
alpn = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
884 |
title = "ALPN"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
885 |
description = "Protocol requested in TLS"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
886 |
width = 11; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
887 |
mapper = function(_, session) |
11896
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11895
diff
changeset
|
888 |
if not session.conn then return end |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
889 |
local sock = session.conn:socket(); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
890 |
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:
11854
diff
changeset
|
891 |
end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
892 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
893 |
smacks = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
894 |
title = "SM"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
895 |
description = "Stream Management (XEP-0198) status"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
896 |
key = "smacks"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
897 |
width = 11; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
898 |
mapper = function(smacks_xmlns, session) |
11896
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11895
diff
changeset
|
899 |
if not smacks_xmlns then return "no"; end |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
900 |
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:
11854
diff
changeset
|
901 |
return "yes"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
902 |
end; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
903 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
904 |
smacks_queue = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
905 |
title = "SM Queue"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
906 |
description = "Length of Stream Management stanza queue"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
907 |
key = "outgoing_stanza_queue"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
908 |
width = 8; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
909 |
align = "right"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
910 |
mapper = function (queue) |
12060
e62025f949f9
mod_smacks: Limit queue memory consumption using new util
Kim Alvefur <zash@zash.se>
parents:
12027
diff
changeset
|
911 |
return queue and tostring(queue:count_unacked()); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
912 |
end |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
913 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
914 |
csi = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
915 |
title = "CSI State"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
916 |
description = "Client State Indication (XEP-0352)"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
917 |
key = "state"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
918 |
-- TODO include counter |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
919 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
920 |
s2s_sasl = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
921 |
title = "SASL"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
922 |
description = "Server authentication status"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
923 |
key = "external_auth"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
924 |
width = 10; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
925 |
mapper = capitalize |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
926 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
927 |
dialback = { |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
928 |
title = "Dialback"; |
12233
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12232
diff
changeset
|
929 |
description = "Legacy server verification"; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
930 |
key = "dialback_key"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
931 |
width = 13; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
932 |
mapper = function (dialback_key, session) |
11896
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11895
diff
changeset
|
933 |
if not dialback_key then |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
934 |
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:
11854
diff
changeset
|
935 |
return "Not used"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
936 |
end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
937 |
return "Not initiated"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
938 |
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:
11854
diff
changeset
|
939 |
return "Initiated"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
940 |
else |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
941 |
return "Completed"; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
942 |
end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
943 |
end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
944 |
}; |
12664
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
945 |
role = { |
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
946 |
title = "Role"; |
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
947 |
description = "Session role"; |
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
948 |
width = 20; |
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
949 |
key = "role"; |
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
950 |
mapper = function(role) |
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
951 |
return role.name; |
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
952 |
end; |
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
953 |
} |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
954 |
}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
955 |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
956 |
local function get_colspec(colspec, default) |
11891
b043e1bb8e8e
mod_admin_shell: Allow passing columns as a string for convenience
Kim Alvefur <zash@zash.se>
parents:
11890
diff
changeset
|
957 |
if type(colspec) == "string" then colspec = array(colspec:gmatch("%S+")); end |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
958 |
local columns = {}; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
959 |
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:
11854
diff
changeset
|
960 |
if type(col) == "string" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
961 |
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:
11854
diff
changeset
|
962 |
elseif type(col) ~= "table" then |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
963 |
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:
11854
diff
changeset
|
964 |
else |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
965 |
columns[i] = col; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
966 |
end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
967 |
end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
968 |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
969 |
return columns; |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
970 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
971 |
|
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
972 |
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:
11854
diff
changeset
|
973 |
local print = self.session.print; |
12664
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
974 |
local columns = get_colspec(colspec, { "id"; "jid"; "role"; "ipv"; "status"; "secure"; "smacks"; "csi" }); |
12533
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12510
diff
changeset
|
975 |
local row = format_table(columns, self.session.width); |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
976 |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
977 |
local function match(session) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
978 |
local jid = get_jid(session) |
12232
f60f9cd9d26c
mod_admin_shell: Use exact match instead of Lua patterns in c2s,s2s:show
Kim Alvefur <zash@zash.se>
parents:
12230
diff
changeset
|
979 |
return (not match_jid) or jid == match_jid; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
980 |
end |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
981 |
|
11890
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
982 |
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:
11889
diff
changeset
|
983 |
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:
11889
diff
changeset
|
984 |
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:
11889
diff
changeset
|
985 |
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:
11889
diff
changeset
|
986 |
break |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
987 |
end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
988 |
end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
989 |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
990 |
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:
11889
diff
changeset
|
991 |
local currenthost = nil; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
992 |
|
11921
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11909
diff
changeset
|
993 |
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:
11909
diff
changeset
|
994 |
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:
11909
diff
changeset
|
995 |
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:
11909
diff
changeset
|
996 |
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:
11909
diff
changeset
|
997 |
for _, session in ipairs(c2s_sessions) do |
11890
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
998 |
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:
11889
diff
changeset
|
999 |
currenthost = session.host; |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
1000 |
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:
11889
diff
changeset
|
1001 |
print(row()); |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
1002 |
end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
1003 |
|
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1004 |
print(row(session)); |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1005 |
end |
11921
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11909
diff
changeset
|
1006 |
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:
11909
diff
changeset
|
1007 |
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:
11909
diff
changeset
|
1008 |
end |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11909
diff
changeset
|
1009 |
return true, ("%d c2s sessions shown"):format(total_count); |
10860
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 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1012 |
function def_env.c2s:show_tls(match_jid) |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1013 |
return self:show(match_jid, { "jid"; "id"; "secure"; "encryption" }); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1014 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1015 |
|
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 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
|
1017 |
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
|
1018 |
return { |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1019 |
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
|
1020 |
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
|
1021 |
}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1022 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1023 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1024 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1025 |
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
|
1026 |
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
|
1027 |
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
|
1028 |
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
|
1029 |
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
|
1030 |
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
|
1031 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1032 |
end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1033 |
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
|
1034 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1035 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1036 |
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
|
1037 |
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
|
1038 |
--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
|
1039 |
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
|
1040 |
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
|
1041 |
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
|
1042 |
end); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1043 |
return 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
|
1044 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1045 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1046 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1047 |
def_env.s2s = {}; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1048 |
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:
11854
diff
changeset
|
1049 |
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:
11854
diff
changeset
|
1050 |
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:
11854
diff
changeset
|
1051 |
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:
11854
diff
changeset
|
1052 |
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:
11854
diff
changeset
|
1053 |
end |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1054 |
|
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1055 |
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:
11854
diff
changeset
|
1056 |
local print = self.session.print; |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1057 |
local columns = get_colspec(colspec, { "id"; "host"; "dir"; "remote"; "ipv"; "secure"; "s2s_sasl"; "dialback" }); |
12533
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12510
diff
changeset
|
1058 |
local row = format_table(columns, self.session.width); |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1059 |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1060 |
local function match(session) |
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1061 |
local host, remote = get_s2s_hosts(session); |
12232
f60f9cd9d26c
mod_admin_shell: Use exact match instead of Lua patterns in c2s,s2s:show
Kim Alvefur <zash@zash.se>
parents:
12230
diff
changeset
|
1062 |
return not match_jid or host == match_jid or remote == match_jid; |
10860
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 |
|
11890
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
1065 |
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:
11889
diff
changeset
|
1066 |
local currenthost = nil; |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
1067 |
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:
11889
diff
changeset
|
1068 |
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:
11889
diff
changeset
|
1069 |
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:
11889
diff
changeset
|
1070 |
break |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
1071 |
end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
1072 |
end |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
1073 |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
1074 |
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:
11889
diff
changeset
|
1075 |
|
11921
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11909
diff
changeset
|
1076 |
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:
11909
diff
changeset
|
1077 |
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:
11909
diff
changeset
|
1078 |
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:
11909
diff
changeset
|
1079 |
local shown_count = #s2s_sessions; |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1080 |
|
11890
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
1081 |
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:
11889
diff
changeset
|
1082 |
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:
11889
diff
changeset
|
1083 |
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:
11889
diff
changeset
|
1084 |
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:
11889
diff
changeset
|
1085 |
print(row()); |
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
1086 |
end |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1087 |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1088 |
print(row(session)); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1089 |
end |
11921
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11909
diff
changeset
|
1090 |
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:
11909
diff
changeset
|
1091 |
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:
11909
diff
changeset
|
1092 |
end |
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11909
diff
changeset
|
1093 |
return true, ("%d s2s connections shown"):format(total_count); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1094 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1095 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1096 |
function def_env.s2s:show_tls(match_jid) |
11889
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
1097 |
return self:show(match_jid, { "id"; "host"; "dir"; "remote"; "secure"; "encryption"; "cert" }); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1098 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1099 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1100 |
local 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
|
1101 |
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
|
1102 |
print( |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1103 |
(" %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
|
1104 |
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
|
1105 |
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
|
1106 |
) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1107 |
); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1108 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1109 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1110 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1111 |
-- 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
|
1112 |
-- 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
|
1113 |
-- 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
|
1114 |
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
|
1115 |
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
|
1116 |
print( |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1117 |
(" %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
|
1118 |
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
|
1119 |
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
|
1120 |
) |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1121 |
); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1122 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1123 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1124 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1125 |
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
|
1126 |
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
|
1127 |
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
|
1128 |
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
|
1129 |
/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
|
1130 |
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
|
1131 |
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
|
1132 |
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
|
1133 |
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
|
1134 |
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
|
1135 |
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
|
1136 |
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
|
1137 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1138 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1139 |
local 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
|
1140 |
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
|
1141 |
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
|
1142 |
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
|
1143 |
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
|
1144 |
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
|
1145 |
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
|
1146 |
{ |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1147 |
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
|
1148 |
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
|
1149 |
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
|
1150 |
}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1151 |
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
|
1152 |
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
|
1153 |
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
|
1154 |
}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1155 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1156 |
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
|
1157 |
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
|
1158 |
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
|
1159 |
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
|
1160 |
}); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1161 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1162 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1163 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1164 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1165 |
local 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
|
1166 |
-- 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
|
1167 |
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
|
1168 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1169 |
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
|
1170 |
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
|
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 |
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
|
1174 |
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
|
1175 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1176 |
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
|
1177 |
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
|
1178 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1179 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1180 |
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
|
1181 |
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
|
1182 |
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
|
1183 |
print("---") |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1184 |
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
|
1185 |
print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1186 |
local 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
|
1187 |
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
|
1188 |
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
|
1189 |
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
|
1190 |
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
|
1191 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1192 |
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
|
1193 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1194 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1195 |
print(""); |
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 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
|
1197 |
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
|
1198 |
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
|
1199 |
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
|
1200 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1201 |
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
|
1202 |
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
|
1203 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1204 |
print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1205 |
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
|
1206 |
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
|
1207 |
print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1208 |
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
|
1209 |
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
|
1210 |
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
|
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 |
print("---"); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1213 |
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
|
1214 |
..(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
|
1215 |
.." 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
|
1216 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1217 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1218 |
function def_env.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
|
1219 |
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
|
1220 |
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
|
1221 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1222 |
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
|
1223 |
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
|
1224 |
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
|
1225 |
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
|
1226 |
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
|
1227 |
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
|
1228 |
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
|
1229 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1230 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1231 |
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
|
1232 |
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
|
1233 |
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
|
1234 |
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
|
1235 |
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
|
1236 |
(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
|
1237 |
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
|
1238 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1239 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1240 |
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
|
1241 |
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 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1243 |
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
|
1244 |
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
|
1245 |
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
|
1246 |
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
|
1247 |
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
|
1248 |
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
|
1249 |
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
|
1250 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1251 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1252 |
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
|
1253 |
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
|
1254 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1255 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1256 |
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
|
1257 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1258 |
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
|
1259 |
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
|
1260 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1261 |
function def_env.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
|
1262 |
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
|
1263 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1264 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1265 |
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
|
1266 |
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
|
1267 |
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
|
1268 |
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
|
1269 |
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
|
1270 |
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
|
1271 |
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
|
1272 |
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
|
1273 |
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
|
1274 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1275 |
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
|
1276 |
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
|
1277 |
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
|
1278 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1279 |
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
|
1280 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1281 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1282 |
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
|
1283 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1284 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1285 |
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
|
1286 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1287 |
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
|
1288 |
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
|
1289 |
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
|
1290 |
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
|
1291 |
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
|
1292 |
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
|
1293 |
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
|
1294 |
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
|
1295 |
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
|
1296 |
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
|
1297 |
end |
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 |
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
|
1300 |
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
|
1301 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1302 |
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
|
1303 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1304 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1305 |
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
|
1306 |
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
|
1307 |
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
|
1308 |
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
|
1309 |
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
|
1310 |
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
|
1311 |
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
|
1312 |
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
|
1313 |
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
|
1314 |
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
|
1315 |
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
|
1316 |
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
|
1317 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1318 |
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
|
1319 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1320 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1321 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1322 |
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 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1324 |
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
|
1325 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1326 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1327 |
def_env.muc = {}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1328 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1329 |
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
|
1330 |
__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
|
1331 |
__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
|
1332 |
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
|
1333 |
end; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1334 |
}; |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1335 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1336 |
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
|
1337 |
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
|
1338 |
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
|
1339 |
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
|
1340 |
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
|
1341 |
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
|
1342 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1343 |
return 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
|
1344 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1345 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1346 |
function def_env.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
|
1347 |
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
|
1348 |
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
|
1349 |
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
|
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 |
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
|
1352 |
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
|
1353 |
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
|
1354 |
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
|
1355 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1356 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1357 |
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
|
1358 |
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
|
1359 |
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
|
1360 |
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
|
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 |
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
|
1363 |
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
|
1364 |
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
|
1365 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1366 |
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
|
1367 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1368 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1369 |
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
|
1370 |
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
|
1371 |
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
|
1372 |
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
|
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 |
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
|
1375 |
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
|
1376 |
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
|
1377 |
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
|
1378 |
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
|
1379 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1380 |
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
|
1381 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1382 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1383 |
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
|
1384 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1385 |
def_env.user = {}; |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1386 |
function def_env.user:create(jid, password, role) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1387 |
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
|
1388 |
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
|
1389 |
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
|
1390 |
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
|
1391 |
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
|
1392 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1393 |
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
|
1394 |
if ok then |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1395 |
if ok and role then |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1396 |
local role_ok, rerr = um.set_user_role(jid, host, role); |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1397 |
if not role_ok then return nil, "User created, but could not set role: " .. tostring(rerr); end |
12016
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11995
diff
changeset
|
1398 |
end |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1399 |
return true, "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
|
1400 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1401 |
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
|
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 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1404 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1405 |
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
|
1406 |
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
|
1407 |
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
|
1408 |
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
|
1409 |
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
|
1410 |
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
|
1411 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1412 |
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
|
1413 |
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
|
1414 |
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
|
1415 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1416 |
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
|
1417 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1418 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1419 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1420 |
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
|
1421 |
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
|
1422 |
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
|
1423 |
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
|
1424 |
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
|
1425 |
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
|
1426 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1427 |
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
|
1428 |
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
|
1429 |
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
|
1430 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1431 |
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
|
1432 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1433 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1434 |
|
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1435 |
function def_env.user:role(jid, host) |
12213
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12212
diff
changeset
|
1436 |
local username, userhost = jid_split(jid); |
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12212
diff
changeset
|
1437 |
if host == nil then host = userhost; end |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1438 |
if not prosody.hosts[host] then |
12213
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12212
diff
changeset
|
1439 |
return nil, "No such host: "..host; |
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12212
diff
changeset
|
1440 |
elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then |
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12212
diff
changeset
|
1441 |
return nil, "No such user"; |
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12212
diff
changeset
|
1442 |
end |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1443 |
|
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1444 |
local primary_role = um.get_user_role(username, host); |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1445 |
local secondary_roles = um.get_user_secondary_roles(username, host); |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1446 |
|
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1447 |
print(primary_role and primary_role.name or "<none>"); |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1448 |
|
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1449 |
local count = primary_role and 1 or 0; |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1450 |
for role_name in pairs(secondary_roles or {}) do |
12213
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12212
diff
changeset
|
1451 |
count = count + 1; |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1452 |
print(role_name.." (secondary)"); |
12213
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12212
diff
changeset
|
1453 |
end |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1454 |
|
12213
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12212
diff
changeset
|
1455 |
return true, count == 1 and "1 role" or count.." roles"; |
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12212
diff
changeset
|
1456 |
end |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1457 |
def_env.user.roles = def_env.user.role; |
12213
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12212
diff
changeset
|
1458 |
|
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1459 |
-- user:setrole("someone@example.com", "example.com", "prosody:admin") |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1460 |
-- user:setrole("someone@example.com", "prosody:admin") |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1461 |
function def_env.user:setrole(jid, host, new_role) |
12018
efbf288b529e
mod_admin_shell: Support setting roles on hosts other than the users'
Kim Alvefur <zash@zash.se>
parents:
12017
diff
changeset
|
1462 |
local username, userhost = jid_split(jid); |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1463 |
if new_role == nil then host, new_role = userhost, host; end |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1464 |
if not prosody.hosts[host] then |
12017
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12016
diff
changeset
|
1465 |
return nil, "No such host: "..host; |
12022
c65789f5004e
mod_admin_shell: Only check that local users exist locally
Kim Alvefur <zash@zash.se>
parents:
12018
diff
changeset
|
1466 |
elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then |
12017
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12016
diff
changeset
|
1467 |
return nil, "No such user"; |
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12016
diff
changeset
|
1468 |
end |
12672
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1469 |
return um.set_user_role(username, host, new_role); |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1470 |
end |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1471 |
|
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1472 |
function def_env.user:addrole(jid, host, new_role) |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1473 |
local username, userhost = jid_split(jid); |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1474 |
if new_role == nil then host, new_role = userhost, host; end |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1475 |
if not prosody.hosts[host] then |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1476 |
return nil, "No such host: "..host; |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1477 |
elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1478 |
return nil, "No such user"; |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1479 |
end |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1480 |
return um.add_user_secondary_role(username, host, new_role); |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1481 |
end |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1482 |
|
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1483 |
function def_env.user:delrole(jid, host, role_name) |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1484 |
local username, userhost = jid_split(jid); |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1485 |
if role_name == nil then host, role_name = userhost, host; end |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1486 |
if not prosody.hosts[host] then |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1487 |
return nil, "No such host: "..host; |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1488 |
elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1489 |
return nil, "No such user"; |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1490 |
end |
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12664
diff
changeset
|
1491 |
return um.remove_user_secondary_role(username, host, role_name); |
12017
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12016
diff
changeset
|
1492 |
end |
12016
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11995
diff
changeset
|
1493 |
|
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11995
diff
changeset
|
1494 |
-- TODO switch to table view, include roles |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1495 |
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
|
1496 |
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
|
1497 |
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
|
1498 |
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
|
1499 |
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
|
1500 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1501 |
local 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
|
1502 |
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
|
1503 |
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
|
1504 |
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
|
1505 |
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
|
1506 |
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
|
1507 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1508 |
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
|
1509 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1510 |
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
|
1511 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1512 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1513 |
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
|
1514 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1515 |
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
|
1516 |
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
|
1517 |
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
|
1518 |
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
|
1519 |
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
|
1520 |
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
|
1521 |
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
|
1522 |
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
|
1523 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1524 |
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
|
1525 |
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
|
1526 |
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
|
1527 |
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
|
1528 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1529 |
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
|
1530 |
: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
|
1531 |
local time_start = time.now(); |
12126
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1532 |
local print = self.session.print; |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1533 |
local function onchange(what) |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1534 |
return function(event) |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1535 |
local s2s_session = event.session; |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1536 |
if (s2s_session.from_host == localhost and s2s_session.to_host == remotehost) |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1537 |
or (s2s_session.to_host == localhost and s2s_session.from_host == remotehost) then |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1538 |
local dir = available_columns.dir.mapper(s2s_session.direction, s2s_session); |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1539 |
print(("Session %s (%s%s%s) %s (%gs)"):format(s2s_session.id, localhost, dir, remotehost, what, |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1540 |
time.now() - time_start)); |
12130
0d8e6646ce42
mod_admin_shell: Log creation of incoming s2s connections during ping
Kim Alvefur <zash@zash.se>
parents:
12126
diff
changeset
|
1541 |
elseif s2s_session.type == "s2sin_unauthed" and s2s_session.to_host == nil and s2s_session.from_host == nil then |
0d8e6646ce42
mod_admin_shell: Log creation of incoming s2s connections during ping
Kim Alvefur <zash@zash.se>
parents:
12126
diff
changeset
|
1542 |
print(("Session %s %s (%gs)"):format(s2s_session.id, what, time.now() - time_start)); |
12126
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1543 |
end |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1544 |
end |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1545 |
end |
12285
9016071867d7
mod_admin_shell: Track connected events instead of created
Kim Alvefur <zash@zash.se>
parents:
12262
diff
changeset
|
1546 |
local onconnected = onchange("connected"); |
12126
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1547 |
local onauthenticated = onchange("authenticated"); |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1548 |
local onestablished = onchange("established"); |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1549 |
local ondestroyed = onchange("destroyed"); |
12285
9016071867d7
mod_admin_shell: Track connected events instead of created
Kim Alvefur <zash@zash.se>
parents:
12262
diff
changeset
|
1550 |
module:hook("s2s-connected", onconnected, 1); |
12126
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1551 |
module:context(localhost):hook("s2s-authenticated", onauthenticated, 1); |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1552 |
module:hook("s2sout-established", onestablished, 1); |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1553 |
module:hook("s2sin-established", onestablished, 1); |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1554 |
module:hook("s2s-destroyed", ondestroyed, 1); |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1555 |
return module:context(localhost):send_iq(iq, nil, timeout):finally(function() |
12285
9016071867d7
mod_admin_shell: Track connected events instead of created
Kim Alvefur <zash@zash.se>
parents:
12262
diff
changeset
|
1556 |
module:unhook("s2s-connected", onconnected, 1); |
12126
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1557 |
module:context(localhost):unhook("s2s-authenticated", onauthenticated); |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1558 |
module:unhook("s2sout-established", onestablished); |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1559 |
module:unhook("s2sin-established", onestablished); |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1560 |
module:unhook("s2s-destroyed", ondestroyed); |
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12060
diff
changeset
|
1561 |
end):next(function(pong) |
12555
3b7e97e0a8ef
mod_admin_shell: Show session id ping reply came
Kim Alvefur <zash@zash.se>
parents:
12544
diff
changeset
|
1562 |
return ("pong from %s on %s in %gs"):format(pong.stanza.attr.from, pong.origin.id, time.now() - time_start); |
11957
848a522fd731
mod_admin_shell: Remove now redundant promise awaiting in xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
11954
diff
changeset
|
1563 |
end); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1564 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1565 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1566 |
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
|
1567 |
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
|
1568 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1569 |
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
|
1570 |
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
|
1571 |
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
|
1572 |
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
|
1573 |
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
|
1574 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1575 |
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
|
1576 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1577 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1578 |
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
|
1579 |
local resolver = get_resolver(self.session); |
11958
b963ac00c967
mod_admin_shell: Remove now redundant promise awaiting in dns:lookup()
Kim Alvefur <zash@zash.se>
parents:
11957
diff
changeset
|
1580 |
return resolver:lookup_promise(name, typ, class) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1581 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1582 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1583 |
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
|
1584 |
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
|
1585 |
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
|
1586 |
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
|
1587 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1588 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1589 |
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
|
1590 |
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
|
1591 |
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
|
1592 |
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
|
1593 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1594 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1595 |
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
|
1596 |
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
|
1597 |
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
|
1598 |
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
|
1599 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1600 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1601 |
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
|
1602 |
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
|
1603 |
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
|
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 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1606 |
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
|
1607 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1608 |
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
|
1609 |
local print = self.session.print; |
11365
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11046
diff
changeset
|
1610 |
hosts = array.collect(set.new({ not hosts and "*" or nil }) + get_hosts_set(hosts)):sort(_sort_hosts); |
11368
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11367
diff
changeset
|
1611 |
local output = format_table({ |
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11367
diff
changeset
|
1612 |
{ title = "Module", width = "20%" }, |
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11367
diff
changeset
|
1613 |
{ title = "URL", width = "80%" }, |
12533
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12510
diff
changeset
|
1614 |
}, self.session.width); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1615 |
|
11365
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11046
diff
changeset
|
1616 |
for _, host in ipairs(hosts) do |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1617 |
local 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
|
1618 |
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
|
1619 |
local http_host = module:context(host):get_option_string("http_host"); |
11365
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11046
diff
changeset
|
1620 |
if host == "*" then |
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11046
diff
changeset
|
1621 |
print("Global HTTP endpoints available on all hosts:"); |
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11046
diff
changeset
|
1622 |
else |
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11046
diff
changeset
|
1623 |
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:
11046
diff
changeset
|
1624 |
end |
11368
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11367
diff
changeset
|
1625 |
print(output()); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1626 |
for _, provider in ipairs(http_apps) do |
11366
52d93fba2ee1
mod_admin_shell: List modules providing each HTTP endpoint
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
1627 |
local mod = provider._provided_by; |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1628 |
local url = module:context(host):http_url(provider.name, provider.default_path); |
11366
52d93fba2ee1
mod_admin_shell: List modules providing each HTTP endpoint
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
1629 |
mod = mod and "mod_"..mod or "" |
11368
bb6b744f7f1a
mod_admin_shell: Pretty-print HTTP endpoints in a human table
Kim Alvefur <zash@zash.se>
parents:
11367
diff
changeset
|
1630 |
print(output{mod, url}); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1631 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1632 |
print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1633 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1634 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1635 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1636 |
local 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
|
1637 |
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
|
1638 |
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
|
1639 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1640 |
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
|
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 |
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
|
1643 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1644 |
|
12403
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1645 |
def_env.watch = {}; |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1646 |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1647 |
function def_env.watch:log() |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1648 |
local writing = false; |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1649 |
local sink = logger.add_simple_sink(function (source, level, message) |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1650 |
if writing then return; end |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1651 |
writing = true; |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1652 |
self.session.print(source, level, message); |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1653 |
writing = false; |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1654 |
end); |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1655 |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1656 |
while self.session.is_connected() do |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1657 |
async.sleep(3); |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1658 |
end |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1659 |
if not logger.remove_sink(sink) then |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1660 |
module:log("warn", "Unable to remove watch:log() sink"); |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1661 |
end |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1662 |
end |
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1663 |
|
12468
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1664 |
local stanza_watchers = module:require("mod_debug_stanzas/watcher"); |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1665 |
function def_env.watch:stanzas(target_spec, filter_spec) |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1666 |
local function handler(event_type, stanza, session) |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1667 |
if stanza then |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1668 |
if event_type == "sent" then |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1669 |
self.session.print(("\n<!-- sent to %s -->"):format(session.id)); |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1670 |
elseif event_type == "received" then |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1671 |
self.session.print(("\n<!-- received from %s -->"):format(session.id)); |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1672 |
else |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1673 |
self.session.print(("\n<!-- %s (%s) -->"):format(event_type, session.id)); |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1674 |
end |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1675 |
self.session.print(stanza); |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1676 |
elseif session then |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1677 |
self.session.print("\n<!-- session "..session.id.." "..event_type.." -->"); |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1678 |
elseif event_type then |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1679 |
self.session.print("\n<!-- "..event_type.." -->"); |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1680 |
end |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1681 |
end |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1682 |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1683 |
stanza_watchers.add({ |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1684 |
target_spec = { |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1685 |
jid = target_spec; |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1686 |
}; |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1687 |
filter_spec = filter_spec and { |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1688 |
with_jid = filter_spec; |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1689 |
}; |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1690 |
}, handler); |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1691 |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1692 |
while self.session.is_connected() do |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1693 |
async.sleep(3); |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1694 |
end |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1695 |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1696 |
stanza_watchers.remove(handler); |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
1697 |
end |
12403
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12402
diff
changeset
|
1698 |
|
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1699 |
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
|
1700 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1701 |
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
|
1702 |
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
|
1703 |
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
|
1704 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1705 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1706 |
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
|
1707 |
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
|
1708 |
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
|
1709 |
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
|
1710 |
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
|
1711 |
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
|
1712 |
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
|
1713 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1714 |
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
|
1715 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1716 |
else |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1717 |
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
|
1718 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1719 |
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
|
1720 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1721 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1722 |
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
|
1723 |
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
|
1724 |
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
|
1725 |
local h, params = add_task.h, add_task.params; |
10992
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10990
diff
changeset
|
1726 |
local function normalize_time(t) |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10990
diff
changeset
|
1727 |
return t; |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10990
diff
changeset
|
1728 |
end |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10990
diff
changeset
|
1729 |
local function format_time(t) |
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10990
diff
changeset
|
1730 |
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:
10990
diff
changeset
|
1731 |
end |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1732 |
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
|
1733 |
print("-- util.timer"); |
10990
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1734 |
elseif server.timer then |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1735 |
print("-- net.server.timer"); |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1736 |
h = server.timer.add_task.timers; |
10992
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10990
diff
changeset
|
1737 |
normalize_time = server.timer.to_absolute_time or normalize_time; |
10990
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1738 |
end |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1739 |
if h then |
11482
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11369
diff
changeset
|
1740 |
local timers = {}; |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1741 |
for i, id in ipairs(h.ids) do |
10990
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1742 |
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:
10933
diff
changeset
|
1743 |
if not params then |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1744 |
local param = cb.param; |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1745 |
if param then |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1746 |
cb = param.callback; |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1747 |
else |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1748 |
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:
10933
diff
changeset
|
1749 |
end |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1750 |
elseif params[id] then |
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10933
diff
changeset
|
1751 |
cb = params[id].callback or cb; |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1752 |
end |
11482
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11369
diff
changeset
|
1753 |
table.insert(timers, { format_time(t), cb }); |
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11369
diff
changeset
|
1754 |
end |
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11369
diff
changeset
|
1755 |
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:
11369
diff
changeset
|
1756 |
for _, t in ipairs(timers) do |
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11369
diff
changeset
|
1757 |
print(t[1], t[2]) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1758 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1759 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1760 |
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
|
1761 |
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
|
1762 |
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
|
1763 |
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
|
1764 |
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
|
1765 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1766 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1767 |
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
|
1768 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1769 |
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
|
1770 |
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
|
1771 |
if next_time then |
10992
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10990
diff
changeset
|
1772 |
return true, ("Next event at %s (in %.6fs)"):format(format_time(next_time), normalize_time(next_time) - time.now()); |
10860
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 true; |
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 |
-- 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
|
1779 |
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
|
1780 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1781 |
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
|
1782 |
|
10891
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10882
diff
changeset
|
1783 |
local short_units = { |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10882
diff
changeset
|
1784 |
seconds = "s", |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10882
diff
changeset
|
1785 |
bytes = "B", |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10882
diff
changeset
|
1786 |
}; |
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10882
diff
changeset
|
1787 |
|
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1788 |
local stats_methods = {}; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1789 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1790 |
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:
11508
diff
changeset
|
1791 |
local creation_timestamp, sum, count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1792 |
local buckets = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1793 |
local prev_bucket_count = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1794 |
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:
11508
diff
changeset
|
1795 |
if suffix == "_created" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1796 |
creation_timestamp = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1797 |
elseif suffix == "_sum" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1798 |
sum = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1799 |
elseif suffix == "_count" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1800 |
count = value |
12230
7db81c9cbbbf
mod_admin_shell: Fix traceback on rendering graph of stats without extra labels
Kim Alvefur <zash@zash.se>
parents:
12229
diff
changeset
|
1801 |
elseif extra_labels then |
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1802 |
local bucket_threshold = extra_labels["le"] |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1803 |
local bucket_count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1804 |
if cumulative then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1805 |
bucket_count = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1806 |
else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1807 |
bucket_count = value - prev_bucket_count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1808 |
prev_bucket_count = value |
10891
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10882
diff
changeset
|
1809 |
end |
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1810 |
if bucket_threshold == "+Inf" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1811 |
t_insert(buckets, {threshold = 1/0, count = bucket_count}) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1812 |
elseif bucket_threshold ~= nil then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1813 |
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:
11508
diff
changeset
|
1814 |
end |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1815 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1816 |
end |
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1817 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1818 |
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:
11508
diff
changeset
|
1819 |
print("[no data or not a histogram]") |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1820 |
return false |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1821 |
end |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1822 |
|
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1823 |
local graph_width, graph_height, wscale = #buckets, 10, 1; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1824 |
if graph_width < 8 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1825 |
wscale = 8 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1826 |
elseif graph_width < 16 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1827 |
wscale = 4 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1828 |
elseif graph_width < 32 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1829 |
wscale = 2 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1830 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1831 |
local eighth_chars = " ▁▂▃▄▅▆▇█"; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1832 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1833 |
local max_bin_samples = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1834 |
for _, bucket in ipairs(buckets) do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1835 |
if bucket.count > max_bin_samples then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1836 |
max_bin_samples = bucket.count |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1837 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1838 |
end |
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1839 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1840 |
print(""); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1841 |
print(prefix) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1842 |
print(("_"):rep(graph_width*wscale).." "..max_bin_samples); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1843 |
for row = graph_height, 1, -1 do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1844 |
local row_chars = {}; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1845 |
local min_eighths, max_eighths = 8, 0; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1846 |
for i = 1, #buckets do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1847 |
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:
11508
diff
changeset
|
1848 |
if char_eighths < min_eighths then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1849 |
min_eighths = char_eighths; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1850 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1851 |
if char_eighths > max_eighths then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1852 |
max_eighths = char_eighths; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1853 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1854 |
if char_eighths == 0 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1855 |
row_chars[i] = ("-"):rep(wscale); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1856 |
else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1857 |
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:
11508
diff
changeset
|
1858 |
row_chars[i] = char:rep(wscale); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1859 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1860 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1861 |
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:
11508
diff
changeset
|
1862 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1863 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1864 |
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:
11508
diff
changeset
|
1865 |
local row = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1866 |
for i = 1, #buckets do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1867 |
local threshold = buckets[i].threshold |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1868 |
t_insert(row, legend_pat:format(threshold)) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1869 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1870 |
t_insert(row, " " .. metric_family.unit) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1871 |
print(t_concat(row, "/")) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1872 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1873 |
return true |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1874 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1875 |
|
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1876 |
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:
11508
diff
changeset
|
1877 |
return self:render_single_fancy_histogram_ex(print, prefix, metric_family, metric, false) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1878 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1879 |
|
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1880 |
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:
11508
diff
changeset
|
1881 |
-- cf = cumulative frequency |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1882 |
return self:render_single_fancy_histogram_ex(print, prefix, metric_family, metric, true) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1883 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1884 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1885 |
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
|
1886 |
for _, stat_info in ipairs(self) do |
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1887 |
local family_name, metric_family = unpack(stat_info, 1, 2) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1888 |
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
|
1889 |
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
|
1890 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1891 |
|
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1892 |
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:
11508
diff
changeset
|
1893 |
return self |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1894 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1895 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1896 |
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
|
1897 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1898 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1899 |
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
|
1900 |
for _, stat_info in ipairs(self) do |
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1901 |
local family_name, metric_family = unpack(stat_info, 1, 2) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1902 |
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
|
1903 |
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
|
1904 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1905 |
|
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1906 |
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:
11508
diff
changeset
|
1907 |
return self |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1908 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1909 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1910 |
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
|
1911 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1912 |
|
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1913 |
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:
11508
diff
changeset
|
1914 |
local created_timestamp, current_value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1915 |
for suffix, _, value in metric:iter_samples() do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1916 |
if suffix == "_created" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1917 |
created_timestamp = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1918 |
elseif suffix == "_total" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1919 |
current_value = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1920 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1921 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1922 |
if current_value and created_timestamp then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1923 |
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:
11508
diff
changeset
|
1924 |
local unit = base_unit .. "/s" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1925 |
local factor = 1 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1926 |
if base_unit == "s" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1927 |
-- be smart! |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1928 |
unit = "%" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1929 |
factor = 100 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1930 |
elseif base_unit == "" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1931 |
unit = "events/s" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1932 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1933 |
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:
11508
diff
changeset
|
1934 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1935 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1936 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1937 |
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:
11508
diff
changeset
|
1938 |
local current_value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1939 |
for _, _, value in metric:iter_samples() do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1940 |
current_value = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1941 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1942 |
if current_value then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1943 |
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:
11508
diff
changeset
|
1944 |
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:
11508
diff
changeset
|
1945 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1946 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1947 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1948 |
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:
11508
diff
changeset
|
1949 |
local sum, count |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1950 |
for suffix, _, value in metric:iter_samples() do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1951 |
if suffix == "_sum" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1952 |
sum = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1953 |
elseif suffix == "_count" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1954 |
count = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1955 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1956 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1957 |
if sum and count then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1958 |
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:
11508
diff
changeset
|
1959 |
if count == 0 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1960 |
print(("%-50s %s"):format(prefix, "no obs.")); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1961 |
else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1962 |
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:
11508
diff
changeset
|
1963 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1964 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1965 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1966 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1967 |
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:
11508
diff
changeset
|
1968 |
local labelkeys = metric_family.label_keys |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1969 |
if #labelkeys > 0 then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1970 |
print(family_name) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1971 |
for labelset, metric in metric_family:iter_metrics() do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1972 |
local labels = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1973 |
for i, k in ipairs(labelkeys) do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1974 |
local v = labelset[i] |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1975 |
t_insert(labels, ("%s=%s"):format(k, v)) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1976 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1977 |
local prefix = " "..t_concat(labels, " ") |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1978 |
render_func(self, print, prefix, metric_family, metric) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1979 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1980 |
else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1981 |
for _, metric in metric_family:iter_metrics() do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1982 |
render_func(self, print, family_name, metric_family, metric) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1983 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1984 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1985 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1986 |
|
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1987 |
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
|
1988 |
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
|
1989 |
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
|
1990 |
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
|
1991 |
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
|
1992 |
print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1993 |
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
|
1994 |
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
|
1995 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1996 |
print(""); |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1997 |
else |
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1998 |
local metric_family = stat_info[2] |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
1999 |
if metric_family.type_ == "counter" then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2000 |
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:
11508
diff
changeset
|
2001 |
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:
11508
diff
changeset
|
2002 |
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:
11508
diff
changeset
|
2003 |
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:
11508
diff
changeset
|
2004 |
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:
11508
diff
changeset
|
2005 |
end |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2006 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2007 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2008 |
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
|
2009 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2010 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2011 |
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
|
2012 |
local function new_stats_context(self) |
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2013 |
-- 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:
11508
diff
changeset
|
2014 |
-- 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:
11508
diff
changeset
|
2015 |
-- 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:
11508
diff
changeset
|
2016 |
-- the next sample and so on. |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2017 |
return setmetatable({ session = self.session, stats = true, now = time.now() }, stats_mt); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2018 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2019 |
|
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2020 |
function def_env.stats:show(name_filter) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2021 |
local statsman = require "core.statsmanager" |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2022 |
local collect = statsman.collect |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2023 |
if collect then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2024 |
-- force collection if in manual mode |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2025 |
collect() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2026 |
end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2027 |
local metric_registry = statsman.get_metric_registry(); |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2028 |
local displayed_stats = new_stats_context(self); |
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2029 |
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:
11508
diff
changeset
|
2030 |
if not name_filter or family_name:match(name_filter) then |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2031 |
table.insert(displayed_stats, { |
11527
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2032 |
family_name, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2033 |
metric_family, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2034 |
output = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11508
diff
changeset
|
2035 |
}) |
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2036 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2037 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2038 |
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
|
2039 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2040 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2041 |
|
12468
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
2042 |
function module.unload() |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
2043 |
stanza_watchers.cleanup(); |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
2044 |
end |
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12403
diff
changeset
|
2045 |
|
10860
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2046 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2047 |
------------- |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2048 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2049 |
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
|
2050 |
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
|
2051 |
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
|
2052 |
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
|
2053 |
____ \ / _ |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2054 |
| _ \ _ __ ___ ___ _-_ __| |_ _ |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2055 |
| |_) | '__/ _ \/ __|/ _ \ / _` | | | | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2056 |
| __/| | | (_) \__ \ |_| | (_| | |_| | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2057 |
|_| |_| \___/|___/\___/ \__,_|\__, | |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2058 |
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
|
2059 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2060 |
]] |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2061 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2062 |
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
|
2063 |
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
|
2064 |
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
|
2065 |
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
|
2066 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2067 |
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
|
2068 |
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
|
2069 |
end |
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2070 |
end |