Comparison

plugins/mod_admin_shell.lua @ 13072:7fcf41b541e0

mod_admin_shell: Use same wildcard matching in other s2s command Consistency is nice.
author Kim Alvefur <zash@zash.se>
date Mon, 10 Apr 2023 14:24:39 +0200
parent 13071:b5a419ac0f84
child 13079:e7a5e5a0dc02
comparison
equal deleted inserted replaced
13071:b5a419ac0f84 13072:7fcf41b541e0
1189 1189
1190 function def_env.s2s:showcert(domain) 1190 function def_env.s2s:showcert(domain)
1191 local print = self.session.print; 1191 local print = self.session.print;
1192 local s2s_sessions = module:shared"/*/s2s/sessions"; 1192 local s2s_sessions = module:shared"/*/s2s/sessions";
1193 local domain_sessions = set.new(array.collect(values(s2s_sessions))) 1193 local domain_sessions = set.new(array.collect(values(s2s_sessions)))
1194 /function(session) return (session.to_host == domain or session.from_host == domain) and session or nil; end; 1194 /function(session) return match_s2s_jid(session, domain) and session or nil; end;
1195 local cert_set = {}; 1195 local cert_set = {};
1196 for session in domain_sessions do 1196 for session in domain_sessions do
1197 local conn = session.conn; 1197 local conn = session.conn;
1198 conn = conn and conn:socket(); 1198 conn = conn and conn:socket();
1199 if not conn.getpeerchain then 1199 if not conn.getpeerchain then
1292 elseif from == to then 1292 elseif from == to then
1293 return false, "Both from and to are the same... you can't do that :)"; 1293 return false, "Both from and to are the same... you can't do that :)";
1294 end 1294 end
1295 1295
1296 for _, session in pairs(s2s_sessions) do 1296 for _, session in pairs(s2s_sessions) do
1297 local id = session.id or (session.type..tostring(session):match("[a-f0-9]+$")); 1297 local id = session.id or (session.type .. tostring(session):match("[a-f0-9]+$"));
1298 if (match_id and match_id == id) 1298 if (match_id and match_id == id) or ((from and match_wildcard(from, session.to_host)) or (to and match_wildcard(to, session.to_host))) then
1299 or (session.from_host == from and session.to_host == to) then
1300 print(("Closing connection from %s to %s [%s]"):format(session.from_host, session.to_host, id)); 1299 print(("Closing connection from %s to %s [%s]"):format(session.from_host, session.to_host, id));
1301 (session.close or s2smanager.destroy_session)(session, build_reason(text, condition)); 1300 (session.close or s2smanager.destroy_session)(session, build_reason(text, condition));
1302 count = count + 1 ; 1301 count = count + 1;
1303 end 1302 end
1304 end 1303 end
1305 return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); 1304 return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s");
1306 end 1305 end
1307 1306
1308 function def_env.s2s:closeall(host, text, condition) 1307 function def_env.s2s:closeall(host, text, condition)
1309 local count = 0; 1308 local count = 0;
1310 local s2s_sessions = module:shared"/*/s2s/sessions"; 1309 local s2s_sessions = module:shared"/*/s2s/sessions";
1311 for _,session in pairs(s2s_sessions) do 1310 for _,session in pairs(s2s_sessions) do
1312 if not host or session.from_host == host or session.to_host == host then 1311 if not host or host == "*" or match_s2s_jid(session, host) then
1313 session:close(build_reason(text, condition)); 1312 session:close(build_reason(text, condition));
1314 count = count + 1; 1313 count = count + 1;
1315 end 1314 end
1316 end 1315 end
1317 if count == 0 then return false, "No sessions to close."; 1316 if count == 0 then return false, "No sessions to close.";