misc updates
This commit is contained in:
parent
c41747e146
commit
32784ff442
@ -1,8 +1,8 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
type IP struct {
|
type IP struct {
|
||||||
ID int `json:"id"`
|
IP string `json:"ip"`
|
||||||
IP string `json:"ip"`
|
Rdns string `json:"rdns"`
|
||||||
Rdns string `json:"rdns"`
|
Src string `json:"src"`
|
||||||
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) {
|
func DiscoverURLS(cfg config.Config) (Discovery, error) {
|
||||||
var disc Discovery
|
var disc Discovery
|
||||||
var urls []Url
|
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: "folders", Path: "/config/folders"})
|
||||||
urls = append(urls, Url{Key: "trustlist", Path: "/config/trustlist"})
|
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}
|
disc = Discovery{Version: "1.0", URLs: urls}
|
||||||
return disc, nil
|
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) {
|
func GetIP(ctx *context.Context, config *config.Config, ipquery interface{}) (apiip *api.IP, err error) {
|
||||||
var ip IP
|
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")
|
err = fmt.Errorf("not found")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ func ScanIP(cfg *config.Config) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
time.Sleep(60 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,17 +107,19 @@ func (ip *IP) APIFormat() *api.IP {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &api.IP{
|
return &api.IP{
|
||||||
IP: ip.IP,
|
IP: ip.IP,
|
||||||
Rdns: ip.Rdns.String,
|
Rdns: ip.Rdns.String,
|
||||||
Src: ip.Src,
|
Src: ip.Src,
|
||||||
|
Hostname: ip.Hostname,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type IP struct {
|
type IP struct {
|
||||||
ID int `xorm:"pk autoincr" json:"-"`
|
ID int `xorm:"pk autoincr" json:"-"`
|
||||||
IP string `xorm:"text notnull unique(ipsrc)" json:"ip"`
|
IP string `xorm:"text notnull unique(ipsrc)" json:"ip"`
|
||||||
Rdns sql.NullString `xorm:"text default" json:"rdns"`
|
Rdns sql.NullString `xorm:"text default" json:"rdns"`
|
||||||
Src string `xorm:"text notnull unique(ipsrc)" json:"src"`
|
Src string `xorm:"text notnull unique(ipsrc)" json:"src"`
|
||||||
Created time.Time `xorm:"created notnull" json:"-"`
|
Hostname string `xorm:"text notnull unique(ipsrc)" json:"hostname"`
|
||||||
Updated time.Time `xorm:"updated notnull" json:"-"`
|
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)
|
num, err := cfg.Db.Insert(&ip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error inserting ip address", num, err)
|
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))
|
tmpval := fmt.Sprintf("%s %s", channel, string(val))
|
||||||
|
Loading…
Reference in New Issue
Block a user