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
bd885da1
Commit
bd885da1
authored
Nov 27, 2015
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
recoard 特殊字符去掉
parent
35db337f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
17 deletions
+22
-17
connect.py
connect.py
+14
-16
log_api.py
jlog/log_api.py
+8
-1
No files found.
connect.py
View file @
bd885da1
...
@@ -53,6 +53,12 @@ def color_print(msg, color='red', exits=False):
...
@@ -53,6 +53,12 @@ def color_print(msg, color='red', exits=False):
return
msg
return
msg
def
write_log
(
f
,
msg
):
msg
=
re
.
sub
(
r'[\r\n]'
,
'
\r\n
'
,
msg
)
f
.
write
(
msg
)
f
.
flush
()
class
Tty
(
object
):
class
Tty
(
object
):
"""
"""
A virtual tty class
A virtual tty class
...
@@ -603,19 +609,15 @@ class Nav(object):
...
@@ -603,19 +609,15 @@ class Nav(object):
while
True
:
while
True
:
print
"请输入执行的命令, 按q退出"
print
"请输入执行的命令, 按q退出"
data
=
'ansible> '
data
=
'ansible> '
log_file_f
.
write
(
data
)
write_log
(
log_file_f
,
data
)
log_file_f
.
flush
()
now_timestamp
=
time
.
time
()
now_timestamp
=
time
.
time
()
log_time_f
.
write
(
'
%
s
%
s
\n
'
%
(
round
(
now_timestamp
-
pre_timestamp
,
4
),
len
(
data
)))
write_log
(
log_time_f
,
'
%
s
%
s
\n
'
%
(
round
(
now_timestamp
-
pre_timestamp
,
4
),
len
(
data
)))
log_time_f
.
flush
()
pre_timestamp
=
now_timestamp
pre_timestamp
=
now_timestamp
command
=
raw_input
(
"
\033
[1;32mCmds>:
\033
[0m "
)
.
strip
()
command
=
raw_input
(
"
\033
[1;32mCmds>:
\033
[0m "
)
.
strip
()
data
=
'
%
s
\r\n
'
%
command
data
=
'
%
s
\r\n
'
%
command
log_file_f
.
write
(
data
)
write_log
(
log_file_f
,
data
)
log_file_f
.
flush
()
now_timestamp
=
time
.
time
()
now_timestamp
=
time
.
time
()
log_time_f
.
write
(
'
%
s
%
s
\n
'
%
(
round
(
now_timestamp
-
pre_timestamp
,
4
),
len
(
data
)))
write_log
(
log_time_f
,
'
%
s
%
s
\n
'
%
(
round
(
now_timestamp
-
pre_timestamp
,
4
),
len
(
data
)))
log_time_f
.
flush
()
pre_timestamp
=
now_timestamp
pre_timestamp
=
now_timestamp
TtyLog
(
log
=
log
,
cmd
=
command
,
datetime
=
datetime
.
datetime
.
now
())
.
save
()
TtyLog
(
log
=
log
,
cmd
=
command
,
datetime
=
datetime
.
datetime
.
now
())
.
save
()
if
command
==
'q'
:
if
command
==
'q'
:
...
@@ -632,10 +634,8 @@ class Nav(object):
...
@@ -632,10 +634,8 @@ class Nav(object):
output
=
re
.
sub
(
r'[\r\n]'
,
'
\r\n
'
,
output
)
output
=
re
.
sub
(
r'[\r\n]'
,
'
\r\n
'
,
output
)
data
=
'
%
s
\r\n
%
s
\r\n
'
%
(
header
,
output
)
data
=
'
%
s
\r\n
%
s
\r\n
'
%
(
header
,
output
)
now_timestamp
=
time
.
time
()
now_timestamp
=
time
.
time
()
log_file_f
.
write
(
data
)
write_log
(
log_file_f
,
data
)
log_file_f
.
flush
()
write_log
(
log_time_f
,
'
%
s
%
s
\n
'
%
(
round
(
now_timestamp
-
pre_timestamp
,
4
),
len
(
data
)))
log_time_f
.
write
(
'
%
s
%
s
\n
'
%
(
round
(
now_timestamp
-
pre_timestamp
,
4
),
len
(
data
)))
log_time_f
.
flush
()
pre_timestamp
=
now_timestamp
pre_timestamp
=
now_timestamp
print
print
else
:
else
:
...
@@ -645,10 +645,8 @@ class Nav(object):
...
@@ -645,10 +645,8 @@ class Nav(object):
output
=
re
.
sub
(
r'[\r\n]'
,
'
\r\n
'
,
output
)
output
=
re
.
sub
(
r'[\r\n]'
,
'
\r\n
'
,
output
)
data
=
'
%
s
\r\n
%
s
\r\n
'
%
(
header
,
output
)
data
=
'
%
s
\r\n
%
s
\r\n
'
%
(
header
,
output
)
now_timestamp
=
time
.
time
()
now_timestamp
=
time
.
time
()
log_file_f
.
write
(
data
)
write_log
(
log_file_f
,
data
)
log_file_f
.
flush
()
write_log
(
log_time_f
,
'
%
s
%
s
\n
'
%
(
round
(
now_timestamp
-
pre_timestamp
,
4
),
len
(
data
)))
log_time_f
.
write
(
'
%
s
%
s
\n
'
%
(
round
(
now_timestamp
-
pre_timestamp
,
4
),
len
(
data
)))
log_time_f
.
flush
()
pre_timestamp
=
now_timestamp
pre_timestamp
=
now_timestamp
print
print
print
"="
*
20
print
"="
*
20
...
...
jlog/log_api.py
View file @
bd885da1
...
@@ -6,6 +6,7 @@ from contextlib import closing
...
@@ -6,6 +6,7 @@ from contextlib import closing
from
codecs
import
open
as
copen
from
codecs
import
open
as
copen
from
json
import
dumps
from
json
import
dumps
from
math
import
ceil
from
math
import
ceil
import
re
from
os.path
import
basename
,
dirname
,
exists
,
join
from
os.path
import
basename
,
dirname
,
exists
,
join
from
struct
import
unpack
from
struct
import
unpack
from
subprocess
import
Popen
from
subprocess
import
Popen
...
@@ -19,10 +20,16 @@ from jumpserver.api import BASE_DIR
...
@@ -19,10 +20,16 @@ from jumpserver.api import BASE_DIR
DEFAULT_TEMPLATE
=
join
(
BASE_DIR
,
'templates'
,
'jlog'
,
'static.jinja2'
)
DEFAULT_TEMPLATE
=
join
(
BASE_DIR
,
'templates'
,
'jlog'
,
'static.jinja2'
)
rz_pat
=
re
.
compile
(
r'\x18B\w+\r\x8a(\x11)?'
)
def
escapeString
(
string
):
def
escapeString
(
string
):
string
=
string
.
encode
(
'unicode_escape'
)
.
decode
(
'utf-8'
)
string
=
rz_pat
.
sub
(
''
,
string
)
try
:
string
=
string
.
encode
(
'unicode_escape'
)
.
decode
(
'utf-8'
,
'ignore'
)
except
(
UnicodeEncodeError
,
UnicodeDecodeError
):
string
=
string
.
decode
(
'utf-8'
,
'ignore'
)
print
repr
(
string
)
string
=
string
.
replace
(
"'"
,
"
\\
'"
)
string
=
string
.
replace
(
"'"
,
"
\\
'"
)
string
=
'
\'
'
+
string
+
'
\'
'
string
=
'
\'
'
+
string
+
'
\'
'
return
string
return
string
...
...
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