vpnmanager/manager/models.py

35 lines
1.4 KiB
Python
Raw Normal View History

2018-11-25 15:05:26 +00:00
from django.db import models
from django.conf import settings
import uuid
2018-11-25 21:02:16 +00:00
def getRandom():
2018-11-25 15:05:26 +00:00
return str(uuid.uuid4().hex)
class Organization(models.Model):
2018-11-26 19:55:09 +00:00
name = models.CharField("Organization Name", max_length=300)
2018-11-25 15:05:26 +00:00
users = models.ManyToManyField(settings.AUTH_USER_MODEL)
def __str__(self):
return self.name
2018-11-25 21:02:16 +00:00
class Network(models.Model):
2018-11-26 19:55:09 +00:00
extip = models.CharField("External/Public IP", max_length=15)
intip = models.CharField("Internal/Private IP", max_length=15)
2018-11-25 21:02:16 +00:00
organizations = models.ManyToManyField(Organization)
def __str__(self):
return "%s (%s)" % (self.intip, self.extip)
2018-11-25 15:05:26 +00:00
class Device(models.Model):
serial = models.CharField("Device Serial Number", max_length=12, unique=True)
2018-11-25 21:02:16 +00:00
name = models.CharField("Common Name", max_length=100, blank=True, null=True)
2018-11-25 15:05:26 +00:00
organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
2018-11-26 08:50:53 +00:00
network = models.ForeignKey(Network, on_delete=models.SET_NULL, blank=True, null=True)
2018-11-25 15:05:26 +00:00
curip = models.CharField("Current IP Address", max_length=15, blank=True, null=True)
2018-11-25 21:02:16 +00:00
lasttime = models.DateTimeField("Last Received Heartbeat", blank=True, null=True)
2018-11-25 15:05:26 +00:00
secret = models.CharField("Secret", default=getRandom, max_length=128)
2018-11-28 15:38:35 +00:00
reboot = models.BooleanField("Trigger Reboot", default=False)
2018-11-25 15:05:26 +00:00
2018-11-25 21:02:16 +00:00
def __str__(self):
return "%s%s" % (self.serial, " (%s)" % self.curip if self.curip else "")