fix(console): fix command not found [EE-6982] (#11825)

pull/11848/head
Matt Hook 2024-05-20 14:35:29 +12:00 committed by GitHub
parent 2b01136d03
commit db8f9c6f6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 7 deletions

View File

@ -121,7 +121,8 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [
.map((k) => k + '=' + params[k]) .map((k) => k + '=' + params[k])
.join('&'); .join('&');
initTerm(url, ExecService.resizeTTY.bind(this, endpoint.Id, params.id)); const isLinuxCommand = execConfig.Cmd ? isLinuxTerminalCommand(execConfig.Cmd[0]) : false;
initTerm(url, ExecService.resizeTTY.bind(this, params.id), isLinuxCommand);
}) })
.catch(function error(err) { .catch(function error(err) {
Notifications.error('Failure', err, 'Unable to exec into container'); Notifications.error('Failure', err, 'Unable to exec into container');
@ -165,7 +166,12 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [
restcall(termWidth + add, termHeight + add, 1); restcall(termWidth + add, termHeight + add, 1);
} }
function initTerm(url, resizeRestCall) { function isLinuxTerminalCommand(command) {
const validShellCommands = ['ash', 'bash', 'dash', 'sh'];
return validShellCommands.includes(command);
}
function initTerm(url, resizeRestCall, isLinuxTerm = false) {
let resizefun = resize.bind(this, resizeRestCall); let resizefun = resize.bind(this, resizeRestCall);
if ($transition$.params().nodeName) { if ($transition$.params().nodeName) {
@ -186,15 +192,21 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [
$scope.state = states.connected; $scope.state = states.connected;
term = new Terminal(); term = new Terminal();
if (isLinuxTerm) {
// linux terminals support xterm
socket.send('export LANG=C.UTF-8\n'); socket.send('export LANG=C.UTF-8\n');
socket.send('export LC_ALL=C.UTF-8\n'); socket.send('export LC_ALL=C.UTF-8\n');
socket.send('clear\n'); socket.send('export TERM="xterm-256color"\n');
socket.send('alias ls="ls --color=auto"\n');
socket.send('echo -e "\\033[2J\\033[H"\n');
}
term.onData(function (data) { term.onData(function (data) {
socket.send(data); socket.send(data);
// This code is detect whether the user has typed CTRL+D // This code is detect whether the user has
// or exit in the terminal // typed CTRL+D or exit in the terminal
if (data === '\x04') { if (data === '\x04') {
// If the user types CTRL+D, close the terminal // If the user types CTRL+D, close the terminal
closeTerminal = true; closeTerminal = true;

View File

@ -29,6 +29,7 @@
<select class="form-control" ng-model="formValues.command" id="command" data-cy="command-select"> <select class="form-control" ng-model="formValues.command" id="command" data-cy="command-select">
<option value="ash" ng-if="imageOS == 'linux'">/bin/ash</option> <option value="ash" ng-if="imageOS == 'linux'">/bin/ash</option>
<option value="bash" ng-if="imageOS == 'linux'">/bin/bash</option> <option value="bash" ng-if="imageOS == 'linux'">/bin/bash</option>
<option value="dash" ng-if="imageOS == 'linux'">/bin/dash</option>
<option value="sh" ng-if="imageOS == 'linux'">/bin/sh</option> <option value="sh" ng-if="imageOS == 'linux'">/bin/sh</option>
<option value="powershell" ng-if="imageOS == 'windows'">powershell</option> <option value="powershell" ng-if="imageOS == 'windows'">powershell</option>
<option value="cmd.exe" ng-if="imageOS == 'windows'">cmd.exe</option> <option value="cmd.exe" ng-if="imageOS == 'windows'">cmd.exe</option>