Fixed meshcore agent size, user group domains, notification closes across tabs.

Ylian Saint-Hilaire committed Jan 7, 2020 at 11:08 UTC 238483c6455e6efa4d10a25810b84677342308fe
5 files changed +42 -30
agents/meshcore.js
+4 -8
@@ -42,24 +42,20 @@ function createMeshCore(agent) {
42 if (process.platform == 'win32' && require('user-sessions').isRoot())
43 {
44 // Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
45 - var actualSize = require('fs').statSync(process.execPath).size / 1024;
45 + var actualSize = Math.floor(require('fs').statSync(process.execPath).size / 1024);
46 var writtenSize = 0;
47 try
48 {
49 writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize');
50 }
51 - catch(x)
52 - {
53 - }
51 + catch(x) { }
52 if (writtenSize != actualSize)
53 {
54 try
55 {
56 require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize);
57 }
60 - catch (x2)
61 - {
62 - }
58 + catch (x2) { }
59 }
60 }
61
@@ -1953,7 +1949,7 @@ function createMeshCore(agent) {
1949 break;
1950 }
1951 case 'agentsize':
1956 - var actualSize = require('fs').statSync(process.execPath).size / 1024;
1952 + var actualSize = Math.floor(require('fs').statSync(process.execPath).size / 1024);
1953 if (process.platform == 'win32')
1954 {
1955 // Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
meshuser.js
+28 -20
@@ -376,7 +376,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
376 const lastLoginTime = parent.users[user._id].pastlogin;
377 if (lastLoginTime != null) {
378 db.GetFailedLoginCount(user.name, user.domain, new Date(lastLoginTime * 1000), function (count) {
379 - if (count > 0) { try { ws.send(JSON.stringify({ action: 'msg', type: 'notify', title: "Security Warning", tag: 'ServerNotify', value: "There has been " + count + " failed login attempts on this account since the last login." })); } catch (ex) { } delete user.pastlogin; }
379 + if (count > 0) { try { ws.send(JSON.stringify({ action: 'msg', type: 'notify', title: "Security Warning", tag: 'ServerNotify', id: Math.random(), value: "There has been " + count + " failed login attempts on this account since the last login." })); } catch (ex) { } delete user.pastlogin; }
380 });
381 }
382
@@ -394,6 +394,20 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
394
395 switch (command.action) {
396 case 'ping': { try { ws.send(JSON.stringify({ action: 'pong' })); } catch (ex) { } break; }
397 + case 'intersession':
398 + {
399 + // Sends data between sessions of the same user
400 + var sessions = parent.wssessions[obj.user._id];
401 + if (sessions == null) break;
402 +
403 + // Create the notification message and send on all sessions except our own (no echo back).
404 + var notification = JSON.stringify(command);
405 + for (var i in sessions) { if (sessions[i] != obj.ws) { try { sessions[i].send(notification); } catch (ex) { } } }
406 +
407 + // TODO: Send the message of user sessions connected to other servers.
408 +
409 + break;
410 + }
411 case 'authcookie':
412 {
413 // Renew the authentication cookie
@@ -1054,7 +1068,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1068 db.GetUserWithVerifiedEmail(domain.id, command.email, function (err, docs) {
1069 if ((docs != null) && (docs.length > 0)) {
1070 // Notify the duplicate email error
1057 - try { ws.send(JSON.stringify({ action: 'msg', type: 'notify', title: 'Account Settings', tag: 'ServerNotify', value: 'Failed to change email address, another account already using: <b>' + EscapeHtml(command.email) + '</b>.' })); } catch (ex) { }
1071 + try { ws.send(JSON.stringify({ action: 'msg', type: 'notify', title: 'Account Settings', id: Math.random(), tag: 'ServerNotify', value: 'Failed to change email address, another account already using: <b>' + EscapeHtml(command.email) + '</b>.' })); } catch (ex) { }
1072 } else {
1073 // Update the user's email
1074 var oldemail = user.email;
@@ -1218,7 +1232,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1232 }
1233
1234 // Create the notification message
1221 - var notification = { action: 'msg', type: 'notify', domain: domain.id, value: command.msg, title: user.name, icon: 0, tag: 'broadcast' };
1235 + var notification = { action: 'msg', type: 'notify', domain: domain.id, value: command.msg, title: user.name, icon: 0, tag: 'broadcast', id: Math.random() };
1236
1237 // Send the notification on all user sessions for this server
1238 for (var i in parent.wssessions2) {
@@ -1268,7 +1282,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1282 // Account count exceed, do notification
1283
1284 // Create the notification message
1271 - var notification = { action: "msg", type: "notify", value: "Account limit reached.", title: "Server Limit", userid: user._id, username: user.name, domain: domain.id };
1285 + var notification = { action: 'msg', type: 'notify', id: Math.random(), value: "Account limit reached.", title: "Server Limit", userid: user._id, username: user.name, domain: domain.id };
1286
1287 // Get the list of sessions for this user
1288 var sessions = parent.wssessions[user._id];
@@ -1356,7 +1370,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1370 try { ws.send(JSON.stringify({ action: 'adduser', responseid: command.responseid, result: 'maxUsersExceed' })); } catch (ex) { }
1371 } else {
1372 // Create the notification message
1359 - var notification = { action: "msg", type: "notify", value: "Account limit reached.", title: "Server Limit", userid: user._id, username: user.name, domain: domain.id };
1373 + var notification = { action: 'msg', type: 'notify', id: Math.random(), value: "Account limit reached.", title: "Server Limit", userid: user._id, username: user.name, domain: domain.id };
1374
1375 // Get the list of sessions for this user
1376 var sessions = parent.wssessions[user._id];
@@ -1486,22 +1500,16 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1500 {
1501 // TODO: Return only groups in the same administrative domain?
1502 if ((user.siteadmin & SITERIGHT_USERGROUPS) == 0) {
1489 - // We are not user group administrator, return a list with limited data.
1503 + // We are not user group administrator, return a list with limited data for our domain.
1504 var groups = {}, groupCount = 0;
1491 - for (var i in parent.userGroups) { groupCount++; groups[i] = { name: parent.userGroups[i].name }; }
1505 + for (var i in parent.userGroups) { if (parent.userGroups[i].domain == domain.id) { groupCount++; groups[i] = { name: parent.userGroups[i].name }; } }
1506 try { ws.send(JSON.stringify({ action: 'usergroups', ugroups: groupCount?groups:null, tag: command.tag })); } catch (ex) { }
1507 } else {
1494 - // We are user group administrator, return a full user group list.
1495 - try { ws.send(JSON.stringify({ action: 'usergroups', ugroups: parent.userGroups, tag: command.tag })); } catch (ex) { }
1508 + // We are user group administrator, return a full user group list for our domain.
1509 + var groups = {}, groupCount = 0;
1510 + for (var i in parent.userGroups) { if (parent.userGroups[i].domain == domain.id) { groupCount++; groups[i] = parent.userGroups[i]; } }
1511 + try { ws.send(JSON.stringify({ action: 'usergroups', ugroups: groupCount ? groups : null, tag: command.tag })); } catch (ex) { }
1512 }
1497 -
1498 - /*
1499 - // Request a list of all user groups this user as rights to
1500 - if ((user.siteadmin & SITERIGHT_USERGROUPS) == 0) { return; }
1501 - db.GetAllTypeNoTypeField('ugrp', domain.id, function (err, docs) {
1502 - try { ws.send(JSON.stringify({ action: 'usergroups', ugroups: common.unEscapeAllLinksFieldName(docs), tag: command.tag })); } catch (ex) { }
1503 - });
1504 - */
1513 break;
1514 }
1515 case 'createusergroup':
@@ -1944,7 +1952,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1952 if ((user.groups != null) && (user.groups.length > 0) && ((chguser.groups == null) || (findOne(chguser.groups, user.groups) == false))) break;
1953
1954 // Create the notification message
1947 - var notification = { action: "msg", type: "notify", value: command.msg, title: user.name, icon: 8, userid: user._id, username: user.name };
1955 + var notification = { action: 'msg', type: 'notify', id: Math.random(), value: command.msg, title: user.name, icon: 8, userid: user._id, username: user.name };
1956
1957 // Get the list of sessions for this user
1958 var sessions = parent.wssessions[command.userid];
@@ -1969,7 +1977,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1977
1978 // Create the notification message
1979 var notification = {
1972 - "action": "msg", "type": "notify", "value": "Chat Request, Click here to accept.", "title": user.name, "userid": user._id, "username": user.name, "tag": 'meshmessenger/' + encodeURIComponent(command.userid) + '/' + encodeURIComponent(user._id)
1980 + 'action': 'msg', 'type': 'notify', id: Math.random(), 'value': "Chat Request, Click here to accept.", 'title': user.name, 'userid': user._id, 'username': user.name, 'tag': 'meshmessenger/' + encodeURIComponent(command.userid) + '/' + encodeURIComponent(user._id)
1981 };
1982
1983 // Get the list of sessions for this user
@@ -3442,7 +3450,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3450 }
3451
3452 // Display a notification message for this session only.
3445 - function displayNotificationMessage(msg, title, tag) { ws.send(JSON.stringify({ "action": "msg", "type": "notify", "value": msg, "title": title, "userid": user._id, "username": user.name, "tag": tag })); }
3453 + function displayNotificationMessage(msg, title, tag) { ws.send(JSON.stringify({ 'action': 'msg', 'type': 'notify', id: Math.random(), 'value': msg, 'title': title, 'userid': user._id, 'username': user.name, 'tag': tag })); }
3454
3455 // Read the folder and all sub-folders and serialize that into json.
3456 function readFilesRec(path) {
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.4.6-x",
3 + "version": "0.4.6-z",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
views/default.handlebars
+8
@@ -1657,6 +1657,10 @@
1657 displayServerTrace();
1658 break;
1659 }
1660 + case 'intersession' : {
1661 + if (message.subaction == 'removeNotify') { notificationDelete(message.id); }
1662 + break;
1663 + }
1664 case 'traceinfo': {
1665 if (typeof message.traceSources == 'object') {
1666 if ((message.traceSources != null) && (message.traceSources.length > 0)) {
@@ -1865,6 +1869,7 @@
1869 var n = getstore('notifications', 0);
1870 if (((n & 8) == 0) && (message.amtMessage != null)) { break; } // Intel AMT desktop & terminal messages should be ignored.
1871 var n = { text: message.value, title: message.title, icon: message.icon };
1872 + if (message.id != null) { n.id = message.id; }
1873 if (message.nodeid != null) { n.nodeid = message.nodeid; }
1874 if (message.tag != null) { n.tag = message.tag; }
1875 if (message.username != null) { n.username = message.username; }
@@ -1900,6 +1905,7 @@
1905 } else {
1906 if (message.type == 'notify') { // This is a notification message.
1907 var n = { text: message.value, title: message.title, icon: message.icon };
1908 + if (message.id != null) { n.id = message.id; }
1909 if (message.tag != null) { n.tag = message.tag; }
1910 if (message.username != null) { n.username = message.username; }
1911 addNotification(n);
@@ -2538,6 +2544,7 @@
2544 }
2545 case 'notify': {
2546 var n = { text: message.event.value, title: message.event.title, icon: message.event.icon };
2547 + if (message.id != null) { n.id = message.id; }
2548 if (message.event.tag != null) { n.tag = message.event.tag; }
2549 addNotification(n);
2550 break;
@@ -9881,6 +9888,7 @@
9888 if (e != null) {
9889 for (var i in notifications) { if (notifications[i].id == id) { j = i; } }
9890 if (j != -1) {
9891 + meshserver.send({ action: 'intersession', subaction: 'removeNotify', id: id }); // Remove the notification in other sessions of the same user.
9892 if (notifications[j].notification) { notifications[j].notification.close(); delete notifications[j].notification; }
9893 notifications.splice(j, 1);
9894 e.parentNode.removeChild(e);
webserver.js
+1 -1
@@ -1154,7 +1154,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
1154 render(req, res, getRenderPage('message', req), getRenderArgs({ title3: 'Account Verification', message: 'Verified email <b>' + EscapeHtml(user.email) + '</b> for user account <b>' + EscapeHtml(user.name) + '</b>. <a href="' + domain.url + '">Go to login page</a>.' }, domain));
1155
1156 // Send a notification
1157 - obj.parent.DispatchEvent([user._id], obj, { action: 'notify', value: 'Email verified:<br /><b>' + EscapeHtml(user.email) + '</b>.', nolog: 1 });
1157 + obj.parent.DispatchEvent([user._id], obj, { action: 'notify', value: 'Email verified:<br /><b>' + EscapeHtml(user.email) + '</b>.', nolog: 1, id: Math.random() });
1158 }
1159 });
1160 }