Comparison

plugins/mod_admin_adhoc.lua @ 6458:f906b803dc42

mod_admin_web: Add "List S2S connections" command
author Florian Zeitz <florob@babelmonkeys.de>
date Sun, 28 Sep 2014 23:03:03 +0200
parent 6457:ddcb29a35409
child 6464:737c81bd898e
comparison
equal deleted inserted replaced
6457:ddcb29a35409 6458:f906b803dc42
7 local _G = _G; 7 local _G = _G;
8 8
9 local prosody = _G.prosody; 9 local prosody = _G.prosody;
10 local hosts = prosody.hosts; 10 local hosts = prosody.hosts;
11 local t_concat = table.concat; 11 local t_concat = table.concat;
12 local t_sort = table.sort;
12 13
13 local module_host = module:get_host(); 14 local module_host = module:get_host();
14 15
15 local keys = require "util.iterators".keys; 16 local keys = require "util.iterators".keys;
16 local usermanager_user_exists = require "core.usermanager".user_exists; 17 local usermanager_user_exists = require "core.usermanager".user_exists;
359 end 360 end
360 end 361 end
361 return { status = "completed", result = {layout = get_online_users_result_layout, values = {onlineuserjids=t_concat(users, "\n")}} }; 362 return { status = "completed", result = {layout = get_online_users_result_layout, values = {onlineuserjids=t_concat(users, "\n")}} };
362 end); 363 end);
363 364
365 -- Getting a list of S2S connections (this host)
366 local list_s2s_this_result = dataforms_new {
367 title = "List of S2S connections on this host";
368
369 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/s2s#list" };
370 { name = "sessions", type = "text-multi", label = "Connections:" };
371 { name = "num_in", type = "text-single", label = "#incomming connections:" };
372 { name = "num_out", type = "text-single", label = "#outgoing connections:" };
373 };
374
375 local function session_flags(session, line)
376 line = line or {};
377
378 if session.id then
379 line[#line+1] = "["..session.id.."]"
380 else
381 line[#line+1] = "["..session.type..(tostring(session):match("%x*$")).."]"
382 end
383
384 local flags = {};
385 if session.cert_identity_status == "valid" then
386 flags[#flags+1] = "authenticated";
387 end
388 if session.secure then
389 flags[#flags+1] = "encrypted";
390 end
391 if session.compressed then
392 flags[#flags+1] = "compressed)";
393 end
394 if session.smacks then
395 flags[#flags+1] = "sm";
396 end
397 if session.ip and session.ip:match(":") then
398 flags[#flags+1] = "IPv6";
399 end
400 line[#line+1] = "("..t_concat(flags, ", ")..")";
401
402 return t_concat(line, " ");
403 end
404
405 local function list_s2s_this_handler(self, data, state)
406 local count_in, count_out = 0, 0;
407 local s2s_list = {};
408
409 local s2s_sessions = module:shared"/*/s2s/sessions";
410 for _, session in pairs(s2s_sessions) do
411 local remotehost, localhost, direction;
412 if session.direction == "outgoing" then
413 direction = "->";
414 count_out = count_out + 1;
415 remotehost, localhost = session.to_host or "?", session.from_host or "?";
416 else
417 direction = "<-";
418 count_in = count_in + 1;
419 remotehost, localhost = session.from_host or "?", session.to_host or "?";
420 end
421 local sess_lines = { r = remotehost,
422 session_flags(session, { "", direction, remotehost or "?" })};
423
424 if remotehost:match(module_host) or localhost:match(module_host) then
425 s2s_list[#s2s_list+1] = sess_lines;
426 end
427 end
428
429 t_sort(s2s_list, function(a, b)
430 return a.r < b.r;
431 end);
432
433 for i, sess_lines in ipairs(s2s_list) do
434 s2s_list[i] = sess_lines[1];
435 end
436
437 return { status = "completed", result = { layout = list_s2s_this_result; values = {
438 sessions = t_concat(s2s_list, "\n"),
439 num_in = tostring(count_in),
440 num_out = tostring(count_out)
441 } } };
442 end
443
364 -- Getting a list of loaded modules 444 -- Getting a list of loaded modules
365 local list_modules_result = dataforms_new { 445 local list_modules_result = dataforms_new {
366 title = "List of loaded modules"; 446 title = "List of loaded modules";
367 447
368 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#list" }; 448 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#list" };
725 local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin"); 805 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"); 806 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"); 807 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"); 808 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"); 809 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");
810 local list_s2s_this_desc = adhoc_new("List S2S connections", "http://prosody.im/protocol/s2s#list", list_s2s_this_handler, "admin");
730 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); 811 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"); 812 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"); 813 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"); 814 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"); 815 local globally_reload_module_desc = adhoc_new("Globally reload module", "http://prosody.im/protocol/modules#global-reload", globally_reload_module_handler, "global_admin");
745 module:provides("adhoc", end_user_session_desc); 826 module:provides("adhoc", end_user_session_desc);
746 module:provides("adhoc", get_user_password_desc); 827 module:provides("adhoc", get_user_password_desc);
747 module:provides("adhoc", get_user_roster_desc); 828 module:provides("adhoc", get_user_roster_desc);
748 module:provides("adhoc", get_user_stats_desc); 829 module:provides("adhoc", get_user_stats_desc);
749 module:provides("adhoc", get_online_users_desc); 830 module:provides("adhoc", get_online_users_desc);
831 module:provides("adhoc", list_s2s_this_desc);
750 module:provides("adhoc", list_modules_desc); 832 module:provides("adhoc", list_modules_desc);
751 module:provides("adhoc", load_module_desc); 833 module:provides("adhoc", load_module_desc);
752 module:provides("adhoc", globally_load_module_desc); 834 module:provides("adhoc", globally_load_module_desc);
753 module:provides("adhoc", reload_modules_desc); 835 module:provides("adhoc", reload_modules_desc);
754 module:provides("adhoc", globally_reload_module_desc); 836 module:provides("adhoc", globally_reload_module_desc);