Merge pull request #978 from bergware/master

VMs: automatically update virtio-win iso list
This commit is contained in:
tom mortensen
2021-11-06 07:56:07 -07:00
committed by GitHub
6 changed files with 36 additions and 33 deletions

View File

@@ -151,7 +151,7 @@ _(Enable Docker)_:
:docker_enable_help:
_(Docker Stop Timeout)_:
: <input class='narrow' id="DOCKER_TIMEOUT" type="number" name="DOCKER_TIMEOUT" min='1' value="<?=$dockercfg['DOCKER_TIMEOUT']?>">
: <input class='narrow' id="DOCKER_TIMEOUT" type="number" name="DOCKER_TIMEOUT" min='1' value="<?=$dockercfg['DOCKER_TIMEOUT']?>">_(seconds)_
:docker_timeout_help:
@@ -173,7 +173,7 @@ _(Docker vDisk size)_:
:docker_vdisk_size_help:
_(Docker vDisk location)_:
: <input id="DOCKER_IMAGE_FILE1" type="text" name="DOCKER_IMAGE_FILE1" value="<?=$dockercfg['DOCKER_IMAGE_FILE']?>" placeholder="e.g. /mnt/user/system/docker.img" data-pickcloseonfile="true" data-pickfilter="img" data-pickroot="/mnt" data-pickfolders="true" disabled required="required" pattern="^[^\\]*(docker-xfs\.img|docker\.img)$">
: <input type="text" id="DOCKER_IMAGE_FILE1" name="DOCKER_IMAGE_FILE1" autocomplete="off" value="<?=$dockercfg['DOCKER_IMAGE_FILE']?>" placeholder="_(e.g.)_ /mnt/user/system/docker.img" data-pickcloseonfile="true" data-pickfilter="img" data-pickroot="/mnt" data-pickfolders="true" disabled required pattern="^[^\\]*(docker-xfs\.img|docker\.img)$">
<span class="deleteLabel"><label><input type="checkbox" class="deleteCheckbox"> _(Delete vDisk file)_</label></span>
<?if ($var['fsState'] != "Started"):?><span><i class="fa fa-warning icon warning"></i> _(Modify with caution: unable to validate path until Array is Started)_</span>
<?elseif (!is_dir(dirname($dockercfg['DOCKER_IMAGE_FILE']))):?><span class="nonexist"><i class="fa fa-warning icon warning"></i> _(Path does not exist)_</span>
@@ -184,7 +184,7 @@ _(Docker vDisk location)_:
</div>
<div markdown="1" id="vdisk_dir" style="display:none">
_(Docker directory)_:
: <input id="DOCKER_IMAGE_FILE2" type="text" name="DOCKER_IMAGE_FILE2" value="<?=$dockercfg['DOCKER_IMAGE_FILE']?>" placeholder="e.g. /mnt/user/system/docker" data-pickcloseonfile="true" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="/mnt" data-pickfolders="true" disabled required="required" pattern="^[^\\]*/$">
: <input type="text" id="DOCKER_IMAGE_FILE2" name="DOCKER_IMAGE_FILE2" autocomplete="off" value="<?=$dockercfg['DOCKER_IMAGE_FILE']?>" placeholder="_(e.g.)_ /mnt/user/system/docker" data-pickcloseonfile="true" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="/mnt" data-pickfolders="true" disabled required pattern="^[^\\]*/$">
<span class="deleteLabel"><label><input type="checkbox" class="deleteCheckbox"> _(Delete directory)_</label></span>
<?if ($var['fsState'] != "Started"):?><span><i class="fa fa-warning icon warning"></i> _(Modify with caution: unable to validate path until Array is Started)_</span>
<?elseif (!is_dir(dirname($dockercfg['DOCKER_IMAGE_FILE']))):?><span class="nonexist"><i class="fa fa-warning icon warning"></i> _(Path does not exist)_</span>
@@ -194,7 +194,7 @@ _(Docker directory)_:
</div>
_(Default appdata storage location)_:
: <input id="DOCKER_APP_CONFIG_PATH" type="text" name="DOCKER_APP_CONFIG_PATH" value="<?=$dockercfg['DOCKER_APP_CONFIG_PATH']?>" placeholder="e.g. /mnt/user/appdata/" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="<?=is_dir('/mnt/user')?'/mnt/user':'/mnt'?>" data-pickfolders="true" pattern="^[^\\]*/$">
: <input type="text" id="DOCKER_APP_CONFIG_PATH" name="DOCKER_APP_CONFIG_PATH" autocomplete="off" value="<?=$dockercfg['DOCKER_APP_CONFIG_PATH']?>" placeholder="_(e.g.)_ /mnt/user/appdata/" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="<?=is_dir('/mnt/user')?'/mnt/user':'/mnt'?>" data-pickfolders="true" pattern="^[^\\]*/$">
<?if ($var['fsState'] != "Started"):?>
<span><i class="fa fa-warning icon warning"></i> _(Modify with caution: unable to validate path until Array is Started)_</span>
<?elseif (!is_dir($dockercfg['DOCKER_APP_CONFIG_PATH'])):?>

