mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
756c04fd95
commit
ba4793f980
2 changed files with 39 additions and 48 deletions
|
@ -20,11 +20,41 @@ type Module interface {
|
||||||
Handlers() []ModuleHandler
|
Handlers() []ModuleHandler
|
||||||
Parameters() map[string]*ModuleParam
|
Parameters() map[string]*ModuleParam
|
||||||
|
|
||||||
|
Extra() map[string]interface{}
|
||||||
Running() bool
|
Running() bool
|
||||||
Start() error
|
Start() error
|
||||||
Stop() error
|
Stop() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ModuleList []Module
|
||||||
|
|
||||||
|
type moduleJSON struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Author string `json:"author"`
|
||||||
|
Parameters map[string]*ModuleParam `json:"parameters"`
|
||||||
|
Handlers []ModuleHandler `json:"handlers"`
|
||||||
|
Running bool `json:"running"`
|
||||||
|
State map[string]interface{} `json:"state"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mm ModuleList) MarshalJSON() ([]byte, error) {
|
||||||
|
mods := []moduleJSON{}
|
||||||
|
for _, m := range mm {
|
||||||
|
mJSON := moduleJSON{
|
||||||
|
Name: m.Name(),
|
||||||
|
Description: m.Description(),
|
||||||
|
Author: m.Author(),
|
||||||
|
Parameters: m.Parameters(),
|
||||||
|
Handlers: m.Handlers(),
|
||||||
|
Running: m.Running(),
|
||||||
|
State: m.Extra(),
|
||||||
|
}
|
||||||
|
mods = append(mods, mJSON)
|
||||||
|
}
|
||||||
|
return json.Marshal(mods)
|
||||||
|
}
|
||||||
|
|
||||||
type SessionModule struct {
|
type SessionModule struct {
|
||||||
Name string
|
Name string
|
||||||
Session *Session
|
Session *Session
|
||||||
|
@ -37,12 +67,6 @@ type SessionModule struct {
|
||||||
tag string
|
tag string
|
||||||
}
|
}
|
||||||
|
|
||||||
type sessionModuleJSON struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Started bool `json:"started"`
|
|
||||||
State map[string]interface{} `json:"state"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func AsTag(name string) string {
|
func AsTag(name string) string {
|
||||||
return fmt.Sprintf("%s ", tui.Wrap(tui.BACKLIGHTBLUE, tui.Wrap(tui.FOREBLACK, name)))
|
return fmt.Sprintf("%s ", tui.Wrap(tui.BACKLIGHTBLUE, tui.Wrap(tui.FOREBLACK, name)))
|
||||||
}
|
}
|
||||||
|
@ -62,6 +86,15 @@ func NewSessionModule(name string, s *Session) SessionModule {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *SessionModule) Extra() map[string]interface{} {
|
||||||
|
extra := make(map[string]interface{})
|
||||||
|
m.State.Range(func(k, v interface{}) bool {
|
||||||
|
extra[k.(string)] = v
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return extra
|
||||||
|
}
|
||||||
|
|
||||||
func (m *SessionModule) InitState(keys ...string) {
|
func (m *SessionModule) InitState(keys ...string) {
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
m.State.Store(key, nil)
|
m.State.Store(key, nil)
|
||||||
|
@ -75,21 +108,6 @@ func (m *SessionModule) ResetState() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SessionModule) MarshalJSON() ([]byte, error) {
|
|
||||||
doc := sessionModuleJSON{
|
|
||||||
Name: m.Name,
|
|
||||||
Started: m.Started,
|
|
||||||
State: make(map[string]interface{}),
|
|
||||||
}
|
|
||||||
|
|
||||||
m.State.Range(func(k, v interface{}) bool {
|
|
||||||
doc.State[k.(string)] = v
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
|
|
||||||
return json.Marshal(doc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *SessionModule) Debug(format string, args ...interface{}) {
|
func (m *SessionModule) Debug(format string, args ...interface{}) {
|
||||||
m.Session.Events.Log(log.DEBUG, m.tag+format, args...)
|
m.Session.Events.Log(log.DEBUG, m.tag+format, args...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package session
|
package session
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
@ -45,32 +44,6 @@ var (
|
||||||
|
|
||||||
type UnknownCommandCallback func(cmd string) bool
|
type UnknownCommandCallback func(cmd string) bool
|
||||||
|
|
||||||
type ModuleList []Module
|
|
||||||
|
|
||||||
type JSONModule struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
Author string `json:"author"`
|
|
||||||
Parameters map[string]*ModuleParam `json:"parameters"`
|
|
||||||
Handlers []ModuleHandler `json:"handlers"`
|
|
||||||
Running bool `json:"running"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mm ModuleList) MarshalJSON() ([]byte, error) {
|
|
||||||
mods := []JSONModule{}
|
|
||||||
for _, m := range mm {
|
|
||||||
mods = append(mods, JSONModule{
|
|
||||||
Name: m.Name(),
|
|
||||||
Description: m.Description(),
|
|
||||||
Author: m.Author(),
|
|
||||||
Parameters: m.Parameters(),
|
|
||||||
Handlers: m.Handlers(),
|
|
||||||
Running: m.Running(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return json.Marshal(mods)
|
|
||||||
}
|
|
||||||
|
|
||||||
type GPS struct {
|
type GPS struct {
|
||||||
Latitude float64 // Latitude.
|
Latitude float64 // Latitude.
|
||||||
Longitude float64 // Longitude.
|
Longitude float64 // Longitude.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue