Mercurial > prosody-hg
annotate plugins/mod_admin_shell.lua @ 14120:0e9e3efa381f 13.0
mod_admin_shell: Fail user creation/modification if new password fails saslprep
This saves us from setting an invalid password and preventing the new account
from authenticating.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 02 Apr 2026 20:53:04 +0100 |
| parents | b9688ac25255 |
| children | 7008869fcce2 d666e7cd8609 |
| rev | line source |
|---|---|
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Prosody IM |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 -- COPYING file in the source package for more information. |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 -- |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 -- luacheck: ignore 212/self |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 module:set_global(); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 module:depends("admin_socket"); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
13 local hostmanager = require "prosody.core.hostmanager"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
14 local modulemanager = require "prosody.core.modulemanager"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
15 local s2smanager = require "prosody.core.s2smanager"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
16 local portmanager = require "prosody.core.portmanager"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
17 local helpers = require "prosody.util.helpers"; |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
18 local it = require "prosody.util.iterators"; |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
19 local server = require "prosody.net.server"; |
|
13350
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
20 local schema = require "prosody.util.jsonschema"; |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
21 local st = require "prosody.util.stanza"; |
|
13732
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
22 local parse_args = require "prosody.util.argparse".parse; |
|
14120
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
23 local saslprep = require "prosody.util.encodings".stringprep.saslprep; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local _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
|
26 |
|
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 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
|
28 |
|
12589
39ae08180c81
compat: Remove handling of Lua 5.1 location of 'unpack' function
Kim Alvefur <zash@zash.se>
parents:
12551
diff
changeset
|
29 local unpack = table.unpack; |
|
13593
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
30 local cache = require "prosody.util.cache"; |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
31 local new_short_id = require "prosody.util.id".short; |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
32 local iterators = require "prosody.util.iterators"; |
|
10856
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 keys, values = iterators.keys, iterators.values; |
|
13013
430333198e4c
mod_admin_shell: Allow matching on host or bare JID in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12993
diff
changeset
|
34 local jid_bare, jid_split, jid_join, jid_resource, jid_compare = import("prosody.util.jid", "bare", "prepped_split", "join", "resource", "compare"); |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
35 local set, array = require "prosody.util.set", require "prosody.util.array"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
36 local cert_verify_identity = require "prosody.util.x509".verify_identity; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
37 local envload = require "prosody.util.envload".envload; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
38 local envloadfile = require "prosody.util.envload".envloadfile; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
39 local has_pposix, pposix = pcall(require, "prosody.util.pposix"); |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
40 local async = require "prosody.util.async"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
41 local serialization = require "prosody.util.serialization"; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 local serialize_config = serialization.new ({ fatal = false, unquoted = true}); |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
43 local time = require "prosody.util.time"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
44 local promise = require "prosody.util.promise"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
45 local logger = require "prosody.util.logger"; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
47 local t_insert = table.insert; |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
48 local t_concat = table.concat; |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
49 |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
50 local format_number = require "prosody.util.human.units".format; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
51 local format_table = require "prosody.util.human.io".table; |
|
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
52 |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
53 local function capitalize(s) |
|
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
54 if not s then return end |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
55 return (s:gsub("^%a", string.upper):gsub("_", " ")); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
56 end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
57 |
|
11931
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
58 local function pre(prefix, str, alt) |
|
12505
604bb5b8362d
mod_admin_shell: Tighten up type checks to fix #1754 (thanks clouded)
Kim Alvefur <zash@zash.se>
parents:
12304
diff
changeset
|
59 if type(str) ~= "string" or str == "" then return alt or ""; end |
|
11931
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
60 return prefix .. str; |
|
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
61 end |
|
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
62 |
|
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
63 local function suf(str, suffix, alt) |
|
12505
604bb5b8362d
mod_admin_shell: Tighten up type checks to fix #1754 (thanks clouded)
Kim Alvefur <zash@zash.se>
parents:
12304
diff
changeset
|
64 if type(str) ~= "string" or str == "" then return alt or ""; end |
|
11931
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
65 return str .. suffix; |
|
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
66 end |
|
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
67 |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
72 local function new_section(section_desc) |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
73 return setmetatable({}, { |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
74 help = { |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
75 desc = section_desc; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
76 commands = {}; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
77 }; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
78 }); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
79 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
80 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
81 local help_topics = {}; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
82 local function help_topic(name) |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
83 return function (desc) |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
84 return function (content) |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
85 help_topics[name] = { |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
86 desc = desc; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
87 content = content; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
88 }; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
89 end; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
90 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
91 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
92 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
93 -- Seed with default sections and their description text |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
94 help_topic "console" "Help regarding the console itself" [[ |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
95 Hey! Welcome to Prosody's admin console. |
|
13769
5cc4a3e0335c
mod_admin_shell: Remove outdated help text (fixes #1898)
Matthew Wild <mwild1@gmail.com>
parents:
13737
diff
changeset
|
96 If you're ever wondering how to get out, simply type 'quit' (ctrl+d should also |
|
5cc4a3e0335c
mod_admin_shell: Remove outdated help text (fixes #1898)
Matthew Wild <mwild1@gmail.com>
parents:
13737
diff
changeset
|
97 work). |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
98 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
99 For those well-versed in Prosody's internals, or taking instruction from those who are, |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
100 you can prefix a command with > to escape the console sandbox, and access everything in |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
101 the running server. Great fun, but be careful not to break anything :) |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
102 ]]; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
103 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
104 local available_columns; --forward declaration so it is reachable from the help |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
105 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
106 help_topic "columns" "Information about customizing session listings" (function (self, print) |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
107 print [[The columns shown by c2s:show() and s2s:show() can be customizied via the]] |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
108 print [['columns' argument as described here.]] |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
109 print [[]] |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
110 print [[Columns can be specified either as "id jid ipv" or as {"id", "jid", "ipv"}.]] |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
111 print [[Available columns are:]] |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
112 local meta_columns = { |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
113 { title = "ID"; width = 5 }; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
114 { title = "Column Title"; width = 12 }; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
115 { title = "Description"; width = 12 }; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
116 }; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
117 -- auto-adjust widths |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
118 for column, spec in pairs(available_columns) do |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
119 meta_columns[1].width = math.max(meta_columns[1].width or 0, #column); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
120 meta_columns[2].width = math.max(meta_columns[2].width or 0, #(spec.title or "")); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
121 meta_columns[3].width = math.max(meta_columns[3].width or 0, #(spec.description or "")); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
122 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
123 local row = format_table(meta_columns, self.session.width) |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
124 print(row()); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
125 for column, spec in iterators.sorted_pairs(available_columns) do |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
126 print(row({ column, spec.title, spec.description })); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
127 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
128 print [[]] |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
129 print [[Most fields on the internal session structures can also be used as columns]] |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
130 -- Also, you can pass a table column specification directly, with mapper callback and all |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
131 end); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
132 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
133 help_topic "roles" "Show information about user roles" [[ |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
134 Roles may grant access or restrict users from certain operations. |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
135 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
136 Built-in roles are: |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
137 prosody:guest - Guest/anonymous user |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
138 prosody:registered - Registered user |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
139 prosody:member - Provisioned user |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
140 prosody:admin - Host administrator |
|
13641
d980c3e03637
mod_admin_shell: Fix column alignment in 'help roles'
Kim Alvefur <zash@zash.se>
parents:
13640
diff
changeset
|
141 prosody:operator - Server administrator |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
142 |
|
13828
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
143 To view roles and policies, see the commands in 'help role'. |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
144 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
145 Roles can be assigned using the user management commands (see 'help user'). |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
146 ]]; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
147 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
148 |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
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 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
|
157 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 console = {}; |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 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
|
162 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 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
|
164 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
|
165 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 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
|
167 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
|
168 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 |
|
12397
ddf02f2a3354
mod_admin_shell: Add session.write() method to write data to client with no \n
Matthew Wild <mwild1@gmail.com>
parents:
12304
diff
changeset
|
170 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:
12304
diff
changeset
|
171 return session.send(st.stanza("repl-output", attr):text(tostring(line))); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 |
|
13593
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
174 local function request_repl_input(session, input_type) |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
175 if input_type ~= "password" then |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
176 return promise.reject("internal error - unsupported input type "..tostring(input_type)); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
177 end |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
178 local pending_inputs = session.pending_inputs; |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
179 if not pending_inputs then |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
180 pending_inputs = cache.new(5, function (input_id, input_promise) --luacheck: ignore 212/input_id |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
181 input_promise.reject(); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
182 end); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
183 session.pending_inputs = pending_inputs; |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
184 end |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
185 |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
186 local input_id = new_short_id(); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
187 local p = promise.new(function (resolve, reject) |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
188 pending_inputs:set(input_id, { resolve = resolve, reject = reject }); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
189 end):finally(function () |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
190 pending_inputs:set(input_id, nil); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
191 end); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
192 session.send(st.stanza("repl-request-input", { type = input_type, id = input_id })); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
193 return p; |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
194 end |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
195 |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
196 module:hook("admin-disconnected", function (event) |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
197 local pending_inputs = event.session.pending_inputs; |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
198 if not pending_inputs then return; end |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
199 for input_promise in pending_inputs:values() do |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
200 input_promise.reject(); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
201 end |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
202 end); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
203 |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
204 module:hook("admin/repl-requested-input", function (event) |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
205 local input_id = event.stanza.attr.id; |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
206 local input_promise = event.origin.pending_inputs:get(input_id); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
207 if not input_promise then |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
208 event.origin.send(st.stanza("repl-result", { type = "error" }):text("Internal error - unexpected input")); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
209 return true; |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
210 end |
|
13796
c8e534b4f2e2
mod_admin_shell, prosodyctl shell: Report command failure when no password entered (fixes #1907)
Matthew Wild <mwild1@gmail.com>
parents:
13770
diff
changeset
|
211 local status = event.stanza.attr.status or "submit"; |
|
c8e534b4f2e2
mod_admin_shell, prosodyctl shell: Report command failure when no password entered (fixes #1907)
Matthew Wild <mwild1@gmail.com>
parents:
13770
diff
changeset
|
212 local text = event.stanza:get_text(); |
|
c8e534b4f2e2
mod_admin_shell, prosodyctl shell: Report command failure when no password entered (fixes #1907)
Matthew Wild <mwild1@gmail.com>
parents:
13770
diff
changeset
|
213 if status == "submit" then |
|
c8e534b4f2e2
mod_admin_shell, prosodyctl shell: Report command failure when no password entered (fixes #1907)
Matthew Wild <mwild1@gmail.com>
parents:
13770
diff
changeset
|
214 input_promise.resolve(text); |
|
c8e534b4f2e2
mod_admin_shell, prosodyctl shell: Report command failure when no password entered (fixes #1907)
Matthew Wild <mwild1@gmail.com>
parents:
13770
diff
changeset
|
215 else |
|
c8e534b4f2e2
mod_admin_shell, prosodyctl shell: Report command failure when no password entered (fixes #1907)
Matthew Wild <mwild1@gmail.com>
parents:
13770
diff
changeset
|
216 input_promise.reject(status == "cancel" and (text ~= "" and text) or "cancelled"); |
|
c8e534b4f2e2
mod_admin_shell, prosodyctl shell: Report command failure when no password entered (fixes #1907)
Matthew Wild <mwild1@gmail.com>
parents:
13770
diff
changeset
|
217 end |
|
13596
85e8cc6870ae
mod_admin_shell: Mark event as handled when requested input is submitted
Matthew Wild <mwild1@gmail.com>
parents:
13594
diff
changeset
|
218 return true; |
|
13593
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
219 end); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
220 |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 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
|
222 local session = { |
|
11950
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
223 send = function (t) |
|
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
224 return send_repl_output(admin_session, t); |
|
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
225 end; |
|
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
226 print = function (...) |
|
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
227 local t = {}; |
|
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
228 for i=1,select("#", ...) do |
|
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
229 t[i] = tostring(select(i, ...)); |
|
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
230 end |
|
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
231 return send_repl_output(admin_session, table.concat(t, "\t")); |
|
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
232 end; |
|
12397
ddf02f2a3354
mod_admin_shell: Add session.write() method to write data to client with no \n
Matthew Wild <mwild1@gmail.com>
parents:
12304
diff
changeset
|
233 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:
12304
diff
changeset
|
234 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:
12304
diff
changeset
|
235 end; |
|
13593
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
236 request_input = function (input_type) |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
237 return request_repl_input(admin_session, input_type); |
|
f57872788424
mod_admin_shell: Add session method to request (password) input from shell client
Matthew Wild <mwild1@gmail.com>
parents:
13591
diff
changeset
|
238 end; |
|
11950
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
239 serialize = tostring; |
|
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
240 disconnect = function () admin_session:close(); end; |
|
12398
478fff93ac37
mod_admin_shell: Add session.is_connected() method
Matthew Wild <mwild1@gmail.com>
parents:
12397
diff
changeset
|
241 is_connected = function () |
|
478fff93ac37
mod_admin_shell: Add session.is_connected() method
Matthew Wild <mwild1@gmail.com>
parents:
12397
diff
changeset
|
242 return not not admin_session.conn; |
|
478fff93ac37
mod_admin_shell: Add session.is_connected() method
Matthew Wild <mwild1@gmail.com>
parents:
12397
diff
changeset
|
243 end |
|
11950
d2a9e95fd27b
mod_admin_shell: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
11949
diff
changeset
|
244 }; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
245 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
|
246 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 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
|
248 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
|
249 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
|
250 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
251 -- 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
|
252 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
|
253 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
|
254 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
|
255 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
256 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
257 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
258 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
|
259 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
260 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
|
261 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
262 |
|
13736
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
263 local function process_cmd_line(session, arg_line) |
|
13732
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
264 local chunk = load("return "..arg_line, "=shell", "t", {}); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
265 local ok, args = pcall(chunk); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
266 if not ok then return nil, args; end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
267 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
268 local section_name, command = args[1], args[2]; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
269 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
270 local section_mt = getmetatable(def_env[section_name]); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
271 local section_help = section_mt and section_mt.help; |
|
13734
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
272 local command_help = section_help and section_help.commands[command]; |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
273 |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
274 if not command_help then |
|
13736
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
275 if commands[section_name] then |
|
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
276 commands[section_name](session, table.concat(args, " ")); |
|
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
277 return; |
|
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
278 end |
|
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
279 if section_help then |
|
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
280 return nil, "Command not found or necessary module not loaded. Try 'help "..section_name.." for a list of available commands."; |
|
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
281 end |
|
13734
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
282 return nil, "Command not found. Is the necessary module loaded?"; |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
283 end |
|
13732
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
284 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
285 local fmt = { "%s"; ":%s("; ")" }; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
286 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
287 if command_help.flags then |
|
13734
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
288 local flags, flags_err, flags_err_extra = parse_args(args, command_help.flags); |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
289 if not flags then |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
290 if flags_err == "missing-value" then |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
291 return nil, "Expected value after "..flags_err_extra; |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
292 elseif flags_err == "param-not-found" then |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
293 return nil, "Unknown parameter: "..flags_err_extra; |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
294 end |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
295 return nil, flags_err; |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
296 end |
|
13732
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
297 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
298 table.remove(flags, 2); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
299 table.remove(flags, 1); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
300 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
301 local n_fixed_args = #command_help.args; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
302 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
303 local arg_str = {}; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
304 for i = 1, n_fixed_args do |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
305 if flags[i] ~= nil then |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
306 table.insert(arg_str, ("%q"):format(flags[i])); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
307 else |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
308 table.insert(arg_str, "nil"); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
309 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
310 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
311 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
312 table.insert(arg_str, "flags"); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
313 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
314 for i = n_fixed_args + 1, #flags do |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
315 if flags[i] ~= nil then |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
316 table.insert(arg_str, ("%q"):format(flags[i])); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
317 else |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
318 table.insert(arg_str, "nil"); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
319 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
320 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
321 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
322 table.insert(fmt, 3, "%s"); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
323 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
324 return "local flags = ...; return "..string.format(table.concat(fmt), section_name, command, table.concat(arg_str, ", ")), flags; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
325 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
326 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
327 for i = 3, #args do |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
328 if args[i]:sub(1, 1) == ":" then |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
329 table.insert(fmt, i, ")%s("); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
330 elseif i > 3 and fmt[i - 1]:match("%%q$") then |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
331 table.insert(fmt, i, ", %q"); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
332 else |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
333 table.insert(fmt, i, "%q"); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
334 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
335 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
336 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
337 return "return "..string.format(table.concat(fmt), table.unpack(args)); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
338 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
339 |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 end |
|
12529
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12506
diff
changeset
|
346 |
|
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12506
diff
changeset
|
347 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:
12506
diff
changeset
|
348 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:
12506
diff
changeset
|
349 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:
12506
diff
changeset
|
350 |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
351 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
|
352 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
|
353 |
|
13770
a28349b8a387
prosodyctl shell: More reliable detection of REPL/interactive mode (fixes #1895)
Matthew Wild <mwild1@gmail.com>
parents:
13769
diff
changeset
|
354 session.repl = event.stanza.attr.repl ~= "0"; |
|
a28349b8a387
prosodyctl shell: More reliable detection of REPL/interactive mode (fixes #1895)
Matthew Wild <mwild1@gmail.com>
parents:
13769
diff
changeset
|
355 |
|
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
356 local result = st.stanza("repl-result"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
357 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
358 if 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
|
359 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
|
360 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
|
361 else |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
362 local command = line:match("^(%w+) ") or line:match("^%w+$") or line:match("%p"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
363 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
|
364 commands[command](session, line); |
|
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
365 event.origin.send(result); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
366 return; |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
367 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
368 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
369 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
370 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
|
371 |
|
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 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
|
373 commands[line:lower()](session, line); |
|
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
374 event.origin.send(result); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
375 return; |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
376 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
377 |
|
11736
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
378 if useglobalenv and not session.globalenv then |
|
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
379 session.globalenv = redirect_output(_G, session); |
|
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
380 end |
|
ddb87df3de30
mod_admin_shell: Keep unrestricted environment for session lifetime
Kim Alvefur <zash@zash.se>
parents:
11607
diff
changeset
|
381 |
|
13591
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
382 local function send_result(taskok, message) |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
383 if not message then |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
384 if type(taskok) ~= "string" and useglobalenv then |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
385 taskok = session.serialize(taskok); |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
386 end |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
387 result:text("Result: "..tostring(taskok)); |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
388 elseif (not taskok) and message then |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
389 result.attr.type = "error"; |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
390 result:text("Error: "..tostring(message)); |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
391 else |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
392 result:text("OK: "..tostring(message)); |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
393 end |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
394 |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
395 event.origin.send(result); |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
396 end |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
397 |
|
13732
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
398 local taskok, message; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
399 local env = (useglobalenv and session.globalenv) or session.env or nil; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
400 local flags; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
401 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
402 local source; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
403 if line:match("^{") then |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
404 -- Input is a serialized array of strings, typically from |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
405 -- a command-line invocation of 'prosodyctl shell something' |
|
13736
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
406 source, flags = process_cmd_line(session, line); |
|
13734
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
407 if not source then |
|
13736
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
408 if flags then -- err |
|
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
409 send_result(false, flags); |
|
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
410 else -- no err, but nothing more to do |
|
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
411 -- This happens if it was a "simple" command |
|
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
412 event.origin.send(result); |
|
42367f7e6e94
mod_admin_shell: Fix simple command execution (e.g. help)
Matthew Wild <mwild1@gmail.com>
parents:
13735
diff
changeset
|
413 end |
|
13734
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
414 return; |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
415 end |
|
13732
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
416 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
417 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
418 local chunkname = "=console"; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
419 -- luacheck: ignore 311/err |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
420 local chunk, err = envload(source or ("return "..line), chunkname, env); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
421 if not chunk then |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
422 if not source then |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
423 chunk, err = envload(line, chunkname, env); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
424 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
425 if not chunk then |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
426 err = err:gsub("^%[string .-%]:%d+: ", ""); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
427 err = err:gsub("^:%d+: ", ""); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
428 err = err:gsub("'<eof>'", "the end of the line"); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
429 result.attr.type = "error"; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
430 result:text("Sorry, I couldn't understand that... "..err); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
431 event.origin.send(result); |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
432 return; |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
433 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
434 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
435 |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
436 taskok, message = chunk(flags); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
437 |
|
11949
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11946
diff
changeset
|
438 if promise.is_promise(taskok) then |
|
13591
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
439 taskok:next(function (resolved_message) |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
440 send_result(true, resolved_message); |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
441 end, function (rejected_message) |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
442 send_result(nil, rejected_message); |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
443 end); |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
444 else |
|
382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
Matthew Wild <mwild1@gmail.com>
parents:
13582
diff
changeset
|
445 send_result(taskok, message); |
|
11949
ae4bc56f18e0
mod_admin_shell: Wait for promises
Kim Alvefur <zash@zash.se>
parents:
11946
diff
changeset
|
446 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
447 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
448 |
|
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10856
diff
changeset
|
449 module:hook("admin/repl-input", function (event) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
450 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
|
451 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
|
452 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
|
453 end |
|
12887
68df46926c26
mod_admin_socket: Return error on unhandled input to prevent apparent freeze
Kim Alvefur <zash@zash.se>
parents:
12788
diff
changeset
|
454 return true; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
455 end); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
456 |
|
13683
4c1f26b4883b
mod_admin_shell: Support for hiding certain commands from default help listing
Matthew Wild <mwild1@gmail.com>
parents:
13681
diff
changeset
|
457 local function describe_command(s, hidden) |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
458 local section, name, args, desc = s:match("^([%w_]+):([%w_]+)%(([^)]*)%) %- (.+)$"); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
459 if not section then |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
460 error("Failed to parse command description: "..s); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
461 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
462 local command_help = getmetatable(def_env[section]).help.commands; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
463 command_help[name] = { |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
464 desc = desc; |
|
13354
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
465 args = array.collect(args:gmatch("[%w_]+")):map(function (arg_name) |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
466 return { name = arg_name }; |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
467 end); |
|
13683
4c1f26b4883b
mod_admin_shell: Support for hiding certain commands from default help listing
Matthew Wild <mwild1@gmail.com>
parents:
13681
diff
changeset
|
468 hidden = hidden; |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
469 }; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
470 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
471 |
|
13684
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
472 local function hidden_command(s) |
|
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
473 return describe_command(s, true); |
|
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
474 end |
|
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
475 |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
476 -- 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
|
477 -- 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
|
478 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
479 -- Help about individual topics is handled by def_env.help |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
480 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
|
481 local print = session.print; |
|
13354
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
482 |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
483 local topic = data:match("^help (%w+)"); |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
484 if topic then |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
485 return def_env.help[topic]({ session = session }); |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
486 end |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
487 |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
488 print [[Commands are divided into multiple sections. For help on a particular section, ]] |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
489 print [[type: help SECTION (for example, 'help c2s'). Sections are: ]] |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
490 print [[]] |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
491 local row = format_table({ { title = "Section", width = 7 }, { title = "Description", width = "100%" } }, session.width) |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
492 print(row()) |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
493 for section_name, section in it.sorted_pairs(def_env) do |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
494 local section_mt = getmetatable(section); |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
495 local section_help = section_mt and section_mt.help; |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
496 print(row { section_name; section_help and section_help.desc or "" }); |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
497 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
498 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
499 print(""); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
500 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
501 print [[In addition to info about commands, the following general topics are available:]] |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
502 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
503 print(""); |
|
13354
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
504 for topic_name, topic_info in it.sorted_pairs(help_topics) do |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
505 print(topic_name .. " - "..topic_info.desc); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
506 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
507 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
508 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
509 -- 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
|
510 -- 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
|
511 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
512 --luacheck: ignore 212/self |
|
13132
5bfcfd12c423
mod_admin_shell: Use new serialize preset to simplify default config
Kim Alvefur <zash@zash.se>
parents:
13128
diff
changeset
|
513 local serialize_defaults = module:get_option("console_prettyprint_settings", { |
|
5bfcfd12c423
mod_admin_shell: Use new serialize preset to simplify default config
Kim Alvefur <zash@zash.se>
parents:
13128
diff
changeset
|
514 preset = "pretty"; |
|
5bfcfd12c423
mod_admin_shell: Use new serialize preset to simplify default config
Kim Alvefur <zash@zash.se>
parents:
13128
diff
changeset
|
515 maxdepth = 2; |
|
5bfcfd12c423
mod_admin_shell: Use new serialize preset to simplify default config
Kim Alvefur <zash@zash.se>
parents:
13128
diff
changeset
|
516 table_iterator = "pairs"; |
|
5bfcfd12c423
mod_admin_shell: Use new serialize preset to simplify default config
Kim Alvefur <zash@zash.se>
parents:
13128
diff
changeset
|
517 }) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
518 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
519 def_env.output = new_section("Configure admin console output"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
520 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
|
521 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
|
522 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
|
523 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
524 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
|
525 -- 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
|
526 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
|
527 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
528 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
|
529 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
|
530 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
|
531 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
532 end |
|
11891
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
533 if opts.table_iterator == "pairs" then |
|
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
534 opts.table_iterator = pairs; |
|
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
535 elseif type(opts.table_iterator) ~= "function" then |
|
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
536 opts.table_iterator = nil; -- rawpairs is the default |
|
6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Kim Alvefur <zash@zash.se>
parents:
11889
diff
changeset
|
537 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
538 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
|
539 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
540 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
541 def_env.help = setmetatable({}, { |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
542 help = { |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
543 desc = "Show this help about available commands"; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
544 commands = {}; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
545 }; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
546 __index = function (_, section_name) |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
547 return function (self) |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
548 local print = self.session.print; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
549 local section_mt = getmetatable(def_env[section_name]); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
550 local section_help = section_mt and section_mt.help; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
551 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
552 local c = 0; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
553 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
554 if section_help then |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
555 print("Help: "..section_name); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
556 if section_help.desc then |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
557 print(section_help.desc); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
558 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
559 print(("-"):rep(#(section_help.desc or section_name))); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
560 print(""); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
561 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
562 if section_help.content then |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
563 print(section_help.content); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
564 print(""); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
565 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
566 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
567 for command, command_help in it.sorted_pairs(section_help.commands or {}) do |
|
13683
4c1f26b4883b
mod_admin_shell: Support for hiding certain commands from default help listing
Matthew Wild <mwild1@gmail.com>
parents:
13681
diff
changeset
|
568 if not command_help.hidden then |
|
4c1f26b4883b
mod_admin_shell: Support for hiding certain commands from default help listing
Matthew Wild <mwild1@gmail.com>
parents:
13681
diff
changeset
|
569 c = c + 1; |
|
4c1f26b4883b
mod_admin_shell: Support for hiding certain commands from default help listing
Matthew Wild <mwild1@gmail.com>
parents:
13681
diff
changeset
|
570 local desc = command_help.desc or command_help.module and ("Provided by mod_"..command_help.module) or ""; |
|
13737
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
571 if self.session.repl then |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
572 local args = array.pluck(command_help.args, "name"):concat(", "); |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
573 print(("%s:%s(%s) - %s"):format(section_name, command, args, desc)); |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
574 else |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
575 local args = array.pluck(command_help.args, "name"):concat("> <"); |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
576 if args ~= "" then |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
577 args = "<"..args..">"; |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
578 end |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
579 print(("%s %s %s"):format(section_name, command, args)); |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
580 print((" %s"):format(desc)); |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
581 if command_help.flags then |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
582 local flags = command_help.flags; |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
583 print(""); |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
584 print((" Flags:")); |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
585 |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
586 if flags.kv_params then |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
587 for name in it.sorted_pairs(flags.kv_params) do |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
588 print(" --"..name:gsub("_", "-")); |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
589 end |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
590 end |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
591 |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
592 if flags.value_params then |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
593 for name in it.sorted_pairs(flags.value_params) do |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
594 print(" --"..name:gsub("_", "-").." <"..name..">"); |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
595 end |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
596 end |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
597 |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
598 if flags.array_params then |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
599 for name in it.sorted_pairs(flags.array_params) do |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
600 print(" --"..name:gsub("_", "-").." <"..name..">, ..."); |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
601 end |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
602 end |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
603 |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
604 end |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
605 print(""); |
|
46e7cc4de5e6
mod_admin_shell: Improve help listing in non-REPL mode
Matthew Wild <mwild1@gmail.com>
parents:
13736
diff
changeset
|
606 end |
|
13683
4c1f26b4883b
mod_admin_shell: Support for hiding certain commands from default help listing
Matthew Wild <mwild1@gmail.com>
parents:
13681
diff
changeset
|
607 end |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
608 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
609 elseif help_topics[section_name] then |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
610 local topic = help_topics[section_name]; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
611 if type(topic.content) == "function" then |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
612 topic.content(self, print); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
613 else |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
614 print(topic.content); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
615 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
616 print(""); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
617 return true, "Showing help topic '"..section_name.."'"; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
618 else |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
619 print("Unknown topic: "..section_name); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
620 end |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
621 print(""); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
622 return true, ("%d command(s) listed"):format(c); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
623 end; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
624 end; |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
625 }); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
626 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
627 def_env.server = new_section("Uptime, version, shutting down, etc."); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
628 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
629 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
|
630 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
|
631 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
|
632 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
|
633 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
|
634 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
635 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
636 describe_command [[server:version() - Show the server's version number]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
637 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
|
638 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
|
639 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
640 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
641 describe_command [[server:uptime() - Show how long the server has been running]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
642 function def_env.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
|
643 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
|
644 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
|
645 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
|
646 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
|
647 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
|
648 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
|
649 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
|
650 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
|
651 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
|
652 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
|
653 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
|
654 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
655 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
656 describe_command [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] |
|
11831
94cd363116a3
mod_admin_shell: Allow passing an exit code to server:shutdown()
Kim Alvefur <zash@zash.se>
parents:
11736
diff
changeset
|
657 function def_env.server:shutdown(reason, code) |
|
94cd363116a3
mod_admin_shell: Allow passing an exit code to server:shutdown()
Kim Alvefur <zash@zash.se>
parents:
11736
diff
changeset
|
658 prosody.shutdown(reason, code); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
659 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
|
660 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
661 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
662 local function human(kb) |
|
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
663 return format_number(kb*1024, "B", "b"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
664 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
665 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
666 describe_command [[server:memory() - Show details about the server's memory usage]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
667 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
|
668 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
|
669 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
|
670 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
671 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
|
672 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
|
673 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
|
674 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
|
675 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
|
676 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
|
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 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
679 def_env.module = new_section("Commands to load/reload/unload modules/plugins"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
680 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
681 local function get_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
|
682 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
|
683 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
|
684 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
|
685 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
|
686 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
|
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 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
|
689 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
|
690 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
|
691 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
|
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 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
694 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
695 -- 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
|
696 -- 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
|
697 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
|
698 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
|
699 / 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
|
700 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
|
701 -- 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
|
702 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
|
703 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
|
704 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
705 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
|
706 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
707 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 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
|
709 -- 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
|
710 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
|
711 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
|
712 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
713 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
|
714 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
715 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 -- 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
|
717 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
|
718 end; |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
719 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
|
720 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
|
721 end |
|
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 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
|
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 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
725 describe_command [[module:info(module, host) - Show information about a loaded module]] |
|
11601
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
726 function def_env.module:info(name, hosts) |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
727 if not name then |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
728 return nil, "module name expected"; |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
729 end |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
730 local print = self.session.print; |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
731 hosts = get_hosts_with_module(hosts, name); |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
732 if hosts:empty() then |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
733 return false, "mod_" .. name .. " does not appear to be loaded on the specified hosts"; |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
734 end |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
735 |
|
11932
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11931
diff
changeset
|
736 local function item_name(item) return item.name; end |
|
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11931
diff
changeset
|
737 |
|
12540
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12538
diff
changeset
|
738 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:
12538
diff
changeset
|
739 if not t then |
|
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12538
diff
changeset
|
740 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:
12538
diff
changeset
|
741 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:
12538
diff
changeset
|
742 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:
12538
diff
changeset
|
743 else |
|
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12538
diff
changeset
|
744 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:
12538
diff
changeset
|
745 end |
|
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12538
diff
changeset
|
746 end |
|
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12538
diff
changeset
|
747 |
|
11606
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
748 local friendly_descriptions = { |
|
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
749 ["adhoc-provider"] = "Ad-hoc commands", |
|
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
750 ["auth-provider"] = "Authentication provider", |
|
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
751 ["http-provider"] = "HTTP services", |
|
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
752 ["net-provider"] = "Network service", |
|
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
753 ["storage-provider"] = "Storage driver", |
|
11931
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
754 ["measure"] = "Legacy metrics", |
|
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
755 ["metric"] = "Metrics", |
|
11991
bef2a59b00d1
mod_admin_shell: List periodic tasks in module:info
Kim Alvefur <zash@zash.se>
parents:
11954
diff
changeset
|
756 ["task"] = "Periodic task", |
|
11606
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
757 }; |
|
11607
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
758 local item_formatters = { |
|
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
759 ["feature"] = tostring, |
|
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
760 ["identity"] = function(ident) return ident.type .. "/" .. ident.category; end, |
|
11932
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11931
diff
changeset
|
761 ["adhoc-provider"] = item_name, |
|
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11931
diff
changeset
|
762 ["auth-provider"] = item_name, |
|
92925f1320e7
mod_admin_shell: Factor out simple function in module:info for reuse
Kim Alvefur <zash@zash.se>
parents:
11931
diff
changeset
|
763 ["storage-provider"] = item_name, |
|
11943
cf47834d3698
mod_admin_shell: Fix showing default HTTP path in module:info
Kim Alvefur <zash@zash.se>
parents:
11932
diff
changeset
|
764 ["http-provider"] = function(item, mod) return mod:http_url(item.name, item.default_path); end, |
|
12538
0f56587bb37f
mod_admin_shell: Drop unused argument [luacheck]
Kim Alvefur <zash@zash.se>
parents:
12537
diff
changeset
|
765 ["net-provider"] = function(item) |
|
12537
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12536
diff
changeset
|
766 local service_name = item.name; |
|
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12536
diff
changeset
|
767 local ports_list = {}; |
|
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12536
diff
changeset
|
768 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:
12536
diff
changeset
|
769 table.insert(ports_list, "["..interface.."]:"..port); |
|
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12536
diff
changeset
|
770 end |
|
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12536
diff
changeset
|
771 if not ports_list[1] then |
|
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12536
diff
changeset
|
772 return service_name..": not listening on any ports"; |
|
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12536
diff
changeset
|
773 end |
|
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12536
diff
changeset
|
774 return service_name..": "..table.concat(ports_list, ", "); |
|
74418f8096b0
mod_admin_shell: Show bound ports in module:info
Kim Alvefur <zash@zash.se>
parents:
12536
diff
changeset
|
775 end, |
|
11931
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
776 ["measure"] = function(item) return item.name .. " (" .. suf(item.conf and item.conf.unit, " ") .. item.type .. ")"; end, |
|
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
777 ["metric"] = function(item) |
|
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
778 return ("%s (%s%s)%s"):format(item.name, suf(item.mf.unit, " "), item.mf.type_, pre(": ", item.mf.description)); |
|
c65d5da8e99a
mod_admin_shell: List collected metrics in module:info
Kim Alvefur <zash@zash.se>
parents:
11930
diff
changeset
|
779 end, |
|
12540
0684506c99d3
mod_admin_shell: Include last (mod_cron) task run time in module:info()
Kim Alvefur <zash@zash.se>
parents:
12538
diff
changeset
|
780 ["task"] = function (item) return string.format("%s (%s, %s)", item.name or item.id, item.when, task_timefmt(item.last)); end |
|
11607
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
781 }; |
|
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
782 |
|
11601
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
783 for host in hosts do |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
784 local mod = modulemanager.get_module(host, name); |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
785 if mod.module.host == "*" then |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
786 print("in global context"); |
|
11604
7466bf65d7c8
mod_admin_shell: module:info: Use existing host string representation
Kim Alvefur <zash@zash.se>
parents:
11603
diff
changeset
|
787 else |
|
7466bf65d7c8
mod_admin_shell: module:info: Use existing host string representation
Kim Alvefur <zash@zash.se>
parents:
11603
diff
changeset
|
788 print("on " .. tostring(prosody.hosts[mod.module.host])); |
|
11601
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
789 end |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
790 print(" path: " .. (mod.module.path or "n/a")); |
|
11602
78ec0741c2bc
mod_admin_shell: module:info: Show module status
Kim Alvefur <zash@zash.se>
parents:
11601
diff
changeset
|
791 if mod.module.status_message then |
|
78ec0741c2bc
mod_admin_shell: module:info: Show module status
Kim Alvefur <zash@zash.se>
parents:
11601
diff
changeset
|
792 print(" status: [" .. mod.module.status_type .. "] " .. mod.module.status_message); |
|
78ec0741c2bc
mod_admin_shell: module:info: Show module status
Kim Alvefur <zash@zash.se>
parents:
11601
diff
changeset
|
793 end |
|
11605
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
794 if mod.module.items and next(mod.module.items) ~= nil then |
|
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
795 print(" provides:"); |
|
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
796 for kind, items in pairs(mod.module.items) do |
|
11606
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
797 local label = friendly_descriptions[kind] or kind:gsub("%-", " "):gsub("^%a", string.upper); |
|
0b65d43f4da4
mod_admin_shell: module:info: Show friendlier name for known 'items'
Kim Alvefur <zash@zash.se>
parents:
11605
diff
changeset
|
798 print(string.format(" - %s (%d item%s)", label, #items, #items > 1 and "s" or "")); |
|
11607
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
799 local formatter = item_formatters[kind]; |
|
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
800 if formatter then |
|
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
801 for _, item in ipairs(items) do |
|
11850
bfa85965106e
mod_admin_shell: Show HTTP base-URLs in module:info()
Kim Alvefur <zash@zash.se>
parents:
11831
diff
changeset
|
802 print(" - " .. formatter(item, mod.module)); |
|
11607
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
803 end |
|
03eb4c0dca27
mod_admin_shell: module:info: List 'items' that can be formatted easily
Kim Alvefur <zash@zash.se>
parents:
11606
diff
changeset
|
804 end |
|
11605
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
805 end |
|
225ef07f2bee
mod_admin_shell: module:info: List provided 'items'
Kim Alvefur <zash@zash.se>
parents:
11604
diff
changeset
|
806 end |
|
11603
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
807 if mod.module.dependencies and next(mod.module.dependencies) ~= nil then |
|
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
808 print(" dependencies:"); |
|
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
809 for dep in pairs(mod.module.dependencies) do |
|
12927
918dfbb330fd
mod_admin_shell: Limit module dependency listings to loaded on current host
Kim Alvefur <zash@zash.se>
parents:
12922
diff
changeset
|
810 -- Dependencies are per module instance, not per host, so dependencies |
|
918dfbb330fd
mod_admin_shell: Limit module dependency listings to loaded on current host
Kim Alvefur <zash@zash.se>
parents:
12922
diff
changeset
|
811 -- of/on global modules may list modules not actually loaded on the |
|
918dfbb330fd
mod_admin_shell: Limit module dependency listings to loaded on current host
Kim Alvefur <zash@zash.se>
parents:
12922
diff
changeset
|
812 -- current host. |
|
918dfbb330fd
mod_admin_shell: Limit module dependency listings to loaded on current host
Kim Alvefur <zash@zash.se>
parents:
12922
diff
changeset
|
813 if modulemanager.is_loaded(host, dep) then |
|
918dfbb330fd
mod_admin_shell: Limit module dependency listings to loaded on current host
Kim Alvefur <zash@zash.se>
parents:
12922
diff
changeset
|
814 print(" - mod_" .. dep); |
|
918dfbb330fd
mod_admin_shell: Limit module dependency listings to loaded on current host
Kim Alvefur <zash@zash.se>
parents:
12922
diff
changeset
|
815 end |
|
11603
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
816 end |
|
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
817 end |
|
12922
aaf055d6fe7a
mod_admin_shell: Show reverse dependencies in module:info()
Kim Alvefur <zash@zash.se>
parents:
12908
diff
changeset
|
818 if mod.module.reverse_dependencies and next(mod.module.reverse_dependencies) ~= nil then |
|
aaf055d6fe7a
mod_admin_shell: Show reverse dependencies in module:info()
Kim Alvefur <zash@zash.se>
parents:
12908
diff
changeset
|
819 print(" reverse dependencies:"); |
|
aaf055d6fe7a
mod_admin_shell: Show reverse dependencies in module:info()
Kim Alvefur <zash@zash.se>
parents:
12908
diff
changeset
|
820 for dep in pairs(mod.module.reverse_dependencies) do |
|
12927
918dfbb330fd
mod_admin_shell: Limit module dependency listings to loaded on current host
Kim Alvefur <zash@zash.se>
parents:
12922
diff
changeset
|
821 if modulemanager.is_loaded(host, dep) then |
|
918dfbb330fd
mod_admin_shell: Limit module dependency listings to loaded on current host
Kim Alvefur <zash@zash.se>
parents:
12922
diff
changeset
|
822 print(" - mod_" .. dep); |
|
918dfbb330fd
mod_admin_shell: Limit module dependency listings to loaded on current host
Kim Alvefur <zash@zash.se>
parents:
12922
diff
changeset
|
823 end |
|
11603
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
824 end |
|
4e24408a3f57
mod_admin_shell: module:info: List dependencies
Kim Alvefur <zash@zash.se>
parents:
11602
diff
changeset
|
825 end |
|
11601
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
826 end |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
827 return true; |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
828 end |
|
9483728f890f
mod_admin_shell: Add basic command that shows more info about loaded modules
Kim Alvefur <zash@zash.se>
parents:
11523
diff
changeset
|
829 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
830 describe_command [[module:load(module, host) - Load the specified module on the specified host (or all hosts if none given)]] |
|
12603
05ca75309fa0
mod_admin_shell: Remove obsolete module:load() argument from 0.8 time
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
831 function def_env.module:load(name, hosts) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
832 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
|
833 |
|
13562
f77c247258cc
mod_admin_shell: Report when a module is already loaded
Kim Alvefur <zash@zash.se>
parents:
13561
diff
changeset
|
834 local already_loaded = set.new(); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
835 -- 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
|
836 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
|
837 for host in hosts do |
|
13128
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
838 local configured_modules, component = modulemanager.get_modules_for_host(host); |
|
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
839 |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
840 if (not modulemanager.is_loaded(host, name)) then |
|
12603
05ca75309fa0
mod_admin_shell: Remove obsolete module:load() argument from 0.8 time
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
841 mod, err = modulemanager.load(host, name); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
842 if 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
|
843 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
|
844 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
|
845 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
|
846 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
|
847 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
848 break; |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
849 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
850 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
|
851 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
852 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
|
853 self.session.print("Loaded for "..mod.module.host); |
|
13128
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
854 |
|
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
855 if not (configured_modules:contains(name) or name == component) then |
|
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
856 self.session.print("Note: Module will not be loaded after restart unless enabled in configuration"); |
|
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
857 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
858 end |
|
13562
f77c247258cc
mod_admin_shell: Report when a module is already loaded
Kim Alvefur <zash@zash.se>
parents:
13561
diff
changeset
|
859 else |
|
f77c247258cc
mod_admin_shell: Report when a module is already loaded
Kim Alvefur <zash@zash.se>
parents:
13561
diff
changeset
|
860 already_loaded:add(host); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
861 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
862 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
863 |
|
13561
d8f7a8a26965
mod_admin_shell: Refactor end of module:load
Kim Alvefur <zash@zash.se>
parents:
13542
diff
changeset
|
864 if not ok then |
|
d8f7a8a26965
mod_admin_shell: Refactor end of module:load
Kim Alvefur <zash@zash.se>
parents:
13542
diff
changeset
|
865 return ok, "Last error: "..tostring(err); |
|
d8f7a8a26965
mod_admin_shell: Refactor end of module:load
Kim Alvefur <zash@zash.se>
parents:
13542
diff
changeset
|
866 end |
|
13562
f77c247258cc
mod_admin_shell: Report when a module is already loaded
Kim Alvefur <zash@zash.se>
parents:
13561
diff
changeset
|
867 if already_loaded == hosts then |
|
f77c247258cc
mod_admin_shell: Report when a module is already loaded
Kim Alvefur <zash@zash.se>
parents:
13561
diff
changeset
|
868 return ok, "Module already loaded"; |
|
f77c247258cc
mod_admin_shell: Report when a module is already loaded
Kim Alvefur <zash@zash.se>
parents:
13561
diff
changeset
|
869 end |
|
13561
d8f7a8a26965
mod_admin_shell: Refactor end of module:load
Kim Alvefur <zash@zash.se>
parents:
13542
diff
changeset
|
870 return ok, "Module loaded onto "..count.." host"..(count ~= 1 and "s" or ""); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
871 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
872 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
873 describe_command [[module:unload(module, host) - The same, but just unloads the module from memory]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
874 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
|
875 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
|
876 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
877 -- 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
|
878 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
|
879 for host in hosts do |
|
13128
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
880 local configured_modules, component = modulemanager.get_modules_for_host(host); |
|
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
881 |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
882 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
|
883 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
|
884 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
|
885 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
|
886 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
|
887 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
888 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
|
889 self.session.print("Unloaded from "..host); |
|
13128
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
890 |
|
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
891 if configured_modules:contains(name) or name == component then |
|
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
892 self.session.print("Note: Module will be loaded after restart unless disabled in configuration"); |
|
38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Kim Alvefur <zash@zash.se>
parents:
13117
diff
changeset
|
893 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
894 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
895 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
896 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
897 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
|
898 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
899 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
900 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
|
901 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
|
902 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
|
903 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
|
904 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
905 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
906 describe_command [[module:reload(module, host) - The same, but unloads and loads the module (saving state if the module supports it)]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
907 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
|
908 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
|
909 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
910 -- 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
|
911 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
|
912 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
|
913 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
|
914 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
|
915 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
|
916 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
|
917 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
|
918 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
919 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
|
920 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
|
921 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
|
922 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
923 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
|
924 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
925 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
926 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
927 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
|
928 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
929 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
930 describe_command [[module:list(host) - List the modules loaded on the specified host]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
931 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
|
932 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
|
933 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
934 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
|
935 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
|
936 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
|
937 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
|
938 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
|
939 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
|
940 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
|
941 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
942 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
|
943 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
944 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
945 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
|
946 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
|
947 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
|
948 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
|
949 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
|
950 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
951 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
|
952 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
953 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
954 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
955 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
956 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
957 def_env.config = new_section("Reloading the configuration, etc."); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
958 |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
959 function def_env.config:load(filename, format) |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
960 local config_load = require "prosody.core.configmanager".load; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
961 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
|
962 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
|
963 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
|
964 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
965 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
|
966 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
967 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
968 describe_command [[config:get([host,] option) - Show the value of a config option.]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
969 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
|
970 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
|
971 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
|
972 end |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
973 local config_get = require "prosody.core.configmanager".get |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
974 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
|
975 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
976 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
977 describe_command [[config:set([host,] option, value) - Update the value of a config option without writing to the config file.]] |
|
13062
da51c36ed1e7
mod_admin_shell: Add config:set([host,] key, value) because why not
Kim Alvefur <zash@zash.se>
parents:
13061
diff
changeset
|
978 function def_env.config:set(host, key, value) |
|
da51c36ed1e7
mod_admin_shell: Add config:set([host,] key, value) because why not
Kim Alvefur <zash@zash.se>
parents:
13061
diff
changeset
|
979 if host ~= "*" and not prosody.hosts[host] then |
|
da51c36ed1e7
mod_admin_shell: Add config:set([host,] key, value) because why not
Kim Alvefur <zash@zash.se>
parents:
13061
diff
changeset
|
980 host, key, value = "*", host, key; |
|
da51c36ed1e7
mod_admin_shell: Add config:set([host,] key, value) because why not
Kim Alvefur <zash@zash.se>
parents:
13061
diff
changeset
|
981 end |
|
da51c36ed1e7
mod_admin_shell: Add config:set([host,] key, value) because why not
Kim Alvefur <zash@zash.se>
parents:
13061
diff
changeset
|
982 return require "prosody.core.configmanager".set(host, key, value); |
|
da51c36ed1e7
mod_admin_shell: Add config:set([host,] key, value) because why not
Kim Alvefur <zash@zash.se>
parents:
13061
diff
changeset
|
983 end |
|
da51c36ed1e7
mod_admin_shell: Add config:set([host,] key, value) because why not
Kim Alvefur <zash@zash.se>
parents:
13061
diff
changeset
|
984 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
985 describe_command [[config:reload() - Reload the server configuration. Modules may need to be reloaded for changes to take effect.]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
986 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
|
987 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
|
988 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
|
989 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
990 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
991 def_env.c2s = new_section("Commands to manage local client-to-server sessions"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
992 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
993 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
|
994 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
|
995 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
|
996 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
997 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
998 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
|
999 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
|
1000 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
|
1001 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
|
1002 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
|
1003 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
|
1004 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1005 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1006 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
|
1007 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
|
1008 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
|
1009 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
|
1010 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
|
1011 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
|
1012 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1013 |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1014 local function _sort_by_jid(a, b) |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1015 if a.host == b.host then |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1016 if a.username == b.username then return (a.resource or "") > (b.resource or ""); end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1017 return (a.username or "") > (b.username or ""); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1018 end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1019 return _sort_hosts(a.host or "", b.host or ""); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1020 end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1021 |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1022 local function show_c2s(callback) |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1023 get_c2s():sort(_sort_by_jid):map(function (session) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1024 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
|
1025 end); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1026 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1027 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1028 describe_command [[c2s:count() - Count sessions without listing them]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1029 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
|
1030 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
|
1031 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
|
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 |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1034 local function get_s2s_hosts(session) --> local,remote |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1035 if session.direction == "outgoing" then |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1036 return session.host or session.from_host, session.to_host; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1037 elseif session.direction == "incoming" then |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1038 return session.host or session.to_host, session.from_host; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1039 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1040 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1041 |
|
12224
2b348d65cd69
mod_admin_shell: Add help section about customizing table columns
Kim Alvefur <zash@zash.se>
parents:
12209
diff
changeset
|
1042 available_columns = { |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1043 jid = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1044 title = "JID"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1045 description = "Full JID of user session"; |
|
13037
635ed9a362ee
mod_admin_shell: Dynamically size JIDs and hosts
Kim Alvefur <zash@zash.se>
parents:
13036
diff
changeset
|
1046 width = "3p"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1047 key = "full_jid"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1048 mapper = function(full_jid, session) return full_jid or get_jid(session) end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1049 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1050 host = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1051 title = "Host"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1052 description = "Local hostname"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1053 key = "host"; |
|
13037
635ed9a362ee
mod_admin_shell: Dynamically size JIDs and hosts
Kim Alvefur <zash@zash.se>
parents:
13036
diff
changeset
|
1054 width = "1p"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1055 mapper = function(host, session) |
|
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
1056 return host or get_s2s_hosts(session) or "?"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1057 end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1058 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1059 remote = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1060 title = "Remote"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1061 description = "Remote hostname"; |
|
13037
635ed9a362ee
mod_admin_shell: Dynamically size JIDs and hosts
Kim Alvefur <zash@zash.se>
parents:
13036
diff
changeset
|
1062 width = "1p"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1063 mapper = function(_, session) |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1064 return select(2, get_s2s_hosts(session)); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1065 end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1066 }; |
|
12023
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12019
diff
changeset
|
1067 port = { |
|
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12019
diff
changeset
|
1068 title = "Port"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1069 description = "Server port used"; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1070 width = #string.format("%d", 0xffff); -- max 16 bit unsigned integer |
|
12023
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12019
diff
changeset
|
1071 align = "right"; |
|
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12019
diff
changeset
|
1072 key = "conn"; |
|
12787
3735ad8d6f8e
mod_admin_shell: Ensure connection exists to get port from (fixes #1777)
Kim Alvefur <zash@zash.se>
parents:
12637
diff
changeset
|
1073 mapper = function(conn) |
|
3735ad8d6f8e
mod_admin_shell: Ensure connection exists to get port from (fixes #1777)
Kim Alvefur <zash@zash.se>
parents:
12637
diff
changeset
|
1074 if conn then |
|
3735ad8d6f8e
mod_admin_shell: Ensure connection exists to get port from (fixes #1777)
Kim Alvefur <zash@zash.se>
parents:
12637
diff
changeset
|
1075 return conn:serverport(); |
|
3735ad8d6f8e
mod_admin_shell: Ensure connection exists to get port from (fixes #1777)
Kim Alvefur <zash@zash.se>
parents:
12637
diff
changeset
|
1076 end |
|
3735ad8d6f8e
mod_admin_shell: Ensure connection exists to get port from (fixes #1777)
Kim Alvefur <zash@zash.se>
parents:
12637
diff
changeset
|
1077 end; |
|
12023
5a3781a12285
mod_admin_shell: Add port as a c2s/s2s:show column definition
Kim Alvefur <zash@zash.se>
parents:
12019
diff
changeset
|
1078 }; |
|
13473
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1079 created = { |
|
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1080 title = "Connection Created"; |
|
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1081 description = "Time when connection was created"; |
|
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1082 width = #"YYYY MM DD HH:MM:SS"; |
|
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1083 align = "right"; |
|
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1084 key = "conn"; |
|
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1085 mapper = function(conn) |
|
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1086 if conn then |
|
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1087 return os.date("%F %T", math.floor(conn.created)); |
|
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1088 end |
|
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1089 end; |
|
9eb081616842
mod_admin_shell: Add connection created time
aidan@jmad.org
parents:
13354
diff
changeset
|
1090 }; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1091 dir = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1092 title = "Dir"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1093 description = "Direction of server-to-server connection"; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1094 width = #"<->"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1095 key = "direction"; |
|
11888
050c515fe9aa
mod_admin_shell: Indicate bi-directional s2s connections
Kim Alvefur <zash@zash.se>
parents:
11887
diff
changeset
|
1096 mapper = function(dir, session) |
|
050c515fe9aa
mod_admin_shell: Indicate bi-directional s2s connections
Kim Alvefur <zash@zash.se>
parents:
11887
diff
changeset
|
1097 if session.incoming and session.outgoing then return "<->"; end |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1098 if dir == "outgoing" then return "-->"; end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1099 if dir == "incoming" then return "<--"; end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1100 end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1101 }; |
|
13036
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1102 id = { |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1103 title = "Session ID"; |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1104 description = "Internal session ID used in logging"; |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1105 -- Depends on log16(?) of pointers which may vary over runtime, so + some margin |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1106 width = math.max(#"c2s", #"s2sin", #"s2sout") + #(tostring({}):match("%x+$")) + 2; |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1107 key = "id"; |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1108 }; |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1109 type = { |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1110 title = "Type"; |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1111 description = "Session type"; |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1112 width = math.max(#"c2s_unauthed", #"s2sout_unauthed"); |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1113 key = "type"; |
|
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1114 }; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1115 method = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1116 title = "Method"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1117 description = "Connection method"; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1118 width = math.max(#"BOSH", #"WebSocket", #"TCP"); |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1119 mapper = function(_, session) |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1120 if session.bosh_version then |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1121 return "BOSH"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1122 elseif session.websocket_request then |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1123 return "WebSocket"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1124 else |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1125 return "TCP"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1126 end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1127 end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1128 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1129 ipv = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1130 title = "IPv"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1131 description = "Internet Protocol version (4 or 6)"; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1132 width = #"IPvX"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1133 key = "ip"; |
|
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
1134 mapper = function(ip) if ip then return ip:find(":") and "IPv6" or "IPv4"; end end; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1135 }; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1136 ip = { |
|
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1137 title = "IP address"; |
|
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1138 description = "IP address the session connected from"; |
|
13043
d4f7118d1531
mod_admin_shell: Make IP column thinner if IPv6 is disabled
Kim Alvefur <zash@zash.se>
parents:
13042
diff
changeset
|
1139 width = module:get_option_boolean("use_ipv6", true) and #"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" or #"198.051.100.255"; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1140 key = "ip"; |
|
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1141 }; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1142 status = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1143 title = "Status"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1144 description = "Presence status"; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1145 width = math.max(#"online", #"chat"); |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1146 key = "presence"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1147 mapper = function(p) |
|
11946
c0a01e5f5656
mod_admin_shell: Reduce width of 'Status' column
Kim Alvefur <zash@zash.se>
parents:
11945
diff
changeset
|
1148 if not p then return ""; end |
|
c0a01e5f5656
mod_admin_shell: Reduce width of 'Status' column
Kim Alvefur <zash@zash.se>
parents:
11945
diff
changeset
|
1149 return p:get_child_text("show") or "online"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1150 end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1151 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1152 secure = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1153 title = "Security"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1154 description = "TLS version or security status"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1155 key = "conn"; |
|
13041
61b00bd20074
mod_admin_shell: Fix attempt to compare number with string
Kim Alvefur <zash@zash.se>
parents:
13037
diff
changeset
|
1156 width = math.max(#"secure", #"TLSvX.Y"); |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1157 mapper = function(conn, session) |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1158 if not session.secure then return "insecure"; end |
|
11905
bbfa707a4756
mod_admin_shell: Handle absence of connection in security column (thanks arcseconds)
Kim Alvefur <zash@zash.se>
parents:
11892
diff
changeset
|
1159 if not conn or not conn:ssl() then return "secure" end |
|
12480
7e9ebdc75ce4
net: isolate LuaSec-specifics
Jonas Schäfer <jonas@wielicki.name>
parents:
12464
diff
changeset
|
1160 local tls_info = conn.ssl_info and conn:ssl_info(); |
|
11945
142b9c4010fe
mod_admin_shell: Reduce width of 'Security' column (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
11943
diff
changeset
|
1161 return tls_info and tls_info.protocol or "secure"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1162 end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1163 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1164 encryption = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1165 title = "Encryption"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1166 description = "Encryption algorithm used (TLS cipher suite)"; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1167 -- openssl ciphers 'ALL:COMPLEMENTOFALL' | tr : \\n | awk 'BEGIN {n=1} length() > n {n=length()} END {print(n)}' |
|
13036
1612c7f7dd55
mod_admin_shell: More dynamic widths calculations
Kim Alvefur <zash@zash.se>
parents:
13035
diff
changeset
|
1168 width = #"ECDHE-ECDSA-CHACHA20-POLY1305"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1169 key = "conn"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1170 mapper = function(conn) |
|
12480
7e9ebdc75ce4
net: isolate LuaSec-specifics
Jonas Schäfer <jonas@wielicki.name>
parents:
12464
diff
changeset
|
1171 local info = conn and conn.ssl_info and conn:ssl_info(); |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1172 if info then return info.cipher end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1173 end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1174 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1175 cert = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1176 title = "Certificate"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1177 description = "Validation status of certificate"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1178 key = "cert_identity_status"; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1179 width = math.max(#"Expired", #"Self-signed", #"Untrusted", #"Mismatched", #"Unknown"); |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1180 mapper = function(cert_status, session) |
|
13089
41598b7ec543
mod_admin_shell: Refactor 'cert' column
Kim Alvefur <zash@zash.se>
parents:
13079
diff
changeset
|
1181 if cert_status == "invalid" then |
|
41598b7ec543
mod_admin_shell: Refactor 'cert' column
Kim Alvefur <zash@zash.se>
parents:
13079
diff
changeset
|
1182 -- non-nil cert_identity_status implies valid chain, which covers just |
|
41598b7ec543
mod_admin_shell: Refactor 'cert' column
Kim Alvefur <zash@zash.se>
parents:
13079
diff
changeset
|
1183 -- about every error condition except mismatched certificate names |
|
41598b7ec543
mod_admin_shell: Refactor 'cert' column
Kim Alvefur <zash@zash.se>
parents:
13079
diff
changeset
|
1184 return "Mismatched"; |
|
41598b7ec543
mod_admin_shell: Refactor 'cert' column
Kim Alvefur <zash@zash.se>
parents:
13079
diff
changeset
|
1185 elseif cert_status then |
|
41598b7ec543
mod_admin_shell: Refactor 'cert' column
Kim Alvefur <zash@zash.se>
parents:
13079
diff
changeset
|
1186 -- basically only "valid" |
|
41598b7ec543
mod_admin_shell: Refactor 'cert' column
Kim Alvefur <zash@zash.se>
parents:
13079
diff
changeset
|
1187 return capitalize(cert_status); |
|
41598b7ec543
mod_admin_shell: Refactor 'cert' column
Kim Alvefur <zash@zash.se>
parents:
13079
diff
changeset
|
1188 end |
|
41598b7ec543
mod_admin_shell: Refactor 'cert' column
Kim Alvefur <zash@zash.se>
parents:
13079
diff
changeset
|
1189 -- no certificate status, |
|
13517
4bf889e94831
mod_admin_shell: Prevent traceback due to type error
Kim Alvefur <zash@zash.se>
parents:
13489
diff
changeset
|
1190 if type(session.cert_chain_errors) == "table" then |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1191 local cert_errors = set.new(session.cert_chain_errors[1]); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1192 if cert_errors:contains("certificate has expired") then |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1193 return "Expired"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1194 elseif cert_errors:contains("self signed certificate") then |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1195 return "Self-signed"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1196 end |
|
13089
41598b7ec543
mod_admin_shell: Refactor 'cert' column
Kim Alvefur <zash@zash.se>
parents:
13079
diff
changeset
|
1197 -- Some other cert issue, or something up the chain |
|
41598b7ec543
mod_admin_shell: Refactor 'cert' column
Kim Alvefur <zash@zash.se>
parents:
13079
diff
changeset
|
1198 -- TODO borrow more logic from mod_s2s/friendly_cert_error() |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1199 return "Untrusted"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1200 end |
|
13517
4bf889e94831
mod_admin_shell: Prevent traceback due to type error
Kim Alvefur <zash@zash.se>
parents:
13489
diff
changeset
|
1201 -- TODO cert_chain_errors can be a string, handle that |
|
12293
145cb8305c67
mod_admin_shell: Squeeze some characters out of the Certificate column
Kim Alvefur <zash@zash.se>
parents:
12291
diff
changeset
|
1202 return "Unknown"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1203 end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1204 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1205 sni = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1206 title = "SNI"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1207 description = "Hostname requested in TLS"; |
|
13037
635ed9a362ee
mod_admin_shell: Dynamically size JIDs and hosts
Kim Alvefur <zash@zash.se>
parents:
13036
diff
changeset
|
1208 width = "1p"; -- same as host, remote etc |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1209 mapper = function(_, session) |
|
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
1210 if not session.conn then return end |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1211 local sock = session.conn:socket(); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1212 return sock and sock.getsniname and sock:getsniname() or ""; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1213 end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1214 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1215 alpn = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1216 title = "ALPN"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1217 description = "Protocol requested in TLS"; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1218 width = math.max(#"http/1.1", #"xmpp-client", #"xmpp-server"); |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1219 mapper = function(_, session) |
|
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
1220 if not session.conn then return end |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1221 local sock = session.conn:socket(); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1222 return sock and sock.getalpn and sock:getalpn() or ""; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1223 end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1224 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1225 smacks = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1226 title = "SM"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1227 description = "Stream Management (XEP-0198) status"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1228 key = "smacks"; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1229 -- FIXME shorter synonym for hibernating |
|
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1230 width = math.max(#"yes", #"no", #"hibernating"); |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1231 mapper = function(smacks_xmlns, session) |
|
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
1232 if not smacks_xmlns then return "no"; end |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1233 if session.hibernating then return "hibernating"; end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1234 return "yes"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1235 end; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1236 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1237 smacks_queue = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1238 title = "SM Queue"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1239 description = "Length of Stream Management stanza queue"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1240 key = "outgoing_stanza_queue"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1241 width = 8; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1242 align = "right"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1243 mapper = function (queue) |
|
12056
e62025f949f9
mod_smacks: Limit queue memory consumption using new util
Kim Alvefur <zash@zash.se>
parents:
12023
diff
changeset
|
1244 return queue and tostring(queue:count_unacked()); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1245 end |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1246 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1247 csi = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1248 title = "CSI State"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1249 description = "Client State Indication (XEP-0352)"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1250 key = "state"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1251 -- TODO include counter |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1252 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1253 s2s_sasl = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1254 title = "SASL"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1255 description = "Server authentication status"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1256 key = "external_auth"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1257 width = 10; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1258 mapper = capitalize |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1259 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1260 dialback = { |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1261 title = "Dialback"; |
|
12229
30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Kim Alvefur <zash@zash.se>
parents:
12228
diff
changeset
|
1262 description = "Legacy server verification"; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1263 key = "dialback_key"; |
|
13035
93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Kim Alvefur <zash@zash.se>
parents:
13034
diff
changeset
|
1264 width = math.max(#"Not used", #"Not initiated", #"Initiated", #"Completed"); |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1265 mapper = function (dialback_key, session) |
|
11892
e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Kim Alvefur <zash@zash.se>
parents:
11891
diff
changeset
|
1266 if not dialback_key then |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1267 if session.type == "s2sin" or session.type == "s2sout" then |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1268 return "Not used"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1269 end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1270 return "Not initiated"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1271 elseif session.type == "s2sin_unauthed" or session.type == "s2sout_unauthed" then |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1272 return "Initiated"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1273 else |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1274 return "Completed"; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1275 end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1276 end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1277 }; |
|
12660
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12638
diff
changeset
|
1278 role = { |
|
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12638
diff
changeset
|
1279 title = "Role"; |
|
13034
1387888a5596
mod_admin_shell: Strip 'prosody:' prefix to allow narrower Role column
Kim Alvefur <zash@zash.se>
parents:
13013
diff
changeset
|
1280 description = "Session role with 'prosody:' prefix removed"; |
|
13287
1e2d65403867
mod_admin_shell: Make 'Role' column dynamically sized
Kim Alvefur <zash@zash.se>
parents:
13170
diff
changeset
|
1281 width = "1p"; |
|
12660
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12638
diff
changeset
|
1282 key = "role"; |
|
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12638
diff
changeset
|
1283 mapper = function(role) |
|
13034
1387888a5596
mod_admin_shell: Strip 'prosody:' prefix to allow narrower Role column
Kim Alvefur <zash@zash.se>
parents:
13013
diff
changeset
|
1284 local name = role and role.name; |
|
1387888a5596
mod_admin_shell: Strip 'prosody:' prefix to allow narrower Role column
Kim Alvefur <zash@zash.se>
parents:
13013
diff
changeset
|
1285 return name and name:match"^prosody:(%w+)" or name; |
|
12660
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12638
diff
changeset
|
1286 end; |
|
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12638
diff
changeset
|
1287 } |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1288 }; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1289 |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1290 local function get_colspec(colspec, default) |
|
11887
b043e1bb8e8e
mod_admin_shell: Allow passing columns as a string for convenience
Kim Alvefur <zash@zash.se>
parents:
11886
diff
changeset
|
1291 if type(colspec) == "string" then colspec = array(colspec:gmatch("%S+")); end |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1292 local columns = {}; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1293 for i, col in pairs(colspec or default) do |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1294 if type(col) == "string" then |
|
13042
0f05804e974d
mod_admin_shell: Make default column width 1 part
Kim Alvefur <zash@zash.se>
parents:
13041
diff
changeset
|
1295 columns[i] = available_columns[col] or { title = capitalize(col); width = "1p"; key = col }; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1296 elseif type(col) ~= "table" then |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1297 return false, ("argument %d: expected string|table but got %s"):format(i, type(col)); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1298 else |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1299 columns[i] = col; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1300 end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1301 end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1302 |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1303 return columns; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1304 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1305 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1306 describe_command [[c2s:show(jid, columns) - Show all client sessions with the specified JID (or all if no JID given)]] |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1307 function def_env.c2s:show(match_jid, colspec) |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1308 local print = self.session.print; |
|
12660
e8f57970ced5
mod_admin_shell: Show session role in c2s:show
Kim Alvefur <zash@zash.se>
parents:
12638
diff
changeset
|
1309 local columns = get_colspec(colspec, { "id"; "jid"; "role"; "ipv"; "status"; "secure"; "smacks"; "csi" }); |
|
12529
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12506
diff
changeset
|
1310 local row = format_table(columns, self.session.width); |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1311 |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1312 local function match(session) |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1313 local jid = get_jid(session) |
|
13053
8128c4f1b08b
mod_admin_shell: Allow "*" as substitute for 'nil' for easier CLI usage
Kim Alvefur <zash@zash.se>
parents:
13043
diff
changeset
|
1314 return (not match_jid) or match_jid == "*" or jid_compare(jid, match_jid); |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1315 end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1316 |
|
11886
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1317 local group_by_host = true; |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1318 for _, col in ipairs(columns) do |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1319 if col.key == "full_jid" or col.key == "host" then |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1320 group_by_host = false; |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1321 break |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1322 end |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1323 end |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1324 |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1325 if not group_by_host then print(row()); end |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1326 local currenthost = nil; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1327 |
|
11917
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1328 local c2s_sessions = get_c2s(); |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1329 local total_count = #c2s_sessions; |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1330 c2s_sessions:filter(match):sort(_sort_by_jid); |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1331 local shown_count = #c2s_sessions; |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1332 for _, session in ipairs(c2s_sessions) do |
|
11886
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1333 if group_by_host and session.host ~= currenthost then |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1334 currenthost = session.host; |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1335 print("#",prosody.hosts[currenthost] or "Unknown host"); |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1336 print(row()); |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1337 end |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1338 |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1339 print(row(session)); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1340 end |
|
11917
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1341 if total_count ~= shown_count then |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1342 return true, ("%d out of %d c2s sessions shown"):format(shown_count, total_count); |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1343 end |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1344 return true, ("%d c2s sessions shown"):format(total_count); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1345 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1346 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1347 describe_command [[c2s:show_tls(jid) - Show TLS cipher info for encrypted sessions]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1348 function def_env.c2s:show_tls(match_jid) |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1349 return self:show(match_jid, { "jid"; "id"; "secure"; "encryption" }); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
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 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1352 local 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
|
1353 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
|
1354 return { |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1355 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
|
1356 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
|
1357 }; |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1358 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1359 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1360 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1361 describe_command [[c2s:close(jid) - Close all sessions for the specified JID]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1362 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
|
1363 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
|
1364 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
|
1365 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
|
1366 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
|
1367 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
|
1368 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1369 end); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1370 return 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
|
1371 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1372 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1373 describe_command [[c2s:closeall() - Close all active c2s connections ]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1374 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
|
1375 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
|
1376 --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
|
1377 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
|
1378 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
|
1379 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
|
1380 end); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1381 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
|
1382 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1383 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1384 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1385 def_env.s2s = new_section("Commands to manage sessions between this server and others"); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1386 |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1387 local function _sort_s2s(a, b) |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1388 local a_local, a_remote = get_s2s_hosts(a); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1389 local b_local, b_remote = get_s2s_hosts(b); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1390 if (a_local or "") == (b_local or "") then return _sort_hosts(a_remote or "", b_remote or ""); end |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1391 return _sort_hosts(a_local or "", b_local or ""); |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1392 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1393 |
|
13071
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1394 local function match_wildcard(match_jid, jid) |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1395 -- host == host or (host) == *.(host) or sub(.host) == *(.host) |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1396 return jid == match_jid or jid == match_jid:sub(3) or jid:sub(-#match_jid + 1) == match_jid:sub(2); |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1397 end |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1398 |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1399 local function match_s2s_jid(session, match_jid) |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1400 local host, remote = get_s2s_hosts(session); |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1401 if not match_jid or match_jid == "*" then |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1402 return true; |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1403 elseif host == match_jid or remote == match_jid then |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1404 return true; |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1405 elseif match_jid:sub(1, 2) == "*." then |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1406 return match_wildcard(match_jid, host) or match_wildcard(match_jid, remote); |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1407 end |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1408 return false; |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1409 end |
|
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1410 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1411 describe_command [[s2s:show(domain, columns) - Show all s2s connections for the given domain (or all if no domain given)]] |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1412 function def_env.s2s:show(match_jid, colspec) |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1413 local print = self.session.print; |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1414 local columns = get_colspec(colspec, { "id"; "host"; "dir"; "remote"; "ipv"; "secure"; "s2s_sasl"; "dialback" }); |
|
12529
7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
Kim Alvefur <zash@zash.se>
parents:
12506
diff
changeset
|
1415 local row = format_table(columns, self.session.width); |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1416 |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1417 local function match(session) |
|
13071
b5a419ac0f84
mod_admin_shell: Factor apart wildcard matching into function for reuse
Kim Alvefur <zash@zash.se>
parents:
13062
diff
changeset
|
1418 return match_s2s_jid(session, match_jid); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1419 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1420 |
|
11886
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1421 local group_by_host = true; |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1422 local currenthost = nil; |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1423 for _, col in ipairs(columns) do |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1424 if col.key == "host" then |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1425 group_by_host = false; |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1426 break |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1427 end |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1428 end |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1429 |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1430 if not group_by_host then print(row()); end |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1431 |
|
11917
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1432 local s2s_sessions = array(iterators.values(module:shared"/*/s2s/sessions")); |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1433 local total_count = #s2s_sessions; |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1434 s2s_sessions:filter(match):sort(_sort_s2s); |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1435 local shown_count = #s2s_sessions; |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1436 |
|
11886
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1437 for _, session in ipairs(s2s_sessions) do |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1438 if group_by_host and currenthost ~= get_s2s_hosts(session) then |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1439 currenthost = get_s2s_hosts(session); |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1440 print("#",prosody.hosts[currenthost] or "Unknown host"); |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1441 print(row()); |
|
b0b258e092da
mod_admin_shell: Optionally group session listings by host when not included as column
Kim Alvefur <zash@zash.se>
parents:
11885
diff
changeset
|
1442 end |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1443 |
|
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1444 print(row(session)); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1445 end |
|
11917
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1446 if total_count ~= shown_count then |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1447 return true, ("%d out of %d s2s connections shown"):format(shown_count, total_count); |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1448 end |
|
d27b74b25105
mod_admin_shell: Return counts of shown vs total from new table views
Kim Alvefur <zash@zash.se>
parents:
11905
diff
changeset
|
1449 return true, ("%d s2s connections shown"):format(total_count); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1450 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1451 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1452 describe_command [[s2s:show_tls(domain) - Show TLS cipher info for encrypted sessions]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1453 function def_env.s2s:show_tls(match_jid) |
|
11885
197642f9972f
mod_admin_shell: New table based implementation of c2s and s2s:show()
Kim Alvefur <zash@zash.se>
parents:
11850
diff
changeset
|
1454 return self:show(match_jid, { "id"; "host"; "dir"; "remote"; "secure"; "encryption"; "cert" }); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1455 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1456 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1457 local 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
|
1458 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
|
1459 print( |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1460 (" %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
|
1461 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
|
1462 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
|
1463 ) |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1464 ); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1465 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1466 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1467 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1468 -- 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
|
1469 -- 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
|
1470 -- 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
|
1471 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
|
1472 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
|
1473 print( |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1474 (" %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
|
1475 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
|
1476 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
|
1477 ) |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1478 ); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1479 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1480 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1481 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1482 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
|
1483 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
|
1484 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
|
1485 local domain_sessions = set.new(array.collect(values(s2s_sessions))) |
|
13072
7fcf41b541e0
mod_admin_shell: Use same wildcard matching in other s2s command
Kim Alvefur <zash@zash.se>
parents:
13071
diff
changeset
|
1486 /function(session) return match_s2s_jid(session, domain) and session or nil; end; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1487 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
|
1488 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
|
1489 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
|
1490 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
|
1491 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
|
1492 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
|
1493 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
|
1494 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1495 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1496 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
|
1497 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
|
1498 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
|
1499 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
|
1500 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
|
1501 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
|
1502 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
|
1503 { |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1504 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
|
1505 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
|
1506 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
|
1507 }; |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1508 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
|
1509 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
|
1510 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
|
1511 }; |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1512 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1513 table.insert(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
|
1514 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
|
1515 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
|
1516 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
|
1517 }); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1518 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1519 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1520 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1521 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1522 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
|
1523 -- 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
|
1524 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
|
1525 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1526 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
|
1527 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
|
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 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1530 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
|
1531 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
|
1532 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1533 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
|
1534 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
|
1535 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1536 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1537 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
|
1538 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
|
1539 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
|
1540 print("---") |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1541 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
|
1542 print(""); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1543 local 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
|
1544 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
|
1545 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
|
1546 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
|
1547 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
|
1548 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1549 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
|
1550 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1551 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1552 print(""); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1553 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
|
1554 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
|
1555 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
|
1556 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
|
1557 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1558 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
|
1559 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
|
1560 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1561 print(""); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1562 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
|
1563 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
|
1564 print(""); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1565 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
|
1566 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
|
1567 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
|
1568 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1569 print("---"); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1570 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
|
1571 ..(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
|
1572 .." 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
|
1573 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1574 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1575 describe_command [[s2s:close(from, to) - Close a connection from one domain to another]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1576 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
|
1577 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
|
1578 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
|
1579 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1580 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
|
1581 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
|
1582 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
|
1583 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
|
1584 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
|
1585 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
|
1586 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
|
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 for _, session in pairs(s2s_sessions) do |
|
13072
7fcf41b541e0
mod_admin_shell: Use same wildcard matching in other s2s command
Kim Alvefur <zash@zash.se>
parents:
13071
diff
changeset
|
1590 local id = session.id or (session.type .. tostring(session):match("[a-f0-9]+$")); |
|
13869
f44f2a8a8c37
mod_admin_shell: Fix matching logic in s2s:close (Thanks Menel)
Kim Alvefur <zash@zash.se>
parents:
13828
diff
changeset
|
1591 if (match_id and match_id == id) or ((from and match_wildcard(from, session.from_host)) and (to and match_wildcard(to, session.to_host))) then |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1592 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
|
1593 (session.close or s2smanager.destroy_session)(session, build_reason(text, condition)); |
|
13072
7fcf41b541e0
mod_admin_shell: Use same wildcard matching in other s2s command
Kim Alvefur <zash@zash.se>
parents:
13071
diff
changeset
|
1594 count = count + 1; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1595 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1596 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1597 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
|
1598 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1599 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1600 describe_command [[s2s:closeall(host) - Close all the incoming/outgoing s2s sessions to specified host]] |
|
10856
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.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
|
1602 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
|
1603 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
|
1604 for _,session in pairs(s2s_sessions) do |
|
13072
7fcf41b541e0
mod_admin_shell: Use same wildcard matching in other s2s command
Kim Alvefur <zash@zash.se>
parents:
13071
diff
changeset
|
1605 if not host or host == "*" or match_s2s_jid(session, host) then |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1606 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
|
1607 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
|
1608 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1609 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1610 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
|
1611 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
|
1612 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1613 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1614 def_env.host = new_section("Commands to activate, deactivate and list virtual hosts"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1615 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1616 describe_command [[host:activate(hostname) - Activates the specified host]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1617 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
|
1618 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
|
1619 end |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1620 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1621 describe_command [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1622 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
|
1623 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
|
1624 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1625 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1626 describe_command [[host:list() - List the currently-activated hosts]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1627 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
|
1628 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
|
1629 local i = 0; |
|
12676
3ab3ef9584e3
mod_admin_shell: Rename variable to avoid confusion with global function
Kim Alvefur <zash@zash.se>
parents:
12675
diff
changeset
|
1630 local host_type; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1631 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
|
1632 i = i + 1; |
|
12676
3ab3ef9584e3
mod_admin_shell: Rename variable to avoid confusion with global function
Kim Alvefur <zash@zash.se>
parents:
12675
diff
changeset
|
1633 host_type = host_session.type; |
|
3ab3ef9584e3
mod_admin_shell: Rename variable to avoid confusion with global function
Kim Alvefur <zash@zash.se>
parents:
12675
diff
changeset
|
1634 if host_type == "local" then |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1635 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
|
1636 else |
|
12676
3ab3ef9584e3
mod_admin_shell: Rename variable to avoid confusion with global function
Kim Alvefur <zash@zash.se>
parents:
12675
diff
changeset
|
1637 host_type = module:context(host):get_option_string("component_module", host_type); |
|
3ab3ef9584e3
mod_admin_shell: Rename variable to avoid confusion with global function
Kim Alvefur <zash@zash.se>
parents:
12675
diff
changeset
|
1638 if host_type ~= "component" then |
|
3ab3ef9584e3
mod_admin_shell: Rename variable to avoid confusion with global function
Kim Alvefur <zash@zash.se>
parents:
12675
diff
changeset
|
1639 host_type = host_type .. " component"; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1640 end |
|
12676
3ab3ef9584e3
mod_admin_shell: Rename variable to avoid confusion with global function
Kim Alvefur <zash@zash.se>
parents:
12675
diff
changeset
|
1641 print(("%s (%s)"):format(host, host_type)); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1642 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1643 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 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
|
1645 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1646 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1647 def_env.port = new_section("Commands to manage ports the server is listening on"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1648 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1649 describe_command [[port:list() - Lists all network ports prosody currently listens on]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1650 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
|
1651 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
|
1652 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
|
1653 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
|
1654 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
|
1655 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
|
1656 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
|
1657 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
|
1658 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
|
1659 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
|
1660 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1661 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1662 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
|
1663 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
|
1664 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1665 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
|
1666 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1667 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1668 describe_command [[port:close(port, interface) - Close a port]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1669 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
|
1670 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
|
1671 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
|
1672 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
|
1673 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
|
1674 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
|
1675 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
|
1676 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
|
1677 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
|
1678 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
|
1679 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
|
1680 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
|
1681 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1682 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
|
1683 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1684 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1685 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1686 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1687 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1688 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
|
1689 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1690 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1691 def_env.muc = new_section("Commands to create, list and manage chat rooms"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1692 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1693 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
|
1694 __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
|
1695 __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
|
1696 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
|
1697 end; |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1698 }; |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1699 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1700 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
|
1701 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
|
1702 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
|
1703 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
|
1704 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
|
1705 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
|
1706 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1707 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
|
1708 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1709 |
|
12867
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1710 local function get_muc(room_jid) |
|
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1711 local room_name, host = check_muc(room_jid); |
|
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1712 if not room_name then |
|
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1713 return room_name, host; |
|
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1714 end |
|
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1715 local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid); |
|
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1716 if not room_obj then |
|
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1717 return nil, "No such room: "..room_jid; |
|
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1718 end |
|
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1719 return room_obj; |
|
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1720 end |
|
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1721 |
|
12870
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1722 local muc_util = module:require"muc/util"; |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1723 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1724 describe_command [[muc:create(roomjid, { config }) - Create the specified MUC room with the given config]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1725 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
|
1726 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
|
1727 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
|
1728 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
|
1729 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1730 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
|
1731 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
|
1732 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
|
1733 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
|
1734 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1735 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1736 describe_command [[muc:room(roomjid) - Reference the specified MUC room to access MUC API methods]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1737 function def_env.muc:room(room_jid) |
|
12867
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1738 local room_obj, err = get_muc(room_jid); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1739 if not room_obj then |
|
12867
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1740 return room_obj, err; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1741 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1742 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
|
1743 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1744 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1745 describe_command [[muc:list(host) - List rooms on the specified MUC component]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1746 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
|
1747 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
|
1748 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
|
1749 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
|
1750 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1751 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
|
1752 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
|
1753 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
|
1754 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
|
1755 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
|
1756 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1757 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
|
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 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1760 describe_command [[muc:occupants(roomjid, filter) - List room occupants, optionally filtered on substring or role]] |
|
12865
e6324117f124
mod_admin_shell: Add muc:occupants(room) command to list occupants
Kim Alvefur <zash@zash.se>
parents:
12789
diff
changeset
|
1761 function def_env.muc:occupants(room_jid, filter) |
|
12867
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1762 local room_obj, err = get_muc(room_jid); |
|
12865
e6324117f124
mod_admin_shell: Add muc:occupants(room) command to list occupants
Kim Alvefur <zash@zash.se>
parents:
12789
diff
changeset
|
1763 if not room_obj then |
|
12867
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1764 return room_obj, err; |
|
12865
e6324117f124
mod_admin_shell: Add muc:occupants(room) command to list occupants
Kim Alvefur <zash@zash.se>
parents:
12789
diff
changeset
|
1765 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1766 |
|
12865
e6324117f124
mod_admin_shell: Add muc:occupants(room) command to list occupants
Kim Alvefur <zash@zash.se>
parents:
12789
diff
changeset
|
1767 local print = self.session.print; |
|
12868
d5cb86b84d12
mod_admin_shell: Use tables to present MUC users
Kim Alvefur <zash@zash.se>
parents:
12867
diff
changeset
|
1768 local row = format_table({ |
|
12869
70ee82579076
mod_admin_shell: Make Role and Affiliation columns the same width for aesthetics
Kim Alvefur <zash@zash.se>
parents:
12868
diff
changeset
|
1769 { title = "Role"; width = 12; key = "role" }; -- longest role name |
|
12868
d5cb86b84d12
mod_admin_shell: Use tables to present MUC users
Kim Alvefur <zash@zash.se>
parents:
12867
diff
changeset
|
1770 { title = "JID"; width = "75%"; key = "bare_jid" }; |
|
d5cb86b84d12
mod_admin_shell: Use tables to present MUC users
Kim Alvefur <zash@zash.se>
parents:
12867
diff
changeset
|
1771 { title = "Nickname"; width = "25%"; key = "nick"; mapper = jid_resource }; |
|
d5cb86b84d12
mod_admin_shell: Use tables to present MUC users
Kim Alvefur <zash@zash.se>
parents:
12867
diff
changeset
|
1772 }, self.session.width); |
|
12870
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1773 local occupants = array.collect(iterators.select(2, room_obj:each_occupant())); |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1774 local total = #occupants; |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1775 if filter then |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1776 occupants:filter(function(occupant) |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1777 return occupant.role == filter or jid_resource(occupant.nick):find(filter, 1, true); |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1778 end); |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1779 end |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1780 local displayed = #occupants; |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1781 occupants:sort(function(a, b) |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1782 if a.role ~= b.role then |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1783 return muc_util.valid_roles[a.role] > muc_util.valid_roles[b.role]; |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1784 else |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1785 return a.bare_jid < b.bare_jid; |
|
12868
d5cb86b84d12
mod_admin_shell: Use tables to present MUC users
Kim Alvefur <zash@zash.se>
parents:
12867
diff
changeset
|
1786 end |
|
12870
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1787 end); |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1788 |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1789 if displayed == 0 then |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1790 return true, ("%d out of %d occupant%s listed"):format(displayed, total, total ~= 1 and "s" or "") |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1791 end |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1792 |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1793 print(row()); |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1794 for _, occupant in ipairs(occupants) do |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1795 print(row(occupant)); |
|
12865
e6324117f124
mod_admin_shell: Add muc:occupants(room) command to list occupants
Kim Alvefur <zash@zash.se>
parents:
12789
diff
changeset
|
1796 end |
|
e6324117f124
mod_admin_shell: Add muc:occupants(room) command to list occupants
Kim Alvefur <zash@zash.se>
parents:
12789
diff
changeset
|
1797 |
|
e6324117f124
mod_admin_shell: Add muc:occupants(room) command to list occupants
Kim Alvefur <zash@zash.se>
parents:
12789
diff
changeset
|
1798 if total == displayed then |
|
e6324117f124
mod_admin_shell: Add muc:occupants(room) command to list occupants
Kim Alvefur <zash@zash.se>
parents:
12789
diff
changeset
|
1799 return true, ("%d occupant%s listed"):format(total, total ~= 1 and "s" or "") |
|
e6324117f124
mod_admin_shell: Add muc:occupants(room) command to list occupants
Kim Alvefur <zash@zash.se>
parents:
12789
diff
changeset
|
1800 else |
|
e6324117f124
mod_admin_shell: Add muc:occupants(room) command to list occupants
Kim Alvefur <zash@zash.se>
parents:
12789
diff
changeset
|
1801 return true, ("%d out of %d occupant%s listed"):format(displayed, total, total ~= 1 and "s" or "") |
|
e6324117f124
mod_admin_shell: Add muc:occupants(room) command to list occupants
Kim Alvefur <zash@zash.se>
parents:
12789
diff
changeset
|
1802 end |
|
12013
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1803 end |
|
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
1804 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1805 describe_command [[muc:affiliations(roomjid, filter) - List affiliated members of the room, optionally filtered on substring or affiliation]] |
|
12866
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1806 function def_env.muc:affiliations(room_jid, filter) |
|
12867
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1807 local room_obj, err = get_muc(room_jid); |
|
12866
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1808 if not room_obj then |
|
12867
2defb0fc2be9
mod_admin_shell: Factor out room retrieval into common function
Kim Alvefur <zash@zash.se>
parents:
12866
diff
changeset
|
1809 return room_obj, err; |
|
12866
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1810 end |
|
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1811 |
|
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1812 local print = self.session.print; |
|
12868
d5cb86b84d12
mod_admin_shell: Use tables to present MUC users
Kim Alvefur <zash@zash.se>
parents:
12867
diff
changeset
|
1813 local row = format_table({ |
|
12869
70ee82579076
mod_admin_shell: Make Role and Affiliation columns the same width for aesthetics
Kim Alvefur <zash@zash.se>
parents:
12868
diff
changeset
|
1814 { title = "Affiliation"; width = 12 }; -- longest affiliation name |
|
12868
d5cb86b84d12
mod_admin_shell: Use tables to present MUC users
Kim Alvefur <zash@zash.se>
parents:
12867
diff
changeset
|
1815 { title = "JID"; width = "75%" }; |
|
d5cb86b84d12
mod_admin_shell: Use tables to present MUC users
Kim Alvefur <zash@zash.se>
parents:
12867
diff
changeset
|
1816 { title = "Nickname"; width = "25%"; key = "reserved_nickname" }; |
|
d5cb86b84d12
mod_admin_shell: Use tables to present MUC users
Kim Alvefur <zash@zash.se>
parents:
12867
diff
changeset
|
1817 }, self.session.width); |
|
12870
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1818 local affiliated = array(); |
|
12866
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1819 for affiliated_jid, affiliation, affiliation_data in room_obj:each_affiliation() do |
|
12870
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1820 affiliated:push(setmetatable({ affiliation; affiliated_jid }, { __index = affiliation_data })); |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1821 end |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1822 |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1823 local total = #affiliated; |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1824 if filter then |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1825 affiliated:filter(function(affiliation) |
|
12871
885323e2a1ce
mod_admin_shell: Match substring in muc:affiliations() like muc:occupants()
Kim Alvefur <zash@zash.se>
parents:
12870
diff
changeset
|
1826 return filter == affiliation[1] or affiliation[2]:find(filter, 1, true); |
|
12870
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1827 end); |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1828 end |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1829 local displayed = #affiliated; |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1830 local aff_ranking = muc_util.valid_affiliations; |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1831 affiliated:sort(function(a, b) |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1832 if a[1] ~= b[1] then |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1833 return aff_ranking[a[1]] > aff_ranking[b[1]]; |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1834 else |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1835 return a[2] < b[2]; |
|
12868
d5cb86b84d12
mod_admin_shell: Use tables to present MUC users
Kim Alvefur <zash@zash.se>
parents:
12867
diff
changeset
|
1836 end |
|
12870
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1837 end); |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1838 |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1839 if displayed == 0 then |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1840 return true, ("%d out of %d affiliations%s listed"):format(displayed, total, total ~= 1 and "s" or "") |
|
12866
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1841 end |
|
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1842 |
|
12870
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1843 print(row()); |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1844 for _, affiliation in ipairs(affiliated) do |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1845 print(row(affiliation)); |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1846 end |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1847 |
|
56397f3b58c1
mod_admin_shell: Sort MUC users by relation and JID
Kim Alvefur <zash@zash.se>
parents:
12869
diff
changeset
|
1848 |
|
12866
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1849 if total == displayed then |
|
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1850 return true, ("%d affiliation%s listed"):format(total, total ~= 1 and "s" or "") |
|
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1851 else |
|
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1852 return true, ("%d out of %d affiliation%s listed"):format(displayed, total, total ~= 1 and "s" or "") |
|
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1853 end |
|
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1854 end |
|
54aea2622459
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Kim Alvefur <zash@zash.se>
parents:
12865
diff
changeset
|
1855 |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
1856 local um = require"prosody.core.usermanager"; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1857 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1858 def_env.user = new_section("Commands to create and delete users, and change their passwords"); |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1859 |
|
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1860 describe_command [[user:create(jid, password, role) - Create the specified user account]] |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
1861 function def_env.user:create(jid, password, role) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1862 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
|
1863 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
|
1864 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
|
1865 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
|
1866 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
|
1867 end |
|
12672
c8f59ce7d3cf
mod_admin_shell: Ensure account has role before it is usable
Kim Alvefur <zash@zash.se>
parents:
12670
diff
changeset
|
1868 |
|
13170
082c7d856e61
core, plugins: Split prosody:user role into prosody:{guest,registered,member}
Matthew Wild <mwild1@gmail.com>
parents:
13132
diff
changeset
|
1869 if not role then |
|
082c7d856e61
core, plugins: Split prosody:user role into prosody:{guest,registered,member}
Matthew Wild <mwild1@gmail.com>
parents:
13132
diff
changeset
|
1870 role = module:get_option_string("default_provisioned_role", "prosody:member"); |
|
12672
c8f59ce7d3cf
mod_admin_shell: Ensure account has role before it is usable
Kim Alvefur <zash@zash.se>
parents:
12670
diff
changeset
|
1871 end |
|
c8f59ce7d3cf
mod_admin_shell: Ensure account has role before it is usable
Kim Alvefur <zash@zash.se>
parents:
12670
diff
changeset
|
1872 |
|
14120
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1873 return promise.resolve(password or self.session.request_input("password")):next(function (raw_password) |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1874 local prepped_password = saslprep(raw_password); |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1875 if not prepped_password or prepped_password == "" then |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1876 return promise.reject("Unacceptable password"); |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1877 end |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1878 |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1879 self.session.print(("PW: %q"):format(raw_password)); |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1880 self.session.print(("PW2: %q"):format(prepped_password)); |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1881 |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1882 local ok, err = um.create_user_with_role(username, prepped_password, host, role); |
|
13594
abbdcef552fb
mod_admin_shell: user:create(): request password via prompt if none given
Matthew Wild <mwild1@gmail.com>
parents:
13593
diff
changeset
|
1883 if not ok then |
|
13597
62aca6adcfd3
mod_admin_shell: user:create(): Reject promise with error message on failure
Matthew Wild <mwild1@gmail.com>
parents:
13596
diff
changeset
|
1884 return promise.reject("Could not create user: "..err); |
|
13594
abbdcef552fb
mod_admin_shell: user:create(): request password via prompt if none given
Matthew Wild <mwild1@gmail.com>
parents:
13593
diff
changeset
|
1885 end |
|
abbdcef552fb
mod_admin_shell: user:create(): request password via prompt if none given
Matthew Wild <mwild1@gmail.com>
parents:
13593
diff
changeset
|
1886 return ("Created %s with role '%s'"):format(jid, role); |
|
abbdcef552fb
mod_admin_shell: user:create(): request password via prompt if none given
Matthew Wild <mwild1@gmail.com>
parents:
13593
diff
changeset
|
1887 end); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1888 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1889 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1890 describe_command [[user:disable(jid) - Disable the specified user account, preventing login]] |
|
12908
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1891 function def_env.user:disable(jid) |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1892 local username, host = jid_split(jid); |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1893 if not prosody.hosts[host] then |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1894 return nil, "No such host: "..host; |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1895 elseif not um.user_exists(username, host) then |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1896 return nil, "No such user"; |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1897 end |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1898 local ok, err = um.disable_user(username, host); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1899 if ok then |
|
12908
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1900 return true, "User disabled"; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1901 else |
|
12908
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1902 return nil, "Could not disable user: "..err; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1903 end |
|
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 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1906 describe_command [[user:enable(jid) - Enable the specified user account, restoring login access]] |
|
12908
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1907 function def_env.user:enable(jid) |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1908 local username, host = jid_split(jid); |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1909 if not prosody.hosts[host] then |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1910 return nil, "No such host: "..host; |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1911 elseif not um.user_exists(username, host) then |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1912 return nil, "No such user"; |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1913 end |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1914 local ok, err = um.enable_user(username, host); |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1915 if ok then |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1916 return true, "User enabled"; |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1917 else |
|
e96c3ea64996
mod_admin_shell: Add commands to disable and enable accounts
Kim Alvefur <zash@zash.se>
parents:
12888
diff
changeset
|
1918 return nil, "Could not enable user: "..err; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1919 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1920 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1921 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1922 describe_command [[user:delete(jid) - Permanently remove the specified user account]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1923 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
|
1924 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
|
1925 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
|
1926 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
|
1927 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
|
1928 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
|
1929 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1930 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
|
1931 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
|
1932 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
|
1933 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1934 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
|
1935 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1936 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1937 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
1938 describe_command [[user:password(jid, password) - Set the password for the specified user account]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1939 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
|
1940 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
|
1941 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
|
1942 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
|
1943 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
|
1944 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
|
1945 end |
|
13598
2cd43975a15c
mod_admin_shell: user:password(): Support prompting for password if none given
Matthew Wild <mwild1@gmail.com>
parents:
13597
diff
changeset
|
1946 |
|
14120
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1947 return promise.resolve(password or self.session.request_input("password")):next(function (raw_password) |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1948 local prepped_password = saslprep(raw_password); |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1949 if not prepped_password or prepped_password == "" then |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1950 return promise.reject("Unacceptable password"); |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1951 end |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1952 |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1953 self.session.print(("PW: %q"):format(raw_password)); |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1954 self.session.print(("PW2: %q"):format(prepped_password)); |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1955 |
|
0e9e3efa381f
mod_admin_shell: Fail user creation/modification if new password fails saslprep
Matthew Wild <mwild1@gmail.com>
parents:
14113
diff
changeset
|
1956 local ok, err = um.set_password(username, prepped_password, host, nil); |
|
13598
2cd43975a15c
mod_admin_shell: user:password(): Support prompting for password if none given
Matthew Wild <mwild1@gmail.com>
parents:
13597
diff
changeset
|
1957 if ok then |
|
2cd43975a15c
mod_admin_shell: user:password(): Support prompting for password if none given
Matthew Wild <mwild1@gmail.com>
parents:
13597
diff
changeset
|
1958 return "User password changed"; |
|
2cd43975a15c
mod_admin_shell: user:password(): Support prompting for password if none given
Matthew Wild <mwild1@gmail.com>
parents:
13597
diff
changeset
|
1959 else |
|
2cd43975a15c
mod_admin_shell: user:password(): Support prompting for password if none given
Matthew Wild <mwild1@gmail.com>
parents:
13597
diff
changeset
|
1960 return promise.reject("Could not change password for user: "..err); |
|
2cd43975a15c
mod_admin_shell: user:password(): Support prompting for password if none given
Matthew Wild <mwild1@gmail.com>
parents:
13597
diff
changeset
|
1961 end |
|
2cd43975a15c
mod_admin_shell: user:password(): Support prompting for password if none given
Matthew Wild <mwild1@gmail.com>
parents:
13597
diff
changeset
|
1962 end); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1963 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1964 |
|
13684
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
1965 describe_command [[user:role(jid, host) - Show primary role for a user]] |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
1966 function def_env.user:role(jid, host) |
|
12209
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12208
diff
changeset
|
1967 local username, userhost = jid_split(jid); |
|
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12208
diff
changeset
|
1968 if host == nil then host = userhost; end |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
1969 if not prosody.hosts[host] then |
|
12209
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12208
diff
changeset
|
1970 return nil, "No such host: "..host; |
|
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12208
diff
changeset
|
1971 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:
12208
diff
changeset
|
1972 return nil, "No such user"; |
|
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12208
diff
changeset
|
1973 end |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
1974 |
|
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
1975 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:
12660
diff
changeset
|
1976 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:
12660
diff
changeset
|
1977 |
|
13684
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
1978 local primary_role_desc = primary_role and primary_role.name or "<none>"; |
|
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
1979 |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
1980 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:
12660
diff
changeset
|
1981 |
|
13684
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
1982 local n_secondary = 0; |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
1983 for role_name in pairs(secondary_roles or {}) do |
|
13684
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
1984 n_secondary = n_secondary + 1; |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
1985 print(role_name.." (secondary)"); |
|
12209
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12208
diff
changeset
|
1986 end |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
1987 |
|
13684
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
1988 if n_secondary > 0 then |
|
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
1989 return true, primary_role_desc.." (primary)"; |
|
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
1990 end |
|
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
1991 return true, primary_role_desc; |
|
12209
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12208
diff
changeset
|
1992 end |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
1993 def_env.user.roles = def_env.user.role; |
|
12209
3fe2e5da05c3
mod_admin_shell: Add command to show current user roles
Kim Alvefur <zash@zash.se>
parents:
12208
diff
changeset
|
1994 |
|
13685
b9fce1651699
mod_admin_shell: Rename user:setrole to user:set_roles
Matthew Wild <mwild1@gmail.com>
parents:
13684
diff
changeset
|
1995 describe_command [[user:set_role(jid, host, role) - Set primary role of a user (see 'help roles')]] |
|
b9fce1651699
mod_admin_shell: Rename user:setrole to user:set_roles
Matthew Wild <mwild1@gmail.com>
parents:
13684
diff
changeset
|
1996 -- user:set_role("someone@example.com", "example.com", "prosody:admin") |
|
b9fce1651699
mod_admin_shell: Rename user:setrole to user:set_roles
Matthew Wild <mwild1@gmail.com>
parents:
13684
diff
changeset
|
1997 -- user:set_role("someone@example.com", "prosody:admin") |
|
b9fce1651699
mod_admin_shell: Rename user:setrole to user:set_roles
Matthew Wild <mwild1@gmail.com>
parents:
13684
diff
changeset
|
1998 function def_env.user:set_role(jid, host, new_role) |
|
12014
efbf288b529e
mod_admin_shell: Support setting roles on hosts other than the users'
Kim Alvefur <zash@zash.se>
parents:
12013
diff
changeset
|
1999 local username, userhost = jid_split(jid); |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
2000 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:
12660
diff
changeset
|
2001 if not prosody.hosts[host] then |
|
12013
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
2002 return nil, "No such host: "..host; |
|
12018
c65789f5004e
mod_admin_shell: Only check that local users exist locally
Kim Alvefur <zash@zash.se>
parents:
12014
diff
changeset
|
2003 elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then |
|
12013
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
2004 return nil, "No such user"; |
|
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
2005 end |
|
13540
cc67109ce502
mod_admin_shell: Allow assigning roles to arbitrary JIDs when supported
Kim Alvefur <zash@zash.se>
parents:
13517
diff
changeset
|
2006 if userhost == host then |
|
cc67109ce502
mod_admin_shell: Allow assigning roles to arbitrary JIDs when supported
Kim Alvefur <zash@zash.se>
parents:
13517
diff
changeset
|
2007 return um.set_user_role(username, userhost, new_role); |
|
cc67109ce502
mod_admin_shell: Allow assigning roles to arbitrary JIDs when supported
Kim Alvefur <zash@zash.se>
parents:
13517
diff
changeset
|
2008 else |
|
cc67109ce502
mod_admin_shell: Allow assigning roles to arbitrary JIDs when supported
Kim Alvefur <zash@zash.se>
parents:
13517
diff
changeset
|
2009 return um.set_jid_role(jid, host, new_role); |
|
cc67109ce502
mod_admin_shell: Allow assigning roles to arbitrary JIDs when supported
Kim Alvefur <zash@zash.se>
parents:
13517
diff
changeset
|
2010 end |
|
12013
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
2011 end |
|
12012
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11991
diff
changeset
|
2012 |
|
13684
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
2013 hidden_command [[user:addrole(jid, host, role) - Add a secondary role to a user]] |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
2014 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:
12660
diff
changeset
|
2015 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:
12660
diff
changeset
|
2016 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:
12660
diff
changeset
|
2017 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:
12660
diff
changeset
|
2018 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:
12660
diff
changeset
|
2019 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:
12660
diff
changeset
|
2020 return nil, "No such user"; |
|
13542
67288253d9a2
mod_admin_shell: Reject attempt to add or remove roles for unrelated hosts
Kim Alvefur <zash@zash.se>
parents:
13540
diff
changeset
|
2021 elseif userhost ~= host then |
|
67288253d9a2
mod_admin_shell: Reject attempt to add or remove roles for unrelated hosts
Kim Alvefur <zash@zash.se>
parents:
13540
diff
changeset
|
2022 return nil, "Can't add roles outside users own host" |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
2023 end |
|
13681
8f43b954bdac
mod_admin_shell: Fix result handling of user addrole/delrole commands
Matthew Wild <mwild1@gmail.com>
parents:
13641
diff
changeset
|
2024 local role, err = um.add_user_secondary_role(username, host, new_role); |
|
8f43b954bdac
mod_admin_shell: Fix result handling of user addrole/delrole commands
Matthew Wild <mwild1@gmail.com>
parents:
13641
diff
changeset
|
2025 if not role then |
|
8f43b954bdac
mod_admin_shell: Fix result handling of user addrole/delrole commands
Matthew Wild <mwild1@gmail.com>
parents:
13641
diff
changeset
|
2026 return nil, err; |
|
8f43b954bdac
mod_admin_shell: Fix result handling of user addrole/delrole commands
Matthew Wild <mwild1@gmail.com>
parents:
13641
diff
changeset
|
2027 end |
|
8f43b954bdac
mod_admin_shell: Fix result handling of user addrole/delrole commands
Matthew Wild <mwild1@gmail.com>
parents:
13641
diff
changeset
|
2028 return true, "Role added"; |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
2029 end |
|
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
2030 |
|
13684
026a75a443de
mod_admin_shell: Hide secondary role commands, focus on primary roles
Matthew Wild <mwild1@gmail.com>
parents:
13683
diff
changeset
|
2031 hidden_command [[user:delrole(jid, host, role) - Remove a secondary role from a user]] |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
2032 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:
12660
diff
changeset
|
2033 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:
12660
diff
changeset
|
2034 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:
12660
diff
changeset
|
2035 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:
12660
diff
changeset
|
2036 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:
12660
diff
changeset
|
2037 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:
12660
diff
changeset
|
2038 return nil, "No such user"; |
|
13542
67288253d9a2
mod_admin_shell: Reject attempt to add or remove roles for unrelated hosts
Kim Alvefur <zash@zash.se>
parents:
13540
diff
changeset
|
2039 elseif userhost ~= host then |
|
67288253d9a2
mod_admin_shell: Reject attempt to add or remove roles for unrelated hosts
Kim Alvefur <zash@zash.se>
parents:
13540
diff
changeset
|
2040 return nil, "Can't remove roles outside users own host" |
|
12668
5d85de8b0723
mod_admin_shell: Update with new role management commands and help text
Matthew Wild <mwild1@gmail.com>
parents:
12660
diff
changeset
|
2041 end |
|
13681
8f43b954bdac
mod_admin_shell: Fix result handling of user addrole/delrole commands
Matthew Wild <mwild1@gmail.com>
parents:
13641
diff
changeset
|
2042 local ok, err = um.remove_user_secondary_role(username, host, role_name); |
|
8f43b954bdac
mod_admin_shell: Fix result handling of user addrole/delrole commands
Matthew Wild <mwild1@gmail.com>
parents:
13641
diff
changeset
|
2043 if not ok then |
|
8f43b954bdac
mod_admin_shell: Fix result handling of user addrole/delrole commands
Matthew Wild <mwild1@gmail.com>
parents:
13641
diff
changeset
|
2044 return nil, err; |
|
8f43b954bdac
mod_admin_shell: Fix result handling of user addrole/delrole commands
Matthew Wild <mwild1@gmail.com>
parents:
13641
diff
changeset
|
2045 end |
|
8f43b954bdac
mod_admin_shell: Fix result handling of user addrole/delrole commands
Matthew Wild <mwild1@gmail.com>
parents:
13641
diff
changeset
|
2046 return true, "Role removed"; |
|
12013
ae45f052b34b
mod_admin_shell: Add command for updating roles user:roles(jid, roles)
Kim Alvefur <zash@zash.se>
parents:
12012
diff
changeset
|
2047 end |
|
12012
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11991
diff
changeset
|
2048 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2049 describe_command [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] |
|
12012
71d799a8638f
mod_admin_shell: Allow setting roles when creating user
Kim Alvefur <zash@zash.se>
parents:
11991
diff
changeset
|
2050 -- TODO switch to table view, include roles |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2051 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
|
2052 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
|
2053 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
|
2054 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
|
2055 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
|
2056 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2057 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
|
2058 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
|
2059 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
|
2060 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
|
2061 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
|
2062 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
|
2063 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2064 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
|
2065 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2066 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
|
2067 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2068 |
|
13354
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
2069 def_env.xmpp = new_section("Commands for sending XMPP stanzas"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2070 |
|
13996
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2071 describe_command [[xmpp:ping(localjid, remotejid) - Sends a ping to an XMPP entity and reports the response]] |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
2072 local new_id = require "prosody.util.id".medium; |
|
13996
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2073 function def_env.xmpp:ping(localjid, remotejid, timeout) |
|
13999
5ad86978ae78
mod_admin_shell: Ensure JIDs are normalized in xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13996
diff
changeset
|
2074 local localnode, localhost, localresource = jid_split(localjid); |
|
5ad86978ae78
mod_admin_shell: Ensure JIDs are normalized in xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13996
diff
changeset
|
2075 local remotenode, remotehost, remoteresource = jid_split(remotejid); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2076 if not localhost then |
|
13996
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2077 return nil, "Invalid sender JID"; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2078 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
|
2079 return nil, "No such local host"; |
|
13996
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2080 elseif localresource then |
|
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2081 return nil, "Server can't send ping from local resource"; -- Would require creating a temporary session with bound resource and everything |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2082 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2083 if not remotehost then |
|
13996
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2084 return nil, "Invalid destination JID"; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2085 end |
|
13999
5ad86978ae78
mod_admin_shell: Ensure JIDs are normalized in xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13996
diff
changeset
|
2086 local iq = st.iq { from = jid_join(localnode, localhost); to = jid_join(remotenode, remotehost, remoteresource); type = "get"; id = new_id() } |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2087 :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
|
2088 local time_start = time.now(); |
|
12122
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2089 local print = self.session.print; |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2090 local function onchange(what) |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2091 return function(event) |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2092 local s2s_session = event.session; |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2093 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:
12056
diff
changeset
|
2094 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:
12056
diff
changeset
|
2095 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:
12056
diff
changeset
|
2096 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:
12056
diff
changeset
|
2097 time.now() - time_start)); |
|
12126
0d8e6646ce42
mod_admin_shell: Log creation of incoming s2s connections during ping
Kim Alvefur <zash@zash.se>
parents:
12122
diff
changeset
|
2098 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:
12122
diff
changeset
|
2099 print(("Session %s %s (%gs)"):format(s2s_session.id, what, time.now() - time_start)); |
|
12122
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2100 end |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2101 end |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2102 end |
|
13996
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2103 if localhost == remotehost or prosody.hosts[remotehost] then |
|
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2104 -- No s2s connections will be triggered |
|
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2105 return module:context(localhost):send_iq(iq, nil, timeout):next(function(pong) |
|
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2106 return ("pong from %s in %gs"):format(pong.stanza.attr.from, time.now() - time_start); |
|
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2107 end); |
|
8d90a83603d6
mod_admin_shell: Allow pinging any JID with xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
13869
diff
changeset
|
2108 end |
|
12281
9016071867d7
mod_admin_shell: Track connected events instead of created
Kim Alvefur <zash@zash.se>
parents:
12258
diff
changeset
|
2109 local onconnected = onchange("connected"); |
|
12122
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2110 local onauthenticated = onchange("authenticated"); |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2111 local onestablished = onchange("established"); |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2112 local ondestroyed = onchange("destroyed"); |
|
12281
9016071867d7
mod_admin_shell: Track connected events instead of created
Kim Alvefur <zash@zash.se>
parents:
12258
diff
changeset
|
2113 module:hook("s2s-connected", onconnected, 1); |
|
12122
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2114 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:
12056
diff
changeset
|
2115 module:hook("s2sout-established", onestablished, 1); |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2116 module:hook("s2sin-established", onestablished, 1); |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2117 module:hook("s2s-destroyed", ondestroyed, 1); |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2118 return module:context(localhost):send_iq(iq, nil, timeout):finally(function() |
|
12281
9016071867d7
mod_admin_shell: Track connected events instead of created
Kim Alvefur <zash@zash.se>
parents:
12258
diff
changeset
|
2119 module:unhook("s2s-connected", onconnected, 1); |
|
12122
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2120 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:
12056
diff
changeset
|
2121 module:unhook("s2sout-established", onestablished); |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2122 module:unhook("s2sin-established", onestablished); |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2123 module:unhook("s2s-destroyed", ondestroyed); |
|
50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Kim Alvefur <zash@zash.se>
parents:
12056
diff
changeset
|
2124 end):next(function(pong) |
|
12551
3b7e97e0a8ef
mod_admin_shell: Show session id ping reply came
Kim Alvefur <zash@zash.se>
parents:
12540
diff
changeset
|
2125 return ("pong from %s on %s in %gs"):format(pong.stanza.attr.from, pong.origin.id, time.now() - time_start); |
|
11953
848a522fd731
mod_admin_shell: Remove now redundant promise awaiting in xmpp:ping()
Kim Alvefur <zash@zash.se>
parents:
11950
diff
changeset
|
2126 end); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2127 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2128 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2129 def_env.dns = new_section("Commands to manage and inspect the internal DNS resolver"); |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
2130 local adns = require"prosody.net.adns"; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2131 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2132 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
|
2133 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
|
2134 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
|
2135 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
|
2136 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
|
2137 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2138 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
|
2139 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2140 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2141 describe_command [[dns:lookup(name, type, class) - Do a DNS lookup]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2142 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
|
2143 local resolver = get_resolver(self.session); |
|
11954
b963ac00c967
mod_admin_shell: Remove now redundant promise awaiting in dns:lookup()
Kim Alvefur <zash@zash.se>
parents:
11953
diff
changeset
|
2144 return resolver:lookup_promise(name, typ, class) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2145 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2146 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2147 describe_command [[dns:addnameserver(nameserver) - Add a nameserver to the list]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2148 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
|
2149 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
|
2150 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
|
2151 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
|
2152 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2153 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2154 describe_command [[dns:setnameserver(nameserver) - Replace the list of name servers with the supplied one]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2155 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
|
2156 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
|
2157 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
|
2158 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
|
2159 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2160 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2161 describe_command [[dns:purge() - Clear the DNS cache]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2162 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
|
2163 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
|
2164 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
|
2165 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
|
2166 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2167 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2168 describe_command [[dns:cache() - Show cached records]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2169 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
|
2170 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
|
2171 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
|
2172 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2173 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2174 def_env.http = new_section("Commands to inspect HTTP services"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2175 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2176 describe_command [[http:list(hosts) - Show HTTP endpoints]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2177 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
|
2178 local print = self.session.print; |
|
11361
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
2179 hosts = array.collect(set.new({ not hosts and "*" or nil }) + get_hosts_set(hosts)):sort(_sort_hosts); |
|
13117
7eb6244b4984
mod_admin_shell: Show internal URL where different from external
Kim Alvefur <zash@zash.se>
parents:
13108
diff
changeset
|
2180 local output_simple = format_table({ |
|
13108
6cd768e6ac7c
mod_admin_shell: Show internal URL in addition to external in http:list
Kim Alvefur <zash@zash.se>
parents:
13105
diff
changeset
|
2181 { title = "Module"; width = "1p" }; |
|
13117
7eb6244b4984
mod_admin_shell: Show internal URL where different from external
Kim Alvefur <zash@zash.se>
parents:
13108
diff
changeset
|
2182 { title = "External URL"; width = "6p" }; |
|
7eb6244b4984
mod_admin_shell: Show internal URL where different from external
Kim Alvefur <zash@zash.se>
parents:
13108
diff
changeset
|
2183 }, self.session.width); |
|
7eb6244b4984
mod_admin_shell: Show internal URL where different from external
Kim Alvefur <zash@zash.se>
parents:
13108
diff
changeset
|
2184 local output_split = format_table({ |
|
7eb6244b4984
mod_admin_shell: Show internal URL where different from external
Kim Alvefur <zash@zash.se>
parents:
13108
diff
changeset
|
2185 { title = "Module"; width = "1p" }; |
|
7eb6244b4984
mod_admin_shell: Show internal URL where different from external
Kim Alvefur <zash@zash.se>
parents:
13108
diff
changeset
|
2186 { title = "External URL"; width = "3p" }; |
|
13108
6cd768e6ac7c
mod_admin_shell: Show internal URL in addition to external in http:list
Kim Alvefur <zash@zash.se>
parents:
13105
diff
changeset
|
2187 { title = "Internal URL"; width = "3p" }; |
|
6cd768e6ac7c
mod_admin_shell: Show internal URL in addition to external in http:list
Kim Alvefur <zash@zash.se>
parents:
13105
diff
changeset
|
2188 }, self.session.width); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2189 |
|
11361
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
2190 for _, host in ipairs(hosts) do |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2191 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
|
2192 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
|
2193 local http_host = module:context(host):get_option_string("http_host"); |
|
11361
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
2194 if host == "*" then |
|
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
2195 print("Global HTTP endpoints available on all hosts:"); |
|
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
2196 else |
|
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
2197 print("HTTP endpoints on "..host..(http_host and (" (using "..http_host.."):") or ":")); |
|
dab1a6e46087
mod_admin_shell: List global HTTP endpoints by default
Kim Alvefur <zash@zash.se>
parents:
11042
diff
changeset
|
2198 end |
|
13117
7eb6244b4984
mod_admin_shell: Show internal URL where different from external
Kim Alvefur <zash@zash.se>
parents:
13108
diff
changeset
|
2199 print(output_split()); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2200 for _, provider in ipairs(http_apps) do |
|
11362
52d93fba2ee1
mod_admin_shell: List modules providing each HTTP endpoint
Kim Alvefur <zash@zash.se>
parents:
11361
diff
changeset
|
2201 local mod = provider._provided_by; |
|
13108
6cd768e6ac7c
mod_admin_shell: Show internal URL in addition to external in http:list
Kim Alvefur <zash@zash.se>
parents:
13105
diff
changeset
|
2202 local external = module:context(host):http_url(provider.name, provider.default_path); |
|
6cd768e6ac7c
mod_admin_shell: Show internal URL in addition to external in http:list
Kim Alvefur <zash@zash.se>
parents:
13105
diff
changeset
|
2203 local internal = module:context(host):http_url(provider.name, provider.default_path, "internal"); |
|
6cd768e6ac7c
mod_admin_shell: Show internal URL in addition to external in http:list
Kim Alvefur <zash@zash.se>
parents:
13105
diff
changeset
|
2204 if external==internal then internal="" end |
|
11362
52d93fba2ee1
mod_admin_shell: List modules providing each HTTP endpoint
Kim Alvefur <zash@zash.se>
parents:
11361
diff
changeset
|
2205 mod = mod and "mod_"..mod or "" |
|
13117
7eb6244b4984
mod_admin_shell: Show internal URL where different from external
Kim Alvefur <zash@zash.se>
parents:
13108
diff
changeset
|
2206 print((internal=="" and output_simple or output_split){mod, external, internal}); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2207 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2208 print(""); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2209 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2210 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2211 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2212 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
|
2213 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
|
2214 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
|
2215 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2216 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
|
2217 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2218 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
|
2219 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2220 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2221 def_env.watch = new_section("Commands for watching live logs from the server"); |
|
12399
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2222 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2223 describe_command [[watch:log() - Follow debug logs]] |
|
12399
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2224 function def_env.watch:log() |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2225 local writing = false; |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2226 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:
12398
diff
changeset
|
2227 if writing then return; end |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2228 writing = true; |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2229 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:
12398
diff
changeset
|
2230 writing = false; |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2231 end); |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2232 |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2233 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:
12398
diff
changeset
|
2234 async.sleep(3); |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2235 end |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2236 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:
12398
diff
changeset
|
2237 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:
12398
diff
changeset
|
2238 end |
|
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2239 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2240 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2241 describe_command [[watch:stanzas(target, filter) - Watch live stanzas matching the specified target and filter]] |
|
12464
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2242 local stanza_watchers = module:require("mod_debug_stanzas/watcher"); |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2243 function def_env.watch:stanzas(target_spec, filter_spec) |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2244 local function handler(event_type, stanza, session) |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2245 if stanza then |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2246 if event_type == "sent" then |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2247 self.session.print(("\n<!-- sent to %s -->"):format(session.id)); |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2248 elseif event_type == "received" then |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2249 self.session.print(("\n<!-- received from %s -->"):format(session.id)); |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2250 else |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2251 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:
12399
diff
changeset
|
2252 end |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2253 self.session.print(stanza); |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2254 elseif session then |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2255 self.session.print("\n<!-- session "..session.id.." "..event_type.." -->"); |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2256 elseif event_type then |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2257 self.session.print("\n<!-- "..event_type.." -->"); |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2258 end |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2259 end |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2260 |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2261 stanza_watchers.add({ |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2262 target_spec = { |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2263 jid = target_spec; |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2264 }; |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2265 filter_spec = filter_spec and { |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2266 with_jid = filter_spec; |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2267 }; |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2268 }, handler); |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2269 |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2270 while self.session.is_connected() do |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2271 async.sleep(3); |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2272 end |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2273 |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2274 stanza_watchers.remove(handler); |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
2275 end |
|
12399
d99772b739e0
mod_admin_shell: Add watch:log() command to tail logs in realtime
Matthew Wild <mwild1@gmail.com>
parents:
12398
diff
changeset
|
2276 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2277 def_env.debug = new_section("Commands for debugging the server"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2278 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2279 describe_command [[debug:logevents(host) - Enable logging of fired events on host]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2280 function def_env.debug:logevents(host) |
|
13104
8c786880e28d
mod_admin_shell: Allow logging global events with debug:logevents("*")
Kim Alvefur <zash@zash.se>
parents:
13089
diff
changeset
|
2281 if host == "*" then |
|
8c786880e28d
mod_admin_shell: Allow logging global events with debug:logevents("*")
Kim Alvefur <zash@zash.se>
parents:
13089
diff
changeset
|
2282 helpers.log_events(prosody.events); |
|
13105
7d9e26003b05
mod_admin_shell: Allow logging HTTP events with debug:logevents("http")
Kim Alvefur <zash@zash.se>
parents:
13104
diff
changeset
|
2283 elseif host == "http" then |
|
7d9e26003b05
mod_admin_shell: Allow logging HTTP events with debug:logevents("http")
Kim Alvefur <zash@zash.se>
parents:
13104
diff
changeset
|
2284 helpers.log_events(require "prosody.net.http.server"._events); |
|
7d9e26003b05
mod_admin_shell: Allow logging HTTP events with debug:logevents("http")
Kim Alvefur <zash@zash.se>
parents:
13104
diff
changeset
|
2285 return true |
|
13104
8c786880e28d
mod_admin_shell: Allow logging global events with debug:logevents("*")
Kim Alvefur <zash@zash.se>
parents:
13089
diff
changeset
|
2286 else |
|
8c786880e28d
mod_admin_shell: Allow logging global events with debug:logevents("*")
Kim Alvefur <zash@zash.se>
parents:
13089
diff
changeset
|
2287 helpers.log_host_events(host); |
|
8c786880e28d
mod_admin_shell: Allow logging global events with debug:logevents("*")
Kim Alvefur <zash@zash.se>
parents:
13089
diff
changeset
|
2288 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2289 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
|
2290 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2291 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2292 describe_command [[debug:events(host, event) - Show registered event handlers]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2293 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
|
2294 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
|
2295 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
|
2296 if host == "http" then |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
2297 events_obj = require "prosody.net.http.server"._events; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2298 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
|
2299 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
|
2300 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2301 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
|
2302 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2303 else |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2304 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
|
2305 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2306 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
|
2307 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2308 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2309 describe_command [[debug:timers() - Show information about scheduled timers]] |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2310 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
|
2311 local print = self.session.print; |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
2312 local add_task = require"prosody.util.timer".add_task; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2313 local h, params = add_task.h, add_task.params; |
|
10988
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
2314 local function normalize_time(t) |
|
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
2315 return t; |
|
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
2316 end |
|
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
2317 local function format_time(t) |
|
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
2318 return os.date("%F %T", math.floor(normalize_time(t))); |
|
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
2319 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2320 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
|
2321 print("-- util.timer"); |
|
10986
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2322 elseif server.timer then |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2323 print("-- net.server.timer"); |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2324 h = server.timer.add_task.timers; |
|
10988
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
2325 normalize_time = server.timer.to_absolute_time or normalize_time; |
|
10986
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2326 end |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2327 if h then |
|
11478
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
2328 local timers = {}; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2329 for i, id in ipairs(h.ids) do |
|
10986
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2330 local t, cb = h.priorities[i], h.items[id]; |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2331 if not params then |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2332 local param = cb.param; |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2333 if param then |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2334 cb = param.callback; |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2335 else |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2336 cb = cb.timer_callback or cb; |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2337 end |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2338 elseif params[id] then |
|
d585deb8c882
mod_admin_shell: Fix debug:timers to handle net.server native timers
Kim Alvefur <zash@zash.se>
parents:
10929
diff
changeset
|
2339 cb = params[id].callback or cb; |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2340 end |
|
11478
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
2341 table.insert(timers, { format_time(t), cb }); |
|
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
2342 end |
|
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
2343 table.sort(timers, function (a, b) return a[1] < b[1] end); |
|
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
2344 for _, t in ipairs(timers) do |
|
c0c4431ab27b
mod_admin_shell: Sort timers by time in debug:timers()
Kim Alvefur <zash@zash.se>
parents:
11365
diff
changeset
|
2345 print(t[1], t[2]) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2346 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2347 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2348 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
|
2349 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
|
2350 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
|
2351 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
|
2352 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
|
2353 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2354 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2355 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
|
2356 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2357 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
|
2358 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
|
2359 if next_time then |
|
10988
9dcbbb1d12c3
mod_admin_shell: Handle server_epoll using monotonic time internally
Kim Alvefur <zash@zash.se>
parents:
10986
diff
changeset
|
2360 return true, ("Next event at %s (in %.6fs)"):format(format_time(next_time), normalize_time(next_time) - time.now()); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2361 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2362 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2363 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
|
2364 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2365 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2366 describe_command [[debug:async() - Show information about pending asynchronous tasks]] |
|
13334
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2367 function def_env.debug:async(runner_id) |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2368 local print = self.session.print; |
|
13338
470ab6b55e93
mod_admin_shell: Fix lint [luacheck]
Kim Alvefur <zash@zash.se>
parents:
13334
diff
changeset
|
2369 local time_now = time.now(); |
|
13334
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2370 |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2371 if runner_id then |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2372 for runner, since in pairs(async.waiting_runners) do |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2373 if runner.id == runner_id then |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2374 print("ID ", runner.id); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2375 local f = runner.func; |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2376 if f == async.default_runner_func then |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2377 print("Function ", tostring(runner.current_item).." (from work queue)"); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2378 else |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2379 print("Function ", tostring(f)); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2380 if st.is_stanza(runner.current_item) then |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2381 print("Stanza:") |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2382 print("\t"..runner.current_item:indent(2):pretty_print()); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2383 else |
|
13338
470ab6b55e93
mod_admin_shell: Fix lint [luacheck]
Kim Alvefur <zash@zash.se>
parents:
13334
diff
changeset
|
2384 print("Work item", self.session.serialize(runner.current_item, "debug")); |
|
13334
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2385 end |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2386 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2387 |
|
13334
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2388 print("Coroutine ", tostring(runner.thread).." ("..coroutine.status(runner.thread)..")"); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2389 print("Since ", since); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2390 print("Status ", ("%s since %s (%0.2f seconds ago)"):format(runner.state, os.date("%Y-%m-%d %R:%S", math.floor(since)), time_now-since)); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2391 print(""); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2392 print(debug.traceback(runner.thread)); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2393 return true, "Runner is "..runner.state; |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2394 end |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2395 end |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2396 return nil, "Runner not found or is currently idle"; |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2397 end |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2398 |
|
13338
470ab6b55e93
mod_admin_shell: Fix lint [luacheck]
Kim Alvefur <zash@zash.se>
parents:
13334
diff
changeset
|
2399 local row = format_table({ |
|
470ab6b55e93
mod_admin_shell: Fix lint [luacheck]
Kim Alvefur <zash@zash.se>
parents:
13334
diff
changeset
|
2400 { title = "ID"; width = 12 }; |
|
470ab6b55e93
mod_admin_shell: Fix lint [luacheck]
Kim Alvefur <zash@zash.se>
parents:
13334
diff
changeset
|
2401 { title = "Function"; width = "10p" }; |
|
470ab6b55e93
mod_admin_shell: Fix lint [luacheck]
Kim Alvefur <zash@zash.se>
parents:
13334
diff
changeset
|
2402 { title = "Status"; width = "16" }; |
|
470ab6b55e93
mod_admin_shell: Fix lint [luacheck]
Kim Alvefur <zash@zash.se>
parents:
13334
diff
changeset
|
2403 { title = "Location"; width = "10p" }; |
|
470ab6b55e93
mod_admin_shell: Fix lint [luacheck]
Kim Alvefur <zash@zash.se>
parents:
13334
diff
changeset
|
2404 }, self.session.width); |
|
13334
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2405 print(row()) |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2406 |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2407 local c = 0; |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2408 for runner, since in pairs(async.waiting_runners) do |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2409 c = c + 1; |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2410 local f = runner.func; |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2411 if f == async.default_runner_func then |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2412 f = runner.current_item; |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2413 end |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2414 -- We want to fetch the location in the code that the runner yielded from, |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2415 -- excluding util.async's wrapper code. A level of `2` assumes that we |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2416 -- yielded directly from a function in util.async. This is *currently* true |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2417 -- of all util.async yields, but it's fragile. |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2418 local location = debug.getinfo(runner.thread, 2); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2419 print(row { |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2420 runner.id; |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2421 tostring(f); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2422 ("%s (%0.2fs)"):format(runner.state, time_now - since); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2423 location.short_src..(location.currentline and ":"..location.currentline or ""); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2424 }); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2425 end |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2426 return true, ("%d runners pending"):format(c); |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2427 end |
|
aefcb6b4f47d
mod_admin_shell: Add debug:async() command to show blocked async runners
Matthew Wild <mwild1@gmail.com>
parents:
13287
diff
changeset
|
2428 |
|
13819
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2429 describe_command [[debug:cert_index([path]) - Show Prosody's view of a directory of certs]] |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2430 function def_env.debug:cert_index(path) |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2431 local print = self.session.print; |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2432 local cm = require "core.certmanager"; |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2433 |
|
14090
2aeb5dcb36bf
mod_admin_shell: Make cert index search path relative to config file
Kim Alvefur <zash@zash.se>
parents:
13999
diff
changeset
|
2434 path = path or module:get_option_path("certificates", "certs", "config"); |
|
13819
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2435 |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2436 local sink = logger.add_simple_sink(function (source, level, message) |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2437 if source == "certmanager" then |
|
13823
e78e79f1b5f5
mod_admin_shell: Visual tweaks to the output of debug:cert_index()
Matthew Wild <mwild1@gmail.com>
parents:
13819
diff
changeset
|
2438 if level == "debug" or level == "info" then |
|
e78e79f1b5f5
mod_admin_shell: Visual tweaks to the output of debug:cert_index()
Matthew Wild <mwild1@gmail.com>
parents:
13819
diff
changeset
|
2439 level = "II"; |
|
e78e79f1b5f5
mod_admin_shell: Visual tweaks to the output of debug:cert_index()
Matthew Wild <mwild1@gmail.com>
parents:
13819
diff
changeset
|
2440 elseif level == "warn" or level == "error" then |
|
e78e79f1b5f5
mod_admin_shell: Visual tweaks to the output of debug:cert_index()
Matthew Wild <mwild1@gmail.com>
parents:
13819
diff
changeset
|
2441 level = "EE"; |
|
e78e79f1b5f5
mod_admin_shell: Visual tweaks to the output of debug:cert_index()
Matthew Wild <mwild1@gmail.com>
parents:
13819
diff
changeset
|
2442 end |
|
e78e79f1b5f5
mod_admin_shell: Visual tweaks to the output of debug:cert_index()
Matthew Wild <mwild1@gmail.com>
parents:
13819
diff
changeset
|
2443 self.session.print(level..": "..message); |
|
13819
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2444 end |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2445 end); |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2446 |
|
13823
e78e79f1b5f5
mod_admin_shell: Visual tweaks to the output of debug:cert_index()
Matthew Wild <mwild1@gmail.com>
parents:
13819
diff
changeset
|
2447 print("II: Scanning "..path.."..."); |
|
e78e79f1b5f5
mod_admin_shell: Visual tweaks to the output of debug:cert_index()
Matthew Wild <mwild1@gmail.com>
parents:
13819
diff
changeset
|
2448 |
|
13819
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2449 local index = {}; |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2450 cm.index_certs(path, index) |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2451 |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2452 if not logger.remove_sink(sink) then |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2453 module:log("warn", "Unable to remove log sink"); |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2454 end |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2455 |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2456 local c, max_domain = 0, 8; |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2457 for domain in pairs(index) do |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2458 if #domain > max_domain then |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2459 max_domain = #domain; |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2460 end |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2461 end |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2462 |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2463 print(""); |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2464 |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2465 local row = format_table({ |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2466 { title = "Domain", width = max_domain }; |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2467 { title = "Certificate", width = "100%" }; |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2468 { title = "Service", width = 5 }; |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2469 }, self.session.width); |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2470 print(row()); |
|
13823
e78e79f1b5f5
mod_admin_shell: Visual tweaks to the output of debug:cert_index()
Matthew Wild <mwild1@gmail.com>
parents:
13819
diff
changeset
|
2471 print(("-"):rep(self.session.width or 80)); |
|
13819
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2472 for domain, certs in it.sorted_pairs(index) do |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2473 for cert_file, services in it.sorted_pairs(certs) do |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2474 for service in it.sorted_pairs(services) do |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2475 c = c + 1; |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2476 print(row({ domain, cert_file, service })); |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2477 end |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2478 end |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2479 end |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2480 |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2481 print(""); |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2482 |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2483 return true, ("Showing %d certificates in %s"):format(c, path); |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2484 end |
|
3ee95eb17045
mod_admin_shell: Add debug:cert_index() command
Matthew Wild <mwild1@gmail.com>
parents:
13796
diff
changeset
|
2485 |
|
13828
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2486 def_env.role = new_section("Role and access management"); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2487 |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2488 describe_command [[role:list(host) - List known roles]] |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2489 function def_env.role:list(host) |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2490 if not host then |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2491 return nil, "Specify which host to list roles for"; |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2492 end |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2493 local role_list = {}; |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2494 for _, role in it.sorted_pairs(um.get_all_roles(host)) do |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2495 table.insert(role_list, role); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2496 end |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2497 table.sort(role_list, function (a, b) |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2498 if a.priority ~= b.priority then |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2499 return (a.priority or 0) > (b.priority or 0); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2500 end |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2501 return a.name < b.name; |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2502 end); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2503 for _, role in ipairs(role_list) do |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2504 self.session.print(role.name); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2505 end |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2506 return true, ("Showing %d roles on %s"):format(#role_list, host); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2507 end |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2508 |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2509 describe_command [[role:show(host, role_name) - Show information about a role]] |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2510 function def_env.role:show(host, role_name) |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2511 if not host or not role_name then |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2512 return nil, "Specify the host and role to show"; |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2513 end |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2514 |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2515 local print = self.session.print; |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2516 local role = um.get_role_by_name(role_name, host); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2517 |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2518 if not role then |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2519 return nil, ("Unable to find role %s on host %s"):format(role_name, host); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2520 end |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2521 |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2522 local inherits = {}; |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2523 for _, inherited_role in ipairs(role.inherits or {}) do |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2524 table.insert(inherits, inherited_role.name); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2525 end |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2526 |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2527 local permissions = {}; |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2528 for permission, is_allowed in role:policies() do |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2529 permissions[permission] = is_allowed and "allowed" or "denied"; |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2530 end |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2531 |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2532 print("Name: ", role.name); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2533 print("Inherits:", table.concat(inherits, ", ")); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2534 print("Policies:"); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2535 local c = 0; |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2536 for permission, policy in it.sorted_pairs(permissions) do |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2537 c = c + 1; |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2538 print(" ["..(policy == "allowed" and "+" or " ").."] " .. permission); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2539 end |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2540 print(""); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2541 return true, ("Showing role %s with %d policies"):format(role.name, c); |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2542 end |
|
a071b20ccc0f
mod_admin_shell: Add role:list() and role:show() commands
Matthew Wild <mwild1@gmail.com>
parents:
13823
diff
changeset
|
2543 |
|
13349
d5d4e386c6fb
mod_admin_shell: Refactor help to data structures for extensibility
Matthew Wild <mwild1@gmail.com>
parents:
13338
diff
changeset
|
2544 def_env.stats = new_section("Commands to show internal statistics"); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2545 |
|
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
2546 local short_units = { |
|
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
2547 seconds = "s", |
|
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
2548 bytes = "B", |
|
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
2549 }; |
|
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
2550 |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2551 local stats_methods = {}; |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2552 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2553 function stats_methods:render_single_fancy_histogram_ex(print, prefix, metric_family, metric, cumulative) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2554 local creation_timestamp, sum, count |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2555 local buckets = {} |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2556 local prev_bucket_count = 0 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2557 for suffix, extra_labels, value in metric:iter_samples() do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2558 if suffix == "_created" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2559 creation_timestamp = value |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2560 elseif suffix == "_sum" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2561 sum = value |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2562 elseif suffix == "_count" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2563 count = value |
|
12226
7db81c9cbbbf
mod_admin_shell: Fix traceback on rendering graph of stats without extra labels
Kim Alvefur <zash@zash.se>
parents:
12225
diff
changeset
|
2564 elseif extra_labels then |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2565 local bucket_threshold = extra_labels["le"] |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2566 local bucket_count |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2567 if cumulative then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2568 bucket_count = value |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2569 else |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2570 bucket_count = value - prev_bucket_count |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2571 prev_bucket_count = value |
|
10887
3debe04a6162
mod_admin_shell: Format stats with util.human.units
Kim Alvefur <zash@zash.se>
parents:
10878
diff
changeset
|
2572 end |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2573 if bucket_threshold == "+Inf" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2574 t_insert(buckets, {threshold = 1/0, count = bucket_count}) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2575 elseif bucket_threshold ~= nil then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2576 t_insert(buckets, {threshold = tonumber(bucket_threshold), count = bucket_count}) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2577 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2578 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2579 end |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2580 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2581 if #buckets == 0 or not creation_timestamp or not sum or not count then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2582 print("[no data or not a histogram]") |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2583 return false |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2584 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2585 |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2586 local graph_width, graph_height, wscale = #buckets, 10, 1; |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2587 if graph_width < 8 then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2588 wscale = 8 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2589 elseif graph_width < 16 then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2590 wscale = 4 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2591 elseif graph_width < 32 then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2592 wscale = 2 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2593 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2594 local eighth_chars = " ▁▂▃▄▅▆▇█"; |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2595 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2596 local max_bin_samples = 0 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2597 for _, bucket in ipairs(buckets) do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2598 if bucket.count > max_bin_samples then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2599 max_bin_samples = bucket.count |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2600 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2601 end |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2602 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2603 print(""); |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2604 print(prefix) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2605 print(("_"):rep(graph_width*wscale).." "..max_bin_samples); |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2606 for row = graph_height, 1, -1 do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2607 local row_chars = {}; |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2608 local min_eighths, max_eighths = 8, 0; |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2609 for i = 1, #buckets do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2610 local char_eighths = math.ceil(math.max(math.min((graph_height/(max_bin_samples/buckets[i].count))-(row-1), 1), 0)*8); |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2611 if char_eighths < min_eighths then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2612 min_eighths = char_eighths; |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2613 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2614 if char_eighths > max_eighths then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2615 max_eighths = char_eighths; |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2616 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2617 if char_eighths == 0 then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2618 row_chars[i] = ("-"):rep(wscale); |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2619 else |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2620 local char = eighth_chars:sub(char_eighths*3+1, char_eighths*3+3); |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2621 row_chars[i] = char:rep(wscale); |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2622 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2623 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2624 print(table.concat(row_chars).."|- "..string.format("%.8g", math.ceil((max_bin_samples/graph_height)*(row-0.5)))); |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2625 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2626 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2627 local legend_pat = string.format("%%%d.%dg", wscale-1, wscale-1) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2628 local row = {} |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2629 for i = 1, #buckets do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2630 local threshold = buckets[i].threshold |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2631 t_insert(row, legend_pat:format(threshold)) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2632 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2633 t_insert(row, " " .. metric_family.unit) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2634 print(t_concat(row, "/")) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2635 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2636 return true |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2637 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2638 |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2639 function stats_methods:render_single_fancy_histogram(print, prefix, metric_family, metric) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2640 return self:render_single_fancy_histogram_ex(print, prefix, metric_family, metric, false) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2641 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2642 |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2643 function stats_methods:render_single_fancy_histogram_cf(print, prefix, metric_family, metric) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2644 -- cf = cumulative frequency |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2645 return self:render_single_fancy_histogram_ex(print, prefix, metric_family, metric, true) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2646 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2647 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2648 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
|
2649 for _, stat_info in ipairs(self) do |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2650 local family_name, metric_family = unpack(stat_info, 1, 2) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2651 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
|
2652 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
|
2653 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2654 |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2655 if not self:render_family(print, family_name, metric_family, self.render_single_fancy_histogram_cf) then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2656 return self |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2657 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2658 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2659 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
|
2660 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2661 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2662 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
|
2663 for _, stat_info in ipairs(self) do |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2664 local family_name, metric_family = unpack(stat_info, 1, 2) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2665 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
|
2666 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
|
2667 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2668 |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2669 if not self:render_family(print, family_name, metric_family, self.render_single_fancy_histogram) then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2670 return self |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2671 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2672 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2673 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
|
2674 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2675 |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2676 function stats_methods:render_single_counter(print, prefix, metric_family, metric) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2677 local created_timestamp, current_value |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2678 for suffix, _, value in metric:iter_samples() do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2679 if suffix == "_created" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2680 created_timestamp = value |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2681 elseif suffix == "_total" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2682 current_value = value |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2683 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2684 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2685 if current_value and created_timestamp then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2686 local base_unit = short_units[metric_family.unit] or metric_family.unit |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2687 local unit = base_unit .. "/s" |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2688 local factor = 1 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2689 if base_unit == "s" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2690 -- be smart! |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2691 unit = "%" |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2692 factor = 100 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2693 elseif base_unit == "" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2694 unit = "events/s" |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2695 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2696 print(("%-50s %s"):format(prefix, format_number(factor * current_value / (self.now - created_timestamp), unit.." [avg]"))); |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2697 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2698 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2699 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2700 function stats_methods:render_single_gauge(print, prefix, metric_family, metric) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2701 local current_value |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2702 for _, _, value in metric:iter_samples() do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2703 current_value = value |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2704 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2705 if current_value then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2706 local unit = short_units[metric_family.unit] or metric_family.unit |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2707 print(("%-50s %s"):format(prefix, format_number(current_value, unit))); |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2708 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2709 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2710 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2711 function stats_methods:render_single_summary(print, prefix, metric_family, metric) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2712 local sum, count |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2713 for suffix, _, value in metric:iter_samples() do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2714 if suffix == "_sum" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2715 sum = value |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2716 elseif suffix == "_count" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2717 count = value |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2718 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2719 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2720 if sum and count then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2721 local unit = short_units[metric_family.unit] or metric_family.unit |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2722 if count == 0 then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2723 print(("%-50s %s"):format(prefix, "no obs.")); |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2724 else |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2725 print(("%-50s %s"):format(prefix, format_number(sum / count, unit.."/event [avg]"))); |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2726 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2727 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2728 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2729 |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2730 function stats_methods:render_family(print, family_name, metric_family, render_func) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2731 local labelkeys = metric_family.label_keys |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2732 if #labelkeys > 0 then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2733 print(family_name) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2734 for labelset, metric in metric_family:iter_metrics() do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2735 local labels = {} |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2736 for i, k in ipairs(labelkeys) do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2737 local v = labelset[i] |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2738 t_insert(labels, ("%s=%s"):format(k, v)) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2739 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2740 local prefix = " "..t_concat(labels, " ") |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2741 render_func(self, print, prefix, metric_family, metric) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2742 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2743 else |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2744 for _, metric in metric_family:iter_metrics() do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2745 render_func(self, print, family_name, metric_family, metric) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2746 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2747 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2748 end |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2749 |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2750 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
|
2751 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
|
2752 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
|
2753 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
|
2754 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
|
2755 print(""); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2756 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
|
2757 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
|
2758 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2759 print(""); |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2760 else |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2761 local metric_family = stat_info[2] |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2762 if metric_family.type_ == "counter" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2763 stats:render_family(print, stat_info[1], metric_family, stats.render_single_counter) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2764 elseif metric_family.type_ == "gauge" or metric_family.type_ == "unknown" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2765 stats:render_family(print, stat_info[1], metric_family, stats.render_single_gauge) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2766 elseif metric_family.type_ == "summary" or metric_family.type_ == "histogram" then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2767 stats:render_family(print, stat_info[1], metric_family, stats.render_single_summary) |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2768 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2769 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2770 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2771 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
|
2772 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2773 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2774 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
|
2775 local function new_stats_context(self) |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2776 -- TODO: instead of now(), it might be better to take the time of the last |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2777 -- interval, if the statistics backend is set to use periodic collection |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2778 -- Otherwise we get strange stuff like average cpu usage decreasing until |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2779 -- the next sample and so on. |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2780 return setmetatable({ session = self.session, stats = true, now = time.now() }, stats_mt); |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2781 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2782 |
|
13354
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
2783 describe_command [[stats:show(pattern) - Show internal statistics, optionally filtering by name with a pattern.]] |
|
83f3076965f6
mod_admin_shell: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13352
diff
changeset
|
2784 -- Undocumented currently, you can append :histogram() or :cfgraph() to stats:show() for rendered graphs. |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2785 function def_env.stats:show(name_filter) |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12927
diff
changeset
|
2786 local statsman = require "prosody.core.statsmanager" |
|
13582
67c9fc643873
mod_admin_shell: stats:show(): Friendlier error message when statistics disabled
Matthew Wild <mwild1@gmail.com>
parents:
13562
diff
changeset
|
2787 local metric_registry = statsman.get_metric_registry(); |
|
67c9fc643873
mod_admin_shell: stats:show(): Friendlier error message when statistics disabled
Matthew Wild <mwild1@gmail.com>
parents:
13562
diff
changeset
|
2788 if not metric_registry then |
|
67c9fc643873
mod_admin_shell: stats:show(): Friendlier error message when statistics disabled
Matthew Wild <mwild1@gmail.com>
parents:
13562
diff
changeset
|
2789 return nil, [[Statistics disabled. Try `statistics = "internal"` in the global section of the config file and restart.]]; |
|
67c9fc643873
mod_admin_shell: stats:show(): Friendlier error message when statistics disabled
Matthew Wild <mwild1@gmail.com>
parents:
13562
diff
changeset
|
2790 end |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2791 local collect = statsman.collect |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2792 if collect then |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2793 -- force collection if in manual mode |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2794 collect() |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2795 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2796 local displayed_stats = new_stats_context(self); |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2797 for family_name, metric_family in iterators.sorted_pairs(metric_registry:get_metric_families()) do |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2798 if not name_filter or family_name:match(name_filter) then |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2799 table.insert(displayed_stats, { |
|
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2800 family_name, |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2801 metric_family, |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2802 output = {} |
|
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
11504
diff
changeset
|
2803 }) |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2804 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2805 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2806 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
|
2807 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2808 |
|
13350
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2809 local command_metadata_schema = { |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2810 type = "object"; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2811 properties = { |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2812 section = { type = "string" }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2813 section_desc = { type = "string" }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2814 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2815 name = { type = "string" }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2816 desc = { type = "string" }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2817 help = { type = "string" }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2818 args = { |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2819 type = "array"; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2820 items = { |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2821 type = "object"; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2822 properties = { |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2823 name = { type = "string", required = true }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2824 type = { type = "string", required = false }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2825 }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2826 }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2827 }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2828 }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2829 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2830 required = { "name", "section", "desc", "args" }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2831 }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2832 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2833 -- host_commands[section..":"..name][host] = handler |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2834 -- host_commands[section..":"..name][false] = metadata |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2835 local host_commands = {}; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2836 |
|
14113
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2837 -- Remove command handlers for a host (specify name to clear just one command) |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2838 function clear_host_commands(host, name) |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2839 for command_name, command_info in pairs(host_commands) do |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2840 if not name or name == command_name then |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2841 command_info[host] = nil; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2842 local has_any_host_handlers_left; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2843 for k in pairs(command_info) do |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2844 if k ~= false then |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2845 has_any_host_handlers_left = true; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2846 break; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2847 end |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2848 end |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2849 if not has_any_host_handlers_left then |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2850 host_commands[command_name] = nil; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2851 end |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2852 if name then |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2853 break; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2854 end |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2855 end |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2856 end |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2857 end |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2858 |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2859 -- This returns a wrapper function which routes to the correct handler for a host |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2860 local function new_host_command_handler(qualified_name, selector_name, selector_index) |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2861 return function (...) |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2862 local selected_host = select(2, jid_split((select(selector_index, ...)))); |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2863 if type(selected_host) ~= "string" then |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2864 return nil, "Invalid or missing argument '"..selector_name.."'"; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2865 end |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2866 if not prosody.hosts[selected_host] then |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2867 return nil, "Unknown host: "..selected_host; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2868 end |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2869 local host_handler = host_commands[qualified_name][selected_host]; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2870 if not host_handler then |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2871 return nil, "This command is not available on "..selected_host; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2872 end |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2873 return host_handler(...); |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2874 end; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2875 end |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2876 |
|
13350
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2877 local function new_item_handlers(command_host) |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2878 local function on_command_added(event) |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2879 local command = event.item; |
|
13603
6e5124f72e9a
mod_admin_shell: Fix reporting origin module for commands
Kim Alvefur <zash@zash.se>
parents:
13598
diff
changeset
|
2880 local mod_name = event.source and ("mod_"..event.source.name) or "<unknown module>"; |
|
13350
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2881 if not schema.validate(command_metadata_schema, command) or type(command.handler) ~= "function" then |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2882 module:log("warn", "Ignoring command added by %s: missing or invalid data", mod_name); |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2883 return; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2884 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2885 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2886 local handler = command.handler; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2887 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2888 if command_host then |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2889 if type(command.host_selector) ~= "string" then |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2890 module:log("warn", "Ignoring command %s:%s() added by %s - missing/invalid host_selector", command.section, command.name, mod_name); |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2891 return; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2892 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2893 local qualified_name = command.section..":"..command.name; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2894 local host_command_info = host_commands[qualified_name]; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2895 if not host_command_info then |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2896 local selector_index; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2897 for i, arg in ipairs(command.args) do |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2898 if arg.name == command.host_selector then |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2899 selector_index = i + 1; -- +1 to account for 'self' |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2900 break; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2901 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2902 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2903 if not selector_index then |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2904 module:log("warn", "Command %s() host selector argument '%s' not found - not registering", qualified_name, command.host_selector); |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2905 return; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2906 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2907 host_command_info = { |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2908 [false] = { |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2909 host_selector = command.host_selector; |
|
14113
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2910 handler = new_host_command_handler(qualified_name, command.host_selector, selector_index); |
|
13350
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2911 }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2912 }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2913 host_commands[qualified_name] = host_command_info; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2914 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2915 if host_command_info[command_host] then |
|
14113
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2916 module:log("warn", "Command %s() is already registered on %s - overwriting with %s", qualified_name, command_host, mod_name); |
|
13350
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2917 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2918 host_command_info[command_host] = handler; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2919 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2920 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2921 local section_t = def_env[command.section]; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2922 if not section_t then |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2923 section_t = {}; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2924 def_env[command.section] = section_t; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2925 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2926 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2927 if command_host then |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2928 section_t[command.name] = host_commands[command.section..":"..command.name][false].handler; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2929 else |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2930 section_t[command.name] = command.handler; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2931 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2932 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2933 local section_mt = getmetatable(section_t); |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2934 if not section_mt then |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2935 section_mt = {}; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2936 setmetatable(section_t, section_mt); |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2937 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2938 local section_help = section_mt.help; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2939 if not section_help then |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2940 section_help = { |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2941 desc = command.section_desc; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2942 commands = {}; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2943 }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2944 section_mt.help = section_help; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2945 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2946 |
|
13734
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
2947 if command.flags then |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
2948 if command.flags.stop_on_positional == nil then |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
2949 command.flags.stop_on_positional = false; |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
2950 end |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
2951 if command.flags.strict == nil then |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
2952 command.flags.strict = true; |
|
c133635d0bc6
mod_admin_shell: Improved error handling for shell-invoked commands
Matthew Wild <mwild1@gmail.com>
parents:
13732
diff
changeset
|
2953 end |
|
13732
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
2954 end |
|
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
2955 |
|
13350
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2956 section_help.commands[command.name] = { |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2957 desc = command.desc; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2958 full = command.help; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2959 args = array(command.args); |
|
13732
1465b1e305df
mod_admin_shell, util.prosodyctl.shell: Process command-line args on server-side, with argparse support
Matthew Wild <mwild1@gmail.com>
parents:
13687
diff
changeset
|
2960 flags = command.flags; |
|
13350
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2961 module = command._provided_by; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2962 }; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2963 |
|
13605
74a8006ee7f6
mod_admin_shell: Remove redundant 'mod_' prefix from debug message
Kim Alvefur <zash@zash.se>
parents:
13603
diff
changeset
|
2964 module:log("debug", "Shell command added by %s: %s:%s()", mod_name, command.section, command.name); |
|
13350
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2965 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2966 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2967 local function on_command_removed(event) |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2968 local command = event.item; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2969 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2970 local handler = event.item.handler; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2971 if type(handler) ~= "function" or not schema.validate(command_metadata_schema, command) then |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2972 return; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2973 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2974 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2975 local section_t = def_env[command.section]; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2976 if not section_t or section_t[command.name] ~= handler then |
|
14113
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2977 -- Handler doesn't match, but it could be the host-selector wrapper |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2978 -- Let's try removing a per-host command |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2979 local qualified_name = command.section..":"..command.name; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2980 local host_command_handlers = host_commands[qualified_name]; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2981 if host_command_handlers then |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2982 -- Bingo! |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2983 module:log("debug", "Removing command %s from %s", qualified_name, command_host); |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2984 clear_host_commands(command_host, qualified_name); |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2985 elseif section_t then |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2986 module:log("warn", "Not removing shell command: handler mismatch: %q ~= %q", section_t and section_t[command.name], handler); |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2987 return; |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
2988 end |
|
13350
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2989 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2990 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2991 section_t[command.name] = nil; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2992 if next(section_t) == nil then -- Delete section if empty |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2993 def_env[command.section] = nil; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2994 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2995 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2996 return on_command_added, on_command_removed; |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2997 end |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2998 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
2999 module:handle_items("shell-command", new_item_handlers()); |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
3000 |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
3001 function module.add_host(host_module) |
|
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
3002 host_module:handle_items("shell-command", new_item_handlers(host_module.host)); |
|
14113
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
3003 function host_module.unload() |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
3004 -- Due to non-deterministic unload order, we might not see item |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
3005 -- removal events for all commands before we get unloaded, so |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
3006 -- we clear everything from the host explicitly when we're |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
3007 -- unloaded (also sensible if we are unloaded manually) |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
3008 clear_host_commands(host_module.host); |
|
b9688ac25255
mod_admin_shell: Improve per-host command cleanup
Matthew Wild <mwild1@gmail.com>
parents:
14090
diff
changeset
|
3009 end |
|
13350
0573401b0f9f
mod_admin_shell: Support for 'shell-command' items (global and per-host)
Matthew Wild <mwild1@gmail.com>
parents:
13349
diff
changeset
|
3010 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3011 |
|
12464
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
3012 function module.unload() |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
3013 stanza_watchers.cleanup(); |
|
f4c59af273a3
mod_admin_shell: Add watch:stanzas() command
Matthew Wild <mwild1@gmail.com>
parents:
12399
diff
changeset
|
3014 end |
|
10856
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3015 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3016 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3017 ------------- |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3018 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3019 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
|
3020 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
|
3021 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
|
3022 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
|
3023 ____ \ / _ |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3024 | _ \ _ __ ___ ___ _-_ __| |_ _ |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3025 | |_) | '__/ _ \/ __|/ _ \ / _` | | | | |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3026 | __/| | | (_) \__ \ |_| | (_| | |_| | |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3027 |_| |_| \___/|___/\___/ \__,_|\__, | |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3028 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
|
3029 |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3030 ]] |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3031 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3032 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
|
3033 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
|
3034 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
|
3035 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
|
3036 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3037 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
|
3038 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
|
3039 end |
|
c99711eda0d1
mod_admin_shell: New module that implements the console interface over an admin socket
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3040 end |
