-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcmd_result.go
112 lines (106 loc) · 3.23 KB
/
cmd_result.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package omp
import "encoding/xml"
// Result .
type Result struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr,omitempty"`
Owner *struct {
Text string `xml:",chardata"`
Name string `xml:"name,omitempty"`
} `xml:"owner,omitempty"`
Comment string `xml:"comment,omitempty"`
CreationTime string `xml:"creation_time,omitempty"`
ModificationTime string `xml:"modification_time,omitempty"`
UserTags *UserTags `xml:"user_tags,omitempty"`
Host string `xml:"host,omitempty"`
Port string `xml:"port,omitempty"`
Nvt *Nvt `xml:"nvt,omitempty"`
Threat string `xml:"threat,omitempty"`
Description string `xml:"description,omitempty"`
OriginalThreat string `xml:"original_threat,omitempty"`
Notes string `xml:"notes,omitempty"`
Overrides *struct {
Text string `xml:",chardata"`
Override *struct {
Chardata string `xml:",chardata"`
ID string `xml:"id,attr,omitempty"`
Nvt *struct {
Text string `xml:",chardata"`
Oid string `xml:"oid,attr,omitempty"`
Name string `xml:"name,omitempty"`
} `xml:"nvt,omitempty"`
Text *struct {
Text string `xml:",chardata"`
Excerpt string `xml:"excerpt,attr,omitempty"`
} `xml:"text,omitempty"`
NewThreat string `xml:"new_threat,omitempty"`
Orphan string `xml:"orphan,omitempty"`
} `xml:"override,omitempty"`
} `xml:"overrides,omitempty"`
}
// Results wrap result struct
type Results struct {
Text string `xml:",chardata"`
Start string `xml:"start,attr,omitempty"`
Max string `xml:"max,attr,omitempty"`
Result []Result `xml:"result,omitempty"`
}
// GetResults .
type GetResults struct {
responseBase
XMLName xml.Name `xml:"get_results"`
Text string `xml:",chardata"`
ResultID string `xml:"result_id,attr,omitempty"`
TaskID string `xml:"task_id,attr,omitempty"`
Filter string `xml:"filter,attr,omitempty"`
}
// GetResultsResponse .
type GetResultsResponse struct {
responseBase
XMLName xml.Name `xml:"get_results_response"`
Text string `xml:",chardata"`
Result []Result `xml:"result,omitempty"`
Filters *Filters `xml:"filters,omitempty"`
Sort *struct {
Text string `xml:",chardata"`
Field *struct {
Text string `xml:",chardata"`
Order string `xml:"order,omitempty"`
} `xml:"field,omitempty"`
} `xml:"sort,omitempty"`
Results *struct {
Text string `xml:",chardata"`
Max string `xml:"max,attr,omitempty"`
Start string `xml:"start,attr,omitempty"`
} `xml:"results,omitempty"`
ResultCount *struct {
Text string `xml:",chardata"`
Filtered string `xml:"filtered,omitempty"`
Page string `xml:"page,omitempty"`
} `xml:"result_count,omitempty"`
}
// GetResults .
func (c *Connector) GetResults(r *Result, taskID string, filter ...string) ([]Result, error) {
res := []Result{}
req := GetResults{}
if filter != nil && len(filter) != 0 {
req.Filter = filter[0]
}
if r != nil {
if len(r.ID) != 0 {
req.ResultID = r.ID
}
}
if len(taskID) != 0 {
req.TaskID = taskID
}
resp := &GetResultsResponse{}
err := c.doRequest(req, resp)
if err != nil {
return []Result{}, err
}
if len(resp.Result) != 0 {
res = append(res, resp.Result...)
}
return res, nil
}