mirror of https://github.com/jumpserver/jumpserver
[Update] 增加批量终端session api
parent
0aa4755565
commit
af2db2d870
Binary file not shown.
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Jumpserver 0.3.3\n"
|
"Project-Id-Version: Jumpserver 0.3.3\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-03-06 17:57+0800\n"
|
"POT-Creation-Date: 2018-03-07 11:27+0800\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: ibuler <ibuler@qq.com>\n"
|
"Last-Translator: ibuler <ibuler@qq.com>\n"
|
||||||
"Language-Team: Jumpserver team<ibuler@qq.com>\n"
|
"Language-Team: Jumpserver team<ibuler@qq.com>\n"
|
||||||
|
@ -660,12 +660,6 @@ msgstr "更新"
|
||||||
msgid "Delete"
|
msgid "Delete"
|
||||||
msgstr "删除"
|
msgstr "删除"
|
||||||
|
|
||||||
#: assets/templates/assets/_system_user.html:16
|
|
||||||
#: assets/templates/assets/system_user_list.html:16
|
|
||||||
#: assets/views/system_user.py:45
|
|
||||||
msgid "Create system user"
|
|
||||||
msgstr "创建系统用户"
|
|
||||||
|
|
||||||
#: assets/templates/assets/_system_user.html:37
|
#: assets/templates/assets/_system_user.html:37
|
||||||
#: assets/templates/assets/asset_create.html:16
|
#: assets/templates/assets/asset_create.html:16
|
||||||
#: assets/templates/assets/asset_update.html:21
|
#: assets/templates/assets/asset_update.html:21
|
||||||
|
@ -762,12 +756,6 @@ msgstr "测试"
|
||||||
msgid "Task has been send, seen left asset status"
|
msgid "Task has been send, seen left asset status"
|
||||||
msgstr "任务已下发,查看左侧资产状态"
|
msgstr "任务已下发,查看左侧资产状态"
|
||||||
|
|
||||||
#: assets/templates/assets/admin_user_create_update.html:16
|
|
||||||
#: assets/templates/assets/admin_user_list.html:14
|
|
||||||
#: assets/views/admin_user.py:48
|
|
||||||
msgid "Create admin user"
|
|
||||||
msgstr "创建管理用户"
|
|
||||||
|
|
||||||
#: assets/templates/assets/admin_user_detail.html:83
|
#: assets/templates/assets/admin_user_detail.html:83
|
||||||
msgid "Replace node assets admin user with this"
|
msgid "Replace node assets admin user with this"
|
||||||
msgstr "替换资产的管理员"
|
msgstr "替换资产的管理员"
|
||||||
|
@ -788,6 +776,11 @@ msgstr "替换资产的管理员"
|
||||||
msgid "Confirm"
|
msgid "Confirm"
|
||||||
msgstr "确认"
|
msgstr "确认"
|
||||||
|
|
||||||
|
#: assets/templates/assets/admin_user_list.html:14
|
||||||
|
#: assets/views/admin_user.py:48
|
||||||
|
msgid "Create admin user"
|
||||||
|
msgstr "创建管理用户"
|
||||||
|
|
||||||
#: assets/templates/assets/admin_user_list.html:26
|
#: assets/templates/assets/admin_user_list.html:26
|
||||||
#: assets/templates/assets/system_user_list.html:28
|
#: assets/templates/assets/system_user_list.html:28
|
||||||
msgid "Unreachable"
|
msgid "Unreachable"
|
||||||
|
@ -979,6 +972,11 @@ msgstr "Uid"
|
||||||
msgid "Add to node"
|
msgid "Add to node"
|
||||||
msgstr "添加到节点"
|
msgstr "添加到节点"
|
||||||
|
|
||||||
|
#: assets/templates/assets/system_user_list.html:16
|
||||||
|
#: assets/views/system_user.py:45
|
||||||
|
msgid "Create system user"
|
||||||
|
msgstr "创建系统用户"
|
||||||
|
|
||||||
#: assets/templates/assets/system_user_list.html:131
|
#: assets/templates/assets/system_user_list.html:131
|
||||||
msgid "This will delete the selected System Users !!!"
|
msgid "This will delete the selected System Users !!!"
|
||||||
msgstr "删除选择系统用户"
|
msgstr "删除选择系统用户"
|
||||||
|
@ -1607,10 +1605,6 @@ msgstr "选择资产组"
|
||||||
msgid "Join"
|
msgid "Join"
|
||||||
msgstr "加入"
|
msgstr "加入"
|
||||||
|
|
||||||
#: perms/templates/perms/asset_permission_create_update.html:17
|
|
||||||
msgid "Create asset permission "
|
|
||||||
msgstr "创建资产权限"
|
|
||||||
|
|
||||||
#: perms/templates/perms/asset_permission_detail.html:66
|
#: perms/templates/perms/asset_permission_detail.html:66
|
||||||
msgid "User count"
|
msgid "User count"
|
||||||
msgstr "用户数量"
|
msgstr "用户数量"
|
||||||
|
@ -1783,7 +1777,7 @@ msgstr "Web终端"
|
||||||
|
|
||||||
#: templates/_nav.html:50 terminal/templates/terminal/session_list.html:75
|
#: templates/_nav.html:50 terminal/templates/terminal/session_list.html:75
|
||||||
#: terminal/views/command.py:47 terminal/views/session.py:75
|
#: terminal/views/command.py:47 terminal/views/session.py:75
|
||||||
#: terminal/views/session.py:92 terminal/views/session.py:114
|
#: terminal/views/session.py:93 terminal/views/session.py:115
|
||||||
#: terminal/views/terminal.py:31 terminal/views/terminal.py:46
|
#: terminal/views/terminal.py:31 terminal/views/terminal.py:46
|
||||||
#: terminal/views/terminal.py:58
|
#: terminal/views/terminal.py:58
|
||||||
msgid "Terminal"
|
msgid "Terminal"
|
||||||
|
@ -1896,7 +1890,7 @@ msgid "Goto"
|
||||||
msgstr "转到"
|
msgstr "转到"
|
||||||
|
|
||||||
#: terminal/templates/terminal/session_detail.html:17
|
#: terminal/templates/terminal/session_detail.html:17
|
||||||
#: terminal/views/session.py:115
|
#: terminal/views/session.py:116
|
||||||
msgid "Session detail"
|
msgid "Session detail"
|
||||||
msgstr "会话详情"
|
msgstr "会话详情"
|
||||||
|
|
||||||
|
@ -1939,10 +1933,8 @@ msgid "Terminate"
|
||||||
msgstr "终断"
|
msgstr "终断"
|
||||||
|
|
||||||
#: terminal/templates/terminal/session_list.html:116
|
#: terminal/templates/terminal/session_list.html:116
|
||||||
#, fuzzy
|
|
||||||
#| msgid "Deactive selected"
|
|
||||||
msgid "Terminate selected"
|
msgid "Terminate selected"
|
||||||
msgstr "禁用所选"
|
msgstr "终断所选"
|
||||||
|
|
||||||
#: terminal/templates/terminal/session_list.html:136
|
#: terminal/templates/terminal/session_list.html:136
|
||||||
msgid "Terminate task send, waiting ..."
|
msgid "Terminate task send, waiting ..."
|
||||||
|
@ -1991,7 +1983,7 @@ msgstr "信息"
|
||||||
msgid "Session online list"
|
msgid "Session online list"
|
||||||
msgstr "在线会话"
|
msgstr "在线会话"
|
||||||
|
|
||||||
#: terminal/views/session.py:93
|
#: terminal/views/session.py:94
|
||||||
msgid "Session offline list"
|
msgid "Session offline list"
|
||||||
msgstr "离线会话"
|
msgstr "离线会话"
|
||||||
|
|
||||||
|
@ -2653,3 +2645,6 @@ msgstr "密码更新"
|
||||||
#: users/views/user.py:374
|
#: users/views/user.py:374
|
||||||
msgid "Public key update"
|
msgid "Public key update"
|
||||||
msgstr "密钥更新"
|
msgstr "密钥更新"
|
||||||
|
|
||||||
|
#~ msgid "Create asset permission "
|
||||||
|
#~ msgstr "创建资产权限"
|
||||||
|
|
|
@ -13,7 +13,7 @@ from .views import IndexView, LunaView
|
||||||
schema_view = get_schema_view(title='Users API', renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer])
|
schema_view = get_schema_view(title='Users API', renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer])
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', IndexView.as_view(), name='index'),
|
url(r'^$', IndexView.as_view(), name='index'),
|
||||||
url(r'^luna/$', LunaView.as_view(), name='luna-error'),
|
url(r'^luna/', LunaView.as_view(), name='luna-error'),
|
||||||
url(r'^users/', include('users.urls.views_urls', namespace='users')),
|
url(r'^users/', include('users.urls.views_urls', namespace='users')),
|
||||||
url(r'^assets/', include('assets.urls.views_urls', namespace='assets')),
|
url(r'^assets/', include('assets.urls.views_urls', namespace='assets')),
|
||||||
url(r'^perms/', include('perms.urls.views_urls', namespace='perms')),
|
url(r'^perms/', include('perms.urls.views_urls', namespace='perms')),
|
||||||
|
|
|
@ -5,14 +5,15 @@ import logging
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from rest_framework import viewsets, serializers
|
|
||||||
from rest_framework.views import APIView, Response
|
|
||||||
from rest_framework.permissions import AllowAny
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.core.files.storage import default_storage
|
from django.core.files.storage import default_storage
|
||||||
from django.http import HttpResponseNotFound
|
from django.http import HttpResponseNotFound
|
||||||
|
from rest_framework import viewsets, serializers
|
||||||
|
from rest_framework.views import APIView, Response
|
||||||
|
from rest_framework.permissions import AllowAny
|
||||||
|
from rest_framework_bulk import BulkModelViewSet
|
||||||
|
|
||||||
from common.utils import get_object_or_none
|
from common.utils import get_object_or_none
|
||||||
from .models import Terminal, Status, Session, Task
|
from .models import Terminal, Status, Session, Task
|
||||||
|
@ -178,12 +179,29 @@ class SessionViewSet(viewsets.ModelViewSet):
|
||||||
return self.queryset
|
return self.queryset
|
||||||
|
|
||||||
|
|
||||||
class TaskViewSet(viewsets.ModelViewSet):
|
class TaskViewSet(BulkModelViewSet):
|
||||||
queryset = Task.objects.all()
|
queryset = Task.objects.all()
|
||||||
serializer_class = TaskSerializer
|
serializer_class = TaskSerializer
|
||||||
permission_classes = (IsSuperUserOrAppUser,)
|
permission_classes = (IsSuperUserOrAppUser,)
|
||||||
|
|
||||||
|
|
||||||
|
class KillSessionAPI(APIView):
|
||||||
|
permission_classes = (IsSuperUserOrAppUser,)
|
||||||
|
model = Task
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
validated_session = []
|
||||||
|
for session_id in request.data:
|
||||||
|
session = get_object_or_none(Session, id=session_id)
|
||||||
|
if session and not session.is_finished:
|
||||||
|
validated_session.append(session_id)
|
||||||
|
self.model.objects.create(
|
||||||
|
name="kill_session", args=session.id,
|
||||||
|
terminal=session.terminal,
|
||||||
|
)
|
||||||
|
return Response({"ok": validated_session})
|
||||||
|
|
||||||
|
|
||||||
class CommandViewSet(viewsets.ViewSet):
|
class CommandViewSet(viewsets.ViewSet):
|
||||||
"""接受app发送来的command log, 格式如下
|
"""接受app发送来的command log, 格式如下
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from rest_framework_bulk.serializers import BulkListSerializer
|
||||||
|
|
||||||
|
|
||||||
|
from common.mixins import BulkSerializerMixin
|
||||||
|
from common.utils import get_object_or_none
|
||||||
from .models import Terminal, Status, Session, Task
|
from .models import Terminal, Status, Session, Task
|
||||||
from .backends import get_multi_command_store
|
from .backends import get_multi_command_store
|
||||||
|
|
||||||
|
@ -47,6 +51,7 @@ class SessionSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Session
|
model = Session
|
||||||
|
list_serializer_class = BulkListSerializer
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
def get_command_amount(self, obj):
|
def get_command_amount(self, obj):
|
||||||
|
@ -60,11 +65,12 @@ class StatusSerializer(serializers.ModelSerializer):
|
||||||
model = Status
|
model = Status
|
||||||
|
|
||||||
|
|
||||||
class TaskSerializer(serializers.ModelSerializer):
|
class TaskSerializer(BulkSerializerMixin, serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
model = Task
|
model = Task
|
||||||
|
list_serializer_class = BulkListSerializer
|
||||||
|
|
||||||
|
|
||||||
class ReplaySerializer(serializers.Serializer):
|
class ReplaySerializer(serializers.Serializer):
|
||||||
|
|
|
@ -110,10 +110,10 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content_bottom_left %}
|
{% block content_bottom_left %}
|
||||||
<div id="actions" >
|
<div id="actions" {% if type != "online" %} style="display: none" {% endif %}>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<select class="form-control m-b" style="width: auto" id="slct_bulk_update">
|
<select class="form-control m-b" style="width: auto" id="slct_bulk_update">
|
||||||
<option value="delete">{% trans 'Terminate selected' %}</option>
|
<option value="terminate">{% trans 'Terminate selected' %}</option>
|
||||||
</select>
|
</select>
|
||||||
<div class="input-group-btn pull-left" style="padding-left: 5px;">
|
<div class="input-group-btn pull-left" style="padding-left: 5px;">
|
||||||
<button id='btn_bulk_update' style="height: 32px;" class="btn btn-sm btn-primary">
|
<button id='btn_bulk_update' style="height: 32px;" class="btn btn-sm btn-primary">
|
||||||
|
@ -134,7 +134,7 @@
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
var success_message = '{% trans "Terminate task send, waiting ..." %}';
|
var success_message = '{% trans "Terminate task send, waiting ..." %}';
|
||||||
var the_url = "{% url 'api-terminal:tasks-list' %}";
|
var the_url = "{% url 'api-terminal:kill-session' %}";
|
||||||
APIUpdateAttr({
|
APIUpdateAttr({
|
||||||
url: the_url,
|
url: the_url,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -165,14 +165,31 @@
|
||||||
}).on('click', '.btn-term', function () {
|
}).on('click', '.btn-term', function () {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var session_id = $this.attr('value');
|
var session_id = $this.attr('value');
|
||||||
var terminal_id = $this.attr('terminal');
|
var data = [
|
||||||
var data = {
|
session_id
|
||||||
name: "kill_session",
|
];
|
||||||
args: session_id,
|
|
||||||
terminal: terminal_id
|
|
||||||
};
|
|
||||||
terminateSession(data)
|
terminateSession(data)
|
||||||
})
|
}).on('click', '#btn_bulk_update', function () {
|
||||||
|
var action = $('#slct_bulk_update').val();
|
||||||
|
var id_list = [];
|
||||||
|
$(".cbx-term:checked").each(function (index, data) {
|
||||||
|
id_list.push($(data).attr("value"))
|
||||||
|
});
|
||||||
|
if (id_list.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function doTerminate() {
|
||||||
|
terminateSession(id_list)
|
||||||
|
}
|
||||||
|
switch(action) {
|
||||||
|
case 'terminate':
|
||||||
|
doTerminate();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ urlpatterns = [
|
||||||
url(r'^v1/sessions/(?P<pk>[0-9a-zA-Z\-]{36})/replay/$',
|
url(r'^v1/sessions/(?P<pk>[0-9a-zA-Z\-]{36})/replay/$',
|
||||||
api.SessionReplayViewSet.as_view({'get': 'retrieve', 'post': 'create'}),
|
api.SessionReplayViewSet.as_view({'get': 'retrieve', 'post': 'create'}),
|
||||||
name='session-replay'),
|
name='session-replay'),
|
||||||
|
url(r'^v1/tasks/kill-session/', api.KillSessionAPI.as_view(), name='kill-session'),
|
||||||
url(r'^v1/terminal/(?P<terminal>[a-zA-Z0-9\-]{36})/access-key', api.TerminalTokenApi.as_view(), name='terminal-access-key'),
|
url(r'^v1/terminal/(?P<terminal>[a-zA-Z0-9\-]{36})/access-key', api.TerminalTokenApi.as_view(), name='terminal-access-key'),
|
||||||
url(r'^v1/terminal/config', api.TerminalConfig.as_view(), name='terminal-config'),
|
url(r'^v1/terminal/config', api.TerminalConfig.as_view(), name='terminal-config'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -74,6 +74,7 @@ class SessionOnlineListView(SessionListView):
|
||||||
context = {
|
context = {
|
||||||
'app': _('Terminal'),
|
'app': _('Terminal'),
|
||||||
'action': _('Session online list'),
|
'action': _('Session online list'),
|
||||||
|
'type': 'online',
|
||||||
'now': timezone.now(),
|
'now': timezone.now(),
|
||||||
}
|
}
|
||||||
kwargs.update(context)
|
kwargs.update(context)
|
||||||
|
|
Loading…
Reference in New Issue