aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-04-29 22:23:05 +0200
committerKim Alvefur <zash@zash.se>2020-04-29 22:23:05 +0200
commitedce14b4a40664a6f10239d7f2ef50421f6a93af (patch)
tree23ac15702d28ba1b474eab4f39ebbb577f6df9f8 /plugins
parentb966c976903eecced5a16826ef2da07cb011809f (diff)
downloadprosody-edce14b4a40664a6f10239d7f2ef50421f6a93af.tar.gz
prosody-edce14b4a40664a6f10239d7f2ef50421f6a93af.zip
mod_admin_telnet: Pretty-print values returned from commands
This makes it much nicer to inspect Prosody internals. Existing textual status messages from commands are not serialized to preserve existing behavior. Explicit serialization of configuration is kept in order to make it clear that returned strings are serialized strings that would look like what's actually in the config file. The default maxdepth of 2 seems ought to be an okay default, balanced between showing enough structure to continue exploring and DoS-ing your terminal. Thanks to Ge0rG for the motivation to finally do this.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_admin_telnet.lua17
1 files changed, 13 insertions, 4 deletions
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua
index 2efd424c..5407b737 100644
--- a/plugins/mod_admin_telnet.lua
+++ b/plugins/mod_admin_telnet.lua
@@ -32,7 +32,8 @@ local envload = require "util.envload".envload;
local envloadfile = require "util.envload".envloadfile;
local has_pposix, pposix = pcall(require, "util.pposix");
local async = require "util.async";
-local serialize = require "util.serialization".new({ fatal = false, unquoted = true});
+local serialization = require "util.serialization";
+local serialize_config = serialization.new ({ fatal = false, unquoted = true});
local time = require "util.time";
local commands = module:shared("commands")
@@ -80,6 +81,7 @@ function console:new_session(conn)
end
w("| "..table.concat(t, "\t").."\n");
end;
+ serialize = serialization.new({ fatal = false, unquoted = true, maxdepth = 2});
disconnect = function () conn:close(); end;
};
session.env = setmetatable({}, default_env_mt);
@@ -141,7 +143,10 @@ function console:process_line(session, line)
local taskok, message = chunk();
if not message then
- session.print("Result: "..tostring(taskok));
+ if type(taskok) ~= "string" then
+ taskok = session.serialize(taskok);
+ end
+ session.print("Result: "..taskok);
return;
elseif (not taskok) and message then
session.print("Command completed with a problem");
@@ -149,7 +154,11 @@ function console:process_line(session, line)
return;
end
- session.print("OK: "..tostring(message));
+ if type(message) ~= "string" then
+ message = session.serialize(message);
+ end
+
+ session.print("OK: "..message);
end
local sessions = {};
@@ -527,7 +536,7 @@ function def_env.config:get(host, key)
host, key = "*", host;
end
local config_get = require "core.configmanager".get
- return true, serialize(config_get(host, key));
+ return true, serialize_config(config_get(host, key));
end
function def_env.config:reload()