Merge pull request #1117 from arifer612/feat/docker-webui

Use docker label as primary source for WebUI
This commit is contained in:
tom mortensen
2022-06-27 16:12:39 -07:00
committed by GitHub

View File

@@ -268,11 +268,12 @@ class DockerTemplates {
return false;
}
private function getControlURL(&$ct, $myIP) {
private function getControlURL(&$ct, $myIP, $WebUI) {
global $host;
$port = &$ct['Ports'][0];
$myIP = $myIP ?: $this->getTemplateValue($ct['Image'], 'MyIP') ?: ($ct['NetworkMode']=='host'||$port['NAT'] ? $host : ($port['IP'] ?: DockerUtil::myIP($ct['Name'])));
$WebUI = preg_replace("%\[IP\]%", $myIP, $this->getTemplateValue($ct['Image'], 'WebUI'));
// Get the WebUI address from the templates as a fallback
$WebUI = preg_replace("%\[IP\]%", $myIP, $WebUI ?: $this->getTemplateValue($ct['Image'], 'WebUI'));
if (preg_match("%\[PORT:(\d+)\]%", $WebUI, $matches)) {
$ConfigPort = $matches[1];
foreach ($ct['Ports'] as $port) {
@@ -306,13 +307,13 @@ class DockerTemplates {
}
if ($ct['Running']) {
$port = &$ct['Ports'][0];
$webui = $this->getTemplateValue($ct['Image'], 'WebUI');
$webui = $tmp['url'] ?: $this->getTemplateValue($ct['Image'], 'WebUI');
if (strlen($webui) > 0 && !preg_match("%\[(IP|PORT:(\d+))\]%", $webui)) {
// non-templated webui, user specified
$tmp['url'] = $webui;
} else {
$ip = ($ct['NetworkMode']=='host'||$port['NAT'] ? $host : $port['IP']);
$tmp['url'] = $ip ? (strpos($tmp['url'],$ip)!==false ? $tmp['url'] : $this->getControlURL($ct, $ip)) : $tmp['url'];
$tmp['url'] = $ip ? (strpos($tmp['url'],$ip)!==false ? $tmp['url'] : $this->getControlURL($ct, $ip, $tmp['url'])) : $tmp['url'];
}
$tmp['shell'] = $tmp['shell'] ?? $this->getTemplateValue($image, 'Shell');
}