Add Wifi devices

This commit is contained in:
Kumi 2018-12-23 10:37:14 +01:00
parent bd4b713560
commit 2f10145f96
8 changed files with 104 additions and 10 deletions

View file

@ -30,3 +30,5 @@ config interface 'DHCP'
option netmask '255.255.255.0'
option ifname 'lo'
config interface 'wwan'
option proto 'dhcp'

View file

@ -27,13 +27,11 @@ config wifi-device 'radio1'
option noscan '1'
option txpower '20'
config wifi-iface 'default_radio1'
config wifi-iface
option network 'wwan'
option ssid '$WIFISSID'
option encryption 'psk2'
option device 'radio1'
option network 'VPN360'
option mode 'ap'
option ssid '$SSID-2.4'
option encryption 'none'
option wds '1'
option ifname 'wlan1'
option disabled '1'
option mode 'sta'
option key '$WIFIKEY'

View file

@ -1,7 +1,8 @@
from django.contrib import admin
from .models import Organization, Device, Network, Model
from .models import Organization, Device, Network, Model, Wifi
admin.site.register(Organization)
admin.site.register(Device)
admin.site.register(Network)
admin.site.register(Model)
admin.site.register(Wifi)

View file

@ -0,0 +1,32 @@
# Generated by Django 2.1.3 on 2018-12-20 16:41
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('manager', '0014_device_model'),
]
operations = [
migrations.CreateModel(
name='WiFi',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('serial', models.CharField(max_length=12, unique=True, verbose_name='Device Serial Number')),
('ssid', models.CharField(max_length=32, verbose_name='WiFi SSID')),
('bssid', models.CharField(blank=True, max_length=64, null=True, verbose_name='WiFi BSSID')),
('key', models.CharField(max_length=32, verbose_name='WiFi key')),
('ip', models.CharField(blank=True, max_length=15, null=True, verbose_name='Configuration IP')),
('user', models.CharField(blank=True, max_length=32, null=True, verbose_name='Configuration User Name')),
('password', models.CharField(blank=True, max_length=32, null=True, verbose_name='Configuration Password')),
],
),
migrations.AddField(
model_name='device',
name='wifi',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='manager.WiFi'),
),
]

View file

@ -0,0 +1,19 @@
# Generated by Django 2.1.3 on 2018-12-20 16:43
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('manager', '0015_auto_20181220_1641'),
]
operations = [
migrations.AlterField(
model_name='device',
name='wifi',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='manager.Wifi'),
),
]

View file

@ -0,0 +1,19 @@
# Generated by Django 2.1.3 on 2018-12-23 09:36
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('manager', '0016_auto_20181220_1643'),
]
operations = [
migrations.AlterField(
model_name='device',
name='wifi',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='manager.Wifi'),
),
]

View file

@ -28,12 +28,25 @@ class Model(models.Model):
def __str__(self):
return self.name
class Wifi(models.Model):
serial = models.CharField("Device Serial Number", max_length=12, unique=True)
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.CharField("Configuration IP", max_length=15, 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):
return "%s (%s)" % (this.serial, this.ssid)
class Device(models.Model):
serial = models.CharField("Device Serial Number", max_length=12, unique=True)
name = models.CharField("Common Name", max_length=100, default="", blank=True, null=True)
model = models.ForeignKey(Model, on_delete=models.CASCADE)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
network = models.ForeignKey(Network, on_delete=models.SET_NULL, blank=True, null=True)
wifi = models.OneToOneField(Wifi, on_delete=models.SET_NULL, blank=True, null=True)
curip = models.CharField("Current IP Address", max_length=15, blank=True, null=True)
lasttime = models.DateTimeField("Last Received IP", blank=True, null=True)
lastbeat = models.DateTimeField("Last Received Timestamp", blank=True, null=True)

View file

@ -185,7 +185,17 @@ def getconfig(request, device_id):
wirein = wireless.read()
with open(tempdir.name + "/etc/config/wireless", "w") as wireout:
wireout.write(wirein.replace("$SSID", device.serial))
wire = wirein.replace("$SSID", device.serial)
try:
wire2 = wire.replace("$WIFISSID", device.wifi.ssid)
wire2 = wire2.replace("$WIFIKEY", device.wifi.key)
except:
wire2 = wire.replace("$WIFISSID", "NoSuchWiFi")
wire2 = wire2.replace("$WIFIKEY", "NoSuchKey")
wireout.write(wire2)
'''
# Generate .tar.gz file