aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2010-12-18 21:04:45 +0100
committerFlorian Zeitz <florob@babelmonkeys.de>2010-12-18 21:04:45 +0100
commit103b279022a8476465aca894a47ef2f4a955c120 (patch)
tree660f0a447a13e3ae41e63d2b6d47320ba1cd9006
parent22a83d733c206006fbcf24baaec0e197ed4a3e57 (diff)
downloadprosody-103b279022a8476465aca894a47ef2f4a955c120.tar.gz
prosody-103b279022a8476465aca894a47ef2f4a955c120.zip
mod_admin_adhoc: Support for reloading multiple modules
-rw-r--r--plugins/mod_admin_adhoc.lua30
-rwxr-xr-xprosodyctl2
-rw-r--r--util/prosodyctl.lua4
3 files changed, 20 insertions, 16 deletions
diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua
index 9ddb3b9f..f59a08c5 100644
--- a/plugins/mod_admin_adhoc.lua
+++ b/plugins/mod_admin_adhoc.lua
@@ -446,35 +446,39 @@ function load_module_handler(self, data, state)
end
end
--- TODO: Allow reloading multiple modules (depends on list-multi)
function reload_modules_handler(self, data, state)
local layout = dataforms_new {
- title = "Reload module";
- instructions = "Select the module to be reloaded";
+ title = "Reload modules";
+ instructions = "Select the modules to be reloaded";
{ name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#reload" };
- { name = "module", type = "list-single", required = true, label = "Module to be reloaded:"};
+ { name = "modules", type = "list-multi", required = true, label = "Modules to be reloaded:"};
};
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
+ if #fields.modules == 0 then
return { status = "completed", error = {
message = "Please specify a module. (This means your client misbehaved, as this field is required)"
} };
end
- local ok, err = modulemanager.reload(data.to, fields.module);
- if ok then
- return { status = "completed", info = 'Module "'..fields.module..'" successfully reloaded on host "'..data.to..'".' };
- else
- return { status = "completed", error = { message = 'Failed to reload module "'..fields.module..'" on host "'..data.to..
- '". Error was: "'..tostring(err)..'"' } };
+ local ok_list, err_list = {}, {};
+ for _, module in ipairs(fields.modules) do
+ local ok, err = modulemanager.reload(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 reloaded on host "..data.to..":\n"..t_concat(ok_list, "\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 = { module = modules } } }, "executing";
+ return { status = "executing", form = { layout = layout; values = { modules = modules } } }, "executing";
end
end
@@ -582,7 +586,7 @@ local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/p
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 reload_modules_desc = adhoc_new("Reload module", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "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");
diff --git a/prosodyctl b/prosodyctl
index 05a71b38..cfc5ca77 100755
--- a/prosodyctl
+++ b/prosodyctl
@@ -331,7 +331,7 @@ function commands.adduser(arg)
if ok then return 0; end
- show_message(error_messages[msg])
+ show_message(msg)
return 1;
end
diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua
index 3e6e90ee..40d21be8 100644
--- a/util/prosodyctl.lua
+++ b/util/prosodyctl.lua
@@ -41,9 +41,9 @@ function adduser(params)
end
storagemanager.initialize_host(host);
- local ok = usermanager.create_user(user, password, host);
+ local ok, errmsg = usermanager.create_user(user, password, host);
if not ok then
- return false, "unable-to-save-data";
+ return false, errmsg;
end
return true;
end