Fixed NameList bug

This change the NameList class in order to fix the bug when you try to
edit the name of sniffed clients.

Now NameList::get  return the id of the namelist when receiving a mac
adress (return -1 if the mac adress is not found)

Now NameList::getName return the name when received an id (return
nothing if the id is not found)
This commit is contained in:
N0vaPixel
2017-05-14 01:54:38 +02:00
parent 4c069a53bd
commit ec0d4fb2f2
5 changed files with 38 additions and 24 deletions

View File

@@ -35,15 +35,18 @@ function getResults() {
clientsFound.innerHTML = res.clients.length;
var tr = '';
if (res.clients.length > 0) tr += '<tr><th>Pkts</th><th>Vendor</th><th>Name</th><th>MAC</th><th>AP</th><th><button class="marginNull button-primary" onclick="select(-1)">select</button>&nbsp|&nbsp<button class="marginNull button-primary" onclick="select(-2)">deselect</button>&nbspall</th></tr>';
if (res.clients.length > 0) tr += '<tr><th>Pkts</th><th>Vendor</th><th>Name</th><th>MAC</th><th>AP</th>';
if (res.clients.length > 1) tr += '<th><button class="marginNull button-primary" onclick="select(-1)">select</button>&nbsp|&nbsp<button class="marginNull button-primary" onclick="select(-2)">deselect</button>&nbspall</th></tr>';
else tr += '<th>Select</th></tr>';
for (var i = 0; i < res.clients.length; i++) {
if (res.clients[i].s == 1) tr += '<tr class="selected">';
else tr += '<tr>';
tr += '<td>' + res.clients[i].p + '</td>';
tr += '<td>' + res.clients[i].v + '</td>';
tr += '<td>' + res.clients[i].n + ' <a onclick="changeName(' + res.clients[i].i + ')">edit</a></td>';
if(res.clients[i].l >= 0) tr += '<td>' + res.clients[i].n + ' <a onclick="editNameList(' + res.clients[i].l + ')">edit</a></td>';
else tr += '<td><a onclick="setName(' + res.clients[i].i + ')">set</a></td>';
tr += '<td>' + res.clients[i].m + '</td>';
tr += '<td>' + res.clients[i].a + '</td>';
@@ -62,7 +65,7 @@ function getResults() {
tr += '<tr>';
tr += '<td>' + res.nameList[i].m + '</td>';
tr += '<td>' + res.nameList[i].n + ' <a onclick="changeName(' + i + ')">edit</a></td>';
tr += '<td>' + res.nameList[i].n + ' <a onclick="editNameList(' + i + ')">edit</a></td>';
tr += '<td><button class="marginNull button-warn" onclick="deleteName(' + i + ')">x</button></td>';
tr += '<td><button class="marginNull button-primary" onclick="add(' + i + ')">add</button></td>';
tr += '</tr>';
@@ -110,10 +113,22 @@ function addClient(){
});
}
function changeName(id) {
var newName = prompt("Name for " + res.nameList[id].m);
function setName(id) {
var newName = prompt("Name for " + res.clients[id].m);
if (newName != null) {
getResponse("editNameList.json?id=" + id + "&name=" + newName, function(responseText) {
getResponse("setName.json?id=" + id + "&name=" + newName, function(responseText) {
if(responseText == "true") getResults();
else showMessage("response error editNameList.json");
});
}
}
function editNameList(id) {
var newName = prompt("Name for " + res.nameList[id].m);
if (newName != null) {
getResponse("editNameList.json" + "?id=" + id + "&name=" + newName, function(responseText) {
if(responseText == "true") getResults();
else showMessage("response error editNameList.json");
});