Merge pull request #868 from TotallyNotElite/master
[WIP] Add dynamic resizing of xterm tty
This commit is contained in:
commit
106e900c82
|
@ -39,8 +39,7 @@ var MESHRIGHT_LIMITEDINPUT = 4096;
|
|||
|
||||
function createMeshCore(agent) {
|
||||
var obj = {};
|
||||
if (process.platform == 'win32' && require('user-sessions').isRoot())
|
||||
{
|
||||
if (process.platform == 'win32' && require('user-sessions').isRoot()) {
|
||||
// Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
|
||||
try {
|
||||
var writtenSize = 0, actualSize = Math.floor(require('fs').statSync(process.execPath).size / 1024);
|
||||
|
@ -1224,21 +1223,28 @@ function createMeshCore(agent) {
|
|||
var options = { uid: (this.httprequest.protocol == 8) ? require('user-sessions').consoleUid() : null, env: env };
|
||||
var setupcommands = ' alias ls=\'ls --color=auto\'\n';
|
||||
if (shell == sh) setupcommands += ' stty erase ^H\n';
|
||||
setupcommands += ' clear\n';
|
||||
|
||||
if (script && shell && process.platform == 'linux') {
|
||||
this.httprequest.process = childProcess.execFile(script, ['script', '--return', '--quiet', '-c', '"' + shell + '"', '/dev/null'], options); // Start as active user
|
||||
// Is child process the shell? Needed for resizing.
|
||||
this.httprequest.process.isChildShell = true;
|
||||
this.httprequest.process.stdin.write(setupcommands);
|
||||
} else if (python && shell) {
|
||||
this.httprequest.process = childProcess.execFile(python, ['python', '-c', 'import pty; pty.spawn(["' + shell + '"])'], options); // Start as active user
|
||||
// Is child process the shell? Needed for resizing.
|
||||
this.httprequest.process.isChildShell = true;
|
||||
if (process.platform == 'linux') { this.httprequest.process.stdin.write(setupcommands); }
|
||||
} else if (bash) {
|
||||
options.type = childProcess.SpawnTypes.TERM;
|
||||
this.httprequest.process = childProcess.execFile(bash, ['bash', '-i'], options); // Start as active user
|
||||
// Is child process the shell? Needed for resizing.
|
||||
this.httprequest.process.isChildShell = false;
|
||||
if (process.platform == 'linux') { this.httprequest.process.stdin.write(setupcommands); }
|
||||
} else if (sh) {
|
||||
options.type = childProcess.SpawnTypes.TERM;
|
||||
this.httprequest.process = childProcess.execFile(sh, ['sh'], options); // Start as active user
|
||||
// Is child process the shell? Needed for resizing.
|
||||
this.httprequest.process.isChildShell = false;
|
||||
if (process.platform == 'linux') { this.httprequest.process.stdin.write(setupcommands + "PS1='$ '\n"); }
|
||||
} else {
|
||||
MeshServerLog("Failed to start remote terminal session, no shell found");
|
||||
|
@ -1791,8 +1797,15 @@ function createMeshCore(agent) {
|
|||
// TODO
|
||||
} else {
|
||||
if (ws.httprequest.process == null) return;
|
||||
//sendConsoleText('Linux-TermSize: ' + obj.cols + 'x' + obj.rows);
|
||||
// TODO
|
||||
// ILibDuktape_ChildProcess kill doesn't support sending signals
|
||||
if (fs.existsSync("/bin/kill"))
|
||||
{
|
||||
if (ws.httprequest.process.isChildShell)
|
||||
// We need to send signal to the child of the process, since the child is the shell
|
||||
childProcess.execFile('/bin/bash', ['bash', "-c", "kill -SIGWINCH $(pgrep -P " + ws.httprequest.process.pid + ")"]);
|
||||
else
|
||||
childProcess.execFile('/bin/bash', ['bash', "-c", "kill -SIGWINCH " + ws.httprequest.process.pid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -2226,8 +2239,7 @@ function createMeshCore(agent) {
|
|||
break;
|
||||
}
|
||||
case 'ps': {
|
||||
processManager.getProcesses(function (plist)
|
||||
{
|
||||
processManager.getProcesses(function (plist) {
|
||||
var x = '';
|
||||
for (var i in plist) { x += i + ((plist[i].user) ? (', ' + plist[i].user) : '') + ', ' + plist[i].cmd + '\r\n'; }
|
||||
sendConsoleText(x, sessionid);
|
||||
|
|
|
@ -180,6 +180,7 @@
|
|||
break;
|
||||
case 3:
|
||||
// Connected
|
||||
tunnel.sendText(`mcresize() { old=$(stty -g);stty raw -echo min 0 time 5;printf '\\0337\\033[r\\033[999;999H\\033[6n\\0338' > /dev/tty;IFS='[;R' read -r _ rows cols _ < /dev/tty;stty "$old";stty cols "$cols" rows "$rows"; };trap mcresize SIGWINCH;clear\n`);
|
||||
term.focus();
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue