Files
webgui/emhttp/plugins/dynamix/Selftest.page

145 lines
5.5 KiB
Plaintext

Menu="Device:2 New:2"
Title="Self-Test"
Tag="wrench"
Cond="array_key_exists($name, $disks) || array_key_exists($name, $devs)"
---
<?PHP
/* Copyright 2005-2023, Lime Technology
* Copyright 2012-2023, 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('Ymd-Hi');
$file = _var($disk,'id','no-id')."-$date.txt";
$zip = str_replace(' ','_',strtolower(_var($var,'NAME','tower')))."-smart-$date.zip";
$long = !isset($disks[$name]['spindownDelay']) || _var($disks[$name],'spindownDelay')==0 || (_var($disks[$name],'spindownDelay')==-1 && _var($var,'spindownDelay')==0);
?>
_(Download SMART report)_:
: <span class="inline-block">
<input type='button' value="_(Download)_" onclick='saveSMART()'>
</span>
_(SMART self-test history)_:
: <span class="inline-block">
<input type="button" value="_(Show)_" id="toggle_log" onclick="selftestLog()">
</span>
:selftest_history_help:
<pre id="selftest" style="display:none"></pre>
_(SMART error log)_:
: <span class="inline-block">
<input type="button" value="_(Show)_" id="toggle_error" onclick="errorLog()">
</span>
:selftest_error_log_help:
<pre id="errorlog" style="display:none"></pre>
_(SMART short self-test)_:
: <span class="inline-block">
<input type='button' value="_(Start)_" id='short_test' onclick="startShortTest()">
</span>
:selftest_short_test_help:
_(SMART extended self-test)_:
: <span class="inline-block">
<input type='button' value="_(Start)_" id='long_test' onclick="startLongTest()"<?=$long ? "" : " disabled"?>>
</span>
: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:'<?=$dev?>',name:'<?=$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:'<?=$dev?>',name:'<?=$name?>',csrf:'<?=$var['csrf_token']?>'},function(data) {
$('#test_result').html(data);
if (data.indexOf('%')>=0) {
if ($('#smart_selftest').length) {
$('#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)_").removeAttr('disabled');
$('#long_test').val("_(Start)_").removeAttr('disabled');
if (!init) {
$.removeCookie('test.<?=$dev?>');
}
}
});
}
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.<?=$dev?>','short',{expires:365});
$.post('/webGui/include/SmartInfo.php',{cmd:'short',port:'<?=$dev?>',name:'<?=$name?>'},function(){timers.testUpdate = setTimeout(testUpdate,0);});
} else {
clearTimeout(timers.testUpdate);
$.removeCookie('test.<?=$dev?>');
$.post('/webGui/include/SmartInfo.php',{cmd:'stop',port:'<?=$dev?>',name:'<?=$name?>'},function(){setTimeout(testUpdate,0);});
}
}
function startLongTest() {
if ($('#long_test').val()=="_(Start)_") {
$('#long_test').val("_(Stop)_");
$('#short_test').attr('disabled','disabled');
$.cookie('test.<?=$dev?>','long',{expires:365});
$.post('/webGui/include/SmartInfo.php',{cmd:'long',port:'<?=$dev?>',name:'<?=$name?>'},function(){timers.testUpdate = setTimeout(testUpdate,0);});
} else {
clearTimeout(timers.testUpdate);
$.removeCookie('test.<?=$dev?>');
$.post('/webGui/include/SmartInfo.php',{cmd:'stop',port:'<?=$dev?>',name:'<?=$name?>'},function(){setTimeout(testUpdate,0);});
}
}
$(function() {
var smarttest = $.cookie('test.<?=$dev?>');
testUpdate(smarttest===undefined);
if (smarttest !== undefined) $('#'+smarttest+'_test').val("_(Stop)_").removeAttr('disabled');
$.post('/webGui/include/SmartInfo.php',{cmd:'selftest',port:'<?=$dev?>',name:'<?=$name?>'},function(data){$('#selftest').html(data);});
$.post('/webGui/include/SmartInfo.php',{cmd:'errorlog',port:'<?=$dev?>',name:'<?=$name?>'},function(data){$('#errorlog').html(data);});
});
</script>