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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242class LocationGlobe {
constructor(parentId) {
if (!parentId) throw "Missing parameters";
const path = require("path");
this._geodata = require(path.join(__dirname, "assets/misc/grid.json"));
require(path.join(__dirname, "assets/vendor/encom-globe.js"));
this.ENCOM = window.ENCOM;
// Create DOM and include lib
this.parent = document.getElementById(parentId);
this.parent.innerHTML += `<div id="mod_globe">
<div id="mod_globe_innercontainer">
<h1>WORLD VIEW<i>GLOBAL NETWORK MAP</i></h1>
<h2>ENDPOINT LAT/LON<i class="mod_globe_headerInfo">0.0000, 0.0000</i></h2>
<div id="mod_globe_canvas_placeholder"></div>
<h3>OFFLINE</h3>
</div>
</div>`;
this.lastgeo = {};
this.conns = [];
setTimeout(() => {
let container = document.getElementById("mod_globe_innercontainer");
let placeholder = document.getElementById("mod_globe_canvas_placeholder");
// Create Globe
this.globe = new this.ENCOM.Globe(placeholder.offsetWidth, placeholder.offsetHeight, {
font: window.theme.cssvars.font_main,
data: [],
tiles: this._geodata.tiles,
baseColor: window.theme.globe.base || `rgb(${window.theme.r},${window.theme.g},${window.theme.b})`,
markerColor: window.theme.globe.marker || `rgb(${window.theme.r},${window.theme.g},${window.theme.b})`,
pinColor: window.theme.globe.pin || `rgb(${window.theme.r},${window.theme.g},${window.theme.b})`,
satelliteColor: window.theme.globe.satellite || `rgb(${window.theme.r},${window.theme.g},${window.theme.b})`,
scale: 1.1,
viewAngle: 0.630,
dayLength: 1000 * 45,
introLinesDuration: 2000,
introLinesColor: window.theme.globe.marker || `rgb(${window.theme.r},${window.theme.g},${window.theme.b})`,
maxPins: 300,
maxMarkers: 100
});
// Place Globe
placeholder.remove();
container.append(this.globe.domElement);
// Init animations
this._animate = () => {
if (window.mods.globe.globe) {
window.mods.globe.globe.tick();
}
if (window.mods.globe._animate) {
setTimeout(() => {
try {
requestAnimationFrame(window.mods.globe._animate);
} catch(e) {
// We probably got caught in a theme change. Print it out but everything should keep running fine.
console.warn(e);
}
}, 1000 / 30);
}
};
this.globe.init(window.theme.colors.light_black, () => {
this._animate();
window.audioManager.scan.play();
});
// resize handler
this.resizeHandler = () => {
let canvas = document.querySelector("div#mod_globe canvas");
window.mods.globe.globe.camera.aspect = canvas.offsetWidth / canvas.offsetHeight;
window.mods.globe.globe.camera.updateProjectionMatrix();
window.mods.globe.globe.renderer.setSize(canvas.offsetWidth, canvas.offsetHeight);
};
window.addEventListener("resize", this.resizeHandler);
// Connections
this.conns = [];
this.addConn = ip => {
let data = null;
try {
data = window.mods.netstat.geoLookup.get(ip);
} catch {
// do nothing
}
let geo = (data !== null ? data.location : {});
if (geo.latitude && geo.longitude) {
const lat = Number(geo.latitude);
const lon = Number(geo.longitude);
window.mods.globe.conns.push({
ip,
pin: window.mods.globe.globe.addPin(lat, lon, "", 1.2),
});
}
};
this.removeConn = ip => {
let index = this.conns.findIndex(x => x.ip === ip);
this.conns[index].pin.remove();
this.conns.splice(index, 1);
};
// Add random satellites
let constellation = [];
for(var i = 0; i< 2; i++){
for(var j = 0; j< 3; j++){
constellation.push({
lat: 50 * i - 30 + 15 * Math.random(),
lon: 120 * j - 120 + 30 * i,
altitude: Math.random() * (1.7 - 1.3) + 1.3
});
}
}
this.globe.addConstellation(constellation);
}, 2000);
// Init updaters when intro animation is done
setTimeout(() => {
this.updateLoc();
this.locUpdater = setInterval(() => {
this.updateLoc();
}, 1000);
this.updateConns();
this.connsUpdater = setInterval(() => {
this.updateConns();
}, 3000);
}, 4000);
}
addRandomConnectedMarkers() {
const randomLat = this.getRandomInRange(40, 90, 3);
const randomLong = this.getRandomInRange(-180, 0, 3);
this.globe.addMarker(randomLat, randomLong, '');
this.globe.addMarker(randomLat - 20, randomLong + 150, '', true);
}
addTemporaryConnectedMarker(ip) {
let data = window.mods.netstat.geoLookup.get(ip);
let geo = (data !== null ? data.location : {});
if (geo.latitude && geo.longitude) {
const lat = Number(geo.latitude);
const lon = Number(geo.longitude);
window.mods.globe.conns.push({
ip,
pin: window.mods.globe.globe.addPin(lat, lon, "", 1.2)
});
let mark = window.mods.globe.globe.addMarker(lat, lon, '', true);
setTimeout(() => {
mark.remove();
}, 3000);
}
}
removeMarkers() {
this.globe.markers.forEach(marker => { marker.remove(); });
this.globe.markers = [];
}
removePins() {
this.globe.pins.forEach(pin => {
pin.remove();
});
this.globe.pins = [];
}
getRandomInRange(from, to, fixed) {
return (Math.random() * (to - from) + from).toFixed(fixed) * 1;
}
updateLoc() {
if (window.mods.netstat.offline) {
document.querySelector("div#mod_globe").setAttribute("class", "offline");
document.querySelector("i.mod_globe_headerInfo").innerText = "(OFFLINE)";
this.removePins();
this.removeMarkers();
this.conns = [];
this.lastgeo = {
latitude: 0,
longitude: 0
};
} else {
this.updateConOnlineConnection().then(() => {
document.querySelector("div#mod_globe").setAttribute("class", "");
}).catch(() => {
document.querySelector("i.mod_globe_headerInfo").innerText = "UNKNOWN";
})
}
}
async updateConOnlineConnection() {
let newgeo = window.mods.netstat.ipinfo.geo;
newgeo.latitude = Math.round(newgeo.latitude*10000)/10000;
newgeo.longitude = Math.round(newgeo.longitude*10000)/10000;
if (newgeo.latitude !== this.lastgeo.latitude || newgeo.longitude !== this.lastgeo.longitude) {
document.querySelector("i.mod_globe_headerInfo").innerText = `${newgeo.latitude}, ${newgeo.longitude}`;
this.removePins();
this.removeMarkers();
//this.addRandomConnectedPoints();
this.conns = [];
this._locPin = this.globe.addPin(newgeo.latitude, newgeo.longitude, "", 1.2);
this._locMarker = this.globe.addMarker(newgeo.latitude, newgeo.longitude, "", false, 1.2);
}
this.lastgeo = newgeo;
document.querySelector("div#mod_globe").setAttribute("class", "");
}
updateConns() {
if (!window.mods.globe.globe || window.mods.netstat.offline) return false;
window.si.networkConnections().then(conns => {
let newconns = [];
conns.forEach(conn => {
let ip = conn.peeraddress;
let state = conn.state;
if (state === "ESTABLISHED" && ip !== "0.0.0.0" && ip !== "127.0.0.1" && ip !== "::") {
newconns.push(ip);
}
});
this.conns.forEach(conn => {
if (newconns.indexOf(conn.ip) !== -1) {
newconns.splice(newconns.indexOf(conn.ip), 1);
} else {
this.removeConn(conn.ip);
}
});
newconns.forEach(ip => {
this.addConn(ip);
});
});
}
}
module.exports = {
LocationGlobe
};