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
0f09172e
Commit
0f09172e
authored
May 11, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
conflict reslove
parents
f71c8551
94876344
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
27 deletions
+20
-27
connect.py
connect.py
+20
-27
No files found.
connect.py
View file @
0f09172e
...
@@ -93,9 +93,7 @@ class Tty(object):
...
@@ -93,9 +93,7 @@ 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
.
vim_end_flag
=
False
self
.
vim_end_pattern
=
re
.
compile
(
r'\x1b\[\?1049'
,
re
.
X
)
self
.
vim_end_pattern
=
re
.
compile
(
r'\x1b\[\?1049'
,
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
=
None
self
.
stream
=
None
self
.
screen
=
None
self
.
screen
=
None
...
@@ -117,7 +115,8 @@ class Tty(object):
...
@@ -117,7 +115,8 @@ class Tty(object):
return
True
return
True
return
False
return
False
def
command_parser
(
self
,
command
):
@staticmethod
def
command_parser
(
command
):
"""
"""
处理命令中如果有ps1或者mysql的特殊情况,极端情况下会有ps1和mysql
处理命令中如果有ps1或者mysql的特殊情况,极端情况下会有ps1和mysql
:param command:要处理的字符传
:param command:要处理的字符传
...
@@ -157,14 +156,10 @@ class Tty(object):
...
@@ -157,14 +156,10 @@ class Tty(object):
else
:
else
:
command
=
line_data
command
=
line_data
break
break
if
command
!=
''
:
# 判断用户输入的是否是vim 或者fg命令
if
self
.
vim_pattern
.
search
(
command
):
self
.
vim_flag
=
True
# 虚拟屏幕清空
self
.
screen
.
reset
()
except
Exception
:
except
Exception
:
pass
pass
# 虚拟屏幕清空
self
.
screen
.
reset
()
return
command
return
command
def
get_log
(
self
):
def
get_log
(
self
):
...
@@ -345,9 +340,8 @@ class SshTty(Tty):
...
@@ -345,9 +340,8 @@ class SshTty(Tty):
pre_timestamp
=
now_timestamp
pre_timestamp
=
now_timestamp
log_file_f
.
flush
()
log_file_f
.
flush
()
if
self
.
vim_flag
:
self
.
vim_data
+=
x
self
.
vim_data
+=
x
if
input_mode
:
elif
input_mode
:
data
+=
x
data
+=
x
except
socket
.
timeout
:
except
socket
.
timeout
:
...
@@ -361,20 +355,19 @@ class SshTty(Tty):
...
@@ -361,20 +355,19 @@ class SshTty(Tty):
termlog
.
recoder
=
True
termlog
.
recoder
=
True
input_mode
=
True
input_mode
=
True
if
self
.
is_output
(
str
(
x
)):
if
self
.
is_output
(
str
(
x
)):
if
self
.
vim_flag
:
# 如果len(str(x)) > 1 说明是复制输入的
match
=
self
.
vim_end_pattern
.
findall
(
self
.
vim_data
)
if
len
(
str
(
x
))
>
1
:
if
match
:
data
=
x
if
self
.
vim_end_flag
or
len
(
match
)
==
2
:
match
=
self
.
vim_end_pattern
.
findall
(
self
.
vim_data
)
self
.
vim_flag
=
False
if
match
:
self
.
vim_end_flag
=
False
if
self
.
vim_flag
or
len
(
match
)
==
2
:
else
:
self
.
vim_flag
=
False
self
.
vim_end_flag
=
True
else
:
else
:
self
.
vim_flag
=
True
# 如果len(str(x)) > 1 说明是复制输入的
elif
not
self
.
vim_flag
:
if
len
(
str
(
x
))
>
1
:
self
.
vim_flag
=
False
data
=
x
data
=
self
.
deal_command
(
data
)[
0
:
200
]
data
=
self
.
deal_command
(
data
)[
0
:
200
]
if
len
(
data
)
>
0
:
if
data
is
not
None
:
TtyLog
(
log
=
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
data
)
.
save
()
TtyLog
(
log
=
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
data
)
.
save
()
data
=
''
data
=
''
self
.
vim_data
=
''
self
.
vim_data
=
''
...
@@ -402,7 +395,7 @@ class SshTty(Tty):
...
@@ -402,7 +395,7 @@ class SshTty(Tty):
"""
"""
# 发起ssh连接请求 Make a ssh connection
# 发起ssh连接请求 Make a ssh connection
ssh
=
self
.
get_connection
()
ssh
=
self
.
get_connection
()
transport
=
ssh
.
get_transport
()
transport
=
ssh
.
get_transport
()
transport
.
set_keepalive
(
30
)
transport
.
set_keepalive
(
30
)
transport
.
use_compression
(
True
)
transport
.
use_compression
(
True
)
...
@@ -418,7 +411,7 @@ class SshTty(Tty):
...
@@ -418,7 +411,7 @@ class SshTty(Tty):
signal
.
signal
(
signal
.
SIGWINCH
,
self
.
set_win_size
)
signal
.
signal
(
signal
.
SIGWINCH
,
self
.
set_win_size
)
except
:
except
:
pass
pass
self
.
posix_shell
()
self
.
posix_shell
()
# Shutdown channel socket
# Shutdown channel socket
...
...
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