2018-06-03 20:37:52 +02:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
2019-03-08 15:53:45 +01:00
|
|
|
"time"
|
2018-06-03 20:37:52 +02:00
|
|
|
|
2019-02-28 16:24:29 +01:00
|
|
|
// "github.com/bdlm/log"
|
2019-03-08 15:53:45 +01:00
|
|
|
"dev.sum7.eu/genofire/golang-lib/database"
|
2018-06-03 20:37:52 +02:00
|
|
|
|
2019-03-08 05:57:00 +01:00
|
|
|
"dev.sum7.eu/genofire/wifictld-analyzer/capture"
|
2019-03-08 15:53:45 +01:00
|
|
|
"dev.sum7.eu/genofire/wifictld-analyzer/data"
|
2018-06-03 20:37:52 +02:00
|
|
|
)
|
|
|
|
|
2019-03-08 05:57:00 +01:00
|
|
|
func (c *Controller) Handler(addr *net.UDPAddr, msg *capture.SocketMSG) (*capture.SocketMSG, error) {
|
2018-06-03 20:37:52 +02:00
|
|
|
ignore := false
|
2019-03-08 05:57:00 +01:00
|
|
|
if msg.Types.Is(capture.SocketMSGTypeClient) && msg.Client != nil {
|
2019-03-08 15:53:45 +01:00
|
|
|
ignore = c.LearnClient(addr.IP, msg.Client)
|
2018-06-03 20:37:52 +02:00
|
|
|
}
|
2019-03-08 05:57:00 +01:00
|
|
|
if !msg.Types.Is(capture.SocketMSGTypeRequest) {
|
2018-06-03 20:37:52 +02:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2019-03-08 15:53:45 +01:00
|
|
|
client := &data.Client{Addr: msg.Client.Addr}
|
|
|
|
|
|
|
|
if result := database.Read.Select([]string{"try_probe", "try_auth"}).First(client); result.Error != nil {
|
|
|
|
return nil, result.Error
|
|
|
|
}
|
|
|
|
|
2019-03-08 05:57:00 +01:00
|
|
|
msg = &capture.SocketMSG{
|
2019-03-08 15:53:45 +01:00
|
|
|
Types: (capture.SocketMSGTypeResponse | capture.SocketMSGTypeClient),
|
|
|
|
Client: &capture.WifiClient{
|
|
|
|
Addr: msg.Client.Addr,
|
|
|
|
Time: time.Now(),
|
|
|
|
TryProbe: client.TryProbe,
|
|
|
|
TryAuth: client.TryAuth,
|
|
|
|
},
|
2018-06-03 20:37:52 +02:00
|
|
|
}
|
|
|
|
|
2018-07-16 13:00:37 +02:00
|
|
|
if !ignore {
|
2018-06-03 20:37:52 +02:00
|
|
|
return msg, nil
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|