mirror of https://github.com/jumpserver/jumpserver
Update table desgin doc and audit log
parent
0cda4e0905
commit
59727656c3
|
@ -1,5 +1,53 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
|
class LoginLog(models.Model):
|
||||||
|
LOGIN_TYPE_CHOICE = (
|
||||||
|
('S', 'ssh'),
|
||||||
|
('W', 'web'),
|
||||||
|
)
|
||||||
|
|
||||||
|
username = models.CharField(max_length=20, verbose_name=_('Username'))
|
||||||
|
name = models.CharField(max_length=20, blank=True, verbose_name=_('Name'))
|
||||||
|
login_type = models.CharField(choices=LOGIN_TYPE_CHOICE, max_length=1, verbose_name=_('Login type'))
|
||||||
|
login_ip = models.GenericIPAddressField(verbose_name=_('Login ip'))
|
||||||
|
login_city = models.CharField(max_length=100, blank=True, null=True, verbose_name=_('Login city'))
|
||||||
|
user_agent = models.CharField(max_length=100, blank=True, null=True, verbose_name=_('User agent'))
|
||||||
|
date_login = models.DateTimeField(auto_now=True, verbose_name=_('Date login'))
|
||||||
|
date_logout = models.DateTimeField(null=True, verbose_name=_('Date logout'))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = 'loginlog'
|
||||||
|
ordering = ['-date_login', 'username']
|
||||||
|
|
||||||
|
|
||||||
|
class ProxyLog(models.Model):
|
||||||
|
LOGIN_TYPE_CHOICE = (
|
||||||
|
('S', 'ssh'),
|
||||||
|
('W', 'web'),
|
||||||
|
)
|
||||||
|
|
||||||
|
username = models.CharField(max_length=20, verbose_name=_('Username'))
|
||||||
|
name = models.CharField(max_length=20, blank=True, verbose_name=_('Name'))
|
||||||
|
hostname = models.CharField(max_length=128, blank=True, verbose_name=_('Hostname'))
|
||||||
|
ip = models.GenericIPAddressField(max_length=32, verbose_name=_('IP'))
|
||||||
|
system_user = models.CharField(max_length=20, verbose_name=_('System user'))
|
||||||
|
login_type = models.CharField(choices=LOGIN_TYPE_CHOICE, max_length=1, verbose_name=_('Login type'))
|
||||||
|
log_file = models.CharField(max_length=1000, blank=True, null=True)
|
||||||
|
is_finished = models.BooleanField(default=False, verbose_name=_('Is finished'))
|
||||||
|
date_start = models.DateTimeField(auto_now=True, verbose_name=_('Date start'))
|
||||||
|
date_finished = models.DateTimeField(null=True, verbose_name=_('Date finished'))
|
||||||
|
|
||||||
|
|
||||||
|
class CommandLog(models.Model):
|
||||||
|
proxy_log = models.ForeignKey(ProxyLog, on_delete=models.CASCADE, related_name='proxy_log')
|
||||||
|
command = models.CharField(max_length=1000, blank=True)
|
||||||
|
output = models.TextField(blank=True)
|
||||||
|
date_start = models.DateTimeField(null=True)
|
||||||
|
date_finished = models.DateTimeField(null=True)
|
||||||
|
|
|
@ -12,10 +12,10 @@ from rest_framework_bulk import ListBulkCreateUpdateDestroyAPIView
|
||||||
from .models import User, UserGroup
|
from .models import User, UserGroup
|
||||||
from .serializers import UserDetailSerializer, UserAndGroupSerializer, \
|
from .serializers import UserDetailSerializer, UserAndGroupSerializer, \
|
||||||
GroupDetailSerializer, UserPKUpdateSerializer, UserBulkUpdateSerializer, GroupBulkUpdateSerializer
|
GroupDetailSerializer, UserPKUpdateSerializer, UserBulkUpdateSerializer, GroupBulkUpdateSerializer
|
||||||
from common.mixins import BulkDeleteApiMixin
|
from common.mixins import BulkDeleteApiMixin, get_logger
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('jumpserver.users.api')
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class UserDetailApi(generics.RetrieveUpdateDestroyAPIView):
|
class UserDetailApi(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
|
|
@ -634,10 +634,13 @@
|
||||||
<part>id</part>
|
<part>id</part>
|
||||||
</key>
|
</key>
|
||||||
</table>
|
</table>
|
||||||
<table x="300" y="770" name="login_log">
|
<table x="268" y="776" name="login_log">
|
||||||
<row name="id" null="1" autoincrement="1">
|
<row name="id" null="1" autoincrement="1">
|
||||||
<datatype>INTEGER</datatype>
|
<datatype>INTEGER</datatype>
|
||||||
<default>NULL</default></row>
|
<default>NULL</default></row>
|
||||||
|
<row name="name" null="1" autoincrement="0">
|
||||||
|
<datatype>CHAR</datatype>
|
||||||
|
<default>NULL</default></row>
|
||||||
<row name="username" null="1" autoincrement="0">
|
<row name="username" null="1" autoincrement="0">
|
||||||
<datatype>VARCHAR</datatype>
|
<datatype>VARCHAR</datatype>
|
||||||
<default>NULL</default></row>
|
<default>NULL</default></row>
|
||||||
|
@ -663,7 +666,7 @@
|
||||||
<part>id</part>
|
<part>id</part>
|
||||||
</key>
|
</key>
|
||||||
</table>
|
</table>
|
||||||
<table x="139" y="772" name="admin_log">
|
<table x="108" y="775" name="admin_log">
|
||||||
<row name="id" null="1" autoincrement="1">
|
<row name="id" null="1" autoincrement="1">
|
||||||
<datatype>INTEGER</datatype>
|
<datatype>INTEGER</datatype>
|
||||||
<default>NULL</default></row>
|
<default>NULL</default></row>
|
||||||
|
@ -689,14 +692,20 @@
|
||||||
<part>id</part>
|
<part>id</part>
|
||||||
</key>
|
</key>
|
||||||
</table>
|
</table>
|
||||||
<table x="435" y="806" name="proxy_log">
|
<table x="418" y="775" name="proxy_log">
|
||||||
<row name="id" null="1" autoincrement="1">
|
<row name="id" null="1" autoincrement="1">
|
||||||
<datatype>INTEGER</datatype>
|
<datatype>INTEGER</datatype>
|
||||||
<default>NULL</default></row>
|
<default>NULL</default></row>
|
||||||
|
<row name="name" null="1" autoincrement="0">
|
||||||
|
<datatype>VARCHAR</datatype>
|
||||||
|
<default>NULL</default></row>
|
||||||
<row name="username" null="1" autoincrement="0">
|
<row name="username" null="1" autoincrement="0">
|
||||||
<datatype>CHAR</datatype>
|
<datatype>CHAR</datatype>
|
||||||
<default>NULL</default></row>
|
<default>NULL</default></row>
|
||||||
<row name="hostname" null="1" autoincrement="0">
|
<row name="hostname" null="1" autoincrement="0">
|
||||||
|
<datatype>VARCHAR</datatype>
|
||||||
|
<default>NULL</default></row>
|
||||||
|
<row name="ip" null="1" autoincrement="0">
|
||||||
<datatype>CHAR</datatype>
|
<datatype>CHAR</datatype>
|
||||||
<default>NULL</default></row>
|
<default>NULL</default></row>
|
||||||
<row name="sysuser" null="1" autoincrement="0">
|
<row name="sysuser" null="1" autoincrement="0">
|
||||||
|
@ -705,18 +714,9 @@
|
||||||
<row name="login_type" null="1" autoincrement="0">
|
<row name="login_type" null="1" autoincrement="0">
|
||||||
<datatype>CHAR</datatype>
|
<datatype>CHAR</datatype>
|
||||||
<default>NULL</default></row>
|
<default>NULL</default></row>
|
||||||
<row name="refer_id" null="1" autoincrement="0">
|
|
||||||
<datatype>INTEGER</datatype>
|
|
||||||
<default>NULL</default></row>
|
|
||||||
<row name="log_file" null="1" autoincrement="0">
|
<row name="log_file" null="1" autoincrement="0">
|
||||||
<datatype>CHAR</datatype>
|
<datatype>CHAR</datatype>
|
||||||
<default>NULL</default></row>
|
<default>NULL</default></row>
|
||||||
<row name="login_ip" null="1" autoincrement="0">
|
|
||||||
<datatype>VARCHAR</datatype>
|
|
||||||
<default>NULL</default></row>
|
|
||||||
<row name="login_city" null="1" autoincrement="0">
|
|
||||||
<datatype>VARCHAR</datatype>
|
|
||||||
<default>NULL</default></row>
|
|
||||||
<row name="is_finished" null="1" autoincrement="0">
|
<row name="is_finished" null="1" autoincrement="0">
|
||||||
<datatype>INTEGER</datatype>
|
<datatype>INTEGER</datatype>
|
||||||
<default>NULL</default></row>
|
<default>NULL</default></row>
|
||||||
|
@ -738,11 +738,17 @@
|
||||||
<datatype>INTEGER</datatype>
|
<datatype>INTEGER</datatype>
|
||||||
<default>NULL</default><relation table="proxy_log" row="id" />
|
<default>NULL</default><relation table="proxy_log" row="id" />
|
||||||
</row>
|
</row>
|
||||||
|
<row name="command" null="1" autoincrement="0">
|
||||||
|
<datatype>CHAR</datatype>
|
||||||
|
<default>NULL</default></row>
|
||||||
|
<row name="output" null="1" autoincrement="0">
|
||||||
|
<datatype>VARCHAR</datatype>
|
||||||
|
<default>NULL</default></row>
|
||||||
<row name="date_start" null="1" autoincrement="0">
|
<row name="date_start" null="1" autoincrement="0">
|
||||||
<datatype>DATE</datatype>
|
<datatype>DATE</datatype>
|
||||||
<default>NULL</default></row>
|
<default>NULL</default></row>
|
||||||
<row name="command" null="1" autoincrement="0">
|
<row name="date_finished" null="1" autoincrement="0">
|
||||||
<datatype>CHAR</datatype>
|
<datatype>DATE</datatype>
|
||||||
<default>NULL</default></row>
|
<default>NULL</default></row>
|
||||||
<key type="PRIMARY" name="">
|
<key type="PRIMARY" name="">
|
||||||
<part>id</part>
|
<part>id</part>
|
||||||
|
|
|
@ -23,4 +23,3 @@ sshpubkeys==2.2.0
|
||||||
djangorestframework-bulk==0.2.1
|
djangorestframework-bulk==0.2.1
|
||||||
python-gssapi==0.6.4
|
python-gssapi==0.6.4
|
||||||
tornado==4.4.2
|
tornado==4.4.2
|
||||||
|
|
||||||
|
|
|
@ -6,21 +6,21 @@ __version__ = '0.3.3'
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import base64
|
# import base64
|
||||||
import time
|
import time
|
||||||
from binascii import hexlify
|
# from binascii import hexlify
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
from multiprocessing.process import Process
|
# from multiprocessing.process import Process
|
||||||
import traceback
|
import traceback
|
||||||
import tty
|
# import tty
|
||||||
import termios
|
# import termios
|
||||||
import struct
|
# import struct
|
||||||
import fcntl
|
# import fcntl
|
||||||
import signal
|
# import signal
|
||||||
import socket
|
import socket
|
||||||
import select
|
import select
|
||||||
import errno
|
# import errno
|
||||||
import paramiko
|
import paramiko
|
||||||
import django
|
import django
|
||||||
|
|
||||||
|
@ -210,8 +210,7 @@ class Navigation:
|
||||||
class ProxyChannel:
|
class ProxyChannel:
|
||||||
ENTER_CHAR = ['\r', '\n', '\r\n']
|
ENTER_CHAR = ['\r', '\n', '\r\n']
|
||||||
output_data = []
|
output_data = []
|
||||||
command = []
|
history = {}
|
||||||
output = []
|
|
||||||
|
|
||||||
def __init__(self, client_channel, backend_channel, client_addr):
|
def __init__(self, client_channel, backend_channel, client_addr):
|
||||||
self.client_channel = client_channel
|
self.client_channel = client_channel
|
||||||
|
@ -219,39 +218,30 @@ class ProxyChannel:
|
||||||
self.client_addr = client_addr
|
self.client_addr = client_addr
|
||||||
self.in_input_mode = True
|
self.in_input_mode = True
|
||||||
self.is_first_input = True
|
self.is_first_input = True
|
||||||
self.id = 0
|
self.no = 0
|
||||||
|
self.command = ''
|
||||||
# def stream_flow(self, input_=None, output_=None):
|
self.output = ''
|
||||||
# if input_:
|
|
||||||
# self.in_input_mode = True
|
|
||||||
# if input_ in ['\r', '\n', '\r\n']:
|
|
||||||
# self.in_input_mode = False
|
|
||||||
#
|
|
||||||
# if output_:
|
|
||||||
# print(''.join(self.__class__.output_data))
|
|
||||||
# if not self.in_input_mode:
|
|
||||||
# command = ''.join(self.__class__.output_data)
|
|
||||||
# del self.__class__.output_data
|
|
||||||
# self.__class__.output_data = []
|
|
||||||
# self.__class__.output_data.append(output_)
|
|
||||||
|
|
||||||
def get_output(self):
|
def get_output(self):
|
||||||
if self.in_input_mode is False:
|
if self.in_input_mode is False:
|
||||||
self.__class__.output_data.pop()
|
# self.__class__.output_data.pop()
|
||||||
result = ''.join(self.__class__.output_data)
|
self.output = output = ''.join(self.__class__.output_data)[:200]
|
||||||
self.__class__.output.append(result)
|
self.__class__.history[self.no]['output'] = self.output
|
||||||
|
self.__class__.history[self.no]['date_finished'] = time.time()
|
||||||
print('>>>>>>>>>>> output <<<<<<<<<<')
|
print('>>>>>>>>>>> output <<<<<<<<<<')
|
||||||
print(result)
|
print(output)
|
||||||
print('>>>>>>>>>>> end output <<<<<<<<<<')
|
print('>>>>>>>>>>> end output <<<<<<<<<<')
|
||||||
del self.__class__.output_data
|
del self.__class__.output_data
|
||||||
self.__class__.output_data = []
|
self.__class__.output_data = []
|
||||||
|
self.no += 1
|
||||||
|
print(self.__class__.history)
|
||||||
|
|
||||||
def get_command(self, client_data):
|
def get_command(self, client_data):
|
||||||
if client_data in self.__class__.ENTER_CHAR:
|
if client_data in self.__class__.ENTER_CHAR:
|
||||||
self.in_input_mode = False
|
self.in_input_mode = False
|
||||||
command = ''.join(self.__class__.output_data)
|
self.command = command = ''.join(self.__class__.output_data)
|
||||||
|
self.__class__.history[self.no] = {'date_started': time.time(), 'command': self.command}
|
||||||
print('########### command ##########')
|
print('########### command ##########')
|
||||||
self.__class__.command.append(command)
|
|
||||||
print(command)
|
print(command)
|
||||||
print('########### end command ##########')
|
print('########### end command ##########')
|
||||||
del self.__class__.output_data
|
del self.__class__.output_data
|
||||||
|
@ -268,7 +258,6 @@ class ProxyChannel:
|
||||||
if client_channel.change_window_size_event.is_set():
|
if client_channel.change_window_size_event.is_set():
|
||||||
backend_channel.resize_pty(width=client_channel.width, height=client_channel.height)
|
backend_channel.resize_pty(width=client_channel.width, height=client_channel.height)
|
||||||
|
|
||||||
# print(self.__class__.output)
|
|
||||||
if client_channel in r:
|
if client_channel in r:
|
||||||
# Get output of the command
|
# Get output of the command
|
||||||
self.get_output()
|
self.get_output()
|
||||||
|
|
Loading…
Reference in New Issue