From b3d8274c180c3332b7064138f661e6207bb8d75e Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 3 Jun 2020 22:49:28 -0700 Subject: [PATCH] Fixed terminal. --- agent-desktop-0.0.2.js | 16 ++++++++++++++-- amt-desktop-0.0.2.js | 4 ++-- amt-redir-node-0.1.0.js | 12 +++--------- amt-redir-ws-0.1.0.js | 28 +++++++++++++++++++++++++++- index.html | 24 ++++++++++++------------ 5 files changed, 58 insertions(+), 26 deletions(-) diff --git a/agent-desktop-0.0.2.js b/agent-desktop-0.0.2.js index 2e9f148..cc39955 100644 --- a/agent-desktop-0.0.2.js +++ b/agent-desktop-0.0.2.js @@ -41,7 +41,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) { obj.oldie = false; obj.CompressionLevel = 50; obj.ScalingLevel = 1024; - obj.FrameRateTimer = 50; + obj.FrameRateTimer = 10; obj.FirstDraw = false; obj.ScreenWidth = 960; @@ -57,6 +57,11 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) { obj.onDisplayinfo = null; obj.accumulator = null; + var xMouseCursorActive = true; + var xMouseCursorCurrent = 'default'; + obj.mouseCursorActive = function (x) { if (xMouseCursorActive == x) return; xMouseCursorActive = x; obj.CanvasId.style.cursor = ((x == true) ? xMouseCursorCurrent : 'default'); } + var mouseCursors = ['default', 'progress', 'crosshair', 'pointer', 'help', 'text', 'no-drop', 'move', 'nesw-resize', 'ns-resize', 'nwse-resize', 'w-resize', 'alias', 'wait', 'none', 'not-allowed', 'col-resize', 'row-resize', 'copy', 'zoom-in', 'zoom-out']; + obj.Start = function () { obj.State = 0; obj.accumulator = null; @@ -213,7 +218,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) { jumboAdd = 8; } if ((cmdsize != str.length) && (obj.debugmode > 0)) { console.log(cmdsize, str.length, cmdsize == str.length); } - if ((command >= 18) && (command != 65)) { console.error("Invalid KVM command " + command + " of size " + cmdsize); console.log("Invalid KVM data", str.length, rstr2hex(str.substring(0, 40)) + '...'); return; } + if ((command >= 18) && (command != 65) && (command != 88)) { console.error("Invalid KVM command " + command + " of size " + cmdsize); console.log("Invalid KVM data", str.length, rstr2hex(str.substring(0, 40)) + '...'); return; } if (cmdsize > str.length) { //console.log('KVM accumulator set to ' + str.length + ' bytes, need ' + cmdsize + ' bytes.'); obj.accumulator = str; @@ -296,6 +301,13 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) { console.log('KVM: ' + str.substring(1)); } break; + case 88: // MNG_KVM_MOUSE_CURSOR + if (cmdsize != 5) break; + var cursorNum = str.charCodeAt(4); + if (cursorNum > mouseCursors.length) { cursorNum = 0; } + xMouseCursorCurrent = mouseCursors[cursorNum]; + if (xMouseCursorActive) { obj.CanvasId.style.cursor = xMouseCursorCurrent; } + break; } return cmdsize + jumboAdd; } diff --git a/amt-desktop-0.0.2.js b/amt-desktop-0.0.2.js index f466bcc..37459bb 100644 --- a/amt-desktop-0.0.2.js +++ b/amt-desktop-0.0.2.js @@ -398,7 +398,7 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) { obj.canvas.canvas.width = obj.width; obj.canvas.canvas.height = obj.height; if (obj.onScreenSizeChange != null) { obj.onScreenSizeChange(obj, obj.ScreenWidth, obj.ScreenHeight); } // ??? } - obj.Send(String.fromCharCode(3, 0, 0, 0, 0, 0) + ShortToStr(obj.width) + ShortToStr(obj.height)); // FramebufferUpdateRequest + obj.send(String.fromCharCode(3, 0, 0, 0, 0, 0) + ShortToStr(obj.width) + ShortToStr(obj.height)); // FramebufferUpdateRequest } else { obj.UnGrabMouseInput(); obj.UnGrabKeyInput(); @@ -743,7 +743,7 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) { if (acc.byteLength < len) return 0; // ###BEGIN###{DesktopInband} if (obj.onKvmData != null) { - var d = arrToStr(acc.slice(8, len)); + var d = arrToStr(new Uint8Array(acc.buffer.slice(8, len))); if ((d.length >= 16) && (d.substring(0, 15) == '\0KvmDataChannel')) { if (obj.kvmDataSupported == false) { obj.kvmDataSupported = true; console.log('KVM Data Channel Supported.'); } if (((obj.onKvmDataAck == -1) && (d.length == 16)) || (d.charCodeAt(15) != 0)) { obj.onKvmDataAck = true; } diff --git a/amt-redir-node-0.1.0.js b/amt-redir-node-0.1.0.js index 624b590..45894fd 100644 --- a/amt-redir-node-0.1.0.js +++ b/amt-redir-node-0.1.0.js @@ -231,7 +231,7 @@ var CreateAmtRedirect = function (module) { if (accArray.byteLength < 10) break; var cs = (10 + (accArray[9] << 8) + accArray[8]); if (accArray.byteLength < cs) break; - if (obj.m.ProcessBinaryData) { obj.m.ProcessBinaryData(obj.acc.slice(10, cs)); } else { obj.m.ProcessData(arrToStr(obj.acc.slice(10, cs))); } + if (obj.m.ProcessBinaryData) { obj.m.ProcessBinaryData(obj.acc.slice(10, cs)); } else { obj.m.ProcessData(arrToStr(new Uint8Array(obj.acc.slice(10, cs)))); } cmdsize = cs; break; case 0x2B: // Keep alive message (43) @@ -243,13 +243,7 @@ var CreateAmtRedirect = function (module) { obj.connectstate = 1; obj.m.Start(); // KVM traffic, forward rest of accumulator directly. - if (accArray.byteLength > 8) { - if (obj.m.ProcessBinaryData) { - obj.m.ProcessBinaryData(obj.acc.slice(8)); - } else { - obj.m.ProcessData(arrToStr(new Uint8Array(obj.acc.slice(8)))); - } - } + if (accArray.byteLength > 8) { if (obj.m.ProcessBinaryData) { obj.m.ProcessBinaryData(obj.acc.slice(8)); } else { obj.m.ProcessData(arrToStr(new Uint8Array(obj.acc.slice(8)))); } } cmdsize = accArray.byteLength; break; case 0xF0: @@ -275,7 +269,7 @@ var CreateAmtRedirect = function (module) { obj.socket.write(new Buffer(x, 'binary')); } - obj.Send = function (x) { + obj.Send = obj.send = function (x) { if (obj.socket == null || obj.connectstate != 1) return; if (obj.protocol == 1) { obj.xxSend(String.fromCharCode(0x28, 0x00, 0x00, 0x00) + ToIntStr(obj.amtsequence++) + ToShortStr(x.length) + x); } else { obj.xxSend(x); } } diff --git a/amt-redir-ws-0.1.0.js b/amt-redir-ws-0.1.0.js index 8023b0c..a5a54d0 100644 --- a/amt-redir-ws-0.1.0.js +++ b/amt-redir-ws-0.1.0.js @@ -9,7 +9,9 @@ var CreateAmtRedirect = function (module, authCookie) { var obj = {}; obj.m = module; // This is the inner module (Terminal or Desktop) module.parent = obj; + // ###BEGIN###{!Mode-Firmware} obj.authCookie = authCookie; + // ###END###{!Mode-Firmware} obj.State = 0; obj.socket = null; // ###BEGIN###{!Mode-Firmware} @@ -31,6 +33,7 @@ var CreateAmtRedirect = function (module, authCookie) { function arrToStr(arr) { return String.fromCharCode.apply(null, arr); } function randomHex(length) { var r = ''; for (var i = 0; i < length; i++) { r += 'abcdef0123456789'.charAt(Math.floor(Math.random() * 16)); } return r; } + // ###BEGIN###{!Mode-Firmware} obj.Start = function (host, port, user, pass, tls) { obj.host = host; obj.port = port; @@ -47,6 +50,19 @@ var CreateAmtRedirect = function (module, authCookie) { obj.socket.onclose = obj.xxOnSocketClosed; obj.xxStateChange(1); } + // ###END###{!Mode-Firmware} + + // ###BEGIN###{Mode-Firmware} + obj.Start = function () { + obj.connectstate = 0; + obj.socket = new WebSocket(window.location.protocol.replace('http', 'ws') + '//' + window.location.host + '/ws-redirection'); + obj.socket.binaryType = 'arraybuffer'; + obj.socket.onopen = obj.xxOnSocketConnected; + obj.socket.onmessage = obj.xxOnMessage; + obj.socket.onclose = obj.xxOnSocketClosed; + obj.xxStateChange(1); + } + // ###END###{Mode-Firmware} obj.xxOnSocketConnected = function () { obj.xxStateChange(2); @@ -86,7 +102,14 @@ var CreateAmtRedirect = function (module, authCookie) { if (accArray.byteLength < 13) return; var oemlen = accArray[12]; if (accArray.byteLength < 13 + oemlen) return; + // ###BEGIN###{!Mode-Firmware} + // Query for available authentication obj.directSend(new Uint8Array([0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); // Query for available authentication + // ###END###{!Mode-Firmware} + // ###BEGIN###{Mode-Firmware} + // When using websocket, we are already authenticated. Send empty basic auth. + obj.directSend(new Uint8Array([0x13, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00])); + // ###END###{Mode-Firmware} cmdsize = (13 + oemlen); break; default: @@ -102,6 +125,7 @@ var CreateAmtRedirect = function (module, authCookie) { for (i = 0; i < authDataLen; i++) { authData.push(accArray[9 + i]); } var authDataBuf = new Uint8Array(obj.acc.slice(9, 9 + authDataLen)); cmdsize = 9 + authDataLen; + // ###BEGIN###{!Mode-Firmware} if (authType == 0) { // Query if (authData.indexOf(4) >= 0) { @@ -149,7 +173,9 @@ var CreateAmtRedirect = function (module, authCookie) { var buf = String.fromCharCode(0x13, 0x00, 0x00, 0x00, authType) + IntToStrX(totallen) + String.fromCharCode(obj.user.length) + obj.user + String.fromCharCode(realm.length) + realm + String.fromCharCode(nonce.length) + nonce + String.fromCharCode(obj.authuri.length) + obj.authuri + String.fromCharCode(cnonce.length) + cnonce + String.fromCharCode(snc.length) + snc + String.fromCharCode(digest.length) + digest; if (authType == 4) buf += (String.fromCharCode(qop.length) + qop); obj.xxSend(buf); - } else if (status == 0) { // Success + } else + // ###END###{!Mode-Firmware} + if (status == 0) { // Success switch (obj.protocol) { case 1: { // Serial-over-LAN: Send Intel AMT serial settings... diff --git a/index.html b/index.html index b652ce3..eb38c7c 100644 --- a/index.html +++ b/index.html @@ -913,21 +913,21 @@
- + - + - + -   +  
  - - - - + + + +
@@ -1617,7 +1617,7 @@