module.host = "*";
+local _G = _G;
+
local prosody = _G.prosody;
local hosts = prosody.hosts;
local connlisteners_register = require "net.connlisteners".register;
local def_env = {};
local default_env_mt = { __index = def_env };
+local function redirect_output(_G, session)
+ return setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end, __newindex = function (t, k, v) rawset(_G, k, v); end });
+end
+
console = {};
function console:new_session(conn)
end
end
- setfenv(chunk, (useglobalenv and _G) or session.env or nil);
+ setfenv(chunk, (useglobalenv and redirect_output(_G, session)) or session.env or nil);
local ranok, taskok, message = pcall(chunk);
def_env.module = {};
-local function get_hosts_set(hosts)
+local function get_hosts_set(hosts, module)
if type(hosts) == "table" then
if hosts[1] then
return set.new(hosts);
elseif type(hosts) == "string" then
return set.new { hosts };
elseif hosts == nil then
+ local mm = require "modulemanager";
return set.new(array.collect(keys(prosody.hosts)))
- / function (host) return prosody.hosts[host].type == "local"; end;
+ / function (host) return prosody.hosts[host].type == "local" or module and mm.is_loaded(host, module); end;
end
end
function def_env.module:unload(name, hosts)
local mm = require "modulemanager";
- hosts = get_hosts_set(hosts);
+ hosts = get_hosts_set(hosts, name);
-- Unload the module for each host
local ok, err, count = true, nil, 0;
function def_env.module:reload(name, hosts)
local mm = require "modulemanager";
- hosts = get_hosts_set(hosts);
+ hosts = get_hosts_set(hosts, name);
-- Reload the module for each host
local ok, err, count = true, nil, 0;
else
print("Closed "..count.." incoming session"..((count == 1 and "") or "s").." from "..from.." to "..to);
end
- elseif hosts[to] and hosts[from]
+ elseif hosts[to] and hosts[from] then
return false, "Both of the hostnames you specified are local, there are no s2s sessions to close";
else
return false, "Neither of the hostnames you specified are being used on this server";