jumpserver/apps/audits/models.py

74 lines
3.0 KiB
Python
Raw Normal View History

2016-10-07 15:54:29 +00:00
# -*- coding: utf-8 -*-
#
2016-08-08 16:43:11 +00:00
from __future__ import unicode_literals
from django.db import models
2016-10-07 15:54:29 +00:00
from django.utils.translation import ugettext_lazy as _
class LoginLog(models.Model):
LOGIN_TYPE_CHOICE = (
2016-10-15 10:28:49 +00:00
('W', 'Web'),
2016-10-15 15:34:02 +00:00
('S', 'SSH Terminal'),
2016-10-15 10:28:49 +00:00
('WT', 'Web Terminal')
2016-10-07 15:54:29 +00:00
)
username = models.CharField(max_length=20, verbose_name=_('Username'))
name = models.CharField(max_length=20, blank=True, verbose_name=_('Name'))
2016-10-15 15:34:02 +00:00
login_type = models.CharField(choices=LOGIN_TYPE_CHOICE, max_length=2, verbose_name=_('Login type'))
2016-10-18 11:28:36 +00:00
terminal = models.CharField(max_length=32, verbose_name=_('Terminal'))
2016-10-07 15:54:29 +00:00
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'))
2016-10-15 10:28:49 +00:00
from_terminal = models.ForeignKey
2016-10-15 15:34:02 +00:00
date_login = models.DateTimeField(auto_now_add=True, verbose_name=_('Date login'))
2016-10-07 15:54:29 +00:00
date_logout = models.DateTimeField(null=True, verbose_name=_('Date logout'))
class Meta:
2016-10-08 16:12:18 +00:00
db_table = 'login_log'
2016-10-07 15:54:29 +00:00
ordering = ['-date_login', 'username']
class ProxyLog(models.Model):
LOGIN_TYPE_CHOICE = (
2016-10-18 11:28:36 +00:00
('S', 'SSH Terminal'),
('WT', 'Web Terminal'),
2016-10-07 15:54:29 +00:00
)
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'))
2016-10-18 11:28:36 +00:00
login_type = models.CharField(choices=LOGIN_TYPE_CHOICE, max_length=2, blank=True,
null=True, verbose_name=_('Login type'))
terminal = models.CharField(max_length=32, blank=True, null=True, verbose_name=_('Terminal'))
2016-10-07 15:54:29 +00:00
log_file = models.CharField(max_length=1000, blank=True, null=True)
2016-10-09 16:39:24 +00:00
was_failed = models.BooleanField(default=False, verbose_name=_('Did connect failed'))
2016-10-07 15:54:29 +00:00
is_finished = models.BooleanField(default=False, verbose_name=_('Is finished'))
2016-10-18 11:28:36 +00:00
date_start = models.DateTimeField(verbose_name=_('Date start'))
2016-10-07 15:54:29 +00:00
date_finished = models.DateTimeField(null=True, verbose_name=_('Date finished'))
2016-10-08 16:12:18 +00:00
def __unicode__(self):
return '%s-%s-%s-%s' % (self.username, self.hostname, self.system_user, self.id)
class Meta:
db_table = 'proxy_log'
ordering = ['-date_start', 'username']
2016-08-08 16:43:11 +00:00
2016-10-07 15:54:29 +00:00
class CommandLog(models.Model):
2016-10-08 16:12:18 +00:00
proxy_log = models.ForeignKey(ProxyLog, on_delete=models.CASCADE, related_name='command_log')
2016-10-18 17:05:28 +00:00
command_no = models.IntegerField()
2016-10-07 15:54:29 +00:00
command = models.CharField(max_length=1000, blank=True)
output = models.TextField(blank=True)
2016-10-18 17:05:28 +00:00
datetime = models.DateTimeField(null=True)
2016-10-08 16:12:18 +00:00
def __unicode__(self):
return '%s: %s' % (self.id, self.command)
class Meta:
db_table = 'command_log'
2016-10-18 17:05:28 +00:00
ordering = ['command_no', 'command']