updated ipbl, bug fixes, change models
All checks were successful
continuous-integration/drone Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Paul 2022-08-28 16:23:21 +02:00
parent a1329fc544
commit 3f000cbf8f
5 changed files with 46 additions and 21 deletions

View File

@ -33,7 +33,9 @@ func main() {
}
defer cfg.Db.Close()
if !cfg.Switchs.NoScanIP {
go models.ScanIP(&cfg)
}
go zmqrouter.Init(&cfg)
go func() { err = routers.RunServer(&ctx, &cfg) }()
if err != nil {

View File

@ -15,6 +15,7 @@ func (cfg *Config) GetConfig() error {
var init bool
var port int
var version bool
var noscanip bool
flag.Usage = utils.Usage
@ -24,6 +25,7 @@ func (cfg *Config) GetConfig() error {
flag.BoolVar(&drop, "drop", false, "If dropping tables must occur")
flag.BoolVar(&init, "init", false, "If init of database must be done")
flag.BoolVar(&version, "version", false, "Show version")
flag.BoolVar(&noscanip, "noscanip", false, "Do not run scanip")
flag.Parse()
@ -32,6 +34,7 @@ func (cfg *Config) GetConfig() error {
cfg.Switchs.Init = init
cfg.Switchs.Port = port
cfg.Switchs.Version = version
cfg.Switchs.NoScanIP = noscanip
var inicfg, err = ini.Load(configfile)
if err != nil {
@ -54,22 +57,23 @@ func (cfg *Config) GetConfig() error {
type Config struct {
Db *xorm.Engine `json:"-"`
DbParams struct {
DbHostname string `json:"dbhostname"`
DbUsername string `json:"dbusername"`
DbPassword string `json:"dbpassword"`
DbDatabase string `json:"dbdatabase"`
} `json:"dbparams"`
DbHostname string
DbUsername string
DbPassword string
DbDatabase string
} `json:"-"`
Options struct {
Version string `json:"version"`
HideBanner bool `json:"hidebanner"`
ZMQChannel string `json:"zmqchannel"`
Version string
HideBanner bool
ZMQChannel string
} `json:"-"`
Switchs struct {
Port int `json:"port"`
NoFeed bool `json:"nofeed"`
Debug bool `json:"debug"`
Drop bool `json:"drop"`
Init bool `json:"init"`
Version bool `json:"version"`
Port int
NoFeed bool
Debug bool
Drop bool
Init bool
Version bool
NoScanIP bool
} `json:"-"`
}

View File

@ -138,6 +138,7 @@ type CfgSet struct {
Filename string `xorm:"text notnull" json:"filename"`
Regex string `xorm:"text notnull" json:"regex"`
Blocktime int64 `xorm:"notnull default 60" json:"blocktime"`
TryFail int64 `xorm:"notnull default 5" json:"tryfail"`
Enabled bool `xorm:"notnull default true" json:"-"`
}

View File

@ -33,6 +33,15 @@ func GetIPsLast(ctx *context.Context, config *config.Config, interval string) (a
return
}
func GetIPsWithoutHostInfo(ctx *context.Context, config *config.Config) (apiips []string, err error) {
var ips []IP
err = config.Db.In("ip").GroupBy("ip").Find(&ips)
for _, ml := range ips {
apiips = append(apiips, ml.IP)
}
return
}
func GetIP(ctx *context.Context, cfg *config.Config, ipquery interface{}) (apiip *APIIP, err error) {
session := cfg.Db.NewSession()
defer session.Close()
@ -169,6 +178,7 @@ func (ip *IP) APIFormat() *APIIP {
Date: ip.Updated.Local().String(),
}
}
func (ip *APIIP) APIConvert() *IP {
if ip == nil {
return nil
@ -185,6 +195,10 @@ func (ip *APIIP) APIConvert() *IP {
}
}
func (ip *APIIP) BeforeInsert() (err error) {
return
}
type IP struct {
ID int `xorm:"pk autoincr"`
IP string `xorm:"text notnull unique(ipsrc)" json:"ip"`

View File

@ -57,6 +57,10 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
ret, err := models.GetIPsLast(ctx, cfg, interval)
return Result(c, err, ret)
})
e.GET("/ips/withouthostinfo", func(c echo.Context) (err error) {
ret, err := models.GetIPsWithoutHostInfo(ctx, cfg)
return Result(c, err, ret)
})
e.POST("/ips", func(c echo.Context) (err error) {
var apiips = []models.APIIP{}
var ips = []models.IP{}
@ -74,13 +78,13 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
return Result(c, err, msg)
})
e.POST("/hostinfo", func(c echo.Context) (err error) {
var hostinfo = models.HostInfo{}
err = c.Bind(&hostinfo)
var hostinfos = []models.HostInfo{}
err = c.Bind(&hostinfos)
if err != nil {
return Result(c, err, hostinfo)
return Result(c, err, hostinfos)
}
num, err := cfg.Db.Insert(&hostinfo)
msg := fmt.Sprintf("Inserted %v host info (%d)", hostinfo, num)
num, err := cfg.Db.Insert(&hostinfos)
msg := fmt.Sprintf("Inserted %v host info (%d)", hostinfos, num)
log.Println(msg)
return Result(c, err, msg)
})