From 50cf4d5634c15d2e9b611ec190ce053e4c2acd01 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Fri, 8 Mar 2019 15:16:37 +0000 Subject: [PATCH] Implement custom SSIDs and WPA2-PSK encryption --- device-config/1/etc/config/wireless | 3 +- device-config/2/etc/config/wireless | 3 +- manager/migrations/0049_auto_20190308_1334.py | 28 +++++++++++++++ manager/migrations/0050_auto_20190308_1342.py | 36 +++++++++++++++++++ manager/models.py | 4 ++- manager/tasks.py | 4 ++- manager/views.py | 4 +++ templates/manager/add.html | 8 +++++ templates/manager/edit.html | 10 ++++++ templates/two_factor/core/setup.html | 3 +- 10 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 manager/migrations/0049_auto_20190308_1334.py create mode 100644 manager/migrations/0050_auto_20190308_1342.py diff --git a/device-config/1/etc/config/wireless b/device-config/1/etc/config/wireless index 4fefc2d..1798283 100644 --- a/device-config/1/etc/config/wireless +++ b/device-config/1/etc/config/wireless @@ -24,7 +24,8 @@ config wifi-device 'radio1' config wifi-iface option device 'radio1' option mode 'ap' - option encryption 'none' option ssid '$SSID' + option encryption '$ENC' + option key '$KEY' option network 'VPN360' diff --git a/device-config/2/etc/config/wireless b/device-config/2/etc/config/wireless index c261a97..5e3a647 100644 --- a/device-config/2/etc/config/wireless +++ b/device-config/2/etc/config/wireless @@ -14,7 +14,8 @@ config wifi-iface 'default_radio0' option device 'radio0' option network 'VPN360' option mode 'ap' - option encryption 'none' + option encryption '$ENC' + option key '$KEY' option ifname 'wlan0' option ssid '$SSID' diff --git a/manager/migrations/0049_auto_20190308_1334.py b/manager/migrations/0049_auto_20190308_1334.py new file mode 100644 index 0000000..1e8b171 --- /dev/null +++ b/manager/migrations/0049_auto_20190308_1334.py @@ -0,0 +1,28 @@ +# Generated by Django 2.1.5 on 2019-03-08 13:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('manager', '0048_auto_20190219_1521'), + ] + + operations = [ + migrations.AddField( + model_name='model', + name='key', + field=models.CharField(blank=True, max_length=64, null=True, verbose_name='Broadcast WPA2 Key'), + ), + migrations.AddField( + model_name='model', + name='ssid', + field=models.CharField(blank=True, max_length=32, null=True, verbose_name='Broadcast SSID'), + ), + migrations.AlterField( + model_name='device', + name='wifi', + field=models.ManyToManyField(blank=True, to='manager.Wifi'), + ), + ] diff --git a/manager/migrations/0050_auto_20190308_1342.py b/manager/migrations/0050_auto_20190308_1342.py new file mode 100644 index 0000000..c20d149 --- /dev/null +++ b/manager/migrations/0050_auto_20190308_1342.py @@ -0,0 +1,36 @@ +# Generated by Django 2.1.5 on 2019-03-08 13:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('manager', '0049_auto_20190308_1334'), + ] + + operations = [ + migrations.RemoveField( + model_name='model', + name='key', + ), + migrations.RemoveField( + model_name='model', + name='ssid', + ), + migrations.AddField( + model_name='device', + name='key', + field=models.CharField(blank=True, max_length=64, null=True, verbose_name='Broadcast WPA2 Key'), + ), + migrations.AddField( + model_name='device', + name='ssid', + field=models.CharField(blank=True, max_length=32, null=True, verbose_name='Broadcast SSID'), + ), + 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 e966020..a214dc4 100644 --- a/manager/models.py +++ b/manager/models.py @@ -63,9 +63,11 @@ class Device(models.Model): 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) def __str__(self): - return "%s%s" % (self.serial, " (%s)" % self.curip if self.curip else "") + return "%s%s" % (self.serial, " (%s)" % self.ssid if self.ssid else "") class DeviceLog(models.Model): ADD = 0 diff --git a/manager/tasks.py b/manager/tasks.py index 0538b32..a644a8e 100644 --- a/manager/tasks.py +++ b/manager/tasks.py @@ -53,7 +53,9 @@ def mkfirmware(device, path): wirein = wireless.read() with open(tempdir.name + "/etc/config/wireless", "w") as wireout: - wire = wirein.replace("$SSID", device.serial) + wire = wirein.replace("$SSID", device.ssid or device.serial) + wire = wire.replace("$KEY", device.key or "") + wire = wire.replace("$ENC", "psk2" if device.key else "none") wireout.write(wire + "\n" + makewificonfig(device)) # Create compilation environment diff --git a/manager/views.py b/manager/views.py index 17edeb3..f347b51 100644 --- a/manager/views.py +++ b/manager/views.py @@ -478,6 +478,8 @@ def makedevice(request): device_name = request.POST.get("name", "") device_organization = request.POST.get("organization", "") device_model = request.POST.get("model", "") + device_ssid = request.POST.get("ssid", device_serial) + device_key = request.POST.get("key", "") if not device_serial: orga = Organization.objects.all() @@ -515,6 +517,8 @@ def makedevice(request): device = Device.objects.create( serial=device_serial, name=device_name, + ssid=device_ssid, + key=device_key, model=Model.objects.filter(id=device_model)[0], network=Network.objects.filter(intip="No VPN")[0], organization=Organization.objects.filter(id=device_organization)[0], diff --git a/templates/manager/add.html b/templates/manager/add.html index 85e6096..ee448fd 100644 --- a/templates/manager/add.html +++ b/templates/manager/add.html @@ -12,6 +12,14 @@ +
+ + +
+
+ + +
+{% if user.is_staff %} +
+ + +
+
+ + +
+{% endif %}