-
Notifications
You must be signed in to change notification settings - Fork 321
/
main.go
115 lines (95 loc) · 2.2 KB
/
main.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
113
114
115
package main
import "C" // required
import (
"encoding/json"
"github.com/opensec-cn/kunpeng/config"
"github.com/opensec-cn/kunpeng/plugin"
_ "github.com/opensec-cn/kunpeng/plugin/go"
_ "github.com/opensec-cn/kunpeng/plugin/json"
"github.com/opensec-cn/kunpeng/util"
"github.com/opensec-cn/kunpeng/web"
)
var VERSION string
type greeting string
func (g greeting) Check(taskJSON string) []map[string]interface{} {
var task plugin.Task
json.Unmarshal([]byte(taskJSON), &task)
return plugin.Scan(task)
}
func (g greeting) GetPlugins() []map[string]interface{} {
return plugin.GetPlugins()
}
func (g greeting) SetConfig(configJSON string) {
config.Set(configJSON)
}
func (g greeting) ShowLog() {
config.SetDebug(true)
}
func (g greeting) GetVersion() string {
return VERSION
}
func (g greeting) StartBuffer() {
util.Logger.StartBuffer()
}
func (g greeting) GetLog(sep string) string {
return util.Logger.BufferContent(sep)
}
//export StartWebServer
func StartWebServer(bindAddr *C.char) {
go web.StartServer(C.GoString(bindAddr))
}
//export Check
func Check(task *C.char) *C.char {
util.Logger.Info(C.GoString(task))
var m plugin.Task
err := json.Unmarshal([]byte(C.GoString(task)), &m)
if err != nil {
util.Logger.Error(err.Error())
return C.CString("[]")
}
util.Logger.Info(m)
result := plugin.Scan(m)
if len(result) == 0 {
return C.CString("[]")
}
b, err := json.Marshal(result)
if err != nil {
util.Logger.Error(err.Error())
return C.CString("[]")
}
return C.CString(string(b))
}
//export GetPlugins
func GetPlugins() *C.char {
var result string
plugins := plugin.GetPlugins()
b, err := json.Marshal(plugins)
if err != nil {
util.Logger.Error(err.Error())
return C.CString("[]")
}
result = string(b)
return C.CString(result)
}
//export SetConfig
func SetConfig(configJSON *C.char) {
config.Set(C.GoString(configJSON))
}
//export ShowLog
func ShowLog() {
config.SetDebug(true)
}
//export GetVersion
func GetVersion() *C.char {
return C.CString(VERSION)
}
//export StartBuffer
func StartBuffer() {
util.Logger.StartBuffer()
}
//export GetLog
func GetLog(sep *C.char) *C.char {
return C.CString(util.Logger.BufferContent(C.GoString(sep)))
}
var Greeter greeting
func main() {}