Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
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
coco
Commits
53a1a5e1
Commit
53a1a5e1
authored
Dec 25, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of github.com:jumpserver/coco into dev
parents
4a92f2fb
09167f5b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
12 deletions
+26
-12
httpd.py
coco/httpd.py
+1
-1
recorder.py
coco/recorder.py
+23
-3
session.py
coco/session.py
+2
-8
No files found.
coco/httpd.py
View file @
53a1a5e1
...
...
@@ -120,7 +120,7 @@ class SSHws(Namespace, BaseWebSocketHandler):
def
on_leave
(
self
,
room
):
if
self
.
rooms
[
room
][
"admin"
]
==
request
.
sid
:
self
.
emit
(
"data"
,
"
\n
Admin leave"
,
room
=
room
)
self
.
rooms
.
remove
(
room
)
del
self
.
rooms
[
room
]
leave_room
(
room
=
room
)
def
on_disconnect
(
self
):
...
...
coco/recorder.py
View file @
53a1a5e1
...
...
@@ -5,7 +5,11 @@
import
abc
import
logging
import
threading
import
time
import
os
import
gzip
import
json
import
shutil
from
.alignment
import
MemoryQueue
...
...
@@ -98,18 +102,34 @@ class ServerReplayRecorder(ReplayRecorder):
:return:
"""
# Todo: <liuzheng712@gmail.com>
self
.
file
.
write
(
data
)
if
len
(
data
[
'data'
])
>
0
:
# print(json.dumps(
# data['data'].decode('utf-8', 'replace')))
self
.
file
.
write
(
'"'
+
str
(
data
[
'timestamp'
]
-
self
.
starttime
)
+
'":'
+
json
.
dumps
(
data
[
'data'
]
.
decode
(
'utf-8'
,
'replace'
))
+
','
)
def
session_start
(
self
,
session_id
):
self
.
starttime
=
time
.
time
()
self
.
file
=
open
(
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay'
),
'a'
)
self
.
file
.
write
(
'{'
)
def
session_end
(
self
,
session_id
):
self
.
file
.
write
(
'"0":""}'
)
self
.
file
.
close
()
with
open
(
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay'
),
'rb'
)
as
f_in
,
\
gzip
.
open
(
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay.gz'
),
'wb'
)
as
f_out
:
shutil
.
copyfileobj
(
f_in
,
f_out
)
if
self
.
push_to_server
(
session_id
):
logger
.
info
(
"Succeed to push {}'s {}"
.
format
(
session_id
,
"record"
))
else
:
logger
.
error
(
"Failed to push {}'s {}"
.
format
(
session_id
,
"record"
))
def
push_to_server
(
self
):
pass
def
push_to_server
(
self
,
session_id
):
return
self
.
app
.
service
.
push_session_replay
(
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay'
),
session_id
)
def
__del__
(
self
):
print
(
"{} has been gc"
.
format
(
self
))
...
...
coco/session.py
View file @
53a1a5e1
...
...
@@ -8,19 +8,17 @@ import datetime
import
selectors
import
time
BUF_SIZE
=
1024
logger
=
logging
.
getLogger
(
__file__
)
class
Session
:
def
__init__
(
self
,
client
,
server
,
command_recorder
=
None
,
replay_recorder
=
None
):
self
.
id
=
str
(
uuid
.
uuid4
())
self
.
client
=
client
# Master of the session, it's a client sock
self
.
server
=
server
# Server channel
self
.
_watchers
=
[]
# Only watch session
self
.
_sharers
=
[]
# Join to the session, read and write
self
.
_sharers
=
[]
# Join to the session, read and write
self
.
replaying
=
True
self
.
date_created
=
datetime
.
datetime
.
now
()
self
.
date_finished
=
None
...
...
@@ -123,6 +121,7 @@ class Session:
events
=
self
.
sel
.
select
()
for
sock
in
[
key
.
fileobj
for
key
,
_
in
events
]:
data
=
sock
.
recv
(
BUF_SIZE
)
# self.put_replay(data)
if
sock
==
self
.
server
:
if
len
(
data
)
==
0
:
msg
=
"Server close the connection"
...
...
@@ -184,8 +183,3 @@ class Session:
def
__del__
(
self
):
logger
.
info
(
"Session {} object has been GC"
)
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