[Change] Rename applications -> terminal

pull/828/merge
ibuler 2017-12-01 17:28:47 +08:00
parent 19051d36dc
commit 61a8d95f46
37 changed files with 51 additions and 50 deletions

View File

@ -5,4 +5,4 @@ from users.utils import AdminUserRequiredMixin
from users.models import User
from assets.models import Asset, SystemUser
from users.permissions import IsSuperUserOrAppUser, IsAppUser
from applications.models import Terminal
from terminal.models import Terminal

View File

@ -33,7 +33,7 @@ app.conf.update(
'args': (),
},
'clean_terminal_history': {
'task': 'applications.tasks.clean_terminal_history',
'task': 'terminal.tasks.clean_terminal_history',
'schedule': 60*60*60,
'args': (),
}

View File

@ -9,7 +9,7 @@ from django.shortcuts import HttpResponse
DEMO_MODE = os.environ.get("DEMO_MODE", "")
SAFE_URL = r'^/users/login|^/api/applications/v1/.*|/api/audits/.*|/api/users/v1/auth/|/api/users/v1/profile/'
SAFE_URL = r'^/users/login|^/api/terminal/v1/.*|/api/audits/.*|/api/users/v1/auth/|/api/users/v1/profile/'
class TimezoneMiddleware(MiddlewareMixin):

View File

