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