-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapply-fix.mjs
More file actions
77 lines (69 loc) · 2.66 KB
/
apply-fix.mjs
File metadata and controls
77 lines (69 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env node
import fs from 'fs';
const file = './server.js';
let content = fs.readFileSync(file, 'utf8');
const oldCode = ` if (localResults.length > 0) {
const best = localResults[0];
result.source = 'local-db';
result.found = true;
result.endpoint = {
device: best.device,
deviceIp: best.device_ip,
ifName: best.interface,
vlan: best.vlan,
source: 'local-nodes'
};
result.dbResult = {
local: { count: localResults.length, data: localResults }
};
result.elapsed = \`\${Date.now() - t0}ms\`;
console.log(\`[MAC-HYBRID] Found in LOCAL DB: \${result.endpoint?.device} \${result.endpoint?.ifName} (\${localElapsed}ms)\`);
return res.json(result);
}
} catch (localErr) {`;
const newCode = ` if (localResults.length > 0) {
const best = localResults[0];
const bestIsPhysical = isPhysicalPort(best.interface);
// Salva i risultati DB
result.dbResult = {
local: { count: localResults.length, data: localResults }
};
// Se la migliore porta è FISICA, restituisci subito
if (bestIsPhysical) {
result.source = 'local-db';
result.found = true;
result.endpoint = {
device: best.device,
deviceIp: best.device_ip,
ifName: best.interface,
vlan: best.vlan,
source: 'local-nodes'
};
result.elapsed = \`\${Date.now() - t0}ms\`;
console.log(\`[MAC-HYBRID] Found PHYSICAL PORT in LOCAL DB: \${result.endpoint?.device} \${result.endpoint?.ifName} (\${localElapsed}ms)\`);
return res.json(result);
}
// Se è VLAN interface, salva info e continua per trovare porta fisica
console.log(\`[MAC-HYBRID] Local DB has only VLAN interface (\${best.interface}), continuing to find physical port...\`);
result.vlanResult = {
device: best.device,
deviceIp: best.device_ip,
vlanInterface: best.interface,
vlan: best.vlan
};
}
} catch (localErr) {`;
if (content.includes(oldCode)) {
content = content.replace(oldCode, newCode);
fs.writeFileSync(file, content);
console.log('✓ FASE 0 modificata con successo');
} else {
console.log('⚠ FASE 0 non trovata o già modificata');
}
// Verifica
const check = fs.readFileSync(file, 'utf8');
if (check.includes('bestIsPhysical')) {
console.log('✓ Modifica applicata correttamente');
} else {
console.log('✗ Modifica NON applicata');
}