mirror of
https://github.com/SpacehuhnTech/esp8266_deauther.git
synced 2025-12-21 14:09:59 +01:00
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:
@@ -120,7 +120,7 @@ void ClientScan::packetSniffer(uint8_t *buf, uint16_t len) {
|
||||
}
|
||||
|
||||
String ClientScan::getClientName(int num) {
|
||||
return nameList.get(clients._get(num));
|
||||
return nameList.getName(nameList.get(clients._get(num)));
|
||||
}
|
||||
int ClientScan::getClientPackets(int num) {
|
||||
return packets[clients.getNum(clients._get(num))];
|
||||
@@ -169,7 +169,8 @@ size_t ClientScan::getSize(){
|
||||
json += "\"i\":" + (String)i + ",";
|
||||
json += "\"p\":" + (String)getClientPackets(i) + ",";
|
||||
json += "\"m\":\"" + getClientMac(i).toString() + "\",";
|
||||
json += "\"n\":\"" + (String)nameList.get(getClientMac(i)) + "\",";
|
||||
json += "\"n\":\"" + (String)nameList.getName(nameList.get(getClientMac(i))) + "\",";
|
||||
json += "\"l\":" + (String)nameList.get(getClientMac(i)) + ",";
|
||||
json += "\"v\":\"" + (String)getClientVendor(i) + "\",";
|
||||
json += "\"s\":" + (String)getClientSelected(i) + ",";
|
||||
if(getClientConnectedAp(i)>=0) json += "\"a\":\"" + (String)apScan.getAPName(getClientConnectedAp(i)) + "\"";
|
||||
@@ -207,7 +208,8 @@ void ClientScan::send() {
|
||||
json += "\"i\":" + (String)i + ",";
|
||||
json += "\"p\":" + (String)getClientPackets(i) + ",";
|
||||
json += "\"m\":\"" + getClientMac(i).toString() + "\",";
|
||||
json += "\"n\":\"" + (String)nameList.get(getClientMac(i)) + "\",";
|
||||
json += "\"n\":\"" + (String)nameList.getName(nameList.get(getClientMac(i))) + "\",";
|
||||
json += "\"l\":" + (String)nameList.get(getClientMac(i)) + ",";
|
||||
json += "\"v\":\"" + (String)getClientVendor(i) + "\",";
|
||||
json += "\"s\":" + (String)getClientSelected(i) + ",";
|
||||
if(getClientConnectedAp(i)>=0) json += "\"a\":\"" + (String)apScan.getAPName(getClientConnectedAp(i)) + "\"";
|
||||
|
||||
@@ -50,24 +50,21 @@ void NameList::add(Mac client, String name) {
|
||||
NameList::save();
|
||||
}
|
||||
|
||||
String NameList::get(Mac client) {
|
||||
int NameList::get(Mac client) {
|
||||
String returnStr;
|
||||
int clientNum = clients.getNum(client);
|
||||
if (clientNum > -1) {
|
||||
for (int h = 0; h < nameLength; h++) {
|
||||
if (names[clientNum][h] != 0x00) returnStr += (char)names[clientNum][h];
|
||||
}
|
||||
}
|
||||
return returnStr;
|
||||
return clientNum;
|
||||
}
|
||||
|
||||
String NameList::getName(int num) {
|
||||
String returnStr;
|
||||
for (int h = 0; h < nameLength; h++) {
|
||||
if (names[num][h] != 0x00) returnStr += (char)names[num][h];
|
||||
if (num >= 0) {
|
||||
for (int h = 0; h < nameLength; h++) {
|
||||
if (names[num][h] != 0x00) returnStr += (char)names[num][h];
|
||||
}
|
||||
returnStr.trim();
|
||||
return returnStr;
|
||||
}
|
||||
returnStr.trim();
|
||||
return returnStr;
|
||||
}
|
||||
|
||||
Mac NameList::getMac(int num) {
|
||||
|
||||
@@ -25,7 +25,7 @@ class NameList
|
||||
void clear();
|
||||
void add(Mac client, String name);
|
||||
void edit(int num, String name);
|
||||
String get(Mac client);
|
||||
int get(Mac client);
|
||||
String getName(int num);
|
||||
Mac getMac(int num);
|
||||
void remove(int num);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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> | <button class="marginNull button-primary" onclick="select(-2)">deselect</button> all</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> | <button class="marginNull button-primary" onclick="select(-2)">deselect</button> all</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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user