Added Pool state check before starting array

First implementation
This commit is contained in:
bergware
2023-02-07 11:43:04 +01:00
parent 0975b1e891
commit 72bb601334
2 changed files with 44 additions and 31 deletions

View File

@@ -144,36 +144,42 @@ function getFileContent(event,form) {
reader.readAsDataURL(input.files[0]);
}
function prepareInput(form) {
$(form).append('<input type="hidden" name="cmdStart" value="Start">');
if (form.input === undefined) {
form.submit();
return;
}
form.input.disabled = true;
form.local.disabled = true;
form.file.disabled = true;
form.text.disabled = true;
form.copy.disabled = true;
if (form.text.value) {
var valid = new RegExp('^[ -~]+$');
if (valid.test(form.text.value)) {
$(form).append('<input type="hidden" name="luksKey" value="'+base64(form.text.value)+'">');
form.submit();
$.post('/webGui/include/Report.php',{cmd:'state',pools:'<?=implode(',',$pools)?>'},function(state) {
if (state.length==0) {
$(form).append('<input type="hidden" name="cmdStart" value="Start">');
if (form.input === undefined) {
form.submit();
return;
}
form.input.disabled = true;
form.local.disabled = true;
form.file.disabled = true;
form.text.disabled = true;
form.copy.disabled = true;
if (form.text.value) {
var valid = new RegExp('^[ -~]+$');
if (valid.test(form.text.value)) {
$(form).append('<input type="hidden" name="luksKey" value="'+base64(form.text.value)+'">');
form.submit();
} else {
form.input.disabled = false;
form.local.disabled = false;
form.file.disabled = false;
form.text.disabled = false;
form.copy.disabled = false;
swal({title:"_(Printable Characters Only)_",text:"_(Use **ASCII** characters from space ' ' to tilde '~')_<br>_(Otherwise use the **keyfile** method for UTF8 input)_",html:true,type:'error',confirmButtonText:"_(Ok)_"});
}
return;
}
var data = {};
data['#file'] = 'unused';
data['#include'] = 'webGui/include/KeyUpload.php';
data['file'] = form.file.value;
$.post('/update.php',data,function(){form.submit();});
} else {
form.input.disabled = false;
form.local.disabled = false;
form.file.disabled = false;
form.text.disabled = false;
form.copy.disabled = false;
swal({title:"_(Printable Characters Only)_",text:"_(Use **ASCII** characters from space ' ' to tilde '~')_<br>_(Otherwise use the **keyfile** method for UTF8 input)_",html:true,type:'error',confirmButtonText:"_(Ok)_"});
swal({title:"_(Wrong Pool State)_",text:state,type:'error',html:true,confirmButtonText:"_(Ok)_"});
}
return;
}
var data = {};
data['#file'] = 'unused';
data['#include'] = 'webGui/include/KeyUpload.php';
data['file'] = form.file.value;
$.post('/update.php',data,function(){form.submit();});
});
}
function parityWarning(form) {
if (form.md_invalidslot.checked) {

View File

@@ -1,6 +1,6 @@
<?PHP
/* Copyright 2005-2021, Lime Technology
* Copyright 2012-2021, Bergware International.
/* 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,
@@ -11,7 +11,7 @@
*/
?>
<?
switch ($_POST['cmd']) {
switch ($_POST['cmd']??'') {
case 'config':
$config = "/boot/config";
$files = ['disk:0','docker:1','domain:1','flash:0','ident:1','share:0']; // config files to check
@@ -37,5 +37,12 @@ case 'notice':
$notices = file_exists($tmp) ? file($tmp,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES) : [];
echo implode("\n",array_map('unbundle',$notices));
break;
case 'state':
$pools = explode(',',$_POST['pools']);
$disks = parse_ini_file('state/disks.ini',true);
$error = [];
foreach ($pools as $pool) if ($disks[$pool]['state'] != 'STOPPED') $error[] = $pool.' - '.$disks[$pool]['state'];
echo implode('<br>',$error);
break;
}
?>