Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ function dockerUIBlockerScript($enable) {
if (is_file($filename)) {
$oldXML = simplexml_load_file($filename);
if ($oldXML->Icon != $_POST['contIcon']) {
if (!strpos($Repository,":")) $Repository .= ":latest";
$iconPath = $DockerTemplates->getIcon($Repository,$Name);
@unlink("$docroot/$iconPath");
@unlink("{$dockerManPaths['images']}/".basename($iconPath));
$DockerTemplates->purgeUnusedIconFiles($Name);
}
}
file_put_contents($filename, $postXML);
Expand Down
74 changes: 66 additions & 8 deletions emhttp/plugins/dynamix.docker.manager/include/DockerClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,25 @@ public function getAllInfo($reload=false,$com=true,$communityApplications=false)
// looking for a match. Bad.
$labelIconUrl = $ct['Icon'] ?? null;
if (!$communityApplications) {
$isDockerman = ($ct['Manager'] ?? '') === 'dockerman';
$preferLabelIcon = !empty($labelIconUrl) && !$isDockerman;
$labelIconChanged = $preferLabelIcon
&& ($tmp['icon-url'] ?? '') !== $labelIconUrl;
$labelIconRemoved = !$isDockerman && !empty($tmp['icon-url']) && empty($labelIconUrl);
$iconExists = !empty($tmp['icon'])
&& (is_file($tmp['icon']) || is_file($docroot . $tmp['icon']));
if (!$iconExists || $reload) {
$tmp['icon'] = $this->getIcon($image, $name, $labelIconUrl ?: ($tmp['icon'] ?? ''));
if ($labelIconRemoved) {
$this->purgeUnusedIconFiles($name);
$tmp['icon'] = '/plugins/dynamix.docker.manager/images/question.png';
unset($tmp['icon-url']);
} elseif (!$iconExists || $reload || $labelIconChanged) {
$tmp['icon'] = $this->getIcon($image, $name, $labelIconUrl ?: ($tmp['icon'] ?? ''), $preferLabelIcon);
if ($preferLabelIcon) $tmp['icon-url'] = $labelIconUrl;
// Explicitly return the fallback asset, so that subsequent polls see
// the local file instead of rerunning the expensive template scan
if (empty($tmp['icon'])) $tmp['icon'] = '/plugins/dynamix.docker.manager/images/question.png';
} elseif (!$preferLabelIcon) {
unset($tmp['icon-url']);
}
Comment on lines +340 to 359

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for how $tmp['icon'] is used elsewhere to understand the expected value type
rg -n -C3 "\\\$tmp\['icon'\]" --type=php

Repository: unraid/webgui

Length of output: 2279


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="emhttp/plugins/dynamix.docker.manager/include/DockerClient.php"

# Show getIcon signature + body
rg -n "function\s+getIcon\s*\(" -n "$FILE" && \
  awk 'NR>=440 && NR<=520 {print NR ":" $0}' "$FILE"

# Find all getIcon calls and context
rg -n "->getIcon\(" "$FILE" && \
  rg -n -C3 "->getIcon\(" "$FILE"

# Inspect purgeUnusedIconFiles for the glob/pattern logic mentioned
rg -n "function\s+purgeUnusedIconFiles\s*\(" "$FILE" && \
  awk 'NR>=480 && NR<=540 {print NR ":" $0}' "$FILE"

Repository: unraid/webgui

Length of output: 5516


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="emhttp/plugins/dynamix.docker.manager/include/DockerClient.php"

# Inspect download_url implementation
rg -n "function\s+download_url\s*\(" "$FILE" && \
  awk 'NR>=520 && NR<=620 {print NR ":" $0}' "$FILE"

# Find where $tmp['icon-url'] is assigned/used in this function/file
rg -n "\$tmp\['icon-url'\]" "$FILE" -S && \
  rg -n -C3 "\$tmp\['icon-url'\]" "$FILE" -S

# Show getAllInfo context around the snippet lines (330-370)
awk 'NR>=320 && NR<=370 {print NR ":" $0}' "$FILE"

Repository: unraid/webgui

Length of output: 7440


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="emhttp/plugins/dynamix.docker.manager/include/DockerClient.php"

# Show all assignments/usages of tmp['icon'] in this file
rg -n "\$tmp\['icon'\]" "$FILE"

# Show all assignments/usages of tmp['icon-url'] in this file
rg -n "\$tmp\['icon-url'\]" "$FILE"

# Locate any place where $tmp is persisted (webui-info) and might already contain icon/icon-url
rg -n "webui-info|DockerUtil::saveJSON|DockerUtil::loadJSON" "$FILE"

# Inspect how icons are stored/updated around getAllInfo
rg -n "getAllInfo|getAllInfo\(" "$FILE" && \
  awk 'NR>=300 && NR<=420 {print NR ":" $0}' "$FILE"

Repository: unraid/webgui

Length of output: 39


🏁 Script executed:

#!/bin/bash
set +e
FILE="emhttp/plugins/dynamix.docker.manager/include/DockerClient.php"

echo "== tmp['icon'] occurrences =="
rg -n "\$tmp\['icon'\]" "$FILE" || true

echo "== tmp['icon-url'] occurrences =="
rg -n "\$tmp\['icon-url'\]" "$FILE" || true

echo "== webui-info persistence =="
rg -n "webui-info|DockerUtil::saveJSON|DockerUtil::loadJSON" "$FILE" || true

echo "== getAllInfo region =="
rg -n "getAllInfo|getAllInfo\(" "$FILE" || true
awk 'NR>=260 && NR<=390 {print NR ":" $0}' "$FILE"

Repository: unraid/webgui

Length of output: 7676


Fix icon fallback: don’t pass $tmp['icon'] (local file path) into getIcon() as $iconUrl

DockerClient::getAllInfo() calls getIcon(..., $labelIconUrl ?: ($tmp['icon'] ?? ''), ...). When Icon label URL is empty and the template icon is also empty, getIcon() uses that 3rd argument as $imgUrl and passes it to download_url(). If it’s a filesystem path (from $tmp['icon']), the download will fail and icon resolution will fall back to the question image.

Suggested fix
-				$tmp['icon'] = $this->getIcon($image, $name, $labelIconUrl ?: ($tmp['icon'] ?? ''), $preferLabelIcon);
+				$tmp['icon'] = $this->getIcon($image, $name, $labelIconUrl ?: ($tmp['icon-url'] ?? ''), $preferLabelIcon);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$isDockerman = ($ct['Manager'] ?? '') === 'dockerman';
$preferLabelIcon = !empty($labelIconUrl) && !$isDockerman;
$labelIconChanged = $preferLabelIcon
&& ($tmp['icon-url'] ?? '') !== $labelIconUrl;
$labelIconRemoved = !$isDockerman && !empty($tmp['icon-url']) && empty($labelIconUrl);
$iconExists = !empty($tmp['icon'])
&& (is_file($tmp['icon']) || is_file($docroot . $tmp['icon']));
if (!$iconExists || $reload) {
$tmp['icon'] = $this->getIcon($image, $name, $labelIconUrl ?: ($tmp['icon'] ?? ''));
if ($labelIconRemoved) {
$this->purgeUnusedIconFiles($name);
$tmp['icon'] = '/plugins/dynamix.docker.manager/images/question.png';
unset($tmp['icon-url']);
} elseif (!$iconExists || $reload || $labelIconChanged) {
$tmp['icon'] = $this->getIcon($image, $name, $labelIconUrl ?: ($tmp['icon'] ?? ''), $preferLabelIcon);
if ($preferLabelIcon) $tmp['icon-url'] = $labelIconUrl;
// Explicitly return the fallback asset, so that subsequent polls see
// the local file instead of rerunning the expensive template scan
if (empty($tmp['icon'])) $tmp['icon'] = '/plugins/dynamix.docker.manager/images/question.png';
} elseif (!$preferLabelIcon) {
unset($tmp['icon-url']);
}
$isDockerman = ($ct['Manager'] ?? '') === 'dockerman';
$preferLabelIcon = !empty($labelIconUrl) && !$isDockerman;
$labelIconChanged = $preferLabelIcon
&& ($tmp['icon-url'] ?? '') !== $labelIconUrl;
$labelIconRemoved = !$isDockerman && !empty($tmp['icon-url']) && empty($labelIconUrl);
$iconExists = !empty($tmp['icon'])
&& (is_file($tmp['icon']) || is_file($docroot . $tmp['icon']));
if ($labelIconRemoved) {
$this->purgeUnusedIconFiles($name);
$tmp['icon'] = '/plugins/dynamix.docker.manager/images/question.png';
unset($tmp['icon-url']);
} elseif (!$iconExists || $reload || $labelIconChanged) {
$tmp['icon'] = $this->getIcon($image, $name, $labelIconUrl ?: ($tmp['icon-url'] ?? ''), $preferLabelIcon);
if ($preferLabelIcon) $tmp['icon-url'] = $labelIconUrl;
// Explicitly return the fallback asset, so that subsequent polls see
// the local file instead of rerunning the expensive template scan
if (empty($tmp['icon'])) $tmp['icon'] = '/plugins/dynamix.docker.manager/images/question.png';
} elseif (!$preferLabelIcon) {
unset($tmp['icon-url']);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@emhttp/plugins/dynamix.docker.manager/include/DockerClient.php` around lines
340 - 359, DockerClient::getAllInfo() currently calls getIcon($image, $name,
$labelIconUrl ?: ($tmp['icon'] ?? ''), $preferLabelIcon) which can pass a local
filesystem path (from $tmp['icon']) into getIcon() as $imgUrl so download_url()
tries to fetch it and fails; change the third argument so we never forward a
local file path — pass $labelIconUrl if non-empty, otherwise pass an empty
string (e.g. $labelIconUrl ?: '') when calling getIcon(), leaving local
$tmp['icon'] untouched; ensure $preferLabelIcon logic and the subsequent
assignment of $tmp['icon-url'] and fallback question.png behavior remain the
same.

}
if ($ct['Running']) {
Expand Down Expand Up @@ -430,14 +442,28 @@ public function getAllInfo($reload=false,$com=true,$communityApplications=false)
return $info;
}

public function getIcon($Repository,$contName,$tmpIconUrl='') {
private function getIconFile($imgUrl) {
return sprintf('%s-%s.png', 'icon', sha1($imgUrl));
}

private function getIconRamPath($contName, $imgUrl) {
global $dockerManPaths;
return sprintf('%s/%s-%s', $dockerManPaths['images-ram'], $contName, $this->getIconFile($imgUrl));
}

public function getIcon($Repository,$contName,$iconUrl='',$preferIconUrl=false) {
global $docroot, $dockerManPaths;
$imgUrl = $this->getTemplateValue($Repository, 'Icon','all',$contName);
if (!$imgUrl) $imgUrl = $tmpIconUrl;
if ($preferIconUrl) {
$imgUrl = $iconUrl ?: $this->getTemplateValue($Repository, 'Icon','all',$contName);
} else {
$imgUrl = $this->getTemplateValue($Repository, 'Icon','all',$contName);
if (!$imgUrl) $imgUrl = $iconUrl;
}
if (!$imgUrl || trim($imgUrl) == "/plugins/dynamix.docker.manager/images/question.png") return '';

$iconRAM = sprintf('%s/%s-%s.png', $dockerManPaths['images-ram'], $contName, 'icon');
$icon = sprintf('%s/%s-%s.png', $dockerManPaths['images'], $contName, 'icon');
$iconFile = $this->getIconFile($imgUrl);
$iconRAM = $this->getIconRamPath($contName, $imgUrl);
$icon = sprintf('%s/%s', $dockerManPaths['images'], $iconFile);

if (!is_dir(dirname($iconRAM))) mkdir(dirname($iconRAM), 0755, true);
if (!is_dir(dirname($icon))) mkdir(dirname($icon), 0755, true);
Expand All @@ -447,14 +473,46 @@ public function getIcon($Repository,$contName,$tmpIconUrl='') {
@copy($icon, $iconRAM);
}
if (!is_file($icon) && is_file($iconRAM)) {
@copy($iconRAM,$icon);
@copy($iconRAM, $icon);
}
if (!is_file($iconRAM)) {
my_logger("$contName: Could not download icon $imgUrl");
}
else {
$this->purgeUnusedIconFiles($contName, $iconFile);
}

return (is_file($iconRAM)) ? str_replace($docroot, '', $iconRAM) : '';
}

public function purgeUnusedIconFiles($contName, $keepIcon='') {
global $docroot, $dockerManPaths;

$icon_glob = sprintf('%s/%s-*.png', $dockerManPaths['images-ram'], $contName);
$ramFiles = glob($icon_glob);
foreach ($ramFiles as $filename) {
if ( ($keepIcon === '') || !(strpos($filename, $keepIcon) !== false) ) {
@unlink($filename);
}
}

$icon_glob = sprintf('%s/%s*.png', $dockerManPaths['images'], $contName);
foreach (glob($icon_glob) as $filename) {
if ( ($keepIcon === '') || !(strpos($filename, $keepIcon) !== false) ) {
@unlink($filename);
}
}

foreach ($ramFiles as $ramFile) {
if ( strpos($ramFile, '-icon-') !== false ) {
$suffix = substr($ramFile, strrpos($ramFile, '-icon-') + 6);
if ( $suffix && !glob($dockerManPaths['images-ram'].'/*icon-'.$suffix) ) {
$filename = sprintf('%s/icon-%s', $dockerManPaths['images'], $suffix);
@unlink($filename);
}
}
}
}
}

####################################
Expand Down
Loading