Skip to content

Commit

Permalink
Fixed terminal.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ylianst committed Jun 4, 2020
1 parent ad54251 commit b3d8274
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 26 deletions.
16 changes: 14 additions & 2 deletions agent-desktop-0.0.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions amt-desktop-0.0.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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; }
Expand Down
12 changes: 3 additions & 9 deletions amt-redir-node-0.1.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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); }
}
Expand Down
28 changes: 27 additions & 1 deletion amt-redir-ws-0.1.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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:
Expand All @@ -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) {
Expand Down Expand Up @@ -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...
Expand Down
24 changes: 12 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -913,21 +913,21 @@ <h1>Serial-over-LAN Terminal</h1>
<tr>
<td style="padding-top:2px;padding-bottom:2px;background:#CCC">
<div style="float:right;text-align:right">
<input id="id_tcrbutton" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event);return false" class="bottombutton" value="CR+LF" title="Toggle what the return key will send" onclick="termToggleCr()">
<input id="id_tcrbutton" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event);return false" class="bottombutton" value="CR+LF" title="Toggle what the return key will send" onclick="termToggleCr();Q('id_tcrbutton').blur()">
<!-- ###BEGIN###{TerminalSize} -->
<input id="id_tsizebutton" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event); return false" class="bottombutton" value="80x25" title="Toggle terminal size" onclick="termToggleSize()">
<input id="id_tsizebutton" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event); return false" class="bottombutton" value="80x25" title="Toggle terminal size" onclick="termToggleSize();Q('id_tsizebutton').blur()">
<!-- ###END###{TerminalSize} -->
<input id="id_tfxkeysbutton" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event);return false" class="bottombutton" value="Intel (F10 = ESC+[OM)" title="Toggle F1 to F10 keys emulation type" onclick="termToggleFx()">
<input id="id_tfxkeysbutton" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event);return false" class="bottombutton" value="Intel (F10 = ESC+[OM)" title="Toggle F1 to F10 keys emulation type" onclick="termToggleFx();Q('id_tfxkeysbutton').blur()">
<!-- ###BEGIN###{Terminal-Enumation-All} -->
<input id="id_ttypebutton" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event);return false" class="bottombutton" value="Extended Ascii" title="Toggle terminal emulation type" onclick="termToggleType()">&nbsp;
<input id="id_ttypebutton" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event);return false" class="bottombutton" value="Extended Ascii" title="Toggle terminal emulation type" onclick="termToggleType();Q('id_ttypebutton').blur()">&nbsp;
<!-- ###END###{Terminal-Enumation-All} -->
</div>
<div>
&nbsp;
<input type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event); return false" class="bottombutton" value="Ctl-C" onclick="termSendKey(3)">
<input type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event); return false" class="bottombutton" value="Ctl-X" onclick="termSendKey(24)">
<input type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event); return false" class="bottombutton" value="ESC" onclick="termSendKey(27)">
<input type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event); return false" class="bottombutton" value="Backspace" onclick="termSendKey(8)">
<input id="id_toolbtncc" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event); return false" class="bottombutton" value="Ctl-C" onclick="termSendKey(3);Q('id_toolbtncc').blur()">
<input id="id_toolbtncx" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event); return false" class="bottombutton" value="Ctl-X" onclick="termSendKey(24);Q('id_toolbtncx').blur()">
<input id="id_toolbtnes" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event); return false" class="bottombutton" value="ESC" onclick="termSendKey(27);Q('id_toolbtnes').blur()">
<input id="id_toolbtnbs" type="button" onkeypress="return false" onkeydown="if (event.keyCode == 13) handleKeyPress(event); return false" class="bottombutton" value="Backspace" onclick="termSendKey(8);Q('id_toolbtnbs').blur()">
<input id="id_tpastebutton" type="button" onkeypress="return false" onkeydown="return false" class="cadbutton" value="Paste" disabled="disabled" onclick="setDialogMode(3,'Paste',3,termPaste)">
</div>
</td>
Expand Down Expand Up @@ -1617,7 +1617,7 @@ <h4 style="width:100%;border-bottom:1px solid gray">Software KVM</h4>
<!-- ###END###{PowerControl} -->
<script type="text/javascript">
// ###BEGIN###{!Look-BrandedCommander}
var version = '0.8.3';
var version = '0.8.4';
// ###END###{!Look-BrandedCommander}
// ###BEGIN###{Look-BrandedCommander}
var version = '1.2.0';
Expand Down Expand Up @@ -7670,8 +7670,8 @@ <h4 style="width:100%;border-bottom:1px solid gray">Software KVM</h4>
// ###END###{Mode-NodeWebkit}
}

function termPaste() { terminal.m.TermSendKeys(d3pastetextarea.value) }
function termSendKey(k) { terminal.m.TermSendKey(k) }
function termPaste() { terminal.m.TermSendKeys(d3pastetextarea.value); return false; }
function termSendKey(k) { terminal.m.TermSendKey(k); return false; }

// ###BEGIN###{TerminalSize}
function termToggleSize() {
Expand Down Expand Up @@ -8401,7 +8401,7 @@ <h4 style="width:100%;border-bottom:1px solid gray">Software KVM</h4>
h = '<div class=filelist file=999><input file=999 style=float:left name=fd class=fcb type=checkbox onchange=p24setActions() value="' + f.nx + '">&nbsp;<span style=float:right title=\"' + title + '\">' + right + '</span><span><div class=fileIcon' + f.t + '></div><a style=cursor:pointer onclick=p24folderset(\"' + encodeURIComponent(f.nx) + '\")>' + shortname + '</a></span></div>';
} else {
var link = shortname;
if (f.s > 0) { link = '<a rel=\"noreferrer noopener\" target=\"_blank\" style=cursor:pointer onclick=\"p24downloadfile("' + encodeURIComponent(newlinkpath + '/' + name) + '","' + encodeURIComponent(name) + '",' + f.s + ')\">' + shortname + '</a>'; }
if (f.s > 0) { link = '<a rel=\"noreferrer noopener\" target=\"_blank\" style=cursor:pointer onclick=\'p24downloadfile("' + encodeURIComponent(newlinkpath + '/' + name) + '","' + encodeURIComponent(name) + '",' + f.s + ')\'>' + shortname + '</a>'; }
h = '<div class=filelist file=3><input file=3 style=float:left name=fd class=fcb type=checkbox onchange=p24setActions() value="' + f.nx + '">&nbsp;<span class=fsize>' + fdatestr + '</span><span style=float:right>' + fsize + '</span><span><div class=fileIcon' + f.t + '></div>' + link + '</span></div>';
}

Expand Down

0 comments on commit b3d8274

Please sign in to comment.