Add MAC to pills

Retrieve and cache MACs one by one as users select clients.
multi-ogserver
Javier Sánchez Parra 2022-05-04 17:22:38 +02:00
parent 72c10e1529
commit ce651453c4
2 changed files with 30 additions and 1 deletions

View File

@ -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('<br>')[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('<br>' + 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('<div class="badge badge-pill og-pill badge-light" ' +
'id="'+ pill_id + '">' + client_checkbox.name +
'<br>' + client_checkbox.value + '</div>');
show_client_mac(pill_id);
}
return;
}

View File

@ -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():