fix runcommands missing data (#5477)

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
Simon Smith 2023-10-28 19:28:30 +01:00 committed by GitHub
parent 6c15bcbe05
commit 2173921f07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1496,33 +1496,33 @@ function handleServerCommand(data) {
if (options.uid == null) break;
if (((require('user-sessions').minUid != null) && (options.uid < require('user-sessions').minUid()))) break; // This command can only run as user.
}
var replydata = "";
if (process.platform == 'win32') {
if (data.type == 1) {
// Windows command shell
mesh.cmdchild = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['cmd'], options);
mesh.cmdchild.descriptorMetadata = 'UserCommandsShell';
mesh.cmdchild.stdout.on('data', function (c) { sendConsoleText(c.toString()); });
mesh.cmdchild.stderr.on('data', function (c) { sendConsoleText(c.toString()); });
mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); });
mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); });
mesh.cmdchild.stdin.write(data.cmds + '\r\nexit\r\n');
mesh.cmdchild.on('exit', function () { sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
mesh.cmdchild.on('exit', function () { sendConsoleText(replydata); sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
} else if (data.type == 2) {
// Windows Powershell
mesh.cmdchild = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], options);
mesh.cmdchild.descriptorMetadata = 'UserCommandsPowerShell';
mesh.cmdchild.stdout.on('data', function (c) { sendConsoleText(c.toString()); });
mesh.cmdchild.stderr.on('data', function (c) { sendConsoleText(c.toString()); });
mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); });
mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); });
mesh.cmdchild.stdin.write(data.cmds + '\r\nexit\r\n');
mesh.cmdchild.on('exit', function () { sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
mesh.cmdchild.on('exit', function () { sendConsoleText(replydata); sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
}
} else if (data.type == 3) {
// Linux shell
mesh.cmdchild = require('child_process').execFile('/bin/sh', ['sh'], options);
mesh.cmdchild.descriptorMetadata = 'UserCommandsShell';
mesh.cmdchild.stdout.on('data', function (c) { sendConsoleText(c.toString()); });
mesh.cmdchild.stderr.on('data', function (c) { sendConsoleText(c.toString()); });
mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); });
mesh.cmdchild.stderr.on('data', function (c) { replydata + c.toString(); });
mesh.cmdchild.stdin.write(data.cmds.split('\r').join('') + '\nexit\n');
mesh.cmdchild.on('exit', function () { sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
mesh.cmdchild.on('exit', function () { sendConsoleText(replydata); sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
}
break;
}