Updated mesh agents.
Ylian Saint-Hilaire committed
Jan 22, 2019 at 17:47 UTC
b5fb7ad3de77c18417980486c56ef68236b8e707
22 files changed
+194
-4
agents/MeshCmd-signed.exe
Binary files a/agents/MeshCmd-signed.exe and b/agents/MeshCmd-signed.exe differ
agents/MeshCmd64-signed.exe
Binary files a/agents/MeshCmd64-signed.exe and b/agents/MeshCmd64-signed.exe differ
agents/MeshService-signed.exe
Binary files a/agents/MeshService-signed.exe and b/agents/MeshService-signed.exe differ
agents/MeshService.exe
Binary files a/agents/MeshService.exe and b/agents/MeshService.exe differ
agents/MeshService64-signed.exe
Binary files a/agents/MeshService64-signed.exe and b/agents/MeshService64-signed.exe differ
agents/MeshService64.exe
Binary files a/agents/MeshService64.exe and b/agents/MeshService64.exe differ
agents/meshagent_arm
Binary files a/agents/meshagent_arm and b/agents/meshagent_arm differ
agents/meshagent_arm-linaro
Binary files a/agents/meshagent_arm-linaro and b/agents/meshagent_arm-linaro differ
agents/meshagent_armhf
Binary files a/agents/meshagent_armhf and b/agents/meshagent_armhf differ
agents/meshagent_osx-x86-64
Binary files a/agents/meshagent_osx-x86-64 and b/agents/meshagent_osx-x86-64 differ
agents/meshagent_pogo
Binary files a/agents/meshagent_pogo and b/agents/meshagent_pogo differ
agents/meshagent_poky
Binary files a/agents/meshagent_poky and b/agents/meshagent_poky differ
agents/meshagent_poky64
Binary files a/agents/meshagent_poky64 and b/agents/meshagent_poky64 differ
agents/meshagent_x86
Binary files a/agents/meshagent_x86 and b/agents/meshagent_x86 differ
agents/meshagent_x86-64
Binary files a/agents/meshagent_x86-64 and b/agents/meshagent_x86-64 differ
agents/meshagent_x86-64_nokvm
Binary files a/agents/meshagent_x86-64_nokvm and b/agents/meshagent_x86-64_nokvm differ
agents/meshagent_x86_nokvm
Binary files a/agents/meshagent_x86_nokvm and b/agents/meshagent_x86_nokvm differ
agents/recoverycore.js
+184
-1
@@ -1,14 +1,56 @@
1
2
var http = require('http');
3
var childProcess = require('child_process');
4
-var meshCoreObj = { "action": "coreinfo", "value": "MeshCore Recovery", "caps": 10 }; // Capability bitmask: 1 = Desktop, 2 = Terminal, 4 = Files, 8 = Console, 16 = JavaScript
4
+var meshCoreObj = { "action": "coreinfo", "value": "MeshCore Recovery", "caps": 14 }; // Capability bitmask: 1 = Desktop, 2 = Terminal, 4 = Files, 8 = Console, 16 = JavaScript
5
var nextTunnelIndex = 1;
6
var tunnels = {};
7
+var fs = require('fs');
8
+
9
+//attachDebugger({ webport: 9994, wait: 1 }).then(function (p) { console.log('Debug on port: ' + p); });
10
11
function sendConsoleText(msg)
12
{
13
require('MeshAgent').SendCommand({ "action": "msg", "type": "console", "value": msg });
14
}
15
+// Return p number of spaces
16
+function addPad(p, ret) { var r = ''; for (var i = 0; i < p; i++) { r += ret; } return r; }
17
+
18
+var path =
19
+ {
20
+ join: function ()
21
+ {
22
+ var x = [];
23
+ for (var i in arguments)
24
+ {
25
+ var w = arguments[i];
26
+ if (w != null)
27
+ {
28
+ while (w.endsWith('/') || w.endsWith('\\')) { w = w.substring(0, w.length - 1); }
29
+ if (i != 0)
30
+ {
31
+ while (w.startsWith('/') || w.startsWith('\\')) { w = w.substring(1); }
32
+ }
33
+ x.push(w);
34
+ }
35
+ }
36
+ if (x.length == 0) return '/';
37
+ return x.join('/');
38
+ }
39
+ };
40
+// Convert an object to string with all functions
41
+function objToString(x, p, pad, ret) {
42
+ if (ret == undefined) ret = '';
43
+ if (p == undefined) p = 0;
44
+ if (x == null) { return '[null]'; }
45
+ if (p > 8) { return '[...]'; }
46
+ if (x == undefined) { return '[undefined]'; }
47
+ if (typeof x == 'string') { if (p == 0) return x; return '"' + x + '"'; }
48
+ if (typeof x == 'buffer') { return '[buffer]'; }
49
+ if (typeof x != 'object') { return x; }
50
+ var r = '{' + (ret ? '\r\n' : ' ');
51
+ for (var i in x) { if (i != '_ObjectID') { r += (addPad(p + 2, pad) + i + ': ' + objToString(x[i], p + 2, pad, ret) + (ret ? '\r\n' : ' ')); } }
52
+ return r + addPad(p, pad) + '}';
53
+}
54
55
// Split a string taking into account the quoats. Used for command line parsing
56
function splitArgs(str)
@@ -122,6 +164,12 @@ require('MeshAgent').AddCommandHandler(function (data)
164
s.on('end', function ()
165
{
166
if (tunnels[this.httprequest.index] == null) return; // Stop duplicate calls.
167
+
168
+ // If there is a upload or download active on this connection, close the file
169
+ if (this.httprequest.uploadFile) { fs.closeSync(this.httprequest.uploadFile); this.httprequest.uploadFile = undefined; }
170
+ if (this.httprequest.downloadFile) { fs.closeSync(this.httprequest.downloadFile); this.httprequest.downloadFile = undefined; }
171
+
172
+
173
//sendConsoleText("Tunnel #" + this.httprequest.index + " closed.", this.httprequest.sessionid);
174
delete tunnels[this.httprequest.index];
175
@@ -130,6 +178,14 @@ require('MeshAgent').AddCommandHandler(function (data)
178
});
179
s.on('data', function (data)
180
{
181
+ // If this is upload data, save it to file
182
+ if (this.httprequest.uploadFile)
183
+ {
184
+ try { fs.writeSync(this.httprequest.uploadFile, data); } catch (e) { this.write(new Buffer(JSON.stringify({ action: 'uploaderror' }))); return; } // Write to the file, if there is a problem, error out.
185
+ this.write(new Buffer(JSON.stringify({ action: 'uploadack', reqid: this.httprequest.uploadFileid }))); // Ask for more data
186
+ return;
187
+ }
188
+
189
if (this.httprequest.state == 0) {
190
// Check if this is a relay connection
191
if (data == 'c') { this.httprequest.state = 1; sendConsoleText("Tunnel #" + this.httprequest.index + " now active", this.httprequest.sessionid); }
@@ -175,6 +231,76 @@ require('MeshAgent').AddCommandHandler(function (data)
231
});
232
}
233
}
234
+ else if (this.httprequest.protocol == 5)
235
+ {
236
+ // Process files commands
237
+ var cmd = null;
238
+ try { cmd = JSON.parse(data); } catch (e) { };
239
+ if (cmd == null) { return; }
240
+ if ((cmd.ctrlChannel == '102938') || ((cmd.type == 'offer') && (cmd.sdp != null))) { return; } // If this is control data, handle it now.
241
+ if (cmd.action == undefined) { return; }
242
+ console.log('action: ', cmd.action);
243
+
244
+ //sendConsoleText('CMD: ' + JSON.stringify(cmd));
245
+
246
+ if ((cmd.path != null) && (process.platform != 'win32') && (cmd.path[0] != '/')) { cmd.path = '/' + cmd.path; } // Add '/' to paths on non-windows
247
+ //console.log(objToString(cmd, 0, ' '));
248
+ switch (cmd.action)
249
+ {
250
+ case 'ls':
251
+ // Send the folder content to the browser
252
+ var response = getDirectoryInfo(cmd.path);
253
+ if (cmd.reqid != undefined) { response.reqid = cmd.reqid; }
254
+ this.write(new Buffer(JSON.stringify(response)));
255
+ break;
256
+ case 'mkdir': {
257
+ // Create a new empty folder
258
+ fs.mkdirSync(cmd.path);
259
+ break;
260
+ }
261
+ case 'rm': {
262
+ // Delete, possibly recursive delete
263
+ for (var i in cmd.delfiles)
264
+ {
265
+ try { deleteFolderRecursive(path.join(cmd.path, cmd.delfiles[i]), cmd.rec); } catch (e) { }
266
+ }
267
+ break;
268
+ }
269
+ case 'rename': {
270
+ // Rename a file or folder
271
+ var oldfullpath = path.join(cmd.path, cmd.oldname);
272
+ var newfullpath = path.join(cmd.path, cmd.newname);
273
+ try { fs.renameSync(oldfullpath, newfullpath); } catch (e) { console.log(e); }
274
+ break;
275
+ }
276
+ case 'upload': {
277
+ // Upload a file, browser to agent
278
+ if (this.httprequest.uploadFile != undefined) { fs.closeSync(this.httprequest.uploadFile); this.httprequest.uploadFile = undefined; }
279
+ if (cmd.path == undefined) break;
280
+ var filepath = cmd.name ? path.join(cmd.path, cmd.name) : cmd.path;
281
+ try { this.httprequest.uploadFile = fs.openSync(filepath, 'wbN'); } catch (e) { this.write(new Buffer(JSON.stringify({ action: 'uploaderror', reqid: cmd.reqid }))); break; }
282
+ this.httprequest.uploadFileid = cmd.reqid;
283
+ if (this.httprequest.uploadFile) { this.write(new Buffer(JSON.stringify({ action: 'uploadstart', reqid: this.httprequest.uploadFileid }))); }
284
+ break;
285
+ }
286
+ case 'copy': {
287
+ // Copy a bunch of files from scpath to dspath
288
+ for (var i in cmd.names) {
289
+ var sc = path.join(cmd.scpath, cmd.names[i]), ds = path.join(cmd.dspath, cmd.names[i]);
290
+ if (sc != ds) { try { fs.copyFileSync(sc, ds); } catch (e) { } }
291
+ }
292
+ break;
293
+ }
294
+ case 'move': {
295
+ // Move a bunch of files from scpath to dspath
296
+ for (var i in cmd.names) {
297
+ var sc = path.join(cmd.scpath, cmd.names[i]), ds = path.join(cmd.dspath, cmd.names[i]);
298
+ if (sc != ds) { try { fs.copyFileSync(sc, ds); fs.unlinkSync(sc); } catch (e) { } }
299
+ }
300
+ break;
301
+ }
302
+ }
303
+ }
304
}
305
});
306
});
@@ -281,3 +407,60 @@ function processConsoleCommand(cmd, args, rights, sessionid)
407
} catch (e) { response = 'Command returned an exception error: ' + e; console.log(e); }
408
if (response != null) { sendConsoleText(response, sessionid); }
409
}
410
+
411
+// Get a formated response for a given directory path
412
+function getDirectoryInfo(reqpath)
413
+{
414
+ var response = { path: reqpath, dir: [] };
415
+ if (((reqpath == undefined) || (reqpath == '')) && (process.platform == 'win32')) {
416
+ // List all the drives in the root, or the root itself
417
+ var results = null;
418
+ try { results = fs.readDrivesSync(); } catch (e) { } // TODO: Anyway to get drive total size and free space? Could draw a progress bar.
419
+ if (results != null) {
420
+ for (var i = 0; i < results.length; ++i) {
421
+ var drive = { n: results[i].name, t: 1 };
422
+ if (results[i].type == 'REMOVABLE') { drive.dt = 'removable'; } // TODO: See if this is USB/CDROM or something else, we can draw icons.
423
+ response.dir.push(drive);
424
+ }
425
+ }
426
+ } else {
427
+ // List all the files and folders in this path
428
+ if (reqpath == '') { reqpath = '/'; }
429
+ var results = null, xpath = path.join(reqpath, '*');
430
+ //if (process.platform == "win32") { xpath = xpath.split('/').join('\\'); }
431
+ try { results = fs.readdirSync(xpath); } catch (e) { }
432
+ if (results != null) {
433
+ for (var i = 0; i < results.length; ++i) {
434
+ if ((results[i] != '.') && (results[i] != '..')) {
435
+ var stat = null, p = path.join(reqpath, results[i]);
436
+ //if (process.platform == "win32") { p = p.split('/').join('\\'); }
437
+ try { stat = fs.statSync(p); } catch (e) { } // TODO: Get file size/date
438
+ if ((stat != null) && (stat != undefined)) {
439
+ if (stat.isDirectory() == true) {
440
+ response.dir.push({ n: results[i], t: 2, d: stat.mtime });
441
+ } else {
442
+ response.dir.push({ n: results[i], t: 3, s: stat.size, d: stat.mtime });
443
+ }
444
+ }
445
+ }
446
+ }
447
+ }
448
+ }
449
+ return response;
450
+}
451
+// Delete a directory with a files and directories within it
452
+function deleteFolderRecursive(path, rec) {
453
+ if (fs.existsSync(path)) {
454
+ if (rec == true) {
455
+ fs.readdirSync(path.join(path, '*')).forEach(function (file, index) {
456
+ var curPath = path.join(path, file);
457
+ if (fs.statSync(curPath).isDirectory()) { // recurse
458
+ deleteFolderRecursive(curPath, true);
459
+ } else { // delete file
460
+ fs.unlinkSync(curPath);
461
+ }
462
+ });
463
+ }
464
+ fs.unlinkSync(path);
465
+ }
466
+};
meshagent.js
+7
-1
@@ -322,7 +322,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
322
ws.on('error', function (err) { console.log('AGENT WSERR: ' + err); });
323
324
// If the mesh agent web socket is closed, clean up.
325
- ws.on('close', function (req) { if (obj.nodeid != null) { obj.parent.parent.debug(1, 'Agent disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ')'); } obj.close(0); });
325
+ ws.on('close', function (req) {
326
+ if (obj.nodeid != null) {
327
+ //console.log('Agent disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ') id=' + obj.agentInfo.agentId);
328
+ obj.parent.parent.debug(1, 'Agent disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ') id=' + obj.agentInfo.agentId);
329
+ }
330
+ obj.close(0);
331
+ });
332
// obj.ws._socket._parent.on('close', function (req) { if (obj.nodeid != null) { obj.parent.parent.debug(1, 'Agent TCP disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ')'); } });
333
334
// Start authenticate the mesh agent by sending a auth nonce & server TLS cert hash.
public/scripts/agent-desktop-0.0.2.js
+1
@@ -160,6 +160,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
160
161
obj.ProcessScreenMsg = function (width, height) {
162
if (obj.debugmode > 0) { console.log("ScreenSize: " + width + " x " + height); }
163
+ console.log("ScreenSize: " + width + " x " + height);
164
obj.Canvas.setTransform(1, 0, 0, 1, 0, 0);
165
obj.rotation = 0;
166
obj.FirstDraw = true;
views/default.handlebars
+1
-1
@@ -6620,7 +6620,7 @@
6620
//function addHtmlValue(t, v) { return '<div style=height:20px><div style=float:right;width:220px><b>' + v + '</b></div><div>' + t + '</div></div>'; }
6621
function addHtmlValue(t, v) { return '<table><td style=width:120px>' + t + '<td><b>' + v + '</b></table>'; }
6622
function addHtmlValue2(t, v) { return '<div><div style=display:inline-block;float:right>' + v + '</div><div style=display:inline-block>' + t + '</div></div>'; }
6623
- 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 = parsedUri[x]; break; } case 1: { r[name] = parsedUri[x]; var x = parseInt(r[name]); if (x == r[name]) { r[name] = x; } break; } default: { break; } } } return r; }
6623
+ 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; }
6624
function focusTextBox(x) { setTimeout(function(){ Q(x).selectionStart = Q(x).selectionEnd = 65535; Q(x).focus(); }, 0); }
6625
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
6626
</script>
views/messenger.handlebars
+1
-1
@@ -162,7 +162,7 @@
162
}
163
164
function haltEvent(e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
165
- 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 = parsedUri[x]; break; } case 1: { r[name] = parsedUri[x]; var x = parseInt(r[name]); if (x == r[name]) { r[name] = x; } break; } default: { break; } } } return r; }
165
+ 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; }
166
167
// Update user controls
168
function updateControls() {