Software /
code /
prosody
Comparison
plugins/mod_admin_adhoc.lua @ 5325:97bf651e32a4
mod_admin_adhoc: Implement global module loading
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Wed, 06 Feb 2013 00:51:25 +0100 |
parent | 5324:8602fffdd1df |
child | 5326:e96361eb8286 |
comparison
equal
deleted
inserted
replaced
5324:8602fffdd1df | 5325:97bf651e32a4 |
---|---|
464 else | 464 else |
465 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = layout }, "executing"; | 465 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = layout }, "executing"; |
466 end | 466 end |
467 end | 467 end |
468 | 468 |
469 local function globally_load_module_handler(self, data, state) | |
470 local layout = dataforms_new { | |
471 title = "Globally load module"; | |
472 instructions = "Specify the module to be loaded on all hosts"; | |
473 | |
474 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-load" }; | |
475 { name = "module", type = "text-single", required = true, label = "Module to globally load:"}; | |
476 }; | |
477 if state then | |
478 local ok_list, err_list = {}, {}; | |
479 | |
480 if data.action == "cancel" then | |
481 return { status = "canceled" }; | |
482 end | |
483 | |
484 local fields, err = layout:data(data.form); | |
485 if err then | |
486 return generate_error_message(err); | |
487 end | |
488 | |
489 local ok, err = modulemanager.load(data.to, fields.module); | |
490 if ok then | |
491 ok_list[#ok_list + 1] = data.to; | |
492 else | |
493 err_list[#err_list + 1] = data.to .. " (Error: " .. tostring(err) .. ")"; | |
494 end | |
495 | |
496 -- Is this a global module? | |
497 if modulemanager.is_loaded("*", fields.module) and not modulemanager.is_loaded(data.to, fields.module) then | |
498 return { status = "completed", info = 'Global module '..fields.module..' loaded.' }; | |
499 end | |
500 | |
501 -- This is either a shared or "normal" module, load it on all other hosts | |
502 for host_name, host in pairs(hosts) do | |
503 if host_name ~= data.to and host.type == "local" then | |
504 local ok, err = modulemanager.load(host_name, fields.module); | |
505 if ok then | |
506 ok_list[#ok_list + 1] = host_name; | |
507 else | |
508 err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")"; | |
509 end | |
510 end | |
511 end | |
512 | |
513 local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully loaded onto the hosts:\n"..t_concat(ok_list, "\n")) or "") | |
514 .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") .. | |
515 (#err_list > 0 and ("Failed to load the module "..fields.module.." onto the hosts:\n"..t_concat(err_list, "\n")) or ""); | |
516 return { status = "completed", info = info }; | |
517 else | |
518 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = layout }, "executing"; | |
519 end | |
520 end | |
521 | |
469 function reload_modules_handler(self, data, state) | 522 function reload_modules_handler(self, data, state) |
470 local layout = dataforms_new { | 523 local layout = dataforms_new { |
471 title = "Reload modules"; | 524 title = "Reload modules"; |
472 instructions = "Select the modules to be reloaded"; | 525 instructions = "Select the modules to be reloaded"; |
473 | 526 |
664 local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin"); | 717 local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin"); |
665 local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin"); | 718 local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin"); |
666 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"); | 719 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"); |
667 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); | 720 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); |
668 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin"); | 721 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin"); |
722 local globally_load_module_desc = adhoc_new("Globally load module", "http://prosody.im/protocol/modules#global-load", globally_load_module_handler, "global_admin"); | |
669 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); | 723 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); |
670 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin"); | 724 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin"); |
671 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); | 725 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); |
672 local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin"); | 726 local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin"); |
673 local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin"); | 727 local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin"); |
681 module:provides("adhoc", get_user_roster_desc); | 735 module:provides("adhoc", get_user_roster_desc); |
682 module:provides("adhoc", get_user_stats_desc); | 736 module:provides("adhoc", get_user_stats_desc); |
683 module:provides("adhoc", get_online_users_desc); | 737 module:provides("adhoc", get_online_users_desc); |
684 module:provides("adhoc", list_modules_desc); | 738 module:provides("adhoc", list_modules_desc); |
685 module:provides("adhoc", load_module_desc); | 739 module:provides("adhoc", load_module_desc); |
740 module:provides("adhoc", globally_load_module_desc); | |
686 module:provides("adhoc", reload_modules_desc); | 741 module:provides("adhoc", reload_modules_desc); |
687 module:provides("adhoc", shut_down_service_desc); | 742 module:provides("adhoc", shut_down_service_desc); |
688 module:provides("adhoc", unload_modules_desc); | 743 module:provides("adhoc", unload_modules_desc); |
689 module:provides("adhoc", activate_host_desc); | 744 module:provides("adhoc", activate_host_desc); |
690 module:provides("adhoc", deactivate_host_desc); | 745 module:provides("adhoc", deactivate_host_desc); |