mirror of
https://github.com/bettercap/bettercap
synced 2025-07-06 04:52:10 -07:00
Merge pull request #1156 from bettercap/otto_onExit
Implement onExit otto function calls when quitting the session or modules.
This commit is contained in:
commit
2c6f048cec
3 changed files with 31 additions and 0 deletions
|
@ -14,6 +14,8 @@ import (
|
|||
"github.com/evilsocket/islazy/log"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
|
||||
"github.com/robertkrimen/otto"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -225,6 +227,14 @@ func (p *DNSProxy) Start() {
|
|||
}
|
||||
|
||||
func (p *DNSProxy) Stop() error {
|
||||
if p.Script != nil {
|
||||
if p.Script.Plugin.HasFunc("onExit") {
|
||||
if _, err := p.Script.Call("onExit"); err != nil {
|
||||
log.Error("Error while executing onExit callback: %s", "\nTraceback:\n "+err.(*otto.Error).String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if p.doRedirect && p.Redirection != nil {
|
||||
p.Debug("disabling redirection %s", p.Redirection.String())
|
||||
if err := p.Sess.Firewall.EnableRedirection(p.Redirection, false); err != nil {
|
||||
|
|
|
@ -27,6 +27,8 @@ import (
|
|||
"github.com/evilsocket/islazy/log"
|
||||
"github.com/evilsocket/islazy/str"
|
||||
"github.com/evilsocket/islazy/tui"
|
||||
|
||||
"github.com/robertkrimen/otto"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -432,6 +434,14 @@ func (p *HTTPProxy) Start() {
|
|||
}
|
||||
|
||||
func (p *HTTPProxy) Stop() error {
|
||||
if p.Script != nil {
|
||||
if p.Script.Plugin.HasFunc("onExit") {
|
||||
if _, err := p.Script.Call("onExit"); err != nil {
|
||||
log.Error("Error while executing onExit callback: %s", "\nTraceback:\n "+err.(*otto.Error).String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if p.doRedirect && p.Redirection != nil {
|
||||
p.Debug("disabling redirection %s", p.Redirection.String())
|
||||
if err := p.Sess.Firewall.EnableRedirection(p.Redirection, false); err != nil {
|
||||
|
|
|
@ -13,11 +13,14 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/bettercap/bettercap/v2/core"
|
||||
"github.com/bettercap/bettercap/v2/log"
|
||||
"github.com/bettercap/bettercap/v2/network"
|
||||
|
||||
"github.com/bettercap/readline"
|
||||
"github.com/evilsocket/islazy/str"
|
||||
"github.com/evilsocket/islazy/tui"
|
||||
|
||||
"github.com/robertkrimen/otto"
|
||||
)
|
||||
|
||||
func (s *Session) generalHelp() {
|
||||
|
@ -155,6 +158,14 @@ func (s *Session) activeHandler(args []string, sess *Session) error {
|
|||
}
|
||||
|
||||
func (s *Session) exitHandler(args []string, sess *Session) error {
|
||||
if s.script != nil {
|
||||
if s.script.Plugin.HasFunc("onExit") {
|
||||
if _, err := s.script.Plugin.Call("onExit"); err != nil {
|
||||
log.Error("Error while executing onExit callback: %s", "\nTraceback:\n "+err.(*otto.Error).String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// notify any listener that the session is about to end
|
||||
s.Events.Add("session.stopped", nil)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue