misc updates
This commit is contained in:
parent
c41747e146
commit
32784ff442
@ -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"`
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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:"-"`
|
||||
}
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user