wifictld-analyzer/controller/learn.go

58 lines
1.2 KiB
Go
Raw Normal View History

2019-03-08 15:53:45 +01:00
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
}