Comparison

plugins/mod_admin_shell.lua @ 11886:b0b258e092da

mod_admin_shell: Optionally group session listings by host when not included as column Similar to the earlier view
author Kim Alvefur <zash@zash.se>
date Wed, 10 Nov 2021 15:54:27 +0100
parent 11885:197642f9972f
child 11887:b043e1bb8e8e
comparison
equal deleted inserted replaced
11885:197642f9972f 11886:b0b258e092da
831 local function match(session) 831 local function match(session)
832 local jid = get_jid(session) 832 local jid = get_jid(session)
833 return (not match_jid) or jid:match(match_jid) 833 return (not match_jid) or jid:match(match_jid)
834 end 834 end
835 835
836 print(row()); 836 local group_by_host = true;
837 for _, col in ipairs(columns) do
838 if col.key == "full_jid" or col.key == "host" then
839 group_by_host = false;
840 break
841 end
842 end
843
844 if not group_by_host then print(row()); end
845 local currenthost = nil;
837 846
838 for _, session in ipairs(get_c2s():filter(match):sort(_sort_by_jid)) do 847 for _, session in ipairs(get_c2s():filter(match):sort(_sort_by_jid)) do
848 if group_by_host and session.host ~= currenthost then
849 currenthost = session.host;
850 print("#",prosody.hosts[currenthost] or "Unknown host");
851 print(row());
852 end
853
839 print(row(session)); 854 print(row(session));
840 end 855 end
841 return true; 856 return true;
842 end 857 end
843 858
892 local function match(session) 907 local function match(session)
893 local host, remote = get_s2s_hosts(session); 908 local host, remote = get_s2s_hosts(session);
894 return not match_jid or (host or ""):match(match_jid) or (remote or ""):match(match_jid); 909 return not match_jid or (host or ""):match(match_jid) or (remote or ""):match(match_jid);
895 end 910 end
896 911
912 local group_by_host = true;
913 local currenthost = nil;
914 for _, col in ipairs(columns) do
915 if col.key == "host" then
916 group_by_host = false;
917 break
918 end
919 end
920
921 if not group_by_host then print(row()); end
922
897 local s2s_sessions = array(iterators.values(module:shared"/*/s2s/sessions")):filter(match):sort(_sort_s2s); 923 local s2s_sessions = array(iterators.values(module:shared"/*/s2s/sessions")):filter(match):sort(_sort_s2s);
898 924
899 print(row());
900
901 for _, session in ipairs(s2s_sessions) do 925 for _, session in ipairs(s2s_sessions) do
926 if group_by_host and currenthost ~= get_s2s_hosts(session) then
927 currenthost = get_s2s_hosts(session);
928 print("#",prosody.hosts[currenthost] or "Unknown host");
929 print(row());
930 end
931
902 print(row(session)); 932 print(row(session));
903 end 933 end
904 return true; -- TODO counts 934 return true; -- TODO counts
905 end 935 end
906 936