-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.js
executable file
·75 lines (68 loc) · 1.65 KB
/
status.js
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
#! /usr/bin/env node
var _redis = require('redis'),
knownMacs = process.env.RADAR_MAC_ADDRESSES;
var redis = {
client: null,
setStatus: function setStatus (turnOn) {
this.client.set('system-status', turnOn);
return;
}
};
if (process.argv.length) {
console.info('ARGV: \n', process.argv);
let possibleMACS = [];
for (let i = 0; i < process.argv.length; i++) {
if (process.argv[i].indexOf(':') > -1) {
possibleMACS.push(process.argv[i]);
}
}
let macsToCheck = possibleMACS.join(" ");
console.info(macsToCheck);
redis.client = _redis.createClient();
// XXX: validate arp table data a bit more
storeArpTable(macsToCheck, function (err, reply) {
if (err) {
redis.client.quit();
console.error(err);
process.exit();
}
// Check the data for MACS
redis.client.get('arpData', function (err, reply) {
if (err) {
redis.client.quit();
console.error(err);
process.exit();
}
if (parseTable(reply)) {
// we see a MAC
redis.setStatus(0);
} else {
redis.setStatus(1);
}
redis.client.quit();
process.exit();
});
});
} else {
console.error('No args?!');
redis.client.quit();
process.exit();
}
function storeArpTable (arpTableData, callback) {
if (!arpTableData) {
return callback('No arp data available');
}
redis.client.set('arpData', arpTableData, callback);
}
function parseTable (arpTableData) {
console.log('knownmacs? ', arpTableData.indexOf(knownMacs));
return arpTableData.indexOf(knownMacs);
}
process.on('SIGINT', function () {
try {
redis.client.quit();
process.exit();
} catch (ex) {
process.exit();
}
});