forked from jumpserver/koko
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_check.go
More file actions
120 lines (101 loc) · 1.92 KB
/
command_check.go
File metadata and controls
120 lines (101 loc) · 1.92 KB
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 proxy
import (
"context"
"sync"
"github.com/jumpserver/koko/pkg/jms-sdk-go/model"
)
const (
StatusQuery = "query"
StatusStart = "start"
StatusNone = "none"
)
type commandConfirmStatus struct {
Status string
data string
Rule model.SystemUserFilterRule
Cmd string
sync.Mutex
wg sync.WaitGroup
ctx context.Context
cancelFunc context.CancelFunc
action model.RuleAction
Processor string
}
func (c *commandConfirmStatus) SetStatus(status string) {
c.Lock()
defer c.Unlock()
c.Status = status
}
func (c *commandConfirmStatus) SetAction(action model.RuleAction) {
c.Lock()
defer c.Unlock()
c.action = action
}
func (c *commandConfirmStatus) GetAction() model.RuleAction {
c.Lock()
defer c.Unlock()
return c.action
}
func (c *commandConfirmStatus) SetProcessor(processor string) {
c.Lock()
defer c.Unlock()
c.Processor = processor
}
func (c *commandConfirmStatus) GetProcessor() string {
c.Lock()
defer c.Unlock()
return c.Processor
}
func (c *commandConfirmStatus) SetRule(rule model.SystemUserFilterRule) {
c.Lock()
defer c.Unlock()
c.Rule = rule
}
func (c *commandConfirmStatus) SetData(data string) {
c.Lock()
defer c.Unlock()
c.data = data
}
func (c *commandConfirmStatus) SetCmd(cmd string) {
c.Lock()
defer c.Unlock()
c.Cmd = cmd
}
func (c *commandConfirmStatus) ResetCtx() {
c.Lock()
defer c.Unlock()
c.ctx, c.cancelFunc = context.WithCancel(context.Background())
}
func (c *commandConfirmStatus) InRunning() bool {
c.Lock()
defer c.Unlock()
switch c.Status {
case StatusStart:
return true
}
return false
}
func (c *commandConfirmStatus) InQuery() bool {
c.Lock()
defer c.Unlock()
switch c.Status {
case StatusQuery:
return true
}
return false
}
func (c *commandConfirmStatus) IsNeedCancel(b []byte) bool {
if len(b) > 0 {
switch b[0] {
case CtrlC, CtrlD:
c.cancelFunc()
c.wg.Wait()
return true
}
}
return false
}
const (
CtrlC = 3
CtrlD = 4
)