diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mod_admin_telnet.lua | 22 | ||||
-rw-r--r-- | plugins/storage/sqlbasic.lib.lua | 4 |
2 files changed, 15 insertions, 11 deletions
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index ca37ca7a..ebd817b5 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -15,12 +15,17 @@ local hosts = prosody.hosts; local console_listener = { default_port = 5582; default_mode = "*a"; interface = "127.0.0.1" }; +local hostmanager = require "core.hostmanager"; +local modulemanager = require "core.modulemanager"; + local iterators = require "util.iterators"; local keys, values = iterators.keys, iterators.values; local jid = require "util.jid"; local jid_bare, jid_split = jid.bare, jid.split; local set, array = require "util.set", require "util.array"; local cert_verify_identity = require "util.x509".verify_identity; +local envload = require "util.envload".envload; +local envloadfile = require "util.envload".envloadfile; local commands = module:shared("commands") local def_env = module:shared("env"); @@ -30,9 +35,9 @@ local core_post_stanza = prosody.core_post_stanza; local function redirect_output(_G, session) local env = setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end }); env.dofile = function(name) - local f, err = loadfile(name); + local f, err = envloadfile(name, env); if not f then return f, err; end - return setfenv(f, env)(); + return f(); end; return env; end @@ -104,9 +109,10 @@ function console_listener.onincoming(conn, data) session.env._ = line; local chunkname = "=console"; - local chunk, err = loadstring("return "..line, chunkname); + local env = (useglobalenv and redirect_output(_G, session)) or session.env or nil + local chunk, err = envload("return "..line, chunkname, env); if not chunk then - chunk, err = loadstring(line, chunkname); + chunk, err = envload(line, chunkname, env); if not chunk then err = err:gsub("^%[string .-%]:%d+: ", ""); err = err:gsub("^:%d+: ", ""); @@ -115,9 +121,7 @@ function console_listener.onincoming(conn, data) break; end end - - setfenv(chunk, (useglobalenv and redirect_output(_G, session)) or session.env or nil); - + local ranok, taskok, message = pcall(chunk); if not (ranok or message or useglobalenv) and commands[line:lower()] then @@ -642,6 +646,7 @@ local function print_errors(print, errors) end function def_env.s2s:showcert(domain) + local ser = require "util.serialization".serialize; local print = self.session.print; local domain_sessions = set.new(array.collect(keys(incoming_s2s))) /function(session) return session.from_host == domain and session or nil; end; @@ -973,8 +978,7 @@ if option and option ~= "short" and option ~= "full" and option ~= "graphic" the if type(option) == "string" then session.print(option) elseif type(option) == "function" then - setfenv(option, redirect_output(_G, session)); - pcall(option, session); + module:log("warn", "Using functions as value for the console_banner option is no longer supported"); end end end diff --git a/plugins/storage/sqlbasic.lib.lua b/plugins/storage/sqlbasic.lib.lua index f1202287..ab3648f9 100644 --- a/plugins/storage/sqlbasic.lib.lua +++ b/plugins/storage/sqlbasic.lib.lua @@ -3,12 +3,12 @@ -- This driver stores data as simple key-values local ser = require "util.serialization".serialize; +local envload = require "util.envload".envload; local deser = function(data) module:log("debug", "deser: %s", tostring(data)); if not data then return nil; end - local f = loadstring("return "..data); + local f = envload("return "..data, nil, {}); if not f then return nil; end - setfenv(f, {}); local s, d = pcall(f); if not s then return nil; end return d; |