Comparison

mod_adhoc_cmd_modules/mod_adhoc_cmd_modules.lua @ 235:10a3cca32797

mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
author Florian Zeitz <florob@babelmonkeys.de>
date Thu, 05 Aug 2010 23:09:56 +0200
parent 208:214cb85cdfbf
child 241:665552d75ee2
comparison
equal deleted inserted replaced
234:abcb59ab355c 235:10a3cca32797
32 local layout = dataforms_new { 32 local layout = dataforms_new {
33 title = "Load module"; 33 title = "Load module";
34 instructions = "Specify the module to be loaded"; 34 instructions = "Specify the module to be loaded";
35 35
36 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#load" }; 36 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#load" };
37 { name = "module", type = "text-single", label = "Module to be loaded:"}; 37 { name = "module", type = "text-single", required = true, label = "Module to be loaded:"};
38 }; 38 };
39 if state then 39 if state then
40 if data.action == "cancel" then 40 if data.action == "cancel" then
41 return { status = "canceled" }; 41 return { status = "canceled" };
42 end 42 end
43 local fields = layout:data(data.form); 43 local fields = layout:data(data.form);
44 if (not fields.module) or (fields.module == "") then
45 return { status = "completed", error = {
46 message = "Please specify a module. (This means your client misbehaved, as this field is required)"
47 } };
48 end
44 if modulemanager.is_loaded(data.to, fields.module) then 49 if modulemanager.is_loaded(data.to, fields.module) then
45 return { status = "completed", info = "Module already loaded" }; 50 return { status = "completed", info = "Module already loaded" };
46 end 51 end
47 local ok, err = modulemanager.load(data.to, fields.module); 52 local ok, err = modulemanager.load(data.to, fields.module);
48 if ok then 53 if ok then
62 local layout = dataforms_new { 67 local layout = dataforms_new {
63 title = "Reload module"; 68 title = "Reload module";
64 instructions = "Select the module to be reloaded"; 69 instructions = "Select the module to be reloaded";
65 70
66 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#reload" }; 71 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#reload" };
67 { name = "module", type = "list-single", label = "Module to be reloaded:"}; 72 { name = "module", type = "list-single", required = true, label = "Module to be reloaded:"};
68 }; 73 };
69 if state then 74 if state then
70 if data.action == "cancel" then 75 if data.action == "cancel" then
71 return { status = "canceled" }; 76 return { status = "canceled" };
72 end 77 end
73 local fields = layout:data(data.form); 78 local fields = layout:data(data.form);
79 if (not fields.module) or (fields.module == "") then
80 return { status = "completed", error = {
81 message = "Please specify a module. (This means your client misbehaved, as this field is required)"
82 } };
83 end
74 local ok, err = modulemanager.reload(data.to, fields.module); 84 local ok, err = modulemanager.reload(data.to, fields.module);
75 if ok then 85 if ok then
76 return { status = "completed", info = 'Module "'..fields.module..'" successfully reloaded on host "'..data.to..'".' }; 86 return { status = "completed", info = 'Module "'..fields.module..'" successfully reloaded on host "'..data.to..'".' };
77 else 87 else
78 return { status = "completed", error = { message = 'Failed to reload module "'..fields.module..'" on host "'..data.to.. 88 return { status = "completed", error = { message = 'Failed to reload module "'..fields.module..'" on host "'..data.to..
89 local layout = dataforms_new { 99 local layout = dataforms_new {
90 title = "Unload module"; 100 title = "Unload module";
91 instructions = "Select the module to be unloaded"; 101 instructions = "Select the module to be unloaded";
92 102
93 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" }; 103 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" };
94 { name = "module", type = "list-single", label = "Module to be unloaded:"}; 104 { name = "module", type = "list-single", required = true, label = "Module to be unloaded:"};
95 }; 105 };
96 if state then 106 if state then
97 if data.action == "cancel" then 107 if data.action == "cancel" then
98 return { status = "canceled" }; 108 return { status = "canceled" };
99 end 109 end
100 local fields = layout:data(data.form); 110 local fields = layout:data(data.form);
111 if (not fields.module) or (fields.module == "") then
112 return { status = "completed", error = {
113 message = "Please specify a module. (This means your client misbehaved, as this field is required)"
114 } };
115 end
101 local ok, err = modulemanager.unload(data.to, fields.module); 116 local ok, err = modulemanager.unload(data.to, fields.module);
102 if ok then 117 if ok then
103 return { status = "completed", info = 'Module "'..fields.module..'" successfully unloaded on host "'..data.to..'".' }; 118 return { status = "completed", info = 'Module "'..fields.module..'" successfully unloaded on host "'..data.to..'".' };
104 else 119 else
105 return { status = "completed", error = { message = 'Failed to unload module "'..fields.module..'" on host "'..data.to.. 120 return { status = "completed", error = { message = 'Failed to unload module "'..fields.module..'" on host "'..data.to..