plugins/mod_admin_adhoc.lua

changeset 3895
84f8153d06ce
parent 3540
bc139431830b
child 3777
bd1845f9d5a4
equal deleted inserted replaced
3894:22368fbb71dd 3895:84f8153d06ce
444 local modules = array.collect(keys(hosts[data.to].modules)):sort(); 444 local modules = array.collect(keys(hosts[data.to].modules)):sort();
445 return { status = "executing", form = layout }, "executing"; 445 return { status = "executing", form = layout }, "executing";
446 end 446 end
447 end 447 end
448 448
449 -- TODO: Allow reloading multiple modules (depends on list-multi)
450 function reload_modules_handler(self, data, state) 449 function reload_modules_handler(self, data, state)
451 local layout = dataforms_new { 450 local layout = dataforms_new {
452 title = "Reload module"; 451 title = "Reload modules";
453 instructions = "Select the module to be reloaded"; 452 instructions = "Select the modules to be reloaded";
454 453
455 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#reload" }; 454 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#reload" };
456 { name = "module", type = "list-single", required = true, label = "Module to be reloaded:"}; 455 { name = "modules", type = "list-multi", required = true, label = "Modules to be reloaded:"};
457 }; 456 };
458 if state then 457 if state then
459 if data.action == "cancel" then 458 if data.action == "cancel" then
460 return { status = "canceled" }; 459 return { status = "canceled" };
461 end 460 end
462 local fields = layout:data(data.form); 461 local fields = layout:data(data.form);
463 if (not fields.module) or (fields.module == "") then 462 if #fields.modules == 0 then
464 return { status = "completed", error = { 463 return { status = "completed", error = {
465 message = "Please specify a module. (This means your client misbehaved, as this field is required)" 464 message = "Please specify a module. (This means your client misbehaved, as this field is required)"
466 } }; 465 } };
467 end 466 end
468 local ok, err = modulemanager.reload(data.to, fields.module); 467 local ok_list, err_list = {}, {};
469 if ok then 468 for _, module in ipairs(fields.modules) do
470 return { status = "completed", info = 'Module "'..fields.module..'" successfully reloaded on host "'..data.to..'".' }; 469 local ok, err = modulemanager.reload(data.to, module);
471 else 470 if ok then
472 return { status = "completed", error = { message = 'Failed to reload module "'..fields.module..'" on host "'..data.to.. 471 ok_list[#ok_list + 1] = module;
473 '". Error was: "'..tostring(err)..'"' } }; 472 else
474 end 473 err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")";
474 end
475 end
476 local info = (#ok_list > 0 and ("The following modules were successfully reloaded on host "..data.to..":\n"..t_concat(ok_list, "\n")) or "")..
477 (#err_list > 0 and ("Failed to reload the following modules on host "..data.to..":\n"..t_concat(err_list, "\n")) or "");
478 return { status = "completed", info = info };
475 else 479 else
476 local modules = array.collect(keys(hosts[data.to].modules)):sort(); 480 local modules = array.collect(keys(hosts[data.to].modules)):sort();
477 return { status = "executing", form = { layout = layout; values = { module = modules } } }, "executing"; 481 return { status = "executing", form = { layout = layout; values = { modules = modules } } }, "executing";
478 end 482 end
479 end 483 end
480 484
481 function send_to_online(message, server) 485 function send_to_online(message, server)
482 if server then 486 if server then
580 local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin"); 584 local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin");
581 local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin"); 585 local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin");
582 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"); 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");
583 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); 587 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin");
584 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin"); 588 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin");
585 local reload_modules_desc = adhoc_new("Reload module", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); 589 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin");
586 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "admin"); 590 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "admin");
587 local unload_modules_desc = adhoc_new("Unload module", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); 591 local unload_modules_desc = adhoc_new("Unload module", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin");
588 592
589 module:add_item("adhoc", add_user_desc); 593 module:add_item("adhoc", add_user_desc);
590 module:add_item("adhoc", change_user_password_desc); 594 module:add_item("adhoc", change_user_password_desc);

mercurial