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
1c8dfae8
Commit
1c8dfae8
authored
7 years ago
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of bitbucket.org:jumpserver/coco into dev
parents
444ba916
c2293e45
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
7 deletions
+65
-7
httpd.py
coco/httpd.py
+1
-2
recorder.py
coco/recorder.py
+64
-5
No files found.
coco/httpd.py
View file @
1c8dfae8
...
@@ -11,7 +11,7 @@ from .models import Request, Client, WSProxy
...
@@ -11,7 +11,7 @@ from .models import Request, Client, WSProxy
from
.proxy
import
ProxyServer
from
.proxy
import
ProxyServer
from
.utils
import
get_logger
from
.utils
import
get_logger
__version__
=
'0.
4
.0'
__version__
=
'0.
5
.0'
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
logger
=
get_logger
(
__file__
)
logger
=
get_logger
(
__file__
)
...
@@ -257,7 +257,6 @@ class HttpServer:
...
@@ -257,7 +257,6 @@ class HttpServer:
def
run
(
self
):
def
run
(
self
):
host
=
self
.
flask_app
.
config
[
"BIND_HOST"
]
host
=
self
.
flask_app
.
config
[
"BIND_HOST"
]
port
=
self
.
flask_app
.
config
[
"HTTPD_PORT"
]
port
=
self
.
flask_app
.
config
[
"HTTPD_PORT"
]
print
(
'Starting websocket server at {}:{}'
.
format
(
host
,
port
))
self
.
socket_io
.
init_app
(
self
.
flask_app
,
async_mode
=
self
.
async_mode
)
self
.
socket_io
.
init_app
(
self
.
flask_app
,
async_mode
=
self
.
async_mode
)
self
.
socket_io
.
run
(
self
.
flask_app
,
port
=
port
,
host
=
host
,
debug
=
False
)
self
.
socket_io
.
run
(
self
.
flask_app
,
port
=
port
,
host
=
host
,
debug
=
False
)
...
...
This diff is collapsed.
Click to expand it.
coco/recorder.py
View file @
1c8dfae8
...
@@ -129,11 +129,45 @@ class ServerReplayRecorder(ReplayRecorder):
...
@@ -129,11 +129,45 @@ class ServerReplayRecorder(ReplayRecorder):
logger
.
info
(
"Succeed to push {}'s {}"
.
format
(
session_id
,
"record"
))
logger
.
info
(
"Succeed to push {}'s {}"
.
format
(
session_id
,
"record"
))
else
:
else
:
logger
.
error
(
"Failed to push {}'s {}"
.
format
(
session_id
,
"record"
))
logger
.
error
(
"Failed to push {}'s {}"
.
format
(
session_id
,
"record"
))
self
.
push_to_server
(
session_id
)
def
push_to_server
(
self
,
session_id
):
def
push_to_server
(
self
,
session_id
):
if
self
.
upload_replay
(
3
,
session_id
):
if
self
.
finish_replay
(
3
,
session_id
):
return
True
else
:
return
False
else
:
return
False
def
push_local
(
self
,
session_id
):
return
self
.
app
.
service
.
push_session_replay
(
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay.gz'
),
return
self
.
app
.
service
.
push_session_replay
(
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay.gz'
),
session_id
)
session_id
)
def
upload_replay
(
self
,
times
,
session_id
):
if
times
>
0
:
if
self
.
push_local
(
session_id
):
logger
.
info
(
"success push session: {}'s replay log "
.
format
(
session_id
))
return
True
else
:
logger
.
error
(
"failed report session {}'s replay log, try {} times"
.
format
(
session_id
,
times
))
return
self
.
upload_replay
(
times
-
1
,
session_id
)
else
:
logger
.
error
(
"failed report session {}'s replay log"
.
format
(
session_id
))
return
False
def
finish_replay
(
self
,
times
,
session_id
):
if
times
>
0
:
if
self
.
app
.
service
.
finish_replay
(
session_id
):
logger
.
info
(
"success report session {}'s replay log "
.
format
(
session_id
))
return
True
else
:
logger
.
error
(
"failed report session {}'s replay log, try {} times"
.
format
(
session_id
,
times
))
return
self
.
finish_replay
(
times
-
1
,
session_id
)
else
:
logger
.
error
(
"failed report session {}'s replay log"
.
format
(
session_id
))
return
False
def
__del__
(
self
):
def
__del__
(
self
):
print
(
"{} has been gc"
.
format
(
self
))
print
(
"{} has been gc"
.
format
(
self
))
del
self
.
file
del
self
.
file
...
@@ -254,17 +288,41 @@ class S3ReplayRecorder(ServerReplayRecorder):
...
@@ -254,17 +288,41 @@ class S3ReplayRecorder(ServerReplayRecorder):
else
:
else
:
self
.
s3
=
boto3
.
client
(
's3'
)
self
.
s3
=
boto3
.
client
(
's3'
)
def
push_to_server
(
self
,
session_id
):
def
push_to_s3
(
self
,
session_id
):
logger
.
debug
(
"push to server"
)
try
:
try
:
self
.
s3
.
upload_file
(
self
.
s3
.
upload_file
(
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay.gz'
),
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay.gz'
),
self
.
bucket
,
self
.
bucket
,
self
.
app
.
config
.
get
(
"NAME"
,
"coco"
)
+
time
.
strftime
(
'
%
Y-
%
m-
%
d'
,
time
.
localtime
(
time
.
strftime
(
'
%
Y-
%
m-
%
d'
,
time
.
localtime
(
self
.
starttime
))
+
'/'
+
session_id
+
'.replay.gz'
)
self
.
starttime
))
+
'/'
+
session_id
+
'.replay.gz'
)
return
True
except
:
except
:
return
self
.
app
.
service
.
push_session_replay
(
return
False
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay.gz'
),
session_id
)
def
upload_replay
(
self
,
times
,
session_id
):
if
times
>
0
:
if
self
.
push_to_s3
(
session_id
):
logger
.
info
(
"success push session: {}'s replay log to S3 "
.
format
(
session_id
))
return
True
else
:
logger
.
error
(
"failed report session {}'s replay log to S3, try {} times"
.
format
(
session_id
,
times
))
return
self
.
upload_replay
(
times
-
1
,
session_id
)
else
:
logger
.
error
(
"failed report session {}'s replay log S3, try to push to local"
.
format
(
session_id
))
return
self
.
upload_replay_to_local
(
3
,
session_id
)
def
upload_replay_to_local
(
self
,
times
,
session_id
):
if
times
>
0
:
if
self
.
push_local
(
session_id
):
logger
.
info
(
"success push session: {}'s replay log "
.
format
(
session_id
))
return
True
else
:
logger
.
error
(
"failed report session {}'s replay log, try {} times"
.
format
(
session_id
,
times
))
return
self
.
upload_replay_to_local
(
times
-
1
,
session_id
)
else
:
logger
.
error
(
"failed report session {}'s replay log"
.
format
(
session_id
))
return
False
def
get_command_recorder_class
(
config
):
def
get_command_recorder_class
(
config
):
...
@@ -279,6 +337,7 @@ def get_command_recorder_class(config):
...
@@ -279,6 +337,7 @@ def get_command_recorder_class(config):
def
get_replay_recorder_class
(
config
):
def
get_replay_recorder_class
(
config
):
replay_storage
=
config
[
"REPLAY_STORAGE"
]
replay_storage
=
config
[
"REPLAY_STORAGE"
]
logger
.
debug
(
replay_storage
)
storage_type
=
replay_storage
.
get
(
'TYPE'
)
storage_type
=
replay_storage
.
get
(
'TYPE'
)
if
storage_type
==
"s3"
:
if
storage_type
==
"s3"
:
return
S3ReplayRecorder
return
S3ReplayRecorder
...
...
This diff is collapsed.
Click to expand it.
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