From ae285176a909b361aff144cb7559bc4e5ed39157 Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Fri, 26 Apr 2024 08:35:02 +0100 Subject: [PATCH] Update WIP --- .../dynamix.vm.manager/include/VMedit.php | 28 +++++++++++++- .../dynamix.vm.manager/include/libvirt.php | 2 +- .../include/libvirt_helpers.php | 26 +++++++++++-- .../templates/Custom.form.php | 3 ++ .../templates/Custom.formXML.php | 38 +++++++++++++------ 5 files changed, 81 insertions(+), 16 deletions(-) diff --git a/emhttp/plugins/dynamix.vm.manager/include/VMedit.php b/emhttp/plugins/dynamix.vm.manager/include/VMedit.php index 4f9c74141..fbcda9452 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/VMedit.php +++ b/emhttp/plugins/dynamix.vm.manager/include/VMedit.php @@ -102,7 +102,7 @@ if ($newmodel && $arrLoad['form'] == "Custom.form.php") $arrLoad['form'] = "Cust - +
@@ -161,6 +161,21 @@ function isVMXMLMode() { return ($.cookie('vmmanager_listview_mode') == 'xml'); } +function isinlineXMLMode() { + return ($.cookie('vmmanager_inline_mode') == 'hide'); +} + +function hidexml(checked) +{ + var form = document.getElementById("vmform"); // Replace "yourFormId" with the actual ID of your form + var xmlElements = form.getElementsByClassName("xml"); + if (checked == 1) xmldisplay = "none"; else xmldisplay = ""; + // Unhide each element + for (var i = 0; i < xmlElements.length; i++) { + xmlElements[i].style.display = xmldisplay; // Setting to empty string will revert to default style +} +} + $(function() { $('.autostart').switchButton({ on_label: "_(Yes)_", @@ -177,10 +192,20 @@ $(function() { off_label: "_(Form View)_", checked: isVMXMLMode() }); + $('.inlineview').switchButton({ + labels_placement: "left", + on_label: "_(Hide inline xml)_", + off_label: "_(Show Inline XML)_", + checked: isinlineXMLMode() + }); $('.advancedview').change(function () { toggleRows('xmlview', $(this).is(':checked'), 'formview'); $.cookie('vmmanager_listview_mode', $(this).is(':checked') ? 'xml' : 'form', { expires: 3650 }); }); + $('.inlineview').change(function () { + hidexml($(this).is(':checked')); + $.cookie('vmmanager_inline_mode', $(this).is(':checked') ? 'hide' : 'show', { expires: 3650 }); + }); $('#template_img').click(function (){ var p = $(this).position(); @@ -227,6 +252,7 @@ $(function() { } else { $('.advancedview_panel').fadeOut('fast'); } + hidexml(isinlineXMLMode()); $("#vmform #btnCancel").click(function (){ done(); diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php index 93d98dac2..314901baa 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php +++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php @@ -1801,7 +1801,7 @@ } function domain_define($xml, $autostart=false) { - if (strpos($xml,'')) { + if (strpos($xml,'') || strpos($xml,'')) { $tmp = explode("\n", $xml); for ($i = 0; $i < sizeof($tmp); $i++) if (strpos('.'.$tmp[$i], " $arrNICs, 'usb' => $arrUSBDevs, 'shares' => $lv->domain_get_mount_filesystems($res), - 'qemucmdline' => getQEMUCmdLine($strDOMXML), + 'qemucmdline' => getQEMUCmdLine($strDOMXML)."\n".getQEMUOverride($strDOMXML), 'clocks' => getClocks($strDOMXML), 'xml' => [ 'machine' => $lv->domain_get_xml($vmname, "//domain/os/*"), @@ -1565,7 +1565,19 @@ private static $encoding = 'UTF-8'; $y = strpos($xml,"", $z +19) ; if ($y != false) $z =$y ; } - return substr($xml,$x, ($z + 19) -$x) ; + return substr($xml,$x, ($z + 19) -$x); + } + + function getQEMUOverride($xml) { + $x = strpos($xml,"", 0) ; + if ($x === false) return null ; + $y = strpos($xml,"", 0) ; + $z=$y ; + while ($y!=false) { + $y = strpos($xml,"", $z +16) ; + if ($y != false) $z =$y ; + } + return substr($xml,$x, ($z + 16) -$x) ; } function getchannels($res) { @@ -2648,6 +2660,7 @@ function build_xml_templates($strXML) { "console"=> "yes", "input"=> "yes", "audio"=> "yes", + "video"=> "yes", "watchdog"=> "yes", "memballoon"=> "yes", "graphics"=> "yes", @@ -2672,7 +2685,14 @@ function build_xml_templates($strXML) { $endpos = strpos($xml,$endcheck,$strpos); } # echo substr($xml,$strpos,$endpos-$strpos+strlen($endcheck)) ; - $devxml[$xmlsection][$count] = substr($xml,$strpos,$endpos-$strpos+strlen($endcheck)) ; + if ($xmlsection == "disk") { + $disk = substr($xml,$strpos,$endpos-$strpos+strlen($endcheck)); + $xmldiskdoc = new SimpleXMLElement($disk); + $devxml[$xmlsection][$xmldiskdoc->target->attributes()->dev->__toString()] = $disk; + + } else { + $devxml[$xmlsection][$count] = substr($xml,$strpos,$endpos-$strpos+strlen($endcheck)) ; + } $count++; } } diff --git a/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php b/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php index 9e04f95d8..9579fcafa 100644 --- a/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php +++ b/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php @@ -1913,6 +1913,9 @@ $(function() { $('.advancedview').change(function () { if ($(this).is(':checked')) { setTimeout(function() { + var xmlPanelHeight = window.outerHeight - 550; + if (xmlPanelHeight < 0) xmlPanelHeight = null; + editor.setSize(null,xmlPanelHeight); editor.refresh(); }, 100); } diff --git a/emhttp/plugins/dynamix.vm.manager/templates/Custom.formXML.php b/emhttp/plugins/dynamix.vm.manager/templates/Custom.formXML.php index 10ac45dd3..8a7f03474 100644 --- a/emhttp/plugins/dynamix.vm.manager/templates/Custom.formXML.php +++ b/emhttp/plugins/dynamix.vm.manager/templates/Custom.formXML.php @@ -328,7 +328,7 @@ _(Name)_: - +
@@ -537,7 +537,7 @@ - +
@@ -656,6 +656,7 @@ + _(OS Install CDRom Bus)_: @@ -691,6 +692,7 @@ +
@@ -790,7 +792,7 @@ ?>
- + @@ -1135,7 +1137,7 @@ - + @@ -1474,7 +1476,7 @@ _(USB Devices)_: -
+
$arrDev) { @@ -1482,7 +1484,7 @@
+ ()
_(Other PCI Devices)_: -
+
- + @@ -1603,7 +1605,7 @@ ?> - + Click Create to generate the vDisks and return to the Virtual Machines page where your new VM will be created.

+ + + + + + + + + +
_(Other XML)_: +
@@ -1937,8 +1952,9 @@ $(function() { $('.advancedview').change(function () { if ($(this).is(':checked')) { setTimeout(function() { - var h = window.outerHeight - 550; - editor.setSize(null,h ); + var xmlPanelHeight = window.outerHeight - 550; + if (xmlPanelHeight < 0) xmlPanelHeight = null; + editor.setSize(null,xmlPanelHeight); editor.refresh(); }, 100); }