Commit d19b47a4 authored by ibuler's avatar ibuler

add command log modal

parent 573b3a87
...@@ -54,6 +54,17 @@ class ProxyLog(models.Model): ...@@ -54,6 +54,17 @@ class ProxyLog(models.Model):
def __unicode__(self): def __unicode__(self):
return '%s-%s-%s-%s' % (self.username, self.hostname, self.system_user, self.id) return '%s-%s-%s-%s' % (self.username, self.hostname, self.system_user, self.id)
@property
def commands_dict(self):
commands = self.command_log.all()
return [
{
"command_no": command.command_no,
"command": command.command,
"output": command.output_decode,
"datetime": command.datetime,
} for command in commands]
class Meta: class Meta:
db_table = 'proxy_log' db_table = 'proxy_log'
ordering = ['-date_start', 'username'] ordering = ['-date_start', 'username']
......
...@@ -14,7 +14,7 @@ class ProxyLogSerializer(serializers.ModelSerializer): ...@@ -14,7 +14,7 @@ class ProxyLogSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = models.ProxyLog model = models.ProxyLog
fields = ['id', 'name', 'username', 'hostname', 'ip', 'system_user', 'login_type', 'terminal', fields = ['id', 'name', 'username', 'hostname', 'ip', 'system_user', 'login_type', 'terminal',
'log_file', 'was_failed', 'is_finished', 'date_start', 'time', 'command_length'] 'log_file', 'was_failed', 'is_finished', 'date_start', 'time', 'command_length', "commands_dict"]
@staticmethod @staticmethod
def get_time(obj): def get_time(obj):
......
{% extends '_modal.html' %} {% extends '_modal.html' %}
{% load i18n %} {% load i18n %}
{% block modal_id %}Proxy command list{% endblock %} {% block modal_id %}command_table{% endblock %}
{% block modal_title%}{% trans "Proxy command list" %}{% endblock %}
{% block modal_body %} {% block modal_body %}
<div class="ibox-content">
<table class="footable table table-stripped toggle-arrow-tiny" data-page-size="10"> <table class="footable table table-stripped toggle-arrow-tiny" data-page-size="10">
<thead> <thead>
<tr> <tr>
...@@ -13,7 +11,7 @@ ...@@ -13,7 +11,7 @@
<th>Datetime</th> <th>Datetime</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody class="table_body">
{% for command in object_list %} {% for command in object_list %}
<tr> <tr>
<td>{{ command.command_no }}</td> <td>{{ command.command_no }}</td>
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<tbody> <tbody>
</tbody> </tbody>
</table> </table>
{% include 'audits/_proxy_log_command_modal.html' %} {% include 'audits/proxy_log_command_list_modal.html' %}
{% endblock %} {% endblock %}
{% block custom_foot_js %} {% block custom_foot_js %}
<script src="{% static 'js/jquery.form.min.js' %}"></script> <script src="{% static 'js/jquery.form.min.js' %}"></script>
...@@ -55,6 +55,13 @@ $(document).ready(function(){ ...@@ -55,6 +55,13 @@ $(document).ready(function(){
var detail_btn = '<a href="{% url "users:user-detail" pk=99991937 %}">' + cellData + '</a>'; var detail_btn = '<a href="{% url "users:user-detail" pk=99991937 %}">' + cellData + '</a>';
$(td).html(detail_btn.replace('99991937', rowData.id)); $(td).html(detail_btn.replace('99991937', rowData.id));
}}, }},
{targets: 4, createdCell: function (td, cellData, rowData) {
if (cellData) {
$(td).html('<a url="{% url "audits:proxy-log-detail-api" pk=99991938 %}" class="commands">99991937</a>'
.replace('99991937', cellData)
.replace('99991938',rowData.id))
}
}},
{targets: 5, createdCell: function (td, cellData) { {targets: 5, createdCell: function (td, cellData) {
if (cellData) { if (cellData) {
$(td).html('<i class="fa fa-times text-danger"></i>') $(td).html('<i class="fa fa-times text-danger"></i>')
...@@ -85,12 +92,30 @@ $(document).ready(function(){ ...@@ -85,12 +92,30 @@ $(document).ready(function(){
op_html: $('#actions').html() op_html: $('#actions').html()
}; };
jumpserver.initDataTable(options); jumpserver.initDataTable(options);
}).on('click', '.btn_delete', function(){ }).on('click', '.commands', function () {
var $this = $(this); var url = $(this).attr('url');
var uid = $this.data('uid'); $.ajax({
var name = $(this).data('name'); url: url,
var the_url = '{% url "terminal:terminal-detail-update-delete-api" pk=99991937 %}'.replace('99991937', uid); method: 'GET',
objectDelete($this, name, the_url) success: function (data) {
var table_body = '';
$.each(data.commands_dict, function (index, value) {
table_body += '<tr>' +
'<td>' + value.command_no + '</td>' +
'<td>' + value.command + '</td>' +
'<td>' + value.output + '</td>' +
'<td>' + value.datetime + '</td>' +
'</tr>'
});
console.log(table_body);
$('.table_body').html(table_body);
$('.footable').footable();
$('#command_table').modal('show');
}
})
}) })
</script> </script>
{% endblock %} {% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment