fix: modules that require net.recon can now specify it as a dependency

This commit is contained in:
evilsocket 2019-04-02 00:06:43 +02:00
parent 5ef330f80b
commit 36e5fe8bdb
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
5 changed files with 30 additions and 0 deletions

View file

@ -21,6 +21,7 @@ type Module interface {
Parameters() map[string]*ModuleParam
Extra() map[string]interface{}
Required() []string
Running() bool
Start() error
Stop() error
@ -64,6 +65,7 @@ type SessionModule struct {
handlers []ModuleHandler
params map[string]*ModuleParam
requires []string
tag string
}
@ -79,6 +81,7 @@ func NewSessionModule(name string, s *Session) SessionModule {
StatusLock: &sync.RWMutex{},
State: &sync.Map{},
requires: make([]string, 0),
handlers: make([]ModuleHandler, 0),
params: make(map[string]*ModuleParam),
tag: AsTag(name),
@ -129,6 +132,14 @@ func (m *SessionModule) Fatal(format string, args ...interface{}) {
m.Session.Events.Log(log.FATAL, m.tag+format, args...)
}
func (m *SessionModule) Requires(modName string) {
m.requires = append(m.requires, modName)
}
func (m *SessionModule) Required() []string {
return m.requires
}
func (m *SessionModule) Handlers() []ModuleHandler {
return m.handlers
}
@ -237,6 +248,17 @@ func (m *SessionModule) SetRunning(running bool, cb func()) error {
}
}
if running == true {
for _, modName := range m.Required() {
if m.Session.IsOn(modName) == false {
m.Info("starting %s as a requirement for %s", modName, m.Name)
if err := m.Session.Run(modName + " on"); err != nil {
return fmt.Errorf("error while starting module %s as a requirement for %s: %v", modName, m.Name, err)
}
}
}
}
m.StatusLock.Lock()
m.Started = running
m.StatusLock.Unlock()