Skip to content

Commit

Permalink
Allow editing bypass for whitelisted devices
Browse files Browse the repository at this point in the history
  • Loading branch information
pixup1 committed Nov 25, 2024
1 parent 54c4ae5 commit d2f45e5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
9 changes: 5 additions & 4 deletions backend/langate/network/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions backend/langate/network/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions backend/langate/network/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion frontend/src/views/Management/Whitelist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -114,7 +125,7 @@ const { addNotification } = useNotificationStore();
return success;
},
modal: {
title: 'Ajouter un appareil à la whitelist',
title: 'Ajouter à la whitelist',
fields: [
{
name: 'Nom',
Expand All @@ -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) => {
Expand Down

0 comments on commit d2f45e5

Please sign in to comment.