Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
koko
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
koko
Commits
262803eb
Commit
262803eb
authored
May 17, 2019
by
Eric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] upload command record data
parent
1efa620f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
23 deletions
+41
-23
proxy.go
pkg/proxy/proxy.go
+10
-10
recorder.go
pkg/proxy/recorder.go
+15
-5
switch.go
pkg/proxy/switch.go
+8
-5
terminal.go
pkg/service/terminal.go
+4
-0
urls.go
pkg/service/urls.go
+4
-3
No files found.
pkg/proxy/proxy.go
View file @
262803eb
...
...
@@ -57,15 +57,17 @@ func (p *ProxyServer) validatePermission() bool {
func
(
p
*
ProxyServer
)
getSSHConn
()
(
srvConn
*
ServerSSHConnection
,
err
error
)
{
srvConn
=
&
ServerSSHConnection
{
host
:
p
.
Asset
.
Ip
,
port
:
strconv
.
Itoa
(
p
.
Asset
.
Port
),
user
:
p
.
SystemUser
.
Username
,
password
:
p
.
SystemUser
.
Password
,
timeout
:
config
.
GetConf
()
.
SSHTimeout
,
name
:
p
.
Asset
.
Id
,
host
:
p
.
Asset
.
Ip
,
port
:
strconv
.
Itoa
(
p
.
Asset
.
Port
),
user
:
p
.
SystemUser
.
Username
,
password
:
p
.
SystemUser
.
Password
,
privateKey
:
p
.
SystemUser
.
PrivateKey
,
timeout
:
config
.
GetConf
()
.
SSHTimeout
,
}
pty
:=
p
.
UserConn
.
Pty
()
done
:=
make
(
chan
struct
{})
go
p
.
sendConnectingMsg
(
done
)
go
p
.
sendConnectingMsg
(
done
,
srvConn
.
timeout
)
err
=
srvConn
.
Connect
(
pty
.
Window
.
Height
,
pty
.
Window
.
Width
,
pty
.
Term
)
utils
.
IgnoreErrWriteString
(
p
.
UserConn
,
"
\r\n
"
)
close
(
done
)
...
...
@@ -86,12 +88,11 @@ func (p *ProxyServer) getServerConn() (srvConn ServerConnection, err error) {
}
}
func
(
p
*
ProxyServer
)
sendConnectingMsg
(
done
chan
struct
{})
{
func
(
p
*
ProxyServer
)
sendConnectingMsg
(
done
chan
struct
{}
,
delaySecond
int
)
{
delay
:=
0.0
msg
:=
fmt
.
Sprintf
(
i18n
.
T
(
"Connecting to %s@%s %.1f"
),
p
.
SystemUser
.
Username
,
p
.
Asset
.
Ip
,
delay
)
utils
.
IgnoreErrWriteString
(
p
.
UserConn
,
msg
)
cf
:=
config
.
GetConf
()
for
int
(
delay
)
<
cf
.
SSHTimeout
{
for
int
(
delay
)
<
delaySecond
{
select
{
case
<-
done
:
return
...
...
@@ -145,5 +146,4 @@ func (p *ProxyServer) Proxy() {
}
sw
.
parser
.
SetCMDFilterRules
(
cmdRules
)
_
=
sw
.
Bridge
()
_
=
srvConn
.
Close
()
}
pkg/proxy/recorder.go
View file @
262803eb
...
...
@@ -30,13 +30,15 @@ type CommandRecorder struct {
Session
*
SwitchSession
storage
CommandStorage
queue
chan
*
model
.
Command
queue
chan
*
model
.
Command
closed
chan
struct
{}
}
func
(
c
*
CommandRecorder
)
initial
()
{
c
.
queue
=
make
(
chan
*
model
.
Command
,
10
)
//c.storage = NewCommandStorage()
c
.
storage
,
_
=
NewFileCommandStorage
(
"/tmp/abc.log"
)
c
.
storage
=
NewCommandStorage
()
c
.
closed
=
make
(
chan
struct
{})
//c.storage, _ = NewFileCommandStorage("/tmp/abc.log")
go
c
.
record
()
}
...
...
@@ -58,13 +60,22 @@ func (c *CommandRecorder) Record(command [2]string) {
}
func
(
c
*
CommandRecorder
)
End
()
{
close
(
c
.
queue
)
select
{
case
<-
c
.
closed
:
return
default
:
}
close
(
c
.
closed
)
}
func
(
c
*
CommandRecorder
)
record
()
{
cmdList
:=
make
([]
*
model
.
Command
,
0
)
for
{
select
{
case
<-
c
.
closed
:
if
len
(
cmdList
)
==
0
{
return
}
case
p
,
ok
:=
<-
c
.
queue
:
if
!
ok
{
logger
.
Debug
(
"Session command recorder close: "
,
c
.
Session
.
Id
)
...
...
@@ -79,7 +90,6 @@ func (c *CommandRecorder) record() {
continue
}
}
err
:=
c
.
storage
.
BulkSave
(
cmdList
)
if
err
==
nil
{
cmdList
=
cmdList
[
:
0
]
...
...
pkg/proxy/switch.go
View file @
262803eb
...
...
@@ -4,7 +4,7 @@ import (
"context"
"time"
"github.com/satori/go.uuid"
uuid
"github.com/satori/go.uuid"
"cocogo/pkg/i18n"
"cocogo/pkg/logger"
...
...
@@ -51,7 +51,7 @@ func (s *SwitchSession) Initial() {
s
.
SystemUser
=
s
.
srvConn
.
User
()
s
.
LoginFrom
=
s
.
userConn
.
LoginFrom
()
s
.
RemoteAddr
=
s
.
userConn
.
RemoteAddr
()
s
.
DateStart
=
time
.
Now
()
s
.
DateStart
=
time
.
Now
()
.
UTC
()
s
.
cmdRecorder
=
NewCommandRecorder
(
s
)
s
.
replayRecorder
=
NewReplyRecord
(
s
)
...
...
@@ -77,11 +77,13 @@ func (s *SwitchSession) recordCmd() {
}
func
(
s
*
SwitchSession
)
postBridge
()
{
s
.
cmdRecorder
.
End
()
s
.
replayRecorder
.
End
()
s
.
parser
.
Close
()
s
.
DateEnd
=
time
.
Now
()
.
UTC
()
_
=
s
.
userTran
.
Close
()
_
=
s
.
srvTran
.
Close
()
s
.
parser
.
Close
()
s
.
replayRecorder
.
End
()
s
.
cmdRecorder
.
End
()
}
func
(
s
*
SwitchSession
)
Bridge
()
(
err
error
)
{
...
...
@@ -94,6 +96,7 @@ func (s *SwitchSession) Bridge() (err error) {
}()
go
s
.
parser
.
Parse
()
go
s
.
recordCmd
()
defer
s
.
postBridge
()
for
{
select
{
...
...
pkg/service/terminal.go
View file @
262803eb
...
...
@@ -84,5 +84,9 @@ func PushSessionReplay(sessionID, gZipFile string) {
}
func
PushSessionCommand
(
commands
[]
*
model
.
Command
)
(
err
error
)
{
err
=
authClient
.
Post
(
SessionCommandURL
,
commands
,
nil
)
if
err
!=
nil
{
logger
.
Error
(
err
)
}
return
}
pkg/service/urls.go
View file @
262803eb
...
...
@@ -20,9 +20,10 @@ const (
TerminalConfigURL
=
"/api/terminal/v1/terminal/config/"
// 从jumpserver获取coco的配置
TerminalHeartBeatURL
=
"/api/terminal/v1/terminal/status/"
SessionListURL
=
"/api/terminal/v1/sessions/"
//上传创建的资产会话session id
SessionDetailURL
=
"/api/terminal/v1/sessions/%s/"
// finish session的时候发送
SessionReplayURL
=
"/api/terminal/v1/sessions/%s/replay/"
//上传录像
SessionListURL
=
"/api/terminal/v1/sessions/"
//上传创建的资产会话session id
SessionDetailURL
=
"/api/terminal/v1/sessions/%s/"
// finish session的时候发送
SessionReplayURL
=
"/api/terminal/v1/sessions/%s/replay/"
//上传录像
SessionCommandURL
=
"/api/terminal/v1/command/"
//上传批量命令
FinishTaskURL
=
"/api/terminal/v1/tasks/%s/"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment