Annotate

mod_adhoc_cmd_modules/mod_adhoc_cmd_modules.lua @ 541:947103177844

mod_server_status: renamed mod_xml_status to mod_server_status as the option to output the stats in JSON was added.
author Marco Cirillo <maranda@lightwitch.org>
date Tue, 10 Jan 2012 19:36:28 +0000
parent 250:67f03b7786af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
203
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
1 -- Copyright (C) 2009-2010 Florian Zeitz
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
2 --
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
3 -- This file is MIT/X11 licensed. Please see the
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
4 -- COPYING file in the source package for more information.
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 --
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
7 local _G = _G;
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
8
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
9 local prosody = _G.prosody;
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
10 local hosts = prosody.hosts;
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
11
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
12 require "util.iterators";
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
13 local dataforms_new = require "util.dataforms".new;
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14 local array = require "util.array";
205
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
15 local modulemanager = require "modulemanager";
203
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16 local adhoc_new = module:require "adhoc".new;
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
17
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
18 function list_modules_handler(self, data, state)
205
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
19 local result = dataforms_new {
203
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20 title = "List of loaded modules";
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
21
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
22 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#list" };
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
23 { name = "modules", type = "text-multi", label = "The following modules are loaded:" };
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
24 };
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
25
205
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
26 local modules = array.collect(keys(hosts[data.to].modules)):sort():concat("\n");
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
27
250
67f03b7786af mod_adhoc: Fix dataform creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 241
diff changeset
28 return { status = "completed", result = { layout = result; values = { modules = modules } } };
205
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
29 end
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
30
208
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
31 function load_module_handler(self, data, state)
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
32 local layout = dataforms_new {
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
33 title = "Load module";
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
34 instructions = "Specify the module to be loaded";
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
35
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
36 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#load" };
235
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
37 { name = "module", type = "text-single", required = true, label = "Module to be loaded:"};
208
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
38 };
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
39 if state then
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
40 if data.action == "cancel" then
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
41 return { status = "canceled" };
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
42 end
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
43 local fields = layout:data(data.form);
235
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
44 if (not fields.module) or (fields.module == "") then
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
45 return { status = "completed", error = {
241
665552d75ee2 mod_adhoc_cmd_modules: Fix error message
Florian Zeitz <florob@babelmonkeys.de>
parents: 235
diff changeset
46 message = "Please specify a module."
235
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
47 } };
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
48 end
208
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
49 if modulemanager.is_loaded(data.to, fields.module) then
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
50 return { status = "completed", info = "Module already loaded" };
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
51 end
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
52 local ok, err = modulemanager.load(data.to, fields.module);
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
53 if ok then
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
54 return { status = "completed", info = 'Module "'..fields.module..'" successfully loaded on host "'..data.to..'".' };
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
55 else
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
56 return { status = "completed", error = { message = 'Failed to load module "'..fields.module..'" on host "'..data.to..
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
57 '". Error was: "'..tostring(err or "<unspecified>")..'"' } };
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
58 end
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
59 else
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
60 local modules = array.collect(keys(hosts[data.to].modules)):sort();
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
61 return { status = "executing", form = layout }, "executing";
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
62 end
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
63 end
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
64
206
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
65 -- TODO: Allow reloading multiple modules (depends on list-multi)
205
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
66 function reload_modules_handler(self, data, state)
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
67 local layout = dataforms_new {
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
68 title = "Reload module";
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
69 instructions = "Select the module to be reloaded";
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
70
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
71 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#reload" };
235
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
72 { name = "module", type = "list-single", required = true, label = "Module to be reloaded:"};
205
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
73 };
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
74 if state then
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
75 if data.action == "cancel" then
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
76 return { status = "canceled" };
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
77 end
208
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
78 local fields = layout:data(data.form);
235
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
79 if (not fields.module) or (fields.module == "") then
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
80 return { status = "completed", error = {
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
81 message = "Please specify a module. (This means your client misbehaved, as this field is required)"
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
82 } };
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
83 end
205
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
84 local ok, err = modulemanager.reload(data.to, fields.module);
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
85 if ok then
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
86 return { status = "completed", info = 'Module "'..fields.module..'" successfully reloaded on host "'..data.to..'".' };
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
87 else
208
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
88 return { status = "completed", error = { message = 'Failed to reload module "'..fields.module..'" on host "'..data.to..
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
89 '". Error was: "'..tostring(err)..'"' } };
205
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
90 end
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
91 else
207
1ae653712e37 mod_adhoc: Add capability to pass data to forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 206
diff changeset
92 local modules = array.collect(keys(hosts[data.to].modules)):sort();
250
67f03b7786af mod_adhoc: Fix dataform creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 241
diff changeset
93 return { status = "executing", form = { layout = layout; values = { module = modules } } }, "executing";
203
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
94 end
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
95 end
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
96
206
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
97 -- TODO: Allow unloading multiple modules (depends on list-multi)
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
98 function unload_modules_handler(self, data, state)
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
99 local layout = dataforms_new {
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
100 title = "Unload module";
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
101 instructions = "Select the module to be unloaded";
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
102
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
103 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" };
235
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
104 { name = "module", type = "list-single", required = true, label = "Module to be unloaded:"};
206
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
105 };
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
106 if state then
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
107 if data.action == "cancel" then
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
108 return { status = "canceled" };
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
109 end
208
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
110 local fields = layout:data(data.form);
235
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
111 if (not fields.module) or (fields.module == "") then
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
112 return { status = "completed", error = {
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
113 message = "Please specify a module. (This means your client misbehaved, as this field is required)"
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
114 } };
10a3cca32797 mod_adhoc_cmd_modules: Make required fields required, be more tollerant towards buggy clients
Florian Zeitz <florob@babelmonkeys.de>
parents: 208
diff changeset
115 end
206
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
116 local ok, err = modulemanager.unload(data.to, fields.module);
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
117 if ok then
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
118 return { status = "completed", info = 'Module "'..fields.module..'" successfully unloaded on host "'..data.to..'".' };
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
119 else
208
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
120 return { status = "completed", error = { message = 'Failed to unload module "'..fields.module..'" on host "'..data.to..
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
121 '". Error was: "'..tostring(err)..'"' } };
206
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
122 end
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
123 else
207
1ae653712e37 mod_adhoc: Add capability to pass data to forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 206
diff changeset
124 local modules = array.collect(keys(hosts[data.to].modules)):sort();
250
67f03b7786af mod_adhoc: Fix dataform creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 241
diff changeset
125 return { status = "executing", form = { layout = layout; values = { module = modules } } }, "executing";
206
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
126 end
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
127 end
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
128
203
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
129 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin");
208
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
130 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin");
205
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
131 local reload_modules_desc = adhoc_new("Reload module", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin");
206
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
132 local unload_modules_desc = adhoc_new("Unload module", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin");
203
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
133
4927b9737bb7 mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
134 module:add_item("adhoc", list_modules_desc);
208
214cb85cdfbf mod_adhoc_cmd_modules: Add "Load module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 207
diff changeset
135 module:add_item("adhoc", load_module_desc);
205
a6361a1fda5e mod_adhoc_cmd_modules: Add "Reload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 203
diff changeset
136 module:add_item("adhoc", reload_modules_desc);
206
d3498f115fcd mod_adhoc_cmd_modules: Add "Unload module" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 205
diff changeset
137 module:add_item("adhoc", unload_modules_desc);