From d19b47a427eecb5de9f271d0a08ff8a63e0a7615 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 27 Oct 2016 00:03:05 +0800 Subject: [PATCH] add command log modal --- apps/audits/models.py | 11 ++++++ apps/audits/serializers.py | 2 +- ...html => proxy_log_command_list_modal.html} | 6 +-- .../templates/audits/proxy_log_list.html | 39 +++++++++++++++---- 4 files changed, 46 insertions(+), 12 deletions(-) rename apps/audits/templates/audits/{_proxy_log_command_modal.html => proxy_log_command_list_modal.html} (81%) diff --git a/apps/audits/models.py b/apps/audits/models.py index 4c9c47c40..015f0bfb7 100644 --- a/apps/audits/models.py +++ b/apps/audits/models.py @@ -54,6 +54,17 @@ class ProxyLog(models.Model): def __unicode__(self): 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: db_table = 'proxy_log' ordering = ['-date_start', 'username'] diff --git a/apps/audits/serializers.py b/apps/audits/serializers.py index 62c225672..5191e044b 100644 --- a/apps/audits/serializers.py +++ b/apps/audits/serializers.py @@ -14,7 +14,7 @@ class ProxyLogSerializer(serializers.ModelSerializer): class Meta: model = models.ProxyLog 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 def get_time(obj): diff --git a/apps/audits/templates/audits/_proxy_log_command_modal.html b/apps/audits/templates/audits/proxy_log_command_list_modal.html similarity index 81% rename from apps/audits/templates/audits/_proxy_log_command_modal.html rename to apps/audits/templates/audits/proxy_log_command_list_modal.html index a0e4290ea..790c8b02b 100644 --- a/apps/audits/templates/audits/_proxy_log_command_modal.html +++ b/apps/audits/templates/audits/proxy_log_command_list_modal.html @@ -1,9 +1,7 @@ {% extends '_modal.html' %} {% load i18n %} -{% block modal_id %}Proxy command list{% endblock %} -{% block modal_title%}{% trans "Proxy command list" %}{% endblock %} +{% block modal_id %}command_table{% endblock %} {% block modal_body %} -
@@ -13,7 +11,7 @@ - + {% for command in object_list %} diff --git a/apps/audits/templates/audits/proxy_log_list.html b/apps/audits/templates/audits/proxy_log_list.html index 3865660fa..6078a9194 100644 --- a/apps/audits/templates/audits/proxy_log_list.html +++ b/apps/audits/templates/audits/proxy_log_list.html @@ -40,7 +40,7 @@
Datetime
{{ command.command_no }}
- {% include 'audits/_proxy_log_command_modal.html' %} + {% include 'audits/proxy_log_command_list_modal.html' %} {% endblock %} {% block custom_foot_js %} @@ -55,6 +55,13 @@ $(document).ready(function(){ var detail_btn = '' + cellData + ''; $(td).html(detail_btn.replace('99991937', rowData.id)); }}, + {targets: 4, createdCell: function (td, cellData, rowData) { + if (cellData) { + $(td).html('99991937' + .replace('99991937', cellData) + .replace('99991938',rowData.id)) + } + }}, {targets: 5, createdCell: function (td, cellData) { if (cellData) { $(td).html('') @@ -85,12 +92,30 @@ $(document).ready(function(){ op_html: $('#actions').html() }; jumpserver.initDataTable(options); -}).on('click', '.btn_delete', function(){ - var $this = $(this); - var uid = $this.data('uid'); - var name = $(this).data('name'); - var the_url = '{% url "terminal:terminal-detail-update-delete-api" pk=99991937 %}'.replace('99991937', uid); - objectDelete($this, name, the_url) +}).on('click', '.commands', function () { + var url = $(this).attr('url'); + $.ajax({ + url: url, + method: 'GET', + success: function (data) { + var table_body = ''; + $.each(data.commands_dict, function (index, value) { + table_body += '' + + '' + value.command_no + '' + + '' + value.command + '' + + '' + value.output + '' + + '' + value.datetime + '' + + '' + }); + console.log(table_body); + $('.table_body').html(table_body); + $('.footable').footable(); + $('#command_table').modal('show'); + } + + }) }) + + {% endblock %}