Comparison

plugins/mod_admin_telnet.lua @ 10094:6b1e89868328

mod_admin_telnet: Allow specifying a reason when closing sessions (#1400)
author Kim Alvefur <zash@zash.se>
date Sun, 28 Jul 2019 01:39:47 +0200
parent 10087:36d3709603d1
child 10095:a3c66d0294e1
comparison
equal deleted inserted replaced
10093:1266a63ba567 10094:6b1e89868328
664 664
665 function def_env.c2s:show_tls(match_jid) 665 function def_env.c2s:show_tls(match_jid)
666 return self:show(match_jid, tls_info); 666 return self:show(match_jid, tls_info);
667 end 667 end
668 668
669 function def_env.c2s:close(match_jid) 669 local function build_reason(text, condition)
670 if text or condition then
671 return {
672 text = text,
673 condition = condition or "undefined-condition",
674 };
675 end
676 end
677
678 function def_env.c2s:close(match_jid, text, condition)
670 local count = 0; 679 local count = 0;
671 show_c2s(function (jid, session) 680 show_c2s(function (jid, session)
672 if jid == match_jid or jid_bare(jid) == match_jid then 681 if jid == match_jid or jid_bare(jid) == match_jid then
673 count = count + 1; 682 count = count + 1;
674 session:close(); 683 session:close(build_reason(text, condition));
675 end 684 end
676 end); 685 end);
677 return true, "Total: "..count.." sessions closed"; 686 return true, "Total: "..count.." sessions closed";
678 end 687 end
679 688
680 function def_env.c2s:closeall() 689 function def_env.c2s:closeall(text, condition)
681 local count = 0; 690 local count = 0;
682 --luacheck: ignore 212/jid 691 --luacheck: ignore 212/jid
683 show_c2s(function (jid, session) 692 show_c2s(function (jid, session)
684 count = count + 1; 693 count = count + 1;
685 session:close(); 694 session:close(build_reason(text, condition));
686 end); 695 end);
687 return true, "Total: "..count.." sessions closed"; 696 return true, "Total: "..count.." sessions closed";
688 end 697 end
689 698
690 699
885 return ("Showing "..n_certs.." certificate" 894 return ("Showing "..n_certs.." certificate"
886 ..(n_certs==1 and "" or "s") 895 ..(n_certs==1 and "" or "s")
887 .." presented by "..domain.."."); 896 .." presented by "..domain..".");
888 end 897 end
889 898
890 function def_env.s2s:close(from, to) 899 function def_env.s2s:close(from, to, text, condition)
891 local print, count = self.session.print, 0; 900 local print, count = self.session.print, 0;
892 local s2s_sessions = module:shared"/*/s2s/sessions"; 901 local s2s_sessions = module:shared"/*/s2s/sessions";
893 902
894 local match_id; 903 local match_id;
895 if from and not to then 904 if from and not to then
903 for _, session in pairs(s2s_sessions) do 912 for _, session in pairs(s2s_sessions) do
904 local id = session.type..tostring(session):match("[a-f0-9]+$"); 913 local id = session.type..tostring(session):match("[a-f0-9]+$");
905 if (match_id and match_id == id) 914 if (match_id and match_id == id)
906 or (session.from_host == from and session.to_host == to) then 915 or (session.from_host == from and session.to_host == to) then
907 print(("Closing connection from %s to %s [%s]"):format(session.from_host, session.to_host, id)); 916 print(("Closing connection from %s to %s [%s]"):format(session.from_host, session.to_host, id));
908 (session.close or s2smanager.destroy_session)(session); 917 (session.close or s2smanager.destroy_session)(session, build_reason(text, condition));
909 count = count + 1 ; 918 count = count + 1 ;
910 end 919 end
911 end 920 end
912 return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); 921 return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s");
913 end 922 end
914 923
915 function def_env.s2s:closeall(host) 924 function def_env.s2s:closeall(host, text, condition)
916 local count = 0; 925 local count = 0;
917 local s2s_sessions = module:shared"/*/s2s/sessions"; 926 local s2s_sessions = module:shared"/*/s2s/sessions";
918 for _,session in pairs(s2s_sessions) do 927 for _,session in pairs(s2s_sessions) do
919 if not host or session.from_host == host or session.to_host == host then 928 if not host or session.from_host == host or session.to_host == host then
920 session:close(); 929 session:close(build_reason(text, condition));
921 count = count + 1; 930 count = count + 1;
922 end 931 end
923 end 932 end
924 if count == 0 then return false, "No sessions to close."; 933 if count == 0 then return false, "No sessions to close.";
925 else return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); end 934 else return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); end