-
Notifications
You must be signed in to change notification settings - Fork 2
/
contruct_files_and_markdown_properties
94 lines (79 loc) · 4 KB
/
contruct_files_and_markdown_properties
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Construct custom Spark Message for Follow Client Tracking
// Build custom Google PATH to create uncerntainty circle
// Your Google Static Map API Key
var googleApi = '< Google API Key >';
// Google Static Maps Path Circle Function
// Ref: borland592:https://stackoverflow.com/questions/7316963/drawing-a-circle-google-static-maps/35660617#35660617
function GMapCircle(lat,lng,rad,detail=8){
// Customise your Static Map parameters
var uri = 'https://maps.googleapis.com/maps/api/staticmap?';
var staticMapSrc = 'center=' + lat + ',' + lng;
staticMapSrc += '&zoom=19';
staticMapSrc += '&scale=2';
staticMapSrc += '&size=640x400';
staticMapSrc += '&maptype=roadmap';
staticMapSrc += '&key='+googleApi;
staticMapSrc += '&format=jpg';
staticMapSrc += '&path=color:0x29fd2f|weight:3|fillcolor:0x29fd2f33';
var r = 6371;
var pi = Math.PI;
var _lat = (lat * pi) / 180;
var _lng = (lng * pi) / 180;
var d = (rad/1000) / r;
var i = 0;
for(i = 0; i <= 360; i+=detail) {
var brng = i * pi / 180;
var pLat = Math.asin(Math.sin(_lat) * Math.cos(d) + Math.cos(_lat) * Math.sin(d) * Math.cos(brng));
var pLng = ((_lng + Math.atan2(Math.sin(brng) * Math.sin(d) * Math.cos(_lat), Math.cos(d) - Math.sin(_lat) * Math.sin(pLat))) * 180) / pi;
pLat = (pLat * 180) / pi;
staticMapSrc += "|" + pLat + "," + pLng;
}
// Add Marker to Map
if (msg.payload.type == "wireless") {
staticMapSrc += '&markers=color:0xea4335|label:W|'+lat +','+ lng;
} else {
staticMapSrc += '&markers=color:0x4285f4|label:B|'+lat +','+ lng;
}
// Return custom map URI
return uri + encodeURI(staticMapSrc);}
// Pass Scanning API parameters to GMapCircle Function
var staticMap = GMapCircle(msg.payload.lat,msg.payload.lng,msg.payload.unc,detail=8);
// Build markdown payload
if (msg.payload.type == "wireless") {
// Render wireless markdown
msg.payload.markdown = '**Following Wireless Client**<br>' +
'**Name:** ' + msg.payload.name +
'<br>**First Seen:** ' + msg.payload.cfirstseen +
'<br>**Last Seen:** ' + msg.payload.clastseen +
'<br>**Latitude:** ' + msg.payload.lat +
'<br>**Longitude:** ' + msg.payload.lng +
'<br>**IP:** ' + msg.payload.ipv4 +
'<br>**MAC:** ' + msg.payload.mac +
'<br>**Manufacturer:** ' + msg.payload.manufacturer +
'<br>**OS:** ' + msg.payload.os +
'<br>**RSSI:** ' + msg.payload.rssi +
'<br>**SSID:** ' + msg.payload.ssid;
} else {
// Render bluetooth markdown string
msg.payload.markdown = '**Following Bluetooth Client**<br>' +
'**Name:** ' + msg.payload.name +
'<br>**First Seen:** ' + msg.payload.cfirstseen +
'<br>**Last Seen:** ' + msg.payload.clastseen +
'<br>**Latitude:** ' + msg.payload.lat +
'<br>**Longitude:** ' + msg.payload.lng +
'<br>**MAC:** ' + msg.payload.mac +
'<br>**RSSI:** ' + msg.payload.rssi;
}
// Build Camera String for Spark Post based on tag
if (msg.payload.tag.indexOf('front') >= 0) {
msg.payload.markdown = msg.payload.markdown + '<br>**Camera:** ' + 'https://<shard>.meraki.com/<network>/n/<group>/manage/nodes/new_list/<node A>?timestamp=' + msg.payload.epoch;
}
if (msg.payload.tag.indexOf('rear') >= 0) {
msg.payload.markdown = msg.payload.markdown + '<br>**Camera:** ' + 'https://<shard>.meraki.com/<network>/n/<group>/manage/nodes/new_list/<node B>?timestamp=' + msg.payload.epoch;
}
if (msg.payload.tag.indexOf('hall') >= 0) {
msg.payload.markdown = msg.payload.markdown + '<br>**Camera:** ' + 'https://<shard>.meraki.com/<network>/n/<group>/manage/nodes/new_list/<node C>?timestamp=' + msg.payload.epoch;
}
// Render files string
msg.payload.files = staticMap;
return msg;