diff --git a/plugins/dynamix.docker.manager/DockerContainers.page b/plugins/dynamix.docker.manager/DockerContainers.page index 4a7cc4551..60f455f59 100644 --- a/plugins/dynamix.docker.manager/DockerContainers.page +++ b/plugins/dynamix.docker.manager/DockerContainers.page @@ -37,6 +37,7 @@ th.five{width:5%} th.eight{width:8%} th.load{width:100px} tbody > tr.sortable:hover{cursor:move} +input.wait{width:24px;margin:0 4px;padding:0 5px;border:none;box-shadow:none;background-color:transparent} @@ -75,11 +76,17 @@ function resetSorting() { $.post('/plugins/dynamix.docker.manager/include/UserPrefs.php',{reset:true},function(){loadlist();}); } function listview() { - if ($.cookie('docker_listview_mode')=='advanced') { + var more = $.cookie('docker_listview_mode')=='advanced'; + if (more) { $('.docker_readmore').readmore('destroy'); } else { $('.docker_readmore').readmore({maxHeight:32,moreLink:"",lessLink:""}); } + $('input.autostart').each(function(){ + var wait = $('#'+$(this).prop('id').replace('auto','wait')); + var auto = $(this).prop('checked'); + if (auto && more) wait.show(); else wait.hide(); + }); } var sortableHelper = function(e,i){ i.children().each(function(){ @@ -105,21 +112,28 @@ function loadlist() { $('.iconstatus').each(function(){ if ($(this).hasClass('stopped')) $('div.'+$(this).prop('id')).hide(); }); - $('.autostart').switchButton({labels_placement:"right"}); - $('.autostart').change(function() { - $.post( "/plugins/dynamix.docker.manager/include/UpdateConfig.php",{action:'autostart',container:$(this).attr('container'),response:'json'},function(data){$(this).prop('checked',data.autostart);},'json'); + $('.autostart').switchButton({labels_placement:'right'}); + $('.autostart').change(function(){ + var more = $.cookie('docker_listview_mode')=='advanced'; + var wait = $('#'+$(this).prop('id').replace('auto','wait')); + var auto = $(this).prop('checked'); + if (auto && more) wait.show(); else wait.hide(); + $.post('/plugins/dynamix.docker.manager/include/UpdateConfig.php',{action:'autostart',container:$(this).attr('container'),auto:auto,wait:wait.find('input.wait').val()}); + }); + $('input.wait').change(function(){ + $.post('/plugins/dynamix.docker.manager/include/UpdateConfig.php',{action:'wait',container:$(this).attr('container'),wait:$(this).val()}); }); if ($.cookie('docker_listview_mode')=='advanced') {$('.advanced').show(); $('.basic').hide();} - listview(); context.init({preventDoubleContext:false}); $('input[type=button]').prop('disabled',false).show('slow'); var update = false; for (var i=0,ct; ct=docker[i]; i++) if (ct.update=='false') {update = true; break;}; if (!update) $('input#updateAll').hide(); + listview(); }); } var watchDocker = new NchanSubscriber('/sub/dockerload', /^((?!chrome|android).)*safari/i.test(navigator.userAgent) ? {subscriber:'longpoll'} : {}); -watchDocker.on('message', function(data) { +watchDocker.on('message', function(data){ data = data.split('\n'); for (var i=0,row; row=data[i]; i++) { var id = row.split(' '); @@ -129,7 +143,7 @@ watchDocker.on('message', function(data) { }); $(function() { $('.advancedview').switchButton({labels_placement:'left', on_label:'Advanced View', off_label:'Basic View', checked:$.cookie('docker_listview_mode')=='advanced'}); - $('.advancedview').change(function() { + $('.advancedview').change(function(){ $('.advanced').toggle('slow'); $('.basic').toggle('slow'); $.cookie('docker_listview_mode',$('.advancedview').is(':checked')?'advanced':'basic',{expires:3650}); diff --git a/plugins/dynamix.docker.manager/include/DockerClient.php b/plugins/dynamix.docker.manager/include/DockerClient.php index 99720a2f9..b0962de31 100644 --- a/plugins/dynamix.docker.manager/include/DockerClient.php +++ b/plugins/dynamix.docker.manager/include/DockerClient.php @@ -38,6 +38,10 @@ $driver = DockerUtil::driver(); $docker_cfgfile = '/boot/config/docker.cfg'; $dockercfg = parse_ini_file($docker_cfgfile); +function var_split($item, $i=0) { + return explode(' ',$item)[$i]; +} + ####################################### ## DOCKERTEMPLATES CLASS ## ####################################### @@ -257,7 +261,7 @@ class DockerTemplates { $DockerUpdate = new DockerUpdate(); //$DockerUpdate->verbose = $this->verbose; $info = DockerUtil::loadJSON($dockerManPaths['webui-info']); - $autoStart = @file($dockerManPaths['autostart-file'], FILE_IGNORE_NEW_LINES) ?: []; + $autoStart = array_map('var_split', @file($dockerManPaths['autostart-file'], FILE_IGNORE_NEW_LINES) ?: []); foreach ($DockerClient->getDockerContainers() as $ct) { $name = $ct['Name']; $image = $ct['Image']; diff --git a/plugins/dynamix.docker.manager/include/DockerContainers.php b/plugins/dynamix.docker.manager/include/DockerContainers.php index 7852c6de2..37e6ff8a1 100644 --- a/plugins/dynamix.docker.manager/include/DockerContainers.php +++ b/plugins/dynamix.docker.manager/include/DockerContainers.php @@ -20,6 +20,7 @@ $DockerTemplates = new DockerTemplates(); $containers = $DockerClient->getDockerContainers(); $images = $DockerClient->getDockerImages(); $user_prefs = $dockerManPaths['user-prefs']; +$autostart_file = $dockerManPaths['autostart-file']; if (!$containers && !$images) { echo "No Docker containers installed"; @@ -39,6 +40,9 @@ $docker = ['var docker=[];']; $null = '0.0.0.0'; $menu = []; +$autostart = @file($autostart_file, FILE_IGNORE_NEW_LINES) ?: []; +$names = array_map('var_split', $autostart); + foreach ($containers as $ct) { $name = $ct['Name']; $id = $ct['Id']; @@ -57,6 +61,7 @@ foreach ($containers as $ct) { $shape = $running ? ($paused ? 'pause' : 'play') : 'square'; $status = $running ? ($paused ? 'paused' : 'started') : 'stopped'; $icon = $info['icon'] ?: '/plugins/dynamix.docker.manager/images/question.png'; + $wait = var_split($autostart[array_search($name,$names)],1); $ports = []; foreach ($ct['Ports'] as $port) { $intern = $running ? ($ct['NetworkMode']=='host' ? $host : $port['IP']) : $null; @@ -102,7 +107,8 @@ foreach ($containers as $ct) { echo "".implode('
',$paths)."
"; echo "
"; echo "
"; - echo ""; + echo ""; + echo ""; echo "
"; echo htmlspecialchars(str_replace('Up','Uptime',$ct['Status']))."
Created ".htmlspecialchars($ct['Created'])."
"; } diff --git a/plugins/dynamix.docker.manager/include/UpdateConfig.php b/plugins/dynamix.docker.manager/include/UpdateConfig.php index c1995dd6f..45946d0aa 100644 --- a/plugins/dynamix.docker.manager/include/UpdateConfig.php +++ b/plugins/dynamix.docker.manager/include/UpdateConfig.php @@ -17,46 +17,53 @@ 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']; - -// Update the start/stop configuration -if ($_POST['action'] == 'autostart' ){ - $json = ($_POST['response'] == 'json') ? true : false; - - if (!$json) readfile("$docroot/update.htm"); +$user_prefs = $dockerManPaths['user-prefs']; +switch ($_POST['action']) { +case 'autostart': + // update container autostart setting $container = urldecode(($_POST['container'])); - unset($_POST['container']); - - $allAutoStart = @file($autostart_file, FILE_IGNORE_NEW_LINES) ?: []; - $key = array_search($container, $allAutoStart); - if ($key===false) { - array_push($allAutoStart, $container); - if ($json) echo json_encode(['autostart' => true]); + $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($allAutoStart[$key]); - if ($json) echo json_encode(['autostart' => false]); + unset($autostart[$key]); } - // sort containers for start-up - if (file_exists($user_prefs)) { - $prefs = parse_ini_file($user_prefs); $sort = []; - foreach ($allAutoStart as $ct) $sort[] = array_search($ct,$prefs) ?? 999; - array_multisort($sort,SORT_NUMERIC,$allAutoStart); - } else { - natcasesort($allAutoStart); - } - $allAutoStart ? file_put_contents($autostart_file, implode(PHP_EOL, $allAutoStart).PHP_EOL) : @unlink($autostart_file); -} - -if ($_POST['#action'] == 'templates' ){ + 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'] )) { +if (isset($_GET['is_dir'])) { echo json_encode(['is_dir' => is_dir($_GET['is_dir'])]); } ?>