Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
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
jumpserver
Commits
b4c64991
Commit
b4c64991
authored
Sep 29, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try to fix ssh server close client bug
parent
e3c620e1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
30 deletions
+32
-30
ssh_server.py
terminal/ssh_server.py
+32
-30
No files found.
terminal/ssh_server.py
View file @
b4c64991
...
@@ -81,27 +81,6 @@ class SSHServer(paramiko.ServerInterface):
...
@@ -81,27 +81,6 @@ class SSHServer(paramiko.ServerInterface):
return
paramiko
.
OPEN_SUCCEEDED
return
paramiko
.
OPEN_SUCCEEDED
return
paramiko
.
OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
return
paramiko
.
OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
def
check_auth_gssapi_with_mic
(
self
,
username
,
gss_authenticated
=
paramiko
.
AUTH_FAILED
,
cc_file
=
None
):
if
gss_authenticated
==
paramiko
.
AUTH_SUCCESSFUL
:
return
paramiko
.
AUTH_SUCCESSFUL
return
paramiko
.
AUTH_FAILED
def
check_auth_gssapi_keyex
(
self
,
username
,
gss_authenticated
=
paramiko
.
AUTH_FAILED
,
cc_file
=
None
):
if
gss_authenticated
==
paramiko
.
AUTH_SUCCESSFUL
:
return
paramiko
.
AUTH_SUCCESSFUL
return
paramiko
.
AUTH_FAILED
def
enable_auth_gssapi
(
self
):
UseGSSAPI
=
True
GSSAPICleanupCredentials
=
False
return
UseGSSAPI
def
check_auth_password
(
self
,
username
,
password
):
def
check_auth_password
(
self
,
username
,
password
):
self
.
user
=
user
=
check_user_is_valid
(
username
=
username
,
password
=
password
)
self
.
user
=
user
=
check_user_is_valid
(
username
=
username
,
password
=
password
)
if
self
.
user
:
if
self
.
user
:
...
@@ -153,7 +132,6 @@ class SSHServer(paramiko.ServerInterface):
...
@@ -153,7 +132,6 @@ class SSHServer(paramiko.ServerInterface):
self
.
__class__
.
channel_pools
.
append
(
channel
)
self
.
__class__
.
channel_pools
.
append
(
channel
)
channel
.
username
=
self
.
username
channel
.
username
=
self
.
username
channel
.
addr
=
self
.
addr
channel
.
addr
=
self
.
addr
return
True
return
True
def
check_channel_pty_request
(
self
,
channel
,
term
,
width
,
height
,
pixelwidth
,
def
check_channel_pty_request
(
self
,
channel
,
term
,
width
,
height
,
pixelwidth
,
...
@@ -181,8 +159,14 @@ class BackendServer:
...
@@ -181,8 +159,14 @@ class BackendServer:
def
connect
(
self
,
term
=
'xterm'
,
width
=
80
,
height
=
24
,
timeout
=
10
):
def
connect
(
self
,
term
=
'xterm'
,
width
=
80
,
height
=
24
,
timeout
=
10
):
self
.
ssh
=
ssh
=
paramiko
.
SSHClient
()
self
.
ssh
=
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
connect
(
hostname
=
self
.
host
,
port
=
self
.
port
,
username
=
self
.
username
,
password
=
self
.
host_password
,
pkey
=
self
.
host_private_key
,
look_for_keys
=
False
,
allow_agent
=
True
,
compress
=
True
,
timeout
=
timeout
)
try
:
ssh
.
connect
(
hostname
=
self
.
host
,
port
=
self
.
port
,
username
=
self
.
username
,
password
=
self
.
host_password
,
pkey
=
self
.
host_private_key
,
look_for_keys
=
False
,
allow_agent
=
True
,
compress
=
True
,
timeout
=
timeout
)
except
Exception
:
logger
.
warning
(
'Connect backend server
%
s failed'
%
self
.
host
)
return
None
self
.
channel
=
channel
=
ssh
.
invoke_shell
(
term
=
term
,
width
=
width
,
height
=
height
)
self
.
channel
=
channel
=
ssh
.
invoke_shell
(
term
=
term
,
width
=
width
,
height
=
height
)
logger
.
info
(
'Connect backend server
%(username)
s@
%(host)
s:
%(port)
s successfully'
%
{
logger
.
info
(
'Connect backend server
%(username)
s@
%(host)
s:
%(port)
s successfully'
%
{
'username'
:
self
.
username
,
'username'
:
self
.
username
,
...
@@ -260,12 +244,11 @@ class JumpServer:
...
@@ -260,12 +244,11 @@ class JumpServer:
logger
.
warning
(
'SSH negotiation failed.'
)
logger
.
warning
(
'SSH negotiation failed.'
)
client_channel
=
transport
.
accept
(
20
)
client_channel
=
transport
.
accept
(
20
)
self
.
__class__
.
client_channel_pools
.
append
(
client_channel
)
if
client_channel
is
None
:
if
client_channel
is
None
:
logger
.
warning
(
'No ssh channel get.'
)
logger
.
warning
(
'No ssh channel get.'
)
client
.
close
()
return
None
sys
.
exit
(
404
)
self
.
__class__
.
client_channel_pools
.
append
(
client_channel
)
if
not
ssh_server
.
event
.
is_set
():
if
not
ssh_server
.
event
.
is_set
():
logger
.
warning
(
'Client never asked for a shell.'
)
logger
.
warning
(
'Client never asked for a shell.'
)
return
client_channel
return
client_channel
...
@@ -273,14 +256,17 @@ class JumpServer:
...
@@ -273,14 +256,17 @@ class JumpServer:
def
get_backend_channel
(
self
,
host
,
port
,
username
,
term
=
'xterm'
,
width
=
80
,
height
=
24
):
def
get_backend_channel
(
self
,
host
,
port
,
username
,
term
=
'xterm'
,
width
=
80
,
height
=
24
):
backend_server
=
BackendServer
(
host
,
port
,
username
)
backend_server
=
BackendServer
(
host
,
port
,
username
)
backend_channel
=
backend_server
.
connect
(
term
=
term
,
width
=
width
,
height
=
height
)
backend_channel
=
backend_server
.
connect
(
term
=
term
,
width
=
width
,
height
=
height
)
self
.
__class__
.
backend_server_pools
.
append
(
backend_server
)
self
.
__class__
.
backend_channel_pools
.
append
(
backend_channel
)
if
backend_channel
is
None
:
if
not
backend_channel
:
logger
.
warning
(
'Connect
%(username)
s@
%(host)
s:
%(port)
s failed'
%
{
logger
.
warning
(
'Connect
%(username)
s@
%(host)
s:
%(port)
s failed'
%
{
'username'
:
username
,
'username'
:
username
,
'host'
:
host
,
'host'
:
host
,
'port'
:
port
,
'port'
:
port
,
})
})
return
None
self
.
__class__
.
backend_server_pools
.
append
(
backend_server
)
self
.
__class__
.
backend_channel_pools
.
append
(
backend_channel
)
return
backend_channel
return
backend_channel
...
@@ -289,12 +275,28 @@ class JumpServer:
...
@@ -289,12 +275,28 @@ class JumpServer:
'host'
:
addr
[
0
],
'host'
:
addr
[
0
],
'port'
:
addr
[
1
],
'port'
:
addr
[
1
],
})
})
raise
IndexError
dir
(
client
)
client
.
close
()
return
False
try
:
try
:
client_channel
=
self
.
get_client_channel
(
client
,
addr
)
client_channel
=
self
.
get_client_channel
(
client
,
addr
)
if
client_channel
is
None
:
client
.
close
()
return
host
,
port
,
username
=
self
.
display_navigation
(
'root'
,
client_channel
)
host
,
port
,
username
=
self
.
display_navigation
(
'root'
,
client_channel
)
backend_channel
=
self
.
get_backend_channel
(
host
,
port
,
username
,
backend_channel
=
self
.
get_backend_channel
(
host
,
port
,
username
,
width
=
client_channel
.
width
,
width
=
client_channel
.
width
,
height
=
client_channel
.
height
)
height
=
client_channel
.
height
)
if
backend_channel
is
None
:
client
.
shutdown
()
client
.
close
()
client
.
send
(
'Close'
)
print
(
client
)
print
(
dir
(
client
))
return
while
True
:
while
True
:
r
,
w
,
x
=
select
.
select
([
client_channel
,
backend_channel
],
[],
[])
r
,
w
,
x
=
select
.
select
([
client_channel
,
backend_channel
],
[],
[])
...
...
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