Commit 61648967 authored by ibuler's avatar ibuler

Update some thing

parent bb9a0672
...@@ -11,7 +11,7 @@ from .serializers import TerminalSerializer, TerminalHeatbeatSerializer ...@@ -11,7 +11,7 @@ from .serializers import TerminalSerializer, TerminalHeatbeatSerializer
from .hands import IsSuperUserOrTerminalUser from .hands import IsSuperUserOrTerminalUser
class TerminalApi(ListCreateAPIView): class TerminalCreateListApi(ListCreateAPIView):
queryset = Terminal.objects.all() queryset = Terminal.objects.all()
serializer_class = TerminalSerializer serializer_class = TerminalSerializer
permission_classes = (AllowAny,) permission_classes = (AllowAny,)
...@@ -21,20 +21,20 @@ class TerminalApi(ListCreateAPIView): ...@@ -21,20 +21,20 @@ class TerminalApi(ListCreateAPIView):
if name: if name:
terminal = get_object_or_none(Terminal, name=name) terminal = get_object_or_none(Terminal, name=name)
if terminal: if terminal:
if terminal.is_accepted and terminal.is_active: if terminal.is_active:
return Response(data={'data': {'name': name, 'id': terminal.id}, return Response(data={'data': {'name': name, 'id': terminal.id},
'msg': 'Success'}, 'msg': 'Success'},
status=200) status=200)
else: else:
return Response(data={'data': {'name': name, 'ip': terminal.ip}, return Response(data={'data': {'name': name, 'ip': terminal.ip},
'msg': 'Need admin accept or active it'}, 'msg': 'Need admin active it'},
status=203) status=203)
else: else:
ip = request.META.get('X-Real-IP') or request.META.get('REMOTE_ADDR') ip = request.META.get('X-Real-IP') or request.META.get('REMOTE_ADDR')
terminal = Terminal.objects.create(name=name, ip=ip) terminal = Terminal.objects.create(name=name, ip=ip)
return Response(data={'data': {'name': name, 'ip': terminal.ip}, return Response(data={'data': {'name': name, 'ip': terminal.ip},
'msg': 'Need admin accept or active it'}, 'msg': 'Need admin active it'},
status=204) status=204)
else: else:
return Response(data={'msg': 'Secrete key invalid'}, status=401) return Response(data={'msg': 'Secrete key invalid'}, status=401)
......
# ~*~ coding: utf-8 ~*~
#
from django import forms
from django.utils.translation import ungettext_lazy as _
from .models import Terminal
class TerminalForm(forms.ModelForm):
class Meta:
model = Terminal
fields = ['name', 'ip', 'is_active', 'type', 'url', 'comment']
help_texts = {
'url': 'Example: ssh://192.168.1.1:22 or http://jms.jumpserver.org, that user login'
}
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
# #
from users.backends import IsSuperUserOrTerminalUser from users.backends import IsSuperUserOrTerminalUser
from audits.models import ProxyLog
...@@ -15,13 +15,10 @@ class Terminal(models.Model): ...@@ -15,13 +15,10 @@ class Terminal(models.Model):
ip = models.GenericIPAddressField(verbose_name=_('From ip')) ip = models.GenericIPAddressField(verbose_name=_('From ip'))
is_active = models.BooleanField(default=False, verbose_name=_('Is active')) is_active = models.BooleanField(default=False, verbose_name=_('Is active'))
is_bound_ip = models.BooleanField(default=False, verbose_name=_('Is bound ip')) is_bound_ip = models.BooleanField(default=False, verbose_name=_('Is bound ip'))
heatbeat_interval = models.IntegerField(default=60, verbose_name=_('Heatbeat interval'))
type = models.CharField(choices=TYPE_CHOICES, max_length=2, verbose_name=_('Terminal type')) type = models.CharField(choices=TYPE_CHOICES, max_length=2, verbose_name=_('Terminal type'))
url = models.CharField(max_length=100, verbose_name=_('URL to login')) url = models.CharField(max_length=100, verbose_name=_('URL to login'))
mail_to = models.ManyToManyField(User, verbose_name=_('Mail to'))
is_accepted = models.BooleanField(default=False, verbose_name=_('Is accepted'))
date_created = models.DateTimeField(auto_now_add=True) date_created = models.DateTimeField(auto_now_add=True)
comment = models.TextField(verbose_name=_('Comment')) comment = models.TextField(blank=True, verbose_name=_('Comment'))
def is_valid(self): def is_valid(self):
return self.is_active and self.is_accepted return self.is_active and self.is_accepted
...@@ -36,7 +33,7 @@ class Terminal(models.Model): ...@@ -36,7 +33,7 @@ class Terminal(models.Model):
class Meta: class Meta:
db_table = 'terminal' db_table = 'terminal'
ordering = ['name'] ordering = ['is_active']
class TerminalHeatbeat(models.Model): class TerminalHeatbeat(models.Model):
......
...@@ -4,13 +4,20 @@ ...@@ -4,13 +4,20 @@
from rest_framework import serializers from rest_framework import serializers
from .models import Terminal, TerminalHeatbeat from .models import Terminal, TerminalHeatbeat
from .hands import ProxyLog
class TerminalSerializer(serializers.ModelSerializer): class TerminalSerializer(serializers.ModelSerializer):
proxy_amount = serializers.SerializerMethodField()
class Meta: class Meta:
model = Terminal model = Terminal
fields = ['name', 'ip', 'type', 'url', 'comment', 'is_active', 'is_accepted', fields = ['id', 'name', 'ip', 'type', 'url', 'comment', 'is_active',
'get_type_display'] 'get_type_display', 'proxy_amount']
@staticmethod
def get_proxy_amount(obj):
return ProxyLog.objects.filter(terminal=obj.name, is_finished=False).count()
class TerminalHeatbeatSerializer(serializers.ModelSerializer): class TerminalHeatbeatSerializer(serializers.ModelSerializer):
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<th class="text-center">{% trans 'Name' %}</th> <th class="text-center">{% trans 'Name' %}</th>
<th class="text-center">{% trans 'IP' %}</th> <th class="text-center">{% trans 'IP' %}</th>
<th class="text-center">{% trans 'Type' %}</th> <th class="text-center">{% trans 'Type' %}</th>
<th class="text-center">{% trans 'url' %}</th> <th class="text-center">{% trans 'proxy_amount' %}</th>
<th class="text-center">{% trans 'Active' %}</th> <th class="text-center">{% trans 'Active' %}</th>
<th class="text-center">{% trans 'Action' %}</th> <th class="text-center">{% trans 'Action' %}</th>
</tr> </tr>
...@@ -36,41 +36,37 @@ ...@@ -36,41 +36,37 @@
</tbody> </tbody>
</table> </table>
{% endblock %} {% endblock %}
{% block content_bottom_left %}{% 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>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
var options = { var options = {
ele: $('#terminal_list_table'), ele: $('#terminal_list_table'),
{# columnDefs: [#} columnDefs: [
{# {targets: 1, createdCell: function (td, cellData, rowData) {#} {targets: 1, createdCell: function (td, cellData, rowData) {
{# 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) {#} {targets: 4, createdCell: function (td, cellData) {
{# var innerHtml = cellData.length > 8 ? cellData.substring(0, 8) + '...': cellData;#} var innerHtml = cellData.length > 8 ? cellData.substring(0, 8) + '...': cellData;
{# $(td).html('<a href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</a>');#} $(td).html('<a href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</a>');
{# }},#} }},
{# {targets: 6, 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>')
{# } else {#} } else {
{# $(td).html('<i class="fa fa-check text-navy"></i>')#} $(td).html('<i class="fa fa-check text-navy"></i>')
{# }#} }
{# }},#} }},
{# {targets: 7, createdCell: function (td, cellData, rowData) {#} {targets: 6, createdCell: function (td, cellData, rowData) {
{# var update_btn = '<a href="{% url "users:user-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'.replace('99991937', cellData);#} var update_btn = '<a href="{% url "terminal:terminal-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'.replace('99991937', cellData);
{# var del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="99991937">{% trans "Delete" %}</a>'.replace('99991937', cellData);#} var del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="99991937">{% trans "Delete" %}</a>'.replace('99991937', cellData);
{# if (rowData.id === 1) {#} $(td).html(update_btn + del_btn)
{# $(td).html(update_btn)#} }}
{# } else {#} ],
{# $(td).html(update_btn + del_btn)#}
{# }}],#}
{# ],#}
ajax_url: '{% url "terminal:terminal-list-create-api" %}', ajax_url: '{% url "terminal:terminal-list-create-api" %}',
columns: [{data: function(){return ""}}, {data: "name" }, {data: "ip" }, {data: "get_type_display" }, {data: "url" }, columns: [{data: function(){return ""}}, {data: "name" }, {data: "ip" }, {data: "get_type_display" },
{data: "is_active" }, {data: "ip"}], {data: "proxy_amount"}, {data: "is_active" }, {data: "id"}],
op_html: $('#actions').html() op_html: $('#actions').html()
}; };
jumpserver.initDataTable(options); jumpserver.initDataTable(options);
......
{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% load bootstrap %}
{% block custom_head_css_js %}
<link href="{% static "css/plugins/select2/select2.min.css" %}" rel="stylesheet">
<script src="{% static "js/plugins/select2/select2.full.min.js" %}"></script>
<link href="{% static "css/plugins/datepicker/datepicker3.css" %}" rel="stylesheet">
{% endblock %}
{% block content %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-sm-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>{{ action }}</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<form method="post" class="form-horizontal" action="" enctype="multipart/form-data">
{% csrf_token %}
<h3>{% trans 'Info' %}</h3>
{{ form.name|bootstrap_horizontal }}
{{ form.ip|bootstrap_horizontal }}
{{ form.type|bootstrap_horizontal }}
{{ form.url|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
<h3>{% trans 'Other' %}</h3>
<div class="form-group">
<label for="{{ form.is_active.id_for_label }}" class="col-sm-2 control-label">{% trans 'Active' %}</label>
<div class="col-sm-8">
{{ form.is_active}}
</div>
</div>
{{ form.comment|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-white" type="reset">{% trans 'Reset' %}</button>
<button id="submit_button" class="btn btn-primary" type="submit">{% trans 'Submit' %}</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
<script src="{% static 'js/plugins/datapicker/bootstrap-datepicker.js' %}"></script>
<script>
$(document).ready(function () {
$('.select2').select2();
$('.input-group.date').datepicker({
format: "yyyy-mm-dd",
todayBtn: "linked",
keyboardNavigation: false,
forceParse: false,
calendarWeeks: true,
autoclose: true
});
})
</script>
{% endblock %}
...@@ -11,9 +11,10 @@ app_name = 'terminal' ...@@ -11,9 +11,10 @@ app_name = 'terminal'
urlpatterns = [ urlpatterns = [
url(r'^terminal$', views.TerminalListView.as_view(), name='terminal-list'), url(r'^terminal$', views.TerminalListView.as_view(), name='terminal-list'),
url(r'^terminal/(?P<pk>\d+)/update$', views.TerminalUpdateView.as_view(), name='terminal-update'),
] ]
urlpatterns += [ urlpatterns += [
url(r'^v1/terminal/$', api.TerminalApi.as_view(), name='terminal-list-create-api'), url(r'^v1/terminal/$', api.TerminalCreateListApi.as_view(), name='terminal-list-create-api'),
url(r'^v1/terminal-heatbeat/$', api.TerminalHeatbeatApi.as_view(), name='terminal-heatbeat-api'), url(r'^v1/terminal-heatbeat/$', api.TerminalHeatbeatApi.as_view(), name='terminal-heatbeat-api'),
] ]
# ~*~ coding: utf-8 ~*~ # ~*~ coding: utf-8 ~*~
# #
from django.views.generic import ListView from django.views.generic import ListView, UpdateView
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.urls import reverse_lazy
from .models import Terminal from .models import Terminal
from .forms import TerminalForm
class TerminalListView(ListView): class TerminalListView(ListView):
...@@ -15,3 +17,15 @@ class TerminalListView(ListView): ...@@ -15,3 +17,15 @@ class TerminalListView(ListView):
context = super(TerminalListView, self).get_context_data(**kwargs) context = super(TerminalListView, self).get_context_data(**kwargs)
context.update({'app': _('Terminal'), 'action': _('Terminal list')}) context.update({'app': _('Terminal'), 'action': _('Terminal list')})
return context return context
class TerminalUpdateView(UpdateView):
model = Terminal
form_class = TerminalForm
template_name = 'terminal/terminal_update.html'
success_url = reverse_lazy('terminal:terminal-list')
def get_context_data(self, **kwargs):
context = super(TerminalUpdateView, self).get_context_data(**kwargs)
context.update({'app': _('Terminal'), 'action': _('Update terminal')})
return context
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
<th class="text-center"> <th class="text-center">
<div class="checkbox checkbox-default"><input id="" type="checkbox" class="ipt_check_all"><label></label></div> <div class="checkbox checkbox-default"><input id="" type="checkbox" class="ipt_check_all"><label></label></div>
</th> </th>
<th class="text-center">{% trans 'Name' %}</a></th> <th class="text-center">{% trans 'Name' %}</th>
<th class="text-center">{% trans 'Username' %}</a></th> <th class="text-center">{% trans 'Username' %}</th>
<th class="text-center">{% trans 'Role' %}</th> <th class="text-center">{% trans 'Role' %}</th>
<th class="text-center">{% trans 'User group' %}</th> <th class="text-center">{% trans 'User group' %}</th>
<th class="text-center">{% trans 'Asset num' %}</th> <th class="text-center">{% trans 'Asset num' %}</th>
<th class="text-center">{% trans 'Active' %}</a></th> <th class="text-center">{% trans 'Active' %}</th>
</tr> </tr>
</thead> </thead>
</table> </table>
......
...@@ -92,7 +92,7 @@ $(document).ready(function(){ ...@@ -92,7 +92,7 @@ $(document).ready(function(){
jumpserver.initDataTable(options); jumpserver.initDataTable(options);
}).on('click', '#btn_bulk_update', function(){ }).on('click', '#btn_bulk_update', function(){
var action = $('#slct_bulk_update').val(); var action = $('#slct_bulk_update').val();
var $data_table = $('#user_list_table').DataTable() var $data_table = $('#user_list_table').DataTable();
var id_list = []; var id_list = [];
var plain_id_list = []; var plain_id_list = [];
$data_table.rows({selected: true}).every(function(){ $data_table.rows({selected: true}).every(function(){
...@@ -101,7 +101,7 @@ $(document).ready(function(){ ...@@ -101,7 +101,7 @@ $(document).ready(function(){
}); });
if (id_list === []) { if (id_list === []) {
return false; return false;
}; }
var the_url = "{% url 'users:user-bulk-update-api' %}"; var the_url = "{% url 'users:user-bulk-update-api' %}";
function doDeactive() { function doDeactive() {
var body = $.each(id_list, function(index, user_object) { var body = $.each(id_list, function(index, user_object) {
......
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