forked from prism4time/openvas-golang-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomp.go
73 lines (63 loc) · 1.6 KB
/
omp.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
package omp
import (
"fmt"
"strings"
)
// OMP .
type OMP interface {
// Target related
CreateTarget(t *Target) (string, error)
ModifyTarget(t *Target) error
GetTargets() ([]OMPtarget, error)
DeleteTarget(id string) error
// configs
CreateConfig(id string, name string) (string, error)
GetConfigs() ([]Config, error)
GetConfigByName(name string) (Config, error)
// tasks
CreateTask(t *Task) (string, error)
GetTasks(id string) ([]Task, error)
DeleteTask(id string) error
ModifyTask(t *Task) error
StartTask(id string) (string, error)
StopTask(t *Task) error
// scanners
CreateScanner(s *Scanner, credID string) (string, error)
GetScanners() ([]Scanner, error)
GetScannerByName(scannerName string) (string, error)
GetDefaultScanner() (string, error)
// credentials
CreateCredential(cred Credential) (string, error)
GetCredentials( /*cred Credential*/ ) ([]Credential, error)
// result
GetResults(r *Result, taskID string, filter ...string) ([]Result, error)
// reports
GetReports(id string) (Report, error)
}
// Version 版本类型
type Version int
// Version .
const (
Version4 Version = 4
Version7 = 7
)
// New new an openvas instance
// addr is the openvas address which you want to connect with
func New(addr, username, password string) (OMP, error) {
c, err := newConnector(addr)
if err != nil {
return nil, err
}
err = c.Auth(username, password)
if err != nil {
return nil, err
}
v, err := c.GetVersion()
if err != nil {
return nil, err
}
if strings.HasPrefix(v, "7.0") {
return &OMPv7{c}, nil
}
return nil, fmt.Errorf("server version is %s, not supported yet", v)
}