mirror of
https://github.com/unraid/webgui.git
synced 2026-01-15 06:00:14 -06:00
193 lines
8.9 KiB
Plaintext
193 lines
8.9 KiB
Plaintext
Menu="Device:2 New:2"
|
|
Title="Self-Test"
|
|
Tag="wrench"
|
|
Cond="strpos($disks[$name]['status'],'_NP')===false"
|
|
---
|
|
<?PHP
|
|
/* Copyright 2005-2018, Lime Technology
|
|
* Copyright 2012-2018, 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.
|
|
*/
|
|
?>
|
|
<?
|
|
$date = $date ?? date('Ymd-Hi');
|
|
$live = exec("hdparm -C ".escapeshellarg("/dev/$dev")."|grep -Pom1 'active|unknown'");
|
|
$zip = str_replace(' ','_',strtolower($var['NAME']))."-smart-$date.zip";
|
|
|
|
// deal with unassigned devices
|
|
if (!$dev) {
|
|
$dev = $name;
|
|
foreach ($devs as $disk) {
|
|
if ($disk['device']==$name) {$file = $disk['id']."-$date.txt"; break;}
|
|
}
|
|
}
|
|
|
|
function spindownDelay() {
|
|
global $spindown, $delay;
|
|
$tmp = "/var/tmp/$spindown";
|
|
return file_exists($tmp) ? file_get_contents($tmp) : $delay;
|
|
}
|
|
?>
|
|
Download SMART report:
|
|
: <input type='button' value='Download' onclick='saveSMART()'>
|
|
|
|
SMART self-test history:
|
|
: <input type="button" value="Show" id="toggle_log" onclick="selftestLog()" disabled>
|
|
|
|
> Press **Show** to view the self-test history as is kept on the disk itself.
|
|
> This feature is only available when the disk is in active mode.
|
|
|
|
<pre id="selftest" style="display:none"></pre>
|
|
|
|
SMART error log:
|
|
: <input type="button" value="Show" id="toggle_error" onclick="errorLog()" disabled>
|
|
|
|
> Press **Show** to view the error report as is kept on the disk itself.
|
|
> This feature is only available when the disk is in active mode.
|
|
|
|
<pre id="errorlog" style="display:none"></pre>
|
|
|
|
SMART short self-test:
|
|
: <input type='button' value='Start' id='short_test' onclick="startShortTest()" disabled>
|
|
|
|
> Starts a *short* SMART self-test, the estimated duration can be viewed under the *Capabilities* section. This is usually a few minutes.
|
|
>
|
|
> When the disk is spun down, it will abort any running self-test.
|
|
> This feature is only available when the disk is in active mode.
|
|
|
|
SMART extended self-test:
|
|
: <input type='button' value='Start' id='long_test' onclick="startLongTest()" disabled>
|
|
|
|
> Starts an *extended* SMART self-test, the estimated duration can be viewed under the *Capabilities* section. This is usually several hours.
|
|
>
|
|
> When the disk is spun down, it will abort any running self-test. It is advised to disable the spin down timer of the disk
|
|
> to avoid interruption of this self-test.
|
|
>
|
|
> This feature is only available when the disk is in active mode.
|
|
|
|
Last SMART test result:
|
|
: <span id="test_result"><i class='fa fa-circle-o-notch fa-spin fa-fw'></i></span>
|
|
|
|
> When no test is running it will show here the latest obtained self-test result (if available).
|
|
> Otherwise a progress indicator (percentage value) is shown for a running test.
|
|
|
|
<script>
|
|
function cleanUp() {
|
|
if (document.hasFocus()) {
|
|
$('input[value="Downloading..."]').val('Download').prop('disabled',false);
|
|
$.post('/webGui/include/Download.php',{cmd:'delete',file:'<?=addslashes(htmlspecialchars($file))?>'});
|
|
$.post('/webGui/include/Download.php',{cmd:'delete',file:'<?=addslashes(htmlspecialchars($zip))?>'});
|
|
} else {
|
|
setTimeout(cleanUp,4000);
|
|
}
|
|
}
|
|
function saveSMART() {
|
|
$('input[value="Download"]').val('Downloading...').prop('disabled',true);
|
|
$.post('/webGui/include/SmartInfo.php',{cmd:'save',port:'<?=addslashes(htmlspecialchars($dev))?>',name:'<?=addslashes(htmlspecialchars($name))?>',file:'<?=addslashes(htmlspecialchars($file))?>'}, function() {
|
|
$.post('/webGui/include/Download.php',{cmd:'save',source:'<?=addslashes(htmlspecialchars($file))?>',file:'<?=addslashes(htmlspecialchars($zip))?>'},function(zip) {
|
|
location = zip;
|
|
setTimeout(cleanUp,4000);
|
|
});
|
|
});
|
|
}
|
|
function testUpdate(init) {
|
|
$.post('/webGui/include/SmartInfo.php',{cmd:'update',port:'<?=addslashes(htmlspecialchars($dev))?>',name:'<?=addslashes(htmlspecialchars($name))?>',type:'<?=addslashes(htmlspecialchars($type))?>',csrf:'<?=$var['csrf_token']?>'},function(data) {
|
|
$('#test_result').html(data);
|
|
if (data.indexOf('%')>=0) {
|
|
if ($('#smart_selftest').length) {
|
|
<?if ($spindown):?>
|
|
$('select[name="<?=addslashes(htmlspecialchars($spindown))?>"]').prop('disabled',true);
|
|
<?endif;?>
|
|
$('#smart_selftest').html('<i class="fa fa-camera"></i> S.M.A.R.T self-test in progress...');
|
|
}
|
|
if (!init) timers.testUpdate = setTimeout(testUpdate, 3000);
|
|
} else {
|
|
if ($('#smart_selftest').length) $('#smart_selftest').html('');
|
|
$('#short_test').val('Start');
|
|
$('#long_test').val('Start');
|
|
<?if ($live):?>
|
|
$('#short_test').removeAttr('disabled');
|
|
$('#long_test').removeAttr('disabled');
|
|
<?endif;?>
|
|
if (!init) {
|
|
$.removeCookie('test.<?=addslashes(htmlspecialchars($dev))?>',{path:'/'});
|
|
<?if ($spindown):?>
|
|
$('select[name="<?=addslashes(htmlspecialchars($spindown))?>"]').val(<?=spindownDelay()?>).prop('disabled',false);
|
|
$.post('/update.htm',{'<?=addslashes(htmlspecialchars($spindown))?>':<?=spindownDelay()?>,changeDisk:'apply'});
|
|
$.post('/webGui/include/SmartInfo.php',{cmd:'delete',file:'<?=addslashes(htmlspecialchars($spindown))?>'});
|
|
<?endif;?>
|
|
}
|
|
}
|
|
});
|
|
}
|
|
function selftestLog() {
|
|
$('#selftest').toggle('slow');
|
|
var text = $('#toggle_log').val()=='Show' ? 'Hide' : 'Show';
|
|
$('#toggle_log').val(text);
|
|
}
|
|
function errorLog() {
|
|
$('#errorlog').toggle('slow');
|
|
var text = $('#toggle_error').val()=='Show' ? 'Hide' : 'Show';
|
|
$('#toggle_error').val(text);
|
|
}
|
|
function startShortTest() {
|
|
if ($('#short_test').val()=='Start') {
|
|
$('#short_test').val('Stop');
|
|
$('#long_test').attr('disabled','disabled');
|
|
$.cookie('test.<?=addslashes(htmlspecialchars($dev))?>','short',{path:'/',expires:365});
|
|
$.post('/webGui/include/SmartInfo.php',{cmd:'short',port:'<?=addslashes(htmlspecialchars($dev))?>',name:'<?=addslashes(htmlspecialchars($name))?>'},function(){timers.testUpdate = setTimeout(testUpdate,0);});
|
|
<?if ($spindown):?>
|
|
$('select[name="<?=addslashes(htmlspecialchars($spindown))?>"]').val(0).prop('disabled',true);
|
|
$.post('/update.htm',{'<?=addslashes(htmlspecialchars($spindown))?>':0,changeDisk:'apply'});
|
|
<?endif;?>
|
|
} else {
|
|
clearTimeout(timers.testUpdate);
|
|
$.removeCookie('test.<?=addslashes(htmlspecialchars($dev))?>',{path:'/'});
|
|
$.post('/webGui/include/SmartInfo.php',{cmd:'stop',port:'<?=addslashes(htmlspecialchars($dev))?>',name:'<?=addslashes(htmlspecialchars($name))?>'},function(){setTimeout(testUpdate,0);});
|
|
<?if ($spindown):?>
|
|
$('select[name="<?=addslashes(htmlspecialchars($spindown))?>"]').val(<?=spindownDelay()?>).prop('disabled',false);
|
|
$.post('/update.htm',{'<?=addslashes(htmlspecialchars($spindown))?>':<?=spindownDelay()?>,changeDisk:'apply'});
|
|
$.post('/webGui/include/SmartInfo.php',{cmd:'delete',file:'<?=addslashes(htmlspecialchars($spindown))?>'});
|
|
<?endif;?>
|
|
}
|
|
}
|
|
function startLongTest() {
|
|
if ($('#long_test').val()=='Start') {
|
|
$('#long_test').val('Stop');
|
|
$('#short_test').attr('disabled','disabled');
|
|
$.cookie('test.<?=addslashes(htmlspecialchars($dev))?>','long',{path:'/',expires:365});
|
|
$.post('/webGui/include/SmartInfo.php',{cmd:'long',port:'<?=addslashes(htmlspecialchars($dev))?>',name:'<?=addslashes(htmlspecialchars($name))?>'},function(){timers.testUpdate = setTimeout(testUpdate,0);});
|
|
<?if ($spindown):?>
|
|
$('select[name="<?=addslashes(htmlspecialchars($spindown))?>"]').val(0).prop('disabled',true);
|
|
$.post('/update.htm',{'<?=addslashes(htmlspecialchars($spindown))?>':0,changeDisk:'apply'});
|
|
<?endif;?>
|
|
} else {
|
|
clearTimeout(timers.testUpdate);
|
|
$.removeCookie('test.<?=addslashes(htmlspecialchars($dev))?>',{path:'/'});
|
|
$.post('/webGui/include/SmartInfo.php',{cmd:'stop',port:'<?=addslashes(htmlspecialchars($dev))?>',name:'<?=addslashes(htmlspecialchars($name))?>'},function(){setTimeout(testUpdate,0);});
|
|
<?if ($spindown):?>
|
|
$('select[name="<?=addslashes(htmlspecialchars($spindown))?>"]').val(<?=spindownDelay()?>).prop('disabled',false);
|
|
$.post('/update.htm',{'<?=addslashes(htmlspecialchars($spindown))?>':<?=spindownDelay()?>,changeDisk:'apply'});
|
|
$.post('/webGui/include/SmartInfo.php',{cmd:'delete',file:'<?=addslashes(htmlspecialchars($spindown))?>'});
|
|
<?endif;?>
|
|
}
|
|
}
|
|
$(function() {
|
|
var smarttest = $.cookie('test.<?=addslashes(htmlspecialchars($dev))?>');
|
|
testUpdate(smarttest===undefined);
|
|
if (smarttest !== undefined) $('#'+smarttest+'_test').val('Stop').removeAttr('disabled');
|
|
<?if ($live):?>
|
|
$('#toggle_log').removeAttr('disabled');
|
|
$('#toggle_error').removeAttr('disabled');
|
|
$.post('/webGui/include/SmartInfo.php',{cmd:'selftest',port:'<?=addslashes(htmlspecialchars($dev))?>',name:'<?=addslashes(htmlspecialchars($name))?>'},function(data){$('#selftest').html(data);});
|
|
$.post('/webGui/include/SmartInfo.php',{cmd:'errorlog',port:'<?=addslashes(htmlspecialchars($dev))?>',name:'<?=addslashes(htmlspecialchars($name))?>'},function(data){$('#errorlog').html(data);});
|
|
<?endif;?>
|
|
});
|
|
</script>
|