Use background checking for flash corruption

This commit is contained in:
bergware
2021-08-20 12:13:28 +02:00
parent 745f5f6fce
commit c3a4197e93
2 changed files with 43 additions and 16 deletions

View File

@@ -234,16 +234,16 @@ function escapeQuotes(form) {
var bannerWarnings = [];
var currentBannerWarning = 0;
var bannerWarningInterval = false;
var bannerWarningInterval = null;
var osUpgradeWarning = false;
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;
if ( bannerWarnings.indexOf(text) < 0 ) {
if (bannerWarnings.indexOf(text) < 0) {
var arrayEntry = bannerWarnings.push("placeholder") - 1;
if (!noDismiss) text = text + "<a class='bannerDismiss' onclick='dismissBannerWarning("+arrayEntry+",&quot;"+cookieText+"&quot;)'></a>";
if (!noDismiss) text += "<a class='bannerDismiss' onclick='dismissBannerWarning("+arrayEntry+",&quot;"+cookieText+"&quot;)'></a>";
bannerWarnings[arrayEntry] = text;
} else return bannerWarnings.indexOf(text);
@@ -277,7 +277,6 @@ function showBannerWarnings() {
if (allWarnings.length == 0) {
$(".upgrade_notice").hide();
clearInterval(bannerWarningInterval);
bannerWarningInterval = false;
return;
}
if (currentBannerWarning >= allWarnings.length) currentBannerWarning = 0;
@@ -292,9 +291,7 @@ function addRebootNotice(message="<?=_('You must reboot for changes to take effe
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;
}
if (bannerIndex < 0) return;
removeBannerWarning(bannerIndex);
$.post("/plugins/dynamix.plugin.manager/scripts/PluginAPI.php",{action:'removeRebootNotice',message:message});
}
@@ -369,15 +366,14 @@ $(function() {
$.jGrowl.defaults.themeState = '';
Shadowbox.setup('a.sb-enable', {modal:true});
// add any pre-existing reboot notices
<?$rebootNotice = @file("/tmp/reboot_notifications") ?: [];?>
<?foreach ($rebootNotice as $notice):?>
var rebootMessage = "<?=unbundle($notice)?>";
if (rebootMessage) addBannerWarning("<i class='fa fa-warning' style='float:initial;'></i> "+rebootMessage,false,true);
<?endforeach;?>
// check for flash offline / corrupted. docker.cfg is guaranteed to always exist
<?if (!@parse_ini_file("$config/docker.cfg") || !@parse_ini_file("$config/domain.cfg") || !@parse_ini_file("$config/ident.cfg")):?>
addBannerWarning("<?=_('Your flash drive is corrupted or offline').'. '._('Post your diagnostics in the forum for help').'.'?> <a target='_blank' href='https://wiki.unraid.net/Manual/Changing_The_Flash_Device'><?=_('See also here')?></a>");
<?endif;?>
$.post('/webGui/include/Report.php',{cmd:'notice'},function(notices){
notices = notices.split('\n');
for (var i=0,notice; notice=notices[i]; i++) addBannerWarning("<i class='fa fa-warning' style='float:initial;'></i> "+notice,false,true);
});
// check for flash offline / corrupted.
$.post('/webGui/include/Report.php',{cmd:'sha256'},function(check){
if (check>0) addBannerWarning("<?=_('Your flash drive is corrupted or offline').'. '._('Post your diagnostics in the forum for help').'.'?> <a target='_blank' href='https://wiki.unraid.net/Manual/Changing_The_Flash_Device'><?=_('See also here')?></a>");
});
});
var mobiles=['ipad','iphone','ipod','android'];

View File

@@ -0,0 +1,31 @@
<?PHP
/* Copyright 2005-2021, Lime Technology
* Copyright 2012-2021, 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,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
switch ($_POST['cmd']) {
case 'sha256':
$boot = "/boot";
$check = "/var/tmp/check.sha256";
$image = ['bzroot','bzimage']; // image files to check
if (!file_exists($check)) foreach ($image as $file) file_put_contents($check,trim(file_get_contents("$boot/$file.sha256"))." $boot/$file\n",FILE_APPEND);
passthru("sha256sum --status -c $check",$status);
echo $status;
break;
case 'notice':
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/Secure.php";
$tmp = "/tmp/reboot_notifications";
$notices = file_exists($tmp) ? file($tmp,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES) : [];
echo implode("\n",array_map('unbundle',$notices));
break;
}
?>