@ -61,7 +61,7 @@ INSTALLED_APPS = [
'ops.apps.OpsConfig',
'audits.apps.AuditsConfig',
'common.apps.CommonConfig',
'applications.apps.ApplicationsConfig',
'terminal.apps.ApplicationsConfig',
'rest_framework',
'rest_framework_swagger',
'django_filters',
@ -363,8 +363,8 @@ CAPTCHA_FOREGROUND_COLOR = '#001100'
CAPTCHA_NOISE_FUNCTIONS = ('captcha.helpers.noise_dots',)
CAPTCHA_TEST_MODE = CONFIG.CAPTCHA_TEST_MODE
COMMAND_STORE_BACKEND = 'applications.backends.command.db'
RECORD_STORE_BACKEND = 'applications.backends.replay.db'
COMMAND_STORE_BACKEND = 'terminal.backends.command.db'
RECORD_STORE_BACKEND = 'terminal.backends.replay.db'
# Django bootstrap3 setting, more see http://django-bootstrap3.readthedocs.io/en/latest/settings.html

View File

@ -17,7 +17,7 @@ urlpatterns = [
url(r'^assets/', include('assets.urls.views_urls', namespace='assets')),
url(r'^perms/', include('perms.urls.views_urls', namespace='perms')),
url(r'^audits/', include('audits.urls.views_urls', namespace='audits')),
url(r'^applications/', include('applications.urls.views_urls', namespace='applications')),
url(r'^terminal/', include('terminal.urls.views_urls', namespace='terminal')),
url(r'^ops/', include('ops.urls.view_urls', namespace='ops')),
# Api url view map
@ -25,7 +25,7 @@ urlpatterns = [
url(r'^api/assets/', include('assets.urls.api_urls', namespace='api-assets')),
url(r'^api/perms/', include('perms.urls.api_urls', namespace='api-perms')),
url(r'^api/audits/', include('audits.urls.api_urls', namespace='api-audits')),
url(r'^api/applications/', include('applications.urls.api_urls', namespace='api-applications')),
url(r'^api/terminal/', include('terminal.urls.api_urls', namespace='api-terminal')),
url(r'^api/ops/', include('ops.urls.api_urls', namespace='api-ops')),
url(r'^captcha/', include('captcha.urls')),

View File

@ -34,12 +34,12 @@
</ul>
</li>
<li id="applications">
<li id="terminal">
<a>
<i class="fa fa-rocket"></i> <span class="nav-label">{% trans 'Applications' %}</span><span class="fa arrow"></span>
<i class="fa fa-rocket"></i> <span class="nav-label">{% trans 'Terminal' %}</span><span class="fa arrow"></span>
</a>
<ul class="nav nav-second-level">
<li id="terminal"><a href="{% url 'applications:terminal-list' %}">{% trans 'Terminal' %}</a></li>
<li id="terminal"><a href="{% url 'terminal:terminal-list' %}">{% trans 'Terminal' %}</a></li>
</ul>
</li>

View File

@ -15,7 +15,7 @@ from django.utils import timezone
from django.conf import settings
from common.utils import get_object_or_none
from .models import Terminal, TerminalStatus, TerminalSession, TerminalTask
from .models import Terminal, Status, Session, Task
from .serializers import TerminalSerializer, TerminalStatusSerializer, \
TerminalSessionSerializer, TerminalTaskSerializer
from .hands import IsSuperUserOrAppUser, IsAppUser, ProxyLog, \
@ -65,7 +65,7 @@ class TerminalViewSet(viewsets.ModelViewSet):
class TerminalStatusViewSet(viewsets.ModelViewSet):
queryset = TerminalStatus.objects.all()
queryset = Status.objects.all()
serializer_class = TerminalStatusSerializer
permission_classes = (IsSuperUserOrAppUser,)
session_serializer_class = TerminalSessionSerializer
@ -79,7 +79,7 @@ class TerminalStatusViewSet(viewsets.ModelViewSet):
for session_data in self.request.data.get("sessions", []):
session_data["terminal"] = self.request.user.terminal.id
_id = session_data["id"]
session = get_object_or_none(TerminalSession, id=_id)
session = get_object_or_none(Session, id=_id)
if session:
serializer = TerminalSessionSerializer(data=session_data,
instance=session)
@ -95,7 +95,7 @@ class TerminalStatusViewSet(viewsets.ModelViewSet):
if not session_data["is_finished"]:
sessions_active.append(session_data["id"])
sessions_in_db_active = TerminalSession.objects.filter(
sessions_in_db_active = Session.objects.filter(
is_finished=False, terminal=self.request.user.terminal.id
)
@ -123,7 +123,7 @@ class TerminalStatusViewSet(viewsets.ModelViewSet):
class TerminalSessionViewSet(viewsets.ModelViewSet):
queryset = TerminalSession.objects.all()
queryset = Session.objects.all()
serializers_class = TerminalSessionSerializer
permission_classes = (IsSuperUserOrAppUser,)
@ -136,7 +136,7 @@ class TerminalSessionViewSet(viewsets.ModelViewSet):
class TerminalTaskViewSet(viewsets.ModelViewSet):
queryset = TerminalTask.objects.all()
queryset = Task.objects.all()
serializer_class = TerminalTaskSerializer
permission_classes = (IsSuperUserOrAppUser,)
@ -157,7 +157,7 @@ class SessionReplayAPI(APIView):
def post(self, request, **kwargs):
session_id = kwargs.get("pk", None)
session = get_object_or_404(TerminalSession, id=session_id)
session = get_object_or_404(Session, id=session_id)
record_dir = settings.CONFIG.SESSION_RECORDE_DIR
date = session.date_start.strftime("%Y-%m-%d")
record_dir = os.path.join(record_dir, date, str(session.id))

View File

@ -4,4 +4,4 @@ from django.apps import AppConfig
class ApplicationsConfig(AppConfig):
name = 'applications'
name = 'terminal'

View File

@ -9,8 +9,8 @@ from .base import CommandBase
class CommandStore(CommandBase):
def __init__(self):
from applications.models import SessionCommand
self.model = SessionCommand
from terminal.models import Command
self.model = Command
def save(self, command):
"""

View File

@ -58,9 +58,10 @@ class Terminal(models.Model):
class Meta:
ordering = ('is_accepted',)
db_table = "terminal"
class TerminalStatus(models.Model):
class Status(models.Model):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
session_online = models.IntegerField(verbose_name=_("Session Online"), default=0)
cpu_used = models.FloatField(verbose_name=_("CPU Usage"))
@ -75,7 +76,7 @@ class TerminalStatus(models.Model):
db_table = 'terminal_status'
class TerminalSession(models.Model):
class Session(models.Model):
LOGIN_FROM_CHOICES = (
('ST', 'SSH Terminal'),
('WT', 'Web Terminal'),
@ -100,7 +101,7 @@ class TerminalSession(models.Model):
return "{0.id} of {0.user} to {0.asset}".format(self)
class TerminalTask(models.Model):
class Task(models.Model):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
name = models.CharField(max_length=128, verbose_name=_("Name"))
args = models.CharField(max_length=1024, verbose_name=_("Task Args"))
@ -113,7 +114,7 @@ class TerminalTask(models.Model):
db_table = "terminal_task"
class SessionCommand(AbstractSessionCommand):
class Command(AbstractSessionCommand):
class Meta:
db_table = "session_command"
db_table = "terminal_command"

View File

@ -4,7 +4,7 @@
from django.utils import timezone
from rest_framework import serializers
from .models import Terminal, TerminalStatus, TerminalSession, TerminalTask
from .models import Terminal, Status, Session, Task
from .hands import ProxyLog
@ -19,7 +19,7 @@ class TerminalSerializer(serializers.ModelSerializer):
@staticmethod
def get_session_connected(obj):
return TerminalSession.objects.filter(terminal=obj.id, is_finished=False)
return Session.objects.filter(terminal=obj.id, is_finished=False)
@staticmethod
def get_is_alive(obj):
@ -33,7 +33,7 @@ class TerminalSerializer(serializers.ModelSerializer):
class TerminalSessionSerializer(serializers.ModelSerializer):
class Meta:
model = TerminalSession
model = Session
fields = '__all__'
@ -41,11 +41,11 @@ class TerminalStatusSerializer(serializers.ModelSerializer):
class Meta:
fields = '__all__'
model = TerminalStatus
model = Status
class TerminalTaskSerializer(serializers.ModelSerializer):
class Meta:
fields = '__all__'
model = TerminalTask
model = Task

View File

@ -39,7 +39,7 @@
<tbody>
</tbody>
</table>
{% include 'applications/terminal_modal_accept.html' %}
{% include 'terminal/terminal_modal_accept.html' %}
{% endblock %}
{% block custom_foot_js %}
@ -51,7 +51,7 @@ $(document).ready(function(){
buttons: [],
columnDefs: [
{targets: 1, createdCell: function (td, cellData, rowData) {
var detail_btn = '<a href="{% url "applications:terminal-detail" pk=99991937 %}">' + cellData + '</a>';
var detail_btn = '<a href="{% url "terminal:terminal-detail" pk=99991937 %}">' + cellData + '</a>';
$(td).html(detail_btn.replace('99991937', rowData.id));
}},
{targets: 6, createdCell: function (td, cellData) {
@ -69,7 +69,7 @@ $(document).ready(function(){
}
}},
{targets: 8, createdCell: function (td, cellData, rowData) {
var update_btn = '<a href="{% url "applications:terminal-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
var update_btn = '<a href="{% url "terminal:terminal-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.replace('99991937', cellData);
var delete_btn = '<a class="btn btn-xs btn-danger m-l-xs btn-del" data-id="99991937" data-name="99991938">{% trans "Delete" %}</a>'
.replace('99991937', cellData)
@ -94,7 +94,7 @@ $(document).ready(function(){
}
}}
],
ajax_url: '{% url "api-applications:terminal-list" %}',
ajax_url: '{% url "api-terminal:terminal-list" %}',
columns: [{data: function(){return ""}}, {data: "name" }, {data: "remote_addr" }, {data: "ssh_port"}, {data: "http_port"},
{data: "session_connected"}, {data: "is_accepted" }, {data: 'is_alive'}, {data: "id"}],
op_html: $('#actions').html()
@ -117,13 +117,13 @@ $(document).ready(function(){
var $this = $(this);
var id = $this.data('id');
var name = $(this).data('name');
var the_url = '{% url "api-applications:terminal-detail" pk=99991937 %}'.replace('99991937', id);
var the_url = '{% url "api-terminal:terminal-detail" pk=99991937 %}'.replace('99991937', id);
objectDelete($this, name, the_url)
}).on('click', '.btn-accept', function () {
var $this = $(this);
var terminal_id = $this.data('id');
var the_url = "{% url 'api-applications:terminal-detail' pk=99991937 %}".replace('99991937', terminal_id);
var the_url = "{% url 'api-terminal:terminal-detail' pk=99991937 %}".replace('99991937', terminal_id);
var post_url = $('#form_terminal_accept').attr('action').replace('99991937', terminal_id);
console.log(post_url);
$.ajax({

View File

@ -5,7 +5,7 @@
{% block modal_title%}{% trans "Accept terminal registration" %}{% endblock %}
{% block modal_body %}
{% load bootstrap3 %}
<form action="{% url 'applications:terminal-modal-accept' pk="99991937" %}" method="post" class="form-horizontal" id="form_terminal_accept" enctype="multipart/form-data">
<form action="{% url 'terminal:terminal-modal-accept' pk="99991937" %}" method="post" class="form-horizontal" id="form_terminal_accept" enctype="multipart/form-data">
{% csrf_token %}
<p class="alert alert-danger" id="modal-error" style="display: none"></p>
{% bootstrap_field form.name layout="horizontal" %}

View File

@ -7,7 +7,7 @@ from rest_framework import routers
from .. import api
app_name = 'applications'
app_name = 'terminal'
router = routers.DefaultRouter()
router.register(r'v1/terminal/(?P<terminal>[0-9]+)?/?status', api.TerminalStatusViewSet, 'terminal-status')

View File

@ -6,7 +6,7 @@ from django.conf.urls import url
from .. import views
app_name = 'applications'
app_name = 'terminal'
urlpatterns = [
url(r'^terminal/$', views.TerminalListView.as_view(), name='terminal-list'),

View File

@ -15,7 +15,7 @@ from .hands import AdminUserRequiredMixin
class TerminalListView(LoginRequiredMixin, ListView):
model = Terminal
template_name = 'applications/terminal_list.html'
template_name = 'terminal/terminal_list.html'
form_class = TerminalForm
def get_context_data(self, **kwargs):
@ -31,24 +31,24 @@ class TerminalListView(LoginRequiredMixin, ListView):
class TerminalUpdateView(AdminUserRequiredMixin, UpdateView):
model = Terminal
form_class = TerminalForm
template_name = 'applications/terminal_update.html'
success_url = reverse_lazy('applications:terminal-list')
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': _('Applications'), 'action': _('Update terminal')})
context.update({'app': _('Terminal'), 'action': _('Update terminal')})
return context
class TerminalDetailView(LoginRequiredMixin, DetailView):
model = Terminal
template_name = 'applications/terminal_detail.html'
template_name = 'terminal/terminal_detail.html'
context_object_name = 'terminal'
def get_context_data(self, **kwargs):
context = super(TerminalDetailView, self).get_context_data(**kwargs)
context.update({
'app': _('Applications'),
'app': _('Terminal'),
'action': _('Terminal detail')
})
return context
@ -57,13 +57,13 @@ class TerminalDetailView(LoginRequiredMixin, DetailView):
class TerminalDeleteView(AdminUserRequiredMixin, DeleteView):
model = Terminal
template_name = 'assets/delete_confirm.html'
success_url = reverse_lazy('applications:applications-list')
success_url = reverse_lazy('terminal:terminal-list')
class TerminalModelAccept(AdminUserRequiredMixin, JSONResponseMixin, UpdateView):
model = Terminal
form_class = TerminalForm
template_name = 'applications/terminal_modal_test.html'
template_name = 'Terminal/terminal_modal_test.html'
def form_valid(self, form):
terminal = form.save()
@ -103,7 +103,7 @@ class TerminalConnectView(LoginRequiredMixin, DetailView):
'messages': _('You should use your ssh client tools '
'connect terminal: {} <br /> <br />'
'{}'.format(self.object.name, self.object.url)),
'redirect_url': reverse('applications:terminal-list')
'redirect_url': reverse('terminal:terminal-list')
}
kwargs.update(context)

View File

@ -10,7 +10,7 @@
:license: GPL v2, see LICENSE for more details.
"""
from applications.models import Terminal
from terminal.models import Terminal
from audits.tasks import write_login_log_async
from users.models import User
# from perms.models import AssetPermission