Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
luna
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
luna
Commits
4b6f5c40
Unverified
Commit
4b6f5c40
authored
Sep 04, 2018
by
老广
Committed by
GitHub
Sep 04, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #44 from jumpserver/dev
Dev
parents
2f1d29d6
eee7a4d0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
63 deletions
+50
-63
.gitignore
.gitignore
+1
-0
mock.py
mock.py
+47
-61
environment.prod.ts
src/environments/environment.prod.ts
+2
-2
No files found.
.gitignore
View file @
4b6f5c40
...
...
@@ -45,3 +45,4 @@ Thumbs.db
publish.sh
luna.tar.gz
luna/
package-lock.json
mock.py
View file @
4b6f5c40
#!/usr/bin/env python3
import
eventlet
eventlet
.
monkey_patch
()
import
sys
import
threading
sys
.
path
.
append
(
'/Users/guang/projects/coco'
)
from
flask
import
Flask
,
send_from_directory
,
render_template
,
request
,
jsonify
,
\
redirect
,
send_file
,
abort
from
flask_socketio
import
SocketIO
,
Namespace
,
emit
,
join_room
,
leave_room
import
paramiko
import
uuid
from
threading
import
Lock
from
flask
import
Flask
,
request
,
current_app
,
redirect
import
eventlet
import
time
import
json
import
socket
import
logging
import
select
from
coco.models
import
WSProxy
,
Client
,
Request
from
coco.models
import
WSProxy
,
Client
,
Request
,
Connection
from
coco.httpd
import
ProxyNamespace
logger
=
logging
.
getLogger
(
__file__
)
...
...
@@ -26,9 +27,12 @@ logger.addHandler(sh)
logger2
=
logging
.
getLogger
(
'coco'
)
logger2
.
setLevel
(
logging
.
DEBUG
)
fmt
=
"
%(asctime)
s [
%(module)
s
%(levelname)
s]
%(message)
s"
dtfmt
=
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
fmter
=
logging
.
Formatter
(
fmt
=
fmt
,
datefmt
=
dtfmt
)
sh
.
setFormatter
(
fmter
)
logger2
.
addHandler
(
sh
)
eventlet
.
monkey_patch
()
# async_mode = 'threading'
async_mode
=
'eventlet'
...
...
@@ -36,94 +40,76 @@ app = Flask(__name__, template_folder='dist')
socketio
=
None
nodes
=
'[{"id":"03059e2e-06b8-4ef1-b949-72e230b706fa","key":"0:9:5","name":"部门1","value":"部门1","parent":"ea4688ef-2b65-40cd-944d-5fca39e34f42","assets_granted":[{"id":"ad594b10-9f64-4913-b7b1-135fe63561d1","hostname":"ali-windows","ip":"47.104.243.139","port":3389,"system_users_granted":[{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":"
"}],"is_active":true,"system_users_join":"administrator","os":null,"domain":null,"platform":"Windows","comment":""},{"id":"d9020939-1dd7-4b18-9165-5124f20d1f77","hostname":"newwindows","ip":"10.1.10.114","port":3389,"system_users_granted":[{"id":"46b57293-c662-46f9-8bc4-dcf64f01bedc","name":"newwindows","username":"administrator","priority":10,"protocol":"rdp","comment":""},{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":""}],"is_active":true,"system_users_join":"administrator, administrator","os":null,"domain":null,"platform":"Windows","comment":""},{"id":"9ef36bb3-1bed-455f-be09-3770d3f4bf97","hostname":"test-vm1","ip":"172.19.185.6","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":""}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":""},{"id":"1600ed6d-e3b6-434c-a960-c5bb818806b6","hostname":"windows1","ip":"10.1.10.178","port":3389,"system_users_granted":[{"id":"413ea1d2-ef73-4a90-bae3-571ac1b39d93","name":"2012-test-no-passwd-rdp","username":"administrator","priority":10,"protocol":"rdp","comment":""},{"id":"46b57293-c662-46f9-8bc4-dcf64f01bedc","name":"newwindows","username":"administrator","priority":10,"protocol":"rdp","comment":""},{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":""}],"is_active":true,"system_users_join":"administrator, administrator, administrator","os":null,"domain":null,"platform":"Windows","comment":""},{"id":"27e50edc-52d9-41ef-8c9e-1bff9d1628b2","hostname":"test-vm2","ip":"172.19.185.7","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":""}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":""},{"id":"b6f16269-d02a-4055-9cd8-460fa10b1540","hostname":"test-vm3","ip":"172.19.185.8","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":""}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":""},{"id":"b952a481-a624-467e-b97f-9435155f0d53","hostname":"testserver","ip":"10.1.10.192","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":""}],"is_active":true,"system_users_join":"root","os":"CentOS","domain":"8789580f-b5ca-4478-b6d3-d0dafc4c48e8","platform":"Linux","comment":""},{"id":"969247e0-3796-4090-9aa6-3248560079e6","hostname":"test01","ip":"123.123.123.1","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":""}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":""},{"id":"7e8451cb-8eb7-4c9d-b652-961a6fdce3c4","hostname":"wz-test","ip":"54.222.180.235","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":""}],"is_active":true,"system_users_join":"root","os":"RedHat","domain":null,"platform":"Linux","comment":"
"}],"assets_amount":9}]'
nodes
=
'[{"id":"03059e2e-06b8-4ef1-b949-72e230b706fa","key":"0:9:5","name":"部门1","value":"部门1","parent":"ea4688ef-2b65-40cd-944d-5fca39e34f42","assets_granted":[{"id":"ad594b10-9f64-4913-b7b1-135fe63561d1","hostname":"ali-windows","ip":"47.104.243.139","port":3389,"system_users_granted":[{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":"
windows 服务器而已"}],"is_active":true,"system_users_join":"administrator","os":null,"domain":null,"platform":"Windows","comment":"只是个windows而已"},{"id":"d9020939-1dd7-4b18-9165-5124f20d1f77","hostname":"newwindows","ip":"10.1.10.114","port":3389,"system_users_granted":[{"id":"46b57293-c662-46f9-8bc4-dcf64f01bedc","name":"newwindows","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"},{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"administrator, administrator","os":null,"domain":null,"platform":"Windows","comment":"只是个windows而已"},{"id":"9ef36bb3-1bed-455f-be09-3770d3f4bf97","hostname":"test-vm1","ip":"172.19.185.6","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":"只是个windows而已"},{"id":"1600ed6d-e3b6-434c-a960-c5bb818806b6","hostname":"windows1","ip":"10.1.10.178","port":3389,"system_users_granted":[{"id":"413ea1d2-ef73-4a90-bae3-571ac1b39d93","name":"2012-test-no-passwd-rdp","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"},{"id":"46b57293-c662-46f9-8bc4-dcf64f01bedc","name":"newwindows","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"},{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"administrator, administrator, administrator","os":null,"domain":null,"platform":"Windows","comment":"只是个windows而已"},{"id":"27e50edc-52d9-41ef-8c9e-1bff9d1628b2","hostname":"test-vm2","ip":"172.19.185.7","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":"只是个windows而已"},{"id":"b6f16269-d02a-4055-9cd8-460fa10b1540","hostname":"test-vm3","ip":"172.19.185.8","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":"只是个windows而已"},{"id":"b952a481-a624-467e-b97f-9435155f0d53","hostname":"testserver","ip":"10.1.10.192","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":"CentOS","domain":"8789580f-b5ca-4478-b6d3-d0dafc4c48e8","platform":"Linux","comment":"只是个windows而已"},{"id":"969247e0-3796-4090-9aa6-3248560079e6","hostname":"test01","ip":"123.123.123.1","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":"只是个windows而已"},{"id":"7e8451cb-8eb7-4c9d-b652-961a6fdce3c4","hostname":"wz-test","ip":"54.222.180.235","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":"RedHat","domain":null,"platform":"Linux","comment":"只是个windows而已
"}],"assets_amount":9}]'
class
Forward
er
:
def
__init__
(
self
,
client
):
class
ProxyServ
er
:
def
__init__
(
self
,
client
,
asset
,
system_user
):
self
.
client
=
client
width
=
client
.
request
.
meta
[
'width'
]
height
=
client
.
request
.
meta
[
'height'
]
self
.
server
=
self
.
ssh_with_password
(
width
,
height
)
self
.
watch_win_size_change_async
()
def
proxy
(
self
,
asset
,
system_user
):
def
proxy
(
self
):
while
True
:
r
,
w
,
x
=
select
.
select
([
self
.
server
,
self
.
client
],
[],
[])
r
,
w
,
x
=
select
.
select
([
self
.
server
,
self
.
client
,
self
.
client
.
change_size_evt
],
[],
[])
if
self
.
server
in
r
:
data
=
self
.
server
.
recv
(
1024
)
if
len
(
data
)
==
0
:
break
self
.
client
.
send
(
data
)
if
self
.
client
in
r
:
el
if
self
.
client
in
r
:
data
=
self
.
client
.
recv
(
1024
)
if
len
(
data
)
==
0
:
break
self
.
server
.
send
(
data
)
elif
self
.
client
.
change_size_evt
in
r
:
self
.
resize_win_size
()
def
watch_win_size_change_async
(
self
):
thread
=
threading
.
Thread
(
target
=
self
.
watch_win_size_change
)
thread
.
daemon
=
True
thread
.
start
()
def
resize_win_size
(
self
):
width
,
height
=
self
.
client
.
request
.
meta
[
'width'
],
\
self
.
client
.
request
.
meta
[
'height'
]
logger
.
debug
(
"Resize server chan size {}*{}"
.
format
(
width
,
height
))
self
.
server
.
resize_pty
(
width
=
width
,
height
=
height
)
def
ssh_with_password
(
self
,
width
=
80
,
height
=
24
):
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
connect
(
"192.168.244.1
28"
,
22
,
"web"
,
"redhat
"
)
ssh
.
connect
(
"192.168.244.1
77"
,
22
,
"root"
,
"redhat123
"
)
chan
=
ssh
.
invoke_shell
(
term
=
'xterm'
,
width
=
width
,
height
=
height
)
return
chan
def
watch_win_size_change
(
self
):
while
self
.
client
.
request
.
change_size_event
.
wait
():
self
.
client
.
request
.
change_size_event
.
clear
()
width
=
self
.
client
.
request
.
meta
.
get
(
'width'
,
80
)
height
=
self
.
client
.
request
.
meta
.
get
(
'height'
,
24
)
logger
.
debug
(
"Change win size:
%
s -
%
s"
%
(
width
,
height
))
try
:
self
.
server
.
resize_pty
(
width
=
width
,
height
=
height
)
# self.server.chan.resize_pty(width=width, height=height)
except
Exception
:
break
class
SSHws
(
ProxyNamespace
):
def
on_connect
(
self
):
logger
.
debug
(
"ON connect"
)
self
.
new_connection
()
def
on_host
(
self
,
message
):
# 此处获取主机的信息
logger
.
debug
(
"On host event trigger"
)
def
connect_host
(
self
,
message
):
asset_id
=
message
.
get
(
'uuid'
,
None
)
user_id
=
message
.
get
(
'userid'
,
None
)
system_
user_id
=
message
.
get
(
'userid'
,
None
)
secret
=
message
.
get
(
'secret'
,
None
)
win_size
=
message
.
get
(
'size'
,
(
80
,
24
))
req
=
self
.
make_coco_request
(
win_size
[
0
],
win_size
[
1
])
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
:
cols
,
rows
=
message
.
get
(
'size'
,
(
80
,
24
))
request
.
current_user
=
"admin"
connection
=
Connection
.
get_connection
(
request
.
sid
)
client_id
=
str
(
uuid
.
uuid4
())
client
=
connection
.
new_client
(
client_id
)
client
.
request
.
kind
=
'session'
client
.
request
.
type
=
'pty'
client
.
request
.
meta
.
update
({
'pty'
:
b
'xterm'
,
'width'
:
cols
,
'height'
:
rows
,
})
ws_proxy
=
WSProxy
(
self
,
client_id
)
client
.
chan
=
ws_proxy
self
.
emit
(
'room'
,
{
'room'
:
client_id
,
'secret'
:
secret
})
join_room
(
client_id
)
if
not
asset_id
or
not
system_user_id
:
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
()
client
=
Client
(
parent
,
room
[
"request"
])
forwarder
=
Forwarder
(
client
)
room
[
"client"
]
=
client
room
[
"forwarder"
]
=
forwarder
room
[
"proxy"
]
=
WSProxy
(
self
,
child
,
room
[
"id"
])
room
[
"cols"
],
room
[
"rows"
]
=
win_size
self
.
socketio
.
start_background_task
(
forwarder
.
proxy
,
None
,
None
)
forwarder
=
ProxyServer
(
client
,
None
,
None
)
def
proxy
():
forwarder
.
proxy
()
self
.
logout
(
client_id
,
connection
)
self
.
socketio
.
start_background_task
(
proxy
)
def
on_token
(
self
,
message
):
# 此处获取token含有的主机的信息
...
...
src/environments/environment.prod.ts
View file @
4b6f5c40
...
...
@@ -2,5 +2,5 @@ export const environment = {
production
:
true
};
// export const version = '1.3.0-{{BUILD_NUMBER}} GPLv2.';
// export const version = '1.3.3-101 GPLv2.';
export
const
version
=
'1.
3.3
-{{BUILD_NUMBER}} GPLv2.'
;
//
export const version = '1.3.3-101 GPLv2.';
export
const
version
=
'1.
4.1
-{{BUILD_NUMBER}} GPLv2.'
;
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