From fdca49678e11d789ddb7d36328e1ee3911a061b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=B8=EF=B8=8F?= <29265684+buffermet@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:02:28 +0100 Subject: [PATCH] Implement DNS proxy script onExit call. --- modules/dns_proxy/dns_proxy_base.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/dns_proxy/dns_proxy_base.go b/modules/dns_proxy/dns_proxy_base.go index f8c17445..fe1b84af 100644 --- a/modules/dns_proxy/dns_proxy_base.go +++ b/modules/dns_proxy/dns_proxy_base.go @@ -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 {