Skip to content

Commit

Permalink
Added ignore list
Browse files Browse the repository at this point in the history
  • Loading branch information
Jey-Cee committed Feb 3, 2025
1 parent 54e2a73 commit 61ae0cc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
3 changes: 2 additions & 1 deletion admin/i18n/de/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"endIp": "Letzte IP Adresse",
"descriptionIpRange": "Falls kein benutzerdefinierter IP Bereich angeben wird, wird dieser von Net Tools anhand der Schnittstellenkonfiguration ermittelt.<br>Wenn der IP Bereich aus der Schnittstellenkonfiguration übernommen wird, kann der Scanvorgang sehr viel Zeit in Anspruch nehmen.",
"autoSearch": "Automatische Erkennung von Geräten",
"searchSchedule": "Zeitplan für die Suche"
"searchSchedule": "Zeitplan für die Suche",
"ignore list text": "Anmerkung: Jede MAC-Adresse in dieser Liste wird bei der automatischen Erkennung ignoriert."
}
4 changes: 2 additions & 2 deletions admin/i18n/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"endIp": "End IP address",
"descriptionIpRange": "If you do not enter a custom IP range Net Tools will determine it by interface configuration.<br>If the IP range is taken from interface configuration the scan process can take a long time to finish.",
"autoSearch": "Auto discover devices",
"searchSchedule": "Time schedule for the search"

"searchSchedule": "Time schedule for the search",
"ignore list text": "Note: Every MAC address on this list will be ignored on autodiscovery."
}
34 changes: 34 additions & 0 deletions admin/jsonConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,40 @@
"height": "100%",
"overflow": "hidden"
}
},
"ignoreList": {
"type": "panel",
"label": "Ignore List",
"items": {
"helpIgnoreList": {
"type": "staticText",
"text": "ignore list text"
},
"ignoreListTable": {
"type": "table",
"items": [
{
"type": "text",
"title": "MAC",
"attr": "mac",
"filter": true,
"sort": true,
"default": ""
},
{
"type": "text",
"title": {
"en": "Comment",
"de": "Kommentar"
},
"attr": "comment",
"filter": true,
"sort": true,
"default": ""
}
]
}
}
}
}
}
25 changes: 19 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,13 @@ class NetTools extends utils.Adapter {
if(oldDevices[device].native?.ip) {
newDevice.ip = oldDevices[device].native.ip;
}
devices.push(newDevice);
// Check if device is on ignore list, if not add it to array

const ignore = await this.checkIgnore(newDevice.mac);
console.log(ignore);
console.log(this.config.ignoreListTable);
console.log(newDevice.mac);
if(!ignore) devices.push(newDevice);
}

oldDevices = [];
Expand Down Expand Up @@ -400,6 +406,10 @@ class NetTools extends utils.Adapter {
}
}

async checkIgnore(mac){
return this.config.ignoreListTable.find((/** @type {{ mac: string; }} */ entry) => entry.mac === mac);
}

async handleDiscoveryProbe(ip, oldDevices, decimalSeparator){
return new Promise(async (resolve, reject) => {
try {
Expand Down Expand Up @@ -431,7 +441,7 @@ class NetTools extends utils.Adapter {
}
if (exists === true && entry.ip !== '' && entry.ip !== undefined && entry.ip !== result.host && entry.mac === result.mac) {
const idName = result.mac.replace(/:/g, '');
await this.extendObjectAsync(this.namespace + '.' + idName, {
await this.extendObject(this.namespace + '.' + idName, {
native: {
ip: result.host,
vendor: result.vendor
Expand All @@ -440,8 +450,11 @@ class NetTools extends utils.Adapter {
}
}


if (!exists) {
const ignore = await this.checkIgnore(result.mac);
console.log(ignore);
console.log(this.config.ignoreListTable);
console.log(result.mac);
if (!exists && !ignore) {
await this.addDevice(result.host, result.name, true, result.mac);
}
}
Expand Down Expand Up @@ -532,7 +545,7 @@ class NetTools extends utils.Adapter {



await this.extendObjectAsync(this.namespace + '.' + idName, {
await this.extendObject(this.namespace + '.' + idName, {
type: 'device',
common: {
name: name || ip
Expand All @@ -548,7 +561,7 @@ class NetTools extends utils.Adapter {
});

for (const obj in objects){
await this.extendObjectAsync(idName + '.' + obj, objects[obj]);
await this.extendObject(idName + '.' + obj, objects[obj]);
}


Expand Down

0 comments on commit 61ae0cc

Please sign in to comment.