mod_bosh: Store time to destroy session in inactive_sessions, removing dependency...
[prosody.git] / plugins / mod_admin_adhoc.lua
1 -- Copyright (C) 2009-2011 Florian Zeitz
2 --
3 -- This file is MIT/X11 licensed. Please see the
4 -- COPYING file in the source package for more information.
5 --
6
7 local _G = _G;
8
9 local prosody = _G.prosody;
10 local hosts = prosody.hosts;
11 local t_concat = table.concat;
12
13 require "util.iterators";
14 local usermanager_user_exists = require "core.usermanager".user_exists;
15 local usermanager_create_user = require "core.usermanager".create_user;
16 local usermanager_get_password = require "core.usermanager".get_password;
17 local usermanager_set_password = require "core.usermanager".set_password;
18 local is_admin = require "core.usermanager".is_admin;
19 local rm_load_roster = require "core.rostermanager".load_roster;
20 local st, jid, uuid = require "util.stanza", require "util.jid", require "util.uuid";
21 local timer_add_task = require "util.timer".add_task;
22 local dataforms_new = require "util.dataforms".new;
23 local array = require "util.array";
24 local modulemanager = require "modulemanager";
25
26 local adhoc_new = module:require "adhoc".new;
27
28 function add_user_command_handler(self, data, state)
29         local add_user_layout = dataforms_new{
30                 title = "Adding a User";
31                 instructions = "Fill out this form to add a user.";
32
33                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
34                 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for the account to be added" };
35                 { name = "password", type = "text-private", label = "The password for this account" };
36                 { name = "password-verify", type = "text-private", label = "Retype password" };
37         };
38
39         if state then
40                 if data.action == "cancel" then
41                         return { status = "canceled" };
42                 end
43                 local fields = add_user_layout:data(data.form);
44                 if not fields.accountjid then
45                         return { status = "completed", error = { message = "You need to specify a JID." } };
46                 end
47                 local username, host, resource = jid.split(fields.accountjid);
48                 if data.to ~= host then
49                         return { status = "completed", error = { message = "Trying to add a user on " .. host .. " but command was sent to " .. data.to}};
50                 end
51                 if (fields["password"] == fields["password-verify"]) and username and host then
52                         if usermanager_user_exists(username, host) then
53                                 return { status = "completed", error = { message = "Account already exists" } };
54                         else
55                                 if usermanager_create_user(username, fields.password, host) then
56                                         module:log("info", "Created new account " .. username.."@"..host);
57                                         return { status = "completed", info = "Account successfully created" };
58                                 else
59                                         return { status = "completed", error = { message = "Failed to write data to disk" } };
60                                 end
61                         end
62                 else
63                         module:log("debug", (fields.accountjid or "<nil>") .. " " .. (fields.password or "<nil>") .. " "
64                                 .. (fields["password-verify"] or "<nil>"));
65                         return { status = "completed", error = { message = "Invalid data.\nPassword mismatch, or empty username" } };
66                 end
67         else
68                 return { status = "executing", form = add_user_layout }, "executing";
69         end
70 end
71
72 function change_user_password_command_handler(self, data, state)
73         local change_user_password_layout = dataforms_new{
74                 title = "Changing a User Password";
75                 instructions = "Fill out this form to change a user's password.";
76
77                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
78                 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for this account" };
79                 { name = "password", type = "text-private", required = true, label = "The password for this account" };
80         };
81
82         if state then
83                 if data.action == "cancel" then
84                         return { status = "canceled" };
85                 end
86                 local fields = change_user_password_layout:data(data.form);
87                 if not fields.accountjid or fields.accountjid == "" or not fields.password then
88                         return { status = "completed", error = { message = "Please specify username and password" } };
89                 end
90                 local username, host, resource = jid.split(fields.accountjid);
91                 if data.to ~= host then
92                         return { status = "completed", error = { message = "Trying to change the password of a user on " .. host .. " but command was sent to " .. data.to}};
93                 end
94                 if usermanager_user_exists(username, host) and usermanager_set_password(username, fields.password, host) then
95                         return { status = "completed", info = "Password successfully changed" };
96                 else
97                         return { status = "completed", error = { message = "User does not exist" } };
98                 end
99         else
100                 return { status = "executing", form = change_user_password_layout }, "executing";
101         end
102 end
103
104 function config_reload_handler(self, data, state)
105         local ok, err = prosody.reload_config();
106         if ok then
107                 return { status = "completed", info = "Configuration reloaded (modules may need to be reloaded for this to have an effect)" };
108         else
109                 return { status = "completed", error = { message = "Failed to reload config: " .. tostring(err) } };
110         end
111 end
112
113
114 function delete_user_command_handler(self, data, state)
115         local delete_user_layout = dataforms_new{
116                 title = "Deleting a User";
117                 instructions = "Fill out this form to delete a user.";
118
119                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
120                 { name = "accountjids", type = "jid-multi", label = "The Jabber ID(s) to delete" };
121         };
122
123         if state then
124                 if data.action == "cancel" then
125                         return { status = "canceled" };
126                 end
127                 local fields = delete_user_layout:data(data.form);
128                 local failed = {};
129                 local succeeded = {};
130                 for _, aJID in ipairs(fields.accountjids) do
131                         local username, host, resource = jid.split(aJID);
132                         if (host == data.to) and  usermanager_user_exists(username, host) and disconnect_user(aJID) and usermanager_create_user(username, nil, host) then
133                                 module:log("debug", "User " .. aJID .. " has been deleted");
134                                 succeeded[#succeeded+1] = aJID;
135                         else
136                                 module:log("debug", "Tried to delete non-existant user "..aJID);
137                                 failed[#failed+1] = aJID;
138                         end
139                 end
140                 return {status = "completed", info = (#succeeded ~= 0 and
141                                 "The following accounts were successfully deleted:\n"..t_concat(succeeded, "\n").."\n" or "")..
142                                 (#failed ~= 0 and
143                                 "The following accounts could not be deleted:\n"..t_concat(failed, "\n") or "") };
144         else
145                 return { status = "executing", form = delete_user_layout }, "executing";
146         end
147 end
148
149 function disconnect_user(match_jid)
150         local node, hostname, givenResource = jid.split(match_jid);
151         local host = hosts[hostname];
152         local sessions = host.sessions[node] and host.sessions[node].sessions;
153         for resource, session in pairs(sessions or {}) do
154                 if not givenResource or (resource == givenResource) then
155                         module:log("debug", "Disconnecting "..node.."@"..hostname.."/"..resource);
156                         session:close();
157                 end
158         end
159         return true;
160 end
161
162 function end_user_session_handler(self, data, state)
163         local end_user_session_layout = dataforms_new{
164                 title = "Ending a User Session";
165                 instructions = "Fill out this form to end a user's session.";
166
167                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
168                 { name = "accountjids", type = "jid-multi", label = "The Jabber ID(s) for which to end sessions" };
169         };
170
171         if state then
172                 if data.action == "cancel" then
173                         return { status = "canceled" };
174                 end
175
176                 local fields = end_user_session_layout:data(data.form);
177                 local failed = {};
178                 local succeeded = {};
179                 for _, aJID in ipairs(fields.accountjids) do
180                         local username, host, resource = jid.split(aJID);
181                         if (host == data.to) and  usermanager_user_exists(username, host) and disconnect_user(aJID) then
182                                 succeeded[#succeeded+1] = aJID;
183                         else
184                                 failed[#failed+1] = aJID;
185                         end
186                 end
187                 return {status = "completed", info = (#succeeded ~= 0 and
188                                 "The following accounts were successfully disconnected:\n"..t_concat(succeeded, "\n").."\n" or "")..
189                                 (#failed ~= 0 and
190                                 "The following accounts could not be disconnected:\n"..t_concat(failed, "\n") or "") };
191         else
192                 return { status = "executing", form = end_user_session_layout }, "executing";
193         end
194 end
195
196 local end_user_session_layout = dataforms_new{
197         title = "Ending a User Session";
198         instructions = "Fill out this form to end a user's session.";
199
200         { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
201         { name = "accountjids", type = "jid-multi", label = "The Jabber ID(s) for which to end sessions" };
202 };
203
204
205 function get_user_password_handler(self, data, state)
206         local get_user_password_layout = dataforms_new{
207                 title = "Getting User's Password";
208                 instructions = "Fill out this form to get a user's password.";
209
210                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
211                 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for which to retrieve the password" };
212         };
213
214         local get_user_password_result_layout = dataforms_new{
215                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
216                 { name = "accountjid", type = "jid-single", label = "JID" };
217                 { name = "password", type = "text-single", label = "Password" };
218         };
219
220         if state then
221                 if data.action == "cancel" then
222                         return { status = "canceled" };
223                 end
224                 local fields = get_user_password_layout:data(data.form);
225                 if not fields.accountjid then
226                         return { status = "completed", error = { message = "Please specify a JID." } };
227                 end
228                 local user, host, resource = jid.split(fields.accountjid);
229                 local accountjid = "";
230                 local password = "";
231                 if host ~= data.to then
232                         return { status = "completed", error = { message = "Tried to get password for a user on " .. host .. " but command was sent to " .. data.to } };
233                 elseif usermanager_user_exists(user, host) then
234                         accountjid = fields.accountjid;
235                         password = usermanager_get_password(user, host);
236                 else
237                         return { status = "completed", error = { message = "User does not exist" } };
238                 end
239                 return { status = "completed", result = { layout = get_user_password_result_layout, values = {accountjid = accountjid, password = password} } };
240         else
241                 return { status = "executing", form = get_user_password_layout }, "executing";
242         end
243 end
244
245 function get_user_roster_handler(self, data, state)
246         local get_user_roster_layout = dataforms_new{
247                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
248                 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for which to retrieve the roster" };
249         };
250
251         local get_user_roster_result_layout = dataforms_new{
252                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
253                 { name = "accountjid", type = "jid-single", label = "This is the roster for" };
254                 { name = "roster", type = "text-multi", label = "Roster XML" };
255         };
256
257         if state then
258                 if data.action == "cancel" then
259                         return { status = "canceled" };
260                 end
261
262                 local fields = get_user_roster_layout:data(data.form);
263
264                 if not fields.accountjid then
265                         return { status = "completed", error = { message = "Please specify a JID" } };
266                 end
267
268                 local user, host, resource = jid.split(fields.accountjid);
269                 if host ~= data.to then
270                         return { status = "completed", error = { message = "Tried to get roster for a user on " .. host .. " but command was sent to " .. data.to } };
271                 elseif not usermanager_user_exists(user, host) then
272                         return { status = "completed", error = { message = "User does not exist" } };
273                 end
274                 local roster = rm_load_roster(user, host);
275
276                 local query = st.stanza("query", { xmlns = "jabber:iq:roster" });
277                 for jid in pairs(roster) do
278                         if jid ~= "pending" and jid then
279                                 query:tag("item", {
280                                         jid = jid,
281                                         subscription = roster[jid].subscription,
282                                         ask = roster[jid].ask,
283                                         name = roster[jid].name,
284                                 });
285                                 for group in pairs(roster[jid].groups) do
286                                         query:tag("group"):text(group):up();
287                                 end
288                                 query:up();
289                         end
290                 end
291
292                 local query_text = query:__tostring(); -- TODO: Use upcoming pretty_print() function
293                 query_text = query_text:gsub("><", ">\n<");
294
295                 local result = get_user_roster_result_layout:form({ accountjid = user.."@"..host, roster = query_text }, "result");
296                 result:add_child(query);
297                 return { status = "completed", other = result };
298         else
299                 return { status = "executing", form = get_user_roster_layout }, "executing";
300         end
301 end
302
303 function get_user_stats_handler(self, data, state)
304         local get_user_stats_layout = dataforms_new{
305                 title = "Get User Statistics";
306                 instructions = "Fill out this form to gather user statistics.";
307
308                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
309                 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for statistics" };
310         };
311
312         local get_user_stats_result_layout = dataforms_new{
313                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
314                 { name = "ipaddresses", type = "text-multi", label = "IP Addresses" };
315                 { name = "rostersize", type = "text-single", label = "Roster size" };
316                 { name = "onlineresources", type = "text-multi", label = "Online Resources" };
317         };
318
319         if state then
320                 if data.action == "cancel" then
321                         return { status = "canceled" };
322                 end
323
324                 local fields = get_user_stats_layout:data(data.form);
325
326                 if not fields.accountjid then
327                         return { status = "completed", error = { message = "Please specify a JID." } };
328                 end
329
330                 local user, host, resource = jid.split(fields.accountjid);
331                 if host ~= data.to then
332                         return { status = "completed", error = { message = "Tried to get stats for a user on " .. host .. " but command was sent to " .. data.to } };
333                 elseif not usermanager_user_exists(user, host) then
334                         return { status = "completed", error = { message = "User does not exist" } };
335                 end
336                 local roster = rm_load_roster(user, host);
337                 local rostersize = 0;
338                 local IPs = "";
339                 local resources = "";
340                 for jid in pairs(roster) do
341                         if jid ~= "pending" and jid then
342                                 rostersize = rostersize + 1;
343                         end
344                 end
345                 for resource, session in pairs((hosts[host].sessions[user] and hosts[host].sessions[user].sessions) or {}) do
346                         resources = resources .. "\n" .. resource;
347                         IPs = IPs .. "\n" .. session.ip;
348                 end
349                 return { status = "completed", result = {layout = get_user_stats_result_layout, values = {ipaddresses = IPs, rostersize = tostring(rostersize),
350                         onlineresources = resources}} };
351         else
352                 return { status = "executing", form = get_user_stats_layout }, "executing";
353         end
354 end
355
356 function get_online_users_command_handler(self, data, state)
357         local get_online_users_layout = dataforms_new{
358                 title = "Getting List of Online Users";
359                 instructions = "How many users should be returned at most?";
360
361                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
362                 { name = "max_items", type = "list-single", label = "Maximum number of users",
363                         value = { "25", "50", "75", "100", "150", "200", "all" } };
364                 { name = "details", type = "boolean", label = "Show details" };
365         };
366
367         local get_online_users_result_layout = dataforms_new{
368                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
369                 { name = "onlineuserjids", type = "text-multi", label = "The list of all online users" };
370         };
371
372         if state then
373                 if data.action == "cancel" then
374                         return { status = "canceled" };
375                 end
376
377                 local fields = get_online_users_layout:data(data.form);
378
379                 local max_items = nil
380                 if fields.max_items ~= "all" then
381                         max_items = tonumber(fields.max_items);
382                 end
383                 local count = 0;
384                 local users = {};
385                 for username, user in pairs(hosts[data.to].sessions or {}) do
386                         if (max_items ~= nil) and (count >= max_items) then
387                                 break;
388                         end
389                         users[#users+1] = username.."@"..data.to;
390                         count = count + 1;
391                         if fields.details then
392                                 for resource, session in pairs(user.sessions or {}) do
393                                         local status, priority = "unavailable", tostring(session.priority or "-");
394                                         if session.presence then
395                                                 status = session.presence:child_with_name("show");
396                                                 if status then
397                                                         status = status:get_text() or "[invalid!]";
398                                                 else
399                                                         status = "available";
400                                                 end
401                                         end
402                                         users[#users+1] = " - "..resource..": "..status.."("..priority..")";
403                                 end
404                         end
405                 end
406                 return { status = "completed", result = {layout = get_online_users_result_layout, values = {onlineuserjids=t_concat(users, "\n")}} };
407         else
408                 return { status = "executing", form = get_online_users_layout }, "executing";
409         end
410 end
411
412 function list_modules_handler(self, data, state)
413         local result = dataforms_new {
414                 title = "List of loaded modules";
415
416                 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#list" };
417                 { name = "modules", type = "text-multi", label = "The following modules are loaded:" };
418         };
419
420         local modules = array.collect(keys(hosts[data.to].modules)):sort():concat("\n");
421
422         return { status = "completed", result = { layout = result; values = { modules = modules } } };
423 end
424
425 function load_module_handler(self, data, state)
426         local layout = dataforms_new {
427                 title = "Load module";
428                 instructions = "Specify the module to be loaded";
429
430                 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#load" };
431                 { name = "module", type = "text-single", required = true, label = "Module to be loaded:"};
432         };
433         if state then
434                 if data.action == "cancel" then
435                         return { status = "canceled" };
436                 end
437                 local fields = layout:data(data.form);
438                 if (not fields.module) or (fields.module == "") then
439                         return { status = "completed", error = {
440                                 message = "Please specify a module."
441                         } };
442                 end
443                 if modulemanager.is_loaded(data.to, fields.module) then
444                         return { status = "completed", info = "Module already loaded" };
445                 end
446                 local ok, err = modulemanager.load(data.to, fields.module);
447                 if ok then
448                         return { status = "completed", info = 'Module "'..fields.module..'" successfully loaded on host "'..data.to..'".' };
449                 else
450                         return { status = "completed", error = { message = 'Failed to load module "'..fields.module..'" on host "'..data.to..
451                         '". Error was: "'..tostring(err or "<unspecified>")..'"' } };
452                 end
453         else
454                 local modules = array.collect(keys(hosts[data.to].modules)):sort();
455                 return { status = "executing", form = layout }, "executing";
456         end
457 end
458
459 function reload_modules_handler(self, data, state)
460         local layout = dataforms_new {
461                 title = "Reload modules";
462                 instructions = "Select the modules to be reloaded";
463
464                 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#reload" };
465                 { name = "modules", type = "list-multi", required = true, label = "Modules to be reloaded:"};
466         };
467         if state then
468                 if data.action == "cancel" then
469                         return { status = "canceled" };
470                 end
471                 local fields = layout:data(data.form);
472                 if #fields.modules == 0 then
473                         return { status = "completed", error = {
474                                 message = "Please specify a module. (This means your client misbehaved, as this field is required)"
475                         } };
476                 end
477                 local ok_list, err_list = {}, {};
478                 for _, module in ipairs(fields.modules) do
479                         local ok, err = modulemanager.reload(data.to, module);
480                         if ok then
481                                 ok_list[#ok_list + 1] = module;
482                         else
483                                 err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")";
484                         end
485                 end
486                 local info = (#ok_list > 0 and ("The following modules were successfully reloaded on host "..data.to..":\n"..t_concat(ok_list, "\n")) or "")..
487                         (#err_list > 0 and ("Failed to reload the following modules on host "..data.to..":\n"..t_concat(err_list, "\n")) or "");
488                 return { status = "completed", info = info };
489         else
490                 local modules = array.collect(keys(hosts[data.to].modules)):sort();
491                 return { status = "executing", form = { layout = layout; values = { modules = modules } } }, "executing";
492         end
493 end
494
495 function send_to_online(message, server)
496         if server then
497                 sessions = { [server] = hosts[server] };
498         else
499                 sessions = hosts;
500         end
501
502         local c = 0;
503         for domain, session in pairs(sessions) do
504                 for user in pairs(session.sessions or {}) do
505                         c = c + 1;
506                         message.attr.from = domain;
507                         message.attr.to = user.."@"..domain;
508                         core_post_stanza(session, message);
509                 end
510         end
511
512         return c;
513 end
514
515 function shut_down_service_handler(self, data, state)
516         local shut_down_service_layout = dataforms_new{
517                 title = "Shutting Down the Service";
518                 instructions = "Fill out this form to shut down the service.";
519
520                 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
521                 { name = "delay", type = "list-single", label = "Time delay before shutting down",
522                         value = { {label = "30 seconds", value = "30"},
523                                   {label = "60 seconds", value = "60"},
524                                   {label = "90 seconds", value = "90"},
525                                   {label = "2 minutes", value = "120"},
526                                   {label = "3 minutes", value = "180"},
527                                   {label = "4 minutes", value = "240"},
528                                   {label = "5 minutes", value = "300"},
529                         };
530                 };
531                 { name = "announcement", type = "text-multi", label = "Announcement" };
532         };
533
534         if state then
535                 if data.action == "cancel" then
536                         return { status = "canceled" };
537                 end
538
539                 local fields = shut_down_service_layout:data(data.form);
540
541                 if fields.announcement and #fields.announcement > 0 then
542                         local message = st.message({type = "headline"}, fields.announcement):up()
543                                 :tag("subject"):text("Server is shutting down");
544                         send_to_online(message);
545                 end
546
547                 timer_add_task(tonumber(fields.delay or "5"), prosody.shutdown);
548
549                 return { status = "completed", info = "Server is about to shut down" };
550         else
551                 return { status = "executing", form = shut_down_service_layout }, "executing";
552         end
553 end
554
555 function unload_modules_handler(self, data, state)
556         local layout = dataforms_new {
557                 title = "Unload modules";
558                 instructions = "Select the modules to be unloaded";
559
560                 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" };
561                 { name = "modules", type = "list-multi", required = true, label = "Modules to be unloaded:"};
562         };
563         if state then
564                 if data.action == "cancel" then
565                         return { status = "canceled" };
566                 end
567                 local fields = layout:data(data.form);
568                 if #fields.modules == 0 then
569                         return { status = "completed", error = {
570                                 message = "Please specify a module. (This means your client misbehaved, as this field is required)"
571                         } };
572                 end
573                 local ok_list, err_list = {}, {};
574                 for _, module in ipairs(fields.modules) do
575                         local ok, err = modulemanager.unload(data.to, module);
576                         if ok then
577                                 ok_list[#ok_list + 1] = module;
578                         else
579                                 err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")";
580                         end
581                 end
582                 local info = (#ok_list > 0 and ("The following modules were successfully unloaded on host "..data.to..":\n"..t_concat(ok_list, "\n")) or "")..
583                         (#err_list > 0 and ("Failed to unload the following modules on host "..data.to..":\n"..t_concat(err_list, "\n")) or "");
584                 return { status = "completed", info = info };
585         else
586                 local modules = array.collect(keys(hosts[data.to].modules)):sort();
587                 return { status = "executing", form = { layout = layout; values = { modules = modules } } }, "executing";
588         end
589 end
590
591 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin");
592 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin");
593 local config_reload_desc = adhoc_new("Reload configuration", "http://prosody.im/protocol/config#reload", config_reload_handler, "global_admin");
594 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin");
595 local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin");
596 local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin");
597 local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin");
598 local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin");
599 local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users", get_online_users_command_handler, "admin");
600 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin");
601 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin");
602 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin");
603 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin");
604 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin");
605
606 module:add_item("adhoc", add_user_desc);
607 module:add_item("adhoc", change_user_password_desc);
608 module:add_item("adhoc", config_reload_desc);
609 module:add_item("adhoc", delete_user_desc);
610 module:add_item("adhoc", end_user_session_desc);
611 module:add_item("adhoc", get_user_password_desc);
612 module:add_item("adhoc", get_user_roster_desc);
613 module:add_item("adhoc", get_user_stats_desc);
614 module:add_item("adhoc", get_online_users_desc);
615 module:add_item("adhoc", list_modules_desc);
616 module:add_item("adhoc", load_module_desc);
617 module:add_item("adhoc", reload_modules_desc);
618 module:add_item("adhoc", shut_down_service_desc);
619 module:add_item("adhoc", unload_modules_desc);