View File

@@ -21,7 +21,7 @@ require_once "$docroot/plugins/dynamix.docker.manager/include/DockerClient.php";
$DockerClient = new DockerClient();
$action = unscript($_REQUEST['action']??'');
$container = unscript($_REQUEST['container']??'');
$container = unbundle($_REQUEST['container']??'');
$name = unscript($_REQUEST['name']??'');
$image = unscript($_REQUEST['image']??'');
$arrResponse = ['error' => _('Missing parameters')];

View File

@@ -56,6 +56,7 @@ $pcie_acs_override = detect($syslinux, 'pcie_acs_override');
$vfio_allow_unsafe = detect($syslinux, 'allow_unsafe_interrupts');
$bgcolor = strstr('white,azure',$display['theme']) ? '#f2f2f2' : '#1c1c1c';
$started = $var['fsState']=='Started';
$libvirt_up = $libvirt_running=='yes';
?>
<link type="text/css" rel="stylesheet" href="<?autov('/webGui/styles/jquery.filetree.css')?>">
<link type="text/css" rel="stylesheet" href="<?autov('/webGui/styles/jquery.switchbutton.css')?>">
@@ -99,7 +100,7 @@ _(Enable VMs)_:
<?if ($hardware):?>
<div class="advanced" markdown="1">
<?if ($libvirt_running == 'yes'):?>
<?if ($libvirt_up):?>
<?$libvirt_info = libvirt_version('libvirt')?>
<?$qemu_info = $lv->get_connect_information()?>
_(Libvirt version)_:
@@ -115,12 +116,12 @@ _(Libvirt storage location)_:
<?else: /* Libvirt is stopped */ ?>
_(Libvirt vdisk size)_:
: <input id="IMAGE_SIZE" type="number" min="1" name="IMAGE_SIZE" value="<?=htmlspecialchars($domain_cfg['IMAGE_SIZE']);?>" style="width:50px;" required="required" />_(GB)_ <span id="SIZE_ERROR" class="errortext"></span>
: <input type="number" id="IMAGE_SIZE" name="IMAGE_SIZE" min="1" value="<?=htmlspecialchars($domain_cfg['IMAGE_SIZE']);?>" style="width:50px;" required="required" />_(GB)_ <span id="SIZE_ERROR" class="errortext"></span>
:vms_libvirt_vdisk_size_help:
_(Libvirt storage location)_:
: <input id="IMAGE_FILE" type="text" name="IMAGE_FILE" value="<?=htmlspecialchars($domain_cfg['IMAGE_FILE']);?>" placeholder="e.g. /mnt/user/system/libvirt/libvirt.img" data-pickcloseonfile="true" data-pickfilter="img" data-pickroot="/mnt" data-pickfolders="true" required pattern="^[^\\]*libvirt\.img$">
: <input type="text" id="IMAGE_FILE" name="IMAGE_FILE" autocomplete="off" value="<?=htmlspecialchars($domain_cfg['IMAGE_FILE']);?>" placeholder="e.g. /mnt/user/system/libvirt/libvirt.img" data-pickcloseonfile="true" data-pickfilter="img" data-pickroot="/mnt" data-pickfolders="true" required pattern="^[^\\]*libvirt\.img$">
<?if (file_exists($domain_cfg['IMAGE_FILE'])):?><span id="deletePanel"><label><input type="checkbox" id="deleteCheckbox" /> _(Delete Image File)_</label></span><?endif;?>
<?if (!$started):?><span><i class="fa fa-warning icon warning"></i> _(Modify with caution: unable to validate path until Array is Started)_</span>
<?elseif (!is_dir(dirname($domain_cfg['IMAGE_FILE']))):?><span><i class="fa fa-warning icon warning"></i> _(Path does not exist)_</span>
@@ -130,14 +131,14 @@ _(Libvirt storage location)_:
<?endif;?>
_(Default VM storage path)_:
: <input type="text" id="domaindir" data-pickfolders="true" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="<?=is_dir('/mnt/user')?'/mnt/user':'/mnt'?>" name="DOMAINDIR" value="<?=htmlspecialchars($domain_cfg['DOMAINDIR'])?>" placeholder="Click to Select" pattern="^[^\\]*/$">
: <input type="text" id="domaindir" name="DOMAINDIR" autocomplete="off" data-pickfolders="true" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="<?=is_dir('/mnt/user')?'/mnt/user':'/mnt'?>" value="<?=htmlspecialchars($domain_cfg['DOMAINDIR'])?>" placeholder="_(Click to Select)_" pattern="^[^\\]*/$">
<?if (!$started):?><span><i class="fa fa-warning icon warning"></i> _(Modify with caution: unable to validate path until Array is Started)_</span>
<?elseif (!is_dir($domain_cfg['DOMAINDIR'])):?><span><i class="fa fa-warning icon warning"></i> _(Path does not exist)_</span><?endif;?>
:vms_libvirt_storage_help:
_(Default ISO storage path)_:
: <input type="text" id="mediadir" data-pickfolders="true" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="<?=is_dir('/mnt/user')?'/mnt/user':'/mnt'?>" name="MEDIADIR" value="<?=htmlspecialchars($domain_cfg['MEDIADIR'])?>" placeholder="Click to Select" pattern="^[^\\]*/$">
: <input type="text" id="mediadir" name="MEDIADIR" autocomplete="off" data-pickfolders="true" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="<?=is_dir('/mnt/user')?'/mnt/user':'/mnt'?>" value="<?=htmlspecialchars($domain_cfg['MEDIADIR'])?>" placeholder="_(Click to Select)_" pattern="^[^\\]*/$">
<?if (!$started):?><span><i class="fa fa-warning icon warning"></i> _(Modify with caution: unable to validate path until Array is Started)_</span>
<?elseif (!is_dir($domain_cfg['MEDIADIR'])):?><span><i class="fa fa-warning icon warning"></i> _(Path does not exist)_</span><?endif;?>
@@ -209,7 +210,7 @@ _(VFIO allow unsafe interrupts)_:
<?endif;?>
<?if ($libvirt_running == 'yes' && trim(shell_exec('stat -c %T -f /etc/libvirt'))=='btrfs'):?>
<?if ($libvirt_up && trim(shell_exec('stat -c %T -f /etc/libvirt'))=='btrfs'):?>
<div class="advanced" markdown="1">
<div id="title"><span class="left"><i class="title fa fa-list"></i>_(Libvirt volume info)_</span></div>
_(btrfs filesystem show)_:
@@ -243,7 +244,7 @@ _(btrfs scrub status)_:
<?endif;?>
</div>
<?elseif ($libvirt_running != 'yes'):?>
<?elseif (!$libvirt_up):?>
<form id="removeForm" method="POST" action="/update.php" target="progressFrame">
<input type="hidden" name="#command" value="/plugins/dynamix.vm.manager/scripts/libvirt_rm">
</form>
@@ -254,7 +255,7 @@ _(btrfs scrub status)_:
<script src="<?autov('/plugins/dynamix.vm.manager/javascript/dynamix.vm.manager.js')?>"></script>
<script>
function prepareFS(form,cookie,value) {
if ($(form).find('input[type="submit"]').val()=='Cancel') $.removeCookie(cookie); else $.cookie(cookie,value);
if ($(form).find('input[type="submit"]').val()=="_(Cancel)_") $.removeCookie(cookie); else $.cookie(cookie,value);
}
function btrfsScrub(path) {
$.post('/webGui/include/FileSystemStatus.php',{cmd:'scrub',path:path},function(data) {
@@ -404,9 +405,9 @@ $(function(){
$("#IMAGE_FILE").fileTreeAttach(null, null, function(folder) {
$("#IMAGE_FILE").val(folder + 'libvirt.img').change();
});
$("#domaindir").fileTreeAttach();
$("#mediadir").fileTreeAttach();
$("#winvirtio").fileTreeAttach();
$('#domaindir').fileTreeAttach();
$('#mediadir').fileTreeAttach();
$('#winvirtio').fileTreeAttach();
<?endif;?>
if ($("#IMAGE_FILE").length) {
$("#IMAGE_FILE").on("input change", function(){
@@ -435,11 +436,11 @@ $(function(){
$("#hostshutdown").prop("disabled", checked);
$("#pcie_acs_override").prop("disabled", checked);
$("#vm_shutdown_timeout").prop("disabled", checked);
$("#applyBtn").val(checked ? "Delete" : "Apply").removeAttr('disabled');
$("#applyBtn").val(checked ? "_(Delete)_" : "_(Apply)_").removeAttr('disabled');
});
}
$.post("/plugins/dynamix.vm.manager/include/VMajax.php", {action:'reboot'}, function(data){
var rebootMessage = "VM Settings: A reboot is required to apply changes";
var rebootMessage = "_(VM Settings: A reboot is required to apply changes)_";
if (data.modified) addRebootNotice(rebootMessage); else removeRebootNotice(rebootMessage);
});
if ($.cookie('btrfs-scrub-vm')) btrfsScrub($.cookie('btrfs-scrub-vm'));

View File

@@ -36,8 +36,8 @@ if (count($isos)>1) {
$file = implode('-',$file);
$virtio_isos[$iso]['name'] = "$iso.iso";
$virtio_isos[$iso]['url'] = "$archive/$iso/$file.iso";
$virtio_isos[$iso]['size'] = 600*1024*1024; // assume 600 MB
$virtio_isos[$iso]['md5'] = ''; // unused md5
$virtio_isos[$iso]['size'] = 600*1024*1024; // assume 600 MB - adjusted once file is downloaded
$virtio_isos[$iso]['md5'] = ''; // unused md5 - created once file is downloaded
}
// sort with newest version first
uksort($virtio_isos,function($a,$b){return strnatcmp($b,$a);});

View File

@@ -422,17 +422,17 @@ case 'virtio-win-iso-download':
$arrDownloadVirtIO = $virtio_isos[$strKeyName];
}
if (empty($arrDownloadVirtIO)) {
$arrResponse = ['error' => 'Unknown version: '.$_REQUEST['download_version']];
$arrResponse = ['error' => _('Unknown version').': '.$_REQUEST['download_version']];
} elseif (empty($_REQUEST['download_path'])) {
$arrResponse = ['error' => 'Specify a ISO storage path first'];
$arrResponse = ['error' => _('Specify a ISO storage path first')];
} elseif (!is_dir($_REQUEST['download_path'])) {
$arrResponse = ['error' => 'ISO storage path doesn\'t exist, please create the user share (or empty folder) first'];
$arrResponse = ['error' => _("ISO storage path doesn't exist, please create the user share (or empty folder) first")];
} else {
@mkdir($_REQUEST['download_path'], 0777, true);
$_REQUEST['download_path'] = realpath($_REQUEST['download_path']).'/';
// Check free space
if (disk_free_space($_REQUEST['download_path']) < $arrDownloadVirtIO['size']+10000) {
$arrResponse['error'] = 'Not enough free space, need at least '.ceil($arrDownloadVirtIO['size']/1000000).'MB';
$arrResponse['error'] = _('Not enough free space, need at least').' '.ceil($arrDownloadVirtIO['size']/1000000).'MB';
break;
}
$boolCheckOnly = !empty($_REQUEST['checkonly']);
@@ -445,7 +445,7 @@ case 'virtio-win-iso-download':
// Save to /boot/config/domain.conf
$domain_cfg['MEDIADIR'] = $_REQUEST['download_path'];
$domain_cfg['VIRTIOISO'] = $strTargetFile;
$tmp = ''; $monitor = '/tmp/wget.monitor'; $dots = ' ... ';
$tmp = ''; $monitor = '/tmp/wget.monitor'; $dots = '... ';
foreach ($domain_cfg as $key => $value) $tmp .= "$key=\"$value\"\n";
file_put_contents($domain_cfgfile, $tmp);
$strDownloadCmd = 'wget -cO '.escapeshellarg($strTargetFile).' '.escapeshellarg($arrDownloadVirtIO['url']);
@@ -455,12 +455,11 @@ case 'virtio-win-iso-download':
$strCleanCmd = '(chmod 777 '.escapeshellarg($_REQUEST['download_path']).' '.escapeshellarg($strTargetFile).'; chown nobody:users '.escapeshellarg($_REQUEST['download_path']).' '.escapeshellarg($strTargetFile).'; rm -f '.escapeshellarg($strMD5File).' '.escapeshellarg($strMD5StatusFile).')';
//$strCleanPgrep = '-f "chmod.*chown.*rm.*'.$strMD5StatusFile.'"';
$strAllCmd = "#!/bin/bash\n\n";
$strAllCmd .= $strDownloadCmd.' >>'.escapeshellarg($strLogFile)." 2>$monitor && ";
$strAllCmd .= 'echo "'.$arrDownloadVirtIO['md5'].' '.$strTargetFile.'" >'.escapeshellarg($strMD5File).' && sleep 1 && ';
$strAllCmd .= $strVerifyCmd.' >'.escapeshellarg($strMD5StatusFile).' 2>/dev/null && sleep 2 && ';
$strAllCmd .= $strDownloadCmd.' >>'.escapeshellarg($strLogFile)." 2>$monitor && sleep 1 && ";
$strAllCmd .= 'echo "'.$arrDownloadVirtIO['md5'].' '.$strTargetFile.'" >'.escapeshellarg($strMD5File).' && sleep 3 && ';
$strAllCmd .= $strVerifyCmd.' >'.escapeshellarg($strMD5StatusFile).' 2>/dev/null && sleep 3 && ';
$strAllCmd .= $strCleanCmd.' >>'.escapeshellarg($strLogFile).' 2>&1 && ';
$strAllCmd .= 'rm -f '.escapeshellarg($strLogFile).' && ';
$strAllCmd .= 'rm -f '.escapeshellarg($strInstallScript);
$strAllCmd .= 'rm -f '.escapeshellarg($strLogFile).' '.escapeshellarg($strInstallScript).' '.escapeshellarg($monitor);
$arrResponse = [];
if (file_exists($strTargetFile)) {
if (!file_exists($strLogFile)) {
@@ -475,8 +474,9 @@ case 'virtio-win-iso-download':
}
} else {
if (pgrep($strDownloadPgrep, false)) {
// Get Download percent completed
$arrResponse['status'] = _('Downloading').$dots.exec("tail -2 $monitor|grep -Po '\d+%'");
// Get Download progress and eta
[$done,$eta] = my_explode(' ',exec("tail -2 $monitor|awk 'NF==9 {print \$7,\$9;exit}'"));
$arrResponse['status'] = _('Downloading').$dots.$done.',&nbsp;&nbsp;'._('ETA').': '.$eta;
} elseif (pgrep($strVerifyPgrep, false)) {
// Status = running md5 check
$arrResponse['status'] = _('Verifying').$dots;
@@ -513,13 +513,14 @@ case 'virtio-win-iso-download':
}
}
} elseif (!$boolCheckOnly) {
@unlink($monitor);
if (!pgrep($strInstallScriptPgrep, false)) {
// Run all commands
file_put_contents($strInstallScript, $strAllCmd);
chmod($strInstallScript, 0777);
exec($strInstallScript.' >/dev/null 2>&1 &');
}
$arrResponse['status'] = _('Downloading').$dots;
$arrResponse['status'] = _('Downloading').$dots.'0%';
}
$arrResponse['pid'] = pgrep($strInstallScriptPgrep, false);
}

View File

@@ -125,6 +125,7 @@ function updateTime() {
var days = parseInt(uptime/86400);
var hour = parseInt(uptime/3600%24);
var mins = parseInt(uptime/60%60);
$('span.uptime').html(((days|hour|mins)?plus(days,"<?=_('day')?>","<?=_('days')?>",(hour|mins)==0)+plus(hour,"<?=_('hour')?>","<?=_('hours')?>",mins==0)+plus(mins,"<?=_('minute')?>","<?=_('minutes')?>",true):"<?=_('less than a minute')?>"));
uptime += Math.round((now.getTime() - before.getTime())/1000);
before = now;
if (expiretime > 0) {