vpnmanager/manager/models.py

97 lines
4.2 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):
2019-01-05 15:08:19 +00:00
name = models.CharField("Common Name", max_length=64, blank=True, null=True)
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):
2019-01-05 15:08:19 +00:00
return ("%s" % self.intip + (" (%s)" % self.name if self.name else ""))
2018-11-25 21:02:16 +00:00
class Model(models.Model):
name = models.CharField("Model Name", max_length=100, unique=True)
extname = models.CharField("Manufacturer Model Name", max_length=100)
config = models.TextField("OpenWRT Compile Config", blank=True, null=True)
firmware = models.DateTimeField("Firmware Modification Date", auto_now=True)
wwan = models.BooleanField("Supports WWAN (External WiFi)", default=False)
def __str__(self):
return self.name
2018-12-23 09:37:14 +00:00
class Wifi(models.Model):
serial = models.CharField("Device Serial Number", max_length=12, unique=True)
2018-12-28 09:43:57 +00:00
organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
2018-12-23 09:37:14 +00:00
ssid = models.CharField("WiFi SSID", max_length=32)
bssid = models.CharField("WiFi BSSID", max_length=64, blank=True, null=True)
key = models.CharField("WiFi key", max_length=32)
ip = models.CharField("Configuration IP", max_length=15, blank=True, null=True)
user = models.CharField("Configuration User Name", max_length=32, blank=True, null=True)
password = models.CharField("Configuration Password", max_length=32, blank=True, null=True)
def __str__(this):
return "%s (%s)" % (this.serial, this.ssid)
2018-11-25 15:05:26 +00:00
class Device(models.Model):
serial = models.CharField("Device Serial Number", max_length=12, unique=True)
name = models.CharField("Common Name", max_length=100, default="", blank=True, null=True)
model = models.ForeignKey(Model, on_delete=models.CASCADE)
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-12-28 09:43:57 +00:00
wifi = models.ManyToManyField(Wifi, blank=True)
2018-11-25 15:05:26 +00:00
curip = models.CharField("Current IP Address", max_length=15, blank=True, null=True)
lasttime = models.DateTimeField("Last Received IP", blank=True, null=True, editable=False)
lastbeat = models.DateTimeField("Last Received Timestamp", blank=True, null=True, editable=False)
2018-11-25 15:05:26 +00:00
secret = models.CharField("Secret", default=getRandom, max_length=128)
password = models.CharField("Device Password", default=getRandom, max_length=128)
vpnconfig = models.TextField("VPN Configuration", blank=True, null=True, editable=False)
firmware = models.DateTimeField("Firmware Creation Time", blank=True, null=True, editable=False)
update = models.BooleanField("Trigger Firmware Update", default=False)
2018-11-28 15:38:35 +00:00
reboot = models.BooleanField("Trigger Reboot", default=False)
2018-12-28 09:43:57 +00:00
changed = models.DateTimeField("Last Change of Device Config")
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 "")
2019-01-18 12:50:41 +00:00
class DeviceLog(models.Model):
ADD = 0
REMOVE = 1
NAME = 2
NET = 3
REBOOT = 4
UPDATE = 5
STATUS = 6
INTERNALIP = 7
WIFI = 8
ACTION_CHOICES = (
(ADD, "ADD"),
(REMOVE, "REMOVE"),
(NAME, "NAME"),
(NET, "NET"),
(REBOOT, "REBOOT"),
(UPDATE, "UPDATE"),
(STATUS, "STATUS"),
(INTERNALIP, "INTERNALIP"),
(WIFI, "WIFI")
)
objid = models.CharField("Device ID", max_length=64)
user = models.CharField("User Name", max_length=128, null=True)
date = models.DateTimeField("Action Date", auto_now_add=True)
action = models.IntegerField("Action", choices=ACTION_CHOICES)
oldvalue = models.CharField("Old Value", max_length=256, blank=True, null=True)
newvalue = models.CharField("New Value", max_length=256, blank=True, null=True)