From 5d2cd581c224b879a11f345bc32352daf5a79b2c Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Thu, 30 Dec 2021 12:03:26 +0100 Subject: [PATCH] updated ipbl --- .gitignore | 1 + src/models/cfg.go | 1 + src/models/ip.go | 28 ++++++++++++++++------------ src/routers/funcs.go | 4 ++-- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index b160adb..962a81d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /ipbl *.ini +*.swp /test diff --git a/src/models/cfg.go b/src/models/cfg.go index 4d542a0..cd5c83f 100644 --- a/src/models/cfg.go +++ b/src/models/cfg.go @@ -6,6 +6,7 @@ import ( "git.paulbsd.com/paulbsd/ipbl/src/config" ) +// GetWhitelists ... func GetWhitelists(cfg config.Config) (res []string) { var w = Cfg{Key: "whitelist"} cfg.Db.Get(&w) diff --git a/src/models/ip.go b/src/models/ip.go index cc0bd2c..e227bf9 100644 --- a/src/models/ip.go +++ b/src/models/ip.go @@ -12,8 +12,8 @@ import ( "git.paulbsd.com/paulbsd/ipbl/src/config" ) -// GetIps ... -func GetIps(ctx *context.Context, config *config.Config, limit int) (apimailboxes []*api.IP, err error) { +// GetIPs ... +func GetIPs(ctx *context.Context, config *config.Config, limit int) (apimailboxes []*api.IP, err error) { var ips []IP err = config.Db.Limit(limit).Find(&ips) for _, ml := range ips { @@ -22,8 +22,8 @@ func GetIps(ctx *context.Context, config *config.Config, limit int) (apimailboxe return } -// GetIp ... -func GetIp(ctx *context.Context, config *config.Config, ipquery interface{}) (apiip *api.IP, err error) { +// GetIP ... +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 { @@ -37,6 +37,7 @@ func GetIp(ctx *context.Context, config *config.Config, ipquery interface{}) (ap return } +// UpdateRDNS ... func (i *IP) UpdateRDNS() (result string, err error) { res, err := net.LookupAddr(i.IP) if err != nil { @@ -47,11 +48,13 @@ func (i *IP) UpdateRDNS() (result string, err error) { return } +// InsertIP ... func (i *IP) InsertIP(cfg *config.Config) (num int64, err error) { num, err = cfg.Db.Insert(i) return } +// InsertIPBulk ... func InsertIPBulk(cfg *config.Config, ips *[]IP) (numinserts int64, numfail int64, err error) { for _, ip := range *ips { num, err := cfg.Db.Insert(ip) @@ -64,6 +67,7 @@ func InsertIPBulk(cfg *config.Config, ips *[]IP) (numinserts int64, numfail int6 return } +// ScanIP ... func ScanIP(cfg *config.Config) (err error) { for { var orphans = []IP{} @@ -72,10 +76,10 @@ func ScanIP(cfg *config.Config) (err error) { for _, i := range orphans { reverse, _ := i.UpdateRDNS() if reverse == "" { - fmt.Printf("Set \"none\" rdns to IP %s\n", i.IP) + log.Printf("Set \"none\" rdns to IP %s\n", i.IP) i.Rdns.String = "none" } else { - fmt.Printf("%s %s\n", i.IP, reverse) + log.Printf("%s %s\n", i.IP, reverse) i.Rdns.String = reverse } i.Rdns.Valid = true @@ -91,15 +95,15 @@ func ScanIP(cfg *config.Config) (err error) { } // APIFormat returns a JSON formatted object of IP -func (admin *IP) APIFormat() *api.IP { - if admin == nil { +func (ip *IP) APIFormat() *api.IP { + if ip == nil { return nil } return &api.IP{ - ID: admin.ID, - IP: admin.IP, - Rdns: admin.Rdns.String, - Src: admin.Src, + ID: ip.ID, + IP: ip.IP, + Rdns: ip.Rdns.String, + Src: ip.Src, } } diff --git a/src/routers/funcs.go b/src/routers/funcs.go index 9470791..f483228 100644 --- a/src/routers/funcs.go +++ b/src/routers/funcs.go @@ -25,7 +25,7 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) { // IPs e.GET("/ip/:ip", func(c echo.Context) (err error) { - ret, err := models.GetIp(ctx, cfg, c.Param("ip")) + ret, err := models.GetIP(ctx, cfg, c.Param("ip")) return JSONResult(c, err, ret) }) e.POST("/ip", func(c echo.Context) (err error) { @@ -49,7 +49,7 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) { if c.QueryParam("limit") != "" { limit, _ = strconv.Atoi(c.QueryParam("limit")) } - ret, err := models.GetIps(ctx, cfg, limit) + ret, err := models.GetIPs(ctx, cfg, limit) return JSONResult(c, err, ret) }) e.POST("/ips", func(c echo.Context) (err error) {