From 002b857b2265ea2ea8a4bd2e0de8671515d10342 Mon Sep 17 00:00:00 2001
From: SimonFair <39065407+SimonFair@users.noreply.github.com>
Date: Sun, 6 Apr 2025 09:27:46 +0100
Subject: [PATCH] Add acknowledge all button
---
emhttp/plugins/dynamix/SysDevs.page | 20 +++++++++--
emhttp/plugins/dynamix/include/PCIUpdate.php | 38 ++++++++++++++------
emhttp/plugins/dynamix/include/SysDevs.php | 4 +++
3 files changed, 50 insertions(+), 12 deletions(-)
diff --git a/emhttp/plugins/dynamix/SysDevs.page b/emhttp/plugins/dynamix/SysDevs.page
index 02ed63cf8..675c0d07d 100644
--- a/emhttp/plugins/dynamix/SysDevs.page
+++ b/emhttp/plugins/dynamix/SysDevs.page
@@ -46,6 +46,17 @@ function applyCfg() {
$("#applycfg").attr("disabled",true);
});
}
+function formatFullInput(input) {
+ return input
+ .split(';')
+ .filter(Boolean) // remove empty trailing entry
+ .map(entry => {
+ let [pci, status] = entry.split(',');
+ status = status.charAt(0).toUpperCase() + status.slice(1).toLowerCase();
+ return `${pci} _(${status})_`;
+ })
+ .join('
');
+}
function ackPCI(pcidevice,action) {
switch(action) {
case 'removed':
@@ -60,10 +71,15 @@ function ackPCI(pcidevice,action) {
// 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})
- $('#t1').load('/webGui/include/SysDevs.php',{table:'t1'});
+ $.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 70c85d6f2..ae19c8fab 100644
--- a/emhttp/plugins/dynamix/include/PCIUpdate.php
+++ b/emhttp/plugins/dynamix/include/PCIUpdate.php
@@ -14,20 +14,38 @@
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
require_once "$docroot/webGui/include/Helpers.php";
+
+
+function process_action($pciaddr,$action)
+{
+ global $saved,$current;
+ switch ($action) {
+ case 'removed':
+ unset($saved[$pciaddr]);
+ break;
+ case 'changed':
+ case 'added':
+ $saved[$pciaddr] = $current[$pciaddr];
+ break;
+ }
+}
+
+
$savedfile = "/boot/config/savedpcidata.json";
$saved = loadSavedData($savedfile);
if (!$saved) {echo "ERROR"; return;};
-
+$current = loadCurrentPCIData();
$pciaddr = $_POST['pciid'];
-switch ($_POST['action']??'') {
-case 'removed':
- unset($saved[$pciaddr]);
- break;
-case 'changed':
-case 'added':
- $current = loadCurrentPCIData();
- $saved[$pciaddr] = $current[$pciaddr];
- break;
+$action = $_POST['action']??'';
+
+if ($action == '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));
echo "OK";
diff --git a/emhttp/plugins/dynamix/include/SysDevs.php b/emhttp/plugins/dynamix/include/SysDevs.php
index 1027c3a7f..9f7451fd4 100644
--- a/emhttp/plugins/dynamix/include/SysDevs.php
+++ b/emhttp/plugins/dynamix/include/SysDevs.php
@@ -125,6 +125,7 @@ case 't1':
$groups[] = "IOMMU "._("Removed");
$groups[] = "\tR[{$removeddata['device']['vendor_id']}:{$removeddata['device']['device_id']}] ".str_replace("0000:","",$removedpci)." ".trim($removeddata['device']['description'],"\n");
}
+ $ackparm = "";
foreach ($groups as $line) {
if (!$line) continue;
if ($line[0]=='I') {
@@ -166,6 +167,7 @@ case 't1':
echo "";
echo _("PCI Device change");
echo " "._("Action").":".ucfirst(_($pci_device_diffs[$pciaddress]['status']))." ";
+ $ackparm .= $pciaddress.",".$pci_device_diffs[$pciaddress]['status'].";";
if ($pci_device_diffs[$pciaddress]['status']!="removed") echo $pci_device_diffs[$pciaddress]['device']['description'];
echo "";
if ($pci_device_diffs[$pciaddress]['status']=="changed") {
@@ -224,8 +226,10 @@ case 't1':
if (file_exists("/var/log/vfio-pci") && filesize("/var/log/vfio-pci")) {
echo '';
}
+ if ($ackparm == "") $ackdisable =" disabled "; else $ackdisable = "";
echo '';
echo '';
+ echo '';
echo '';
echo <<