This commit is contained in:
parent
044d328658
commit
5d2cd581c2
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
/ipbl
|
/ipbl
|
||||||
*.ini
|
*.ini
|
||||||
|
*.swp
|
||||||
/test
|
/test
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"git.paulbsd.com/paulbsd/ipbl/src/config"
|
"git.paulbsd.com/paulbsd/ipbl/src/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetWhitelists ...
|
||||||
func GetWhitelists(cfg config.Config) (res []string) {
|
func GetWhitelists(cfg config.Config) (res []string) {
|
||||||
var w = Cfg{Key: "whitelist"}
|
var w = Cfg{Key: "whitelist"}
|
||||||
cfg.Db.Get(&w)
|
cfg.Db.Get(&w)
|
||||||
|
@ -12,8 +12,8 @@ import (
|
|||||||
"git.paulbsd.com/paulbsd/ipbl/src/config"
|
"git.paulbsd.com/paulbsd/ipbl/src/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetIps ...
|
// GetIPs ...
|
||||||
func GetIps(ctx *context.Context, config *config.Config, limit int) (apimailboxes []*api.IP, err error) {
|
func GetIPs(ctx *context.Context, config *config.Config, limit int) (apimailboxes []*api.IP, err error) {
|
||||||
var ips []IP
|
var ips []IP
|
||||||
err = config.Db.Limit(limit).Find(&ips)
|
err = config.Db.Limit(limit).Find(&ips)
|
||||||
for _, ml := range ips {
|
for _, ml := range ips {
|
||||||
@ -22,8 +22,8 @@ func GetIps(ctx *context.Context, config *config.Config, limit int) (apimailboxe
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetIp ...
|
// GetIP ...
|
||||||
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)
|
has, err := config.Db.Where("ip = ?", ipquery).Get(&ip)
|
||||||
if !has {
|
if !has {
|
||||||
@ -37,6 +37,7 @@ func GetIp(ctx *context.Context, config *config.Config, ipquery interface{}) (ap
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateRDNS ...
|
||||||
func (i *IP) UpdateRDNS() (result string, err error) {
|
func (i *IP) UpdateRDNS() (result string, err error) {
|
||||||
res, err := net.LookupAddr(i.IP)
|
res, err := net.LookupAddr(i.IP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -47,11 +48,13 @@ func (i *IP) UpdateRDNS() (result string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InsertIP ...
|
||||||
func (i *IP) InsertIP(cfg *config.Config) (num int64, err error) {
|
func (i *IP) InsertIP(cfg *config.Config) (num int64, err error) {
|
||||||
num, err = cfg.Db.Insert(i)
|
num, err = cfg.Db.Insert(i)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InsertIPBulk ...
|
||||||
func InsertIPBulk(cfg *config.Config, ips *[]IP) (numinserts int64, numfail int64, err error) {
|
func InsertIPBulk(cfg *config.Config, ips *[]IP) (numinserts int64, numfail int64, err error) {
|
||||||
for _, ip := range *ips {
|
for _, ip := range *ips {
|
||||||
num, err := cfg.Db.Insert(ip)
|
num, err := cfg.Db.Insert(ip)
|
||||||
@ -64,6 +67,7 @@ func InsertIPBulk(cfg *config.Config, ips *[]IP) (numinserts int64, numfail int6
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ScanIP ...
|
||||||
func ScanIP(cfg *config.Config) (err error) {
|
func ScanIP(cfg *config.Config) (err error) {
|
||||||
for {
|
for {
|
||||||
var orphans = []IP{}
|
var orphans = []IP{}
|
||||||
@ -72,10 +76,10 @@ func ScanIP(cfg *config.Config) (err error) {
|
|||||||
for _, i := range orphans {
|
for _, i := range orphans {
|
||||||
reverse, _ := i.UpdateRDNS()
|
reverse, _ := i.UpdateRDNS()
|
||||||
if reverse == "" {
|
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"
|
i.Rdns.String = "none"
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%s %s\n", i.IP, reverse)
|
log.Printf("%s %s\n", i.IP, reverse)
|
||||||
i.Rdns.String = reverse
|
i.Rdns.String = reverse
|
||||||
}
|
}
|
||||||
i.Rdns.Valid = true
|
i.Rdns.Valid = true
|
||||||
@ -91,15 +95,15 @@ func ScanIP(cfg *config.Config) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// APIFormat returns a JSON formatted object of IP
|
// APIFormat returns a JSON formatted object of IP
|
||||||
func (admin *IP) APIFormat() *api.IP {
|
func (ip *IP) APIFormat() *api.IP {
|
||||||
if admin == nil {
|
if ip == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &api.IP{
|
return &api.IP{
|
||||||
ID: admin.ID,
|
ID: ip.ID,
|
||||||
IP: admin.IP,
|
IP: ip.IP,
|
||||||
Rdns: admin.Rdns.String,
|
Rdns: ip.Rdns.String,
|
||||||
Src: admin.Src,
|
Src: ip.Src,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
|
|||||||
|
|
||||||
// IPs
|
// IPs
|
||||||
e.GET("/ip/:ip", func(c echo.Context) (err error) {
|
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)
|
return JSONResult(c, err, ret)
|
||||||
})
|
})
|
||||||
e.POST("/ip", func(c echo.Context) (err error) {
|
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") != "" {
|
if c.QueryParam("limit") != "" {
|
||||||
limit, _ = strconv.Atoi(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)
|
return JSONResult(c, err, ret)
|
||||||
})
|
})
|
||||||
e.POST("/ips", func(c echo.Context) (err error) {
|
e.POST("/ips", func(c echo.Context) (err error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user