diff --git a/emhttp/plugins/dynamix/SysDevs.page b/emhttp/plugins/dynamix/SysDevs.page index 675c0d07d..08b4944ce 100644 --- a/emhttp/plugins/dynamix/SysDevs.page +++ b/emhttp/plugins/dynamix/SysDevs.page @@ -57,30 +57,45 @@ function formatFullInput(input) { }) .join('
'); } -function ackPCI(pcidevice,action) { - switch(action) { - case 'removed': - // Remove entry from saved. - swaltext = "_(Acknowledge removal of PCI Address)_: "+pcidevice; - break; - case 'changed': - // Update saved with current - swaltext = "_(Acknowledge update of PCI Address)_: "+pcidevice; - break; - case 'added': - // Add to saved. - swaltext = "_(Acknowledge addition of PCI Address)_: "+pcidevice; - break; - case 'all': - // Add to saved. - swaltext = "_(Acknowledge all PCI Address modifications)_:
"+formatFullInput(pcidevice); - break; - } - swal({title:"Are you sure?",text:swaltext,type:"warning",html:true,showCancelButton:true},function(){ - $.post('/webGui/include/PCIUpdate.php',{action:action,pciid:pcidevice}).done(function(d) { - if (d == "OK") $('#t1').load('/webGui/include/SysDevs.php',{table:'t1'}); - }); +function formatVMS(input) { + return input + .split(';') + .filter(Boolean) // remove empty trailing entry + .join('
'); +} +function ackPCI(pcidevice, action) { + $.post('/webGui/include/PCIUpdate.php', { action: "getvm", pciid: pcidevice }).done(function(vms) { + let swaltext = ""; + + switch(action) { + case 'removed': + swaltext = "_(Acknowledge removal of PCI Address)_: " + pcidevice + "
_(VMs where PCI device used)_
" + formatVMS(vms); + break; + case 'changed': + swaltext = "_(Acknowledge update of PCI Address)_: " + pcidevice + "
_(VMs where PCI device used)_
"+ formatVMS(vms); + break; + case 'added': + swaltext = "_(Acknowledge addition of PCI Address)_: " + pcidevice + "
_(VMs where PCI device used)_
" + formatVMS(vms); + break; + case 'all': + swaltext = "_(Acknowledge all PCI Address modifications)_:
" + formatFullInput(pcidevice) + "
_(VMs where PCI device used)_
" + formatVMS(vms); + break; + } + + swal({ + title: "Are you sure?", + text: swaltext, + type: "warning", + html: true, + showCancelButton: true + }, function() { + $.post('/webGui/include/PCIUpdate.php', { action: action, pciid: pcidevice }).done(function(d) { + if (d === "OK") { + $('#t1').load('/webGui/include/SysDevs.php', { table: 't1' }); + } + }); }); + }); } diff --git a/emhttp/plugins/dynamix/include/PCIUpdate.php b/emhttp/plugins/dynamix/include/PCIUpdate.php index ae19c8fab..8acff1ba1 100644 --- a/emhttp/plugins/dynamix/include/PCIUpdate.php +++ b/emhttp/plugins/dynamix/include/PCIUpdate.php @@ -14,6 +14,7 @@ get_domains(); + foreach ($vms as $vm) { + $vmpciids = $lv->domain_get_vm_pciids($vm); + foreach($vmpciids as $pciid => $pcidetail) { + if (isset($pci_device_changes["0000:".$pciid])) { + $pcitovm["0000:".$pciid][$vm] = $vm; + } + } + } + return $pcitovm; +} $savedfile = "/boot/config/savedpcidata.json"; $saved = loadSavedData($savedfile); @@ -38,15 +53,43 @@ $current = loadCurrentPCIData(); $pciaddr = $_POST['pciid']; $action = $_POST['action']??''; -if ($action == 'all') { +switch($action) { +case "all": $pciaddrs = explode(";", $pciaddr); foreach ($pciaddrs as $pciaddraction){ $values = explode(',',$pciaddraction); process_action($values[0],$values[1]); } -} else { - process_action($pciaddr,$action); + file_put_contents($savedfile,json_encode($saved,JSON_PRETTY_PRINT)); + break; +case "removed": +case "added": +case "changed": + process_action($pciaddr,$action); + file_put_contents($savedfile,json_encode($saved,JSON_PRETTY_PRINT)); + break; +case "getvm": + $pcimap = build_pci_vm_map(); + $pciaddrs = explode(";", $pciaddr); + $vmact =[]; + + foreach ($pciaddrs as $pcidev) { + if ($pcidev == "") continue; + if (strpos($pcidev,",")) { + $values = explode(',',$pcidev); + $pcidev = $values[0]; + } + foreach ($pcimap[$pcidev] as $key => $vmname) { + $vmact[$vmname]= $vmname; + } + } + $ret = implode(";",$vmact); + + echo $ret; + exit; + } + file_put_contents($savedfile,json_encode($saved,JSON_PRETTY_PRINT)); echo "OK"; ?>