From 32784ff44215d36d7f59f295b7636a79952dc1d2 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sun, 13 Mar 2022 12:08:44 +0100 Subject: [PATCH] misc updates --- src/api/ip.go | 8 ++++---- src/models/cfg.go | 3 +++ src/models/ip.go | 26 ++++++++++++++------------ src/zmqrouter/main.go | 6 +++++- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/api/ip.go b/src/api/ip.go index ab09fdc..04d440e 100644 --- a/src/api/ip.go +++ b/src/api/ip.go @@ -1,8 +1,8 @@ package api type IP struct { - ID int `json:"id"` - IP string `json:"ip"` - Rdns string `json:"rdns"` - Src string `json:"src"` + IP string `json:"ip"` + Rdns string `json:"rdns"` + Src string `json:"src"` + Hostname string `json:"hostname"` } diff --git a/src/models/cfg.go b/src/models/cfg.go index 71cf3ea..a73b6ea 100644 --- a/src/models/cfg.go +++ b/src/models/cfg.go @@ -94,8 +94,11 @@ func GetZMQ(cfg config.Config, key string) (res ZMQ, err error) { func DiscoverURLS(cfg config.Config) (Discovery, error) { var disc Discovery var urls []Url + urls = append(urls, Url{Key: "auth", Path: "/auth"}) urls = append(urls, Url{Key: "folders", Path: "/config/folders"}) urls = append(urls, Url{Key: "trustlist", Path: "/config/trustlist"}) + urls = append(urls, Url{Key: "zmqrr", Path: "/config/zmqrr"}) + urls = append(urls, Url{Key: "zmqps", Path: "/config/zmqps"}) disc = Discovery{Version: "1.0", URLs: urls} return disc, nil } diff --git a/src/models/ip.go b/src/models/ip.go index 6e4ac64..784fefb 100644 --- a/src/models/ip.go +++ b/src/models/ip.go @@ -34,8 +34,8 @@ func GetIPsLast(ctx *context.Context, config *config.Config, interval string) (a func GetIP(ctx *context.Context, config *config.Config, ipquery interface{}) (apiip *api.IP, err error) { var ip IP - has, err := config.Db.Where("ip = ?", ipquery).Get(&ip) - if !has { + + if has, err := config.Db.Where("ip = ?", ipquery).Get(&ip); !has { err = fmt.Errorf("not found") return nil, err } @@ -97,7 +97,7 @@ func ScanIP(cfg *config.Config) (err error) { } } } else { - time.Sleep(60 * time.Second) + time.Sleep(10 * time.Second) } } } @@ -107,17 +107,19 @@ func (ip *IP) APIFormat() *api.IP { return nil } return &api.IP{ - IP: ip.IP, - Rdns: ip.Rdns.String, - Src: ip.Src, + IP: ip.IP, + Rdns: ip.Rdns.String, + Src: ip.Src, + Hostname: ip.Hostname, } } type IP struct { - ID int `xorm:"pk autoincr" json:"-"` - IP string `xorm:"text notnull unique(ipsrc)" json:"ip"` - Rdns sql.NullString `xorm:"text default" json:"rdns"` - Src string `xorm:"text notnull unique(ipsrc)" json:"src"` - Created time.Time `xorm:"created notnull" json:"-"` - Updated time.Time `xorm:"updated notnull" json:"-"` + ID int `xorm:"pk autoincr" json:"-"` + IP string `xorm:"text notnull unique(ipsrc)" json:"ip"` + Rdns sql.NullString `xorm:"text default" json:"rdns"` + Src string `xorm:"text notnull unique(ipsrc)" json:"src"` + Hostname string `xorm:"text notnull unique(ipsrc)" json:"hostname"` + Created time.Time `xorm:"created notnull" json:"-"` + Updated time.Time `xorm:"updated notnull" json:"-"` } diff --git a/src/zmqrouter/main.go b/src/zmqrouter/main.go index 6eafe7a..51d8c7b 100644 --- a/src/zmqrouter/main.go +++ b/src/zmqrouter/main.go @@ -51,7 +51,11 @@ func Handle(cfg *config.Config, reqsock *goczmq.Sock, pubsock *goczmq.Sock, chan num, err := cfg.Db.Insert(&ip) if err != nil { log.Println("error inserting ip address", num, err) - continue + } + } else { + num, err := cfg.Db.Where("id = ?", ip.ID).Update(&ip) + if err != nil { + log.Println("error updating ip address", num, err) } } tmpval := fmt.Sprintf("%s %s", channel, string(val))