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
875d2d4b
Commit
875d2d4b
authored
Jan 02, 2018
by
广宏伟
Browse files
Options
Browse Files
Download
Plain Diff
Merged in test (pull request #4)
Merge with Test
parents
c1750831
1454cdf8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
21 additions
and
177 deletions
+21
-177
httpd.py
coco/httpd.py
+9
-164
interactive.py
coco/interactive.py
+1
-4
proxy.py
coco/proxy.py
+2
-1
recorder.py
coco/recorder.py
+1
-1
session.py
coco/session.py
+6
-5
conf_docker.py
conf_docker.py
+1
-1
requirements.txt
requirements/requirements.txt
+1
-1
No files found.
coco/httpd.py
View file @
875d2d4b
...
...
@@ -32,7 +32,7 @@ class BaseWebSocketHandler:
else
:
remote_ip
=
request
.
remote_addr
self
.
clients
[
request
.
sid
][
"request"
]
=
Request
((
remote_ip
,
0
))
self
.
clients
[
request
.
sid
][
"request"
]
.
user
=
self
.
get_current_user
()
self
.
clients
[
request
.
sid
][
"request"
]
.
user
=
self
.
current_user
self
.
clients
[
request
.
sid
][
"request"
]
.
meta
=
{
"width"
:
self
.
clients
[
request
.
sid
][
"cols"
],
"height"
:
self
.
clients
[
request
.
sid
][
"rows"
]}
# self.request.__dict__.update(request.__dict__)
...
...
@@ -41,9 +41,6 @@ class BaseWebSocketHandler:
self
.
app
.
clients
.
append
(
self
.
clients
[
request
.
sid
][
"client"
])
self
.
clients
[
request
.
sid
][
"forwarder"
]
=
ProxyServer
(
self
.
app
,
self
.
clients
[
request
.
sid
][
"client"
])
def
get_current_user
(
self
):
return
User
(
id
=
'61c39c1f5b5742688180b6dda235aadd'
,
username
=
"admin"
,
name
=
"admin"
)
def
check_origin
(
self
,
origin
):
return
True
...
...
@@ -78,7 +75,8 @@ class SSHws(Namespace, BaseWebSocketHandler):
"rw"
:
[]
}
join_room
(
room
)
self
.
current_user
=
self
.
app
.
service
.
check_user_cookie
(
session_id
=
request
.
cookies
.
get
(
'sessionid'
,
''
),
csrf_token
=
request
.
cookies
.
get
(
'csrftoken'
,
''
))
self
.
prepare
(
request
)
def
on_data
(
self
,
message
):
...
...
@@ -106,13 +104,14 @@ class SSHws(Namespace, BaseWebSocketHandler):
self
.
clients
[
request
.
sid
][
"request"
]
.
meta
[
'height'
]
=
message
.
get
(
'rows'
,
24
)
self
.
clients
[
request
.
sid
][
"request"
]
.
change_size_event
.
set
()
def
on_room
(
self
,
message
):
if
message
==
'get'
:
self
.
emit
(
'
room'
,
self
.
clients
[
request
.
sid
][
"room"
]
,
room
=
self
.
clients
[
request
.
sid
][
"room"
])
el
if
message
==
'join'
:
pass
def
on_room
(
self
,
sessionid
):
if
sessionid
not
in
self
.
clients
.
keys
()
:
self
.
emit
(
'
error'
,
"no such session"
,
room
=
self
.
clients
[
request
.
sid
][
"room"
])
el
se
:
self
.
emit
(
'room'
,
self
.
clients
[
sessionid
][
"room"
],
room
=
self
.
clients
[
request
.
sid
][
"room"
])
def
on_join
(
self
,
room
):
self
.
on_leave
(
self
.
clients
[
request
.
id
][
"room"
])
self
.
clients
[
request
.
sid
][
"room"
]
=
room
self
.
rooms
[
room
][
"member"
]
.
append
(
request
.
sid
)
join_room
(
room
=
room
)
...
...
@@ -161,157 +160,3 @@ class HttpServer:
def
shutdown
(
self
):
pass
if
__name__
==
"__main__"
:
app
=
Flask
(
__name__
,
template_folder
=
'/Users/liuzheng/gitproject/Jumpserver/webterminal/dist'
)
@app.route
(
'/luna/<path:path>'
)
def
send_js
(
path
):
return
send_from_directory
(
'/Users/liuzheng/gitproject/Jumpserver/webterminal/dist'
,
path
)
@app.route
(
'/'
)
@app.route
(
'/luna/'
)
def
index
():
return
render_template
(
'index.html'
)
@app.route
(
'/api/perms/v1/user/my/asset-groups-assets/'
)
def
asset_groups_assets
():
assets
=
[
{
"id"
:
0
,
"name"
:
"ungrouped"
,
"assets"
:
[]
},
{
"id"
:
1
,
"name"
:
"Default"
,
"comment"
:
"Default asset group"
,
"assets"
:
[
{
"id"
:
2
,
"hostname"
:
"192.168.1.6"
,
"ip"
:
"192.168.2.6"
,
"port"
:
22
,
"system"
:
"windows"
,
"uuid"
:
"xxxxxx"
,
"system_users"
:
[
{
"id"
:
1
,
"name"
:
"web"
,
"username"
:
"web"
,
"protocol"
:
"ssh"
,
"auth_method"
:
"P"
,
"auto_push"
:
True
}
]
},
{
"id"
:
4
,
"hostname"
:
"testserver123"
,
"ip"
:
"123.57.183.135"
,
"port"
:
8022
,
"system"
:
"linux"
,
"uuid"
:
"linux-xxlkjadf"
,
"system_users"
:
[
{
"id"
:
1
,
"name"
:
"web"
,
"username"
:
"web"
,
"protocol"
:
"ssh"
,
"auth_method"
:
"P"
,
"auto_push"
:
True
}
]
}
]
},
{
"id"
:
4
,
"name"
:
"java"
,
"comment"
:
""
,
"assets"
:
[
{
"id"
:
2
,
"hostname"
:
"192.168.1.6"
,
"ip"
:
"192.168.2.6"
,
"uuid"
:
"sadcascas"
,
"system"
:
"linux"
,
"port"
:
22
,
"system_users"
:
[
{
"id"
:
1
,
"name"
:
"web"
,
"username"
:
"web"
,
"protocol"
:
"ssh"
,
"auth_method"
:
"P"
,
"auto_push"
:
True
}
]
}
]
},
{
"id"
:
3
,
"name"
:
"数据库"
,
"comment"
:
""
,
"assets"
:
[
{
"id"
:
2
,
"hostname"
:
"192.168.1.6"
,
"ip"
:
"192.168.2.6"
,
"port"
:
22
,
"uuid"
:
"sadcascascasdcas"
,
"system"
:
"linux"
,
"system_users"
:
[
{
"id"
:
1
,
"name"
:
"web"
,
"username"
:
"web"
,
"protocol"
:
"ssh"
,
"auth_method"
:
"P"
,
"auto_push"
:
True
}
]
}
]
},
{
"id"
:
2
,
"name"
:
"运维组"
,
"comment"
:
""
,
"assets"
:
[
{
"id"
:
2
,
"hostname"
:
"192.168.1.6"
,
"ip"
:
"192.168.2.6"
,
"port"
:
22
,
"uuid"
:
"zxcasd"
,
"system"
:
"linux"
,
"system_users"
:
[
{
"id"
:
1
,
"name"
:
"web"
,
"username"
:
"web"
,
"protocol"
:
"ssh"
,
"auth_method"
:
"P"
,
"auto_push"
:
True
}
]
}
]
}
]
return
jsonify
(
assets
)
print
(
'socketio'
)
socketio
=
SocketIO
()
socketio
.
init_app
(
app
)
socketio
.
on_namespace
(
SSHws
(
'/ssh'
))
socketio
.
run
(
app
)
coco/interactive.py
View file @
875d2d4b
...
...
@@ -53,10 +53,7 @@ class InteractiveServer:
3) 输入 {green}P/p{end} 显示您有权限的主机.
\r
4) 输入 {green}G/g{end} 显示您有权限的主机组.
\r
5) 输入 {green}G/g{end} + {green}组ID{end} 显示该组下主机. 如: g1
\r
6) 输入 {green}E/e{end} 批量执行命令.(未完成)
\r
7) 输入 {green}U/u{end} 批量上传文件.(未完成)
\r
8) 输入 {green}D/d{end} 批量下载文件.(未完成)
\r
9) 输入 {green}H/h{end} 帮助.
\r
6) 输入 {green}H/h{end} 帮助.
\r
0) 输入 {green}Q/q{end} 退出.
\r\n
"""
)
.
format
(
title
=
"
\033
[1;32m"
,
green
=
"
\033
[32m"
,
end
=
"
\033
[0m"
,
user
=
self
.
client
.
user
...
...
coco/proxy.py
View file @
875d2d4b
...
...
@@ -69,7 +69,8 @@ class ProxyServer:
def
get_server_conn
(
self
,
asset
,
system_user
):
logger
.
info
(
"Connect to {}"
.
format
(
asset
.
hostname
))
if
not
self
.
validate_permission
(
asset
,
system_user
):
self
.
client
.
send
(
warning
(
_
(
'No permission'
)))
# self.client.send(warning(_('No permission')))
self
.
client
.
send
(
warning
(
'No permission'
))
return
None
self
.
get_system_user_auth
(
system_user
)
if
True
:
...
...
coco/recorder.py
View file @
875d2d4b
...
...
@@ -128,7 +128,7 @@ class ServerReplayRecorder(ReplayRecorder):
logger
.
error
(
"Failed to push {}'s {}"
.
format
(
session_id
,
"record"
))
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'
),
return
self
.
app
.
service
.
push_session_replay
(
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay
.gz
'
),
session_id
)
def
__del__
(
self
):
...
...
coco/session.py
View file @
875d2d4b
...
...
@@ -5,6 +5,7 @@ import threading
import
uuid
import
logging
import
datetime
import
time
import
selectors
import
time
...
...
@@ -20,8 +21,8 @@ class Session:
self
.
_watchers
=
[]
# Only watch session
self
.
_sharers
=
[]
# Join to the session, read and write
self
.
replaying
=
True
self
.
date_created
=
datetime
.
datetime
.
now
()
self
.
date_
finishe
d
=
None
self
.
date_created
=
datetime
.
datetime
.
utc
now
()
self
.
date_
en
d
=
None
self
.
stop_evt
=
threading
.
Event
()
self
.
sel
=
selectors
.
DefaultSelector
()
self
.
_command_recorder
=
command_recorder
...
...
@@ -160,7 +161,7 @@ class Session:
logger
.
info
(
"Close the session: {} "
.
format
(
self
.
id
))
self
.
stop_evt
.
set
()
self
.
post_bridge
()
self
.
date_
finished
=
datetime
.
datetime
.
now
()
self
.
date_
end
=
datetime
.
datetime
.
utc
now
()
self
.
server
.
close
()
def
to_json
(
self
):
...
...
@@ -171,8 +172,8 @@ class Session:
"system_user"
:
self
.
server
.
system_user
.
username
,
"login_from"
:
"ST"
,
"is_finished"
:
True
if
self
.
stop_evt
.
is_set
()
else
False
,
"date_start"
:
self
.
date_created
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
),
"date_
finished"
:
self
.
date_finished
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
self
.
date_finishe
d
else
None
"date_start"
:
self
.
date_created
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
+
" +0000"
,
"date_
end"
:
self
.
date_end
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
+
" +0000"
if
self
.
date_en
d
else
None
}
def
__str__
(
self
):
...
...
conf_docker.py
View file @
875d2d4b
...
...
@@ -37,7 +37,7 @@ class Config:
SECRET_KEY
=
os
.
environ
.
get
(
"SECRET_KEY"
)
or
'SKdfm239LSKdfj())_23jK*^2'
# 设置日志级别 ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'CRITICAL']
LOG_LEVEL
=
os
.
environ
.
get
(
"LOG_LEVEL"
)
or
'
INFO
'
LOG_LEVEL
=
os
.
environ
.
get
(
"LOG_LEVEL"
)
or
'
DEBUG
'
# 日志存放的目录
LOG_DIR
=
os
.
environ
.
get
(
"LOG_DIR"
)
or
os
.
path
.
join
(
BASE_DIR
,
'logs'
)
...
...
requirements/requirements.txt
View file @
875d2d4b
...
...
@@ -28,4 +28,4 @@ tornado==4.5.2
urllib3==1.22
wcwidth==0.1.7
werkzeug==0.12.2
jumpserver-python-sdk==0.0.2
0
jumpserver-python-sdk==0.0.2
2
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