This commit is contained in:
parent
0518d4445c
commit
be9446abab
@ -20,7 +20,7 @@ func Initialize(ctx *context.Context, cfg *config.Config) (err error) {
|
||||
models.CfgSet{},
|
||||
models.CfgTrustlist{},
|
||||
models.CfgZMQ{},
|
||||
models.Hostinfo{}}
|
||||
models.HostInfo{}}
|
||||
|
||||
cfg.Db, err = xorm.NewEngine(databaseEngine,
|
||||
fmt.Sprintf("%s://%s:%s@%s/%s",
|
||||
|
@ -4,9 +4,25 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Hostinfo struct {
|
||||
type HostInfo struct {
|
||||
ID int `xorm:"pk autoincr"`
|
||||
Data string `xorm:"text notnull" json:"data"`
|
||||
IP string `xorm:"text unique" json:"ip"`
|
||||
RawWhois string `xorm:"text" json:"raw_whois"`
|
||||
ReverseDNS string `xorm:"text" json:"reverse_dns"`
|
||||
City string `xorm:"text" json:"city"`
|
||||
Country string `xorm:"text" json:"country"`
|
||||
Created time.Time `xorm:"created notnull"`
|
||||
Updated time.Time `xorm:"updated notnull"`
|
||||
}
|
||||
|
||||
type ScanResult struct {
|
||||
Protocol string `json:"proto"`
|
||||
PortID int `json:"port_id"`
|
||||
State string `json:"state"`
|
||||
ServiceName string `json:"service"`
|
||||
}
|
||||
|
||||
type ASN struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
@ -54,9 +54,9 @@ func (ip *IP) UpdateRDNS() (result string, err error) {
|
||||
res, err := net.LookupAddr(ip.IP)
|
||||
if err != nil {
|
||||
result = ""
|
||||
} else {
|
||||
result = res[0]
|
||||
return
|
||||
}
|
||||
result = res[0]
|
||||
return
|
||||
}
|
||||
|
||||
@ -118,12 +118,12 @@ func ScanIP(cfg *config.Config) (err error) {
|
||||
log.Println(err)
|
||||
}
|
||||
if session.Where("rdns IS NULL").Asc("ip").Limit(ScanLimit).Find(&orphans); len(orphans) > 0 {
|
||||
for _, i := range orphans {
|
||||
reverse, _ := i.UpdateRDNS()
|
||||
log.Printf("%s -> \"%s\"\n", i.IP, reverse)
|
||||
i.Rdns.String = reverse
|
||||
i.Rdns.Valid = true
|
||||
_, err = session.ID(i.ID).Cols("rdns").Update(&i)
|
||||
for _, orphan := range orphans {
|
||||
reverse, _ := orphan.UpdateRDNS()
|
||||
log.Printf("%s -> \"%s\"\n", orphan.IP, reverse)
|
||||
orphan.Rdns.String = reverse
|
||||
orphan.Rdns.Valid = true
|
||||
_, err = session.ID(orphan.ID).Cols("rdns").Update(&orphan)
|
||||
|
||||
if err != nil {
|
||||
session.Rollback()
|
||||
@ -164,6 +164,8 @@ func (ip *IP) APIFormat() *APIIP {
|
||||
Rdns: ip.Rdns.String,
|
||||
Src: ip.Src,
|
||||
Hostname: ip.Hostname.String,
|
||||
City: ip.City.String,
|
||||
Country: ip.Country.String,
|
||||
Date: ip.Updated.Local().String(),
|
||||
}
|
||||
}
|
||||
@ -173,9 +175,13 @@ func (ip *APIIP) APIConvert() *IP {
|
||||
}
|
||||
return &IP{
|
||||
IP: ip.IP,
|
||||
Rdns: sql.NullString{String: ip.Rdns, Valid: false},
|
||||
Rdns: sql.NullString{
|
||||
String: ip.Rdns,
|
||||
Valid: false},
|
||||
Src: ip.Src,
|
||||
Hostname: sql.NullString{String: ip.Hostname, Valid: true},
|
||||
Hostname: sql.NullString{
|
||||
String: ip.Hostname,
|
||||
Valid: true},
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,6 +191,8 @@ type IP struct {
|
||||
Rdns sql.NullString `xorm:"text default"`
|
||||
Src string `xorm:"text notnull unique(ipsrc)" json:"src"`
|
||||
Hostname sql.NullString `xorm:"text default '' unique(ipsrc)" json:"hostname"`
|
||||
City sql.NullString `xorm:"text default '' unique(ipsrc)" json:"city"`
|
||||
Country sql.NullString `xorm:"text default '' unique(ipsrc)" json:"country"`
|
||||
Created time.Time `xorm:"created notnull"`
|
||||
Updated time.Time `xorm:"updated notnull"`
|
||||
}
|
||||
@ -194,5 +202,7 @@ type APIIP struct {
|
||||
Rdns string `json:"rdns"`
|
||||
Src string `json:"src"`
|
||||
Hostname string `json:"hostname"`
|
||||
City string `json:"city"`
|
||||
Country string `json:"country"`
|
||||
Date string `json:"date"`
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import "reflect"
|
||||
|
||||
//const keyname string = "id"
|
||||
|
||||
func differ(sl1 []IP, sl2 []IP) (toinsert []IP, err error) {
|
||||
func Differ(sl1 []IP, sl2 []IP) (toinsert []IP, err error) {
|
||||
var m = make(map[string]IPDiffer)
|
||||
longslice := append(sl1, sl2...)
|
||||
|
||||
|
@ -74,12 +74,12 @@ 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{}
|
||||
var hostinfo = models.HostInfo{}
|
||||
err = c.Bind(&hostinfo)
|
||||
if err != nil {
|
||||
return Result(c, err, hostinfo)
|
||||
}
|
||||
num, err := cfg.Db.Insert(hostinfo)
|
||||
num, err := cfg.Db.Insert(&hostinfo)
|
||||
msg := fmt.Sprintf("Inserted %v host info (%d)", hostinfo, num)
|
||||
log.Println(msg)
|
||||
return Result(c, err, msg)
|
||||
|
Loading…
Reference in New Issue
Block a user