summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-07-03 14:25:34 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-07-03 14:25:34 +0200
commit9ea8a74c633082ba21640cf65d0aeb532c59d376 (patch)
tree645ad44d6582c93242a2ffa2faf519943dcf9014 /ogcp/views.py
parent84365a0db240144c5e8b55966489ffbaa31318b2 (diff)
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
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py9
1 files 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: