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
47fc4b67
Unverified
Commit
47fc4b67
authored
Jul 25, 2019
by
老广
Committed by
GitHub
Jul 25, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #253 from jumpserver/dev
Dev
parents
97d80e61
82c5de1c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
11 deletions
+31
-11
connection.py
coco/connection.py
+6
-2
const.py
coco/const.py
+6
-0
proxy.py
coco/proxy.py
+9
-6
sftp.py
coco/sftp.py
+9
-3
sshd.py
coco/sshd.py
+1
-0
No files found.
coco/connection.py
View file @
47fc4b67
...
...
@@ -4,6 +4,8 @@
import
re
import
socket
import
telnetlib
from
.const
import
MANUAL_LOGIN
try
:
import
selectors
...
...
@@ -87,6 +89,8 @@ class SSHConnection:
获取系统用户的认证信息,密码或秘钥
:return: system user have full info
"""
if
self
.
system_user
.
login_mode
==
MANUAL_LOGIN
:
return
password
,
private_key
=
\
app_service
.
get_system_user_auth_info
(
self
.
system_user
,
self
.
asset
)
self
.
system_user
.
password
=
password
...
...
@@ -127,7 +131,7 @@ class SSHConnection:
look_for_keys
=
False
,
sock
=
sock
,
allow_agent
=
False
,
)
transport
=
ssh
.
get_transport
()
transport
.
set_keepalive
(
2
0
)
transport
.
set_keepalive
(
6
0
)
self
.
transport
=
transport
except
Exception
as
e
:
password_short
=
"None"
...
...
@@ -227,7 +231,7 @@ class SSHConnection:
continue
try
:
transport
=
ssh
.
get_transport
()
transport
.
set_keepalive
(
2
0
)
transport
.
set_keepalive
(
6
0
)
sock
=
transport
.
open_channel
(
'direct-tcpip'
,
(
asset
.
ip
,
asset
.
ssh_port
),
(
'127.0.0.1'
,
0
)
)
...
...
coco/const.py
View file @
47fc4b67
...
...
@@ -8,3 +8,9 @@ PERMS_ACTION_NAME_ALL = 'all'
PERMS_ACTION_NAME_CONNECT
=
'connect'
PERMS_ACTION_NAME_UPLOAD_FILE
=
'upload_file'
PERMS_ACTION_NAME_DOWNLOAD_FILE
=
'download_file'
#
# System User login mode choices
#
MANUAL_LOGIN
=
'manual'
AUTO_LOGIN
=
'auto'
coco/proxy.py
View file @
47fc4b67
...
...
@@ -4,28 +4,31 @@
import
threading
import
time
import
copy
from
.session
import
Session
from
.models
import
Server
,
TelnetServer
from
.const
import
PERMS_ACTION_NAME_CONNECT
from
.const
import
(
PERMS_ACTION_NAME_CONNECT
,
MANUAL_LOGIN
)
from
.connection
import
SSHConnection
,
TelnetConnection
from
.service
import
app_service
from
.conf
import
config
from
.utils
import
wrap_with_line_feed
as
wr
,
wrap_with_warning
as
warning
,
\
get_logger
,
net_input
,
ugettext
as
_
,
ignore_error
from
.utils
import
(
wrap_with_line_feed
as
wr
,
wrap_with_warning
as
warning
,
ugettext
as
_
,
get_logger
,
net_input
,
ignore_error
)
logger
=
get_logger
(
__file__
)
BUF_SIZE
=
4096
MANUAL_LOGIN
=
'manual'
AUTO_LOGIN
=
'auto'
class
ProxyServer
:
def
__init__
(
self
,
client
,
asset
,
system_user
):
self
.
client
=
client
self
.
asset
=
asset
self
.
system_user
=
system_user
self
.
system_user
=
copy
.
deepcopy
(
system_user
)
self
.
server
=
None
self
.
connecting
=
True
...
...
coco/sftp.py
View file @
47fc4b67
...
...
@@ -14,6 +14,7 @@ from .connection import SSHConnection
from
.interactive
import
InteractiveServer
from
.const
import
(
PERMS_ACTION_NAME_DOWNLOAD_FILE
,
PERMS_ACTION_NAME_UPLOAD_FILE
,
MANUAL_LOGIN
,
)
CURRENT_DIR
=
os
.
path
.
dirname
(
__file__
)
...
...
@@ -119,7 +120,9 @@ class SFTPServer(paramiko.SFTPServerInterface):
raise
PermissionError
(
"No asset or system user explicit"
)
cache_key
=
'{}@{}'
.
format
(
su
,
host
)
if
cache_key
not
in
self
.
_sftp
:
if
cache_key
in
self
.
_sftp
:
return
self
.
_sftp
[
cache_key
]
conn
=
SSHConnection
.
new_connection
(
self
.
server
.
connection
.
user
,
asset
,
system_user
)
__sftp
=
conn
.
get_sftp
()
...
...
@@ -130,10 +133,13 @@ class SFTPServer(paramiko.SFTPServerInterface):
}
self
.
_sftp
[
cache_key
]
=
sftp
return
sftp
elif
system_user
.
login_mode
==
MANUAL_LOGIN
:
raise
PermissionError
(
"System user is in manual login mode, "
"please use SSH protocol to connect assets first."
)
else
:
raise
OSError
(
"Can not connect asset sftp server: {}"
.
format
(
conn
.
error
))
else
:
return
self
.
_sftp
[
cache_key
]
def
host_has_unique_su
(
self
,
host
):
host_sus
=
self
.
get_host_system_users
(
host
,
only_name
=
True
)
...
...
coco/sshd.py
View file @
47fc4b67
...
...
@@ -77,6 +77,7 @@ class SSHServer:
server
=
SSHInterface
(
connection
)
try
:
transport
.
start_server
(
server
=
server
)
transport
.
set_keepalive
(
60
)
while
transport
.
is_active
():
chan
=
transport
.
accept
()
server
.
event
.
wait
(
5
)
...
...
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