mirror of https://github.com/jumpserver/jumpserver
UPdate some
parent
419876b575
commit
8d358a7a68
|
@ -0,0 +1,100 @@
|
||||||
|
{% extends '_base_list.html' %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% load static %}
|
||||||
|
{% load common_tags %}
|
||||||
|
{% block content_left_head %}
|
||||||
|
<link href="{% static 'css/plugins/datepicker/datepicker3.css' %}" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
#search_btn {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block table_search %}
|
||||||
|
<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">
|
||||||
|
<select class="select2 form-control" name="username">
|
||||||
|
<option value="">{% trans 'Select user' %}</option>
|
||||||
|
{% for user in user_list %}
|
||||||
|
<option value="{{ user.username }}" {% if user.username == username %} selected {% endif %}>{{ user.username }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" class="form-control input-sm" name="keyword" placeholder="Search" value="{{ keyword }}">
|
||||||
|
</div>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-btn">
|
||||||
|
<button id='search_btn' type="submit" class="btn btn-sm btn-primary">
|
||||||
|
搜索
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block table_head %}
|
||||||
|
<th class="text-center">{% trans 'ID' %}</th>
|
||||||
|
<th class="text-center">{% trans 'Username' %}</th>
|
||||||
|
<th class="text-center">{% trans 'Name' %}</th>
|
||||||
|
<th class="text-center">{% trans 'Type' %}</th>
|
||||||
|
<th class="text-center">{% trans 'UA' %}</th>
|
||||||
|
<th class="text-center">{% trans 'IP' %}</th>
|
||||||
|
<th class="text-center">{% trans 'City' %}</th>
|
||||||
|
<th class="text-center">{% trans 'Date' %}</th>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block table_body %}
|
||||||
|
{% for login_log in login_log_list %}
|
||||||
|
<tr class="gradeX">
|
||||||
|
<td class="text-center">
|
||||||
|
{{ login_log.id }}
|
||||||
|
{# <a href="{% url 'audits:proxy-log-detail' pk=login_log.id %}">{{ login_log.id }}</a>#}
|
||||||
|
</td>
|
||||||
|
<td class="text-center">{{ login_log.username }}</td>
|
||||||
|
<td class="text-center">{{ login_log.name }}</td>
|
||||||
|
<td class="text-center">{{ login_log.get_login_type_display }}</td>
|
||||||
|
{% if login_log.login_type == 'W' %}
|
||||||
|
<td class="text-center">
|
||||||
|
<span href="javascript:void(0);" data-toggle="tooltips" title="{{ login_log.user_agent }}">{{ login_log.user_agent | truncatechars:20 }}</span>
|
||||||
|
</td>
|
||||||
|
{% else %}
|
||||||
|
<td class="text-center">{{ login_log.terminal }}</td>
|
||||||
|
{% endif %}
|
||||||
|
<td class="text-center">{{ login_log.login_ip }}</td>
|
||||||
|
<td class="text-center">{{ login_log.login_city }}</td>
|
||||||
|
<td class="text-center">{{ login_log.date_login }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block custom_foot_js %}
|
||||||
|
<script src="{% static 'js/plugins/datepicker/bootstrap-datepicker.js' %}"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('table').DataTable({
|
||||||
|
"searching": false,
|
||||||
|
"paging": false,
|
||||||
|
"order": []
|
||||||
|
});
|
||||||
|
$('#date .input-daterange').datepicker({
|
||||||
|
dateFormat: 'mm/dd/yy',
|
||||||
|
keyboardNavigation: false,
|
||||||
|
forceParse: false,
|
||||||
|
autoclose: true
|
||||||
|
});
|
||||||
|
$('.select2').select2();
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -12,6 +12,7 @@ urlpatterns = [
|
||||||
url(r'^proxy-log/(?P<pk>\d+)$', views.ProxyLogDetailView.as_view(), name='proxy-log-detail'),
|
url(r'^proxy-log/(?P<pk>\d+)$', views.ProxyLogDetailView.as_view(), name='proxy-log-detail'),
|
||||||
url(r'^proxy-log/(?P<pk>\d+)/commands$', views.ProxyLogCommandsListView.as_view(), name='proxy-log-commands-list'),
|
url(r'^proxy-log/(?P<pk>\d+)/commands$', views.ProxyLogCommandsListView.as_view(), name='proxy-log-commands-list'),
|
||||||
url(r'^command-log$', views.CommandLogListView.as_view(), name='command-log-list'),
|
url(r'^command-log$', views.CommandLogListView.as_view(), name='command-log-list'),
|
||||||
|
url(r'^login-log$', views.LoginLogListView.as_view(), name='login-log-list'),
|
||||||
]
|
]
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
|
|
|
@ -10,16 +10,15 @@ from .models import LoginLog
|
||||||
|
|
||||||
def validate_ip(ip):
|
def validate_ip(ip):
|
||||||
try:
|
try:
|
||||||
ipaddress.ip_address(ip)
|
ipaddress.ip_address(ip.decode('utf-8'))
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
print('valid error')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def write_login_log(username, name='', login_type='W',
|
def write_login_log(username, name='', login_type='W',
|
||||||
terminal='', login_ip='', user_agent=''):
|
terminal='', login_ip='', user_agent=''):
|
||||||
print(login_ip)
|
|
||||||
if not (login_ip and validate_ip(login_ip)):
|
if not (login_ip and validate_ip(login_ip)):
|
||||||
login_ip = '0.0.0.0'
|
login_ip = '0.0.0.0'
|
||||||
if not name:
|
if not name:
|
||||||
|
@ -29,11 +28,11 @@ def write_login_log(username, name='', login_type='W',
|
||||||
terminal=terminal, login_city=login_city, user_agent=user_agent)
|
terminal=terminal, login_city=login_city, user_agent=user_agent)
|
||||||
|
|
||||||
|
|
||||||
def get_ip_city(ip, timeout=3):
|
def get_ip_city(ip, timeout=10):
|
||||||
# Taobao ip api: http://ip.taobao.com//service/getIpInfo.php?ip=8.8.8.8
|
# Taobao ip api: http://ip.taobao.com//service/getIpInfo.php?ip=8.8.8.8
|
||||||
# Sina ip api: http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=8.8.8.8&format=js
|
# Sina ip api: http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=8.8.8.8&format=js
|
||||||
|
|
||||||
url = 'http://ip.taobao.com//service/getIpInfo.php?ip=' + ip
|
url = 'http://ip.taobao.com/service/getIpInfo.php?ip=' + ip
|
||||||
r = requests.get(url, timeout=timeout)
|
r = requests.get(url, timeout=timeout)
|
||||||
city = 'Unknown'
|
city = 'Unknown'
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.urls import reverse_lazy
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from .models import ProxyLog, CommandLog
|
from .models import ProxyLog, CommandLog, LoginLog
|
||||||
from .hands import User, Asset, SystemUser, AdminUserRequiredMixin
|
from .hands import User, Asset, SystemUser, AdminUserRequiredMixin
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,3 +151,43 @@ class CommandLogListView(AdminUserRequiredMixin, ListView):
|
||||||
}
|
}
|
||||||
kwargs.update(context)
|
kwargs.update(context)
|
||||||
return super(CommandLogListView, self).get_context_data(**kwargs)
|
return super(CommandLogListView, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class LoginLogListView(AdminUserRequiredMixin, ListView):
|
||||||
|
model = LoginLog
|
||||||
|
template_name = 'audits/login_log_list.html'
|
||||||
|
context_object_name = 'login_log_list'
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
self.queryset = super(LoginLogListView, self).get_queryset()
|
||||||
|
self.keyword = keyword = self.request.GET.get('keyword', '')
|
||||||
|
self.username = username = self.request.GET.get('username', '')
|
||||||
|
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(date_login__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(date_login__lt=date_to)
|
||||||
|
if username:
|
||||||
|
self.queryset = self.queryset.filter(username=username)
|
||||||
|
if keyword:
|
||||||
|
self.queryset = self.queryset.filter(Q(username__contains=keyword) |
|
||||||
|
Q(name__icontains=keyword) |
|
||||||
|
Q(login_ip=keyword)).distinct()
|
||||||
|
return self.queryset
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = {
|
||||||
|
'app': _('Audits'),
|
||||||
|
'action': _('Proxy log list'),
|
||||||
|
'user_list': User.objects.all().order_by('username'),
|
||||||
|
'keyword': self.keyword,
|
||||||
|
'date_from': self.date_from_s,
|
||||||
|
'date_to': self.date_to_s,
|
||||||
|
'username': self.username,
|
||||||
|
}
|
||||||
|
kwargs.update(context)
|
||||||
|
return super(LoginLogListView, self).get_context_data(**kwargs)
|
||||||
|
|
|
@ -323,7 +323,9 @@ jumpserver.initDataTable = function (options) {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
columnDefs: columnDefs,
|
columnDefs: columnDefs,
|
||||||
select: options.select || {style: 'multi'},
|
// select: 'single',
|
||||||
|
// select: options.select || {style: 'single'},
|
||||||
|
// select: false,
|
||||||
ajax: {
|
ajax: {
|
||||||
url: options.ajax_url ,
|
url: options.ajax_url ,
|
||||||
dataSrc: ""
|
dataSrc: ""
|
||||||
|
@ -331,16 +333,16 @@ jumpserver.initDataTable = function (options) {
|
||||||
columns: options.columns || [],
|
columns: options.columns || [],
|
||||||
lengthMenu: [[15, 25, 50, -1], [15, 25, 50, "All"]]
|
lengthMenu: [[15, 25, 50, -1], [15, 25, 50, "All"]]
|
||||||
});
|
});
|
||||||
table.on('select', function(e, dt, type, indexes) {
|
// table.on('select', function(e, dt, type, indexes) {
|
||||||
var $node = table[ type ]( indexes ).nodes().to$();
|
// var $node = table[ type ]( indexes ).nodes().to$();
|
||||||
$node.find('input.ipt_check').prop('checked', true);
|
// $node.find('input.ipt_check').prop('checked', true);
|
||||||
}).on('deselect', function(e, dt, type, indexes) {
|
// }).on('deselect', function(e, dt, type, indexes) {
|
||||||
var $node = table[ type ]( indexes ).nodes().to$();
|
// var $node = table[ type ]( indexes ).nodes().to$();
|
||||||
$node.find('input.ipt_check').prop('checked', false);
|
// $node.find('input.ipt_check').prop('checked', false);
|
||||||
}).on('draw', function(){
|
// }).on('draw', function(){
|
||||||
$('#op').html(options.op_html || '');
|
// $('#op').html(options.op_html || '');
|
||||||
$('#uc').html(options.uc_html || '');
|
// $('#uc').html(options.uc_html || '');
|
||||||
});
|
// });
|
||||||
$('.ipt_check_all').on('click', function() {
|
$('.ipt_check_all').on('click', function() {
|
||||||
if (!jumpserver.checked) {
|
if (!jumpserver.checked) {
|
||||||
$(this).closest('table').find('.ipt_check').prop('checked', true);
|
$(this).closest('table').find('.ipt_check').prop('checked', true);
|
||||||
|
|
|
@ -48,10 +48,10 @@
|
||||||
<li id="command-log">
|
<li id="command-log">
|
||||||
<a href="{% url 'audits:command-log-list' %}">{% trans 'Command log' %}</a>
|
<a href="{% url 'audits:command-log-list' %}">{% trans 'Command log' %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li id="login">
|
<li id="login-log">
|
||||||
<a href="{% url 'perms:asset-permission-list' %}">{% trans 'Login log' %}</a>
|
<a href="{% url 'audits:login-log-list' %}">{% trans 'Login log' %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li id="admin">
|
<li id="admin-log">
|
||||||
<a href="{% url 'perms:asset-permission-list' %}">{% trans 'Admin log' %}</a>
|
<a href="{% url 'perms:asset-permission-list' %}">{% trans 'Admin log' %}</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,6 @@
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'users:user-granted-asset' pk=user.id %}" class="text-center"><i class="fa fa-cubes"></i> {% trans 'Asset granted' %}</a>
|
<a href="{% url 'users:user-granted-asset' pk=user.id %}" class="text-center"><i class="fa fa-cubes"></i> {% trans 'Asset granted' %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
|
||||||
<a href="{% url 'users:user-login-history' pk=user.id %}" class="text-center"><i class="fa fa-calculator-o"></i> {% trans 'Login history' %}</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
<a href="{% url 'users:user-asset-permission' pk=user.id %}" class="text-center"><i class="fa fa-bar-chart-o"></i> {% trans 'Asset permission' %}</a>
|
<a href="{% url 'users:user-asset-permission' pk=user.id %}" class="text-center"><i class="fa fa-bar-chart-o"></i> {% trans 'Asset permission' %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="{% url 'users:user-granted-asset' pk=user.id %}" class="text-center"><i class="fa fa-cubes"></i> {% trans 'Asset granted' %}</a></li>
|
<li><a href="{% url 'users:user-granted-asset' pk=user.id %}" class="text-center"><i class="fa fa-cubes"></i> {% trans 'Asset granted' %}</a></li>
|
||||||
<li><a href="{% url 'users:user-login-history' pk=user.id %}" class="text-center"><i class="fa fa-calculator-o"></i> {% trans 'Login history' %}</a></li>
|
|
||||||
<li class="pull-right">
|
<li class="pull-right">
|
||||||
<a class="btn btn-outline btn-default" href="{% url 'users:user-update' pk=user.id %}"><i class="fa fa-edit"></i>Update</a>
|
<a class="btn btn-outline btn-default" href="{% url 'users:user-update' pk=user.id %}"><i class="fa fa-edit"></i>Update</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -25,9 +25,6 @@
|
||||||
<li class="active">
|
<li class="active">
|
||||||
<a href="{% url 'users:user-granted-asset' pk=user.id %}" class="text-center"><i class="fa fa-cubes"></i> {% trans 'Asset granted' %}</a>
|
<a href="{% url 'users:user-granted-asset' pk=user.id %}" class="text-center"><i class="fa fa-cubes"></i> {% trans 'Asset granted' %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
|
||||||
<a href="{% url 'users:user-login-history' pk=user.id %}" class="text-center"><i class="fa fa-calculator-o"></i> {% trans 'Login history' %}</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
|
|
|
@ -54,7 +54,7 @@ $(document).ready(function(){
|
||||||
}},
|
}},
|
||||||
{targets: 4, createdCell: function (td, cellData) {
|
{targets: 4, createdCell: function (td, cellData) {
|
||||||
var innerHtml = cellData.length > 20 ? cellData.substring(0, 20) + '...': cellData;
|
var innerHtml = cellData.length > 20 ? cellData.substring(0, 20) + '...': cellData;
|
||||||
$(td).html('<a href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</a>');
|
$(td).html('<span href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</span>');
|
||||||
}},
|
}},
|
||||||
{targets: 6, createdCell: function (td, cellData) {
|
{targets: 6, createdCell: function (td, cellData) {
|
||||||
if (!cellData) {
|
if (!cellData) {
|
||||||
|
|
|
@ -13,4 +13,5 @@ sshpubkeys==2.2.0
|
||||||
djangorestframework-bulk==0.2.1
|
djangorestframework-bulk==0.2.1
|
||||||
paramiko==2.0.2
|
paramiko==2.0.2
|
||||||
django-redis-cache==1.7.1
|
django-redis-cache==1.7.1
|
||||||
requests==2.11.1
|
requests==2.11.1
|
||||||
|
itsdangerous==0.24
|
Loading…
Reference in New Issue