Commit 5b0f8971 authored by ibuler's avatar ibuler

Update proxy log and command log view

parent 41337d28
...@@ -13,19 +13,36 @@ ...@@ -13,19 +13,36 @@
{% block table_search %} {% block table_search %}
<form id="search_form" method="get" action="" class="pull-right form-inline"> <form id="search_form" method="get" action="" class="pull-right form-inline">
<div class="form-group" id="date">
<div class="input-daterange input-group" id="datepicker">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input type="text" class="input-sm form-control" style="width: 100px;" name="date_from" value="{{ date_from }}">
<span class="input-group-addon">to</span>
<input type="text" class="input-sm form-control" style="width: 100px;" name="date_to" value="{{ date_to }}">
</div>
</div>
<div class="input-group"> <div class="input-group">
<select class="select2 form-control" name="user"> <select class="select2 form-control" name="username">
<option>{% trans 'Select user' %}</option> <option value="">{% trans 'User' %}</option>
{% for user in user_list %} {% for user in user_list %}
<option value="{{ user.username }}">{{ user.username }}</option> <option value="{{ user.username }}" {% if user.username == username %} selected {% endif %}>{{ user.username }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
<div class="input-group"> <div class="input-group">
<select class="select2 form-control" name="asset"> <select class="select2 form-control" name="ip">
<option>{% trans 'Select asset' %}</option> <option value="">{% trans 'Asset' %}</option>
{% for asset in asset_list %} {% for asset in asset_list %}
<option value="{{ asset.ip }}">{{ asset.ip }}</option> <option value="{{ asset.ip }}" {% if asset.ip == ip %} selected {% endif %}>{{ asset.ip }}</option>
{% endfor %}
</select>
</div>
<div class="input-group">
<select class="select2 form-control" name="system_user">
{# <option value="">{{ system_user }}</option>#}
<option value="">{% trans 'System user' %}</option>
{% for system_user in system_user_list %}
<option value="{{ system_user.username }}" {% if system_user.username == system_user %} selected {% endif %}>{{ system_user.username }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
...@@ -78,6 +95,12 @@ ...@@ -78,6 +95,12 @@
$(document).ready(function () { $(document).ready(function () {
$('.footable').footable(); $('.footable').footable();
$('.select2').select2(); $('.select2').select2();
$('#date .input-daterange').datepicker({
dateFormat: 'mm/dd/yy',
keyboardNavigation: false,
forceParse: false,
autoclose: true
});
}); });
</script> </script>
{% endblock %} {% endblock %}
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<select class="select2 form-control" name="username"> <select class="select2 form-control" name="username">
<option value="">{% trans 'Select user' %}</option> <option value="">{% trans 'Select user' %}</option>
{% for user in user_list %} {% for user in user_list %}
<option value="{{ user.username }}">{{ user.username }}</option> <option value="{{ user.username }}" {% if user.username == username %} selected {% endif %}>{{ user.username }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
...@@ -34,7 +34,15 @@ ...@@ -34,7 +34,15 @@
<select class="select2 form-control" name="ip"> <select class="select2 form-control" name="ip">
<option value="">{% trans 'Select asset' %}</option> <option value="">{% trans 'Select asset' %}</option>
{% for asset in asset_list %} {% for asset in asset_list %}
<option value="{{ asset.ip }}">{{ asset.ip }}</option> <option value="{{ asset.ip }}" {% if asset.ip == ip %} selected {% endif %}>{{ asset.ip }}</option>
{% endfor %}
</select>
</div>
<div class="input-group">
<select class="select2 form-control" name="system_user">
<option value="">{% trans 'System user' %}</option>
{% for su in system_user_list %}
<option value="{{ su.username }}" {% if su.username == system_user %} selected {% endif %}>{{ su.username }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
......
...@@ -15,6 +15,10 @@ from .utils import AdminUserRequiredMixin ...@@ -15,6 +15,10 @@ from .utils import AdminUserRequiredMixin
from .hands import User, Asset, SystemUser from .hands import User, Asset, SystemUser
seven_days_ago_s = (datetime.datetime.now()-datetime.timedelta(7)).strftime('%m/%d/%Y')
now_s = datetime.datetime.now().strftime('%m/%d/%Y')
class ProxyLogListView(AdminUserRequiredMixin, ListView): class ProxyLogListView(AdminUserRequiredMixin, ListView):
model = ProxyLog model = ProxyLog
template_name = 'audits/proxy_log_list.html' template_name = 'audits/proxy_log_list.html'
...@@ -25,14 +29,13 @@ class ProxyLogListView(AdminUserRequiredMixin, ListView): ...@@ -25,14 +29,13 @@ class ProxyLogListView(AdminUserRequiredMixin, ListView):
self.keyword = keyword = self.request.GET.get('keyword', '') self.keyword = keyword = self.request.GET.get('keyword', '')
self.username = username = self.request.GET.get('username', '') self.username = username = self.request.GET.get('username', '')
self.ip = ip = self.request.GET.get('ip', '') self.ip = ip = self.request.GET.get('ip', '')
self.date_from_s = date_from_s = \ self.system_user = system_user = self.request.GET.get('system_user', '')
self.request.GET.get('date_from', '%s' % (datetime.datetime.now()-datetime.timedelta(7)).strftime('%m/%d/%Y')) self.date_from_s = date_from_s = self.request.GET.get('date_from', '%s' % seven_days_ago_s)
self.date_to_s = date_to_s = self.request.GET.get('date_to', '%s' % datetime.datetime.now().strftime('%m/%d/%Y')) self.date_to_s = date_to_s = self.request.GET.get('date_to', '%s' % now_s)
if date_from_s: if date_from_s:
date_from = timezone.datetime.strptime(date_from_s, '%m/%d/%Y') date_from = timezone.datetime.strptime(date_from_s, '%m/%d/%Y')
self.queryset = self.queryset.filter(date_start__gt=date_from) self.queryset = self.queryset.filter(date_start__gt=date_from)
if date_to_s: if date_to_s:
date_to = timezone.datetime.strptime(date_to_s + ' 23:59:59', '%m/%d/%Y %H:%M:%S') date_to = timezone.datetime.strptime(date_to_s + ' 23:59:59', '%m/%d/%Y %H:%M:%S')
self.queryset = self.queryset.filter(date_start__lt=date_to) self.queryset = self.queryset.filter(date_start__lt=date_to)
...@@ -40,6 +43,8 @@ class ProxyLogListView(AdminUserRequiredMixin, ListView): ...@@ -40,6 +43,8 @@ class ProxyLogListView(AdminUserRequiredMixin, ListView):
self.queryset = self.queryset.filter(username=username) self.queryset = self.queryset.filter(username=username)
if ip: if ip:
self.queryset = self.queryset.filter(ip=ip) self.queryset = self.queryset.filter(ip=ip)
if system_user:
self.queryset = self.queryset.filter(system_user=system_user)
if keyword: if keyword:
self.queryset = self.queryset.filter(Q(username__contains=keyword) | self.queryset = self.queryset.filter(Q(username__contains=keyword) |
Q(name__icontains=keyword) | Q(name__icontains=keyword) |
...@@ -52,12 +57,15 @@ class ProxyLogListView(AdminUserRequiredMixin, ListView): ...@@ -52,12 +57,15 @@ class ProxyLogListView(AdminUserRequiredMixin, ListView):
context = { context = {
'app': _('Audits'), 'app': _('Audits'),
'action': _('Proxy log list'), 'action': _('Proxy log list'),
'user_list': User.objects.all(), 'user_list': User.objects.all().order_by('username'),
'asset_list': Asset.objects.all(), 'asset_list': Asset.objects.all().order_by('ip'),
'system_user_list': SystemUser.objects.all(), 'system_user_list': SystemUser.objects.all().order_by('name'),
'keyword': self.keyword, 'keyword': self.keyword,
'date_from': self.date_from_s, 'date_from': self.date_from_s,
'date_to': self.date_to_s, 'date_to': self.date_to_s,
'username': self.username,
'ip': self.ip,
'system_user': self.system_user,
} }
kwargs.update(context) kwargs.update(context)
return super(ProxyLogListView, self).get_context_data(**kwargs) return super(ProxyLogListView, self).get_context_data(**kwargs)
...@@ -101,14 +109,29 @@ class CommandLogListView(AdminUserRequiredMixin, ListView): ...@@ -101,14 +109,29 @@ class CommandLogListView(AdminUserRequiredMixin, ListView):
context_object_name = 'command_list' context_object_name = 'command_list'
def get_queryset(self): def get_queryset(self):
# Todo: Default order by lose asset connection num
self.queryset = super(CommandLogListView, self).get_queryset() self.queryset = super(CommandLogListView, self).get_queryset()
self.keyword = keyword = self.request.GET.get('keyword', '') self.keyword = keyword = self.request.GET.get('keyword', '')
self.sort = sort = self.request.GET.get('sort', '-datetime') self.sort = sort = self.request.GET.get('sort', '-datetime')
self.username = username = self.request.GET.get('username', '')
self.ip = ip = self.request.GET.get('ip', '')
self.system_user = system_user = self.request.GET.get('system_user', '')
self.date_from_s = date_from_s = self.request.GET.get('date_from', '%s' % seven_days_ago_s)
self.date_to_s = date_to_s = self.request.GET.get('date_to', '%s' % now_s)
if date_from_s:
date_from = timezone.datetime.strptime(date_from_s, '%m/%d/%Y')
self.queryset = self.queryset.filter(datetime__gt=date_from)
if date_to_s:
date_to = timezone.datetime.strptime(date_to_s + ' 23:59:59', '%m/%d/%Y %H:%M:%S')
self.queryset = self.queryset.filter(datetime__lt=date_to)
if username:
self.queryset = self.queryset.filter(proxy_log__username=username)
if ip:
self.queryset = self.queryset.filter(proxy_log__ip=ip)
if system_user:
self.queryset = self.queryset.filter(proxy_log__system_user=system_user)
if keyword: if keyword:
self.queryset = self.queryset.filter() self.queryset = self.queryset.filter(command=keyword)
if sort: if sort:
self.queryset = self.queryset.order_by(sort) self.queryset = self.queryset.order_by(sort)
return self.queryset return self.queryset
...@@ -117,9 +140,15 @@ class CommandLogListView(AdminUserRequiredMixin, ListView): ...@@ -117,9 +140,15 @@ class CommandLogListView(AdminUserRequiredMixin, ListView):
context = { context = {
'app': _('Audits'), 'app': _('Audits'),
'action': _('Command log list'), 'action': _('Command log list'),
'user_list': User.objects.all(), 'user_list': User.objects.all().order_by('username'),
'asset_list': Asset.objects.all(), 'asset_list': Asset.objects.all().order_by('ip'),
'system_user_list': SystemUser.objects.all(), 'system_user_list': SystemUser.objects.all().order_by('name'),
'keyword': self.keyword,
'date_from': self.date_from_s,
'date_to': self.date_to_s,
'username': self.username,
'ip': self.ip,
'system_user': self.system_user,
} }
kwargs.update(context) kwargs.update(context)
return super(CommandLogListView, self).get_context_data(**kwargs) return super(CommandLogListView, self).get_context_data(**kwargs)
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