mirror of
https://github.com/unraid/webgui.git
synced 2026-03-11 21:38:50 -05:00
Docker: added shell/bash selection for console
This commit is contained in:
@@ -168,6 +168,7 @@ function postToXML($post, $setOwnership=false) {
|
||||
$xml->Registry = xml_encode(trim($post['contRegistry']));
|
||||
$xml->Network = xml_encode($post['contNetwork']);
|
||||
$xml->MyIP = xml_encode($post['contMyIP']);
|
||||
$xml->Shell = xml_encode($post['contShell']);
|
||||
$xml->Privileged = strtolower($post['contPrivileged'])=='on' ? 'true' : 'false';
|
||||
$xml->Support = xml_encode($post['contSupport']);
|
||||
$xml->Project = xml_encode($post['contProject']);
|
||||
@@ -242,6 +243,7 @@ function xmlToVar($xml) {
|
||||
$out['Registry'] = xml_decode($xml->Registry);
|
||||
$out['Network'] = xml_decode($xml->Network);
|
||||
$out['MyIP'] = xml_decode($xml->MyIP ?? '');
|
||||
$out['Shell'] = xml_decode($xml->Shell ?? 'sh');
|
||||
$out['Privileged'] = xml_decode($xml->Privileged);
|
||||
$out['Support'] = xml_decode($xml->Support);
|
||||
$out['Project'] = xml_decode($xml->Project);
|
||||
@@ -1423,6 +1425,14 @@ optgroup.title{background-color:#625D5D;color:#FFFFFF;text-align:center;margin-t
|
||||
</blockquote>
|
||||
</td>
|
||||
</tr>
|
||||
<tr <?=$showAdditionalInfo?>>
|
||||
<td>Console shell command:</td>
|
||||
<td><select name="contShell" class="narrow">
|
||||
<?=mk_option(1,'sh','Shell')?>
|
||||
<?=mk_option(1,'bash','Bash')?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr <?=$showAdditionalInfo?>>
|
||||
<td>Privileged:</td>
|
||||
<td><input type="checkbox" name="contPrivileged" class="switch-on-off"></td>
|
||||
|
||||
@@ -270,6 +270,7 @@ class DockerTemplates {
|
||||
$port = &$ct['Ports'][0];
|
||||
$ip = ($ct['NetworkMode']=='host'||$port['NAT'] ? $host : $port['IP']);
|
||||
$tmp['url'] = strpos($tmp['url'],$ip)!==false ? $tmp['url'] : $this->getControlURL($ct, $ip);
|
||||
$tmp['shell'] = $tmp['shell'] ?? $this->getTemplateValue($image, 'Shell');
|
||||
}
|
||||
$tmp['registry'] = $tmp['registry'] ?? $this->getTemplateValue($image, 'Registry');
|
||||
$tmp['Support'] = $tmp['Support'] ?? $this->getTemplateValue($image, 'Support');
|
||||
|
||||
@@ -92,10 +92,11 @@ switch ($action) {
|
||||
}
|
||||
break;
|
||||
case 'terminal':
|
||||
$shell = $_REQUEST['shell'] ?: 'sh';
|
||||
$pid = exec("pgrep -a ttyd|awk '/\\/$name\\.sock/{print \$1}'");
|
||||
if ($pid) exec("kill $pid");
|
||||
@unlink("/var/tmp/$name.sock");
|
||||
exec("exec ttyd -o -d0 -i '/var/tmp/$name.sock' docker exec -it '$name' sh &>/dev/null &");
|
||||
exec("exec ttyd -o -d0 -i '/var/tmp/$name.sock' docker exec -it '$name' $shell &>/dev/null &");
|
||||
break;
|
||||
default:
|
||||
$arrResponse = ['error' => "Unknown action '$action'"];
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var eventURL = '/plugins/dynamix.docker.manager/include/Events.php';
|
||||
|
||||
function addDockerContainerContext(container, image, template, started, paused, update, autostart, webui, id, Support, Project) {
|
||||
function addDockerContainerContext(container, image, template, started, paused, update, autostart, webui, shell, id, Support, Project) {
|
||||
var opts = [{header:container, image:'/plugins/dynamix.docker.manager/images/dynamix.docker.manager.png'}];
|
||||
if (started && !paused) {
|
||||
if (webui !== '' && webui != '#') opts.push({text:'WebUI', icon:'fa-globe', href:webui, target:'_blank'});
|
||||
opts.push({text:'Console', icon:'fa-terminal', action:function(e){e.preventDefault(); dockerTerminal(container);}});
|
||||
opts.push({text:'Console', icon:'fa-terminal', action:function(e){e.preventDefault(); dockerTerminal(container,shell);}});
|
||||
opts.push({divider:true});
|
||||
}
|
||||
if (!update) {
|
||||
@@ -45,12 +45,12 @@ function addDockerImageContext(image, imageTag) {
|
||||
opts.push({text:'Remove', icon:'fa-trash', action:function(e){e.preventDefault(); rmImage(image, imageTag);}});
|
||||
context.attach('#'+image, opts);
|
||||
}
|
||||
function dockerTerminal(container) {
|
||||
function dockerTerminal(container,shell) {
|
||||
var height = 600;
|
||||
var width = 900;
|
||||
var top = (screen.height-height)/2;
|
||||
var left = (screen.width-width)/2;
|
||||
$.get(eventURL,{action:'terminal',name:container});
|
||||
$.get(eventURL,{action:'terminal',name:container,shell:shell});
|
||||
setTimeout(function(){window.open('/dockerterminal/'+container+'/', container, 'resizeable=yes,scrollbars=yes,height='+height+',width='+width+',top='+top+',left='+left).focus();},180);
|
||||
}
|
||||
function execUpContainer(container) {
|
||||
|
||||
Reference in New Issue
Block a user