Merge pull request #590 from Squidly271/reboot

Preserve Reboot Required Notifications Across Pages
This commit is contained in:
tom mortensen
2020-02-13 22:25:33 -08:00
committed by GitHub
5 changed files with 90 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
<?PHP
/* Copyright 2019, Lime Technology
* Copyright 2019, Andrew Zawadzki.
/* Copyright 2019-2020, Lime Technology
* Copyright 2019-2020, Andrew Zawadzki.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
@@ -31,35 +31,55 @@ function download_url($url, $path = "") {
return $out ?: false;
}
$options = $_POST['options'];
$plugin = $options['plugin'];
switch ($_POST['action']) {
case 'checkPlugin':
$options = $_POST['options'];
$plugin = $options['plugin'];
if ( ! $plugin || ! file_exists("/var/log/plugins/$plugin") ) {
echo json_encode(array("updateAvailable"=>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;
}
?>

View File

@@ -235,8 +235,6 @@ VFIO allow unsafe interrupts:
<?endif;?>
: <input type="button" id="applyBtn" value="Apply" disabled><input type="button" value="Done" onclick="done()">
</form>
<div class="notice reboot" style="display:none;margin-bottom:24px">System must be rebooted for changes to take effect!</div>
<?if (file_exists("/var/log/libvirt/libvirtd.log")):?>
> View the log for libvirt: <a id="openlog" title="/var/log/libvirt/libvirtd.log" href="#" onclick="openWindow('/webGui/scripts/tail_log&arg1=libvirt/libvirtd.log','Libvirt Log',600,900);">/var/log/libvirt/libvirtd.log</a>
@@ -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);
});
});
</script>

View File

@@ -3,8 +3,8 @@ Title="CPU Isolation"
Tag="icon-cpu"
---
<?PHP
/* Copyright 2005-2018, Lime Technology
* Copyright 2012-2018, Bergware International.
/* Copyright 2005-2020, Lime Technology
* Copyright 2012-2020, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
@@ -23,7 +23,6 @@ Tag="icon-cpu"
<input type="button" value="Apply" onclick="apply(this.form)" disabled><input type="button" value="Done" onclick="done()"><span id="wait-is" class="red-text" style="display:none"><i class="fa fa-spinner fa-spin"></i> Please wait...</span>
</form>
<?if (!$safemode):?>
<div class="notice isol" style="display:none">System must be rebooted for changes to take effect!</div>
<?else:?>
<div class="notice">CPU isolation is prohibited while system is running in SAFE MODE!</div>
<?endif;?>

View File

@@ -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) {

View File

@@ -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 = "<i class='fa fa-warning' style='float:initial;'></i> "+text;
var arrayEntry = bannerWarnings.push("placeholder") - 1;
if (!noDismiss) text = text + "<a class='bannerDismiss' onclick='dismissBannerWarning("+arrayEntry+",&quot;"+cookieText+"&quot;)'></a>";
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("<i class='fa fa-warning' style='float:initial;'></i> "+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("<i class='fa fa-warning' style='float:initial;'></i> "+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=<?=$var['csrf_token']?>";
}
});
// add any pre-existing reboot notices
$(function() {
<?
$rebootNotice = @file("/tmp/reboot_notifications") ?: array();
foreach ($rebootNotice as $notice):
?>
var rebootMessage = "<?=trim($notice)?>";
if ( rebootMessage ) {
addBannerWarning("<i class='fa fa-warning' style='float:initial;'></i> "+rebootMessage,false,true);
}
<?
endforeach;
?>
});
</script>
</head>
<body>