Added support for agent with improved key input.

This commit is contained in:
Ylian Saint-Hilaire 2020-11-17 19:30:26 -08:00
parent 0e99551459
commit 0790376119
31 changed files with 48 additions and 31 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -171,10 +171,9 @@ module.exports.CreateLetsEncrypt = function (parent) {
// Create Certificate Request (CSR)
obj.log("Creating certificate request...");
acme.forge.createCsr({
commonName: obj.leDomains[0],
altNames: obj.leDomains
}).then(function (r) {
var certRequest = { commonName: obj.leDomains[0] };
if (obj.leDomains.length > 1) { certRequest.altNames = obj.leDomains; }
acme.forge.createCsr(certRequest).then(function (r) {
var csr = r[1];
obj.tempPrivateKey = r[0];
obj.log("Requesting certificate from Let's Encrypt...");

File diff suppressed because one or more lines are too long

View File

@ -35,7 +35,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
obj.firstUpKeys = [];
obj.stopInput = false;
obj.localKeyMap = true;
obj.remoteKeyMap = null; // 'fr-CA'
obj.remoteKeyMap = true; // If false, the remote keyboard mapping is not used, only works on Windows.
obj.pressedKeys = [];
obj.sessionid = 0;
@ -282,7 +282,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
// Keyboard and Mouse I/O.
obj.MouseButton = { "NONE": 0x00, "LEFT": 0x02, "RIGHT": 0x08, "MIDDLE": 0x20 };
obj.KeyAction = { "NONE": 0, "DOWN": 1, "UP": 2, "SCROLL": 3, "EXUP": 4, "EXDOWN": 5, "DBLCLICK": 6 };
obj.InputType = { "KEY": 1, "MOUSE": 2, "CTRLALTDEL": 10, "TOUCH": 15, "KEYWITHLAYOUT": 85 };
obj.InputType = { "KEY": 1, "MOUSE": 2, "CTRLALTDEL": 10, "TOUCH": 15, "KEYUNICODE": 85 };
obj.Alternate = 0;
var convertKeyCodeTable = {
@ -399,16 +399,15 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
if (i != -1) { obj.pressedKeys.splice(i, 1); } // Remove the key press from the pressed array
}
if ((obj.remoteKeyMap == null) || (obj.remoteKeyMap == '')) {
// No remote keyboard mapping
obj.send(String.fromCharCode(0x00, obj.InputType.KEY, 0x00, 0x06, (action - 1), kc));
} else {
// With remote keyboard mapping
obj.send(String.fromCharCode(0x00, obj.InputType.KEYWITHLAYOUT, 0x00, 0x16, (action - 1), kc) + obj.remoteKeyMap + ('\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'.substring(0, 16 - obj.remoteKeyMap.length)));
}
obj.send(String.fromCharCode(0x00, obj.InputType.KEY, 0x00, 0x06, (action - 1), kc));
}
}
obj.SendKeyUnicode = function (action, val) {
if (obj.State != 3) return;
obj.send(String.fromCharCode(0x00, obj.InputType.KEYUNICODE, 0x00, 0x07, (action - 1)) + ShortToStr(val));
}
obj.sendcad = function() { obj.SendCtrlAltDelMsg(); }
obj.SendCtrlAltDelMsg = function () {
@ -528,13 +527,30 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
obj.xxMouseDblClick = function (e) { if (obj.State == 3) obj.SendMouseMsg(obj.KeyAction.DBLCLICK, e); if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
obj.xxDOMMouseScroll = function (e) { if (obj.State == 3) { obj.SendMouseMsg(obj.KeyAction.SCROLL, e); return false; } return true; }
obj.xxMouseWheel = function (e) { if (obj.State == 3) { obj.SendMouseMsg(obj.KeyAction.SCROLL, e); return false; } return true; }
obj.xxKeyUp = function (e) { if (obj.State == 3) { obj.SendKeyMsg(obj.KeyAction.UP, e); } if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
obj.xxKeyDown = function (e) { if (obj.State == 3) { obj.SendKeyMsg(obj.KeyAction.DOWN, e); } if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
obj.xxKeyPress = function (e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
obj.xxKeyUp = function (e) {
if ((e.key != 'Dead') && (obj.State == 3)) {
if ((e.key.length == 1) && (obj.remoteKeyMap == false)) { obj.SendKeyUnicode(obj.KeyAction.UP, e.key.charCodeAt(0)); } else { obj.SendKeyMsg(obj.KeyAction.UP, e); }
}
if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
}
obj.xxKeyDown = function (e) {
if ((e.key != 'Dead') && (obj.State == 3)) {
if ((e.key.length == 1) && (obj.remoteKeyMap == false)) { obj.SendKeyUnicode(obj.KeyAction.DOWN, e.key.charCodeAt(0)); } else { obj.SendKeyMsg(obj.KeyAction.DOWN, e); }
}
if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
}
obj.xxKeyPress = function (e) {
if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
}
// Key handlers
obj.handleKeys = function (e) { if (obj.stopInput == true || desktop.State != 3) return false; return obj.xxKeyPress(e); }
obj.handleKeys = function (e) {
//console.log('keypress', e.code, e.key, e.keyCode, (e.key.length == 1) ? e.key.charCodeAt(0) : 0);
if (obj.stopInput == true || desktop.State != 3) return false;
return obj.xxKeyPress(e);
}
obj.handleKeyUp = function (e) {
//console.log('keyup', e.code, e.key, e.keyCode, (e.key.length == 1)?e.key.charCodeAt(0):0);
if (obj.stopInput == true || desktop.State != 3) return false;
if (obj.firstUpKeys.length < 5) {
obj.firstUpKeys.push(e.keyCode);
@ -543,6 +559,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
return obj.xxKeyUp(e);
}
obj.handleKeyDown = function (e) {
//console.log('keydown', e.code, e.key, e.keyCode, (e.key.length == 1) ? e.key.charCodeAt(0) : 0);
if (obj.stopInput == true || desktop.State != 3) return false;
return obj.xxKeyDown(e);
}

File diff suppressed because one or more lines are too long

View File

@ -3198,6 +3198,13 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
if ((fields.overwriteFiles != null) && (fields.overwriteFiles.length == 1) && (fields.overwriteFiles[0] == 'on')) { cmd.overwrite = true; }
if ((fields.createFolder != null) && (fields.createFolder.length == 1) && (fields.createFolder[0] == 'on')) { cmd.createFolder = true; }
// Check if we have al least one target path
if ((cmd.windowsPath == null) && (cmd.linuxPath == null)) {
parent.debug('web', 'Batch upload error, invalid fields: ' + JSON.stringify(fields));
res.send('');
return;
}
// Get server temporary path
var serverpath = obj.path.join(obj.filespath, 'tmp')
try { obj.fs.mkdirSync(obj.parent.filespath); } catch (ex) { }
@ -3226,6 +3233,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
obj.GetNodeWithRights(cmd.domain, cmd.user, cmd.nodeids[i], function (node, rights, visible) {
if ((node == null) || ((rights & 8) == 0) || (visible == false)) return; // We don't have remote control rights to this device
var agentPath = ((node.agent.id > 0) && (node.agent.id < 5)) ? cmd.windowsPath : cmd.linuxPath;
if (agentPath == null) return;
// Event that this operation is being performed.
var targets = obj.CreateNodeDispatchTargets(node.meshid, node._id, ['server-users', cmd.user._id]);
@ -3235,18 +3243,11 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
// Send the agent commands to perform the batch upload operation
for (var f in cmd.files) {
try {
//if ((agentPath != null) && (cmd.files[f].name != null)) {
const acmd = { action: 'wget', overwrite: cmd.overwrite, createFolder: cmd.createFolder, urlpath: '/agentdownload.ashx?c=' + obj.parent.encodeCookie({ a: 'tmpdl', d: cmd.domain.id, nid: node._id, f: cmd.files[f].target }, obj.parent.loginCookieEncryptionKey), path: obj.path.join(agentPath, cmd.files[f].name), folder: agentPath, servertlshash: tlsCertHash };
var agent = obj.wsagents[node._id];
if (agent != null) { try { agent.send(JSON.stringify(acmd)); } catch (ex) { } }
// TODO: Add support for peer servers.
//}
} catch (ex) {
parent.debug('web', 'Exception: ' + ex);
parent.debug('web', 'AgentPath: ' + agentPath);
parent.debug('web', 'Command: ' + JSON.stringify(cmd));
parent.debug('web', 'AgentId: ' + node.agent.id);
if (cmd.files[f].name != null) {
const acmd = { action: 'wget', overwrite: cmd.overwrite, createFolder: cmd.createFolder, urlpath: '/agentdownload.ashx?c=' + obj.parent.encodeCookie({ a: 'tmpdl', d: cmd.domain.id, nid: node._id, f: cmd.files[f].target }, obj.parent.loginCookieEncryptionKey), path: obj.path.join(agentPath, cmd.files[f].name), folder: agentPath, servertlshash: tlsCertHash };
var agent = obj.wsagents[node._id];
if (agent != null) { try { agent.send(JSON.stringify(acmd)); } catch (ex) { } }
// TODO: Add support for peer servers.
}
}
});