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
3d0b8917
Commit
3d0b8917
authored
Dec 06, 2015
by
kelianchun_miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update connect.py
parent
35c818f4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
33 deletions
+48
-33
connect.py
connect.py
+48
-33
No files found.
connect.py
View file @
3d0b8917
...
@@ -104,6 +104,41 @@ class Tty(object):
...
@@ -104,6 +104,41 @@ class Tty(object):
cmd_str
=
patch_char
.
sub
(
''
,
cmd_str
.
rstrip
())
cmd_str
=
patch_char
.
sub
(
''
,
cmd_str
.
rstrip
())
return
cmd_str
return
cmd_str
@staticmethod
def
deal_backspace
(
match_str
,
result_command
,
pattern_str
,
backspace_num
):
'''
处理删除确认键
'''
if
backspace_num
>
0
:
if
backspace_num
>
len
(
result_command
):
result_command
+=
pattern_str
result_command
=
result_command
[
0
:
-
backspace_num
]
else
:
result_command
=
result_command
[
0
:
-
backspace_num
]
result_command
+=
pattern_str
del_len
=
len
(
match_str
)
-
3
if
del_len
>
0
:
result_command
=
result_command
[
0
:
-
del_len
]
return
result_command
,
len
(
match_str
)
@staticmethod
def
deal_replace_char
(
match_str
,
result_command
,
backspace_num
):
'''
处理替换命令
'''
str_lists
=
re
.
findall
(
r'(?<=\x1b\[1@)\w'
,
match_str
)
tmp_str
=
''
.
join
(
str_lists
)
result_command_list
=
list
(
result_command
)
if
len
(
tmp_str
)
>
1
:
result_command_list
[
-
backspace_num
:
-
(
backspace_num
-
len
(
tmp_str
))]
=
tmp_str
elif
len
(
tmp_str
)
>
0
:
if
result_command_list
[
-
backspace_num
]
==
' '
:
result_command_list
.
insert
(
-
backspace_num
,
tmp_str
)
else
:
result_command_list
[
-
backspace_num
]
=
tmp_str
result_command
=
''
.
join
(
result_command_list
)
return
result_command
,
len
(
match_str
)
def
remove_control_char
(
self
,
result_command
):
def
remove_control_char
(
self
,
result_command
):
"""
"""
处理日志特殊字符
处理日志特殊字符
...
@@ -130,10 +165,7 @@ class Tty(object):
...
@@ -130,10 +165,7 @@ class Tty(object):
"""
"""
处理命令中特殊字符
处理命令中特殊字符
"""
"""
str_r
=
re
.
sub
(
'
\x07
'
,
''
,
str_r
)
# 删除响铃
str_r
=
self
.
remove_obstruct_char
(
str_r
)
patch_char
=
re
.
compile
(
'
\x08\x1b
\
[C'
)
# 删除方向左右一起的按键
while
patch_char
.
search
(
str_r
):
str_r
=
patch_char
.
sub
(
''
,
str_r
.
rstrip
())
result_command
=
''
# 最后的结果
result_command
=
''
# 最后的结果
backspace_num
=
0
# 光标移动的个数
backspace_num
=
0
# 光标移动的个数
...
@@ -142,31 +174,21 @@ class Tty(object):
...
@@ -142,31 +174,21 @@ class Tty(object):
while
str_r
:
while
str_r
:
tmp
=
re
.
match
(
r'\s*\w+\s*'
,
str_r
)
tmp
=
re
.
match
(
r'\s*\w+\s*'
,
str_r
)
if
tmp
:
if
tmp
:
str_r
=
str_r
[
len
(
str
(
tmp
.
group
(
0
))):]
if
reach_backspace_flag
:
if
reach_backspace_flag
:
pattern_str
+=
str
(
tmp
.
group
(
0
))
pattern_str
+=
str
(
tmp
.
group
(
0
))
str_r
=
str_r
[
len
(
str
(
tmp
.
group
(
0
))):]
continue
continue
else
:
else
:
result_command
+=
str
(
tmp
.
group
(
0
))
result_command
+=
str
(
tmp
.
group
(
0
))
str_r
=
str_r
[
len
(
str
(
tmp
.
group
(
0
))):]
continue
continue
tmp
=
re
.
match
(
r'\x1b\[K[\x08]*'
,
str_r
)
tmp
=
re
.
match
(
r'\x1b\[K[\x08]*'
,
str_r
)
if
tmp
:
if
tmp
:
if
backspace_num
>
0
:
result_command
,
del_len
=
self
.
deal_backspace
(
str
(
tmp
.
group
(
0
)),
result_command
,
pattern_str
,
backspace_num
)
if
backspace_num
>
len
(
result_command
):
result_command
+=
pattern_str
result_command
=
result_command
[
0
:
-
backspace_num
]
else
:
result_command
=
result_command
[
0
:
-
backspace_num
]
result_command
+=
pattern_str
del_len
=
len
(
str
(
tmp
.
group
(
0
)))
-
3
if
del_len
>
0
:
result_command
=
result_command
[
0
:
-
del_len
]
reach_backspace_flag
=
False
reach_backspace_flag
=
False
backspace_num
=
0
backspace_num
=
0
pattern_str
=
''
pattern_str
=
''
str_r
=
str_r
[
len
(
str
(
tmp
.
group
(
0
)))
:]
str_r
=
str_r
[
del_len
:]
continue
continue
tmp
=
re
.
match
(
r'\x08+'
,
str_r
)
tmp
=
re
.
match
(
r'\x08+'
,
str_r
)
...
@@ -183,6 +205,13 @@ class Tty(object):
...
@@ -183,6 +205,13 @@ class Tty(object):
else
:
else
:
break
break
tmp
=
re
.
match
(
r'(\x1b\[1@\w)+'
,
str_r
)
#处理替换的命令
if
tmp
:
result_command
,
del_len
=
self
.
deal_replace_char
(
str
(
tmp
.
group
(
0
)),
result_command
,
backspace_num
)
str_r
=
str_r
[
del_len
:]
backspace_num
=
0
continue
if
reach_backspace_flag
:
if
reach_backspace_flag
:
pattern_str
+=
str_r
[
0
]
pattern_str
+=
str_r
[
0
]
else
:
else
:
...
@@ -192,22 +221,8 @@ class Tty(object):
...
@@ -192,22 +221,8 @@ class Tty(object):
if
backspace_num
>
0
:
if
backspace_num
>
0
:
result_command
=
result_command
[
0
:
-
backspace_num
]
+
pattern_str
result_command
=
result_command
[
0
:
-
backspace_num
]
+
pattern_str
control_char
=
re
.
compile
(
r"""
result_command
=
self
.
remove_control_char
(
result_command
)
\x1b[ #
%
()*+\-.\/]. |
return
result_command
\r | #匹配 回车符(CR)
(?:\x1b\[|\x9b) [ -?]* [@-~] | #匹配 控制顺序描述符(CSI)... Cmd
(?:\x1b\]|\x9d) .*? (?:\x1b\\|[\a\x9c]) | \x07 | #匹配 操作系统指令(OSC)...终止符或振铃符(ST|BEL)
(?:\x1b[P^_]|[\x90\x9e\x9f]) .*? (?:\x1b\\|\x9c) | #匹配 设备控制串或私讯或应用程序命令(DCS|PM|APC)...终止符(ST)
\x1b. #匹配 转义过后的字符
[\x80-\x9f] | (?:\x1b\]0.*) | \[.*@.*\][\$#] | (.*mysql>.*) #匹配 所有控制字符
"""
,
re
.
X
)
result_command
=
control_char
.
sub
(
''
,
result_command
.
strip
())
if
not
self
.
vim_flag
:
if
result_command
.
startswith
(
'vi'
)
or
result_command
.
startswith
(
'fg'
):
self
.
vim_flag
=
True
return
result_command
.
decode
(
'utf8'
,
"ignore"
)
else
:
return
''
def
get_log
(
self
):
def
get_log
(
self
):
"""
"""
...
...
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