updated ipbl
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2021-12-30 12:03:26 +01:00
parent 044d328658
commit 5d2cd581c2
4 changed files with 20 additions and 14 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/ipbl
*.ini
*.swp
/test

View File

@ -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)

View File

@ -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,
}
}

View File

@ -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) {