Small MQTT improvement.
Ylian Saint-Hilaire committed
Oct 11, 2019 at 13:45 UTC
343155b1f4f6722e515d234c36c78d17ca5bc47f
4 files changed
+103
-9
agents/meshcore.js
+2
@@ -1785,6 +1785,7 @@ function createMeshCore(agent) {
1785
*/
1786
case 'av':
1787
if (process.platform == 'win32') {
1788
+ // Windows Command: "wmic /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct get /FORMAT:CSV"
1789
response = JSON.stringify(require('win-info').av(), null, 1);
1790
} else {
1791
response = 'Not supported on the platform';
@@ -2513,6 +2514,7 @@ function createMeshCore(agent) {
2514
2515
if ((flags & 4) && (process.platform == 'win32')) {
2516
// Update anti-virus information
2517
+ // Windows Command: "wmic /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct get /FORMAT:CSV"
2518
var av, pr;
2519
try { av = require('win-info').av(); } catch (ex) { av = null; } // Antivirus
2520
//if (process.platform == 'win32') { try { pr = require('win-info').pendingReboot(); } catch (ex) { pr = null; } } // Pending reboot
agents/meshcore.min.js
+96
-7
@@ -1170,7 +1170,8 @@ function createMeshCore(agent) {
1170
this.httprequest.desktop.kvm.parent = this.httprequest.desktop;
1171
this.desktop = this.httprequest.desktop;
1172
1173
- this.end = function () {
1173
+ this.end = function ()
1174
+ {
1175
--this.desktop.kvm.connectionCount;
1176
1177
// Unpipe the web socket
@@ -1183,14 +1184,55 @@ function createMeshCore(agent) {
1184
this.httprequest.desktop.kvm.unpipe(this.rtcchannel);
1185
}
1186
1186
- if (this.desktop.kvm.connectionCount == 0) {
1187
+ if (this.desktop.kvm.connectionCount == 0)
1188
+ {
1189
// Display a toast message. This may not be supported on all platforms.
1190
// try { require('toaster').Toast('MeshCentral', 'Remote Desktop Control Ended.'); } catch (ex) { }
1191
1192
this.httprequest.desktop.kvm.end();
1193
+ if(this.httprequest.desktop.kvm.connectionBar)
1194
+ {
1195
+ this.httprequest.desktop.kvm.connectionBar.removeAllListeners('close');
1196
+ this.httprequest.desktop.kvm.connectionBar.close();
1197
+ this.httprequest.desktop.kvm.connectionBar = null;
1198
+ }
1199
+ }
1200
+ else
1201
+ {
1202
+ for(var i in this.httprequest.desktop.kvm.users)
1203
+ {
1204
+ if(this.httprequest.desktop.kvm.users[i] == this.httprequest.username)
1205
+ {
1206
+ this.httprequest.desktop.kvm.users.splice(i, 1);
1207
+ this.httprequest.desktop.kvm.connectionBar.removeAllListeners('close');
1208
+ this.httprequest.desktop.kvm.connectionBar.close();
1209
+
1210
+ this.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')('Sharing desktop with: ' + this.httprequest.desktop.kvm.users.sort().join(', '));
1211
+ this.httprequest.desktop.kvm.connectionBar.httprequest = this.httprequest;
1212
+ this.httprequest.desktop.kvm.connectionBar.on('close', function ()
1213
+ {
1214
+ MeshServerLog('Remote Desktop Connection forcefully closed by local user (' + this.httprequest.remoteaddr + ')', this.httprequest);
1215
+ for (var i in this.httprequest.desktop.kvm._pipedStreams)
1216
+ {
1217
+ this.httprequest.desktop.kvm._pipedStreams[i].end();
1218
+ }
1219
+ this.httprequest.desktop.kvm.end();
1220
+ });
1221
+ break;
1222
+ }
1223
+ }
1224
}
1225
};
1193
- if (this.httprequest.desktop.kvm.hasOwnProperty("connectionCount")) { this.httprequest.desktop.kvm.connectionCount++; } else { this.httprequest.desktop.kvm.connectionCount = 1; }
1226
+ if (this.httprequest.desktop.kvm.hasOwnProperty("connectionCount"))
1227
+ {
1228
+ this.httprequest.desktop.kvm.connectionCount++;
1229
+ this.httprequest.desktop.kvm.users.push(this.httprequest.username);
1230
+ }
1231
+ else
1232
+ {
1233
+ this.httprequest.desktop.kvm.connectionCount = 1;
1234
+ this.httprequest.desktop.kvm.users = [this.httprequest.username];
1235
+ }
1236
1237
if ((this.httprequest.rights == 0xFFFFFFFF) || (((this.httprequest.rights & MESHRIGHT_REMOTECONTROL) != 0) && ((this.httprequest.rights & MESHRIGHT_REMOTEVIEW) == 0))) {
1238
// If we have remote control rights, pipe the KVM input
@@ -1215,10 +1257,32 @@ function createMeshCore(agent) {
1257
// Success
1258
MeshServerLog('Starting remote desktop after local user accepted (' + this.ws.httprequest.remoteaddr + ')', this.ws.httprequest);
1259
this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null }));
1218
- if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 1)) {
1260
+ if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 1))
1261
+ {
1262
// User Notifications is required
1263
try { require('toaster').Toast('MeshCentral', this.ws.httprequest.username + ' started a remote desktop session.'); } catch (ex) { }
1264
}
1265
+ if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 0x40))
1266
+ {
1267
+ // Connection Bar is required
1268
+ MeshServerLog('Remote Desktop Connection Bar Activated/Updated (' + this.ws.httprequest.remoteaddr + ')', this.ws.httprequest);
1269
+ if (this.ws.httprequest.desktop.kvm.connectionBar)
1270
+ {
1271
+ this.ws.httprequest.desktop.kvm.connectionBar.removeAllListeners('close');
1272
+ this.ws.httprequest.desktop.kvm.connectionBar.close();
1273
+ }
1274
+ this.ws.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')('Sharing desktop with: ' + this.ws.httprequest.desktop.kvm.users.sort().join(', '));
1275
+ this.ws.httprequest.desktop.kvm.connectionBar.httprequest = this.ws.httprequest;
1276
+ this.ws.httprequest.desktop.kvm.connectionBar.on('close', function ()
1277
+ {
1278
+ MeshServerLog('Remote Desktop Connection forcefully closed by local user (' + this.httprequest.remoteaddr + ')', this.httprequest);
1279
+ for (var i in this.httprequest.desktop.kvm._pipedStreams)
1280
+ {
1281
+ this.httprequest.desktop.kvm._pipedStreams[i].end();
1282
+ }
1283
+ this.httprequest.desktop.kvm.end();
1284
+ });
1285
+ }
1286
this.ws.httprequest.desktop.kvm.pipe(this.ws, { dataTypeSkip: 1 });
1287
this.ws.resume();
1288
},
@@ -1230,13 +1294,36 @@ function createMeshCore(agent) {
1294
}
1295
else {
1296
// User Consent Prompt is not required
1233
- if (this.httprequest.consent && (this.httprequest.consent & 1)) {
1297
+ if (this.httprequest.consent && (this.httprequest.consent & 1))
1298
+ {
1299
// User Notifications is required
1300
MeshServerLog('Started remote desktop with toast notification (' + this.httprequest.remoteaddr + ')', this.httprequest);
1301
try { require('toaster').Toast('MeshCentral', this.httprequest.username + ' started a remote desktop session.'); } catch (ex) { }
1237
- } else {
1302
+ } else
1303
+ {
1304
MeshServerLog('Started remote desktop without notification (' + this.httprequest.remoteaddr + ')', this.httprequest);
1305
}
1306
+ if (this.httprequest.consent && (this.httprequest.consent & 0x40))
1307
+ {
1308
+ // Connection Bar is required
1309
+ MeshServerLog('Remote Desktop Connection Bar Activated/Updated (' + this.httprequest.remoteaddr + ')', this.httprequest);
1310
+ if(this.httprequest.desktop.kvm.connectionBar)
1311
+ {
1312
+ this.httprequest.desktop.kvm.connectionBar.removeAllListeners('close');
1313
+ this.httprequest.desktop.kvm.connectionBar.close();
1314
+ }
1315
+ this.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')('Sharing desktop with: ' + this.httprequest.desktop.kvm.users.sort().join(', '));
1316
+ this.httprequest.desktop.kvm.connectionBar.httprequest = this.httprequest;
1317
+ this.httprequest.desktop.kvm.connectionBar.on('close', function ()
1318
+ {
1319
+ MeshServerLog('Remote Desktop Connection forcefully closed by local user (' + this.httprequest.remoteaddr + ')', this.httprequest);
1320
+ for (var i in this.httprequest.desktop.kvm._pipedStreams)
1321
+ {
1322
+ this.httprequest.desktop.kvm._pipedStreams[i].end();
1323
+ }
1324
+ this.httprequest.desktop.kvm.end();
1325
+ });
1326
+ }
1327
this.httprequest.desktop.kvm.pipe(this, { dataTypeSkip: 1 });
1328
}
1329
@@ -1698,6 +1785,7 @@ function createMeshCore(agent) {
1785
*/
1786
case 'av':
1787
if (process.platform == 'win32') {
1788
+ // Windows Command: "wmic /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct get /FORMAT:CSV"
1789
response = JSON.stringify(require('win-info').av(), null, 1);
1790
} else {
1791
response = 'Not supported on the platform';
@@ -2426,8 +2514,9 @@ function createMeshCore(agent) {
2514
2515
if ((flags & 4) && (process.platform == 'win32')) {
2516
// Update anti-virus information
2517
+ // Windows Command: "wmic /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct get /FORMAT:CSV"
2518
var av, pr;
2430
- try { av = require('win-info').av(); } catch (ex) { av = []; } // Antivirus
2519
+ try { av = require('win-info').av(); } catch (ex) { av = null; } // Antivirus
2520
//if (process.platform == 'win32') { try { pr = require('win-info').pendingReboot(); } catch (ex) { pr = null; } } // Pending reboot
2521
if ((meshCoreObj.av == null) || (JSON.stringify(meshCoreObj.av) != JSON.stringify(av))) { meshCoreObj.av = av; mesh.SendCommand(meshCoreObj); }
2522
}
mqttbroker.js
+4
-1
@@ -125,7 +125,10 @@ module.exports.CreateMQTTBroker = function (parent, db, args) {
125
var clients = obj.connections[nodeid];
126
if (clients == null) return;
127
if (typeof message == 'string') { message = new Buffer(message); }
128
- for (var i in clients) { clients[i].publish({ cmd: 'publish', qos: 0, topic: topic, payload: message, retain: false }); }
128
+ for (var i in clients) {
129
+ // if (clients[i].subscriptions[topic] != null) { } // Add this if we only want to send subscribed topics.
130
+ clients[i].publish({ cmd: 'publish', qos: 0, topic: topic, payload: message, retain: false });
131
+ }
132
}
133
134
// Handle messages coming from clients
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.4.2-e",
3
+ "version": "0.4.2-f",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",