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
0cda4e09
Commit
0cda4e09
authored
Oct 07, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Record command history
parent
aa02c211
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
34 deletions
+50
-34
ssh_server.py
terminal/ssh_server.py
+50
-34
No files found.
terminal/ssh_server.py
View file @
0cda4e09
...
...
@@ -209,28 +209,53 @@ class Navigation:
class
ProxyChannel
:
ENTER_CHAR
=
[
'
\r
'
,
'
\n
'
,
'
\r\n
'
]
input_data
=
[]
output_data
=
[]
command
=
[]
output
=
[]
def
__init__
(
self
,
client_channel
,
backend_channel
,
client_addr
):
self
.
client_channel
=
client_channel
self
.
backend_channel
=
backend_channel
self
.
client_addr
=
client_addr
self
.
in_input_mode
=
True
def
stream_flow
(
self
,
input_
=
None
,
output_
=
None
):
if
input_
:
self
.
in_input_mode
=
True
if
input_
in
[
'
\r
'
,
'
\n
'
,
'
\r\n
'
]:
self
.
in_input_mode
=
False
if
output_
:
print
(
''
.
join
(
self
.
__class__
.
output_data
))
if
not
self
.
in_input_mode
:
command
=
''
.
join
(
self
.
__class__
.
output_data
)
del
self
.
__class__
.
output_data
self
.
__class__
.
output_data
=
[]
self
.
__class__
.
output_data
.
append
(
output_
)
self
.
is_first_input
=
True
self
.
id
=
0
# def stream_flow(self, input_=None, output_=None):
# if input_:
# self.in_input_mode = True
# if input_ in ['\r', '\n', '\r\n']:
# self.in_input_mode = False
#
# if output_:
# print(''.join(self.__class__.output_data))
# if not self.in_input_mode:
# command = ''.join(self.__class__.output_data)
# del self.__class__.output_data
# self.__class__.output_data = []
# self.__class__.output_data.append(output_)
def
get_output
(
self
):
if
self
.
in_input_mode
is
False
:
self
.
__class__
.
output_data
.
pop
()
result
=
''
.
join
(
self
.
__class__
.
output_data
)
self
.
__class__
.
output
.
append
(
result
)
print
(
'>>>>>>>>>>> output <<<<<<<<<<'
)
print
(
result
)
print
(
'>>>>>>>>>>> end output <<<<<<<<<<'
)
del
self
.
__class__
.
output_data
self
.
__class__
.
output_data
=
[]
def
get_command
(
self
,
client_data
):
if
client_data
in
self
.
__class__
.
ENTER_CHAR
:
self
.
in_input_mode
=
False
command
=
''
.
join
(
self
.
__class__
.
output_data
)
print
(
'########### command ##########'
)
self
.
__class__
.
command
.
append
(
command
)
print
(
command
)
print
(
'########### end command ##########'
)
del
self
.
__class__
.
output_data
self
.
__class__
.
output_data
=
[]
def
proxy
(
self
):
client_channel
=
self
.
client_channel
...
...
@@ -243,24 +268,17 @@ class ProxyChannel:
if
client_channel
.
change_window_size_event
.
is_set
():
backend_channel
.
resize_pty
(
width
=
client_channel
.
width
,
height
=
client_channel
.
height
)
# print(self.__class__.output)
if
client_channel
in
r
:
self
.
in_input_mode
=
True
# Get output of the command
self
.
get_output
()
client_data
=
client_channel
.
recv
(
1024
)
self
.
in_input_mode
=
True
self
.
is_first_input
=
False
if
client_data
in
self
.
__class__
.
ENTER_CHAR
:
self
.
in_input_mode
=
False
command
=
''
.
join
(
self
.
__class__
.
output_data
)
print
(
'########### command ##########'
)
print
(
command
)
print
(
'########### end command ##########'
)
del
self
.
__class__
.
output_data
self
.
__class__
.
output_data
=
[]
backend_channel
.
send
(
client_data
)
output
=
''
.
join
(
self
.
__class__
.
output_data
)
print
(
'>>>>>>>>>>> output <<<<<<<<<<'
)
print
(
output
)
print
(
'>>>>>>>>>>> end output <<<<<<<<<<'
)
continue
# Get command input
self
.
get_command
(
client_data
)
if
len
(
client_data
)
==
0
:
logger
.
info
(
'Logout from ssh server
%(host)
s:
%(username)
s'
%
{
...
...
@@ -280,7 +298,8 @@ class ProxyChannel:
'username'
:
backend_channel
.
username
,
})
break
self
.
__class__
.
output_data
.
append
(
backend_data
)
if
not
self
.
is_first_input
:
self
.
__class__
.
output_data
.
append
(
backend_data
)
client_channel
.
send
(
backend_data
)
...
...
@@ -346,9 +365,6 @@ class JumpServer:
return
backend_channel
def
command_flow
(
self
,
input_
=
None
,
output_
=
None
):
pass
def
handle_ssh_request
(
self
,
client
,
addr
):
logger
.
info
(
"Get ssh request from
%(host)
s:
%(port)
s"
%
{
'host'
:
addr
[
0
],
...
...
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