mirror of
https://github.com/bettercap/bettercap
synced 2025-07-11 23:57:01 -07:00
new: exposing modules realtime status from the rest api
This commit is contained in:
parent
1220874473
commit
2b117e14d6
2 changed files with 42 additions and 19 deletions
|
@ -22,6 +22,14 @@ type Module interface {
|
||||||
Stop() error
|
Stop() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JSONModule struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Author string `json:"author"`
|
||||||
|
Parameters map[string]*ModuleParam `json:"parameters"`
|
||||||
|
Running bool `json:"running"`
|
||||||
|
}
|
||||||
|
|
||||||
type SessionModule struct {
|
type SessionModule struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Session *Session `json:"-"`
|
Session *Session `json:"-"`
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package session
|
package session
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
@ -40,28 +41,42 @@ var (
|
||||||
|
|
||||||
type UnknownCommandCallback func(cmd string) bool
|
type UnknownCommandCallback func(cmd string) bool
|
||||||
|
|
||||||
|
type ModuleList []Module
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
Options core.Options `json:"options"`
|
Options core.Options `json:"options"`
|
||||||
Interface *network.Endpoint `json:"interface"`
|
Interface *network.Endpoint `json:"interface"`
|
||||||
Gateway *network.Endpoint `json:"gateway"`
|
Gateway *network.Endpoint `json:"gateway"`
|
||||||
Firewall firewall.FirewallManager `json:"-"`
|
|
||||||
Env *Environment `json:"env"`
|
Env *Environment `json:"env"`
|
||||||
Lan *network.LAN `json:"lan"`
|
Lan *network.LAN `json:"lan"`
|
||||||
WiFi *network.WiFi `json:"wifi"`
|
WiFi *network.WiFi `json:"wifi"`
|
||||||
BLE *network.BLE `json:"ble"`
|
BLE *network.BLE `json:"ble"`
|
||||||
Queue *packets.Queue `json:"packets"`
|
Queue *packets.Queue `json:"packets"`
|
||||||
Input *readline.Instance `json:"-"`
|
|
||||||
StartedAt time.Time `json:"started_at"`
|
StartedAt time.Time `json:"started_at"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
GPS nmea.GNGGA `json:"gps"`
|
GPS nmea.GNGGA `json:"gps"`
|
||||||
|
Modules ModuleList `json:"modules"`
|
||||||
|
|
||||||
|
Input *readline.Instance `json:"-"`
|
||||||
Prompt Prompt `json:"-"`
|
Prompt Prompt `json:"-"`
|
||||||
|
|
||||||
CoreHandlers []CommandHandler `json:"-"`
|
CoreHandlers []CommandHandler `json:"-"`
|
||||||
Modules []Module `json:"-"`
|
|
||||||
|
|
||||||
Events *EventPool `json:"-"`
|
Events *EventPool `json:"-"`
|
||||||
|
|
||||||
UnkCmdCallback UnknownCommandCallback `json:"-"`
|
UnkCmdCallback UnknownCommandCallback `json:"-"`
|
||||||
|
Firewall firewall.FirewallManager `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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(),
|
||||||
|
Running: m.Running(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return json.Marshal(mods)
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() (*Session, error) {
|
func New() (*Session, error) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue