542 end |
542 end |
543 |
543 |
544 return true; |
544 return true; |
545 end |
545 end |
546 |
546 |
547 -- TODO: Allow unloading multiple modules (depends on list-multi) |
|
548 function unload_modules_handler(self, data, state) |
547 function unload_modules_handler(self, data, state) |
549 local layout = dataforms_new { |
548 local layout = dataforms_new { |
550 title = "Unload module"; |
549 title = "Unload modules"; |
551 instructions = "Select the module to be unloaded"; |
550 instructions = "Select the modules to be unloaded"; |
552 |
551 |
553 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" }; |
552 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" }; |
554 { name = "module", type = "list-single", required = true, label = "Module to be unloaded:"}; |
553 { name = "modules", type = "list-multi", required = true, label = "Modules to be unloaded:"}; |
555 }; |
554 }; |
556 if state then |
555 if state then |
557 if data.action == "cancel" then |
556 if data.action == "cancel" then |
558 return { status = "canceled" }; |
557 return { status = "canceled" }; |
559 end |
558 end |
560 local fields = layout:data(data.form); |
559 local fields = layout:data(data.form); |
561 if (not fields.module) or (fields.module == "") then |
560 if #fields.modules == 0 then |
562 return { status = "completed", error = { |
561 return { status = "completed", error = { |
563 message = "Please specify a module. (This means your client misbehaved, as this field is required)" |
562 message = "Please specify a module. (This means your client misbehaved, as this field is required)" |
564 } }; |
563 } }; |
565 end |
564 end |
566 local ok, err = modulemanager.unload(data.to, fields.module); |
565 local ok_list, err_list = {}, {}; |
567 if ok then |
566 for _, module in ipairs(fields.modules) do |
568 return { status = "completed", info = 'Module "'..fields.module..'" successfully unloaded on host "'..data.to..'".' }; |
567 local ok, err = modulemanager.unload(data.to, module); |
569 else |
568 if ok then |
570 return { status = "completed", error = { message = 'Failed to unload module "'..fields.module..'" on host "'..data.to.. |
569 ok_list[#ok_list + 1] = module; |
571 '". Error was: "'..tostring(err)..'"' } }; |
570 else |
572 end |
571 err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")"; |
|
572 end |
|
573 end |
|
574 local info = (#ok_list > 0 and ("The following modules were successfully unloaded on host "..data.to..":\n"..t_concat(ok_list, "\n")) or "").. |
|
575 (#err_list > 0 and ("Failed to unload the following modules on host "..data.to..":\n"..t_concat(err_list, "\n")) or ""); |
|
576 return { status = "completed", info = info }; |
573 else |
577 else |
574 local modules = array.collect(keys(hosts[data.to].modules)):sort(); |
578 local modules = array.collect(keys(hosts[data.to].modules)):sort(); |
575 return { status = "executing", form = { layout = layout; values = { module = modules } } }, "executing"; |
579 return { status = "executing", form = { layout = layout; values = { modules = modules } } }, "executing"; |
576 end |
580 end |
577 end |
581 end |
578 |
582 |
579 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin"); |
583 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin"); |
580 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin"); |
584 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin"); |
586 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"); |
590 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"); |
587 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); |
591 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); |
588 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin"); |
592 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin"); |
589 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); |
593 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); |
590 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "admin"); |
594 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "admin"); |
591 local unload_modules_desc = adhoc_new("Unload module", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); |
595 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); |
592 |
596 |
593 module:add_item("adhoc", add_user_desc); |
597 module:add_item("adhoc", add_user_desc); |
594 module:add_item("adhoc", change_user_password_desc); |
598 module:add_item("adhoc", change_user_password_desc); |
595 module:add_item("adhoc", delete_user_desc); |
599 module:add_item("adhoc", delete_user_desc); |
596 module:add_item("adhoc", end_user_session_desc); |
600 module:add_item("adhoc", end_user_session_desc); |