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
75a776dd
Commit
75a776dd
authored
Jun 26, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of bitbucket.org:jumpserver/coco into dev
parents
244ab60b
1df7614a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
35 deletions
+20
-35
app.py
coco/app.py
+1
-1
connection.py
coco/connection.py
+2
-1
httpd.py
coco/httpd.py
+14
-32
recorder.py
coco/recorder.py
+3
-1
No files found.
coco/app.py
View file @
75a776dd
...
...
@@ -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__
)
...
...
coco/connection.py
View file @
75a776dd
...
...
@@ -101,7 +101,8 @@ class SSHConnection:
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
try
:
ssh
.
connect
(
gateway
.
ip
,
username
=
gateway
.
username
,
ssh
.
connect
(
gateway
.
ip
,
port
=
gateway
.
port
,
username
=
gateway
.
username
,
password
=
gateway
.
password
,
pkey
=
gateway
.
private_key_obj
)
except
(
paramiko
.
AuthenticationException
,
...
...
coco/httpd.py
View file @
75a776dd
...
...
@@ -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 @
75a776dd
...
...
@@ -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
:
...
...
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