comparison mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 155:7a037cb5ab9e

mod_adhoc_cmd_admin: Add "Get User Statistics" command
author Florian Zeitz < florob@babelmonkeys.de>
date Fri, 21 May 2010 19:24:57 +0200
parents 890140ade4e5
children b3a68e71b8a1
comparison
equal deleted inserted replaced
154:1849614af19a 155:7a037cb5ab9e
82 82
83 local get_user_roster_result_layout = dataforms_new{ 83 local get_user_roster_result_layout = dataforms_new{
84 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; 84 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
85 { name = "accountjid", type = "jid-single", label = "This is the roster for" }; 85 { name = "accountjid", type = "jid-single", label = "This is the roster for" };
86 { name = "roster", type = "text-multi", label = "Roster XML" }; 86 { name = "roster", type = "text-multi", label = "Roster XML" };
87 };
88
89 local get_user_stats_layout = dataforms_new{
90 title = "Get User Statistics";
91 instructions = "Fill out this form to gather user statistics.";
92
93 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
94 { name = "accountjid", type = "jid-single", label = "The Jabber ID for statistics" };
95 };
96
97 local get_user_stats_result_layout = dataforms_new{
98 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
99 { name = "ipaddresses", type = "text-multi", label = "IP Addresses" };
100 { name = "rostersize", type = "text-single", label = "Roster size" };
101 { name = "onlineresources", type = "text-multi", label = "Online Resources" };
87 }; 102 };
88 103
89 local get_online_users_layout = dataforms_new{ 104 local get_online_users_layout = dataforms_new{
90 title = "Getting List of Online Users"; 105 title = "Getting List of Online Users";
91 instructions = "How many users should be returned at most?"; 106 instructions = "How many users should be returned at most?";
290 else 305 else
291 return { status = "executing", form = get_user_roster_layout }, "executing"; 306 return { status = "executing", form = get_user_roster_layout }, "executing";
292 end 307 end
293 end 308 end
294 309
310 function get_user_stats_handler(self, data, state)
311 if state then
312 if data.action == "cancel" then
313 return { status = "canceled" };
314 end
315
316 local fields = get_user_stats_layout:data(data.form);
317
318 local user, host, resource = jid.split(fields.accountjid);
319 if not usermanager_user_exists(user, host) then
320 return { status = "error", error = { type = "cancel", condition = "item-not-found", message = "User does not exist" } };
321 end
322 local roster = rm_load_roster(user, host);
323 local rostersize = 0;
324 local IPs = "";
325 local resources = "";
326 for jid in pairs(roster) do
327 if jid ~= "pending" and jid then
328 rostersize = rostersize + 1;
329 end
330 end
331 for resource, session in pairs((hosts[host].sessions[user] and hosts[host].sessions[user].sessions) or {}) do
332 resources = resources .. "\n" .. resource;
333 IPs = IPs .. "\n" .. session.ip;
334 end
335 return { status = "completed", result = {layout = get_user_stats_result_layout, data = {ipaddresses = IPs, rostersize = tostring(rostersize),
336 onlineresources = resources}} };
337 else
338 return { status = "executing", form = get_user_stats_layout }, "executing";
339 end
340 end
341
295 function get_online_users_command_handler(self, data, state) 342 function get_online_users_command_handler(self, data, state)
296 if state then 343 if state then
297 if data.action == "cancel" then 344 if data.action == "cancel" then
298 return { status = "canceled" }; 345 return { status = "canceled" };
299 end 346 end
391 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin"); 438 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin");
392 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin"); 439 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin");
393 local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin"); 440 local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin");
394 local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin"); 441 local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin");
395 local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin"); 442 local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin");
443 local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin");
396 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"); 444 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");
397 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "admin"); 445 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "admin");
398 446
399 module:add_item("adhoc", add_user_desc); 447 module:add_item("adhoc", add_user_desc);
400 module:add_item("adhoc", announce_desc); 448 module:add_item("adhoc", announce_desc);
401 module:add_item("adhoc", change_user_password_desc); 449 module:add_item("adhoc", change_user_password_desc);
402 module:add_item("adhoc", delete_user_desc); 450 module:add_item("adhoc", delete_user_desc);
403 module:add_item("adhoc", end_user_session_desc); 451 module:add_item("adhoc", end_user_session_desc);
404 module:add_item("adhoc", get_user_password_desc); 452 module:add_item("adhoc", get_user_password_desc);
405 module:add_item("adhoc", get_user_roster_desc); 453 module:add_item("adhoc", get_user_roster_desc);
454 module:add_item("adhoc", get_user_stats_desc);
406 module:add_item("adhoc", get_online_users_desc); 455 module:add_item("adhoc", get_online_users_desc);
407 module:add_item("adhoc", shut_down_service_desc); 456 module:add_item("adhoc", shut_down_service_desc);