mirror of
				https://github.com/Ylianst/MeshCentral.git
				synced 2025-03-09 15:40:18 +00:00 
			
		
		
		
	Added terminal sizing support.
This commit is contained in:
		
							parent
							
								
									ff9e92ccc8
								
							
						
					
					
						commit
						2d86b614d6
					
				
					 4 changed files with 81 additions and 38 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
{
 | 
			
		||||
  "name": "meshcentral",
 | 
			
		||||
  "version": "0.3.5-y",
 | 
			
		||||
  "version": "0.3.5-z",
 | 
			
		||||
  "keywords": [
 | 
			
		||||
    "Remote Management",
 | 
			
		||||
    "Intel AMT",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,9 +5,10 @@
 | 
			
		|||
*/
 | 
			
		||||
 | 
			
		||||
// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
 | 
			
		||||
// https://www.x.org/docs/xterm/ctlseqs.pdf
 | 
			
		||||
 | 
			
		||||
// Construct a MeshServer object
 | 
			
		||||
var CreateAmtRemoteTerminal = function (divid) {
 | 
			
		||||
var CreateAmtRemoteTerminal = function (divid, options) {
 | 
			
		||||
    var obj = {};
 | 
			
		||||
    obj.DivId = divid;
 | 
			
		||||
    obj.DivElement = document.getElementById(divid);
 | 
			
		||||
| 
						 | 
				
			
			@ -44,7 +45,7 @@ var CreateAmtRemoteTerminal = function (divid) {
 | 
			
		|||
    var _VTREVERSE = 2;
 | 
			
		||||
    var _backSpaceErase = false;
 | 
			
		||||
    var _cursorVisible = true;
 | 
			
		||||
    var _scrollRegion = [0, 24];
 | 
			
		||||
    var _scrollRegion;
 | 
			
		||||
    var _altKeypadMode = false;
 | 
			
		||||
    var scrollBackBuffer = [];
 | 
			
		||||
    obj.title = null;
 | 
			
		||||
| 
						 | 
				
			
			@ -64,7 +65,9 @@ var CreateAmtRemoteTerminal = function (divid) {
 | 
			
		|||
        obj.TermDraw();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    obj.xxStateChange = function(newstate) { }
 | 
			
		||||
    obj.xxStateChange = function (newstate) {
 | 
			
		||||
        if ((newstate == 3) && (options != null) && (options.xterm == true)) { obj.TermSendKeys('stty rows ' + obj.height + ' cols ' + obj.width + '\nclear\n'); }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    obj.ProcessData = function (str) {
 | 
			
		||||
        if (obj.debugmode == 2) { console.log("TRecv(" + str.length + "): " + rstr2hex(str)); }
 | 
			
		||||
| 
						 | 
				
			
			@ -250,14 +253,14 @@ var CreateAmtRemoteTerminal = function (divid) {
 | 
			
		|||
                    if (argslen == 1) {
 | 
			
		||||
                        _termx = args[0] - 1;
 | 
			
		||||
                        if (_termx < 0) _termx = 0;
 | 
			
		||||
                        if (_termx > 79) _termx = 79;
 | 
			
		||||
                        if (_termx > (obj.width - 1)) _termx = (obj.width - 1);
 | 
			
		||||
                    }
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'P': // Delete X Character(s), default 1 char
 | 
			
		||||
                    var x = 1;
 | 
			
		||||
                    if (argslen == 1) { x = args[0]; }
 | 
			
		||||
                    for (i = _termx; i < 80 - x; i++) { _tscreen[_termy][i] = _tscreen[_termy][i + x]; _scratt[_termy][i] = _scratt[_termy][i + x]; }
 | 
			
		||||
                    for (i = (80 - x); i < 80; i++) { _tscreen[_termy][i] = ' '; _scratt[_termy][i] = (7 << 6); }
 | 
			
		||||
                    for (i = _termx; i < obj.width - x; i++) { _tscreen[_termy][i] = _tscreen[_termy][i + x]; _scratt[_termy][i] = _scratt[_termy][i + x]; }
 | 
			
		||||
                    for (i = (obj.width - x); i < obj.width; i++) { _tscreen[_termy][i] = ' '; _scratt[_termy][i] = (7 << 6); }
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'L': // Insert X Line(s), default 1 char
 | 
			
		||||
                    var linecount = 1;
 | 
			
		||||
| 
						 | 
				
			
			@ -369,9 +372,9 @@ var CreateAmtRemoteTerminal = function (divid) {
 | 
			
		|||
                case 'r': // Set the scroll region
 | 
			
		||||
                    if (argslen == 2) { _scrollRegion = [args[0] - 1, args[1] - 1]; }
 | 
			
		||||
                    if (_scrollRegion[0] < 0) { _scrollRegion[0] = 0; }
 | 
			
		||||
                    if (_scrollRegion[0] > 24) { _scrollRegion[0] = 24; }
 | 
			
		||||
                    if (_scrollRegion[0] > (obj.height - 1)) { _scrollRegion[0] = (obj.height - 1); }
 | 
			
		||||
                    if (_scrollRegion[1] < 0) { _scrollRegion[1] = 0; }
 | 
			
		||||
                    if (_scrollRegion[1] > 24) { _scrollRegion[1] = 24; }
 | 
			
		||||
                    if (_scrollRegion[1] > (obj.height - 1)) { _scrollRegion[1] = (obj.height - 1); }
 | 
			
		||||
                    if (_scrollRegion[0] > _scrollRegion[1]) { _scrollRegion[0] = _scrollRegion[1]; }
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'S': // Scroll up the scroll region X lines, default 1
 | 
			
		||||
| 
						 | 
				
			
			@ -597,7 +600,7 @@ var CreateAmtRemoteTerminal = function (divid) {
 | 
			
		|||
        _TermLineWrap = _cursorVisible = true;
 | 
			
		||||
        _termx = _termy = 0;
 | 
			
		||||
        _backSpaceErase = false;
 | 
			
		||||
        _scrollRegion = [0, 24];
 | 
			
		||||
        _scrollRegion = [0, (obj.height - 1)];
 | 
			
		||||
        _altKeypadMode = false;
 | 
			
		||||
        obj.TermClear(7 << 6);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -626,8 +629,8 @@ var CreateAmtRemoteTerminal = function (divid) {
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    obj.TermSendKeys = function (keys) { if (obj.debugmode == 2) { console.log("TSend(" + keys.length + "): " + rstr2hex(keys)); } obj.parent.send(keys); }
 | 
			
		||||
    obj.TermSendKey = function (key) { if (obj.debugmode == 2) { console.log("TSend(1): " + rstr2hex(String.fromCharCode(key))); } obj.parent.send(String.fromCharCode(key)); }
 | 
			
		||||
    obj.TermSendKeys = function (keys) { if (obj.debugmode == 2) { console.log("TSend(" + keys.length + "): " + rstr2hex(keys), keys); } obj.parent.send(keys); }
 | 
			
		||||
    obj.TermSendKey = function (key) { if (obj.debugmode == 2) { console.log("TSend(1): " + rstr2hex(String.fromCharCode(key)), key); } obj.parent.send(String.fromCharCode(key)); }
 | 
			
		||||
 | 
			
		||||
    function _TermMoveUp(linecount) {
 | 
			
		||||
        var x, y;
 | 
			
		||||
| 
						 | 
				
			
			@ -730,7 +733,6 @@ var CreateAmtRemoteTerminal = function (divid) {
 | 
			
		|||
        buf = r[0];
 | 
			
		||||
        closetag = r[1];
 | 
			
		||||
        scrollBackBuffer.push(buf + closetag + '<br>');
 | 
			
		||||
        if (scrollBackBuffer.length > 800) { scrollBackBuffer = scrollBackBuffer.slice(0, 800); }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    obj.TermDrawLine = function (buf, y, closetag) {
 | 
			
		||||
| 
						 | 
				
			
			@ -771,8 +773,8 @@ var CreateAmtRemoteTerminal = function (divid) {
 | 
			
		|||
            if (y != (obj.height - 1)) buf += '<br>';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var backbuffer = '';
 | 
			
		||||
        for (var i in scrollBackBuffer) { backbuffer += scrollBackBuffer[i]; }
 | 
			
		||||
        if (scrollBackBuffer.length > 800) { scrollBackBuffer = scrollBackBuffer.slice(scrollBackBuffer.length - 800); }
 | 
			
		||||
        var backbuffer = scrollBackBuffer.join('');
 | 
			
		||||
        obj.DivElement.innerHTML = "<font size='4'><b>" + backbuffer + buf + closetag + "</b></font>";
 | 
			
		||||
        obj.DivElement.scrollTop = obj.DivElement.scrollHeight;
 | 
			
		||||
        if (obj.heightLock == 0) { setTimeout(obj.TermLockHeight, 10); }
 | 
			
		||||
| 
						 | 
				
			
			@ -785,7 +787,9 @@ var CreateAmtRemoteTerminal = function (divid) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    obj.TermInit = function () { obj.TermResetScreen(); }
 | 
			
		||||
    
 | 
			
		||||
    obj.Init();
 | 
			
		||||
 | 
			
		||||
    obj.heightLock = 0;
 | 
			
		||||
    obj.DivElement.style['height'] = '';
 | 
			
		||||
    if ((options != null) && (options.width != null) && (options.height != null)) { obj.Init(options.width, options.height); } else { obj.Init(); }
 | 
			
		||||
    return obj;
 | 
			
		||||
}
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| 
						 | 
				
			
			@ -547,6 +547,9 @@
 | 
			
		|||
                                        <input id="id_tfxkeysbutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="Intel (F10 = ESC+[OM)" title="Toggle F1 to F10 keys emulation type" onclick="termToggleFx()">
 | 
			
		||||
                                        <input id="id_ttypebutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="Extended Ascii" title="Toggle terminal emulation type" onclick="termToggleType()">
 | 
			
		||||
                                    </span>
 | 
			
		||||
                                    <span id="terminalSizeDropDown">
 | 
			
		||||
                                        <select id="termSizeList" onkeypress="return false"><option value="1">80x25</option><option value="2">100x30</option><option value="3" selected>Auto</option></select>
 | 
			
		||||
                                    </span>
 | 
			
		||||
                                    <select id="specialkeylist" onkeypress="return false"></select>
 | 
			
		||||
                                    <input id="specialkeylistinput" type="button" onkeypress="return false" class="bottombutton" value="Send" title="Send the selected special key" onclick="sendSpecialKey()" />
 | 
			
		||||
                                </div>
 | 
			
		||||
| 
						 | 
				
			
			@ -5035,14 +5038,17 @@
 | 
			
		|||
            switch (state) {
 | 
			
		||||
                case 0:
 | 
			
		||||
                    // Disconnected, clear the terminal
 | 
			
		||||
                    QE('termSizeList', true);
 | 
			
		||||
                    QH('termtitle', '');
 | 
			
		||||
                    xterminal.m.TermResetScreen();
 | 
			
		||||
                    xterminal.m.TermDraw();
 | 
			
		||||
                    if (terminal != null) { terminal.Stop(); terminal = null; }
 | 
			
		||||
                    break;
 | 
			
		||||
                case 3:
 | 
			
		||||
                    QE('termSizeList', false);
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                    QE('termSizeList', false);
 | 
			
		||||
                    //console.log('Unhandled onTerminalStateChange state', state);
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -5058,7 +5064,9 @@
 | 
			
		|||
                if (contype == 2) {
 | 
			
		||||
                    // Setup the Intel AMT terminal
 | 
			
		||||
                    if ((terminalNode.intelamt.user == null) || (terminalNode.intelamt.user == '')) { editDeviceAmtSettings(terminalNode._id, connectTerminal); return; }
 | 
			
		||||
                    terminal = CreateAmtRedirect(CreateAmtRemoteTerminal('Term'), authCookie);
 | 
			
		||||
                    var termoptions = {};
 | 
			
		||||
                    if (Q('termSizeList').value == 2) { termoptions.width = 100; termoptions.height = 30; }
 | 
			
		||||
                    terminal = CreateAmtRedirect(CreateAmtRemoteTerminal('Term', termoptions), authCookie);
 | 
			
		||||
                    terminal.debugmode = debugmode;
 | 
			
		||||
                    terminal.m.debugmode = debugmode;
 | 
			
		||||
                    terminal.m.onTitleChange = function (sender, title) { QH('termtitle', ' - ' + EscapeHtml(title)); }
 | 
			
		||||
| 
						 | 
				
			
			@ -5068,7 +5076,17 @@
 | 
			
		|||
                    Q('id_ttypebutton').value = terminalEmulations[terminal.m.terminalEmulation];
 | 
			
		||||
                } else {
 | 
			
		||||
                    // Setup a mesh agent terminal
 | 
			
		||||
                    terminal = CreateAgentRedirect(meshserver, CreateAmtRemoteTerminal('Term'), serverPublicNamePort, authCookie, domainUrl);
 | 
			
		||||
                    var termoptions = {};
 | 
			
		||||
                    if ([1, 2, 3, 4, 21, 22].indexOf(currentNode.agent.id) == -1) {
 | 
			
		||||
                        if (Q('termSizeList').value == 2) { termoptions.width = 100; termoptions.height = 30; termoptions.xterm = true; }
 | 
			
		||||
                        if (Q('termSizeList').value == 3) {
 | 
			
		||||
                            // TODO: Try to improve terminal auto-size.
 | 
			
		||||
                            termoptions.width = Math.floor((Q('column_l').clientWidth - 60) / 10);
 | 
			
		||||
                            termoptions.height = Math.floor((Q('column_l').clientHeight - 120) / 20);
 | 
			
		||||
                            termoptions.xterm = true;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    terminal = CreateAgentRedirect(meshserver, CreateAmtRemoteTerminal('Term', termoptions), serverPublicNamePort, authCookie, domainUrl);
 | 
			
		||||
                    terminal.debugmode = debugmode;
 | 
			
		||||
                    terminal.m.debugmode = debugmode;
 | 
			
		||||
                    terminal.m.onTitleChange = function (sender, title) { QH('termtitle', ' - ' + EscapeHtml(title)); }
 | 
			
		||||
| 
						 | 
				
			
			@ -5076,6 +5094,7 @@
 | 
			
		|||
                    terminal.attemptWebRTC = attemptWebRTC;
 | 
			
		||||
                    terminal.onStateChanged = onTerminalStateChange;
 | 
			
		||||
                    terminal.onConsoleMessageChange = function () {
 | 
			
		||||
                        console.log('terminal.consoleMessage', terminal.consoleMessage);
 | 
			
		||||
                        p12clearConsoleMsg();
 | 
			
		||||
                        if (terminal.consoleMessage) {
 | 
			
		||||
                            QH('p12TermConsoleMsg', EscapeHtml(terminal.consoleMessage).split('\n').join('<br />'));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue