mirror of https://github.com/jumpserver/jumpserver
[Update] 添加celery task log view
parent
9b2c5cb305
commit
420f3c0c4c
|
@ -31,6 +31,7 @@ api_v2 = [
|
||||||
|
|
||||||
app_view_patterns = [
|
app_view_patterns = [
|
||||||
path('auth/', include('authentication.urls.view_urls'), name='auth'),
|
path('auth/', include('authentication.urls.view_urls'), name='auth'),
|
||||||
|
path('ops/', include('ops.urls.view_urls'), name='ops')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
{% load static %}
|
||||||
|
{% load i18n %}
|
||||||
|
<head>
|
||||||
|
<title>{% trans 'Task log' %}</title>
|
||||||
|
<script src="{% static 'js/jquery-3.1.1.min.js' %}"></script>
|
||||||
|
<script src="{% static 'js/plugins/xterm/xterm.js' %}"></script>
|
||||||
|
<script src="{% static 'js/plugins/xterm/addons/fit/fit.js' %}"></script>
|
||||||
|
<link rel="stylesheet" href="{% static 'js/plugins/xterm/xterm.css' %}" />
|
||||||
|
<link rel="shortcut icon" href="{{ FAVICON_URL }}" type="image/x-icon">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.xterm-rows {
|
||||||
|
font-family: "Bitstream Vera Sans Mono", Monaco, "Consolas", Courier, monospace;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal .xterm-viewport {
|
||||||
|
background-color: #1f1b1b;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
body ::-webkit-scrollbar-track {
|
||||||
|
-webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.3);
|
||||||
|
background-color: #272323;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
body ::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
body ::-webkit-scrollbar-thumb {
|
||||||
|
background-color: #494141;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<div id="term" style="height: 100%;width: 100%">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var scheme = document.location.protocol === "https:" ? "wss" : "ws";
|
||||||
|
var port = document.location.port ? ":" + document.location.port : "";
|
||||||
|
var taskId = "{{ task_id }}";
|
||||||
|
var url = "/ws/ops/tasks/log/";
|
||||||
|
var wsURL = scheme + "://" + document.location.hostname + port + url;
|
||||||
|
var failOverPort = "{{ ws_port }}";
|
||||||
|
var failOverWsURL = scheme + "://" + document.location.hostname + ':' + failOverPort + url;
|
||||||
|
var term;
|
||||||
|
var ws;
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
term = new Terminal({
|
||||||
|
cursorBlink: false,
|
||||||
|
screenKeys: false,
|
||||||
|
fontFamily: '"Monaco", "Consolas", "monospace"',
|
||||||
|
fontSize: 13,
|
||||||
|
lineHeight: 1.2,
|
||||||
|
rightClickSelectsWord: true,
|
||||||
|
disableStdin: true
|
||||||
|
});
|
||||||
|
term.open(document.getElementById('term'));
|
||||||
|
window.fit.fit(term);
|
||||||
|
|
||||||
|
ws = new WebSocket(wsURL);
|
||||||
|
ws.onmessage = function(e) {
|
||||||
|
var data = JSON.parse(e.data);
|
||||||
|
term.write(data.message);
|
||||||
|
};
|
||||||
|
ws.onopen = function() {
|
||||||
|
var msg = {"task": taskId};
|
||||||
|
ws.send(JSON.stringify(msg))
|
||||||
|
};
|
||||||
|
ws.onerror = function (e) {
|
||||||
|
ws = new WebSocket(failOverWsURL);
|
||||||
|
ws.onmessage = function(e) {
|
||||||
|
var data = JSON.parse(e.data);
|
||||||
|
term.write(data.message);
|
||||||
|
};
|
||||||
|
ws.onerror = function (e) {
|
||||||
|
term.write("Connect websocket server error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).on('resize', window, function () {
|
||||||
|
window.fit.fit(term);
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -1,9 +1,14 @@
|
||||||
# ~*~ coding: utf-8 ~*~
|
# ~*~ coding: utf-8 ~*~
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from .. import views
|
||||||
|
|
||||||
__all__ = ["urlpatterns"]
|
__all__ = ["urlpatterns"]
|
||||||
|
|
||||||
app_name = "ops"
|
app_name = "ops"
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
]
|
# Resource Task url
|
||||||
|
path('celery/task/<uuid:pk>/log/', views.CeleryTaskLogView.as_view(), name='celery-task-log'),
|
||||||
|
]
|
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
from django.views.generic import TemplateView
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
from common.permissions import PermissionsMixin, IsOrgAdmin, IsOrgAuditor
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['CeleryTaskLogView']
|
||||||
|
|
||||||
|
|
||||||
|
class CeleryTaskLogView(PermissionsMixin, TemplateView):
|
||||||
|
template_name = 'ops/celery_task_log.html'
|
||||||
|
permission_classes = [IsOrgAdmin | IsOrgAuditor]
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context.update({
|
||||||
|
'task_id': self.kwargs.get('pk'),
|
||||||
|
'ws_port': settings.WS_LISTEN_PORT
|
||||||
|
})
|
||||||
|
return context
|
Loading…
Reference in New Issue