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
e6e1a489
Commit
e6e1a489
authored
Feb 27, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 文案改为中文,并且禁止登陆windows的机器
parent
24da12cc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
10 deletions
+30
-10
interactive.py
coco/interactive.py
+11
-8
proxy.py
coco/proxy.py
+1
-1
session.py
coco/session.py
+4
-0
utils.py
coco/utils.py
+13
-0
requirements.txt
requirements/requirements.txt
+1
-1
No files found.
coco/interactive.py
View file @
e6e1a489
...
...
@@ -129,7 +129,6 @@ class InteractiveServer:
input_data
.
append
(
data
)
def
dispatch
(
self
,
opt
):
print
(
repr
(
opt
))
if
opt
is
None
:
return
self
.
_sentinel
elif
opt
.
startswith
(
"/"
):
...
...
@@ -183,7 +182,7 @@ class InteractiveServer:
self
.
get_user_asset_groups
()
if
len
(
self
.
asset_groups
)
==
0
:
self
.
client
.
send
(
warning
(
_
(
"
Nothing
"
)))
self
.
client
.
send
(
warning
(
_
(
"
无
"
)))
return
fake_group
=
AssetGroup
(
name
=
_
(
"Name"
),
assets_amount
=
_
(
"Assets"
),
comment
=
_
(
"Comment"
))
...
...
@@ -197,11 +196,11 @@ class InteractiveServer:
self
.
client
.
send
(
title
(
header
.
format
(
fake_group
,
"ID"
)))
for
index
,
group
in
enumerate
(
self
.
asset_groups
,
1
):
self
.
client
.
send
(
wr
(
line
.
format
(
group
,
index
)))
self
.
client
.
send
(
wr
(
_
(
"
Total
: {}"
)
.
format
(
len
(
self
.
asset_groups
)),
before
=
1
))
self
.
client
.
send
(
wr
(
_
(
"
总共
: {}"
)
.
format
(
len
(
self
.
asset_groups
)),
before
=
1
))
def
display_group_assets
(
self
,
_id
):
if
_id
>
len
(
self
.
asset_groups
)
or
_id
<=
0
:
self
.
client
.
send
(
wr
(
warning
(
"
No matched group, select again
"
)))
self
.
client
.
send
(
wr
(
warning
(
"
没有匹配分组,请重新输入
"
)))
self
.
display_asset_groups
()
return
...
...
@@ -223,7 +222,7 @@ class InteractiveServer:
self
.
client
.
send
(
wr
(
title
(
header
.
format
(
fake_asset
,
"ID"
))))
for
index
,
asset
in
enumerate
(
self
.
search_result
,
1
):
self
.
client
.
send
(
wr
(
line
.
format
(
asset
,
index
)))
self
.
client
.
send
(
wr
(
_
(
"
Total: {} Matched
: {}"
)
.
format
(
self
.
client
.
send
(
wr
(
_
(
"
总共: {} 匹配
: {}"
)
.
format
(
len
(
self
.
assets
),
len
(
self
.
search_result
)),
before
=
1
)
)
...
...
@@ -265,7 +264,7 @@ class InteractiveServer:
return
None
while
True
:
self
.
client
.
send
(
wr
(
_
(
"
Choose one to login
: "
),
after
=
1
))
self
.
client
.
send
(
wr
(
_
(
"
选择一个登陆
: "
),
after
=
1
))
self
.
display_system_users
(
system_users
)
opt
=
self
.
get_option
(
"ID> "
)
if
opt
.
isdigit
()
and
len
(
system_users
)
>
int
(
opt
):
...
...
@@ -284,14 +283,18 @@ class InteractiveServer:
def
search_and_proxy
(
self
,
opt
):
self
.
search_assets
(
opt
)
if
self
.
search_result
and
len
(
self
.
search_result
)
==
1
:
self
.
proxy
(
self
.
search_result
[
0
])
asset
=
self
.
search_result
[
0
]
if
asset
.
platform
==
"Windows"
:
self
.
client
.
send
(
warning
(
_
(
"终端不支持登录windows, 请使用web terminal访问"
)))
return
self
.
proxy
(
asset
)
else
:
self
.
display_search_result
()
def
proxy
(
self
,
asset
):
system_user
=
self
.
choose_system_user
(
asset
.
system_users_granted
)
if
system_user
is
None
:
self
.
client
.
send
(
_
(
"
No user
"
))
self
.
client
.
send
(
_
(
"
没有系统用户
"
))
return
forwarder
=
ProxyServer
(
self
.
app
,
self
.
client
)
forwarder
.
proxy
(
asset
,
system_user
)
...
...
coco/proxy.py
View file @
e6e1a489
...
...
@@ -92,7 +92,7 @@ class ProxyServer:
timeout
=
TIMEOUT
,
compress
=
True
,
auth_timeout
=
10
,
look_for_keys
=
False
)
except
(
paramiko
.
AuthenticationException
,
paramiko
.
BadAuthenticationType
):
except
(
paramiko
.
AuthenticationException
,
paramiko
.
BadAuthenticationType
,
SSHException
):
admins
=
self
.
app
.
config
[
'ADMINS'
]
or
'administrator'
self
.
client
.
send
(
warning
(
wr
(
"Authenticate with server failed, contact {}"
.
format
(
admins
),
...
...
coco/session.py
View file @
e6e1a489
...
...
@@ -28,6 +28,7 @@ class Session:
self
.
_command_recorder
=
command_recorder
self
.
_replay_recorder
=
replay_recorder
self
.
server
.
set_session
(
self
)
self
.
date_last_active
=
datetime
.
datetime
.
utcnow
()
def
add_watcher
(
self
,
watcher
,
silent
=
False
):
"""
...
...
@@ -129,6 +130,8 @@ class Session:
logger
.
info
(
msg
)
self
.
close
()
break
self
.
date_last_active
=
datetime
.
datetime
.
utcnow
()
for
watcher
in
[
self
.
client
]
+
self
.
_watchers
+
self
.
_sharers
:
watcher
.
send
(
data
)
elif
sock
==
self
.
client
:
...
...
@@ -171,6 +174,7 @@ class Session:
"login_from"
:
"ST"
,
"remote_addr"
:
self
.
client
.
addr
[
0
],
"is_finished"
:
True
if
self
.
stop_evt
.
is_set
()
else
False
,
"date_last_active"
:
self
.
date_last_active
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
+
" +0000"
,
"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_end
else
None
}
...
...
coco/utils.py
View file @
e6e1a489
...
...
@@ -289,4 +289,17 @@ def get_logger(file_name):
return
logging
.
getLogger
(
'coco.'
+
file_name
)
zh_pattern
=
re
.
compile
(
u'[
\u4e00
-
\u9fa5
]+'
)
def
len_display
(
s
):
length
=
0
for
i
in
s
:
if
zh_pattern
.
match
(
i
):
length
+=
2
else
:
length
+=
1
return
length
ugettext
=
_gettext
()
requirements/requirements.txt
View file @
e6e1a489
...
...
@@ -30,5 +30,5 @@ tornado==4.5.2
urllib3==1.22
wcwidth==0.1.7
werkzeug==0.12.2
jumpserver-python-sdk==0.0.3
0
jumpserver-python-sdk==0.0.3
1
jms-es-sdk
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