-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerakiReceiver.js
51 lines (42 loc) · 1.84 KB
/
merakiReceiver.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
// nodejs Meraki Presence receiver by Kris Linquist ([email protected])
//
// Prerequisite: the express node module. Use 'sudo npm install express' to install, then start this script with 'nodejs merakiReceiver.js' (sudo required if port <1024)
//
// Meraki will send a HTTP GET request to test the URL and expect to see the validator as a response.
// When it sends the presence information, it will also send the secret. This script validates that the secret is correct prior to parsing the data.
//
// This script listens for the uri {request_uri}:port/meraki
//
var listenport = 3000; //TCP listening port
var secret = "secretkeyverysecret"; //Secret that you chose in the Meraki dashboard
var validator = "7a64f52cde1a36ddb1e25819d509da619218e1b5"; //Validator string that is shown in the Meraki dashboard
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.get('/meraki', function(req, res){
res.send(validator);
console.log("sending validation")
});
app.post('/meraki', function(req, res){
try {
var jsoned = JSON.parse(req.body.data);
if (jsoned.secret == secret) {
for (i=0; i<jsoned.probing.length; i++) {
console.log("client " + jsoned.probing[i].client_mac + " seen on ap " + jsoned.probing[i].ap_mac + " with rssi " + jsoned.probing[i].rssi + " at " + jsoned.probing[i].last_seen);
}
} else {
console.log("invalid secret from " + req.connection.remoteAddress);
}
} catch (e) {
// An error has occured, handle it, by e.g. logging it
console.log("Error. Likely caused by an invalid POST from " + req.connection.remoteAddress + ":");
console.log(e);
res.end();
}
});
app.listen(listenport);
console.log("Meraki presence API receiver listening on port " + listenport);