# HG changeset patch # User Kim Alvefur # Date 1588191785 -7200 # Node ID 459efb1afbfef1056b6862da22167a1346c338da # Parent a1b633ba9bd918b4a29e6eb73f0218ba45c9a3a2 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. diff -r a1b633ba9bd9 -r 459efb1afbfe plugins/mod_admin_telnet.lua --- a/plugins/mod_admin_telnet.lua Mon Apr 27 14:46:15 2020 +0200 +++ b/plugins/mod_admin_telnet.lua Wed Apr 29 22:23:05 2020 +0200 @@ -32,7 +32,8 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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()