forked from vela-ssoc/vela-radar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradar_lua.go
120 lines (96 loc) · 1.94 KB
/
radar_lua.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
116
117
118
119
120
package radar
import (
"time"
"github.com/vela-ssoc/vela-kit/lua"
"github.com/vela-ssoc/vela-radar/web"
)
func (rad *Radar) Type() string {
return typeof
}
func (rad *Radar) Name() string {
return rad.cfg.name
}
func (rad *Radar) Close() error {
if rad.task != nil {
rad.task.close()
}
rad.UndoDefine()
return nil
}
func (rad *Radar) Start() error {
rad.V(time.Now(), lua.VTRun)
return nil
}
func (rad *Radar) pipeL(L *lua.LState) int {
rad.cfg.Chains.CheckMany(L)
return 0
}
func (rad *Radar) NewTaskL(L *lua.LState) int {
if rad.IsWorking() {
L.RaiseError("%+v\n", "scan task running")
return 0
}
target := L.CheckString(1)
task := rad.NewTask(target)
L.Push(task)
return 1
}
func (rad *Radar) defineL(L *lua.LState) int {
rad.Define()
return 0
}
func (rad *Radar) startL(L *lua.LState) int {
xEnv.Start(L, rad).
Err(func(err error) { L.RaiseError("%v", err) }).
From(L.CodeVM()).
Do()
return 0
}
func (rad *Radar) chromeL(L *lua.LState) int {
//todo create chrome object
cfg := &web.ScreenshotCfg{
Proxy: "",
Chrome: false,
Thread: 5,
Timeout: 10,
ResultDir: "screenshoot_result",
Save: false,
Debug: false,
Miniocfg: rad.cfg.MinioCfg,
}
v := L.Get(1)
switch v.Type() {
case lua.LTTable:
v.(*lua.LTable).Range(func(k string, value lua.LValue) {
cfg.NewIndex(L, k, value)
})
default:
goto DONE
}
DONE:
s, err := web.NewScreenServer(L.Context(), cfg, xEnv)
if err != nil {
L.RaiseError("screen server init fail %v", err)
return 0
}
rad.screen = s
return 1
}
// rad.chrome("/aab//cc")
func (rad *Radar) Index(L *lua.LState, key string) lua.LValue {
switch key {
case "start":
return lua.NewFunction(rad.startL)
case "pipe":
return lua.NewFunction(rad.pipeL)
case "task":
return lua.NewFunction(rad.NewTaskL)
case "define":
return lua.NewFunction(rad.defineL)
case "chrome":
return lua.NewFunction(rad.chromeL)
default:
//todo
}
return lua.LNil
}