Make things prettier
This commit is contained in:
parent
66b1fb0fad
commit
78a34b80fa
7 changed files with 43 additions and 14 deletions
23
manager/migrations/0030_auto_20190103_1823.py
Normal file
23
manager/migrations/0030_auto_20190103_1823.py
Normal file
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -13,13 +13,13 @@ class Organization(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Network(models.Model):
|
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)
|
extip = models.CharField("External/Public IP", max_length=15)
|
||||||
intip = models.CharField("Internal/Private IP", max_length=15)
|
intip = models.CharField("Internal/Private IP", max_length=15)
|
||||||
organizations = models.ManyToManyField(Organization)
|
organizations = models.ManyToManyField(Organization)
|
||||||
|
|
||||||
def __str__(self):
|
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):
|
class Model(models.Model):
|
||||||
name = models.CharField("Model Name", max_length=100, unique=True)
|
name = models.CharField("Model Name", max_length=100, unique=True)
|
||||||
|
|
|
@ -18,9 +18,9 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="secret">Device Secret</label>
|
<label for="secret">Device Secret</label>
|
||||||
<input type="text" class="form-control" id="secret" disabled="disabled" value="{{ device.secret }}"></input>
|
<input type="text" class="form-control" id="secret" disabled="disabled" value="{{ device.secret }}"></input>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if user.is_staff %}
|
{% if user.is_staff %}
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="password">Root Password</label>
|
<label for="password">Root Password</label>
|
||||||
<input type="text" class="form-control" id="password" disabled="disabled" value="{{ device.password }}"></input>
|
<input type="text" class="form-control" id="password" disabled="disabled" value="{{ device.password }}"></input>
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
<label for="subnet">Assigned Network</label>
|
<label for="subnet">Assigned Network</label>
|
||||||
<select class="custom-select mr-sm-2" id="subnet" name="subnet">
|
<select class="custom-select mr-sm-2" id="subnet" name="subnet">
|
||||||
{% for choice in subnets %}
|
{% for choice in subnets %}
|
||||||
<option {% if choice.intip == device.network.intip %} selected {% endif %} value="{{ choice.intip }}">{{ choice.intip}} ({{ choice.extip }})</option>
|
<option {% if choice.intip == device.network.intip %} selected {% endif %} value="{{ choice.intip }}">{{ choice.intip}}{% if choice.name %} ({{ choice.name }}){% endif %}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
<small id="subnetHelp" class="form-text text-muted">A network change will require a reboot of the device to be applied.</small>
|
<small id="subnetHelp" class="form-text text-muted">A network change will require a reboot of the device to be applied.</small>
|
||||||
|
|
|
@ -239,7 +239,7 @@ def ping(request, device_id):
|
||||||
ajax += ',\n "network": {'
|
ajax += ',\n "network": {'
|
||||||
ajax += '\n "intip": "%s"' % device[0].network.intip
|
ajax += '\n "intip": "%s"' % device[0].network.intip
|
||||||
ajax += ',\n "extip": "%s"' % device[0].network.extip
|
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 }'
|
ajax += '\n }'
|
||||||
|
|
||||||
except:
|
except:
|
||||||
|
@ -256,10 +256,9 @@ def devices(request):
|
||||||
user = request.user
|
user = request.user
|
||||||
devices = set()
|
devices = set()
|
||||||
wifis = 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):
|
for organization in Organization.objects.filter(users=user):
|
||||||
orga = orga or organization
|
|
||||||
for device in Device.objects.filter(organization=organization):
|
for device in Device.objects.filter(organization=organization):
|
||||||
devices.add(device)
|
devices.add(device)
|
||||||
for wifi in Wifi.objects.filter(organization=organization):
|
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):
|
for organization in Organization.objects.filter(users=request.user):
|
||||||
device = device or Device.objects.filter(id=device_id, organization=organization)
|
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:
|
if not device:
|
||||||
return redirect("/")
|
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", ""):
|
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"))
|
subnet = Network.objects.filter(intip=request.POST.get("subnet", device[0].network.intip if device[0].network else "No VPN"))
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ function styleStatus(msg, device) {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (msg.hasOwnProperty("network")) {
|
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")) {
|
if (msg.hasOwnProperty("reboot")) {
|
||||||
|
|
5
vpnmanager/context_processors.py
Normal file
5
vpnmanager/context_processors.py
Normal file
|
@ -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}
|
|
@ -49,6 +49,7 @@ TEMPLATES = [
|
||||||
'django.template.context_processors.request',
|
'django.template.context_processors.request',
|
||||||
'django.contrib.auth.context_processors.auth',
|
'django.contrib.auth.context_processors.auth',
|
||||||
'django.contrib.messages.context_processors.messages',
|
'django.contrib.messages.context_processors.messages',
|
||||||
|
'vpnmanager.context_processors.admin_header_processor',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue