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
50645630
Commit
50645630
authored
May 09, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改coco,如果system user没有密码需要用户交互输入
parent
3cdb78ef
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
27 deletions
+80
-27
connection.py
coco/connection.py
+0
-9
httpd.py
coco/httpd.py
+0
-6
models.py
coco/models.py
+1
-0
proxy.py
coco/proxy.py
+15
-1
utils.py
coco/utils.py
+63
-10
requirements.txt
requirements/requirements.txt
+1
-1
No files found.
coco/connection.py
View file @
50645630
...
...
@@ -26,7 +26,6 @@ class SSHConnection:
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
sock
=
None
self
.
get_system_user_auth
(
system_user
)
if
asset
.
domain
:
sock
=
self
.
get_proxy_sock
(
asset
)
...
...
@@ -83,14 +82,6 @@ class SSHConnection:
else
:
return
None
,
msg
def
get_system_user_auth
(
self
,
system_user
):
"""
获取系统用户的认证信息,密码或秘钥
:return: system user have full info
"""
system_user
.
password
,
system_user
.
private_key
=
\
self
.
app
.
service
.
get_system_user_auth_info
(
system_user
)
def
get_proxy_sock
(
self
,
asset
):
sock
=
None
domain
=
self
.
app
.
service
.
get_domain_detail_with_gateway
(
...
...
coco/httpd.py
View file @
50645630
...
...
@@ -184,12 +184,6 @@ class ProxyNamespace(BaseNamespace):
self
.
clients
[
request
.
sid
][
"request"
]
.
user
=
self
.
current_user
logger
.
debug
(
self
.
current_user
)
# {
# "user": {UUID},
# "asset": {UUID},
# "system_user": {UUID}
# }
self
.
on_host
({
'secret'
:
secret
,
'uuid'
:
host
[
'asset'
],
'userid'
:
host
[
'system_user'
]})
def
on_resize
(
self
,
message
):
...
...
coco/models.py
View file @
50645630
...
...
@@ -263,6 +263,7 @@ class WSProxy:
def
close
(
self
):
self
.
stop_event
.
set
()
self
.
child
.
shutdown
(
1
)
self
.
child
.
close
()
self
.
ws
.
logout
(
self
.
connection
)
logger
.
debug
(
"Proxy {} closed"
.
format
(
self
))
...
...
coco/proxy.py
View file @
50645630
...
...
@@ -12,7 +12,7 @@ from .session import Session
from
.models
import
Server
from
.connection
import
SSHConnection
from
.utils
import
wrap_with_line_feed
as
wr
,
wrap_with_warning
as
warning
,
\
get_logger
get_logger
,
net_input
logger
=
get_logger
(
__file__
)
...
...
@@ -32,7 +32,21 @@ class ProxyServer:
def
app
(
self
):
return
self
.
_app
()
def
get_system_user_auth
(
self
,
system_user
):
"""
获取系统用户的认证信息,密码或秘钥
:return: system user have full info
"""
password
,
private_key
=
\
self
.
app
.
service
.
get_system_user_auth_info
(
system_user
)
if
not
password
and
not
private_key
:
prompt
=
"{}'s password: "
.
format
(
system_user
.
username
)
password
=
net_input
(
self
.
client
,
prompt
=
prompt
,
sensitive
=
True
)
system_user
.
password
=
password
system_user
.
private_key
=
private_key
def
proxy
(
self
,
asset
,
system_user
):
self
.
get_system_user_auth
(
system_user
)
self
.
send_connecting_message
(
asset
,
system_user
)
self
.
server
=
self
.
get_server_conn
(
asset
,
system_user
)
if
self
.
server
is
None
:
...
...
coco/utils.py
View file @
50645630
...
...
@@ -4,26 +4,17 @@
from
__future__
import
unicode_literals
import
hashlib
import
logging
import
re
import
os
import
threading
import
base64
import
calendar
import
time
import
datetime
import
gettext
from
io
import
StringIO
from
binascii
import
hexlify
import
paramiko
import
pyte
import
pytz
from
email.utils
import
formatdate
from
queue
import
Queue
,
Empty
from
.
exception
import
NoAppException
from
.
import
char
BASE_DIR
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
)))
...
...
@@ -302,4 +293,66 @@ def len_display(s):
return
length
def
net_input
(
client
,
prompt
=
'Opt> '
,
sensitive
=
False
):
"""实现了一个ssh input, 提示用户输入, 获取并返回
:return user input string
"""
input_data
=
[]
parser
=
TtyIOParser
()
client
.
send
(
wrap_with_line_feed
(
prompt
,
before
=
0
,
after
=
0
))
while
True
:
data
=
client
.
recv
(
10
)
if
len
(
data
)
==
0
:
break
# Client input backspace
if
data
in
char
.
BACKSPACE_CHAR
:
# If input words less than 0, should send 'BELL'
if
len
(
input_data
)
>
0
:
data
=
char
.
BACKSPACE_CHAR
[
data
]
input_data
.
pop
()
else
:
data
=
char
.
BELL_CHAR
client
.
send
(
data
)
continue
if
data
.
startswith
(
b
'
\x03
'
):
# Ctrl-C
client
.
send
(
'^C
\r\n
{} '
.
format
(
prompt
)
.
encode
())
input_data
=
[]
continue
elif
data
.
startswith
(
b
'
\x04
'
):
# Ctrl-D
return
'q'
# Todo: Move x1b to char
if
data
.
startswith
(
b
'
\x1b
'
)
or
data
in
char
.
UNSUPPORTED_CHAR
:
client
.
send
(
b
''
)
continue
# handle shell expect
multi_char_with_enter
=
False
if
len
(
data
)
>
1
and
data
[
-
1
]
in
char
.
ENTER_CHAR_ORDER
:
if
sensitive
:
client
.
send
(
len
(
data
)
*
'*'
)
else
:
client
.
send
(
data
)
input_data
.
append
(
data
[:
-
1
])
multi_char_with_enter
=
True
# If user type ENTER we should get user input
if
data
in
char
.
ENTER_CHAR
or
multi_char_with_enter
:
client
.
send
(
wrap_with_line_feed
(
b
''
,
after
=
2
))
option
=
parser
.
parse_input
(
input_data
)
del
input_data
[:]
return
option
.
strip
()
else
:
if
sensitive
:
client
.
send
(
len
(
data
)
*
'*'
)
else
:
client
.
send
(
data
)
input_data
.
append
(
data
)
ugettext
=
_gettext
()
requirements/requirements.txt
View file @
50645630
...
...
@@ -30,7 +30,7 @@ pycparser==2.18
PyNaCl==1.2.1
pyte==0.7.0
python-dateutil==2.6.1
python-engineio==2.
0.1
python-engineio==2.
1.0
python-gssapi==0.6.4
python-socketio==1.8.3
pytz==2017.3
...
...
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