mirror of
https://github.com/unraid/webgui.git
synced 2026-01-03 16:14:54 -06:00
603 lines
23 KiB
Plaintext
603 lines
23 KiB
Plaintext
Menu="OtherSettings"
|
|
Title="VM Manager"
|
|
Icon="icon-virtualization"
|
|
Tag="columns"
|
|
---
|
|
<?php
|
|
/* Copyright 2005-2025, Lime Technology
|
|
* Copyright 2012-2025, Bergware International.
|
|
* Copyright 2015-2021, Derek Macias, Eric Schultz, Jon Panozzo.
|
|
*
|
|
* 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.
|
|
*/
|
|
?>
|
|
<?php
|
|
require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt_helpers.php";
|
|
|
|
// Check for Intel VT-x (vmx) or AMD-V (svm) cpu virtualization support
|
|
// If either kvm_intel or kvm_amd are loaded then Intel VT-x (vmx) or AMD-V (svm) cpu virtualization support was found
|
|
$hardware = !empty(shell_exec("/etc/rc.d/rc.libvirt test"));
|
|
if (!$hardware) {
|
|
echo "<p class='notice'>"._('Your hardware does not have Intel VT-x or AMD-V capability').". "._('This is required to create VMs in KVM').". "._('Please disable the VM function').". ";
|
|
echo "<a href='https://docs.unraid.net/go/determining-hvmiommu-hardware-support/' target='_blank'> "._('View the Docs for more information')."</a></p>";
|
|
}
|
|
|
|
function scan($area, $text)
|
|
{
|
|
return strpos($area, $text) !== false;
|
|
}
|
|
function detect(&$bootcfg, $bootenv, $key)
|
|
{
|
|
if ($bootenv === 'syslinux') {
|
|
$size = count($bootcfg);
|
|
$menu = $i = 0;
|
|
$value = '';
|
|
// find the default section
|
|
while ($i < $size) {
|
|
if (scan($bootcfg[$i], 'label ')) {
|
|
$n = $i + 1;
|
|
// find the current requested setting
|
|
while (!scan($bootcfg[$n], 'label ') && $n < $size) {
|
|
if (scan($bootcfg[$n], 'menu default')) {
|
|
$menu = 1;
|
|
}
|
|
if (scan($bootcfg[$n], 'append')) {
|
|
foreach (explode(' ', $bootcfg[$n]) as $cmd) {
|
|
if (scan($cmd, $key)) {
|
|
$value = explode('=', $cmd)[1];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$n++;
|
|
}
|
|
if ($menu) {
|
|
break;
|
|
} else {
|
|
$i = $n - 1;
|
|
}
|
|
}
|
|
$i++;
|
|
}
|
|
} elseif ($bootenv === 'grub') {
|
|
$menu_entries = [];
|
|
// find the current boot entry
|
|
foreach ($bootcfg as $line) {
|
|
if (preg_match('/set default=(\d+)/', $line, $match)) {
|
|
$bootentry = (int)$match[1];
|
|
break;
|
|
}
|
|
}
|
|
// split boot entries
|
|
foreach ($bootcfg as $line) {
|
|
if (strpos($line, 'menuentry ') === 0) {
|
|
$in_menuentry = true;
|
|
$current_entry = $line . "\n";
|
|
} elseif ($in_menuentry) {
|
|
$current_entry .= $line . "\n";
|
|
if (trim($line) === "}") {
|
|
$menu_entries[] = $current_entry;
|
|
$in_menuentry = false;
|
|
}
|
|
}
|
|
}
|
|
// search in selected menuentry
|
|
$menuentry = explode("\n", $menu_entries[$bootentry]);
|
|
foreach (explode(' ', $menu_entries[$bootentry]) as $cmd) {
|
|
if (scan($cmd, $key)) {
|
|
$value = explode('=', $cmd)[1];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return trim($value);
|
|
}
|
|
if (is_file('/boot/syslinux/syslinux.cfg')) {
|
|
$bootcfg = file('/boot/syslinux/syslinux.cfg', FILE_IGNORE_NEW_LINES + FILE_SKIP_EMPTY_LINES);
|
|
$bootenv = 'syslinux';
|
|
} elseif (is_file('/boot/grub/grub.cfg')) {
|
|
$bootcfg = file('/boot/grub/grub.cfg', FILE_IGNORE_NEW_LINES + FILE_SKIP_EMPTY_LINES);
|
|
$bootenv = 'grub';
|
|
}
|
|
$arrValidNetworks = getValidNetworks();
|
|
$pcie_acs_override = detect($bootcfg, $bootenv, 'pcie_acs_override');
|
|
$vfio_allow_unsafe = detect($bootcfg, $bootenv, 'allow_unsafe_interrupts');
|
|
$bgcolor = $themeHelper->isLightTheme() ? '#f2f2f2' : '#1c1c1c'; // $themeHelper set in DefaultPageLayout.php
|
|
$started = $var['fsState'] == 'Started';
|
|
$libvirt_up = $libvirt_running == 'yes';
|
|
$libvirt_log = file_exists("/var/log/libvirt/libvirtd.log");
|
|
?>
|
|
<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')?>">
|
|
|
|
<?if ($hardware):?>
|
|
|
|
: <span><input type="checkbox" class="advancedview"></span>
|
|
<?endif;?>
|
|
<form markdown="1" id="settingsForm" method="POST" action="/update.php" target="progressFrame" onsubmit="return validateFormOnSubmit();">
|
|
<input type="hidden" name="#file" value="<?=htmlspecialchars($domain_cfgfile)?>">
|
|
<input type="hidden" name="#command" value="/plugins/dynamix/scripts/emcmd">
|
|
<input type="hidden" name="#arg[1]" value="cmdStatus=Apply">
|
|
|
|
_(Enable VMs)_:
|
|
: <select id="SERVICE" name="SERVICE">
|
|
<?= mk_option($libvirt_service, 'disable', _('No'))?>
|
|
<?= mk_option($libvirt_service, 'enable', _('Yes'))?>
|
|
</select>
|
|
<?if ($hardware):?>
|
|
<?if (!$started):?>
|
|
<span id="arraystopped"><i class="fa fa-warning icon warning"></i> <?=($libvirt_service == 'enable') ? '_(VMs will be available after Array is Started)_' : '_(Apply to activate VMs after Array is Started)_'?></span>
|
|
<?endif;?>
|
|
<?endif;?>
|
|
|
|
:vms_enable_help:
|
|
|
|
_(Disable Autostart/Start option for VMs)_:
|
|
: <select id="DISABLE" name="DISABLE">
|
|
<?= mk_option(htmlspecialchars($domain_cfg['DISABLE']), 'no', _('No'))?>
|
|
<?= mk_option(htmlspecialchars($domain_cfg['DISABLE']), 'yes', _('Yes'))?>
|
|
</select>
|
|
|
|
:vms_disable_help:
|
|
|
|
<?if ($hardware):?>
|
|
<div class="advanced" markdown="1">
|
|
<?if ($libvirt_up):?>
|
|
<?$libvirt_info = libvirt_version('libvirt')?>
|
|
<?$qemu_info = $lv->get_connect_information()?>
|
|
_(Libvirt version)_:
|
|
: <?=$libvirt_info['libvirt.major'].'.'.$libvirt_info['libvirt.minor'].'.'.$libvirt_info['libvirt.release']?>
|
|
|
|
_(QEMU version)_:
|
|
: <?=$qemu_info['hypervisor_major'].'.'.$qemu_info['hypervisor_minor'].'.'.$qemu_info['hypervisor_release']?>
|
|
|
|
_(Libvirt storage location)_:
|
|
: <?=htmlspecialchars($domain_cfg['IMAGE_FILE'])?>
|
|
|
|
:vms_libvirt_volume_help:
|
|
|
|
<?else: /* Libvirt is stopped */ ?>
|
|
_(Libvirt vdisk size)_ (_(GB)_):
|
|
: <input type="number" id="IMAGE_SIZE" name="IMAGE_SIZE" min="1" value="<?=htmlspecialchars($domain_cfg['IMAGE_SIZE']);?>" required="required" /><span id="SIZE_ERROR" class="errortext"></span>
|
|
|
|
:vms_libvirt_vdisk_size_help:
|
|
|
|
_(Libvirt storage location)_:
|
|
: <input type="text" id="IMAGE_FILE" name="IMAGE_FILE" autocomplete="off" spellcheck="false" 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>
|
|
<?endif;?>
|
|
<span id="IMAGE_ERROR" class="errortext"></span>
|
|
|
|
:vms_libvirt_location_help:
|
|
|
|
<?endif;?>
|
|
_(Default VM storage path)_:
|
|
: <input type="text" id="domaindir" name="DOMAINDIR" autocomplete="off" spellcheck="false" data-pickfolders="true" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="/mnt" value="<?=htmlspecialchars($domain_cfg['DOMAINDIR'])?>" placeholder="_(Click to Select)_" pattern="^[^\\]*/$" onchange="validatePath(this)">
|
|
<?if (!$started):?>
|
|
<span><i class="fa fa-warning icon warning"></i> _(Modify with caution: unable to validate path until Array is Started)_</span>
|
|
<?endif;?>
|
|
|
|
:vms_libvirt_storage_help:
|
|
|
|
_(Default ISO storage path)_:
|
|
: <input type="text" id="mediadir" name="MEDIADIR" autocomplete="off" spellcheck="false" 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>
|
|
<?endif;?>
|
|
|
|
:vms_libvirt_iso_storage_help:
|
|
|
|
</div>
|
|
_(Default Windows VirtIO driver ISO)_ (_(optional)_):
|
|
: <select id="winvirtio_select" class="lock" disabled></select><input type="text" id="winvirtio" name="VIRTIOISO" data-pickfilter="iso" data-pickcloseonfile="true" data-pickroot="<?=is_dir('/mnt/user') ? '/mnt/user' : '/mnt'?>" value="<?=htmlspecialchars($domain_cfg['VIRTIOISO'])?>"<?if ($started):?> placeholder="_(Click to Select)_" pattern="^[^\\]*\.(iso|ISO)$"<?endif;?>>
|
|
<?if ($started):?>
|
|
<i class="fa fa-trash fa-fw" id="remove_button" title="_(Remove Windows VirtIO driver ISO)_"><span> _(Remove)_</span></i><i class="fa fa-download fa-fw" id="download_button" title="_(Download Windows VirtIO driver ISO)_"><span> _(Download)_</span></i><span id="download_status"></span>
|
|
<?endif;?>
|
|
|
|
:vms_virtio_driver_help:
|
|
|
|
<div class="advanced" markdown="1">
|
|
_(Default network source)_:
|
|
: <select id="network" name="BRNAME">
|
|
<?foreach (array_keys($arrValidNetworks) as $key) {
|
|
echo mk_option("", $key, "- "._($key)." -", "disabled");
|
|
foreach ($arrValidNetworks[$key] as $strNetwork) echo mk_option($domain_cfg['BRNAME'], $strNetwork, $strNetwork);
|
|
}?>
|
|
</select>
|
|
|
|
:vms_network_source_help:
|
|
|
|
_(Upon host shutdown)_:
|
|
: <select id="hostshutdown" name="HOSTSHUTDOWN">
|
|
<?=mk_option($domain_cfg['HOSTSHUTDOWN'], 'shutdown', _('Shutdown VMs'))?>
|
|
<?=mk_option($domain_cfg['HOSTSHUTDOWN'], 'hibernate', _('Hibernate VMs'))?>
|
|
</select>
|
|
|
|
:vms_host_shutdown_help:
|
|
|
|
_(VM shutdown time-out)_:
|
|
: <input type="number" id="vm_shutdown_timeout" name="TIMEOUT" value="<?=htmlspecialchars($domain_cfg['TIMEOUT'])?>">
|
|
<?if (!empty($var['shutdownTimeout']) && !empty($domain_cfg['TIMEOUT']) && (int)$domain_cfg['TIMEOUT'] > (int)$var['shutdownTimeout']):?>
|
|
<span id="arraystopped"><i class="fa fa-warning icon warning"></i> _(exceeds Disk Shutdown)_ <?=htmlspecialchars($var['shutdownTimeout'])?>s _(time-out)_ (<a href="/Settings/DiskSettings">_(edit)_</a>)</span>
|
|
<?endif;?>
|
|
|
|
:vms_shutdown_timeout_help:
|
|
|
|
_(Console Options)_:
|
|
: <select id="vmsconsole" name="CONSOLE">
|
|
<?=mk_option($domain_cfg['CONSOLE'], 'web', _('Web interface'))?>
|
|
<?=mk_option($domain_cfg['CONSOLE'], 'remote', _('Virt-Manager Remote Viewer'))?>
|
|
<?=mk_option($domain_cfg['CONSOLE'], 'both', _('Both Web & Virt-Manager Remote Viewer'))?>
|
|
</select>
|
|
|
|
:vms_console_help:
|
|
|
|
_(Show RDP menu option)_:
|
|
: <select id="vmsrdpopt" name="RDPOPT">
|
|
<?=mk_option($domain_cfg['RDPOPT'], 'no', _('Dont show RDP option'))?>
|
|
<?=mk_option($domain_cfg['RDPOPT'], 'yes', _('Show RDP option'))?>
|
|
</select>
|
|
|
|
:vms_rdpopt_help:
|
|
|
|
_(Show VM Usage)_:
|
|
: <select id="vmusage" name="USAGE">
|
|
<?=mk_option($domain_cfg['USAGE'], 'N', _('Disabled'))?>
|
|
<?=mk_option($domain_cfg['USAGE'], 'Y', _('Enabled'))?>
|
|
</select>
|
|
|
|
:vms_usage_help:
|
|
|
|
_(VM Usage refresh timer)_ (_(seconds)_):
|
|
: <input type="number" id="vm_usage_timer" name="USAGETIMER" value="<?=htmlspecialchars($domain_cfg['USAGETIMER'] ?? 3) ?>">
|
|
|
|
:vms_usage_timer_help:
|
|
|
|
_(PCIe ACS override)_:
|
|
: <select id="pcie_acs_override"<?=$safemode ? ' disabled' : ''?>>
|
|
<?= mk_option($pcie_acs_override, '', _('Disabled'))?>
|
|
<?= mk_option($pcie_acs_override, 'downstream', _('Downstream'))?>
|
|
<?= mk_option($pcie_acs_override, 'multifunction', _('Multi-function'))?>
|
|
<?= mk_option($pcie_acs_override, 'downstream,multifunction', _('Both'))?>
|
|
</select><?if($safemode):?><span>*_(Setting disabled in **safe mode**)_*</span><?endif;?>
|
|
|
|
:vms_acs_override_help:
|
|
|
|
_(VFIO allow unsafe interrupts)_:
|
|
: <select id="vfio_allow_unsafe"<?=$safemode ? ' disabled' : ''?>>
|
|
<?= mk_option($vfio_allow_unsafe, '', _('No'))?>
|
|
<?= mk_option($vfio_allow_unsafe, '1', _('Yes'))?>
|
|
</select><?if($safemode):?><span>*_(Setting disabled in **safe mode**)_*</span><?endif;?>
|
|
|
|
:vms_vfio_interupts_help:
|
|
|
|
</div>
|
|
<?if ($libvirt_log):?>
|
|
<input type="button" onclick="openTerminal('log','libvirt','libvirt/libvirtd.log');" value="<?=_('View libvirt log')?>"/>
|
|
<?else:?>
|
|
|
|
<?endif;?>
|
|
<?else:?>
|
|
|
|
<?endif;?>
|
|
: <span class="inline-block">
|
|
<input type="button" id="applyBtn" value="_(Apply)_" disabled>
|
|
<input type="button" value="_(Done)_" onclick="done()">
|
|
</span>
|
|
</form>
|
|
<?if ($libvirt_log):?>
|
|
|
|
:vms_libvirt_log_help:
|
|
|
|
<?endif;?>
|
|
|
|
<?if ($libvirt_up && trim(shell_exec('stat -c %T -f /etc/libvirt'))=='btrfs'):?>
|
|
<div class="advanced" markdown="1">
|
|
<div class="title"><span class="left"><i class="title fa fa-list"></i>_(Libvirt volume info)_</span></div>
|
|
_(btrfs filesystem show)_:
|
|
: <?="<pre id='btrfs-scrub'>".shell_exec("btrfs filesystem show /etc/libvirt")."</pre>"?>
|
|
|
|
<form markdown="1" method="POST" action="/update.php" target="progressFrame" onsubmit="prepareFS(this,'btrfs-scrub-vm','/etc/libvirt')>">
|
|
<?exec("$docroot/webGui/scripts/btrfs_scrub status /etc/libvirt", $scrub_status, $retval);?>
|
|
_(btrfs scrub status)_:
|
|
: <?="<pre>".implode("\n", $scrub_status)."</pre>"?>
|
|
|
|
<?if ($retval != 0):?>
|
|
<input type="hidden" name="#command" value="/webGui/scripts/btrfs_scrub">
|
|
<input type="hidden" name="#arg[1]" value="start">
|
|
<input type="hidden" name="#arg[2]" value="/etc/libvirt">
|
|
<input type="hidden" name="#arg[3]" value="-r">
|
|
|
|
|
|
: <span class="inline-block">
|
|
<input type="submit" value="_(Scrub)_">
|
|
<label><input type="checkbox" name="#arg[3]" value="">_(Correct file system errors)_</label>
|
|
</span>
|
|
|
|
:vms_scrub_help:
|
|
|
|
<?else:?>
|
|
<input type="hidden" name="#command" value="/webGui/scripts/btrfs_scrub">
|
|
<input type="hidden" name="#arg[1]" value="cancel">
|
|
<input type="hidden" name="#arg[2]" value="/etc/libvirt">
|
|
|
|
|
|
: <span class="inline-block">
|
|
<input type="submit" value="_(Cancel)_">
|
|
</span>
|
|
|
|
:vms_cancel_help:
|
|
|
|
</form>
|
|
<?endif;?>
|
|
</div>
|
|
|
|
<?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>
|
|
<?endif;?>
|
|
|
|
<script src="<?autov('/webGui/javascript/jquery.filetree.js')?>" charset="utf-8"></script>
|
|
<script src="<?autov('/webGui/javascript/jquery.switchbutton.js')?>"></script>
|
|
<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);
|
|
}
|
|
function btrfsScrub(path) {
|
|
$.post('/webGui/include/FileSystemStatus.php',{cmd:'scrub',path:path},function(data) {
|
|
if (data.indexOf('running')>0) {
|
|
$('#btrfs-scrub').text(data);
|
|
setTimeout(function(){btrfsScrub(path);},1000);
|
|
} else {
|
|
$.removeCookie('btrfs-scrub-vm');
|
|
refresh();
|
|
}
|
|
});
|
|
}
|
|
|
|
function validatePath(input) {
|
|
if (input.value.includes("'")) {
|
|
input.setCustomValidity(_("Single quote ' is not allowed in the path.")_);
|
|
} else {
|
|
input.setCustomValidity("");
|
|
}
|
|
input.reportValidity();
|
|
}
|
|
|
|
// Validate both domaindir and mediadir on submit
|
|
function validateFormOnSubmit() {
|
|
const domaindir = document.getElementById('domaindir');
|
|
const mediadir = document.getElementById('mediadir');
|
|
|
|
// Run validation
|
|
validatePath(domaindir);
|
|
validatePath(mediadir);
|
|
|
|
// Check validity in order, and focus the first invalid field
|
|
if (!domaindir.checkValidity()) {
|
|
domaindir.reportValidity();
|
|
domaindir.focus();
|
|
return false;
|
|
}
|
|
|
|
if (!mediadir.checkValidity()) {
|
|
mediadir.reportValidity();
|
|
mediadir.focus();
|
|
return false;
|
|
}
|
|
|
|
// Both valid
|
|
return true;
|
|
}
|
|
|
|
document.getElementById('settingsForm').addEventListener('submit', function(e) {
|
|
if (!validateFormOnSubmit()) {
|
|
e.preventDefault();
|
|
}
|
|
});
|
|
|
|
// Attach validation on input events
|
|
['domaindir', 'mediadir'].forEach(id => {
|
|
const input = document.getElementById(id);
|
|
input.addEventListener('input', () => validatePath(input));
|
|
});
|
|
|
|
// Hook into Unraid fileTreeAttach for both fields
|
|
$('.filepicker').each(function() {
|
|
const input = this;
|
|
$(input).fileTreeAttach(null, null, function(folder) {
|
|
$(input).val(folder);
|
|
validatePath(input);
|
|
$(document).trigger('close.fileTree');
|
|
});
|
|
});
|
|
|
|
$(function(){
|
|
$.post("/plugins/dynamix.vm.manager/include/Fedora-virtio-isos.php",{},function(isos) {
|
|
$('#winvirtio_select').html(isos).prop('disabled',false).change().each(function(){$(this).on('change',function() {
|
|
// attach button updates when select element changes
|
|
var form = $(this).parentsUntil('form').parent();
|
|
form.find('input[value="<?=_("Apply")?>"],input[value="Apply"],input[name="cmdEditShare"],input[name="cmdUserEdit"]').not('input.lock').prop('disabled',false);
|
|
form.find('input[value="<?=_("Done")?>"],input[value="Done"]').not('input.lock').val("<?=_('Reset')?>").prop('onclick',null).off('click').click(function(){formHasUnsavedChanges=false;refresh(form.offset().top);});
|
|
});});
|
|
});
|
|
$("#applyBtn").click(function(){
|
|
if ($("#deleteCheckbox").length && $("#deleteCheckbox").is(":checked")) {
|
|
$("#removeForm").submit();
|
|
return;
|
|
}
|
|
var run = true;
|
|
$("#settingsForm").find('input[type="text"]').each(function(){
|
|
if ($(this).is(':visible') && $(this).attr('pattern')) {
|
|
var pattern = new RegExp($(this).attr('pattern'));
|
|
if (!pattern.test($(this).val())) {$(this).css('color','red'); run = false;}
|
|
}
|
|
});
|
|
<?if ($safemode):?>
|
|
if (run) $("#settingsForm").submit();
|
|
<?else:?>
|
|
if (run) $.post("/plugins/dynamix.vm.manager/include/VMajax.php", {action:'cmdlineoverride',pcie:$('#pcie_acs_override').val(),vfio:$('#vfio_allow_unsafe').val()}, function(data){
|
|
$("#settingsForm").submit();
|
|
});
|
|
<?endif;?>
|
|
});
|
|
|
|
$("#mediadir").on("input change", function(){
|
|
$("#winvirtio_select").change();
|
|
});
|
|
|
|
var checkDownloadTimer = null;
|
|
var checkOrInitDownload = function(checkonly){
|
|
clearTimeout(checkDownloadTimer);
|
|
var $button = $("#download_button");
|
|
var $form = $button.closest('form');
|
|
var postdata = {
|
|
action: "virtio-win-iso-download",
|
|
download_version: $('#winvirtio_select').val(),
|
|
download_path: $('#mediadir').val(),
|
|
checkonly: ((typeof checkonly === 'undefined') ? false : !!checkonly) ? 1 : 0
|
|
};
|
|
$button.removeClass('fa-download').addClass('fa-circle-o-notch fa-spin');
|
|
$.post("/plugins/dynamix.vm.manager/include/VMajax.php", postdata, function(data){
|
|
if (postdata.download_version != $('#winvirtio_select').val())
|
|
return;
|
|
if (data.error) {
|
|
$("#download_status").html('<span style="color: red">' + data.error + '</span>');
|
|
$button.removeClass('fa-circle-o-notch fa-spin').addClass('fa-download');
|
|
} else {
|
|
$("#download_status").html(data.status);
|
|
if (data.pid) {
|
|
checkDownloadTimer = setTimeout(checkOrInitDownload, 1000);
|
|
return;
|
|
}
|
|
if (data.status == "_(Done)_") $("#winvirtio_select").change();
|
|
}
|
|
}, "json");
|
|
};
|
|
$("#SERVICE").change(function changeService(){
|
|
if ($(this).val()=='enable') {
|
|
$('#arraystopped').fadeIn('slow');
|
|
} else {
|
|
$('#arraystopped').fadeOut('fast');
|
|
}
|
|
});
|
|
if ($("#SERVICE").val()!='enable') $('#arraystopped').hide();
|
|
$("#download_button").click(function downloadVirtIOVersion(){
|
|
if (!$(this).hasClass('fa-spin')) {
|
|
checkOrInitDownload(false);
|
|
}
|
|
});
|
|
$("#remove_button").click(function removeVirtIOVersion() {
|
|
var postdata = {
|
|
action: "virtio-win-iso-remove",
|
|
path: $('#mediadir').val(),
|
|
file: $('#winvirtio_select').val()
|
|
};
|
|
$.post("/plugins/dynamix.vm.manager/include/VMajax.php", postdata, function(data){
|
|
if (postdata.file != $('#winvirtio_select').val()) return;
|
|
if (data.success) {
|
|
$("#winvirtio_select").change();
|
|
}
|
|
}, "json");
|
|
});
|
|
// Fire events below once upon showing page
|
|
$("#winvirtio_select").change(function changeVirtIOVersion(){
|
|
clearTimeout(checkDownloadTimer);
|
|
if ($(this).val()=='manual') {
|
|
$("#download_button,#download_status").hide('fast');
|
|
$("#winvirtio").show('fast');
|
|
return;
|
|
}
|
|
$("#winvirtio").hide('fast');
|
|
var params = {
|
|
action: "virtio-win-iso-info",
|
|
path: $("#mediadir").val(),
|
|
file: $(this).val()
|
|
};
|
|
$.post("/plugins/dynamix.vm.manager/include/VMajax.php", params, function(data){
|
|
if (!data.exists || data.pid) {
|
|
$("#remove_button").hide('fast');
|
|
$("#download_button").removeClass('fa-circle-o-notch fa-spin').addClass('fa-download').show('fast');
|
|
$("#download_status").html('').show('fast');
|
|
if (data.pid) checkOrInitDownload(true);
|
|
} else {
|
|
$("#download_button,#download_status").hide('fast');
|
|
$("#remove_button").show('fast');
|
|
$("#winvirtio").val(data.path);
|
|
}
|
|
}, "json");
|
|
});
|
|
if ($.cookie('vmsettings_view_mode') == 'advanced') {
|
|
$('.advanced').show();
|
|
$('.basic').hide();
|
|
}
|
|
<?if ($hardware):?>
|
|
$('.advancedview').switchButton({
|
|
labels_placement: "left",
|
|
on_label: "_(Advanced View)_",
|
|
off_label: "_(Basic View)_",
|
|
checked: $.cookie('vmsettings_view_mode') == 'advanced'
|
|
});
|
|
$('.advancedview').change(function(){
|
|
$('.advanced').toggle('slow');
|
|
$('.basic').toggle('slow');
|
|
$.cookie('vmsettings_view_mode', $('.advancedview').is(':checked') ? 'advanced' : 'basic', {expires:3650});
|
|
});
|
|
<?endif;?>
|
|
showStatus('pid','libvirt/libvirtd');
|
|
<?if ($started):?>
|
|
$("#IMAGE_FILE").fileTreeAttach(null, null, function(folder) {
|
|
$("#IMAGE_FILE").val(folder + 'libvirt.img').change();
|
|
});
|
|
$('#domaindir').fileTreeAttach();
|
|
$('#mediadir').fileTreeAttach();
|
|
$('#winvirtio').fileTreeAttach();
|
|
<?endif;?>
|
|
if ($("#IMAGE_FILE").length) {
|
|
$("#IMAGE_FILE").on("input change", function(){
|
|
$("#IMAGE_ERROR").fadeOut();
|
|
$("#applyBtn").prop("disabled", false);
|
|
<?php if (file_exists($domain_cfg['IMAGE_FILE'])) { ?>
|
|
if ($(this).val() != "<?=$domain_cfg['IMAGE_FILE']?>") {
|
|
$("#deleteCheckbox").prop("disabled", true).attr("checked", false);
|
|
$("#deletePanel").fadeOut();
|
|
} else {
|
|
$("#deleteCheckbox").attr("checked", false).prop("disabled", false);
|
|
$("#deletePanel").fadeIn();
|
|
}
|
|
<?php } ?>
|
|
});
|
|
$("#deleteCheckbox").change(function(){
|
|
var checked = $(this).is(":checked");
|
|
$("#SERVICE").prop("disabled", checked).val('disable');
|
|
$("#IMAGE_SIZE").prop("disabled", checked);
|
|
$("#IMAGE_FILE").prop("disabled", checked).val("<?=$domain_cfg['IMAGE_FILE']?>");
|
|
$("#domaindir").prop("disabled", checked);
|
|
$("#mediadir").prop("disabled", checked);
|
|
$("#winvirtio_select").prop("disabled", checked);
|
|
$("#winvirtio").prop("disabled", checked);
|
|
$("#network").prop("disabled", checked);
|
|
$("#hostshutdown").prop("disabled", checked);
|
|
$("#pcie_acs_override").prop("disabled", checked);
|
|
$("#vm_shutdown_timeout").prop("disabled", checked);
|
|
$("#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)_";
|
|
if (data.modified) addRebootNotice(rebootMessage); else removeRebootNotice(rebootMessage);
|
|
});
|
|
if ($.cookie('btrfs-scrub-vm')) btrfsScrub($.cookie('btrfs-scrub-vm'));
|
|
});
|
|
</script>
|