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
b17a1266
Commit
b17a1266
authored
Sep 26, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify change windows size
parent
be1a374b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
4 deletions
+38
-4
ssh_server.py
terminal/ssh_server.py
+23
-4
utils.py
terminal/utils.py
+15
-0
No files found.
terminal/ssh_server.py
View file @
b17a1266
...
...
@@ -36,7 +36,7 @@ except IndexError:
from
django.conf
import
settings
from
users.utils
import
ssh_key_gen
,
check_user_is_valid
from
utils
import
get_logger
,
SSHServerException
from
utils
import
get_logger
,
SSHServerException
,
control_char
logger
=
get_logger
(
__name__
)
...
...
@@ -48,6 +48,7 @@ class SSHServer(paramiko.ServerInterface):
def
__init__
(
self
,
client
,
addr
):
self
.
event
=
threading
.
Event
()
self
.
change_window_size_event
=
threading
.
Event
()
self
.
client
=
client
self
.
addr
=
addr
self
.
username
=
None
...
...
@@ -133,9 +134,15 @@ class SSHServer(paramiko.ServerInterface):
def
check_channel_pty_request
(
self
,
channel
,
term
,
width
,
height
,
pixelwidth
,
pixelheight
,
modes
):
channel
.
change_window_size_event
=
threading
.
Event
()
channel
.
width
=
width
channel
.
height
=
height
return
True
def
check_channel_window_change_request
(
self
,
channel
,
width
,
height
,
pixelwidth
,
pixelheight
):
channel
.
change_window_size_event
.
set
()
channel
.
width
=
width
channel
.
height
=
height
return
True
...
...
@@ -180,6 +187,7 @@ class Navigation:
def
display_banner
(
self
):
client_channel
=
self
.
client_channel
client_channel
.
send
(
control_char
.
clear
)
client_channel
.
send
(
'
\r\n\r\n\t\t
Welcome to use Jumpserver open source system !
\r\n\r\n
'
)
client_channel
.
send
(
'If you find some bug please contact us <ibuler@qq.com>
\r\n
'
)
client_channel
.
send
(
'See more at https://www.jumpserver.org
\r\n
'
)
...
...
@@ -197,6 +205,10 @@ class JumpServer:
backend_channel_pools
=
[]
client_channel_pools
=
[]
CONTROL_CHAR
=
{
'clear'
:
''
}
def
__init__
(
self
):
self
.
listen_host
=
'0.0.0.0'
self
.
listen_port
=
2222
...
...
@@ -235,9 +247,9 @@ class JumpServer:
raise
SSHServerException
(
'Client never asked for a shell.'
)
return
client_channel
def
get_backend_channel
(
self
,
host
,
port
,
username
):
def
get_backend_channel
(
self
,
host
,
port
,
username
,
term
=
'xterm'
,
width
=
80
,
height
=
24
):
backend_server
=
BackendServer
(
host
,
port
,
username
)
backend_channel
=
backend_server
.
connect
()
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
not
backend_channel
:
...
...
@@ -257,11 +269,16 @@ class JumpServer:
try
:
client_channel
=
self
.
get_client_channel
(
client
,
addr
)
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
,
height
=
client_channel
.
height
)
while
True
:
r
,
w
,
x
=
select
.
select
([
client_channel
,
backend_channel
],
[],
[])
if
client_channel
.
change_window_size_event
.
is_set
():
backend_channel
.
resize_pty
(
width
=
client_channel
.
width
,
height
=
client_channel
.
height
)
if
client_channel
in
r
:
client_data
=
client_channel
.
recv
(
1024
)
if
len
(
client_data
)
==
0
:
...
...
@@ -270,6 +287,7 @@ class JumpServer:
'username'
:
client_channel
.
username
,
})
break
print
(
'CC: '
+
repr
(
client_data
))
backend_channel
.
send
(
client_data
)
if
backend_channel
in
r
:
...
...
@@ -282,6 +300,7 @@ class JumpServer:
'username'
:
backend_channel
.
username
,
})
break
print
(
'SS: '
+
repr
(
backend_data
))
client_channel
.
send
(
backend_data
)
# if len(recv_data) > 20:
...
...
terminal/utils.py
View file @
b17a1266
...
...
@@ -15,5 +15,20 @@ def get_logger(name):
return
logging
.
getLogger
(
'jumpserver.
%
s'
%
name
)
class
ControlChar
:
CHARS
=
{
'clear'
:
'
\x1b
[H
\x1b
[2J'
,
}
def
__init__
(
self
):
pass
def
__getattr__
(
self
,
item
):
return
self
.
__class__
.
CHARS
.
get
(
item
,
''
)
class
SSHServerException
(
Exception
):
pass
control_char
=
ControlChar
()
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