mirror of
https://github.com/unraid/webgui.git
synced 2026-01-18 15:40:09 -06:00
182 lines
8.1 KiB
Plaintext
182 lines
8.1 KiB
Plaintext
Menu="Device:2 New:2"
|
|
Title="Self-Test"
|
|
Tag="wrench"
|
|
Cond="strpos($disks[$name]['status'],'_NP')===false"
|
|
---
|
|
<?PHP
|
|
/* 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,
|
|
* 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>
|
|
|
|
:selftest_history_help:
|
|
|
|
<pre id="selftest" style="display:none"></pre>
|
|
|
|
_(SMART error log)_:
|
|
: <input type="button" value="_(Show)_" id="toggle_error" onclick="errorLog()" disabled>
|
|
|
|
:selftest_error_log_help:
|
|
|
|
<pre id="errorlog" style="display:none"></pre>
|
|
|
|
_(SMART short self-test)_:
|
|
: <input type='button' value='_(Start)_' id='short_test' onclick="startShortTest()" disabled>
|
|
|
|
:selftest_short_test_help:
|
|
|
|
_(SMART extended self-test)_:
|
|
: <input type='button' value='_(Start)_' id='long_test' onclick="startLongTest()" disabled>
|
|
|
|
:selftest_long_test_help:
|
|
|
|
_(Last SMART test result)_:
|
|
: <span id="test_result"><i class='fa fa-circle-o-notch fa-spin fa-fw'></i></span>
|
|
|
|
:selftest_result_help:
|
|
|
|
<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> _(SMART 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>
|