Added device location

This commit is contained in:
Ylian Saint-Hilaire 2017-08-28 15:06:29 -07:00
parent 888e8dedef
commit 41125c66ee
6 changed files with 1429 additions and 2 deletions

View File

@ -393,7 +393,12 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
case 'location':
{
// Sent by the agent to update location information
console.log(JSON.stringify(command));
if ((command.type == 'publicip') && (typeof command.value == 'object') && (command.value.ip) && (command.value.loc)) {
var x = {};
x.publicip = command.value.ip;
x.iploc = command.value.loc;
ChangeAgentLocationInfo(x);
}
break;
}
}
@ -451,6 +456,41 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
});
}
// Change the current core information string and event it
function ChangeAgentLocationInfo(command) {
if ((command == undefined) || (command == null)) return; // Safety, should never happen.
// Check that the mesh exists
obj.db.Get(obj.dbMeshKey, function (err, meshes) {
if (meshes.length != 1) return;
var mesh = meshes[0];
// Get the node and change it if needed
obj.db.Get(obj.dbNodeKey, function (err, nodes) {
if (nodes.length != 1) return;
var device = nodes[0];
if (device.agent) {
var changes = [], change = 0;
// Check if anything changes
if ((command.publicip) && (device.publicip != command.publicip)) { device.publicip = command.publicip; change = 1; changes.push('public ip'); }
if ((command.iploc) && (device.iploc != command.iploc)) { device.iploc = command.iploc; change = 1; changes.push('ip location'); }
// If there are changes, save and event
if (change == 1) {
obj.db.Set(device);
// Event the node change
var event = { etype: 'node', action: 'changenode', nodeid: obj.dbNodeKey, domain: domain.id, msg: 'Changed device ' + device.name + ' from mesh ' + mesh.name + ': ' + changes.join(', ') };
var device2 = obj.common.Clone(device);
if (device2.intelamt && device2.intelamt.pass) delete device2.intelamt.pass; // Remove the Intel AMT password before eventing this.
event.node = device;
obj.parent.parent.DispatchEvent(['*', device.meshid], obj, event);
}
}
});
});
}
// Update the mesh agent tab in the database
function ChangeAgentTag(tag) {
if (tag.length == 0) { tag = undefined; }

BIN
public/images/dot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

1039
public/scripts/ol.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

297
public/styles/ol.css Normal file
View File

@ -0,0 +1,297 @@
.ol-box {
box-sizing: border-box;
border-radius: 2px;
border: 2px solid #00f;
}
.ol-mouse-position {
top: 8px;
right: 8px;
position: absolute;
}
.ol-scale-line {
background: rgba(0,60,136,.3);
border-radius: 4px;
bottom: 8px;
left: 8px;
padding: 2px;
position: absolute;
}
.ol-scale-line-inner {
border: 1px solid #eee;
border-top: none;
color: #eee;
font-size: 10px;
text-align: center;
margin: 1px;
will-change: contents,width;
}
.ol-overlay-container {
will-change: left,right,top,bottom;
}
.ol-unsupported {
display: none;
}
.ol-unselectable, .ol-viewport {
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.ol-selectable {
-webkit-touch-callout: default;
-webkit-user-select: auto;
-moz-user-select: auto;
-ms-user-select: auto;
user-select: auto;
}
.ol-grabbing {
cursor: -webkit-grabbing;
cursor: -moz-grabbing;
cursor: grabbing;
}
.ol-grab {
cursor: move;
cursor: -webkit-grab;
cursor: -moz-grab;
cursor: grab;
}
.ol-control {
position: absolute;
background-color: rgba(255,255,255,.4);
border-radius: 4px;
padding: 2px;
}
.ol-control:hover {
background-color: rgba(255,255,255,.6);
}
.ol-zoom {
top: .5em;
right: .5em;
}
.ol-rotate {
top: .5em;
right: .5em;
transition: opacity .25s linear,visibility 0s linear;
}
.ol-rotate.ol-hidden {
opacity: 0;
visibility: hidden;
transition: opacity .25s linear,visibility 0s linear .25s;
}
.ol-zoom-extent {
top: 4.643em;
left: .5em;
}
.ol-full-screen {
right: .5em;
top: .5em;
}
@media print {
.ol-control {
display: none;
}
}
.ol-control button {
display: block;
margin: 1px;
padding: 0;
color: #fff;
font-size: 1.14em;
font-weight: 700;
text-decoration: none;
text-align: center;
height: 1.375em;
width: 1.375em;
line-height: .4em;
background-color: rgba(0,60,136,.5);
border: none;
border-radius: 2px;
}
.ol-control button::-moz-focus-inner {
border: none;
padding: 0;
}
.ol-zoom-extent button {
line-height: 1.4em;
}
.ol-compass {
display: block;
font-weight: 400;
font-size: 1.2em;
will-change: transform;
}
.ol-touch .ol-control button {
font-size: 1.5em;
}
.ol-touch .ol-zoom-extent {
top: 5.5em;
}
.ol-control button:focus, .ol-control button:hover {
text-decoration: none;
background-color: rgba(0,60,136,.7);
}
.ol-zoom .ol-zoom-in {
border-radius: 2px 2px 0 0;
}
.ol-zoom .ol-zoom-out {
border-radius: 0 0 2px 2px;
}
.ol-attribution {
text-align: right;
bottom: .5em;
right: .5em;
max-width: calc(100% - 1.3em);
}
.ol-attribution ul {
margin: 0;
padding: 0 .5em;
font-size: .7rem;
line-height: 1.375em;
color: #000;
text-shadow: 0 0 2px #fff;
}
.ol-attribution li {
display: inline;
list-style: none;
line-height: inherit;
}
.ol-attribution li:not(:last-child):after {
content: " ";
}
.ol-attribution img {
max-height: 2em;
max-width: inherit;
vertical-align: middle;
}
.ol-attribution button, .ol-attribution ul {
display: inline-block;
}
.ol-attribution.ol-collapsed ul {
display: none;
}
.ol-attribution.ol-logo-only ul {
display: block;
}
.ol-attribution:not(.ol-collapsed) {
background: rgba(255,255,255,.8);
}
.ol-attribution.ol-uncollapsible {
bottom: 0;
right: 0;
border-radius: 4px 0 0;
height: 1.1em;
line-height: 1em;
}
.ol-attribution.ol-logo-only {
background: 0 0;
bottom: .4em;
height: 1.1em;
line-height: 1em;
}
.ol-attribution.ol-uncollapsible img {
margin-top: -.2em;
max-height: 1.6em;
}
.ol-attribution.ol-logo-only button, .ol-attribution.ol-uncollapsible button {
display: none;
}
.ol-zoomslider {
top: 4.5em;
left: .5em;
height: 200px;
}
.ol-zoomslider button {
position: relative;
height: 10px;
}
.ol-touch .ol-zoomslider {
top: 5.5em;
}
.ol-overviewmap {
left: .5em;
bottom: .5em;
}
.ol-overviewmap.ol-uncollapsible {
bottom: 0;
left: 0;
border-radius: 0 4px 0 0;
}
.ol-overviewmap .ol-overviewmap-map, .ol-overviewmap button {
display: inline-block;
}
.ol-overviewmap .ol-overviewmap-map {
border: 1px solid #7b98bc;
height: 150px;
margin: 2px;
width: 150px;
}
.ol-overviewmap:not(.ol-collapsed) button {
bottom: 1px;
left: 2px;
position: absolute;
}
.ol-overviewmap.ol-collapsed .ol-overviewmap-map, .ol-overviewmap.ol-uncollapsible button {
display: none;
}
.ol-overviewmap:not(.ol-collapsed) {
background: rgba(255,255,255,.8);
}
.ol-overviewmap-box {
border: 2px dotted rgba(0,60,136,.7);
}
.ol-overviewmap .ol-overviewmap-box:hover {
cursor: move;
}

View File

@ -7,6 +7,7 @@
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no" />
<link type="text/css" href="styles/style.css" media="screen" rel="stylesheet" title="CSS" />
<link type="text/css" href="styles/ol.css" media="screen" rel="stylesheet" title="CSS" />
<script type="text/javascript" src="scripts/common-0.0.1.js"></script>
<script type="text/javascript" src="scripts/meshcentral.js"></script>
<script type="text/javascript" src="scripts/amt-0.2.0.js"></script>
@ -19,6 +20,7 @@
<script type="text/javascript" src="scripts/agent-redir-ws-0.1.0.js"></script>
<script type="text/javascript" src="scripts/agent-desktop-0.0.2.js"></script>
<script type="text/javascript" src="scripts/filesaver.1.1.20151003.js"></script>
<script type="text/javascript" src="scripts/ol.js"></script>
<title>MeshCentral</title>
</head>
@ -807,6 +809,7 @@
} else {
var x = '<div style=width:100%;max-height:260px;overflow-x:hidden;overflow-y:auto;line-height:160%>';
x += addHtmlValue2('Last Updated', new Date(message.updateTime).toLocaleString());
if (currentNode.publicip) { x += addHtmlValue2('Public IP address', currentNode.publicip); }
for (var i in message.netif) {
var net = message.netif[i];
x += '<hr />'
@ -972,6 +975,8 @@
node.name = message.event.node.name;
node.host = message.event.node.host;
node.desc = message.event.node.desc;
node.publicip = message.event.node.publicip;
node.iploc = message.event.node.iploc;
if (message.event.node.agent != undefined) {
if (node.agent == undefined) node.agent = {};
if (message.event.node.agent.ver != undefined) { node.agent.ver = message.event.node.agent.ver; }
@ -1702,7 +1707,8 @@
x = '<div style=float:right;font-size:x-small>';
if ((meshrights & 4) != 0) x += '<a style=cursor:pointer onclick=p10showDeleteNodeDialog("' + node._id + '")>Delete Device</a>';
x += '</div><div style=font-size:x-small>';
if (mesh.mtype == 2) x += '<a style=cursor:pointer onclick=p10showNodeNetInfoDialog("' + node._id + '")>Interfaces</a>';
if (mesh.mtype == 2) x += '<a style=cursor:pointer onclick=p10showNodeNetInfoDialog("' + node._id + '")>Interfaces</a>&nbsp;';
if (node.iploc) x += '<a style=cursor:pointer onclick=p10showNodeLocationDialog("' + node._id + '")>Location</a>&nbsp;';
x += '</div><br>'
QH('p10html3', x);
@ -1903,6 +1909,43 @@
meshserver.Send({ action: 'removedevices', nodeids: [ nodeid ] });
}
// Show current location
var d2map = null;
function p10showNodeLocationDialog() {
if (xxdialogMode) return;
var loc = currentNode.iploc.split(',');
var lat = parseFloat(loc[0]);
var lng = parseFloat(loc[1]);
//var x = '<div><a href="https://www.google.com/maps/preview/@' + lat + ',' + lng + ',12z" target=_blank>Open in Google maps</a></div>';
var x = '<div id=d2map style=width:100%;height:300px></div>';
setDialogMode(2, "Device Location", 1, null, x);
// Setup the device mark layer
var deviceMark = new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([lng, lat])) });
//deviceMark.setStyle(new ol.style.Style({ image: new ol.style.Icon(({ color: [113, 140, 0], src: 'images/dot.png' })) }));
deviceMark.setStyle(new ol.style.Style({
text: new ol.style.Text({
//font: '12px helvetica,sans-serif',
text: currentNode.name,
textAlign: 'right',
offsetX: -10,
fill: new ol.style.Fill({ color: '#000' }),
stroke: new ol.style.Stroke({ color: '#fff', width: 2 })
}),
image: new ol.style.Icon(({ color: [113, 140, 0], src: 'images/dot.png' })) }));
var vectorSource = new ol.source.Vector({ features: [deviceMark] });
var vectorLayer = new ol.layer.Vector({ source: vectorSource });
// Setup the map
d2map = new ol.Map({
target: 'd2map',
interactions: ol.interaction.defaults({dragPan:false, mouseWheelZoom:false}),
layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }), vectorLayer ],
view: new ol.View({ center: ol.proj.fromLonLat([lng, lat]), zoom: 8 })
});
}
// Show network interfaces
function p10showNodeNetInfoDialog() {
if (xxdialogMode) return;