Mercurial > prosody-modules
comparison mod_adhoc_cmd_modules/mod_adhoc_cmd_modules.lua @ 206:d3498f115fcd
mod_adhoc_cmd_modules: Add "Unload module" command
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 09 Jul 2010 22:38:05 +0200 |
parents | a6361a1fda5e |
children | 1ae653712e37 |
comparison
equal
deleted
inserted
replaced
205:a6361a1fda5e | 206:d3498f115fcd |
---|---|
26 local modules = array.collect(keys(hosts[data.to].modules)):sort():concat("\n"); | 26 local modules = array.collect(keys(hosts[data.to].modules)):sort():concat("\n"); |
27 | 27 |
28 return { status = "completed", result = { layout = result; data = { modules = modules } } }; | 28 return { status = "completed", result = { layout = result; data = { modules = modules } } }; |
29 end | 29 end |
30 | 30 |
31 -- TODO: Allow reloading multiple modules (depends on list-multi | 31 -- TODO: Allow reloading multiple modules (depends on list-multi) |
32 function reload_modules_handler(self, data, state) | 32 function reload_modules_handler(self, data, state) |
33 local modules = {}; | 33 local modules = {}; |
34 local layout = dataforms_new { | 34 local layout = dataforms_new { |
35 title = "Reload module"; | 35 title = "Reload module"; |
36 instructions = "Select the module to be reloaded"; | 36 instructions = "Select the module to be reloaded"; |
57 end | 57 end |
58 return { status = "executing", form = layout }, "executing"; | 58 return { status = "executing", form = layout }, "executing"; |
59 end | 59 end |
60 end | 60 end |
61 | 61 |
62 -- TODO: Allow unloading multiple modules (depends on list-multi) | |
63 function unload_modules_handler(self, data, state) | |
64 local modules = {}; | |
65 local layout = dataforms_new { | |
66 title = "Unload module"; | |
67 instructions = "Select the module to be unloaded"; | |
68 | |
69 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" }; | |
70 { name = "module", type = "list-single", value = modules, label = "Module to be unloaded:"}; | |
71 }; | |
72 if state then | |
73 if data.action == "cancel" then | |
74 return { status = "canceled" }; | |
75 end | |
76 fields = layout:data(data.form); | |
77 local ok, err = modulemanager.unload(data.to, fields.module); | |
78 if ok then | |
79 return { status = "completed", info = 'Module "'..fields.module..'" successfully unloaded on host "'..data.to..'".' }; | |
80 else | |
81 return { status = "completed", error = 'Failed to unload module "'..fields.module..'" on host "'..data.to.. | |
82 '". Error was: "'..tostring(err)..'"' }; | |
83 end | |
84 else | |
85 local modules2 = array.collect(keys(hosts[data.to].modules)):sort(); | |
86 for i, val in ipairs(modules2) do | |
87 modules[i] = val; | |
88 end | |
89 return { status = "executing", form = layout }, "executing"; | |
90 end | |
91 end | |
92 | |
62 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); | 93 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); |
63 local reload_modules_desc = adhoc_new("Reload module", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); | 94 local reload_modules_desc = adhoc_new("Reload module", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); |
95 local unload_modules_desc = adhoc_new("Unload module", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); | |
64 | 96 |
65 module:add_item("adhoc", list_modules_desc); | 97 module:add_item("adhoc", list_modules_desc); |
66 module:add_item("adhoc", reload_modules_desc); | 98 module:add_item("adhoc", reload_modules_desc); |
99 module:add_item("adhoc", unload_modules_desc); |