Skip to content
Merged
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
5 changes: 5 additions & 0 deletions emhttp/plugins/dynamix.docker.manager/AddContainer.page
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ if (substr($_SERVER['REQUEST_URI'],0,7) != '/Docker') {
$docker = "$docroot/languages/$locale/docker.dot";
if (file_exists($docker)) $language = array_merge($language,unserialize(file_get_contents($docker)));
}
// Avoid blocking other browser tabs by releasing the PHP session lock
// before running long-running container creation logic.
if (session_status() === PHP_SESSION_ACTIVE) {
session_write_close();
}
eval('?>'.parse_file("$docroot/plugins/dynamix.docker.manager/include/CreateDocker.php"));
?>
66 changes: 66 additions & 0 deletions emhttp/plugins/dynamix.docker.manager/include/CreateDocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,63 @@ function cpu_pinning() {
## CREATE CONTAINER ##
##########################

// Simple UI blocker used by create/update operations so the user can't keep clicking around mid-install.
function dockerUIBlockerScript($enable) {
if ($enable) {
echo <<<HTML
<script>
(function () {
try {
var d = (window.parent && window.parent.document) ? window.parent.document : document;
if (!d || !d.body) return;

// Define helpers once.
if (!window.parent) window.parent = window;
if (!window.parent.dockerUIBlock) {
window.parent.dockerUIBlock = function (on) {
try {
var doc = (window.parent && window.parent.document) ? window.parent.document : document;
if (!doc || !doc.body) return;

var blockerId = 'dockerInstallBlocker';
var blockerClass = 'docker-install-blocker';

if (!on) {
var o = doc.getElementById(blockerId);
if (o) o.remove();
return;
}

var o2 = doc.getElementById(blockerId);
if (!o2) {
o2 = doc.createElement('div');
o2.id = blockerId;
o2.className = blockerClass;
doc.body.appendChild(o2);
}
} catch (e) {}
};
}

window.parent.dockerUIBlock(true);
} catch (e) {}
})();
</script>
HTML;
} else {
echo <<<HTML
<script>
(function () {
try {
var w = window.parent || window;
if (w && w.dockerUIBlock) w.dockerUIBlock(false);
} catch (e) {}
})();
</script>
HTML;
}
}

if (isset($_POST['contName'])) {
$postXML = postToXML($_POST, true);
$dry_run = isset($_POST['dryRun']) && $_POST['dryRun']=='true';
Expand All @@ -76,6 +133,8 @@ function cpu_pinning() {
// Get the command line
[$cmd, $Name, $Repository] = xmlToCommand($postXML, $create_paths);
readfile("$docroot/plugins/dynamix.docker.manager/log.htm");
echo '<link type="text/css" rel="stylesheet" href="'.autov("/plugins/dynamix.docker.manager/sheets/AddContainer.css",true).'">';
if (!$dry_run) dockerUIBlockerScript(true);
@flush();
// Saving the generated configuration file.
$userTmplDir = $dockerManPaths['templates-user'];
Expand Down Expand Up @@ -114,6 +173,7 @@ function cpu_pinning() {
if (!$DockerClient->doesImageExist($Repository)) {
// Pull image
if (!pullImage($Name, $Repository)) {
dockerUIBlockerScript(false);
echo '<div style="text-align:center"><button type="button" onclick="done()">'._('Done').'</button></div><br>';
goto END;
}
Expand Down Expand Up @@ -166,6 +226,7 @@ function cpu_pinning() {
execCommand($cmd);
if ($startContainer) addRoute($Name); // add route for remote WireGuard access

dockerUIBlockerScript(false);
echo '<div style="text-align:center"><button type="button" onclick="openTerminal(\'docker\',\''.addslashes($Name).'\',\'.log\')">'._('View Container Log').'</button> <button type="button" onclick="done()">'._('Done').'</button></div><br>';
goto END;
}
Expand All @@ -178,6 +239,8 @@ function cpu_pinning() {
$echo = empty($_GET['mute']);
if ($echo) {
readfile("$docroot/plugins/dynamix.docker.manager/log.htm");
echo '<link type="text/css" rel="stylesheet" href="'.autov("/plugins/dynamix.docker.manager/sheets/AddContainer.css",true).'">';
dockerUIBlockerScript(true);
@flush();
}
foreach ($_GET['ct'] as $value) {
Expand Down Expand Up @@ -245,6 +308,9 @@ function cpu_pinning() {
// remove old orphan image since it's no longer used by this container
if ($oldImageID && $oldImageID != $newImageID) removeImage($oldImageID, $echo);
}
if ($echo) {
dockerUIBlockerScript(false);
}
echo '<div style="text-align:center"><button type="button" onclick="window.parent.jQuery(\'#iframe-popup\').dialog(\'close\')">'._('Done').'</button></div><br>';
goto END;
}
Expand Down
7 changes: 7 additions & 0 deletions emhttp/plugins/dynamix.docker.manager/sheets/AddContainer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* Only used for the UI blocker during long-running create/update operations */
.docker-install-blocker {
position: fixed;
inset: 0;
z-index: 2147483647;
cursor: wait;
}
Loading