Merge pull request #298 from bergware/master

Fixed regression error in plugin updates
This commit is contained in:
tom mortensen
2018-03-16 22:38:41 -07:00
committed by GitHub
9 changed files with 289 additions and 405 deletions

View File

@@ -381,8 +381,8 @@ function xmlToCommand($xml, $create_paths=false) {
global $var;
global $docroot;
$xml = xmlToVar($xml);
$cmdName = (strlen($xml['Name'])) ? '--name='.escapeshellarg($xml['Name']) : '';
$cmdPrivileged = (strtolower($xml['Privileged']) == 'true') ? '--privileged=true' : '';
$cmdName = strlen($xml['Name']) ? '--name='.escapeshellarg($xml['Name']) : '';
$cmdPrivileged = strtolower($xml['Privileged'])=='true' ? '--privileged=true' : '';
$cmdNetwork = '--net='.escapeshellarg(strtolower($xml['Network']));
$cmdMyIP = $xml['MyIP'] ? '--ip='.escapeshellarg($xml['MyIP']) : '';
$Volumes = [''];
@@ -434,9 +434,7 @@ function xmlToCommand($xml, $create_paths=false) {
$xml['ExtraParams'],
escapeshellarg($xml['Repository']),
$xml['PostArgs']);
$cmd = trim(preg_replace('/\s+/', ' ', $cmd));
return [$cmd, $xml['Name'], $xml['Repository']];
return [preg_replace('/\s+/', ' ', $cmd), $xml['Name'], $xml['Repository']];
}
function execCommand($command) {
@@ -532,11 +530,10 @@ function getUsedIPs() {
##
## CREATE CONTAINER
##
if (isset($_POST['contName'])) {
$postXML = postToXML($_POST, true);
$dry_run = ($_POST['dryRun'] == "true") ? true : false;
$dry_run = $_POST['dryRun']=='true' ? true : false;
$existing = $_POST['existingContainer'] ?? false;
$create_paths = $dry_run ? false : true;
// Get the command line
@@ -547,10 +544,8 @@ if (isset($_POST['contName'])) {
// Saving the generated configuration file.
$userTmplDir = $dockerManPaths['templates-user'];
if (!is_dir($userTmplDir)) {
mkdir($userTmplDir, 0777, true);
}
if (!empty($Name)) {
if (!is_dir($userTmplDir)) mkdir($userTmplDir, 0777, true);
if ($Name) {
$filename = sprintf('%s/my-%s.xml', $userTmplDir, $Name);
file_put_contents($filename, $postXML);
}
@@ -591,7 +586,6 @@ if (isset($_POST['contName'])) {
}
// Remove old container if renamed
$existing = isset($_POST['existingContainer']) ? $_POST['existingContainer'] : false;
if ($existing && $DockerClient->doesContainerExist($existing)) {
// determine if the container is still running
$oldContainerDetails = $DockerClient->getContainerDetails($existing);
@@ -605,6 +599,8 @@ if (isset($_POST['contName'])) {
// force kill container if still running after 10 seconds
removeContainer($existing);
// remove old template
@unlink("$userTmplDir/my-$existing.xml");
}
if ($startContainer) {

File diff suppressed because it is too large Load Diff

View File

@@ -53,9 +53,9 @@ foreach ($all_containers as $ct) {
$status = $ct['Running'] ? 'started':'stopped';
$icon = $info['icon'] ?: '/plugins/dynamix.docker.manager/images/question.png';
$ports = [];
if ($mode=='bridge') {
$binds = explode('|',exec("docker inspect --format='{{range \$p,\$c := .HostConfig.PortBindings}}{{\$p}}:{{(index \$c 0).HostPort}}|{{end}}' $name 2>/dev/null"));
$ip = exec("docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name 2>/dev/null");
$binds = explode('|',exec("docker inspect --format='{{range \$p,\$c := .HostConfig.PortBindings}}{{\$p}}:{{(index \$c 0).HostPort}}|{{end}}' $name 2>/dev/null"));
if (count($binds)>1) {
$ip = $ct['Running'] ? exec("docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name 2>/dev/null") : '0.0.0.0';
foreach ($binds as $bind) {
if (!$bind) continue;
list($container_port,$host_port) = explode(':',$bind);
@@ -63,7 +63,7 @@ foreach ($all_containers as $ct) {
}
} else {
$binds = explode('|',exec("docker inspect --format='{{range \$p,\$c := .Config.ExposedPorts}}{{\$p}}|{{end}}' $name 2>/dev/null"));
$ip = exec("docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name 2>/dev/null") ?: $eth0['IPADDR:0'];
$ip = $ct['Running'] ? (exec("docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name 2>/dev/null") ?: $eth0['IPADDR:0']) : '0.0.0.0';
foreach ($binds as $bind) {
if (!$bind) continue;
$ports[] = sprintf('%s:%s<i class="fa fa-arrows-h" style="margin:0 6px"></i>%s:%s',$ip, $bind, $ip, str_replace(['/tcp','/udp'],'',$bind));
@@ -113,15 +113,16 @@ foreach ($all_containers as $ct) {
}
foreach ($DockerClient->getDockerImages() as $image) {
if (count($image['usedBy'])) continue;
$menu[] = sprintf("addDockerImageContext('%s','%s');",$image['Id'],implode(', ',$image['Tags']));
$id = $image['Id'];
$menu[] = sprintf("addDockerImageContext('%s','%s');",$id,implode(',',$image['Tags']));
echo "<tr class='advanced'><td style='width:48px;padding:4px'>";
echo "<div id='context-{$image['Id']}' style='display:block;cursor:pointer'>";
echo "<div id='$id' style='display:block;cursor:pointer'>";
echo "<div style='position:relative;width:48px;height:48px;margin:0 auto'>";
echo "<img src='/webGui/images/disk.png' style='position:absolute;opacity:0.3;top:0;bottom:0;left:0;right:0;width:48px;height:48px'>";
echo "</div></div></td>";
echo "<td data-sort-value='ZZZZZZZZZZZ'><i>(orphan image)</i><div style='width:160px;'>Image ID: ".htmlspecialchars($image['Id'])."</div>";
if (strpos(implode($image['Tags']),"&lt;none&gt;:&lt;none&gt;")===false) echo "<div style='width:'160px'>".implode('<br>',array_map('htmlspecialchars',$image['Tags']))."</div>";
echo "</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
echo "<td><i>(orphan image)</i><div style='width:160px;'>Image ID: $id</div>";
echo "<div style='width:160px'>".implode('<br>',array_map('htmlspecialchars',$image['Tags']))."</div></td>";
echo "<td colspan=4'>&nbsp;</td>";
echo "<td><div class='advanced' style='width:124px'>Created ".htmlspecialchars($image['Created'])."</div></td></tr>";
}
echo "\0".implode($menu).implode($docker);

View File

@@ -37,7 +37,7 @@ function addDockerContainerContext(container, image, template, started, update,
function addDockerImageContext(image, imageTag) {
var opts = [{header:'(orphan image)'}];
opts.push({text:"Remove", icon:"fa-trash", action:function(e){e.preventDefault(); rmImage(image, imageTag);}});
context.attach('#context-'+image, opts);
context.attach('#'+image, opts);
}
function execUpContainer(container) {
var title = "Updating the container: "+container;
@@ -70,8 +70,7 @@ function popupWithIframe(title, cmd, reload, func) {
});
$(".ui-dialog .ui-dialog-titlebar").addClass("menu");
$(".ui-dialog .ui-dialog-title").css("text-align", "center").css("width", "100%");
$(".ui-dialog .ui-dialog-content").css("padding", "0");
//$('.ui-widget-overlay').click(function() {$("#iframe-popup").dialog("close");});
$(".ui-dialog .ui-dialog-content").css("padding", "12");
}
function addContainer() {
var path = location.pathname;
@@ -94,12 +93,13 @@ function updateContainer(container) {
showCancelButton:true,
confirmButtonColor:"#8CD4F5",
confirmButtonText:"Yes, update it!"
}, function() {
},function(){
execUpContainer(container);
});
}
function rmContainer(container, image, id) {
var body = "Remove container: "+container+"<br><br><label><input id=\"removeimagechk\" type=\"checkbox\" checked style=\"display:inline; width:unset; height:unset; margin-top:unset; margin-bottom:unset\">also remove image</label>";
$('input[type=button]').prop('disabled',true);
swal({
title:"Are you sure?",
text:body,
@@ -108,18 +108,19 @@ function rmContainer(container, image, id) {
showCancelButton:true,
confirmButtonColor:"#DD6B55",
confirmButtonText:"Yes, delete it!",
closeOnConfirm:false,
showLoaderOnConfirm:true
}, function() {
},function(){
$('#'+id).find('i').removeClass().addClass('iconstatus fa fa-trash orange-text');
if ($("#removeimagechk").prop('checked')) {
eventControl({action:"remove_all", container:id, image:image});
eventControl({action:"remove_all", container:id, image:image},'loadlist');
} else {
eventControl({action:"remove_container", container:id});
eventControl({action:"remove_container", container:id},'loadlist');
}
});
}
function rmImage(image, imageName) {
var body = "Remove image: "+$('<textarea />').html(imageName).text();
$('input[type=button]').prop('disabled',true);
swal({
title:"Are you sure?",
text:body,
@@ -127,32 +128,36 @@ function rmImage(image, imageName) {
showCancelButton:true,
confirmButtonColor:"#DD6B55",
confirmButtonText:"Yes, delete it!",
closeOnConfirm:false,
showLoaderOnConfirm:true
}, function() {
eventControl({action:"remove_image", image:image});
},function(){
$('#'+image).find('i').removeClass().addClass('iconstatus fa fa-trash orange-text');
eventControl({action:"remove_image", image:image},'loadlist');
});
}
function eventControl(params, reload) {
var spin = typeof reload != 'undefined';
function eventControl(params, spin) {
if (spin) $('#'+params['container']).find('i').addClass('fa-spin');
$.post(eventURL, params, function(data) {
if (data.success === true) {
if (spin) setTimeout(reload+'()',500); else location=window.location.href;
if (spin) setTimeout(spin+'()',500); else location=window.location.href;
} else {
swal({title:"Execution error", text:data.success, type:"error"});
swal({
title:"Execution error",
text:data.success, type:"error"
},function(){
if (spin) setTimeout(spin+'()',500); else location=window.location.href;
});
}
}, "json");
},'json');
}
function startAll() {
$('input[type=button]').prop('disabled',true);
for (var i=0,ct; ct=docker[i]; i++) if (ct.state=='false') $('#'+ct.id).find('i').addClass('fa-spin');
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'start'}, function(){loadlist();});
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'start'},function(){loadlist();});
}
function stopAll() {
$('input[type=button]').prop('disabled',true);
for (var i=0,ct; ct=docker[i]; i++) if (ct.state=='true') $('#'+ct.id).find('i').addClass('fa-spin');
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'stop'}, function(){loadlist();});
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'stop'},function(){loadlist();});
}
function checkAll() {
$('input[type=button]').prop('disabled',true);
@@ -169,7 +174,7 @@ function updateAll() {
function containerLogs(container, id) {
var height = 600;
var width = 900;
var run = eventURL+"?action=log&container="+id+"&title=Log for:"+container;
var run = eventURL+'?action=log&container='+id+'&title=Log for: '+container;
var top = (screen.height-height) / 2;
var left = (screen.width-width) / 2;
var options = 'resizeable=yes,scrollbars=yes,height='+height+',width='+width+',top='+top+',left='+left;

View File

@@ -6,8 +6,8 @@ Tabs="true"
Code="f1e6"
---
<?PHP
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, Bergware International.
/* Copyright 2005-2018, Lime Technology
* 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,
@@ -20,6 +20,7 @@ Code="f1e6"
<?
// Remove stale /tmp/plugin/*.plg entries
foreach (glob("/tmp/plugins/*.{plg,txt}", GLOB_NOSORT+GLOB_BRACE) as $entry) if (!file_exists("/var/log/plugins/".basename($entry))) @unlink($entry);
$check = $notify['version'] ? 0 : 1;
?>
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.filetree.css">
<style>#plugin_tree{width:33%;height:200px;overflow-y:scroll;}</style>
@@ -40,7 +41,7 @@ function resize(bind) {
}
<?endif;?>
function loadlist(id) {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{audit:id},function(data) {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{audit:id,check:<?=$check?>},function(data) {
if (id) {
var tmp = id.split(':');
var list = $('#plugin_list');
@@ -64,7 +65,7 @@ function loadlist(id) {
$(function() {
loadlist();
$('#plugin_tree').fileTree({root:'/boot/',filter:'plg'}, function(file) {$('#plugin_file').val(file);});
<?if (!$notify['version']):?>
<?if ($check):?>
$('.tabs').append("<span class='status vhshift'><input type='button' value='Check for Updates' onclick='openBox(\"/plugins/dynamix.plugin.manager/scripts/plugin&arg1=checkall\",\"Plugin Update Check\",490,430,true)'></span>");
<?endif;?>
});

View File

@@ -3,8 +3,8 @@ Title="Update OS"
Tag="thumbs-up"
---
<?PHP
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, Bergware International.
/* Copyright 2005-2018, Lime Technology
* 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,
@@ -17,6 +17,8 @@ Tag="thumbs-up"
<?
$empty = "<tr><td colspan='6' style='text-align:center;padding:24px'><i class='fa fa-circle-o-notch fa-spin fa-3x fa-fw'></i></td><tr>";
$version = $date = 'unknown';
$bzroot = file_exists('/boot/previous/bzroot');
$check = $notify['unraidos'] ? 0 : 1;
if (file_exists('/boot/previous/changes.txt')) {
exec("head -n4 /boot/previous/changes.txt",$rows);
@@ -48,7 +50,7 @@ function downgrade() {
$.get('/plugins/dynamix.plugin.manager/include/Downgrade.php',{version:'<?=$version?>'},function(){refresh();});
}
function loadlist(id) {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{system:'true',audit:id},function(data) {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{system:'true',audit:id,check:<?=$check?>},function(data) {
if (id) {
var tmp = id.split(':');
var tr = 'tr#'+tmp[0].replace(/[\. _]/g,'');
@@ -63,14 +65,14 @@ function loadlist(id) {
<?if (preg_match("/^\*\*(REBOOT REQUIRED|DOWNGRADE)/",@file_get_contents("$docroot/plugins/unRAIDServer/README.md",false,null,0,20))):?>
$('#change_branch').prop('disabled',true);
<?endif;?>
<?if (file_exists('/boot/previous/bzroot')):?>
<?if ($bzroot):?>
$('#previous').show();
<?endif;?>
});
}
$(function() {
loadlist();
<?if (!$notify['unraidos']):?>
<?if ($check):?>
$('.tabs').append("<span class='status vhshift'><input type='button' value='Check for Updates' onclick='openBox(\"/plugins/dynamix.plugin.manager/scripts/plugin&arg1=checkos\",\"Plugin Update Check\",490,430,true)'></span>");
<?endif;?>
});
@@ -79,7 +81,7 @@ $(function() {
<table class='tablesorter plugins shift' id='os_table'>
<thead><tr><th></th><th>Component</th><th>Author</th><th>Version</th><th>Status</th><th>Branch</th></tr></thead>
<tbody id="os_list"><?=$empty?></tbody>
<?if (file_exists('/boot/previous/bzroot')):?>
<?if ($bzroot):?>
<tbody id="previous" style="display:none"><tr><td><img src="/plugins/unRAIDServer/images/unRAIDServer.png"></td><td><b>unRAID Server OS (previous)</b></td><td>LimeTech</td><td><?=$version?></td><td><?=$date?></td><td><input type="button" value="Downgrade" onclick="downgrade()"></td></tbody>
<?endif;?>
</table>

View File

@@ -1,6 +1,6 @@
<?PHP
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, Bergware International.
/* Copyright 2005-2018, Lime Technology
* 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,
@@ -18,6 +18,7 @@ require_once "$docroot/plugins/dynamix.plugin.manager/include/PluginHelpers.php"
$system = $_GET['system'] ?? false;
$branch = $_GET['branch'] ?? false;
$audit = $_GET['audit'] ?? false;
$check = $_GET['check'] ?? false;
$empty = true;
$builtin = ['unRAIDServer'];
$plugins = "/var/log/plugins/*.plg";
@@ -41,7 +42,7 @@ foreach (glob($plugins,GLOB_NOSORT) as $plugin_link) {
//switch between system and custom plugins
if (($system && !$custom) || (!$system && $custom)) continue;
//forced plugin check?
$checked = check_plugin(basename($plugin_file));
$checked = (!$audit && !$check) ? check_plugin(basename($plugin_file)) : true;
//OS update?
$os = $system && $name==$builtin[0];
$toggle = false;

View File

@@ -1,13 +1,17 @@
function ajaxVMDispatch(params, reload){
var spin = typeof reload != 'undefined';
function ajaxVMDispatch(params, spin){
if (spin) $('#vm-'+params['uuid']).find('i').addClass('fa-spin');
$.post("/plugins/dynamix.vm.manager/include/VMajax.php", params, function(data) {
if (data.error) {
swal({title:"Execution error",text:data.error,type:"error"});
swal({
title:"Execution error",
text:data.error, type:"error"
},function(){
if (spin) setTimeout(spin+'()',500); else location=window.location.href;
});
} else {
if (spin) setTimeout(reload+'()',500); else location=window.location.href;
if (spin) setTimeout(spin+'()',500); else location=window.location.href;
}
}, "json");
},'json');
}
function addVMContext(name, uuid, template, state, vncurl, log){
var opts = [{header:name, image:"/plugins/dynamix.vm.manager/images/dynamix.vm.manager.png"}];
@@ -75,12 +79,28 @@ function addVMContext(name, uuid, template, state, vncurl, log){
opts.push({divider:true});
opts.push({text:"Remove VM", icon:"fa-minus", action:function(e) {
e.preventDefault();
swal({title:"Are you sure?",text:"Remove definition:"+name,type:"warning",showCancelButton:true},function(){ajaxVMDispatch({action:"domain-undefine",uuid:uuid});});
swal({
title:"Are you sure?",
text:"Remove definition:"+name,
type:"warning",
showCancelButton:true
},function(){
$('#vm-'+uuid).find('i').removeClass().addClass('iconstatus fa fa-trash orange-text');
ajaxVMDispatch({action:"domain-undefine",uuid:uuid}, "loadlist");
});
}});
if (template != 'OpenELEC') {
opts.push({text:"Remove VM & Disks", icon:"fa-trash", action:function(e) {
e.preventDefault();
swal({title:"Are you sure?",text:"Completely REMOVE "+name+" disk image and definition",type:"warning",showCancelButton:true},function(){ajaxVMDispatch({action:"domain-delete",uuid:uuid});});
swal({
title:"Are you sure?",
text:"Completely REMOVE "+name+" disk image and definition",
type:"warning",
showCancelButton:true
},function(){
$('#vm-'+uuid).find('i').removeClass().addClass('iconstatus fa fa-trash orange-text');
ajaxVMDispatch({action:"domain-delete",uuid:uuid}, "loadlist");
});
}});
}
}

View File

@@ -23,7 +23,6 @@ if (pgrep('dockerd')!==false && ($display=='icons' || $display=='docker')) {
$DockerClient = new DockerClient();
$DockerTemplates = new DockerTemplates();
$containers = $DockerClient->getDockerContainers() ?: [];
ksort($containers,SORT_NATURAL);
$Allinfo = $DockerTemplates->getAllInfo();
$menu = [];
foreach ($containers as $ct) {