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
a1217de8
Commit
a1217de8
authored
7 years ago
by
zheng liu
Browse files
Options
Browse Files
Download
Plain Diff
Merged in dev (pull request #9)
Dev
parents
b0a6cbd1
5d07be79
master
dev
multiprocess
realip
v52
1.5.2
1.5.1
1.5.0
1.4.10
1.4.9
1.4.8
1.4.7
1.4.6
1.4.5
v1.4.7
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
25 deletions
+49
-25
README.md
README.md
+5
-5
app.py
coco/app.py
+2
-2
httpd.py
coco/httpd.py
+1
-1
interactive.py
coco/interactive.py
+15
-4
proxy.py
coco/proxy.py
+5
-2
sshd.py
coco/sshd.py
+18
-10
tasks.py
coco/tasks.py
+3
-1
No files found.
README.md
View file @
a1217de8
...
...
@@ -10,8 +10,8 @@ pre version.
## Install
$ git clone http
://xxxx
$ git clone http
s://github.com/jumpserver/coco.git
## Setting
You need update config.py settings as you need, Be aware of:
...
...
@@ -23,7 +23,7 @@ They are:
NAME:
JUMPSERVER_URL:
SECRET_KEY:
Also some config you need kown:
SSH_HOST:
SSH_PORT:
...
...
@@ -31,8 +31,8 @@ Also some config you need kown:
## Start
# python
ssh
_server.py
# python
run
_server.py
When your start ssh server, It will register with jumpserver api,
Then you need login jumpserver with admin user, active it in
<Terminal>
...
...
This diff is collapsed.
Click to expand it.
coco/app.py
View file @
a1217de8
...
...
@@ -150,10 +150,10 @@ class Coco:
for
s
in
self
.
sessions
:
if
not
s
.
stop_evt
.
is_set
():
continue
if
s
.
date_
finishe
d
is
None
:
if
s
.
date_
en
d
is
None
:
self
.
remove_session
(
s
)
continue
delta
=
datetime
.
datetime
.
now
()
-
s
.
date_
finishe
d
delta
=
datetime
.
datetime
.
now
()
-
s
.
date_
en
d
if
delta
>
datetime
.
timedelta
(
seconds
=
interval
*
5
):
self
.
remove_session
(
s
)
time
.
sleep
(
interval
)
...
...
This diff is collapsed.
Click to expand it.
coco/httpd.py
View file @
a1217de8
...
...
@@ -172,7 +172,7 @@ class HttpServer:
port
=
self
.
app
.
config
[
"HTTPD_PORT"
]
print
(
'Starting websocket server at {}:{}'
.
format
(
host
,
port
))
self
.
socketio
.
on_namespace
(
SSHws
(
'/ssh'
)
.
app
(
self
.
app
))
self
.
socketio
.
init_app
(
self
.
flask
)
self
.
socketio
.
init_app
(
self
.
flask
,
async_mode
=
"threading"
)
self
.
socketio
.
run
(
self
.
flask
,
port
=
port
,
host
=
host
)
def
shutdown
(
self
):
...
...
This diff is collapsed.
Click to expand it.
coco/interactive.py
View file @
a1217de8
...
...
@@ -28,7 +28,7 @@ class InteractiveServer:
self
.
client
=
client
self
.
request
=
client
.
request
self
.
assets
=
None
self
.
search_result
=
None
self
.
_
search_result
=
None
self
.
asset_groups
=
None
self
.
get_user_assets_async
()
self
.
get_user_asset_groups_async
()
...
...
@@ -37,6 +37,18 @@ class InteractiveServer:
def
app
(
self
):
return
self
.
_app
()
@property
def
search_result
(
self
):
if
self
.
_search_result
:
return
self
.
_search_result
else
:
return
None
@search_result.setter
def
search_result
(
self
,
value
):
value
=
self
.
filter_system_users
(
value
)
self
.
_search_result
=
value
def
display_banner
(
self
):
self
.
client
.
send
(
char
.
CLEAR_CHAR
)
logo_path
=
os
.
path
.
join
(
self
.
app
.
root_path
,
"logo.txt"
)
...
...
@@ -219,14 +231,13 @@ class InteractiveServer:
def
filter_system_users
(
assets
):
for
asset
in
assets
:
system_users_granted
=
asset
.
system_users_granted
high_priority
=
max
([
s
.
priority
for
s
in
system_users_granted
])
high_priority
=
max
([
s
.
priority
for
s
in
system_users_granted
])
if
system_users_granted
else
1
system_users_cleaned
=
[
s
for
s
in
system_users_granted
if
s
.
priority
==
high_priority
]
asset
.
system_users_granted
=
system_users_cleaned
return
assets
def
get_user_assets
(
self
):
assets
=
self
.
app
.
service
.
get_user_assets
(
self
.
client
.
user
)
self
.
assets
=
self
.
filter_system_users
(
assets
)
self
.
assets
=
self
.
app
.
service
.
get_user_assets
(
self
.
client
.
user
)
logger
.
debug
(
"Get user {} assets total: {}"
.
format
(
self
.
client
.
user
,
len
(
self
.
assets
)))
def
get_user_assets_async
(
self
):
...
...
This diff is collapsed.
Click to expand it.
coco/proxy.py
View file @
a1217de8
...
...
@@ -7,8 +7,8 @@ import threading
import
logging
import
time
import
weakref
import
paramiko
from
paramiko.ssh_exception
import
SSHException
from
.session
import
Session
from
.models
import
Server
...
...
@@ -130,7 +130,10 @@ class ProxyServer:
width
=
self
.
request
.
meta
.
get
(
'width'
,
80
)
height
=
self
.
request
.
meta
.
get
(
'height'
,
24
)
logger
.
debug
(
"Change win size:
%
s -
%
s"
%
(
width
,
height
))
self
.
server
.
chan
.
resize_pty
(
width
=
width
,
height
=
height
)
try
:
self
.
server
.
chan
.
resize_pty
(
width
=
width
,
height
=
height
)
except
SSHException
:
break
def
watch_win_size_change_async
(
self
):
thread
=
threading
.
Thread
(
target
=
self
.
watch_win_size_change
)
...
...
This diff is collapsed.
Click to expand it.
coco/sshd.py
View file @
a1217de8
...
...
@@ -9,6 +9,8 @@ import threading
import
paramiko
import
sys
import
time
from
.utils
import
ssh_key_gen
from
.interface
import
SSHInterface
from
.interactive
import
InteractiveServer
...
...
@@ -48,13 +50,13 @@ class SSHServer:
try
:
sock
,
addr
=
self
.
sock
.
accept
()
logger
.
info
(
"Get ssh request from {}: {}"
.
format
(
addr
[
0
],
addr
[
1
]))
thread
=
threading
.
Thread
(
target
=
self
.
handle
,
args
=
(
sock
,
addr
))
thread
=
threading
.
Thread
(
target
=
self
.
handle
_connection
,
args
=
(
sock
,
addr
))
thread
.
daemon
=
True
thread
.
start
()
except
Exception
as
e
:
logger
.
error
(
"Start SSH server error: {}"
.
format
(
e
))
def
handle
(
self
,
sock
,
addr
):
def
handle
_connection
(
self
,
sock
,
addr
):
transport
=
paramiko
.
Transport
(
sock
,
gss_kex
=
False
)
try
:
transport
.
load_server_moduli
()
...
...
@@ -73,17 +75,23 @@ class SSHServer:
logger
.
warning
(
"Handle EOF Error"
)
return
chan
=
transport
.
accept
(
10
)
if
chan
is
None
:
logger
.
warning
(
"No ssh channel get"
)
return
while
True
:
chan
=
transport
.
accept
()
if
chan
is
None
:
continue
server
.
event
.
wait
(
5
)
if
not
server
.
event
.
is_set
():
logger
.
warning
(
"Client not request a valid request, exiting"
)
return
server
.
event
.
wait
(
5
)
if
not
server
.
event
.
is_set
():
logger
.
warning
(
"Client not request a valid request, exiting"
)
return
t
=
threading
.
Thread
(
target
=
self
.
handle_chan
,
args
=
(
chan
,
request
))
t
.
daemon
=
True
t
.
start
()
def
handle_chan
(
self
,
chan
,
request
):
client
=
Client
(
chan
,
request
)
print
(
chan
)
print
(
request
)
self
.
app
.
add_client
(
client
)
self
.
dispatch
(
client
)
...
...
This diff is collapsed.
Click to expand it.
coco/tasks.py
View file @
a1217de8
# coding: utf-8
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
import
weakref
import
logging
...
...
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