修改 批量命令记录日志,上传下载记录日志

pull/2/head
guanghongwei 2014-11-06 18:48:13 +08:00
parent fc3d13a4b1
commit d8e4efe7cc
3 changed files with 23 additions and 6 deletions

View File

@ -248,8 +248,8 @@ def exec_cmd_servers(username):
cmd = raw_input('\033[1;32mCmd(s): \033[0m')
if cmd in ['q', 'Q']:
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)
filename = "%s/%s.log" % (exec_log_dir, time.strftime('%Y%m%d'))
f = open(filename, 'a')

View File

@ -34,6 +34,7 @@ ldap_host = cf.get('jumpserver', 'ldap_host')
ldap_base_dn = cf.get('jumpserver', 'ldap_base_dn')
admin_cn = cf.get('jumpserver', 'admin_cn')
admin_pass = cf.get('jumpserver', 'admin_pass')
log_dir = os.path.join(CONF_DIR, 'logs')
def keygen(num):
@ -915,6 +916,14 @@ def upFile(request):
sftp = paramiko.SFTPClient.from_transport(t)
sftp.put(filename, '%s/%s' % (path, upload_file.name))
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})
else:
@ -944,8 +953,15 @@ def downFile(request):
sftp = paramiko.SFTPClient.from_transport(t)
sftp.get(path, 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))
response = HttpResponse(wrapper, mimetype='application/octet-stream')
response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(path)
return response

View File

@ -6,7 +6,7 @@
<table class="table table-striped table-hover table-condensed">
<thead>
<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>
@ -19,12 +19,13 @@
<tbody>
{% for log in logs.object_list %}
<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.host }}</td>
{% if log.finish %}
<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>
{% else %}
<td><span class='monitor' filename="{{ log.logfile }}">监控</span></td>