Device upgrade status indication
This commit is contained in:
parent
ad0efbaf6d
commit
df941650dd
4 changed files with 36 additions and 4 deletions
22
manager/migrations/0054_auto_20190416_0801.py
Normal file
22
manager/migrations/0054_auto_20190416_0801.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 2.1.5 on 2019-04-16 08:01
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('manager', '0053_auto_20190416_0650'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='device',
|
||||
name='firmware',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='device',
|
||||
name='wifi',
|
||||
field=models.ManyToManyField(blank=True, to='manager.Wifi'),
|
||||
),
|
||||
]
|
|
@ -1,7 +1,12 @@
|
|||
from django.utils import timezone
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
|
||||
from macaddress.fields import MACAddressField
|
||||
import uuid
|
||||
import glob
|
||||
import os
|
||||
import datetime
|
||||
|
||||
def getRandom():
|
||||
return str(uuid.uuid4().hex)
|
||||
|
@ -63,7 +68,6 @@ class Device(models.Model):
|
|||
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)
|
||||
reboot = models.BooleanField("Trigger Reboot", default=False)
|
||||
changed = models.DateTimeField("Last Change of Device Config", auto_now_add=True)
|
||||
|
@ -75,6 +79,14 @@ class Device(models.Model):
|
|||
def __str__(self):
|
||||
return "%s%s" % (self.serial, " (%s)" % self.ssid if self.ssid else "")
|
||||
|
||||
def firmware(self):
|
||||
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
|
||||
|
||||
def upgrade_available(self):
|
||||
return (self.firmware() < self.model.firmware) if self.firmware() else True
|
||||
|
||||
class DeviceLog(models.Model):
|
||||
ADD = 0
|
||||
REMOVE = 1
|
||||
|
|
|
@ -81,7 +81,6 @@ def update(request):
|
|||
return HttpResponse(status=503)
|
||||
|
||||
sigUpdateDevice(device.serial, None, False)
|
||||
device.firmware = datetime.datetime.now()
|
||||
device.update = False
|
||||
device.save()
|
||||
|
||||
|
@ -263,7 +262,6 @@ def getconfig(request, device_id):
|
|||
return HttpResponse(status=503)
|
||||
|
||||
sigUpdateDevice(device.serial, None, False)
|
||||
device.firmware = datetime.datetime.now()
|
||||
device.update = False
|
||||
device.save()
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
{% userDevices as devices %}
|
||||
{% for device in devices %}
|
||||
<tr data-orga="[{{ device.organization.id }}]">
|
||||
<td><div style="display: inline; color: grey; font-weight: bold;" title="No information available" id="{{ device.id }}-indicator">⬤</div>{% if device.model.deprecated %} <i style="color: red;" title="Device outdated – please contact us to replace it with a new one" class="fas fa-exclamation-triangle"></i>{% endif %} <div style="display: inline;" {% if user.is_superuser %}title="{{ device.organization.name }}"{% endif %} id="{{ device.id }}-id">{{ device.serial }}{% if device.ssid %}<br><small>SSID: {{ device.ssid }}</small>{% endif %}</div></td>
|
||||
<td><div style="display: inline; color: grey; font-weight: bold;" title="No information available" id="{{ device.id }}-indicator">⬤</div>{% if device.model.deprecated %} <i style="color: red;" title="Device outdated{% if not user.is_superuser %} – please contact us to replace it with a new one{% endif %}" class="fas fa-exclamation-triangle"></i>{% elif user.is_superuser and device.upgrade_available %} <i style="color: green;" title="Firmware upgrade available" class="fas fa-upload"></i>{% endif %} <div style="display: inline;" {% if user.is_superuser %}title="{{ device.organization.name }}"{% endif %} id="{{ device.id }}-id">{{ device.serial }}{% if device.ssid %}<br><small>SSID: {{ device.ssid }}</small>{% endif %}</div></td>
|
||||
<td id="{{ device.id }}-name">{% if device.name %}{{ device.name }}{% endif %}</td>
|
||||
<td id="{{ device.id }}-network">{{ device.network }}</td>
|
||||
<td><div style="display:inline;" id="{{ device.id }}-ip">{% if device.curip %}{{ device.curip }} (at {{ device.lasttime }}){% endif %}</div></td>
|
||||
|
|
Loading…
Reference in a new issue