mirror of https://github.com/portainer/portainer
fix(console): fix command not found [EE-6982] (#11832)
parent
6c98271e43
commit
f5d896bce1
|
@ -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, 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) {
|
||||||
|
@ -183,13 +189,20 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [
|
||||||
socket.onopen = function () {
|
socket.onopen = function () {
|
||||||
$scope.state = states.connected;
|
$scope.state = states.connected;
|
||||||
term = new Terminal();
|
term = new Terminal();
|
||||||
socket.send('export LANG=C.UTF-8\n');
|
|
||||||
socket.send('export LC_ALL=C.UTF-8\n');
|
if (isLinuxTerm) {
|
||||||
socket.send('clear\n');
|
// 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) {
|
term.onData(function (data) {
|
||||||
socket.send(data);
|
socket.send(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
var terminal_container = document.getElementById('terminal-container');
|
var terminal_container = document.getElementById('terminal-container');
|
||||||
term.open(terminal_container);
|
term.open(terminal_container);
|
||||||
term.focus();
|
term.focus();
|
||||||
|
@ -207,11 +220,13 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [
|
||||||
socket.onmessage = function (e) {
|
socket.onmessage = function (e) {
|
||||||
term.write(e.data);
|
term.write(e.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.onerror = function (err) {
|
socket.onerror = function (err) {
|
||||||
$scope.disconnect();
|
$scope.disconnect();
|
||||||
$scope.$apply();
|
|
||||||
Notifications.error('Failure', err, 'Connection error');
|
Notifications.error('Failure', err, 'Connection error');
|
||||||
|
$scope.$apply();
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.onclose = function () {
|
socket.onclose = function () {
|
||||||
$scope.disconnect();
|
$scope.disconnect();
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
<select class="form-control" ng-model="formValues.command" id="command">
|
<select class="form-control" ng-model="formValues.command" id="command">
|
||||||
<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>
|
||||||
|
|
Loading…
Reference in New Issue