mod_admin_adhoc: Support for reloading multiple modules
authorFlorian Zeitz <florob@babelmonkeys.de>
Sat, 18 Dec 2010 20:04:45 +0000 (21:04 +0100)
committerFlorian Zeitz <florob@babelmonkeys.de>
Sat, 18 Dec 2010 20:04:45 +0000 (21:04 +0100)
plugins/mod_admin_adhoc.lua
prosodyctl
util/prosodyctl.lua

index 984ae5ea5c266bc7af57c4aff2606dfbe447e0ef..f59a08c5f40a6979ad352cbd1ea61aad20b0ea48 100644 (file)
@@ -544,39 +544,35 @@ function shut_down_service_handler(self, data, state)
        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 modules";
-               instructions = "Select the modules to be unloaded";
+               title = "Unload module";
+               instructions = "Select the module to be unloaded";
 
                { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" };
-               { name = "modules", type = "list-multi", required = true, label = "Modules to be unloaded:"};
+               { name = "module", type = "list-single", required = true, label = "Module to be unloaded:"};
        };
        if state then
                if data.action == "cancel" then
                        return { status = "canceled" };
                end
                local fields = layout:data(data.form);
-               if #fields.modules == 0 then
+               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)"
                        } };
                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
+               local ok, err = modulemanager.unload(data.to, fields.module);
+               if ok then
+                       return { status = "completed", info = 'Module "'..fields.module..'" successfully unloaded on host "'..data.to..'".' };
+               else
+                       return { status = "completed", error = { message = 'Failed to unload module "'..fields.module..'" on host "'..data.to..
+                       '". Error was: "'..tostring(err)..'"' } };
                end
-               local info = (#ok_list > 0 and ("The following modules were successfully unloaded on host "..data.to..":\n"..t_concat(ok_list, "\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", form = { layout = layout; values = { modules = modules } } }, "executing";
+               return { status = "executing", form = { layout = layout; values = { module = modules } } }, "executing";
        end
 end
 
@@ -592,7 +588,7 @@ local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/pr
 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 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 modules", "http://prosody.im/protocol/modules#unload", unload_modules_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);
index 05a71b38fdb481c7073ed4c324eb5b0b18415293..cfc5ca77a979d74268a5483455984ec2da170462 100755 (executable)
@@ -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
 
index 3e6e90eee7504a665dc5bf46e4fe61d56bd71ee3..40d21be86b617ac8a82230b88561720c28c96e10 100644 (file)
@@ -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