From 9ea8a74c633082ba21640cf65d0aeb532c59d376 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Wed, 3 Jul 2024 14:25:34 +0200 Subject: views: normalize every MAC address during POST processing Use aabbccddeeaa as MAC format in every payload. List of accepted MAC formats: aabbccddeeaa aa:bb:cc:dd:ee:aa aa-bb-cc-dd-ee-aa aa.bb.cc.dd.ee.aa --- ogcp/views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ogcp/views.py b/ogcp/views.py index ac5df38..ab75280 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -96,6 +96,9 @@ class ServerError(Exception): class ServerErrorCode(Exception): pass +def normalize_mac(mac): + return mac.replace(':', '').replace('-', '').replace('.', '').lower() + def ogserver_down(view): flash(_('Cannot talk to ogserver. Is ogserver down?'), category='error') return redirect(url_for(view)) @@ -1307,7 +1310,7 @@ def action_client_update(): "room": int(form.room.data), "name": form.name.data, "boot": form.boot.data, - "mac": form.mac.data } + "mac": normalize_mac(form.mac.data) } server = get_server_from_ip_port(form.server.data) r = server.post('/client/update', payload) if r.status_code != requests.codes.ok: @@ -1550,7 +1553,7 @@ def action_client_add(): payload = {"boot": form.boot.data, "ip": form.ip.data, "livedir": form.livedir.data, - "mac": form.mac.data, + "mac": normalize_mac(form.mac.data), "maintenance": form.maintenance.data, "name": form.name.data, "netdriver": "generic", @@ -1762,7 +1765,7 @@ def action_clients_import_post(): 'room': int(form.room.data)} for client in clients: payload['name'] = client[0] - payload['mac'] = client[1].replace(':', '') + payload['mac'] = normalize_mac(client[1]) payload['ip'] = client[2] resp = server.post('/client/add', payload) if resp.status_code != requests.codes.ok: -- cgit v1.2.3-18-g5258