From d2f45e5fb450ec0d22f9a482d68d693591a62c8c Mon Sep 17 00:00:00 2001 From: pixup1 Date: Tue, 26 Nov 2024 00:19:03 +0100 Subject: [PATCH] Allow editing bypass for whitelisted devices --- backend/langate/network/apps.py | 9 +++++---- backend/langate/network/models.py | 3 --- backend/langate/network/views.py | 1 + frontend/src/views/Management/Whitelist.vue | 19 ++++++++++++++++++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/backend/langate/network/apps.py b/backend/langate/network/apps.py index 108bf0c..8221054 100644 --- a/backend/langate/network/apps.py +++ b/backend/langate/network/apps.py @@ -68,16 +68,17 @@ def ready(self): with open("assets/misc/whitelist.txt", "r") as f: for line in f: line = line.strip().split("|") - if len(line) == 2 or len(line) == 3: + if len(line) >= 2 and len(line) <= 4: name = line[0] mac = line[1] - mark = line[2] if len(line) == 3 else SETTINGS["marks"][0]["value"] + mark = line[2] if len(line) >= 3 else SETTINGS["marks"][0]["value"] + bypass = line[3] if len(line) >= 4 else True dev = Device.objects.filter(mac=mac).first() if dev is None: - dev = DeviceManager.create_device(mac, name, True, True, mark) + dev = DeviceManager.create_device(mac, name, True, False, mark) else: dev.whitelisted = True - dev.bypass = True + dev.bypass = bypass dev.save() try: connect_res = netcontrol.connect_user(dev.mac, dev.mark, dev.bypass, dev.name) diff --git a/backend/langate/network/models.py b/backend/langate/network/models.py index db8988a..571f6f1 100644 --- a/backend/langate/network/models.py +++ b/backend/langate/network/models.py @@ -62,9 +62,6 @@ def create_device(mac, name, whitelisted=False, bypass=False, mark=None): name = generate_dev_name() if not mark: mark = SETTINGS["marks"][0]["value"] - if whitelisted: - # Whitelisted devices have bypass by default - bypass = True # Validate the MAC address validate_mac(mac) diff --git a/backend/langate/network/views.py b/backend/langate/network/views.py index 19007ec..f89a332 100644 --- a/backend/langate/network/views.py +++ b/backend/langate/network/views.py @@ -241,6 +241,7 @@ def patch(self, request, pk): request.data.get("mac", device.mac), request.data.get("name", device.name), request.data.get("mark", device.mark), + request.data.get("bypass", device.bypass), ) return Response(status=status.HTTP_200_OK) diff --git a/frontend/src/views/Management/Whitelist.vue b/frontend/src/views/Management/Whitelist.vue index 57be3f7..e740761 100644 --- a/frontend/src/views/Management/Whitelist.vue +++ b/frontend/src/views/Management/Whitelist.vue @@ -43,6 +43,11 @@ const { addNotification } = useNotificationStore(); key: 'mark', ordering: true, }, + { + name: 'Accès aux sites bloqués', + key: 'bypass', + ordering: false, + }, ]" :pagination="true" :search="true" @@ -72,6 +77,12 @@ const { addNotification } = useNotificationStore(); type: 'number', required: true, }, + { + name: 'Donner accès aux sites bloqués', + key: 'bypass', + type: 'checkbox', + required: false, + }, ], }, function: async (device, data) => { @@ -114,7 +125,7 @@ const { addNotification } = useNotificationStore(); return success; }, modal: { - title: 'Ajouter un appareil à la whitelist', + title: 'Ajouter à la whitelist', fields: [ { name: 'Nom', @@ -134,6 +145,12 @@ const { addNotification } = useNotificationStore(); type: 'number', required: true, }, + { + name: 'Donner accès aux sites bloqués', + key: 'bypass', + type: 'checkbox', + required: false, + }, ], }, function: async (data) => {