jumpserver/apps/terminal/models.py

46 lines
1.4 KiB
Python
Raw Normal View History

2016-10-15 09:14:56 +00:00
from __future__ import unicode_literals
from django.db import models
2016-10-15 10:28:49 +00:00
from django.utils.translation import ugettext_lazy as _
2016-10-15 09:14:56 +00:00
2016-10-15 10:28:49 +00:00
from users.models import User
class Terminal(models.Model):
2016-10-15 15:34:02 +00:00
TYPE_CHOICES = (
('S', 'SSH Terminal'),
('WT', 'Web Terminal')
)
2016-10-17 09:28:07 +00:00
name = models.CharField(max_length=30, unique=True, verbose_name=_('Name'))
2016-10-15 10:28:49 +00:00
ip = models.GenericIPAddressField(verbose_name=_('From ip'))
is_active = models.BooleanField(default=False, verbose_name=_('Is active'))
is_bound_ip = models.BooleanField(default=False, verbose_name=_('Is bound ip'))
2016-10-15 15:34:02 +00:00
type = models.CharField(choices=TYPE_CHOICES, max_length=2, verbose_name=_('Terminal type'))
2016-10-16 14:12:13 +00:00
url = models.CharField(max_length=100, verbose_name=_('URL to login'))
2016-10-15 15:34:02 +00:00
date_created = models.DateTimeField(auto_now_add=True)
2016-10-19 10:33:14 +00:00
comment = models.TextField(blank=True, verbose_name=_('Comment'))
2016-10-15 10:28:49 +00:00
2016-10-17 07:24:41 +00:00
def is_valid(self):
return self.is_active and self.is_accepted
@property
def is_superuser(self):
return False
@property
def is_terminal(self):
return True
2016-10-15 10:28:49 +00:00
class Meta:
2016-10-17 07:24:41 +00:00
db_table = 'terminal'
2016-10-19 10:33:14 +00:00
ordering = ['is_active']
2016-10-15 10:28:49 +00:00
2016-11-10 18:13:13 +00:00
class HeatbeatFailedLog(models.Model):
"""Terminal heatbeat failed log"""
2016-10-15 15:34:02 +00:00
terminal = models.ForeignKey(Terminal, on_delete=models.CASCADE)
2016-10-18 15:49:04 +00:00
date_created = models.DateTimeField(auto_now_add=True)
2016-10-15 10:28:49 +00:00
class Meta:
2016-11-10 18:13:13 +00:00
db_table = 'heatbeat_failed_log'