From f620a9d555b6ff84387cfcbe827e14a7493e76b3 Mon Sep 17 00:00:00 2001 From: Andrew Z Date: Thu, 13 Feb 2020 19:00:42 -0500 Subject: [PATCH] Preserve Reboot Required Notifications --- .../scripts/PluginAPI.php | 78 ++++++++++++------- plugins/dynamix.vm.manager/VMSettings.page | 5 +- plugins/dynamix/CPUisol.page | 5 +- plugins/dynamix/CPUvms.page | 4 +- plugins/dynamix/include/DefaultPageLayout.php | 36 ++++++++- 5 files changed, 90 insertions(+), 38 deletions(-) diff --git a/plugins/dynamix.plugin.manager/scripts/PluginAPI.php b/plugins/dynamix.plugin.manager/scripts/PluginAPI.php index b3b0974e3..d5a7d8a0b 100644 --- a/plugins/dynamix.plugin.manager/scripts/PluginAPI.php +++ b/plugins/dynamix.plugin.manager/scripts/PluginAPI.php @@ -1,6 +1,6 @@ false)); - return; -} + if ( ! $plugin || ! file_exists("/var/log/plugins/$plugin") ) { + echo json_encode(array("updateAvailable"=>false)); + break; + } -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; -} + $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)); - -?> + 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); + break; +} +?> \ No newline at end of file diff --git a/plugins/dynamix.vm.manager/VMSettings.page b/plugins/dynamix.vm.manager/VMSettings.page index 3d4233f8e..85d972588 100644 --- a/plugins/dynamix.vm.manager/VMSettings.page +++ b/plugins/dynamix.vm.manager/VMSettings.page @@ -235,8 +235,6 @@ VFIO allow unsafe interrupts: : - - > View the log for libvirt: /var/log/libvirt/libvirtd.log @@ -451,7 +449,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/CPUisol.page b/plugins/dynamix/CPUisol.page index c2825377a..eb2a8022d 100644 --- a/plugins/dynamix/CPUisol.page +++ b/plugins/dynamix/CPUisol.page @@ -3,8 +3,8 @@ Title="CPU Isolation" Tag="icon-cpu" --- -
CPU isolation is prohibited while system is running in SAFE MODE!
diff --git a/plugins/dynamix/CPUvms.page b/plugins/dynamix/CPUvms.page index e6f3d4b9e..8b75a1ba9 100644 --- a/plugins/dynamix/CPUvms.page +++ b/plugins/dynamix/CPUvms.page @@ -152,8 +152,10 @@ 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 a89b8bf58..3b9fb6b39 100644 --- a/plugins/dynamix/include/DefaultPageLayout.php +++ b/plugins/dynamix/include/DefaultPageLayout.php @@ -225,9 +225,12 @@ function addBannerWarning(text,warning=true,noDismiss=false) { var cookieText = text.replace(/[^a-z0-9]/gi,''); if ($.cookie(cookieText) == "true") return 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; + } else return bannerWarnings.indexOf(text); + if (!bannerWarningInterval) { showBannerWarnings(); bannerWarningInterval = setInterval(showBannerWarnings,10000); @@ -266,6 +269,20 @@ function showBannerWarnings() { currentBannerWarning++; } +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; + } + removeBannerWarning(bannerIndex); + $.post("/plugins/dynamix.plugin.manager/scripts/PluginAPI.php",{action:'removeRebootNotice',message:message}); +} + function showUpgrade(text,noDismiss=false) { if ($.cookie('os_upgrade')==null) { if (osUpgradeWarning) removeBannerWarning(osUpgradeWarning); @@ -378,6 +395,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); + } + +});