From ce651453c420527208d2c7a26a9634de59b09a1e Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Wed, 4 May 2022 17:22:38 +0200 Subject: Add MAC to pills Retrieve and cache MACs one by one as users select clients. --- ogcp/static/js/ogcp.js | 19 ++++++++++++++++++- ogcp/views.py | 12 ++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ogcp/static/js/ogcp.js b/ogcp/static/js/ogcp.js index 4605e5d..ffddc58 100644 --- a/ogcp/static/js/ogcp.js +++ b/ogcp/static/js/ogcp.js @@ -1,16 +1,33 @@ const Endpoint = '/scopes/status'; +const macs = new Map(); const Interval = 1000; let updateTimeoutId = null; +async function show_client_mac(pill_id) { + const pill = $('#' +pill_id); + const ip = pill.html().split('
')[1] + + if (!macs.get(ip)) { + const resp = await fetch('/client/mac?ip=' + ip); + const resp_mac = await resp.json(); + macs.set(ip, resp_mac) + } + + const mac = macs.get(ip) + pill.append('
' + mac); +} + function showSelectedClient(client_checkbox) { const container = $('#selected-clients'); const pill_id = 'pill-' + client_checkbox.name.replaceAll(/[.]|[ ]/g, '_'); if (client_checkbox.checked) { - if (!($('#' + pill_id).length)) + if (!($('#' + pill_id).length)) { $(container).append('
' + client_checkbox.name + '
' + client_checkbox.value + '
'); + show_client_mac(pill_id); + } return; } diff --git a/ogcp/views.py b/ogcp/views.py index 7f54bcf..aae889f 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -284,6 +284,18 @@ def scopes_status(): scopes, _clients = get_scopes() return jsonify(scopes) + +@app.route('/client/mac', methods=['GET']) +@login_required +def get_client_mac(): + ip = parse_elements(request.args.to_dict()) + payload = {'client': list(ip)} + resp = g.server.get('/client/info', payload) + client_info = resp.json() + mac = client_info.get('mac') + return jsonify(mac) + + @app.route('/scopes/') @login_required def scopes(): -- cgit v1.2.3-18-g5258