From acc869c739cc991819ce529a79fce31cab9cb5bc Mon Sep 17 00:00:00 2001 From: Andrew Z Date: Sun, 19 Jan 2020 15:57:59 -0500 Subject: [PATCH 1/9] Preserve reboot notices across pages --- .../dynamix.plugin.manager/PluginHelpers.page | 3 + .../scripts/PluginAPI.php | 75 ++++++++++++------- plugins/dynamix.vm.manager/VMSettings.page | 3 +- plugins/dynamix/CPUvms.page | 3 +- plugins/dynamix/include/DefaultPageLayout.php | 32 ++++++++ 5 files changed, 87 insertions(+), 29 deletions(-) diff --git a/plugins/dynamix.plugin.manager/PluginHelpers.page b/plugins/dynamix.plugin.manager/PluginHelpers.page index eceb9173f..c279a62b7 100644 --- a/plugins/dynamix.plugin.manager/PluginHelpers.page +++ b/plugins/dynamix.plugin.manager/PluginHelpers.page @@ -24,6 +24,8 @@ a.bannerInfo {cursor:pointer;text-decoration:none;} \ No newline at end of file diff --git a/plugins/dynamix.plugin.manager/scripts/PluginAPI.php b/plugins/dynamix.plugin.manager/scripts/PluginAPI.php index b3b0974e3..6b9b439e5 100644 --- a/plugins/dynamix.plugin.manager/scripts/PluginAPI.php +++ b/plugins/dynamix.plugin.manager/scripts/PluginAPI.php @@ -30,36 +30,57 @@ function download_url($url, $path = "") { return $out ?: false; } +file_put_contents("/tmp/trace",$_POST['action']); +switch ($_POST['action']) { + case 'checkPlugin': + $options = $_POST['options']; + $plugin = $options['plugin']; -$options = $_POST['options']; -$plugin = $options['plugin']; + if ( ! $plugin || ! file_exists("/var/log/plugins/$plugin") ) { + echo json_encode(array("updateAvailable"=>false)); + break; + } -if ( ! $plugin || ! file_exists("/var/log/plugins/$plugin") ) { - echo json_encode(array("updateAvailable"=>false)); - return; -} + exec("mkdir -p /tmp/plugins"); + @unlink("/tmp/plugins/$plugin"); + $url = @plugin("pluginURL","/boot/config/plugins/$plugin"); + download_url($url,"/tmp/plugins/$plugin"); -exec("mkdir -p /tmp/plugins"); -@unlink("/tmp/plugins/$plugin"); -$url = @plugin("pluginURL","/boot/config/plugins/$plugin"); -download_url($url,"/tmp/plugins/$plugin"); + $changes = @plugin("changes","/tmp/plugins/$plugin"); + $version = @plugin("version","/tmp/plugins/$plugin"); + $installedVersion = @plugin("version","/boot/config/plugins/$plugin"); + $min = @plugin("min","/tmp/plugins/$plugin") ?: "6.4.0"; + if ( $changes ) { + file_put_contents("/tmp/plugins/".pathinfo($plugin, PATHINFO_FILENAME).".txt",$changes); + } else { + @unlink("/tmp/plugins/".pathinfo($plugin, PATHINFO_FILENAME).".txt"); + } -$changes = @plugin("changes","/tmp/plugins/$plugin"); -$version = @plugin("version","/tmp/plugins/$plugin"); -$installedVersion = @plugin("version","/boot/config/plugins/$plugin"); -$min = @plugin("min","/tmp/plugins/$plugin") ?: "6.4.0"; -if ( $changes ) { - file_put_contents("/tmp/plugins/".pathinfo($plugin, PATHINFO_FILENAME).".txt",$changes); -} else { - @unlink("/tmp/plugins/".pathinfo($plugin, PATHINFO_FILENAME).".txt"); -} - -$update = false; -if ( strcmp($version,$installedVersion) > 0 ) { - $unraid = parse_ini_file("/etc/unraid-version"); - $update = (version_compare($min,$unraid['version'],">")) ? false : true; -} - -echo json_encode(array("updateAvailable" => $update,"version" => $version,"min"=>$min,"changes"=>$changes,"installedVersion"=>$installedVersion)); + $update = false; + if ( strcmp($version,$installedVersion) > 0 ) { + $unraid = parse_ini_file("/etc/unraid-version"); + $update = (version_compare($min,$unraid['version'],">")) ? false : true; + } + echo json_encode(array("updateAvailable" => $update,"version" => $version,"min"=>$min,"changes"=>$changes,"installedVersion"=>$installedVersion)); + break; + + case 'addRebootNotice': + $message = htmlspecialchars(trim($_POST['message'])); + if (!$message) break; + + $existing = @file("/tmp/reboot_notifications",FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: array(); + $existing[] = $message; + + file_put_contents("/tmp/reboot_notifications",implode("\n",array_unique($existing))); + break; + + case 'removeRebootNotice': + $message = htmlspecialchars(trim($_POST['message'])); + $existing = file_get_contents("/tmp/reboot_notifications"); + $newReboots = str_replace($message,"",$existing); + file_put_contents("/tmp/reboot_notifications",$newReboots); + file_put_contents("/tmp/blah","here"); + break; +} ?> diff --git a/plugins/dynamix.vm.manager/VMSettings.page b/plugins/dynamix.vm.manager/VMSettings.page index 15641ba7a..d1290f880 100644 --- a/plugins/dynamix.vm.manager/VMSettings.page +++ b/plugins/dynamix.vm.manager/VMSettings.page @@ -446,7 +446,8 @@ $(function(){ }); } $.post("/plugins/dynamix.vm.manager/include/VMajax.php", {action:'reboot'}, function(data){ - if (data.modified) $('div.notice.reboot').show(); else $('div.notice.reboot').hide(); + var rebootMessage = "VM Settings: A reboot is required to apply changes"; + if (data.modified) addRebootNotice(rebootMessage); else removeRebootNotice(rebootMessage); }); }); diff --git a/plugins/dynamix/CPUvms.page b/plugins/dynamix/CPUvms.page index e6f3d4b9e..725dd3dbd 100644 --- a/plugins/dynamix/CPUvms.page +++ b/plugins/dynamix/CPUvms.page @@ -152,8 +152,9 @@ function is() { } function notice() { // notice to reboot system after changes + var message = "CPU Isolation: A reboot is required to apply changes"; $.post('/webGui/include/CPUset.php',{id:'cmd'},function(d){ - if (d==1) $('div.notice.isol').show(); else $('div.notice.isol').hide(); + if (d==1) addRebootNotice(message); else removeRebootNotice(message); }); } function reset(form) { diff --git a/plugins/dynamix/include/DefaultPageLayout.php b/plugins/dynamix/include/DefaultPageLayout.php index 28b4321a2..aa0e649f1 100644 --- a/plugins/dynamix/include/DefaultPageLayout.php +++ b/plugins/dynamix/include/DefaultPageLayout.php @@ -283,6 +283,23 @@ function showUpgrade(data,noDismiss=false) { osUpgradeWarning = addBannerWarning(data.replace(/(.*)<\/a>/,"$1"),false,noDismiss); } } + +function addRebootNotice(message="You must reboot for changes to take effect") { + addBannerWarning(" "+message,false,true); + + $.post("/plugins/dynamix.plugin.manager/scripts/PluginAPI.php",{action:'addRebootNotice',message:message}); +} + +function removeRebootNotice(message="You must reboot for changes to take effect") { + var bannerIndex = bannerWarnings.indexOf(" "+message); + if ( bannerIndex < 0 ) { + return; + } + console.log(bannerIndex); + removeBannerWarning(bannerIndex); + $.post("/plugins/dynamix.plugin.manager/scripts/PluginAPI.php",{action:'removeRebootNotice',message:message}); +} + function hideUpgrade(set) { removeBannerWarning(osUpgradeWarning); if (set) @@ -388,6 +405,21 @@ $.ajaxPrefilter(function(s, orig, xhr){ s.data += "csrf_token="; } }); + +// add any pre-existing reboot notices +$(function() { + + var rebootMessage = ""; + if ( rebootMessage ) { + addBannerWarning(" "+rebootMessage,false,true); + } + +}); From 25c9c0c45e4db1e5341f63d48aa7db7a5d52ba23 Mon Sep 17 00:00:00 2001 From: Andrew Z Date: Sun, 19 Jan 2020 16:01:12 -0500 Subject: [PATCH 2/9] Remove extraneous whitespace --- plugins/dynamix.plugin.manager/PluginHelpers.page | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/dynamix.plugin.manager/PluginHelpers.page b/plugins/dynamix.plugin.manager/PluginHelpers.page index c279a62b7..eceb9173f 100644 --- a/plugins/dynamix.plugin.manager/PluginHelpers.page +++ b/plugins/dynamix.plugin.manager/PluginHelpers.page @@ -24,8 +24,6 @@ a.bannerInfo {cursor:pointer;text-decoration:none;} \ No newline at end of file From 9faa82278e7e7402d2e0d2ea815ad3987e92c850 Mon Sep 17 00:00:00 2001 From: Squidly271 Date: Sun, 19 Jan 2020 16:20:30 -0500 Subject: [PATCH 3/9] Remove debugging info --- plugins/dynamix.plugin.manager/scripts/PluginAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/dynamix.plugin.manager/scripts/PluginAPI.php b/plugins/dynamix.plugin.manager/scripts/PluginAPI.php index 6b9b439e5..b05835afb 100644 --- a/plugins/dynamix.plugin.manager/scripts/PluginAPI.php +++ b/plugins/dynamix.plugin.manager/scripts/PluginAPI.php @@ -30,7 +30,7 @@ function download_url($url, $path = "") { return $out ?: false; } -file_put_contents("/tmp/trace",$_POST['action']); + switch ($_POST['action']) { case 'checkPlugin': $options = $_POST['options']; From 44af35f29b94087161bc08398bd1be8e09df4345 Mon Sep 17 00:00:00 2001 From: Andrew Z Date: Sun, 19 Jan 2020 16:28:07 -0500 Subject: [PATCH 4/9] Remove debugging --- plugins/dynamix.plugin.manager/scripts/PluginAPI.php | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/dynamix.plugin.manager/scripts/PluginAPI.php b/plugins/dynamix.plugin.manager/scripts/PluginAPI.php index b05835afb..7aa3a976f 100644 --- a/plugins/dynamix.plugin.manager/scripts/PluginAPI.php +++ b/plugins/dynamix.plugin.manager/scripts/PluginAPI.php @@ -80,7 +80,6 @@ switch ($_POST['action']) { $existing = file_get_contents("/tmp/reboot_notifications"); $newReboots = str_replace($message,"",$existing); file_put_contents("/tmp/reboot_notifications",$newReboots); - file_put_contents("/tmp/blah","here"); break; } ?> From 0e3b4f2d4b5afad285406c6b47097237dd1a6a06 Mon Sep 17 00:00:00 2001 From: Andrew Z Date: Sun, 19 Jan 2020 16:35:09 -0500 Subject: [PATCH 5/9] Remove debugging --- plugins/dynamix/include/DefaultPageLayout.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/dynamix/include/DefaultPageLayout.php b/plugins/dynamix/include/DefaultPageLayout.php index aa0e649f1..738d802cf 100644 --- a/plugins/dynamix/include/DefaultPageLayout.php +++ b/plugins/dynamix/include/DefaultPageLayout.php @@ -286,7 +286,6 @@ function showUpgrade(data,noDismiss=false) { function addRebootNotice(message="You must reboot for changes to take effect") { addBannerWarning(" "+message,false,true); - $.post("/plugins/dynamix.plugin.manager/scripts/PluginAPI.php",{action:'addRebootNotice',message:message}); } @@ -295,7 +294,6 @@ function removeRebootNotice(message="You must reboot for changes to take effect" if ( bannerIndex < 0 ) { return; } - console.log(bannerIndex); removeBannerWarning(bannerIndex); $.post("/plugins/dynamix.plugin.manager/scripts/PluginAPI.php",{action:'removeRebootNotice',message:message}); } From f47940822585beae78e19ddd6cc800a08fd99f98 Mon Sep 17 00:00:00 2001 From: Andrew Z Date: Sun, 19 Jan 2020 16:38:52 -0500 Subject: [PATCH 6/9] Removed unused Div --- plugins/dynamix/CPUisol.page | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/dynamix/CPUisol.page b/plugins/dynamix/CPUisol.page index c2825377a..f9e75a07e 100644 --- a/plugins/dynamix/CPUisol.page +++ b/plugins/dynamix/CPUisol.page @@ -23,7 +23,6 @@ Tag="icon-cpu" -
CPU isolation is prohibited while system is running in SAFE MODE!
From d671cd0ddda1140b91c9e8ea0c685479e9d577d3 Mon Sep 17 00:00:00 2001 From: Andrew Z Date: Sun, 19 Jan 2020 16:48:16 -0500 Subject: [PATCH 7/9] Removed unused Div --- plugins/dynamix.vm.manager/VMSettings.page | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/dynamix.vm.manager/VMSettings.page b/plugins/dynamix.vm.manager/VMSettings.page index d1290f880..22138943a 100644 --- a/plugins/dynamix.vm.manager/VMSettings.page +++ b/plugins/dynamix.vm.manager/VMSettings.page @@ -232,8 +232,6 @@ VFIO allow unsafe interrupts: : - - > View the log for libvirt: /var/log/libvirt/libvirtd.log From 1a3e2eee5255e6c1e2689b3d813ac0e267c9199c Mon Sep 17 00:00:00 2001 From: Andrew Z Date: Sun, 19 Jan 2020 19:30:44 -0500 Subject: [PATCH 8/9] Prevent duplicate banners --- plugins/dynamix/include/DefaultPageLayout.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/dynamix/include/DefaultPageLayout.php b/plugins/dynamix/include/DefaultPageLayout.php index 738d802cf..d19e4b5cd 100644 --- a/plugins/dynamix/include/DefaultPageLayout.php +++ b/plugins/dynamix/include/DefaultPageLayout.php @@ -227,11 +227,15 @@ function addBannerWarning(text,warning=true,noDismiss=false) { if ( warning ) { text = " "+text; } - var arrayEntry = bannerWarnings.push("placeholder") - 1; + if ( ! noDismiss ) { text = text + ""; } - bannerWarnings[arrayEntry] = text; + if ( bannerWarnings.indexOf(text) < 0 ) { + var arrayEntry = bannerWarnings.push("placeholder") - 1; + bannerWarnings[arrayEntry] = text; + } + if ( ! bannerWarningInterval ) { showBannerWarnings(); bannerWarningInterval = setInterval(function() { @@ -294,6 +298,7 @@ function removeRebootNotice(message="You must reboot for changes to take effect" if ( bannerIndex < 0 ) { return; } + console.log("banner index: "+bannerIndex); removeBannerWarning(bannerIndex); $.post("/plugins/dynamix.plugin.manager/scripts/PluginAPI.php",{action:'removeRebootNotice',message:message}); } From 8dc8ae828f0afb2df76be9e0dacb83dc3cba62c2 Mon Sep 17 00:00:00 2001 From: Andrew Z Date: Sun, 19 Jan 2020 19:37:48 -0500 Subject: [PATCH 9/9] Tabs to spaces --- plugins/dynamix/include/DefaultPageLayout.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/dynamix/include/DefaultPageLayout.php b/plugins/dynamix/include/DefaultPageLayout.php index d19e4b5cd..f367a6ab3 100644 --- a/plugins/dynamix/include/DefaultPageLayout.php +++ b/plugins/dynamix/include/DefaultPageLayout.php @@ -231,11 +231,11 @@ function addBannerWarning(text,warning=true,noDismiss=false) { if ( ! noDismiss ) { text = text + ""; } - if ( bannerWarnings.indexOf(text) < 0 ) { - var arrayEntry = bannerWarnings.push("placeholder") - 1; - bannerWarnings[arrayEntry] = text; - } - + if ( bannerWarnings.indexOf(text) < 0 ) { + var arrayEntry = bannerWarnings.push("placeholder") - 1; + bannerWarnings[arrayEntry] = text; + } else return bannerWarnings.indexOf(text); + if ( ! bannerWarningInterval ) { showBannerWarnings(); bannerWarningInterval = setInterval(function() { @@ -298,7 +298,7 @@ function removeRebootNotice(message="You must reboot for changes to take effect" if ( bannerIndex < 0 ) { return; } - console.log("banner index: "+bannerIndex); + console.log("banner index: "+bannerIndex); removeBannerWarning(bannerIndex); $.post("/plugins/dynamix.plugin.manager/scripts/PluginAPI.php",{action:'removeRebootNotice',message:message}); }