added lock to ipbl
This commit is contained in:
parent
8eecf6d52d
commit
c5ab1fad2d
@ -17,6 +17,7 @@ import (
|
||||
func main() {
|
||||
var ctx context.Context
|
||||
var cfg config.Config
|
||||
var lock bool
|
||||
cfg.GetConfig()
|
||||
cfg.Options.Version = version
|
||||
|
||||
@ -28,12 +29,12 @@ func main() {
|
||||
defer cfg.Db.Close()
|
||||
|
||||
// Handles IP with no reverse DNS
|
||||
go models.ScanIP(&cfg)
|
||||
go models.ScanIP(&cfg, &lock)
|
||||
|
||||
// Add cron task to handle them
|
||||
cr := cron.New()
|
||||
cr.AddFunc("0 * * * * *", func() {
|
||||
models.ScanIP(&cfg)
|
||||
models.ScanIP(&cfg, &lock)
|
||||
})
|
||||
cr.Start()
|
||||
|
||||
|
@ -64,30 +64,33 @@ func InsertIPBulk(cfg *config.Config, ips *[]IP) (numinserts int64, numfail int6
|
||||
return
|
||||
}
|
||||
|
||||
func ScanIP(cfg *config.Config) (err error) {
|
||||
for {
|
||||
var orphans = []IP{}
|
||||
cfg.Db.Where("rdns IS NULL").Asc("ip").Find(&orphans)
|
||||
if len(orphans) > 0 {
|
||||
for _, i := range orphans {
|
||||
reverse, _ := i.UpdateRDNS()
|
||||
if reverse == "" {
|
||||
fmt.Printf("Set \"none\" rdns to IP %s\n", i.IP)
|
||||
i.Rdns.String = "none"
|
||||
} else {
|
||||
fmt.Printf("%s %s\n", i.IP, reverse)
|
||||
i.Rdns.String = reverse
|
||||
}
|
||||
i.Rdns.Valid = true
|
||||
_, err = cfg.Db.ID(i.ID).Cols("rdns").Update(&i)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
func ScanIP(cfg *config.Config, lock *bool) (err error) {
|
||||
if !*lock {
|
||||
for {
|
||||
var orphans = []IP{}
|
||||
cfg.Db.Where("rdns IS NULL").Asc("ip").Find(&orphans)
|
||||
if len(orphans) > 0 {
|
||||
for _, i := range orphans {
|
||||
reverse, _ := i.UpdateRDNS()
|
||||
if reverse == "" {
|
||||
fmt.Printf("Set \"none\" rdns to IP %s\n", i.IP)
|
||||
i.Rdns.String = "none"
|
||||
} else {
|
||||
fmt.Printf("%s %s\n", i.IP, reverse)
|
||||
i.Rdns.String = reverse
|
||||
}
|
||||
i.Rdns.Valid = true
|
||||
_, err = cfg.Db.ID(i.ID).Cols("rdns").Update(&i)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
*lock = false
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user