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
938bd695
Commit
938bd695
authored
Jun 11, 2018
by
BaiJiangJie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
https://github.com/jumpserver/coco
into dev
parents
fe7c8dad
7014542c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
38 deletions
+22
-38
app.py
coco/app.py
+2
-2
httpd.py
coco/httpd.py
+14
-32
recorder.py
coco/recorder.py
+3
-1
requirements.txt
requirements/requirements.txt
+3
-3
No files found.
coco/app.py
View file @
938bd695
...
...
@@ -25,7 +25,7 @@ from .utils import get_logger, register_app, register_service
eventlet
.
monkey_patch
()
hub_prevent_multiple_readers
(
False
)
__version__
=
'1.3.
1
'
__version__
=
'1.3.
2
'
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
logger
=
get_logger
(
__file__
)
...
...
@@ -184,7 +184,7 @@ class Coco:
ok
=
recorder
.
upload_replay
(
session_id
,
1
)
if
not
ok
and
os
.
path
.
getsize
(
full_path
)
==
0
:
os
.
unlink
(
full_path
)
time
.
sleep
(
1
)
time
.
sleep
(
interval
)
thread
=
threading
.
Thread
(
target
=
func
)
thread
.
start
()
...
...
coco/httpd.py
View file @
938bd695
...
...
@@ -62,52 +62,35 @@ class ProxyNamespace(BaseNamespace):
"""
super
()
.
__init__
(
*
args
,
**
kwargs
)
self
.
connections
=
dict
()
self
.
win_size
=
None
def
new_connection
(
self
):
self
.
connections
[
request
.
sid
]
=
dict
()
def
new_room
(
self
):
def
new_room
(
self
,
req
=
None
):
room_id
=
str
(
uuid
.
uuid4
())
room
=
{
"id"
:
room_id
,
"proxy"
:
None
,
"client"
:
None
,
"forwarder"
:
None
,
"request"
:
self
.
make_coco_request
(),
"cols"
:
80
,
"rows"
:
24
"request"
:
req
,
}
self
.
connections
[
request
.
sid
][
room_id
]
=
room
return
room
@staticmethod
def
get_win_size
():
cols_request
=
request
.
cookies
.
get
(
'cols'
)
rows_request
=
request
.
cookies
.
get
(
'rows'
)
if
cols_request
and
cols_request
.
isdigit
():
cols
=
int
(
cols_request
)
else
:
cols
=
80
if
rows_request
and
rows_request
.
isdigit
():
rows
=
int
(
rows_request
)
else
:
rows
=
24
return
cols
,
rows
def
make_coco_request
(
self
):
def
make_coco_request
(
self
,
cols
=
80
,
rows
=
24
):
x_forwarded_for
=
request
.
headers
.
get
(
"X-Forwarded-For"
,
''
)
.
split
(
','
)
if
x_forwarded_for
and
x_forwarded_for
[
0
]:
remote_ip
=
x_forwarded_for
[
0
]
else
:
remote_ip
=
request
.
remote_addr
width
,
height
=
self
.
get_win_size
()
req
=
Request
((
remote_ip
,
0
))
req
.
user
=
self
.
current_user
req
.
meta
=
{
"width"
:
width
,
"height"
:
height
,
"width"
:
cols
,
"height"
:
rows
,
}
return
req
...
...
@@ -122,19 +105,20 @@ class ProxyNamespace(BaseNamespace):
asset_id
=
message
.
get
(
'uuid'
,
None
)
user_id
=
message
.
get
(
'userid'
,
None
)
secret
=
message
.
get
(
'secret'
,
None
)
room
=
self
.
new_room
()
self
.
win_size
=
message
.
get
(
'size'
,
(
80
,
24
))
req
=
self
.
make_coco_request
(
*
self
.
win_size
)
room
=
self
.
new_room
(
req
)
self
.
emit
(
'room'
,
{
'room'
:
room
[
"id"
],
'secret'
:
secret
})
join_room
(
room
[
"id"
])
if
not
asset_id
or
not
user_id
:
# self.on_connect()
return
asset
=
app_service
.
get_asset
(
asset_id
)
system_user
=
app_service
.
get_system_user
(
user_id
)
if
not
asset
or
not
system_user
:
self
.
on_connect
()
return
child
,
parent
=
socket
.
socketpair
()
...
...
@@ -143,7 +127,6 @@ class ProxyNamespace(BaseNamespace):
room
[
"client"
]
=
client
room
[
"forwarder"
]
=
forwarder
room
[
"proxy"
]
=
WSProxy
(
self
,
child
,
room
[
"id"
])
room
[
"cols"
],
room
[
"rows"
]
=
self
.
get_win_size
()
self
.
socketio
.
start_background_task
(
forwarder
.
proxy
,
asset
,
system_user
)
...
...
@@ -165,6 +148,7 @@ class ProxyNamespace(BaseNamespace):
logger
.
debug
(
"On token trigger"
)
token
=
message
.
get
(
'token'
,
None
)
secret
=
message
.
get
(
'secret'
,
None
)
win_size
=
message
.
get
(
'size'
,
(
80
,
24
))
room
=
self
.
new_room
()
self
.
emit
(
'room'
,
{
'room'
:
room
[
"id"
],
'secret'
:
secret
})
if
not
token
or
not
secret
:
...
...
@@ -186,21 +170,19 @@ class ProxyNamespace(BaseNamespace):
user_id
=
info
.
get
(
'user'
,
None
)
self
.
current_user
=
app_service
.
get_user_profile
(
user_id
)
room
[
"request"
]
.
user
=
self
.
current_user
logger
.
debug
(
self
.
current_user
)
self
.
on_host
({
'secret'
:
secret
,
'uuid'
:
info
[
'asset'
],
'userid'
:
info
[
'system_user'
],
'size'
:
win_size
,
})
def
on_resize
(
self
,
message
):
cols
,
rows
=
message
.
get
(
'cols'
,
None
),
message
.
get
(
'rows'
,
None
)
logger
.
debug
(
"On resize event trigger: {}*{}"
.
format
(
cols
,
rows
))
rooms
=
self
.
connections
.
get
(
request
.
sid
)
if
not
rooms
:
return
room
=
list
(
rooms
.
values
())[
0
]
if
rooms
and
(
room
[
"cols"
],
room
[
"rows"
])
!=
(
cols
,
rows
):
if
self
.
win_size
!=
(
cols
,
rows
):
logger
.
debug
(
"Start change win size: {}*{}"
.
format
(
cols
,
rows
))
for
room
in
rooms
.
values
():
room
[
"request"
]
.
meta
.
update
({
'width'
:
cols
,
'height'
:
rows
...
...
coco/recorder.py
View file @
938bd695
...
...
@@ -72,7 +72,9 @@ class ReplayRecorder(metaclass=abc.ABCMeta):
ok
,
msg
=
self
.
push_to_storage
(
session_id
)
if
not
ok
:
msg
=
'Failed push replay file: {}, try again {}'
.
format
(
msg
,
times
)
msg
=
'Failed push replay file {}: {}, try again {}'
.
format
(
session_id
,
msg
,
times
)
logger
.
warn
(
msg
)
self
.
upload_replay
(
session_id
,
times
-
1
)
else
:
...
...
requirements/requirements.txt
View file @
938bd695
asn1crypto==0.2
3
.0
asn1crypto==0.2
4
.0
bcrypt==3.1.4
boto3==1.6.5
botocore==1.9.5
...
...
@@ -32,7 +32,7 @@ python-dateutil==2.6.1
python-engineio==2.1.0
python-gssapi==0.6.4
python-socketio==1.8.3
pytz==201
7
.3
pytz==201
8
.3
requests==2.18.4
s3transfer==0.1.13
simplejson==3.13.2
...
...
@@ -40,5 +40,5 @@ six==1.11.0
tornado==4.5.2
urllib3==1.22
wcwidth==0.1.7
eventlet==0.22.1
Werkzeug==0.14.1
eventlet==0.22
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