comparison mod_adhoc_cmd_modules/mod_adhoc_cmd_modules.lua @ 207:1ae653712e37

mod_adhoc: Add capability to pass data to forms mod_adhoc_cmd_modules: Update to use afforementioned functionality
author Florian Zeitz <florob@babelmonkeys.de>
date Sat, 10 Jul 2010 01:26:41 +0200
parents d3498f115fcd
children 214cb85cdfbf
comparison
equal deleted inserted replaced
206:d3498f115fcd 207:1ae653712e37
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 = {};
34 local layout = dataforms_new { 33 local layout = dataforms_new {
35 title = "Reload module"; 34 title = "Reload module";
36 instructions = "Select the module to be reloaded"; 35 instructions = "Select the module to be reloaded";
37 36
38 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#reload" }; 37 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#reload" };
39 { name = "module", type = "list-single", value = modules, label = "Module to be reloaded:"}; 38 { name = "module", type = "list-single", label = "Module to be reloaded:"};
40 }; 39 };
41 if state then 40 if state then
42 if data.action == "cancel" then 41 if data.action == "cancel" then
43 return { status = "canceled" }; 42 return { status = "canceled" };
44 end 43 end
49 else 48 else
50 return { status = "completed", error = 'Failed to reload module "'..fields.module..'" on host "'..data.to.. 49 return { status = "completed", error = 'Failed to reload module "'..fields.module..'" on host "'..data.to..
51 '". Error was: "'..tostring(err)..'"' }; 50 '". Error was: "'..tostring(err)..'"' };
52 end 51 end
53 else 52 else
54 local modules2 = array.collect(keys(hosts[data.to].modules)):sort(); 53 local modules = array.collect(keys(hosts[data.to].modules)):sort();
55 for i, val in ipairs(modules2) do 54 return { status = "executing", form = { layout = layout; data = { module = modules } } }, "executing";
56 modules[i] = val;
57 end
58 return { status = "executing", form = layout }, "executing";
59 end 55 end
60 end 56 end
61 57
62 -- TODO: Allow unloading multiple modules (depends on list-multi) 58 -- TODO: Allow unloading multiple modules (depends on list-multi)
63 function unload_modules_handler(self, data, state) 59 function unload_modules_handler(self, data, state)
64 local modules = {};
65 local layout = dataforms_new { 60 local layout = dataforms_new {
66 title = "Unload module"; 61 title = "Unload module";
67 instructions = "Select the module to be unloaded"; 62 instructions = "Select the module to be unloaded";
68 63
69 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" }; 64 { 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:"}; 65 { name = "module", type = "list-single", label = "Module to be unloaded:"};
71 }; 66 };
72 if state then 67 if state then
73 if data.action == "cancel" then 68 if data.action == "cancel" then
74 return { status = "canceled" }; 69 return { status = "canceled" };
75 end 70 end
80 else 75 else
81 return { status = "completed", error = 'Failed to unload module "'..fields.module..'" on host "'..data.to.. 76 return { status = "completed", error = 'Failed to unload module "'..fields.module..'" on host "'..data.to..
82 '". Error was: "'..tostring(err)..'"' }; 77 '". Error was: "'..tostring(err)..'"' };
83 end 78 end
84 else 79 else
85 local modules2 = array.collect(keys(hosts[data.to].modules)):sort(); 80 local modules = array.collect(keys(hosts[data.to].modules)):sort();
86 for i, val in ipairs(modules2) do 81 return { status = "executing", form = { layout = layout; data = { module = modules } } }, "executing";
87 modules[i] = val;
88 end
89 return { status = "executing", form = layout }, "executing";
90 end 82 end
91 end 83 end
92 84
93 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); 85 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin");
94 local reload_modules_desc = adhoc_new("Reload module", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); 86 local reload_modules_desc = adhoc_new("Reload module", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin");