58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
|
package controller
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
"time"
|
||
|
|
||
|
// "github.com/bdlm/log"
|
||
|
"dev.sum7.eu/genofire/golang-lib/database"
|
||
|
|
||
|
"dev.sum7.eu/genofire/wifictld-analyzer/capture"
|
||
|
"dev.sum7.eu/genofire/wifictld-analyzer/data"
|
||
|
)
|
||
|
|
||
|
func (c *Controller) LearnClient(apIP net.IP, clientWifictl *capture.WifiClient) bool {
|
||
|
ret := false
|
||
|
|
||
|
// learn ap
|
||
|
ap := &data.AP{
|
||
|
IP: apIP,
|
||
|
Lastseen: time.Now(),
|
||
|
}
|
||
|
result := database.Read.First(ap)
|
||
|
if result.RowsAffected > 0 {
|
||
|
database.Write.Save(ap)
|
||
|
} else {
|
||
|
database.Write.Create(ap)
|
||
|
}
|
||
|
|
||
|
// learn client
|
||
|
client := &data.Client{
|
||
|
Addr: clientWifictl.Addr,
|
||
|
Lastseen: time.Now(),
|
||
|
APAddr: apIP,
|
||
|
Connected: clientWifictl.Connected,
|
||
|
SignalLowFreq: clientWifictl.SignalLowFreq,
|
||
|
SignalHighFreq: clientWifictl.SignalHighFreq,
|
||
|
}
|
||
|
|
||
|
database.Write.FirstOrCreate(client)
|
||
|
|
||
|
if clientWifictl.TryAuth > client.TryAuth {
|
||
|
client.TryAuth = clientWifictl.TryAuth
|
||
|
}
|
||
|
if clientWifictl.TryProbe > client.TryProbe {
|
||
|
client.TryProbe = clientWifictl.TryProbe
|
||
|
}
|
||
|
|
||
|
if client.FreqHighest < clientWifictl.FreqHighest {
|
||
|
ret = (client.FreqHighest != 0)
|
||
|
client.FreqHighest = clientWifictl.FreqHighest
|
||
|
}
|
||
|
if clientWifictl.Authed {
|
||
|
client.Authed = clientWifictl.Authed
|
||
|
}
|
||
|
database.Write.Save(client)
|
||
|
return ret
|
||
|
}
|