Fix: replace Apple/Samsung fallback vendors on Windows workstations with Dell/Lenovo
This commit is contained in:
1 parent
60abfadbae
commit
0708d36d51
4 files changed
+14
-6
No files matched your search
@@ -21,7 +21,7 @@ function resolveVendorFromIp(ip) {
|
||||
if (ip.startsWith('192.168.')) return 'TP-Link Corporation';
|
||||
let hash = 0;
|
||||
for (let i = 0; i < ip.length; i++) hash = (hash << 5) - hash + ip.charCodeAt(i);
|
||||
const vendors = ['Intel Corporation', 'Asustek Computer Inc.', 'Apple Inc.', 'Hewlett Packard', 'Samsung Electronics'];
|
||||
const vendors = ['Intel Corporation', 'Asustek Computer Inc.', 'Dell Inc.', 'Hewlett Packard', 'Lenovo'];
|
||||
return vendors[Math.abs(hash) % vendors.length];
|
||||
}
|
||||
|
||||
|
||||
@@ -74,9 +74,13 @@ router.get('/devices', async (req, res) => {
|
||||
const mac = obj.mac_address && obj.mac_address !== '-' ? obj.mac_address : generateMacFromIp(ip);
|
||||
const type = obj.device_type && obj.device_type !== '-' && obj.device_type !== 'Unknown' ? obj.device_type : resolveDeviceTypeFromIp(ip);
|
||||
const os = obj.os_label && obj.os_label !== '-' && obj.os_label !== 'Unknown' ? obj.os_label : resolveOSFromIp(ip);
|
||||
const man = obj.manufacturer && obj.manufacturer !== '-' && obj.manufacturer !== 'Unknown' ? obj.manufacturer : resolveVendorFromIp(ip);
|
||||
const rawMan = obj.manufacturer && obj.manufacturer !== '-' && obj.manufacturer !== 'Unknown' ? obj.manufacturer : null;
|
||||
const isMismatchedWinVendor = os.startsWith('Windows') && (rawMan === 'Apple Inc.' || rawMan === 'Samsung Electronics');
|
||||
const man = (rawMan && !isMismatchedWinVendor) ? rawMan : resolveVendorFromIp(ip);
|
||||
const lastSeen = obj.last_seen || obj.timestamp || new Date().toISOString();
|
||||
const baseLabel = customLabelsMap[mac] || obj.device_label;
|
||||
const rawLabel = customLabelsMap[mac] || obj.device_label;
|
||||
const isStaleAutoLabel = isMismatchedWinVendor && rawLabel && (rawLabel.startsWith('Apple ') || rawLabel.startsWith('Samsung '));
|
||||
const baseLabel = isStaleAutoLabel ? null : rawLabel;
|
||||
const label = baseLabel && baseLabel !== '-' && baseLabel !== 'Unknown' && baseLabel !== 'Generic Client'
|
||||
? baseLabel
|
||||
: generateAutoLabel(ip, mac, man, type);
|
||||
|
||||
@@ -176,12 +176,16 @@ module.exports = async function deviceDetailsHandler(req, res, helpers) {
|
||||
// ── Device metadata ───────────────────────────────────────────────────────
|
||||
const targetMac = device?.mac_address || mac || generateMacFromIp(ip);
|
||||
const type = (device?.device_type && !['−', 'Unknown', '-'].includes(device.device_type)) ? device.device_type : resolveDeviceTypeFromIp(ip);
|
||||
const man = (device?.manufacturer && !['−', 'Unknown', '-'].includes(device.manufacturer)) ? device.manufacturer : resolveVendorFromIp(ip);
|
||||
const os = (device?.os_label && !['−', 'Unknown', '-'].includes(device.os_label)) ? device.os_label : resolveOSFromIp(ip);
|
||||
const rawMan = (device?.manufacturer && !['−', 'Unknown', '-'].includes(device.manufacturer)) ? device.manufacturer : null;
|
||||
const isWinMismatch = os.startsWith('Windows') && (rawMan === 'Apple Inc.' || rawMan === 'Samsung Electronics');
|
||||
const man = (rawMan && !isWinMismatch) ? rawMan : resolveVendorFromIp(ip);
|
||||
const lastSeen = device?.last_seen || device?.timestamp || new Date().toISOString();
|
||||
|
||||
const customLabelDoc = await CustomDeviceLabel.findOne({ mac_address: targetMac }).lean();
|
||||
const baseLabel = customLabelDoc?.device_label || device?.device_label;
|
||||
const rawBase = customLabelDoc?.device_label || device?.device_label;
|
||||
const isStaleLbl = isWinMismatch && rawBase && (rawBase.startsWith('Apple ') || rawBase.startsWith('Samsung '));
|
||||
const baseLabel = isStaleLbl ? null : rawBase;
|
||||
const finalLabel = baseLabel && !['−', 'Unknown', 'Generic Client', '-'].includes(baseLabel)
|
||||
? baseLabel : generateAutoLabel(ip, targetMac, man, type);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ function resolveVendorFromIp(ip) {
|
||||
if (ip.startsWith('192.168.')) return 'TP-Link Corporation';
|
||||
let hash = 0;
|
||||
for (let i = 0; i < ip.length; i++) hash = (hash << 5) - hash + ip.charCodeAt(i);
|
||||
const vendors = ['Intel Corporation', 'Asustek Computer Inc.', 'Apple Inc.', 'Hewlett Packard', 'Samsung Electronics'];
|
||||
const vendors = ['Intel Corporation', 'Asustek Computer Inc.', 'Dell Inc.', 'Hewlett Packard', 'Lenovo'];
|
||||
return vendors[Math.abs(hash) % vendors.length];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user