102 lines
2.1 KiB
JavaScript
102 lines
2.1 KiB
JavaScript
var data = {
|
|
loc: [],
|
|
arc: []
|
|
}
|
|
|
|
var colors = {
|
|
loc: "green",
|
|
arc: ["green", "red"],
|
|
}
|
|
|
|
var stroke = {
|
|
loc: 0.1,
|
|
arc: 1.1
|
|
}
|
|
|
|
var geoip = require('geoip-lite');
|
|
|
|
function addArc(src, dest){
|
|
const arcName = src + " -> " + dest;
|
|
if(!data.arc.some(x => x.name === arcName)) {
|
|
if (!src.includes("192.168.1.")) {
|
|
var geoSrc = geoip.lookup(src);
|
|
var startLat = geoSrc.ll[0]
|
|
var startLng = geoSrc.ll[1]
|
|
} else {
|
|
console.log("w")
|
|
}
|
|
if (!dest.includes("192.168.1.")) {
|
|
var geoDest = geoip.lookup(dest);
|
|
var endLat = geoDest.ll[0]
|
|
var endLng = geoDest.ll[1]
|
|
} else {
|
|
console.log("w")
|
|
}
|
|
|
|
// console.log(geoSrc, geoDest)
|
|
if (geoSrc == undefined) {
|
|
startLat = 48.1712
|
|
startLng = 16.321
|
|
}
|
|
|
|
if (geoDest == undefined) {
|
|
endLat = 48.1712
|
|
endLng = 16.321
|
|
}
|
|
console.log(endLat, endLng)
|
|
|
|
var dat = {
|
|
name: arcName,
|
|
startLat: startLat,
|
|
startLng: startLng,
|
|
endLat: endLat,
|
|
endLng: endLng,
|
|
color: colors.arc,
|
|
stroke: stroke.arc
|
|
}
|
|
console.log(arcName)
|
|
data.arc.push(dat);
|
|
addLoc(arcName, startLat, startLng)
|
|
}
|
|
}
|
|
function addLoc(name, lat, lng){
|
|
var dat = {
|
|
name: name,
|
|
lat: lat,
|
|
lng: lng,
|
|
size: stroke.loc,
|
|
color: colors.loc
|
|
};
|
|
|
|
if(!data.loc.some(x => x.lat === lat && x.lng === lng)) {
|
|
data.loc.push(dat);
|
|
}else{
|
|
const dataIndex = data.loc.findIndex(obj => obj.lat === lat && obj.lng === lng);
|
|
data.loc[dataIndex].name = data.loc[dataIndex].name + "<br>" + name;
|
|
}
|
|
}
|
|
|
|
function getLocColor(){
|
|
return colors.loc;
|
|
}
|
|
|
|
function getArcColor(){
|
|
return colors.arc;
|
|
}
|
|
|
|
function getData(){
|
|
return data;
|
|
}
|
|
|
|
function getLocData(){
|
|
return data.loc;
|
|
}
|
|
|
|
function getArcData(){
|
|
return data.arc;
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
addArc, addLoc, getLocData, getArcColor, getData, getArcData, getLocColor
|
|
} |