Implement session script onExit call.

This commit is contained in:
☸️ 2024-11-23 15:49:05 +01:00 committed by GitHub
parent c4e45b368d
commit 159aed5080
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,11 +13,14 @@ import (
"time" "time"
"github.com/bettercap/bettercap/v2/core" "github.com/bettercap/bettercap/v2/core"
"github.com/bettercap/bettercap/v2/log"
"github.com/bettercap/bettercap/v2/network" "github.com/bettercap/bettercap/v2/network"
"github.com/bettercap/readline" "github.com/bettercap/readline"
"github.com/evilsocket/islazy/str" "github.com/evilsocket/islazy/str"
"github.com/evilsocket/islazy/tui" "github.com/evilsocket/islazy/tui"
"github.com/robertkrimen/otto"
) )
func (s *Session) generalHelp() { 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 { 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 // notify any listener that the session is about to end
s.Events.Add("session.stopped", nil) s.Events.Add("session.stopped", nil)