mirror of
https://github.com/bettercap/bettercap
synced 2025-07-14 17:13:39 -07:00
refact: using global wifi objects in order to expose them from the api.rest module
This commit is contained in:
parent
9390a580fd
commit
e895dc6ab2
5 changed files with 29 additions and 46 deletions
|
@ -1,69 +0,0 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/network"
|
||||
"github.com/evilsocket/bettercap-ng/session"
|
||||
)
|
||||
|
||||
type WiFi struct {
|
||||
sync.Mutex
|
||||
Session *session.Session
|
||||
Interface *network.Endpoint
|
||||
Stations map[string]*WiFiStation
|
||||
}
|
||||
|
||||
func NewWiFi(s *session.Session, iface *network.Endpoint) *WiFi {
|
||||
return &WiFi{
|
||||
Session: s,
|
||||
Interface: iface,
|
||||
Stations: make(map[string]*WiFiStation),
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WiFi) List() (list []*WiFiStation) {
|
||||
w.Lock()
|
||||
defer w.Unlock()
|
||||
|
||||
list = make([]*WiFiStation, 0)
|
||||
for _, t := range w.Stations {
|
||||
list = append(list, t)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WiFi) Remove(mac string) {
|
||||
w.Lock()
|
||||
defer w.Unlock()
|
||||
|
||||
if station, found := w.Stations[mac]; found {
|
||||
w.Session.Events.Add("wifi.station.lost", station)
|
||||
delete(w.Stations, mac)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WiFi) AddIfNew(ssid, mac string, isAp bool, channel int, rssi int8) *WiFiStation {
|
||||
w.Lock()
|
||||
defer w.Unlock()
|
||||
|
||||
mac = network.NormalizeMac(mac)
|
||||
if station, found := w.Stations[mac]; found {
|
||||
station.LastSeen = time.Now()
|
||||
station.RSSI = rssi
|
||||
return station
|
||||
}
|
||||
|
||||
newStation := NewWiFiStation(ssid, mac, isAp, channel, rssi)
|
||||
w.Stations[mac] = newStation
|
||||
|
||||
w.Session.Events.Add("wifi.station.new", newStation)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *WiFi) Clear() error {
|
||||
w.Stations = make(map[string]*WiFiStation)
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue