+ whois: use "descr" or "netname" in case there's no "orgname"
This commit is contained in:
parent
875905ce8a
commit
95eeccde8f
|
@ -287,12 +287,14 @@ func (clients *clientsContainer) SetWhoisInfo(ip string, info [][]string) {
|
||||||
if ok {
|
if ok {
|
||||||
c.WhoisInfo = info
|
c.WhoisInfo = info
|
||||||
log.Debug("Clients: set WHOIS info for client %s: %v", c.Name, c.WhoisInfo)
|
log.Debug("Clients: set WHOIS info for client %s: %v", c.Name, c.WhoisInfo)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ch, ok := clients.ipHost[ip]
|
ch, ok := clients.ipHost[ip]
|
||||||
if ok {
|
if ok {
|
||||||
ch.WhoisInfo = info
|
ch.WhoisInfo = info
|
||||||
log.Debug("Clients: set WHOIS info for auto-client %s: %v", ch.Host, ch.WhoisInfo)
|
log.Debug("Clients: set WHOIS info for auto-client %s: %v", ch.Host, ch.WhoisInfo)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ch = ClientHost{
|
ch = ClientHost{
|
||||||
|
|
|
@ -8,6 +8,8 @@ import (
|
||||||
whois "github.com/likexian/whois-go"
|
whois "github.com/likexian/whois-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const maxValueLength = 250
|
||||||
|
|
||||||
// Whois - module context
|
// Whois - module context
|
||||||
type Whois struct {
|
type Whois struct {
|
||||||
clients *clientsContainer
|
clients *clientsContainer
|
||||||
|
@ -26,9 +28,19 @@ func initWhois(clients *clientsContainer) *Whois {
|
||||||
return &w
|
return &w
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the value is too large - cut it and append "..."
|
||||||
|
func trimValue(s string) string {
|
||||||
|
if len(s) <= maxValueLength {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return s[:maxValueLength-3] + "..."
|
||||||
|
}
|
||||||
|
|
||||||
// Parse plain-text data from the response
|
// Parse plain-text data from the response
|
||||||
func whoisParse(data string) map[string]string {
|
func whoisParse(data string) map[string]string {
|
||||||
m := map[string]string{}
|
m := map[string]string{}
|
||||||
|
descr := ""
|
||||||
|
netname := ""
|
||||||
lines := strings.Split(data, "\n")
|
lines := strings.Split(data, "\n")
|
||||||
for _, ln := range lines {
|
for _, ln := range lines {
|
||||||
ln = strings.TrimSpace(ln)
|
ln = strings.TrimSpace(ln)
|
||||||
|
@ -45,14 +57,31 @@ func whoisParse(data string) map[string]string {
|
||||||
k = strings.ToLower(k)
|
k = strings.ToLower(k)
|
||||||
v := strings.TrimSpace(kv[1])
|
v := strings.TrimSpace(kv[1])
|
||||||
|
|
||||||
if k == "orgname" || k == "org-name" {
|
switch k {
|
||||||
m["orgname"] = v
|
case "org-name":
|
||||||
} else if k == "city" {
|
m["orgname"] = trimValue(v)
|
||||||
m["city"] = v
|
case "orgname":
|
||||||
} else if k == "country" {
|
fallthrough
|
||||||
m["country"] = v
|
case "city":
|
||||||
|
fallthrough
|
||||||
|
case "country":
|
||||||
|
m[k] = trimValue(v)
|
||||||
|
|
||||||
|
case "descr":
|
||||||
|
descr = v
|
||||||
|
case "netname":
|
||||||
|
netname = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// descr or netname -> orgname
|
||||||
|
_, ok := m["orgname"]
|
||||||
|
if !ok && len(descr) != 0 {
|
||||||
|
m["orgname"] = trimValue(descr)
|
||||||
|
} else if !ok && len(netname) != 0 {
|
||||||
|
m["orgname"] = trimValue(netname)
|
||||||
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue