Preserve reboot notices across pages

This commit is contained in:
Andrew Z
2020-01-19 15:57:59 -05:00
parent 986d8e7bdb
commit acc869c739
5 changed files with 87 additions and 29 deletions
@@ -24,6 +24,8 @@ a.bannerInfo {cursor:pointer;text-decoration:none;}
</style>
<script>
function ca_hidePluginUpdate(plugin,version,element) {
$.cookie(plugin,version);
$(element).hide();
@@ -83,4 +85,5 @@ function caPluginUpdateCheck(plugin,options=[],callback) {
});
}
</script>
@@ -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;
}
?>
+2 -1
View File
@@ -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);
});
});
</script>
+2 -1
View File
@@ -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) {
@@ -283,6 +283,23 @@ function showUpgrade(data,noDismiss=false) {
osUpgradeWarning = addBannerWarning(data.replace(/<a>(.*)<\/a>/,"<a href='#' onclick='hideUpgrade();openUpgrade();'>$1</a>"),false,noDismiss);
}
}
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;
}
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=<?=$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>