From b5221c9f0df4efb446eed4e9cced2dc77b170937 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 31 Jan 2019 15:00:51 -0800 Subject: [PATCH] Added mesh agent IP address geo-location. --- meshagent.js | 4 ++-- meshuser.js | 2 +- package.json | 2 +- public/images/iplocation.png | Bin 0 -> 754 bytes views/default-min.handlebars | 2 +- views/default.handlebars | 17 +++++++++++++++-- 6 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 public/images/iplocation.png diff --git a/meshagent.js b/meshagent.js index 45565a8c..c571f71d 100644 --- a/meshagent.js +++ b/meshagent.js @@ -87,7 +87,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { } } else { // Update the last connect time - obj.db.Set({ _id: 'lc' + obj.dbNodeKey, type: 'lastconnect', domain: domain.id, time: obj.connectTime }); + if (obj.authenticated == 2) { obj.db.Set({ _id: 'lc' + obj.dbNodeKey, type: 'lastconnect', domain: domain.id, time: obj.connectTime, addr: obj.remoteaddrport }); } } delete obj.nodeid; }; @@ -377,7 +377,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // Mark when we connected to this agent obj.connectTime = Date.now(); - obj.db.Set({ _id: 'lc' + obj.dbNodeKey, type: 'lastconnect', domain: domain.id, time: obj.connectTime }); + obj.db.Set({ _id: 'lc' + obj.dbNodeKey, type: 'lastconnect', domain: domain.id, time: obj.connectTime, addr: obj.remoteaddrport }); // See if this node exists in the database if (nodes.length == 0) { diff --git a/meshuser.js b/meshuser.js index 754e0657..673fd2fa 100644 --- a/meshuser.js +++ b/meshuser.js @@ -354,7 +354,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // Query the database for the last time this node connected obj.db.Get('lc' + command.nodeid, function (err, docs) { - if ((docs != null) && (docs.length > 0)) { try { ws.send(JSON.stringify({ action: 'lastconnect', nodeid: command.nodeid, time: docs[0].time })); } catch (ex) { } } + if ((docs != null) && (docs.length > 0)) { try { ws.send(JSON.stringify({ action: 'lastconnect', nodeid: command.nodeid, time: docs[0].time, addr: docs[0].addr })); } catch (ex) { } } }); break; } diff --git a/package.json b/package.json index 59ce817c..75d4fedf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.2.7-f", + "version": "0.2.7-g", "keywords": [ "Remote Management", "Intel AMT", diff --git a/public/images/iplocation.png b/public/images/iplocation.png new file mode 100644 index 0000000000000000000000000000000000000000..dc199e72dcc2cb863c278c981bda5768fda58dd6 GIT binary patch literal 754 zcmVPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0*6UNK~y+TV=xpI zmg3@MWFQPgxj2A|84~IXEmRb>gaidS*q}0~0B9B;8>@z(fSH_hY*j8p)!r4ght`Cq z$C%1W>5B*{^6^M=bBS2xsji$oqa9gw=9CsoH6@^wiKMu-f*g>+@buB6-+%u6 z`2PLO(W8;hj>eMWKt)x1mIG1xga%_tu~;|P^CwRH{PE-OzkiSK-)DIJ`Td3stKa_o z0^~n?{K!~b6k;0$0WE+1;ssFZ{M8G`&m8~!`#Zzpg>y|L#A*t1zyJC5|Nnn?Jsr3n zAj8+x7$^voN)8IJRZ-l$bpyk#hj)up6Sr;K^ylB-FP}b{N=YR9`9L%z`FdN(N&{W{ z``_P;%QTXf;Nis(XP%wn}H5yNDB-A zaxz1LJ1Z-0U%U3_{@K4T?*NU+3JV2l09t(M%<1;>veW=Spt95ee}*?NU;cgb@Xv#D zzt3&_z9{!|iOR1N%O|xoPwQw0YWVuR>f4K^U!V8<`EmX4uV=tG0BQKrZ1c6<@!Q?g zzpfwpQfK^aQt+>@AAWv*_y5nYug}Xr-m!t8&krLJ8h-7cmDxAHY2o@G>l!{6D}AZf k|6HN<@5?)M4UZlH0L)H!pl7+(Q2+n{07*qoM6N<$f<7c}0RR91 literal 0 HcmV?d00001 diff --git a/views/default-min.handlebars b/views/default-min.handlebars index 581046a1..5b837a6d 100644 --- a/views/default-min.handlebars +++ b/views/default-min.handlebars @@ -1 +1 @@ - MeshCentral
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file + MeshCentral
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file diff --git a/views/default.handlebars b/views/default.handlebars index 0e912280..9e6f033d 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1235,6 +1235,7 @@ var node = getNodeFromId(message.nodeid); if (node != null) { node.lastconnect = message.time; + node.lastaddr = message.addr; if ((currentNode._id == node._id) && (Q('MainComputerState').innerHTML == '')) { QH('MainComputerState', 'Last seen:
' + new Date(node.lastconnect).toLocaleDateString() + ', ' + new Date(node.lastconnect).toLocaleTimeString() + '
'); } @@ -1275,8 +1276,19 @@ QH('d2netinfo', 'No network interface information available for this device.'); } else { var x = '
'; - x += addHtmlValue2('Last Updated', new Date(message.updateTime).toLocaleString()); - if (currentNode.publicip) { x += addHtmlValue2('Public IP address', currentNode.publicip); } + if (currentNode.publicip) { + x += addHtmlValue2('Public IP address', currentNode.publicip); + } else { + if (currentNode.lastconnect) { x += addHtmlValue2('Last agent connection', new Date(currentNode.lastconnect).toLocaleString()); } + if (currentNode.lastaddr) { + if (isPrivateIP(currentNode.lastaddr)) { + x += addHtmlValue2('Last agent address:port', currentNode.lastaddr); + } else { + x += addHtmlValue2('Last agent address:port', '' + currentNode.lastaddr + ''); + } + } + } + x += addHtmlValue2('Last interfaces update', new Date(message.updateTime).toLocaleString()); for (var i in message.netif) { var net = message.netif[i]; x += '
' @@ -6683,6 +6695,7 @@ function parseUriArgs() { var name, r = {}, parsedUri = window.document.location.href.split(/[\?&|\=]/); parsedUri.splice(0, 1); for (x in parsedUri) { switch (x % 2) { case 0: { name = decodeURIComponent(parsedUri[x]); break; } case 1: { r[name] = decodeURIComponent(parsedUri[x]); var x = parseInt(r[name]); if (x == r[name]) { r[name] = x; } break; } default: { break; } } } return r; } function focusTextBox(x) { setTimeout(function(){ Q(x).selectionStart = Q(x).selectionEnd = 65535; Q(x).focus(); }, 0); } function validateEmail(v) { var emailReg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return emailReg.test(v); } // New version + function isPrivateIP(a) { return (a.startsWith('10.') || a.startsWith('172.16.') || a.startsWith('192.168.')); }