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
d8e4efe7
Commit
d8e4efe7
authored
Nov 06, 2014
by
guanghongwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改 批量命令记录日志,上传下载记录日志
parent
fc3d13a4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
6 deletions
+23
-6
jumpserver.py
jumpserver.py
+2
-2
views.py
webroot/AutoSa/AutoSa/views.py
+17
-1
logView.html
webroot/AutoSa/templates/logView.html
+4
-3
No files found.
jumpserver.py
View file @
d8e4efe7
...
@@ -248,8 +248,8 @@ def exec_cmd_servers(username):
...
@@ -248,8 +248,8 @@ def exec_cmd_servers(username):
cmd
=
raw_input
(
'
\033
[1;32mCmd(s):
\033
[0m'
)
cmd
=
raw_input
(
'
\033
[1;32mCmd(s):
\033
[0m'
)
if
cmd
in
[
'q'
,
'Q'
]:
if
cmd
in
[
'q'
,
'Q'
]:
break
break
if
not
os
.
path
.
isdir
():
exec_log_dir
=
os
.
path
.
join
(
log_dir
,
'exec_cmds'
)
exec_log_dir
=
os
.
path
.
join
(
log_dir
,
'exec_cmds'
)
if
not
os
.
path
.
isdir
(
exec_log_dir
):
os
.
mkdir
(
exec_log_dir
,
0777
)
os
.
mkdir
(
exec_log_dir
,
0777
)
filename
=
"
%
s/
%
s.log"
%
(
exec_log_dir
,
time
.
strftime
(
'
%
Y
%
m
%
d'
))
filename
=
"
%
s/
%
s.log"
%
(
exec_log_dir
,
time
.
strftime
(
'
%
Y
%
m
%
d'
))
f
=
open
(
filename
,
'a'
)
f
=
open
(
filename
,
'a'
)
...
...
webroot/AutoSa/AutoSa/views.py
View file @
d8e4efe7
...
@@ -34,6 +34,7 @@ ldap_host = cf.get('jumpserver', 'ldap_host')
...
@@ -34,6 +34,7 @@ ldap_host = cf.get('jumpserver', 'ldap_host')
ldap_base_dn
=
cf
.
get
(
'jumpserver'
,
'ldap_base_dn'
)
ldap_base_dn
=
cf
.
get
(
'jumpserver'
,
'ldap_base_dn'
)
admin_cn
=
cf
.
get
(
'jumpserver'
,
'admin_cn'
)
admin_cn
=
cf
.
get
(
'jumpserver'
,
'admin_cn'
)
admin_pass
=
cf
.
get
(
'jumpserver'
,
'admin_pass'
)
admin_pass
=
cf
.
get
(
'jumpserver'
,
'admin_pass'
)
log_dir
=
os
.
path
.
join
(
CONF_DIR
,
'logs'
)
def
keygen
(
num
):
def
keygen
(
num
):
...
@@ -915,6 +916,14 @@ def upFile(request):
...
@@ -915,6 +916,14 @@ def upFile(request):
sftp
=
paramiko
.
SFTPClient
.
from_transport
(
t
)
sftp
=
paramiko
.
SFTPClient
.
from_transport
(
t
)
sftp
.
put
(
filename
,
'
%
s/
%
s'
%
(
path
,
upload_file
.
name
))
sftp
.
put
(
filename
,
'
%
s/
%
s'
%
(
path
,
upload_file
.
name
))
msg
=
u'上传成功,位于
%
s主机,位置
%
s.'
%
(
host
,
path
)
msg
=
u'上传成功,位于
%
s主机,位置
%
s.'
%
(
host
,
path
)
uplog_dir
=
os
.
path
.
join
(
log_dir
,
'upload'
)
if
not
os
.
path
.
isdir
(
uplog_dir
):
os
.
mkdir
(
uplog_dir
)
filename
=
os
.
path
.
join
(
uplog_dir
,
time
.
strftime
(
'
%
Y
%
m
%
d'
))
f
=
open
(
filename
,
'a'
)
f
.
write
(
'DateTime:
%
s User:
%
s Host:
%
s File:
%
s'
%
(
time
.
strftime
(
'
%
Y/
%
m/
%
d
%
H:
%
M:
%
S'
),
username
,
host
,
path
))
f
.
close
()
return
render_to_response
(
'info.html'
,
{
'msg'
:
msg
})
return
render_to_response
(
'info.html'
,
{
'msg'
:
msg
})
else
:
else
:
...
@@ -944,8 +953,15 @@ def downFile(request):
...
@@ -944,8 +953,15 @@ def downFile(request):
sftp
=
paramiko
.
SFTPClient
.
from_transport
(
t
)
sftp
=
paramiko
.
SFTPClient
.
from_transport
(
t
)
sftp
.
get
(
path
,
download_file
)
sftp
.
get
(
path
,
download_file
)
if
os
.
path
.
isfile
(
download_file
):
if
os
.
path
.
isfile
(
download_file
):
downlog_dir
=
os
.
path
.
join
(
log_dir
,
'download'
)
if
not
os
.
path
.
isdir
(
downlog_dir
):
os
.
mkdir
(
downlog_dir
)
filename
=
os
.
path
.
join
(
downlog_dir
,
time
.
strftime
(
'
%
Y
%
m
%
d'
))
f
=
open
(
filename
,
'a'
)
f
.
write
(
'DateTime:
%
s User:
%
s Host:
%
s File:
%
s'
%
(
time
.
strftime
(
'
%
Y/
%
m/
%
d
%
H:
%
M:
%
S'
),
username
,
host
,
path
))
f
.
close
()
wrapper
=
FileWrapper
(
open
(
download_file
))
wrapper
=
FileWrapper
(
open
(
download_file
))
response
=
HttpResponse
(
wrapper
,
mimetype
=
'application/octet-stream'
)
response
=
HttpResponse
(
wrapper
,
mimetype
=
'application/octet-stream'
)
response
[
'Content-Disposition'
]
=
'attachment; filename=
%
s'
%
os
.
path
.
basename
(
path
)
response
[
'Content-Disposition'
]
=
'attachment; filename=
%
s'
%
os
.
path
.
basename
(
path
)
return
response
return
response
...
...
webroot/AutoSa/templates/logView.html
View file @
d8e4efe7
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<table
class=
"table table-striped table-hover table-condensed"
>
<table
class=
"table table-striped table-hover table-condensed"
>
<thead>
<thead>
<tr>
<tr>
<th>
<input
onclick=
"selectAll()"
type=
"checkbox"
name=
"select_all"
style=
"select_all"
id=
"select_all"
/>
</th>
<th>
id
</th>
<th>
用户名
</th>
<th>
用户名
</th>
<th>
主机
</th>
<th>
主机
</th>
<th>
监控
</th>
<th>
监控
</th>
...
@@ -19,12 +19,13 @@
...
@@ -19,12 +19,13 @@
<tbody>
<tbody>
{% for log in logs.object_list %}
{% for log in logs.object_list %}
<tr>
<tr>
<td><input
type=
"checkbox"
name=
"selected"
value=
"{{ log.id }}"
></td>
<!--<td><input type="checkbox" name="selected" value="{{ log.id }}"></td>-->
<td>
{{ log.id }}
</td>
<td>
{{ log.user }}
</td>
<td>
{{ log.user }}
</td>
<td>
{{ log.host }}
</td>
<td>
{{ log.host }}
</td>
{% if log.finish %}
{% if log.finish %}
<td>
监控
</td>
<td>
监控
</td>
<td><a
href=
"/logHistory/?id={{ log.id }}"
class=
"log_command"
>
命令
统计
</a></td>
<td><a
href=
"/logHistory/?id={{ log.id }}"
class=
"log_command"
>
统计
</a></td>
<td>
阻断
</td>
<td>
阻断
</td>
{% else %}
{% else %}
<td><span
class=
'monitor'
filename=
"{{ log.logfile }}"
>
监控
</span></td>
<td><span
class=
'monitor'
filename=
"{{ log.logfile }}"
>
监控
</span></td>
...
...
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