updated ipbl

This commit is contained in:
Paul Lecuq 2021-12-10 09:24:27 +01:00
parent e3dbfa30e5
commit a81caa6918
2 changed files with 26 additions and 28 deletions

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"log" "log"
"git.paulbsd.com/paulbsd/ipbl/src/config" "git.paulbsd.com/paulbsd/ipbl/src/config"
@ -14,8 +13,6 @@ import (
//var version string //var version string
func main() { func main() {
var ipblCtx ipbl.IP
var cfg config.Config var cfg config.Config
cfg.GetConfig() cfg.GetConfig()
//cfg.Options.Version = version //cfg.Options.Version = version
@ -27,27 +24,7 @@ func main() {
} }
defer cfg.Db.Close() defer cfg.Db.Close()
// Initialize ipbl app context go ipbl.ScanIP(&cfg)
err = ipblCtx.Init(&cfg)
if err != nil {
log.Fatalln(err)
}
var orphans = []ipbl.IP{}
cfg.Db.Where("rdns IS NULL").Asc("ip").Find(&orphans)
for _, i := range orphans {
reverse := i.UpdateRDNS()
if reverse == "" {
fmt.Printf("Set \"none\" rdns to IP %s\n", i.IP)
i.Rdns = "none"
cfg.Db.ID(i.ID).Cols("rdns").Update(&i)
} else {
fmt.Printf("%s %s\n", i.IP, reverse)
i.Rdns = reverse
cfg.Db.ID(i.ID).Cols("rdns").Update(&i)
}
}
fmt.Println("end")
// Run the ipbl web service // Run the ipbl web service
err = ipblws.RunServer(&cfg) err = ipblws.RunServer(&cfg)

View File

@ -1,16 +1,13 @@
package ipbl package ipbl
import ( import (
"fmt"
"net" "net"
"time" "time"
"git.paulbsd.com/paulbsd/ipbl/src/config" "git.paulbsd.com/paulbsd/ipbl/src/config"
) )
func (i *IP) Init(*config.Config) (err error) {
return nil
}
func (i *IP) UpdateRDNS() (result string) { func (i *IP) UpdateRDNS() (result string) {
res, err := net.LookupAddr(i.IP) res, err := net.LookupAddr(i.IP)
if err != nil { if err != nil {
@ -19,6 +16,30 @@ func (i *IP) UpdateRDNS() (result string) {
return res[0] return res[0]
} }
func ScanIP(cfg *config.Config) {
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 = "none"
cfg.Db.ID(i.ID).Cols("rdns").Update(&i)
} else {
fmt.Printf("%s %s\n", i.IP, reverse)
i.Rdns = reverse
cfg.Db.ID(i.ID).Cols("rdns").Update(&i)
}
}
} else {
fmt.Println("end")
break
}
}
}
// User describe accounts // User describe accounts
type IP struct { type IP struct {
ID int `xorm:"pk autoincr" json:"-"` ID int `xorm:"pk autoincr" json:"-"`