Mercurial > prosody-hg
comparison plugins/mod_admin_adhoc.lua @ 5328:5e15e6700412
mod_admin_adhoc: Implement global module unloading
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Thu, 07 Feb 2013 21:14:01 +0100 |
| parents | b0c36b043f00 |
| children | 9fffd5fad4b3 |
comparison
equal
deleted
inserted
replaced
| 5327:b0c36b043f00 | 5328:5e15e6700412 |
|---|---|
| 712 local modules = array.collect(keys(hosts[data.to].modules)):sort(); | 712 local modules = array.collect(keys(hosts[data.to].modules)):sort(); |
| 713 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout; values = { modules = modules } } }, "executing"; | 713 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout; values = { modules = modules } } }, "executing"; |
| 714 end | 714 end |
| 715 end | 715 end |
| 716 | 716 |
| 717 local function globally_unload_module_handler(self, data, state) | |
| 718 local layout = dataforms_new { | |
| 719 title = "Globally unload module"; | |
| 720 instructions = "Specify a module to unload on all hosts"; | |
| 721 | |
| 722 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-unload" }; | |
| 723 { name = "module", type = "list-single", required = true, label = "Module to globally unload:"}; | |
| 724 }; | |
| 725 if state then | |
| 726 if data.action == "cancel" then | |
| 727 return { status = "canceled" }; | |
| 728 end | |
| 729 | |
| 730 local is_global = false; | |
| 731 local fields, err = layout:data(data.form); | |
| 732 if err then | |
| 733 return generate_error_message(err); | |
| 734 end | |
| 735 | |
| 736 if modulemanager.is_loaded("*", fields.module) then | |
| 737 local ok, err = modulemanager.unload("*", fields.module); | |
| 738 if not ok then | |
| 739 return { status = "completed", info = 'Global module '..fields.module..' failed to unload: '..err }; | |
| 740 end | |
| 741 is_global = true; | |
| 742 end | |
| 743 | |
| 744 local ok_list, err_list = {}, {}; | |
| 745 for host_name, host in pairs(hosts) do | |
| 746 if modulemanager.is_loaded(host_name, fields.module) then | |
| 747 local ok, err = modulemanager.unload(host_name, fields.module); | |
| 748 if ok then | |
| 749 ok_list[#ok_list + 1] = host_name; | |
| 750 else | |
| 751 err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")"; | |
| 752 end | |
| 753 end | |
| 754 end | |
| 755 | |
| 756 if #ok_list == 0 and #err_list == 0 then | |
| 757 if is_global then | |
| 758 return { status = "completed", info = 'Successfully unloaded global module '..fields.module }; | |
| 759 else | |
| 760 return { status = "completed", info = 'Module '..fields.module..' not loaded on any host.' }; | |
| 761 end | |
| 762 end | |
| 763 | |
| 764 local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully unloaded on the hosts:\n"..t_concat(ok_list, "\n")) or "") | |
| 765 .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") .. | |
| 766 (#err_list > 0 and ("Failed to unload the module "..fields.module.." on the hosts:\n"..t_concat(err_list, "\n")) or ""); | |
| 767 return { status = "completed", info = info }; | |
| 768 else | |
| 769 local loaded_modules = array(keys(modulemanager.get_modules("*"))); | |
| 770 for _, host in pairs(hosts) do | |
| 771 loaded_modules:append(array(keys(host.modules))); | |
| 772 end | |
| 773 loaded_modules = array(keys(set.new(loaded_modules):items())):sort(); | |
| 774 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout, values = { module = loaded_modules } } }, "executing"; | |
| 775 end | |
| 776 end | |
| 777 | |
| 778 | |
| 717 function activate_host_handler(self, data, state) | 779 function activate_host_handler(self, data, state) |
| 718 local layout = dataforms_new { | 780 local layout = dataforms_new { |
| 719 title = "Activate host"; | 781 title = "Activate host"; |
| 720 instructions = ""; | 782 instructions = ""; |
| 721 | 783 |
| 785 local globally_load_module_desc = adhoc_new("Globally load module", "http://prosody.im/protocol/modules#global-load", globally_load_module_handler, "global_admin"); | 847 local globally_load_module_desc = adhoc_new("Globally load module", "http://prosody.im/protocol/modules#global-load", globally_load_module_handler, "global_admin"); |
| 786 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); | 848 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); |
| 787 local globally_reload_module_desc = adhoc_new("Globally reload module", "http://prosody.im/protocol/modules#global-reload", globally_reload_module_handler, "global_admin"); | 849 local globally_reload_module_desc = adhoc_new("Globally reload module", "http://prosody.im/protocol/modules#global-reload", globally_reload_module_handler, "global_admin"); |
| 788 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin"); | 850 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin"); |
| 789 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); | 851 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); |
| 852 local globally_unload_module_desc = adhoc_new("Globally unload module", "http://prosody.im/protocol/modules#global-unload", globally_unload_module_handler, "global_admin"); | |
| 790 local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin"); | 853 local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin"); |
| 791 local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin"); | 854 local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin"); |
| 792 | 855 |
| 793 module:provides("adhoc", add_user_desc); | 856 module:provides("adhoc", add_user_desc); |
| 794 module:provides("adhoc", change_user_password_desc); | 857 module:provides("adhoc", change_user_password_desc); |
| 804 module:provides("adhoc", globally_load_module_desc); | 867 module:provides("adhoc", globally_load_module_desc); |
| 805 module:provides("adhoc", reload_modules_desc); | 868 module:provides("adhoc", reload_modules_desc); |
| 806 module:provides("adhoc", globally_reload_module_desc); | 869 module:provides("adhoc", globally_reload_module_desc); |
| 807 module:provides("adhoc", shut_down_service_desc); | 870 module:provides("adhoc", shut_down_service_desc); |
| 808 module:provides("adhoc", unload_modules_desc); | 871 module:provides("adhoc", unload_modules_desc); |
| 872 module:provides("adhoc", globally_unload_module_desc); | |
| 809 module:provides("adhoc", activate_host_desc); | 873 module:provides("adhoc", activate_host_desc); |
| 810 module:provides("adhoc", deactivate_host_desc); | 874 module:provides("adhoc", deactivate_host_desc); |
