1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-27 17:29:39 +02:00

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

This commit is contained in:
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])
.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) {
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);
}
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);
if ($transition$.params().nodeName) {
@ -186,15 +192,21 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [
$scope.state = states.connected;
term = new Terminal();
socket.send('export LANG=C.UTF-8\n');
socket.send('export LC_ALL=C.UTF-8\n');
socket.send('clear\n');
if (isLinuxTerm) {
// linux terminals support xterm
socket.send('export LANG=C.UTF-8\n');
socket.send('export LC_ALL=C.UTF-8\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) {
socket.send(data);
// This code is detect whether the user has typed CTRL+D
// or exit in the terminal
// This code is detect whether the user has
// typed CTRL+D or exit in the terminal
if (data === '\x04') {
// If the user types CTRL+D, close the terminal
closeTerminal = true;