Software /
code /
prosody
Changeset
1340:f707d0957155
mod_console: Add s2s:close() to close s2s sessions between two hosts
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 12 Jun 2009 15:35:04 +0100 |
parents | 1339:7d77f92f94c9 |
children | 1341:53decd1ee351 |
files | plugins/mod_console.lua |
diffstat | 1 files changed, 42 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_console.lua Fri Jun 12 11:37:34 2009 +0100 +++ b/plugins/mod_console.lua Fri Jun 12 15:35:04 2009 +0100 @@ -385,6 +385,48 @@ return true, "Total: "..count_out.." outgoing, "..count_in.." incoming connections"; end +function def_env.s2s:close(from, to) + local print, count = self.session.print, 0; + + if not (from and to) then + return false, "Syntax: s2s:close('from', 'to') - Closes all s2s sessions from 'from' to 'to'"; + elseif from == to then + return false, "Both from and to are the same... you can't do that :)"; + end + + if hosts[from] and not hosts[to] then + -- Is an outgoing connection + local session = hosts[from].s2sout[to]; + if not session then + print("No outgoing connection from "..from.." to "..to) + else + s2smanager.destroy_session(session); + count = count + 1; + print("Closed outgoing session from "..from.." to "..to); + end + elseif hosts[to] and not hosts[from] then + -- Is an incoming connection + for session in pairs(incoming_s2s) do + if session.to_host == to and session.from_host == from then + s2smanager.destroy_session(session); + count = count + 1; + end + end + + if count == 0 then + print("No incoming connections from "..from.." to "..to); + else + print("Closed "..count.." incoming session"..((count == 1 and "") or "s").." from "..from.." to "..to); + end + elseif hosts[to] and hosts[from] + return false, "Both of the hostnames you specified are local, there are no s2s sessions to close"; + else + return false, "Neither of the hostnames you specified are being used on this server"; + end + + return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); +end + ------------- function printbanner(session)