A lot more LOCs
This commit is contained in:
parent
6111cc3514
commit
c41cd90a3e
1 changed files with 391 additions and 71 deletions
|
@ -6,15 +6,28 @@ from macaddress.fields import MACAddressField
|
||||||
import uuid
|
import uuid
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def getRandom():
|
def getRandom():
|
||||||
return str(uuid.uuid4().hex)
|
return str(uuid.uuid4().hex)
|
||||||
|
|
||||||
|
|
||||||
class Organization(models.Model):
|
class Organization(models.Model):
|
||||||
name = models.CharField("Organization Name", max_length=300)
|
name = models.CharField(
|
||||||
users = models.ManyToManyField(settings.AUTH_USER_MODEL)
|
"Organization Name",
|
||||||
userlimit = models.IntegerField("User Limit", null=True, blank=True)
|
max_length=300
|
||||||
|
)
|
||||||
|
|
||||||
|
users = models.ManyToManyField(
|
||||||
|
settings.AUTH_USER_MODEL
|
||||||
|
)
|
||||||
|
|
||||||
|
userlimit = models.IntegerField(
|
||||||
|
"User Limit",
|
||||||
|
null=True,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -22,70 +35,262 @@ class Organization(models.Model):
|
||||||
def orgausers(self):
|
def orgausers(self):
|
||||||
return self.users.filter(is_superuser=False)
|
return self.users.filter(is_superuser=False)
|
||||||
|
|
||||||
|
|
||||||
class Network(models.Model):
|
class Network(models.Model):
|
||||||
name = models.CharField("Common Name", max_length=64, blank=True, null=True)
|
name = models.CharField(
|
||||||
extip = models.CharField("External/Public IP", max_length=15, unique=True)
|
max_length=64,
|
||||||
intip = models.CharField("Internal/Private IP", max_length=15, unique=True)
|
blank=True,
|
||||||
organization = models.ManyToManyField(Organization)
|
null=True
|
||||||
|
)
|
||||||
|
|
||||||
|
extip = models.CharField(
|
||||||
|
"External/Public IP",
|
||||||
|
max_length=15,
|
||||||
|
unique=True
|
||||||
|
)
|
||||||
|
|
||||||
|
intip = models.CharField(
|
||||||
|
"Internal/Private IP",
|
||||||
|
max_length=15,
|
||||||
|
unique=True
|
||||||
|
)
|
||||||
|
|
||||||
|
organization = models.ManyToManyField(
|
||||||
|
Organization
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return ("%s" % self.intip + (" (%s)" % self.name if self.name else ""))
|
return "%s" % self.intip + (" (%s)" % self.name if self.name else "")
|
||||||
|
|
||||||
|
|
||||||
class Model(models.Model):
|
class Model(models.Model):
|
||||||
name = models.CharField("Model Name", max_length=100, unique=True)
|
name = models.CharField(
|
||||||
extname = models.CharField("Manufacturer Model Name", max_length=100)
|
"Model Name",
|
||||||
config = models.TextField("OpenWRT Compile Config", blank=True, null=True)
|
max_length=100,
|
||||||
firmware = models.DateTimeField("Firmware Modification Date", auto_now=True)
|
unique=True
|
||||||
wwan = models.BooleanField("Supports WWAN (External WiFi)", default=False)
|
)
|
||||||
deprecated = models.BooleanField("Outdated device type", default=False)
|
|
||||||
|
extname = models.CharField(
|
||||||
|
"Manufacturer Model Name",
|
||||||
|
max_length=100
|
||||||
|
)
|
||||||
|
|
||||||
|
config = models.TextField(
|
||||||
|
"OpenWRT Compile Config",
|
||||||
|
blank=True,
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
|
||||||
|
firmware = models.DateTimeField(
|
||||||
|
"Last Firmware Change",
|
||||||
|
auto_now=True
|
||||||
|
)
|
||||||
|
|
||||||
|
wwan = models.BooleanField(
|
||||||
|
"Supports WWAN (External WiFi)",
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
deprecated = models.BooleanField(
|
||||||
|
"Outdated device type",
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Wifi(models.Model):
|
class Wifi(models.Model):
|
||||||
serial = models.CharField("Device Serial Number", max_length=12, unique=True)
|
serial = models.CharField(
|
||||||
organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
|
"Device Serial Number",
|
||||||
ssid = models.CharField("WiFi SSID", max_length=32)
|
max_length=12,
|
||||||
bssid = models.CharField("WiFi BSSID", max_length=64, blank=True, null=True)
|
unique=True
|
||||||
key = models.CharField("WiFi key", max_length=32)
|
)
|
||||||
ip = models.GenericIPAddressField("Configuration IP", protocol="ipv4", blank=True, null=True)
|
|
||||||
user = models.CharField("Configuration User Name", max_length=32, blank=True, null=True)
|
organization = models.ForeignKey(
|
||||||
password = models.CharField("Configuration Password", max_length=32, blank=True, null=True)
|
Organization,
|
||||||
|
on_delete=models.CASCADE
|
||||||
|
)
|
||||||
|
|
||||||
|
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.GenericIPAddressField(
|
||||||
|
"Configuration IP",
|
||||||
|
protocol="ipv4",
|
||||||
|
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):
|
def __str__(this):
|
||||||
return "%s (%s)" % (this.serial, this.ssid)
|
return "%s (%s)" % (this.serial, this.ssid)
|
||||||
|
|
||||||
|
|
||||||
class Device(models.Model):
|
class Device(models.Model):
|
||||||
serial = models.CharField("Device Serial Number", max_length=12, unique=True)
|
serial = models.CharField(
|
||||||
name = models.CharField("Common Name", max_length=100, default="", blank=True, null=True)
|
"Device Serial Number",
|
||||||
model = models.ForeignKey(Model, on_delete=models.CASCADE)
|
max_length=12,
|
||||||
organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
|
unique=True
|
||||||
network = models.ForeignKey(Network, on_delete=models.SET_NULL, blank=True, null=True)
|
)
|
||||||
wifi = models.ManyToManyField(Wifi, blank=True)
|
|
||||||
curip = models.GenericIPAddressField("Current IP Address", protocol="ipv4", blank=True, null=True)
|
name = models.CharField(
|
||||||
lasttime = models.DateTimeField("Last Received IP", blank=True, null=True, editable=False)
|
"Common Name",
|
||||||
lastbeat = models.DateTimeField("Last Received Timestamp", blank=True, null=True, editable=False)
|
max_length=100,
|
||||||
secret = models.CharField("Secret", default=getRandom, max_length=128)
|
default="",
|
||||||
password = models.CharField("Device Password", default=getRandom, max_length=128)
|
blank=True,
|
||||||
vpnconfig = models.TextField("VPN Configuration", blank=True, null=True, editable=False)
|
null=True
|
||||||
update = models.BooleanField("Trigger Firmware Update", default=False)
|
)
|
||||||
reboot = models.BooleanField("Trigger Reboot", default=False)
|
|
||||||
changed = models.DateTimeField("Last Change of Device Config", auto_now_add=True)
|
model = models.ForeignKey(
|
||||||
wireless = models.DateTimeField("Last Update of Wireless Config", blank=True, null=True, editable=False)
|
Model,
|
||||||
ssid = models.CharField("Broadcast SSID", max_length=32, blank=True, null=True)
|
on_delete=models.CASCADE
|
||||||
key = models.CharField("Broadcast WPA2 Key", max_length=64, blank=True, null=True)
|
)
|
||||||
mac = MACAddressField("Device MAC", null=True, blank=True)
|
|
||||||
|
organization = models.ForeignKey(
|
||||||
|
Organization,
|
||||||
|
on_delete=models.CASCADE
|
||||||
|
)
|
||||||
|
|
||||||
|
network = models.ForeignKey(
|
||||||
|
Network,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
blank=True,
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
|
||||||
|
wifi = models.ManyToManyField(
|
||||||
|
Wifi,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
|
curip = models.GenericIPAddressField(
|
||||||
|
"Current IP Address",
|
||||||
|
protocol="ipv4",
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
update = models.BooleanField(
|
||||||
|
"Trigger Firmware Update",
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
reboot = models.BooleanField(
|
||||||
|
"Trigger Reboot",
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
changed = models.DateTimeField(
|
||||||
|
"Last Change of Device Config",
|
||||||
|
auto_now_add=True
|
||||||
|
)
|
||||||
|
|
||||||
|
wireless = models.DateTimeField(
|
||||||
|
"Last Update of Wireless Config",
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
editable=False
|
||||||
|
)
|
||||||
|
|
||||||
|
ssid = models.CharField(
|
||||||
|
"Broadcast SSID",
|
||||||
|
max_length=32,
|
||||||
|
blank=True,
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
|
||||||
|
key = models.CharField(
|
||||||
|
"Broadcast WPA2 Key",
|
||||||
|
max_length=64,
|
||||||
|
blank=True,
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
|
||||||
|
mac = MACAddressField(
|
||||||
|
"Device MAC",
|
||||||
|
null=True,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s%s" % (self.serial, " (%s)" % self.ssid if self.ssid else "")
|
return "%s%s" % (self.serial, " (%s)" % self.ssid if self.ssid else "")
|
||||||
|
|
||||||
def firmware(self):
|
def firmware(self):
|
||||||
FWDIR = "/opt/vpnmanager/images/"
|
FWDIR = "/opt/vpnmanager/images/"
|
||||||
files = glob.glob(FWDIR + str(self.id) + ".bin")
|
|
||||||
return datetime.datetime.fromtimestamp(os.path.getmtime(files[0]), timezone.get_current_timezone()) if files else None
|
try:
|
||||||
|
fwfile = glob.glob(FWDIR + str(self.id) + ".bin")[0]
|
||||||
|
tz = timezone.get_current_timezone()
|
||||||
|
return datetime.fromtimestamp(os.path.getmtime(fwfile), tz)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
def upgrade_available(self):
|
def upgrade_available(self):
|
||||||
return (self.firmware() < self.model.firmware) if self.firmware() else True
|
if self.firmware():
|
||||||
|
return self.firmware() < self.model.firmware
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class DeviceLog(models.Model):
|
class DeviceLog(models.Model):
|
||||||
ADD = 0
|
ADD = 0
|
||||||
|
@ -112,12 +317,41 @@ class DeviceLog(models.Model):
|
||||||
(ORGA, "ORGA")
|
(ORGA, "ORGA")
|
||||||
)
|
)
|
||||||
|
|
||||||
objid = models.CharField("Device ID", max_length=64)
|
objid = models.CharField(
|
||||||
user = models.CharField("User Name", max_length=128, null=True)
|
"Device ID",
|
||||||
date = models.DateTimeField("Action Date", auto_now_add=True)
|
max_length=64
|
||||||
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)
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UserLog(models.Model):
|
class UserLog(models.Model):
|
||||||
ADD = 0
|
ADD = 0
|
||||||
|
@ -138,12 +372,41 @@ class UserLog(models.Model):
|
||||||
(ORGA, "ORGA")
|
(ORGA, "ORGA")
|
||||||
)
|
)
|
||||||
|
|
||||||
objid = models.CharField("Target User Name", max_length=64)
|
objid = models.CharField(
|
||||||
user = models.CharField("Source User Name", max_length=128, null=True)
|
"Target User Name",
|
||||||
date = models.DateTimeField("Action Date", auto_now_add=True)
|
max_length=64
|
||||||
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)
|
user = models.CharField(
|
||||||
|
"Source 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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class WifiLog(models.Model):
|
class WifiLog(models.Model):
|
||||||
ADD = 0
|
ADD = 0
|
||||||
|
@ -152,7 +415,7 @@ class WifiLog(models.Model):
|
||||||
SSID = 3
|
SSID = 3
|
||||||
KEY = 4
|
KEY = 4
|
||||||
ORGA = 5
|
ORGA = 5
|
||||||
|
|
||||||
ACTION_CHOICES = (
|
ACTION_CHOICES = (
|
||||||
(ADD, "ADD"),
|
(ADD, "ADD"),
|
||||||
(REMOVE, "REMOVE"),
|
(REMOVE, "REMOVE"),
|
||||||
|
@ -162,12 +425,41 @@ class WifiLog(models.Model):
|
||||||
(ORGA, "ORGA")
|
(ORGA, "ORGA")
|
||||||
)
|
)
|
||||||
|
|
||||||
objid = models.CharField("Wifi Name", max_length=64)
|
objid = models.CharField(
|
||||||
user = models.CharField("User Name", max_length=128, null=True)
|
"Wifi Name",
|
||||||
date = models.DateTimeField("Action Date", auto_now_add=True)
|
max_length=64
|
||||||
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)
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Notification(models.Model):
|
class Notification(models.Model):
|
||||||
NOTICE = 0
|
NOTICE = 0
|
||||||
|
@ -180,13 +472,41 @@ class Notification(models.Model):
|
||||||
(EMERGENCY, "EMERGENCY")
|
(EMERGENCY, "EMERGENCY")
|
||||||
)
|
)
|
||||||
|
|
||||||
status = models.IntegerField("Status", choices=STATUS_CHOICES)
|
status = models.IntegerField(
|
||||||
text = models.CharField("Notification Text", max_length=1024)
|
"Status",
|
||||||
expiry = models.DateTimeField("Notification Expiry", null=True, blank=True)
|
choices=STATUS_CHOICES
|
||||||
on_login = models.BooleanField("Display Notification on Login Screen", default=False)
|
)
|
||||||
|
|
||||||
|
text = models.CharField(
|
||||||
|
"Notification Text",
|
||||||
|
max_length=1024
|
||||||
|
)
|
||||||
|
|
||||||
|
expiry = models.DateTimeField(
|
||||||
|
"Notification Expiry",
|
||||||
|
null=True,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
|
on_login = models.BooleanField(
|
||||||
|
"Display Notification on Login Screen",
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UserStatus(models.Model):
|
class UserStatus(models.Model):
|
||||||
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
user = models.OneToOneField(
|
||||||
last_action = models.DateTimeField(null=True, blank=True)
|
settings.AUTH_USER_MODEL,
|
||||||
orga = models.ForeignKey(Organization, on_delete=models.SET_NULL, null=True)
|
on_delete=models.CASCADE
|
||||||
|
)
|
||||||
|
|
||||||
|
last_action = models.DateTimeField(
|
||||||
|
null=True,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
|
orga = models.ForeignKey(
|
||||||
|
Organization,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue