Files
webgui/plugins/dynamix.docker.manager/include/UpdateConfig.php
bergware 9c0cff4782 Added docker autostart wait period
- fixed autostart entries sometimes wrongly sorted
2018-08-05 13:34:46 +02:00

70 lines
2.4 KiB
PHP

<?PHP
/* Copyright 2005-2018, Lime Technology
* Copyright 2014-2018, Guilherme Jardim, Eric Schultz, Jon Panozzo.
* Copyright 2012-2018, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/plugins/dynamix.docker.manager/include/DockerClient.php";
$autostart_file = $dockerManPaths['autostart-file'];
$template_repos = $dockerManPaths['template-repos'];
$user_prefs = $dockerManPaths['user-prefs'];
switch ($_POST['action']) {
case 'autostart':
// update container autostart setting
$container = urldecode(($_POST['container']));
$wait = $_POST['wait'];
$item = rtrim("$container $wait");
$autostart = @file($autostart_file, FILE_IGNORE_NEW_LINES) ?: [];
$key = array_search($item, $autostart);
if ($_POST['auto']=='true') {
if ($key===false) $autostart[] = $item;
} else {
unset($autostart[$key]);
}
if ($autostart) {
if (file_exists($user_prefs)) {
$prefs = parse_ini_file($user_prefs); $sort = [];
foreach ($autostart as $ct) $sort[] = array_search(var_split($ct),$prefs) ?? 999;
array_multisort($sort,$autostart);
} else {
natcasesort($autostart);
}
file_put_contents($autostart_file, implode("\n", $autostart)."\n");
} else @unlink($autostart_file);
break;
case 'wait':
// update wait period used after container autostart
$container = urldecode(($_POST['container']));
$wait = $_POST['wait'];
$item = rtrim("$container $wait");
$autostart = file($autostart_file, FILE_IGNORE_NEW_LINES) ?: [];
$names = array_map('var_split', $autostart);
$autostart[array_search($container,$names)] = $item;
file_put_contents($autostart_file, implode("\n", $autostart)."\n");
break;
case 'templates':
// update template
readfile("$docroot/update.htm");
$repos = $_POST['template_repos'];
file_put_contents($template_repos, $repos);
$DockerTemplates = new DockerTemplates();
$DockerTemplates->downloadTemplates();
break;
}
if (isset($_GET['is_dir'])) {
echo json_encode(['is_dir' => is_dir($_GET['is_dir'])]);
}
?>