--- Copyright (C) 2009-2010 Florian Zeitz
+-- Copyright (C) 2009-2011 Florian Zeitz
--
-- This file is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
local hosts = prosody.hosts;
local t_concat = table.concat;
-require "util.iterators";
+local iterators = require "util.iterators";
+local keys, values = iterators.keys, iterators.values;
local usermanager_user_exists = require "core.usermanager".user_exists;
local usermanager_create_user = require "core.usermanager".create_user;
+local usermanager_delete_user = require "core.usermanager".delete_user;
local usermanager_get_password = require "core.usermanager".get_password;
local usermanager_set_password = require "core.usermanager".set_password;
+local hostmanager_activate = require "core.hostmanager".activate;
+local hostmanager_deactivate = require "core.hostmanager".deactivate;
local is_admin = require "core.usermanager".is_admin;
local rm_load_roster = require "core.rostermanager".load_roster;
local st, jid, uuid = require "util.stanza", require "util.jid", require "util.uuid";
local dataforms_new = require "util.dataforms".new;
local array = require "util.array";
local modulemanager = require "modulemanager";
+local core_post_stanza = prosody.core_post_stanza;
+module:depends("adhoc");
local adhoc_new = module:require "adhoc".new;
+local function generate_error_message(errors)
+ local errmsg = {};
+ for name, err in pairs(errors) do
+ errmsg[#errmsg + 1] = name .. ": " .. err;
+ end
+ return { status = "completed", error = { message = t_concat(errmsg, "\n") } };
+end
+
function add_user_command_handler(self, data, state)
local add_user_layout = dataforms_new{
title = "Adding a User";
if data.action == "cancel" then
return { status = "canceled" };
end
- local fields = add_user_layout:data(data.form);
- if not fields.accountjid then
- return { status = "completed", error = { message = "You need to specify a JID." } };
+ local fields, err = add_user_layout:data(data.form);
+ if err then
+ return generate_error_message(err);
end
local username, host, resource = jid.split(fields.accountjid);
if data.to ~= host then
return { status = "completed", error = { message = "Account already exists" } };
else
if usermanager_create_user(username, fields.password, host) then
- module:log("info", "Created new account " .. username.."@"..host);
+ module:log("info", "Created new account %s@%s", username, host);
return { status = "completed", info = "Account successfully created" };
else
return { status = "completed", error = { message = "Failed to write data to disk" } };
end
end
else
- module:log("debug", (fields.accountjid or "<nil>") .. " " .. (fields.password or "<nil>") .. " "
- .. (fields["password-verify"] or "<nil>"));
+ module:log("debug", "Invalid data, password mismatch or empty username while creating account for %s", fields.accountjid or "<nil>");
return { status = "completed", error = { message = "Invalid data.\nPassword mismatch, or empty username" } };
end
else
- return { status = "executing", form = add_user_layout }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = add_user_layout }, "executing";
end
end
if data.action == "cancel" then
return { status = "canceled" };
end
- local fields = change_user_password_layout:data(data.form);
- if not fields.accountjid or fields.accountjid == "" or not fields.password then
- return { status = "completed", error = { message = "Please specify username and password" } };
+ local fields, err = change_user_password_layout:data(data.form);
+ if err then
+ return generate_error_message(err);
end
local username, host, resource = jid.split(fields.accountjid);
if data.to ~= host then
return { status = "completed", error = { message = "User does not exist" } };
end
else
- return { status = "executing", form = change_user_password_layout }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = change_user_password_layout }, "executing";
+ end
+end
+
+function config_reload_handler(self, data, state)
+ local ok, err = prosody.reload_config();
+ if ok then
+ return { status = "completed", info = "Configuration reloaded (modules may need to be reloaded for this to have an effect)" };
+ else
+ return { status = "completed", error = { message = "Failed to reload config: " .. tostring(err) } };
end
end
+
function delete_user_command_handler(self, data, state)
local delete_user_layout = dataforms_new{
title = "Deleting a User";
if data.action == "cancel" then
return { status = "canceled" };
end
- local fields = delete_user_layout:data(data.form);
+ local fields, err = delete_user_layout:data(data.form);
+ if err then
+ return generate_error_message(err);
+ end
local failed = {};
local succeeded = {};
for _, aJID in ipairs(fields.accountjids) do
local username, host, resource = jid.split(aJID);
- if (host == data.to) and usermanager_user_exists(username, host) and disconnect_user(aJID) and usermanager_create_user(username, nil, host) then
- module:log("debug", "User " .. aJID .. " has been deleted");
+ if (host == data.to) and usermanager_user_exists(username, host) and usermanager_delete_user(username, host) then
+ module:log("debug", "User %s has been deleted", aJID);
succeeded[#succeeded+1] = aJID;
else
- module:log("debug", "Tried to delete non-existant user "..aJID);
+ module:log("debug", "Tried to delete non-existant user %s", aJID);
failed[#failed+1] = aJID;
end
end
(#failed ~= 0 and
"The following accounts could not be deleted:\n"..t_concat(failed, "\n") or "") };
else
- return { status = "executing", form = delete_user_layout }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = delete_user_layout }, "executing";
end
end
local sessions = host.sessions[node] and host.sessions[node].sessions;
for resource, session in pairs(sessions or {}) do
if not givenResource or (resource == givenResource) then
- module:log("debug", "Disconnecting "..node.."@"..hostname.."/"..resource);
+ module:log("debug", "Disconnecting %s@%s/%s", node, hostname, resource);
session:close();
end
end
return { status = "canceled" };
end
- local fields = end_user_session_layout:data(data.form);
+ local fields, err = end_user_session_layout:data(data.form);
+ if err then
+ return generate_error_message(err);
+ end
local failed = {};
local succeeded = {};
for _, aJID in ipairs(fields.accountjids) do
(#failed ~= 0 and
"The following accounts could not be disconnected:\n"..t_concat(failed, "\n") or "") };
else
- return { status = "executing", form = end_user_session_layout }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = end_user_session_layout }, "executing";
end
end
-local end_user_session_layout = dataforms_new{
- title = "Ending a User Session";
- instructions = "Fill out this form to end a user's session.";
-
- { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
- { name = "accountjids", type = "jid-multi", label = "The Jabber ID(s) for which to end sessions" };
-};
-
-
function get_user_password_handler(self, data, state)
local get_user_password_layout = dataforms_new{
title = "Getting User's Password";
if data.action == "cancel" then
return { status = "canceled" };
end
- local fields = get_user_password_layout:data(data.form);
- if not fields.accountjid then
- return { status = "completed", error = { message = "Please specify a JID." } };
+ local fields, err = get_user_password_layout:data(data.form);
+ if err then
+ return generate_error_message(err);
end
local user, host, resource = jid.split(fields.accountjid);
local accountjid = "";
end
return { status = "completed", result = { layout = get_user_password_result_layout, values = {accountjid = accountjid, password = password} } };
else
- return { status = "executing", form = get_user_password_layout }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = get_user_password_layout }, "executing";
end
end
return { status = "canceled" };
end
- local fields = get_user_roster_layout:data(data.form);
+ local fields, err = get_user_roster_layout:data(data.form);
- if not fields.accountjid then
- return { status = "completed", error = { message = "Please specify a JID" } };
+ if err then
+ return generate_error_message(err);
end
local user, host, resource = jid.split(fields.accountjid);
end
end
- local query_text = query:__tostring(); -- TODO: Use upcoming pretty_print() function
- query_text = query_text:gsub("><", ">\n<");
+ local query_text = tostring(query):gsub("><", ">\n<");
local result = get_user_roster_result_layout:form({ accountjid = user.."@"..host, roster = query_text }, "result");
result:add_child(query);
return { status = "completed", other = result };
else
- return { status = "executing", form = get_user_roster_layout }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = get_user_roster_layout }, "executing";
end
end
return { status = "canceled" };
end
- local fields = get_user_stats_layout:data(data.form);
+ local fields, err = get_user_stats_layout:data(data.form);
- if not fields.accountjid then
- return { status = "completed", error = { message = "Please specify a JID." } };
+ if err then
+ return generate_error_message(err);
end
local user, host, resource = jid.split(fields.accountjid);
return { status = "completed", result = {layout = get_user_stats_result_layout, values = {ipaddresses = IPs, rostersize = tostring(rostersize),
onlineresources = resources}} };
else
- return { status = "executing", form = get_user_stats_layout }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = get_user_stats_layout }, "executing";
end
end
return { status = "canceled" };
end
- local fields = get_online_users_layout:data(data.form);
+ local fields, err = get_online_users_layout:data(data.form);
+
+ if err then
+ return generate_error_message(err);
+ end
local max_items = nil
if fields.max_items ~= "all" then
end
return { status = "completed", result = {layout = get_online_users_result_layout, values = {onlineuserjids=t_concat(users, "\n")}} };
else
- return { status = "executing", form = get_online_users_layout }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = get_online_users_layout }, "executing";
end
end
if data.action == "cancel" then
return { status = "canceled" };
end
- local fields = layout:data(data.form);
- if (not fields.module) or (fields.module == "") then
- return { status = "completed", error = {
- message = "Please specify a module."
- } };
+ local fields, err = layout:data(data.form);
+ if err then
+ return generate_error_message(err);
end
if modulemanager.is_loaded(data.to, fields.module) then
return { status = "completed", info = "Module already loaded" };
'". Error was: "'..tostring(err or "<unspecified>")..'"' } };
end
else
- local modules = array.collect(keys(hosts[data.to].modules)):sort();
- return { status = "executing", form = layout }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = layout }, "executing";
+ end
+end
+
+local function globally_load_module_handler(self, data, state)
+ local layout = dataforms_new {
+ title = "Globally load module";
+ instructions = "Specify the module to be loaded on all hosts";
+
+ { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-load" };
+ { name = "module", type = "text-single", required = true, label = "Module to globally load:"};
+ };
+ if state then
+ local ok_list, err_list = {}, {};
+
+ if data.action == "cancel" then
+ return { status = "canceled" };
+ end
+
+ local fields, err = layout:data(data.form);
+ if err then
+ return generate_error_message(err);
+ end
+
+ local ok, err = modulemanager.load(data.to, fields.module);
+ if ok then
+ ok_list[#ok_list + 1] = data.to;
+ else
+ err_list[#err_list + 1] = data.to .. " (Error: " .. tostring(err) .. ")";
+ end
+
+ -- Is this a global module?
+ if modulemanager.is_loaded("*", fields.module) and not modulemanager.is_loaded(data.to, fields.module) then
+ return { status = "completed", info = 'Global module '..fields.module..' loaded.' };
+ end
+
+ -- This is either a shared or "normal" module, load it on all other hosts
+ for host_name, host in pairs(hosts) do
+ if host_name ~= data.to and host.type == "local" then
+ local ok, err = modulemanager.load(host_name, fields.module);
+ if ok then
+ ok_list[#ok_list + 1] = host_name;
+ else
+ err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")";
+ end
+ end
+ end
+
+ local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully loaded onto the hosts:\n"..t_concat(ok_list, "\n")) or "")
+ .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
+ (#err_list > 0 and ("Failed to load the module "..fields.module.." onto the hosts:\n"..t_concat(err_list, "\n")) or "");
+ return { status = "completed", info = info };
+ else
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = layout }, "executing";
end
end
if data.action == "cancel" then
return { status = "canceled" };
end
- local fields = layout:data(data.form);
- if #fields.modules == 0 then
- return { status = "completed", error = {
- message = "Please specify a module. (This means your client misbehaved, as this field is required)"
- } };
+ local fields, err = layout:data(data.form);
+ if err then
+ return generate_error_message(err);
end
local ok_list, err_list = {}, {};
for _, module in ipairs(fields.modules) do
err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")";
end
end
- local info = (#ok_list > 0 and ("The following modules were successfully reloaded on host "..data.to..":\n"..t_concat(ok_list, "\n")) or "")..
+ local info = (#ok_list > 0 and ("The following modules were successfully reloaded on host "..data.to..":\n"..t_concat(ok_list, "\n")) or "")
+ .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
(#err_list > 0 and ("Failed to reload the following modules on host "..data.to..":\n"..t_concat(err_list, "\n")) or "");
return { status = "completed", info = info };
else
local modules = array.collect(keys(hosts[data.to].modules)):sort();
- return { status = "executing", form = { layout = layout; values = { modules = modules } } }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout; values = { modules = modules } } }, "executing";
+ end
+end
+
+local function globally_reload_module_handler(self, data, state)
+ local layout = dataforms_new {
+ title = "Globally reload module";
+ instructions = "Specify the module to reload on all hosts";
+
+ { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-reload" };
+ { name = "module", type = "list-single", required = true, label = "Module to globally reload:"};
+ };
+ if state then
+ if data.action == "cancel" then
+ return { status = "canceled" };
+ end
+
+ local is_global = false;
+ local fields, err = layout:data(data.form);
+ if err then
+ return generate_error_message(err);
+ end
+
+ if modulemanager.is_loaded("*", fields.module) then
+ local ok, err = modulemanager.reload("*", fields.module);
+ if not ok then
+ return { status = "completed", info = 'Global module '..fields.module..' failed to reload: '..err };
+ end
+ is_global = true;
+ end
+
+ local ok_list, err_list = {}, {};
+ for host_name, host in pairs(hosts) do
+ if modulemanager.is_loaded(host_name, fields.module) then
+ local ok, err = modulemanager.reload(host_name, fields.module);
+ if ok then
+ ok_list[#ok_list + 1] = host_name;
+ else
+ err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")";
+ end
+ end
+ end
+
+ if #ok_list == 0 and #err_list == 0 then
+ if is_global then
+ return { status = "completed", info = 'Successfully reloaded global module '..fields.module };
+ else
+ return { status = "completed", info = 'Module '..fields.module..' not loaded on any host.' };
+ end
+ end
+
+ local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully reloaded on the hosts:\n"..t_concat(ok_list, "\n")) or "")
+ .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
+ (#err_list > 0 and ("Failed to reload the module "..fields.module.." on the hosts:\n"..t_concat(err_list, "\n")) or "");
+ return { status = "completed", info = info };
+ else
+ local loaded_modules = array(keys(modulemanager.get_modules("*")));
+ for _, host in pairs(hosts) do
+ loaded_modules:append(array(keys(host.modules)));
+ end
+ loaded_modules = array(keys(set.new(loaded_modules):items())):sort();
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout, values = { module = loaded_modules } } }, "executing";
end
end
return { status = "canceled" };
end
- local fields = shut_down_service_layout:data(data.form);
+ local fields, err = shut_down_service_layout:data(data.form);
+
+ if err then
+ return generate_error_message(err);
+ end
if fields.announcement and #fields.announcement > 0 then
local message = st.message({type = "headline"}, fields.announcement):up()
send_to_online(message);
end
- timer_add_task(tonumber(fields.delay or "5"), prosody.shutdown);
+ timer_add_task(tonumber(fields.delay or "5"), function(time) prosody.shutdown("Shutdown by adhoc command") end);
return { status = "completed", info = "Server is about to shut down" };
else
- return { status = "executing", form = shut_down_service_layout }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = shut_down_service_layout }, "executing";
end
-
- return true;
end
--- TODO: Allow unloading multiple modules (depends on list-multi)
function unload_modules_handler(self, data, state)
local layout = dataforms_new {
- title = "Unload module";
- instructions = "Select the module to be unloaded";
+ title = "Unload modules";
+ instructions = "Select the modules to be unloaded";
{ name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" };
- { name = "module", type = "list-single", required = true, label = "Module to be unloaded:"};
+ { name = "modules", type = "list-multi", required = true, label = "Modules to be unloaded:"};
+ };
+ if state then
+ if data.action == "cancel" then
+ return { status = "canceled" };
+ end
+ local fields, err = layout:data(data.form);
+ if err then
+ return generate_error_message(err);
+ end
+ local ok_list, err_list = {}, {};
+ for _, module in ipairs(fields.modules) do
+ local ok, err = modulemanager.unload(data.to, module);
+ if ok then
+ ok_list[#ok_list + 1] = module;
+ else
+ err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")";
+ end
+ end
+ local info = (#ok_list > 0 and ("The following modules were successfully unloaded on host "..data.to..":\n"..t_concat(ok_list, "\n")) or "")
+ .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
+ (#err_list > 0 and ("Failed to unload the following modules on host "..data.to..":\n"..t_concat(err_list, "\n")) or "");
+ return { status = "completed", info = info };
+ else
+ local modules = array.collect(keys(hosts[data.to].modules)):sort();
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout; values = { modules = modules } } }, "executing";
+ end
+end
+
+local function globally_unload_module_handler(self, data, state)
+ local layout = dataforms_new {
+ title = "Globally unload module";
+ instructions = "Specify a module to unload on all hosts";
+
+ { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-unload" };
+ { name = "module", type = "list-single", required = true, label = "Module to globally unload:"};
+ };
+ if state then
+ if data.action == "cancel" then
+ return { status = "canceled" };
+ end
+
+ local is_global = false;
+ local fields, err = layout:data(data.form);
+ if err then
+ return generate_error_message(err);
+ end
+
+ if modulemanager.is_loaded("*", fields.module) then
+ local ok, err = modulemanager.unload("*", fields.module);
+ if not ok then
+ return { status = "completed", info = 'Global module '..fields.module..' failed to unload: '..err };
+ end
+ is_global = true;
+ end
+
+ local ok_list, err_list = {}, {};
+ for host_name, host in pairs(hosts) do
+ if modulemanager.is_loaded(host_name, fields.module) then
+ local ok, err = modulemanager.unload(host_name, fields.module);
+ if ok then
+ ok_list[#ok_list + 1] = host_name;
+ else
+ err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")";
+ end
+ end
+ end
+
+ if #ok_list == 0 and #err_list == 0 then
+ if is_global then
+ return { status = "completed", info = 'Successfully unloaded global module '..fields.module };
+ else
+ return { status = "completed", info = 'Module '..fields.module..' not loaded on any host.' };
+ end
+ end
+
+ local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully unloaded on the hosts:\n"..t_concat(ok_list, "\n")) or "")
+ .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
+ (#err_list > 0 and ("Failed to unload the module "..fields.module.." on the hosts:\n"..t_concat(err_list, "\n")) or "");
+ return { status = "completed", info = info };
+ else
+ local loaded_modules = array(keys(modulemanager.get_modules("*")));
+ for _, host in pairs(hosts) do
+ loaded_modules:append(array(keys(host.modules)));
+ end
+ loaded_modules = array(keys(set.new(loaded_modules):items())):sort();
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout, values = { module = loaded_modules } } }, "executing";
+ end
+end
+
+
+function activate_host_handler(self, data, state)
+ local layout = dataforms_new {
+ title = "Activate host";
+ instructions = "";
+
+ { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/hosts#activate" };
+ { name = "host", type = "text-single", required = true, label = "Host:"};
};
if state then
if data.action == "cancel" then
return { status = "canceled" };
end
- local fields = layout:data(data.form);
- if (not fields.module) or (fields.module == "") then
- return { status = "completed", error = {
- message = "Please specify a module. (This means your client misbehaved, as this field is required)"
- } };
+ local fields, err = layout:data(data.form);
+ if err then
+ return generate_error_message(err);
end
- local ok, err = modulemanager.unload(data.to, fields.module);
+ local ok, err = hostmanager_activate(fields.host);
+
if ok then
- return { status = "completed", info = 'Module "'..fields.module..'" successfully unloaded on host "'..data.to..'".' };
+ return { status = "completed", info = fields.host .. " activated" };
else
- return { status = "completed", error = { message = 'Failed to unload module "'..fields.module..'" on host "'..data.to..
- '". Error was: "'..tostring(err)..'"' } };
+ return { status = "canceled", error = err }
end
else
- local modules = array.collect(keys(hosts[data.to].modules)):sort();
- return { status = "executing", form = { layout = layout; values = { module = modules } } }, "executing";
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout } }, "executing";
+ end
+end
+
+function deactivate_host_handler(self, data, state)
+ local layout = dataforms_new {
+ title = "Deactivate host";
+ instructions = "";
+
+ { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/hosts#activate" };
+ { name = "host", type = "text-single", required = true, label = "Host:"};
+ };
+ if state then
+ if data.action == "cancel" then
+ return { status = "canceled" };
+ end
+ local fields, err = layout:data(data.form);
+ if err then
+ return generate_error_message(err);
+ end
+ local ok, err = hostmanager_deactivate(fields.host);
+
+ if ok then
+ return { status = "completed", info = fields.host .. " deactivated" };
+ else
+ return { status = "canceled", error = err }
+ end
+ else
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout } }, "executing";
end
end
+
local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin");
local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin");
+local config_reload_desc = adhoc_new("Reload configuration", "http://prosody.im/protocol/config#reload", config_reload_handler, "global_admin");
local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin");
local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin");
local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin");
local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users", get_online_users_command_handler, "admin");
local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin");
local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin");
+local globally_load_module_desc = adhoc_new("Globally load module", "http://prosody.im/protocol/modules#global-load", globally_load_module_handler, "global_admin");
local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin");
-local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "admin");
-local unload_modules_desc = adhoc_new("Unload module", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin");
-
-module:add_item("adhoc", add_user_desc);
-module:add_item("adhoc", change_user_password_desc);
-module:add_item("adhoc", delete_user_desc);
-module:add_item("adhoc", end_user_session_desc);
-module:add_item("adhoc", get_user_password_desc);
-module:add_item("adhoc", get_user_roster_desc);
-module:add_item("adhoc", get_user_stats_desc);
-module:add_item("adhoc", get_online_users_desc);
-module:add_item("adhoc", list_modules_desc);
-module:add_item("adhoc", load_module_desc);
-module:add_item("adhoc", reload_modules_desc);
-module:add_item("adhoc", shut_down_service_desc);
-module:add_item("adhoc", unload_modules_desc);
+local globally_reload_module_desc = adhoc_new("Globally reload module", "http://prosody.im/protocol/modules#global-reload", globally_reload_module_handler, "global_admin");
+local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin");
+local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin");
+local globally_unload_module_desc = adhoc_new("Globally unload module", "http://prosody.im/protocol/modules#global-unload", globally_unload_module_handler, "global_admin");
+local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin");
+local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin");
+
+module:provides("adhoc", add_user_desc);
+module:provides("adhoc", change_user_password_desc);
+module:provides("adhoc", config_reload_desc);
+module:provides("adhoc", delete_user_desc);
+module:provides("adhoc", end_user_session_desc);
+module:provides("adhoc", get_user_password_desc);
+module:provides("adhoc", get_user_roster_desc);
+module:provides("adhoc", get_user_stats_desc);
+module:provides("adhoc", get_online_users_desc);
+module:provides("adhoc", list_modules_desc);
+module:provides("adhoc", load_module_desc);
+module:provides("adhoc", globally_load_module_desc);
+module:provides("adhoc", reload_modules_desc);
+module:provides("adhoc", globally_reload_module_desc);
+module:provides("adhoc", shut_down_service_desc);
+module:provides("adhoc", unload_modules_desc);
+module:provides("adhoc", globally_unload_module_desc);
+module:provides("adhoc", activate_host_desc);
+module:provides("adhoc", deactivate_host_desc);