From 2a9845042589c0f8bac5d14aa5be4138992fc652 Mon Sep 17 00:00:00 2001 From: MaineK00n Date: Thu, 15 Oct 2020 07:48:28 +0900 Subject: [PATCH] change collect scan success address --- models/packages.go | 6 +++--- scan/base.go | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/models/packages.go b/models/packages.go index edd9b963..76574265 100644 --- a/models/packages.go +++ b/models/packages.go @@ -181,9 +181,9 @@ type AffectedProcess struct { // ListenPorts has the result of parsing the port information to the address and port. type ListenPorts struct { - Address string `json:"address"` - Port string `json:"port"` - OpenStatus bool `json:"openStatus"` + Address string `json:"address"` + Port string `json:"port"` + PortScanSuccessOn []string `json:"portScanSuccessOn"` } // NeedRestartProcess keep a processes information affected by software update diff --git a/scan/base.go b/scan/base.go index 674f780c..70c9b56f 100644 --- a/scan/base.go +++ b/scan/base.go @@ -804,37 +804,39 @@ func (l *base) execPortsScan(dest []string) ([]string, error) { } func (l *base) updatePortStatus(open []string) { - for _, p := range l.osPackages.Packages { + for name, p := range l.osPackages.Packages { if p.AffectedProcs == nil { continue } - for _, proc := range p.AffectedProcs { + for proci, proc := range p.AffectedProcs { if proc.ListenPorts == nil { continue } - for _, port := range proc.ListenPorts { - port.OpenStatus = matchListenPorts(open, port) + for porti, port := range proc.ListenPorts { + l.osPackages.Packages[name].AffectedProcs[proci].ListenPorts[porti].PortScanSuccessOn = matchListenPorts(open, port) } } } } -func matchListenPorts(open []string, port models.ListenPorts) bool { +func matchListenPorts(open []string, port models.ListenPorts) []string { + match := []string{} + l := base{} for _, ip := range open { i := l.parseListenPorts(ip) if port.Address == "*" { if port.Port == i.Port { - return true + match = append(match, i.Address) } } else { if port.Address == i.Address && port.Port == i.Port { - return true + match = append(match, i.Address) } } } - return false + return match } func (l *base) ps() (stdout string, err error) {