diff --git a/manager/migrations/0030_auto_20190103_1823.py b/manager/migrations/0030_auto_20190103_1823.py new file mode 100644 index 0000000..4fcf4ab --- /dev/null +++ b/manager/migrations/0030_auto_20190103_1823.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1.3 on 2019-01-03 18:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('manager', '0029_auto_20190103_1809'), + ] + + operations = [ + migrations.RenameField( + model_name='network', + old_name='commonname', + new_name='name', + ), + migrations.AlterField( + model_name='device', + name='wifi', + field=models.ManyToManyField(blank=True, to='manager.Wifi'), + ), + ] diff --git a/manager/models.py b/manager/models.py index d88bf06..8c74e65 100644 --- a/manager/models.py +++ b/manager/models.py @@ -13,13 +13,13 @@ class Organization(models.Model): return self.name class Network(models.Model): - commonname = models.CharField("Common Name", max_length=64, blank=True, null=True) + name = models.CharField("Common Name", max_length=64, blank=True, null=True) extip = models.CharField("External/Public IP", max_length=15) intip = models.CharField("Internal/Private IP", max_length=15) organizations = models.ManyToManyField(Organization) def __str__(self): - return ("%s" % self.intip + (" (%s)" % self.commonname if self.commonname else "")) + return ("%s" % self.intip + (" (%s)" % self.name if self.name else "")) class Model(models.Model): name = models.CharField("Model Name", max_length=100, unique=True) diff --git a/manager/templates/manager/edit.html b/manager/templates/manager/edit.html index 7468a33..f0056f2 100644 --- a/manager/templates/manager/edit.html +++ b/manager/templates/manager/edit.html @@ -18,9 +18,9 @@
+
{% endif %} {% if user.is_staff %} -
@@ -34,7 +34,7 @@ A network change will require a reboot of the device to be applied. diff --git a/manager/views.py b/manager/views.py index 57d82fd..e81c27c 100644 --- a/manager/views.py +++ b/manager/views.py @@ -239,7 +239,7 @@ def ping(request, device_id): ajax += ',\n "network": {' ajax += '\n "intip": "%s"' % device[0].network.intip ajax += ',\n "extip": "%s"' % device[0].network.extip - ajax += ',\n "commonname": "%s"' % device[0].network.commonname + ajax += ',\n "name": "%s"' % device[0].network.name ajax += '\n }' except: @@ -256,10 +256,9 @@ def devices(request): user = request.user devices = set() wifis = set() - orga = None + orga = ", ".join([x.__str__() for x in Organization.objects.filter(users=user)]) for organization in Organization.objects.filter(users=user): - orga = orga or organization for device in Device.objects.filter(organization=organization): devices.add(device) for wifi in Wifi.objects.filter(organization=organization): @@ -285,15 +284,16 @@ def editdevice(request, device_id): for organization in Organization.objects.filter(users=request.user): device = device or Device.objects.filter(id=device_id, organization=organization) - for subnet in Network.objects.filter(organizations=organization): - subnets.add(subnet) - - for wifi in Wifi.objects.filter(organization=organization): - wifis.add(wifi) - if not device: return redirect("/") + for subnet in Network.objects.filter(organizations=device[0].organization): + subnets.add(subnet) + + for wifi in Wifi.objects.filter(organization=device[0].organization): + wifis.add(wifi) + + if request.POST.get("subnet", ""): subnet = Network.objects.filter(intip=request.POST.get("subnet", device[0].network.intip if device[0].network else "No VPN")) diff --git a/static/js/devices.js b/static/js/devices.js index 04e92ca..df51d32 100644 --- a/static/js/devices.js +++ b/static/js/devices.js @@ -29,7 +29,7 @@ function styleStatus(msg, device) { }; if (msg.hasOwnProperty("network")) { - device_network.text(msg.network.intip + " (" + msg.network.commonname + ")"); + device_network.text(msg.network.intip + " (" + msg.network.name + ")"); }; if (msg.hasOwnProperty("reboot")) { diff --git a/vpnmanager/context_processors.py b/vpnmanager/context_processors.py new file mode 100644 index 0000000..66e489c --- /dev/null +++ b/vpnmanager/context_processors.py @@ -0,0 +1,5 @@ +from django.contrib import admin + +def admin_header_processor(request): + site_header = getattr(admin.site, 'site_header') + return {"site_header": site_header} diff --git a/vpnmanager/settings.py b/vpnmanager/settings.py index 01ea57c..34aee4a 100644 --- a/vpnmanager/settings.py +++ b/vpnmanager/settings.py @@ -49,6 +49,7 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'vpnmanager.context_processors.admin_header_processor', ], }, },