1 -- Copyright (C) 2009-2011 Florian Zeitz
3 -- This file is MIT/X11 licensed. Please see the
4 -- COPYING file in the source package for more information.
9 local prosody = _G.prosody;
10 local hosts = prosody.hosts;
11 local t_concat = table.concat;
13 local module_host = module:get_host();
15 local keys = require "util.iterators".keys;
16 local usermanager_user_exists = require "core.usermanager".user_exists;
17 local usermanager_create_user = require "core.usermanager".create_user;
18 local usermanager_delete_user = require "core.usermanager".delete_user;
19 local usermanager_get_password = require "core.usermanager".get_password;
20 local usermanager_set_password = require "core.usermanager".set_password;
21 local hostmanager_activate = require "core.hostmanager".activate;
22 local hostmanager_deactivate = require "core.hostmanager".deactivate;
23 local rm_load_roster = require "core.rostermanager".load_roster;
24 local st, jid = require "util.stanza", require "util.jid";
25 local timer_add_task = require "util.timer".add_task;
26 local dataforms_new = require "util.dataforms".new;
27 local array = require "util.array";
28 local modulemanager = require "modulemanager";
29 local core_post_stanza = prosody.core_post_stanza;
30 local adhoc_simple = require "util.adhoc".new_simple_form;
31 local adhoc_initial = require "util.adhoc".new_initial_data_form;
33 module:depends("adhoc");
34 local adhoc_new = module:require "adhoc".new;
36 local function generate_error_message(errors)
38 for name, err in pairs(errors) do
39 errmsg[#errmsg + 1] = name .. ": " .. err;
41 return { status = "completed", error = { message = t_concat(errmsg, "\n") } };
45 local add_user_layout = dataforms_new{
46 title = "Adding a User";
47 instructions = "Fill out this form to add a user.";
49 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
50 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for the account to be added" };
51 { name = "password", type = "text-private", label = "The password for this account" };
52 { name = "password-verify", type = "text-private", label = "Retype password" };
55 local add_user_command_handler = adhoc_simple(add_user_layout, function(fields, err)
57 return generate_error_message(err);
59 local username, host, resource = jid.split(fields.accountjid);
60 if module_host ~= host then
61 return { status = "completed", error = { message = "Trying to add a user on " .. host .. " but command was sent to " .. module_host}};
63 if (fields["password"] == fields["password-verify"]) and username and host then
64 if usermanager_user_exists(username, host) then
65 return { status = "completed", error = { message = "Account already exists" } };
67 if usermanager_create_user(username, fields.password, host) then
68 module:log("info", "Created new account %s@%s", username, host);
69 return { status = "completed", info = "Account successfully created" };
71 return { status = "completed", error = { message = "Failed to write data to disk" } };
75 module:log("debug", "Invalid data, password mismatch or empty username while creating account for %s", fields.accountjid or "<nil>");
76 return { status = "completed", error = { message = "Invalid data.\nPassword mismatch, or empty username" } };
80 -- Changing a user's password
81 local change_user_password_layout = dataforms_new{
82 title = "Changing a User Password";
83 instructions = "Fill out this form to change a user's password.";
85 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
86 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for this account" };
87 { name = "password", type = "text-private", required = true, label = "The password for this account" };
90 local change_user_password_command_handler = adhoc_simple(change_user_password_layout, function(fields, err)
92 return generate_error_message(err);
94 local username, host, resource = jid.split(fields.accountjid);
95 if module_host ~= host then
96 return { status = "completed", error = { message = "Trying to change the password of a user on " .. host .. " but command was sent to " .. module_host}};
98 if usermanager_user_exists(username, host) and usermanager_set_password(username, fields.password, host) then
99 return { status = "completed", info = "Password successfully changed" };
101 return { status = "completed", error = { message = "User does not exist" } };
105 -- Reloading the config
106 local function config_reload_handler(self, data, state)
107 local ok, err = prosody.reload_config();
109 return { status = "completed", info = "Configuration reloaded (modules may need to be reloaded for this to have an effect)" };
111 return { status = "completed", error = { message = "Failed to reload config: " .. tostring(err) } };
115 -- Deleting a user's account
116 local delete_user_layout = dataforms_new{
117 title = "Deleting a User";
118 instructions = "Fill out this form to delete a user.";
120 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
121 { name = "accountjids", type = "jid-multi", label = "The Jabber ID(s) to delete" };
124 local delete_user_command_handler = adhoc_simple(delete_user_layout, function(fields, err)
126 return generate_error_message(err);
129 local succeeded = {};
130 for _, aJID in ipairs(fields.accountjids) do
131 local username, host, resource = jid.split(aJID);
132 if (host == module_host) and usermanager_user_exists(username, host) and usermanager_delete_user(username, host) then
133 module:log("debug", "User %s has been deleted", aJID);
134 succeeded[#succeeded+1] = aJID;
136 module:log("debug", "Tried to delete non-existant user %s", aJID);
137 failed[#failed+1] = aJID;
140 return {status = "completed", info = (#succeeded ~= 0 and
141 "The following accounts were successfully deleted:\n"..t_concat(succeeded, "\n").."\n" or "")..
143 "The following accounts could not be deleted:\n"..t_concat(failed, "\n") or "") };
146 -- Ending a user's session
147 local function disconnect_user(match_jid)
148 local node, hostname, givenResource = jid.split(match_jid);
149 local host = hosts[hostname];
150 local sessions = host.sessions[node] and host.sessions[node].sessions;
151 for resource, session in pairs(sessions or {}) do
152 if not givenResource or (resource == givenResource) then
153 module:log("debug", "Disconnecting %s@%s/%s", node, hostname, resource);
160 local end_user_session_layout = dataforms_new{
161 title = "Ending a User Session";
162 instructions = "Fill out this form to end a user's session.";
164 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
165 { name = "accountjids", type = "jid-multi", label = "The Jabber ID(s) for which to end sessions" };
168 local end_user_session_handler = adhoc_simple(end_user_session_layout, function(fields, err)
170 return generate_error_message(err);
173 local succeeded = {};
174 for _, aJID in ipairs(fields.accountjids) do
175 local username, host, resource = jid.split(aJID);
176 if (host == module_host) and usermanager_user_exists(username, host) and disconnect_user(aJID) then
177 succeeded[#succeeded+1] = aJID;
179 failed[#failed+1] = aJID;
182 return {status = "completed", info = (#succeeded ~= 0 and
183 "The following accounts were successfully disconnected:\n"..t_concat(succeeded, "\n").."\n" or "")..
185 "The following accounts could not be disconnected:\n"..t_concat(failed, "\n") or "") };
188 -- Getting a user's password
189 local get_user_password_layout = dataforms_new{
190 title = "Getting User's Password";
191 instructions = "Fill out this form to get a user's password.";
193 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
194 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for which to retrieve the password" };
197 local get_user_password_result_layout = dataforms_new{
198 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
199 { name = "accountjid", type = "jid-single", label = "JID" };
200 { name = "password", type = "text-single", label = "Password" };
203 local get_user_password_handler = adhoc_simple(get_user_password_layout, function(fields, err)
205 return generate_error_message(err);
207 local user, host, resource = jid.split(fields.accountjid);
208 local accountjid = "";
210 if host ~= module_host then
211 return { status = "completed", error = { message = "Tried to get password for a user on " .. host .. " but command was sent to " .. module_host } };
212 elseif usermanager_user_exists(user, host) then
213 accountjid = fields.accountjid;
214 password = usermanager_get_password(user, host);
216 return { status = "completed", error = { message = "User does not exist" } };
218 return { status = "completed", result = { layout = get_user_password_result_layout, values = {accountjid = accountjid, password = password} } };
221 -- Getting a user's roster
222 local get_user_roster_layout = dataforms_new{
223 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
224 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for which to retrieve the roster" };
227 local get_user_roster_result_layout = dataforms_new{
228 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
229 { name = "accountjid", type = "jid-single", label = "This is the roster for" };
230 { name = "roster", type = "text-multi", label = "Roster XML" };
233 local get_user_roster_handler = adhoc_simple(get_user_roster_layout, function(fields, err)
235 return generate_error_message(err);
238 local user, host, resource = jid.split(fields.accountjid);
239 if host ~= module_host then
240 return { status = "completed", error = { message = "Tried to get roster for a user on " .. host .. " but command was sent to " .. module_host } };
241 elseif not usermanager_user_exists(user, host) then
242 return { status = "completed", error = { message = "User does not exist" } };
244 local roster = rm_load_roster(user, host);
246 local query = st.stanza("query", { xmlns = "jabber:iq:roster" });
247 for jid in pairs(roster) do
248 if jid ~= "pending" and jid then
251 subscription = roster[jid].subscription,
252 ask = roster[jid].ask,
253 name = roster[jid].name,
255 for group in pairs(roster[jid].groups) do
256 query:tag("group"):text(group):up();
262 local query_text = tostring(query):gsub("><", ">\n<");
264 local result = get_user_roster_result_layout:form({ accountjid = user.."@"..host, roster = query_text }, "result");
265 result:add_child(query);
266 return { status = "completed", other = result };
269 -- Getting user statistics
270 local get_user_stats_layout = dataforms_new{
271 title = "Get User Statistics";
272 instructions = "Fill out this form to gather user statistics.";
274 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
275 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for statistics" };
278 local get_user_stats_result_layout = dataforms_new{
279 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
280 { name = "ipaddresses", type = "text-multi", label = "IP Addresses" };
281 { name = "rostersize", type = "text-single", label = "Roster size" };
282 { name = "onlineresources", type = "text-multi", label = "Online Resources" };
285 local get_user_stats_handler = adhoc_simple(get_user_stats_layout, function(fields, err)
287 return generate_error_message(err);
290 local user, host, resource = jid.split(fields.accountjid);
291 if host ~= module_host then
292 return { status = "completed", error = { message = "Tried to get stats for a user on " .. host .. " but command was sent to " .. module_host } };
293 elseif not usermanager_user_exists(user, host) then
294 return { status = "completed", error = { message = "User does not exist" } };
296 local roster = rm_load_roster(user, host);
297 local rostersize = 0;
299 local resources = "";
300 for jid in pairs(roster) do
301 if jid ~= "pending" and jid then
302 rostersize = rostersize + 1;
305 for resource, session in pairs((hosts[host].sessions[user] and hosts[host].sessions[user].sessions) or {}) do
306 resources = resources .. "\n" .. resource;
307 IPs = IPs .. "\n" .. session.ip;
309 return { status = "completed", result = {layout = get_user_stats_result_layout, values = {ipaddresses = IPs, rostersize = tostring(rostersize),
310 onlineresources = resources}} };
313 -- Getting a list of online users
314 local get_online_users_layout = dataforms_new{
315 title = "Getting List of Online Users";
316 instructions = "How many users should be returned at most?";
318 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
319 { name = "max_items", type = "list-single", label = "Maximum number of users",
320 value = { "25", "50", "75", "100", "150", "200", "all" } };
321 { name = "details", type = "boolean", label = "Show details" };
324 local get_online_users_result_layout = dataforms_new{
325 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
326 { name = "onlineuserjids", type = "text-multi", label = "The list of all online users" };
329 local get_online_users_command_handler = adhoc_simple(get_online_users_layout, function(fields, err)
331 return generate_error_message(err);
334 local max_items = nil
335 if fields.max_items ~= "all" then
336 max_items = tonumber(fields.max_items);
340 for username, user in pairs(hosts[module_host].sessions or {}) do
341 if (max_items ~= nil) and (count >= max_items) then
344 users[#users+1] = username.."@"..module_host;
346 if fields.details then
347 for resource, session in pairs(user.sessions or {}) do
348 local status, priority = "unavailable", tostring(session.priority or "-");
349 if session.presence then
350 status = session.presence:child_with_name("show");
352 status = status:get_text() or "[invalid!]";
354 status = "available";
357 users[#users+1] = " - "..resource..": "..status.."("..priority..")";
361 return { status = "completed", result = {layout = get_online_users_result_layout, values = {onlineuserjids=t_concat(users, "\n")}} };
364 -- Getting a list of loaded modules
365 local list_modules_result = dataforms_new {
366 title = "List of loaded modules";
368 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#list" };
369 { name = "modules", type = "text-multi", label = "The following modules are loaded:" };
372 local function list_modules_handler(self, data, state)
373 local modules = array.collect(keys(hosts[module_host].modules)):sort():concat("\n");
374 return { status = "completed", result = { layout = list_modules_result; values = { modules = modules } } };
378 local load_module_layout = dataforms_new {
379 title = "Load module";
380 instructions = "Specify the module to be loaded";
382 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#load" };
383 { name = "module", type = "text-single", required = true, label = "Module to be loaded:"};
386 local load_module_handler = adhoc_simple(load_module_layout, function(fields, err)
388 return generate_error_message(err);
390 if modulemanager.is_loaded(module_host, fields.module) then
391 return { status = "completed", info = "Module already loaded" };
393 local ok, err = modulemanager.load(module_host, fields.module);
395 return { status = "completed", info = 'Module "'..fields.module..'" successfully loaded on host "'..module_host..'".' };
397 return { status = "completed", error = { message = 'Failed to load module "'..fields.module..'" on host "'..module_host..
398 '". Error was: "'..tostring(err or "<unspecified>")..'"' } };
402 -- Globally loading a module
403 local globally_load_module_layout = dataforms_new {
404 title = "Globally load module";
405 instructions = "Specify the module to be loaded on all hosts";
407 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-load" };
408 { name = "module", type = "text-single", required = true, label = "Module to globally load:"};
411 local globally_load_module_handler = adhoc_simple(globally_load_module_layout, function(fields, err)
412 local ok_list, err_list = {}, {};
415 return generate_error_message(err);
418 local ok, err = modulemanager.load(module_host, fields.module);
420 ok_list[#ok_list + 1] = module_host;
422 err_list[#err_list + 1] = module_host .. " (Error: " .. tostring(err) .. ")";
425 -- Is this a global module?
426 if modulemanager.is_loaded("*", fields.module) and not modulemanager.is_loaded(module_host, fields.module) then
427 return { status = "completed", info = 'Global module '..fields.module..' loaded.' };
430 -- This is either a shared or "normal" module, load it on all other hosts
431 for host_name, host in pairs(hosts) do
432 if host_name ~= module_host and host.type == "local" then
433 local ok, err = modulemanager.load(host_name, fields.module);
435 ok_list[#ok_list + 1] = host_name;
437 err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")";
442 local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully loaded onto the hosts:\n"..t_concat(ok_list, "\n")) or "")
443 .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
444 (#err_list > 0 and ("Failed to load the module "..fields.module.." onto the hosts:\n"..t_concat(err_list, "\n")) or "");
445 return { status = "completed", info = info };
449 local reload_modules_layout = dataforms_new {
450 title = "Reload modules";
451 instructions = "Select the modules to be reloaded";
453 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#reload" };
454 { name = "modules", type = "list-multi", required = true, label = "Modules to be reloaded:"};
457 local reload_modules_handler = adhoc_initial(reload_modules_layout, function()
458 return { modules = array.collect(keys(hosts[module_host].modules)):sort() };
459 end, function(fields, err)
461 return generate_error_message(err);
463 local ok_list, err_list = {}, {};
464 for _, module in ipairs(fields.modules) do
465 local ok, err = modulemanager.reload(module_host, module);
467 ok_list[#ok_list + 1] = module;
469 err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")";
472 local info = (#ok_list > 0 and ("The following modules were successfully reloaded on host "..module_host..":\n"..t_concat(ok_list, "\n")) or "")
473 .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
474 (#err_list > 0 and ("Failed to reload the following modules on host "..module_host..":\n"..t_concat(err_list, "\n")) or "");
475 return { status = "completed", info = info };
478 -- Globally reloading a module
479 local globally_reload_module_layout = dataforms_new {
480 title = "Globally reload module";
481 instructions = "Specify the module to reload on all hosts";
483 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-reload" };
484 { name = "module", type = "list-single", required = true, label = "Module to globally reload:"};
487 local globally_reload_module_handler = adhoc_initial(globally_reload_module_layout, function()
488 local loaded_modules = array(keys(modulemanager.get_modules("*")));
489 for _, host in pairs(hosts) do
490 loaded_modules:append(array(keys(host.modules)));
492 loaded_modules = array(set.new(loaded_modules):items()):sort();
493 return { module = loaded_modules };
494 end, function(fields, err)
495 local is_global = false;
498 return generate_error_message(err);
501 if modulemanager.is_loaded("*", fields.module) then
502 local ok, err = modulemanager.reload("*", fields.module);
504 return { status = "completed", info = 'Global module '..fields.module..' failed to reload: '..err };
509 local ok_list, err_list = {}, {};
510 for host_name, host in pairs(hosts) do
511 if modulemanager.is_loaded(host_name, fields.module) then
512 local ok, err = modulemanager.reload(host_name, fields.module);
514 ok_list[#ok_list + 1] = host_name;
516 err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")";
521 if #ok_list == 0 and #err_list == 0 then
523 return { status = "completed", info = 'Successfully reloaded global module '..fields.module };
525 return { status = "completed", info = 'Module '..fields.module..' not loaded on any host.' };
529 local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully reloaded on the hosts:\n"..t_concat(ok_list, "\n")) or "")
530 .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
531 (#err_list > 0 and ("Failed to reload the module "..fields.module.." on the hosts:\n"..t_concat(err_list, "\n")) or "");
532 return { status = "completed", info = info };
535 local function send_to_online(message, server)
537 sessions = { [server] = hosts[server] };
543 for domain, session in pairs(sessions) do
544 for user in pairs(session.sessions or {}) do
546 message.attr.from = domain;
547 message.attr.to = user.."@"..domain;
548 core_post_stanza(session, message);
555 -- Shutting down the service
556 local shut_down_service_layout = dataforms_new{
557 title = "Shutting Down the Service";
558 instructions = "Fill out this form to shut down the service.";
560 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
561 { name = "delay", type = "list-single", label = "Time delay before shutting down",
562 value = { {label = "30 seconds", value = "30"},
563 {label = "60 seconds", value = "60"},
564 {label = "90 seconds", value = "90"},
565 {label = "2 minutes", value = "120"},
566 {label = "3 minutes", value = "180"},
567 {label = "4 minutes", value = "240"},
568 {label = "5 minutes", value = "300"},
571 { name = "announcement", type = "text-multi", label = "Announcement" };
574 local shut_down_service_handler = adhoc_simple(shut_down_service_layout, function(fields, err)
576 return generate_error_message(err);
579 if fields.announcement and #fields.announcement > 0 then
580 local message = st.message({type = "headline"}, fields.announcement):up()
581 :tag("subject"):text("Server is shutting down");
582 send_to_online(message);
585 timer_add_task(tonumber(fields.delay or "5"), function(time) prosody.shutdown("Shutdown by adhoc command") end);
587 return { status = "completed", info = "Server is about to shut down" };
591 local unload_modules_layout = dataforms_new {
592 title = "Unload modules";
593 instructions = "Select the modules to be unloaded";
595 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" };
596 { name = "modules", type = "list-multi", required = true, label = "Modules to be unloaded:"};
599 local unload_modules_handler = adhoc_initial(unload_modules_layout, function()
600 return { modules = array.collect(keys(hosts[module_host].modules)):sort() };
601 end, function(fields, err)
603 return generate_error_message(err);
605 local ok_list, err_list = {}, {};
606 for _, module in ipairs(fields.modules) do
607 local ok, err = modulemanager.unload(module_host, module);
609 ok_list[#ok_list + 1] = module;
611 err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")";
614 local info = (#ok_list > 0 and ("The following modules were successfully unloaded on host "..module_host..":\n"..t_concat(ok_list, "\n")) or "")
615 .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
616 (#err_list > 0 and ("Failed to unload the following modules on host "..module_host..":\n"..t_concat(err_list, "\n")) or "");
617 return { status = "completed", info = info };
620 -- Globally unloading a module
621 local globally_unload_module_layout = dataforms_new {
622 title = "Globally unload module";
623 instructions = "Specify a module to unload on all hosts";
625 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-unload" };
626 { name = "module", type = "list-single", required = true, label = "Module to globally unload:"};
629 local globally_unload_module_handler = adhoc_initial(globally_unload_module_layout, function()
630 local loaded_modules = array(keys(modulemanager.get_modules("*")));
631 for _, host in pairs(hosts) do
632 loaded_modules:append(array(keys(host.modules)));
634 loaded_modules = array(set.new(loaded_modules):items()):sort();
635 return { module = loaded_modules };
636 end, function(fields, err)
637 local is_global = false;
639 return generate_error_message(err);
642 if modulemanager.is_loaded("*", fields.module) then
643 local ok, err = modulemanager.unload("*", fields.module);
645 return { status = "completed", info = 'Global module '..fields.module..' failed to unload: '..err };
650 local ok_list, err_list = {}, {};
651 for host_name, host in pairs(hosts) do
652 if modulemanager.is_loaded(host_name, fields.module) then
653 local ok, err = modulemanager.unload(host_name, fields.module);
655 ok_list[#ok_list + 1] = host_name;
657 err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")";
662 if #ok_list == 0 and #err_list == 0 then
664 return { status = "completed", info = 'Successfully unloaded global module '..fields.module };
666 return { status = "completed", info = 'Module '..fields.module..' not loaded on any host.' };
670 local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully unloaded on the hosts:\n"..t_concat(ok_list, "\n")) or "")
671 .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
672 (#err_list > 0 and ("Failed to unload the module "..fields.module.." on the hosts:\n"..t_concat(err_list, "\n")) or "");
673 return { status = "completed", info = info };
677 local activate_host_layout = dataforms_new {
678 title = "Activate host";
681 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/hosts#activate" };
682 { name = "host", type = "text-single", required = true, label = "Host:"};
685 local activate_host_handler = adhoc_simple(activate_host_layout, function(fields, err)
687 return generate_error_message(err);
689 local ok, err = hostmanager_activate(fields.host);
692 return { status = "completed", info = fields.host .. " activated" };
694 return { status = "canceled", error = err }
698 -- Deactivating a host
699 local deactivate_host_layout = dataforms_new {
700 title = "Deactivate host";
703 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/hosts#activate" };
704 { name = "host", type = "text-single", required = true, label = "Host:"};
707 local deactivate_host_handler = adhoc_simple(deactivate_host_layout, function(fields, err)
709 return generate_error_message(err);
711 local ok, err = hostmanager_deactivate(fields.host);
714 return { status = "completed", info = fields.host .. " deactivated" };
716 return { status = "canceled", error = err }
721 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin");
722 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin");
723 local config_reload_desc = adhoc_new("Reload configuration", "http://prosody.im/protocol/config#reload", config_reload_handler, "global_admin");
724 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin");
725 local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin");
726 local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin");
727 local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin");
728 local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin");
729 local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users-list", get_online_users_command_handler, "admin");
730 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin");
731 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin");
732 local globally_load_module_desc = adhoc_new("Globally load module", "http://prosody.im/protocol/modules#global-load", globally_load_module_handler, "global_admin");
733 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin");
734 local globally_reload_module_desc = adhoc_new("Globally reload module", "http://prosody.im/protocol/modules#global-reload", globally_reload_module_handler, "global_admin");
735 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin");
736 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin");
737 local globally_unload_module_desc = adhoc_new("Globally unload module", "http://prosody.im/protocol/modules#global-unload", globally_unload_module_handler, "global_admin");
738 local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin");
739 local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin");
741 module:provides("adhoc", add_user_desc);
742 module:provides("adhoc", change_user_password_desc);
743 module:provides("adhoc", config_reload_desc);
744 module:provides("adhoc", delete_user_desc);
745 module:provides("adhoc", end_user_session_desc);
746 module:provides("adhoc", get_user_password_desc);
747 module:provides("adhoc", get_user_roster_desc);
748 module:provides("adhoc", get_user_stats_desc);
749 module:provides("adhoc", get_online_users_desc);
750 module:provides("adhoc", list_modules_desc);
751 module:provides("adhoc", load_module_desc);
752 module:provides("adhoc", globally_load_module_desc);
753 module:provides("adhoc", reload_modules_desc);
754 module:provides("adhoc", globally_reload_module_desc);
755 module:provides("adhoc", shut_down_service_desc);
756 module:provides("adhoc", unload_modules_desc);
757 module:provides("adhoc", globally_unload_module_desc);
758 module:provides("adhoc", activate_host_desc);
759 module:provides("adhoc", deactivate_host_desc);