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
f331b447
Commit
f331b447
authored
Mar 18, 2016
by
liuzheng712
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of github.com:jumpserver/jumpserver into issue_52_bugfix
parents
c022c811
f11016f5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
28 deletions
+39
-28
connect.py
connect.py
+39
-28
No files found.
connect.py
View file @
f331b447
...
@@ -92,11 +92,20 @@ class Tty(object):
...
@@ -92,11 +92,20 @@ class Tty(object):
self
.
remote_ip
=
''
self
.
remote_ip
=
''
self
.
login_type
=
login_type
self
.
login_type
=
login_type
self
.
vim_flag
=
False
self
.
vim_flag
=
False
self
.
ps1_pattern
=
re
.
compile
(
'
\
[
.*@.*
\
]
[
\
$#]
\
s'
)
self
.
ps1_pattern
=
re
.
compile
(
'
\
[
?.*@.*
\
]?
[
\
$#]
\
s'
)
self
.
vim_pattern
=
re
.
compile
(
r'\W
vi[m]+\s.* | \W
fg\s.*'
,
re
.
X
)
self
.
vim_pattern
=
re
.
compile
(
r'\W
?vi[m]?\s.* | \W?
fg\s.*'
,
re
.
X
)
self
.
vim_data
=
''
self
.
vim_data
=
''
self
.
stream
=
pyte
.
ByteStream
()
self
.
stream
=
None
self
.
screen
=
None
self
.
screen
=
None
self
.
__init_screen_stream
()
def
__init_screen_stream
(
self
):
"""
初始化虚拟屏幕和字符流
"""
self
.
stream
=
pyte
.
ByteStream
()
self
.
screen
=
pyte
.
Screen
(
80
,
24
)
self
.
stream
.
attach
(
self
.
screen
)
@staticmethod
@staticmethod
def
is_output
(
strings
):
def
is_output
(
strings
):
...
@@ -125,30 +134,35 @@ class Tty(object):
...
@@ -125,30 +134,35 @@ class Tty(object):
result
=
match
[
-
1
]
.
strip
()
result
=
match
[
-
1
]
.
strip
()
return
result
return
result
def
deal_command
(
self
):
def
deal_command
(
self
,
data
):
"""
"""
处理截获的命令
处理截获的命令
:param data: 要处理的命令
:return:返回最后的处理结果
:return:返回最后的处理结果
"""
"""
command
=
''
command
=
''
# 从虚拟屏幕中获取处理后的数据
try
:
for
line
in
reversed
(
self
.
screen
.
buffer
):
self
.
stream
.
feed
(
data
)
line_data
=
""
.
join
(
map
(
operator
.
attrgetter
(
"data"
),
line
))
.
strip
()
# 从虚拟屏幕中获取处理后的数据
if
len
(
line_data
)
>
0
:
for
line
in
reversed
(
self
.
screen
.
buffer
):
parser_result
=
self
.
command_parser
(
line_data
)
line_data
=
""
.
join
(
map
(
operator
.
attrgetter
(
"data"
),
line
))
.
strip
()
if
parser_result
is
not
None
:
if
len
(
line_data
)
>
0
:
# 2个条件写一起会有错误的数据
parser_result
=
self
.
command_parser
(
line_data
)
if
len
(
parser_result
)
>
0
:
if
parser_result
is
not
None
:
command
=
parser_result
# 2个条件写一起会有错误的数据
else
:
if
len
(
parser_result
)
>
0
:
command
=
line_data
command
=
parser_result
break
else
:
if
command
!=
''
:
command
=
line_data
# 判断用户输入的是否是vim 或者fg命令
break
if
self
.
vim_pattern
.
search
(
command
):
if
command
!=
''
:
self
.
vim_flag
=
True
# 判断用户输入的是否是vim 或者fg命令
# 虚拟屏幕清空
if
self
.
vim_pattern
.
search
(
command
):
self
.
screen
.
reset
()
self
.
vim_flag
=
True
# 虚拟屏幕清空
self
.
screen
.
reset
()
except
Exception
:
pass
return
command
return
command
def
get_log
(
self
):
def
get_log
(
self
):
...
@@ -348,16 +362,15 @@ class SshTty(Tty):
...
@@ -348,16 +362,15 @@ class SshTty(Tty):
# 这个是用来处理用户的复制操作
# 这个是用来处理用户的复制操作
if
input_str
!=
x
:
if
input_str
!=
x
:
data
+=
input_str
data
+=
input_str
self
.
stream
.
feed
(
data
)
if
self
.
vim_flag
:
if
self
.
vim_flag
:
match
=
self
.
ps1_pattern
.
search
(
self
.
vim_data
)
match
=
self
.
ps1_pattern
.
search
(
self
.
vim_data
)
if
match
:
if
match
:
self
.
vim_flag
=
False
self
.
vim_flag
=
False
data
=
self
.
deal_command
()[
0
:
200
]
data
=
self
.
deal_command
(
data
)[
0
:
200
]
if
len
(
data
)
>
0
:
if
len
(
data
)
>
0
:
TtyLog
(
log
=
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
data
)
.
save
()
TtyLog
(
log
=
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
data
)
.
save
()
else
:
else
:
data
=
self
.
deal_command
()[
0
:
200
]
data
=
self
.
deal_command
(
data
)[
0
:
200
]
if
len
(
data
)
>
0
:
if
len
(
data
)
>
0
:
TtyLog
(
log
=
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
data
)
.
save
()
TtyLog
(
log
=
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
data
)
.
save
()
data
=
''
data
=
''
...
@@ -393,10 +406,8 @@ class SshTty(Tty):
...
@@ -393,10 +406,8 @@ class SshTty(Tty):
# 获取连接的隧道并设置窗口大小 Make a channel and set windows size
# 获取连接的隧道并设置窗口大小 Make a channel and set windows size
global
channel
global
channel
win_size
=
self
.
get_win_size
()
win_size
=
self
.
get_win_size
()
#self.channel = channel = ssh.invoke_shell(height=win_size[0], width=win_size[1], term='xterm')
#
self.channel = channel = ssh.invoke_shell(height=win_size[0], width=win_size[1], term='xterm')
self
.
channel
=
channel
=
transport
.
open_session
()
self
.
channel
=
channel
=
transport
.
open_session
()
self
.
screen
=
pyte
.
Screen
(
win_size
[
1
],
win_size
[
0
])
self
.
stream
.
attach
(
self
.
screen
)
channel
.
get_pty
(
term
=
'xterm'
,
height
=
win_size
[
0
],
width
=
win_size
[
1
])
channel
.
get_pty
(
term
=
'xterm'
,
height
=
win_size
[
0
],
width
=
win_size
[
1
])
channel
.
invoke_shell
()
channel
.
invoke_shell
()
try
:
try
:
...
...
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