new: exposing the graph object to js

This commit is contained in:
Simone Margaritelli 2021-04-09 13:46:33 +02:00
parent 0042b77c36
commit 93b7e7f2ed
8 changed files with 48 additions and 13 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/session"
"github.com/evilsocket/islazy/fs"
"github.com/evilsocket/islazy/plugin"
"github.com/evilsocket/islazy/str"
"os"
"path/filepath"
@ -50,6 +51,10 @@ type Module struct {
wLock sync.Mutex
}
func init() {
plugin.Defines["graph"] = graphPackage{}
}
func NewModule(s *session.Session) *Module {
mod := &Module{
SessionModule: session.NewSessionModule("graph", s),
@ -173,8 +178,15 @@ func (mod *Module) updateSettings() error {
}
}
if mod.db, err = NewGraph(mod.settings.path); err != nil {
return err
// only reload if needed
if mod.db != nil && mod.db.path != mod.settings.path {
mod.db = nil
}
if mod.db == nil {
if mod.db, err = NewGraph(mod.settings.path); err != nil {
return err
}
}
return nil