Software / code / prosody
Comparison
plugins/mod_console.lua @ 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 |
| parent | 1322:33d103b0283f |
| child | 1341:53decd1ee351 |
comparison
equal
deleted
inserted
replaced
| 1339:7d77f92f94c9 | 1340:f707d0957155 |
|---|---|
| 383 end | 383 end |
| 384 | 384 |
| 385 return true, "Total: "..count_out.." outgoing, "..count_in.." incoming connections"; | 385 return true, "Total: "..count_out.." outgoing, "..count_in.." incoming connections"; |
| 386 end | 386 end |
| 387 | 387 |
| 388 function def_env.s2s:close(from, to) | |
| 389 local print, count = self.session.print, 0; | |
| 390 | |
| 391 if not (from and to) then | |
| 392 return false, "Syntax: s2s:close('from', 'to') - Closes all s2s sessions from 'from' to 'to'"; | |
| 393 elseif from == to then | |
| 394 return false, "Both from and to are the same... you can't do that :)"; | |
| 395 end | |
| 396 | |
| 397 if hosts[from] and not hosts[to] then | |
| 398 -- Is an outgoing connection | |
| 399 local session = hosts[from].s2sout[to]; | |
| 400 if not session then | |
| 401 print("No outgoing connection from "..from.." to "..to) | |
| 402 else | |
| 403 s2smanager.destroy_session(session); | |
| 404 count = count + 1; | |
| 405 print("Closed outgoing session from "..from.." to "..to); | |
| 406 end | |
| 407 elseif hosts[to] and not hosts[from] then | |
| 408 -- Is an incoming connection | |
| 409 for session in pairs(incoming_s2s) do | |
| 410 if session.to_host == to and session.from_host == from then | |
| 411 s2smanager.destroy_session(session); | |
| 412 count = count + 1; | |
| 413 end | |
| 414 end | |
| 415 | |
| 416 if count == 0 then | |
| 417 print("No incoming connections from "..from.." to "..to); | |
| 418 else | |
| 419 print("Closed "..count.." incoming session"..((count == 1 and "") or "s").." from "..from.." to "..to); | |
| 420 end | |
| 421 elseif hosts[to] and hosts[from] | |
| 422 return false, "Both of the hostnames you specified are local, there are no s2s sessions to close"; | |
| 423 else | |
| 424 return false, "Neither of the hostnames you specified are being used on this server"; | |
| 425 end | |
| 426 | |
| 427 return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); | |
| 428 end | |
| 429 | |
| 388 ------------- | 430 ------------- |
| 389 | 431 |
| 390 function printbanner(session) | 432 function printbanner(session) |
| 391 session.print [[ | 433 session.print [[ |
| 392 ____ \ / _ | 434 ____ \ / _ |