diff --git a/plugins/dynamix/include/DeviceList.php b/plugins/dynamix/include/DeviceList.php index bfe20b319..8ac0f5f4d 100644 --- a/plugins/dynamix/include/DeviceList.php +++ b/plugins/dynamix/include/DeviceList.php @@ -27,7 +27,7 @@ require_once "$docroot/webGui/include/CustomMerge.php"; function in_parity_log($log,$timestamp) { if (file_exists($log)) { $handle = fopen($log, 'r'); - while (($line = fgets($handle)) !== false) { + while (($line = fgets($handle))!==false) { if (strpos($line,$timestamp)!==false) break; } fclose($handle); @@ -35,7 +35,7 @@ function in_parity_log($log,$timestamp) { return !empty($line); } function device_info(&$disk,$online) { - global $path, $var, $show; + global $path, $var, $crypto; $name = $disk['name']; $fancyname = $disk['type']=='New' ? $name : my_disk($name); $type = $disk['type']=='Flash' || $disk['type']=='New' ? $disk['type'] : 'Device'; @@ -58,7 +58,7 @@ function device_info(&$disk,$online) { } $status = "$ctrl$help"; $link = (strcmp($disk['status'], 'DISK_NP')!=0 || $disk['name']=="cache") ? "".$fancyname."" : $fancyname; - if ($show && $online) switch ($disk['luksState']) { + if ($crypto && $online) switch ($disk['luksState']) { case 0: $luks = ""; break; case 1: $luks = "Encrypted and unlocked"; break; case 2: $luks = "Locked: missing encryption key"; break; @@ -90,7 +90,7 @@ function assignment(&$disk) { $out .= ""; } else $out .= ""; - if ($disk['type']=="Cache") + if ($disk['type']=='Cache') foreach ($devs as $dev) {$out .= "";} else foreach ($devs as $dev) if ($dev['tag']==0) {$out .= "";} @@ -123,22 +123,26 @@ function fs_info(&$disk) { function my_diskio($data) { return my_scale($data,$unit,1)." $unit/s"; } +function parity_only($disk) { + return $disk['type']=='Parity'; +} +function data_only($disk) { + return $disk['type']=='Data'; +} +function cache_only($disk) { + return $disk['type']=='Cache'; +} function array_offline(&$disk) { global $var, $disks; - if (strpos($var['mdState'],"ERROR:")===false) { - $w = 'All existing data on this device will be OVERWRITTEN when array is Started'; - if ($disk['type']=="Cache") { - if (!empty($disks['cache']['uuid']) && $disk['status']=="DISK_NEW") $warning = $w; - } - else { - if ($var['mdState']=="NEW_ARRAY") { - if ($disk['type']=="Parity") $warning = $w; - } - else { - if ($disk['status']=="DISK_INVALID" || - $disk['status']=="DISK_DSBL_NEW" || - $disk['status']=="DISK_WRONG" || - $disk['status']=="DISK_NEW") $warning = $w; + if (strpos($var['mdState'],'ERROR:')===false) { + $text = 'All existing data on this device will be OVERWRITTEN when array is Started'; + if ($disk['type']=='Cache') { + if (!empty($disks['cache']['uuid']) && $disk['status']=='DISK_NEW') $warning = $text; + } else { + if ($var['mdState']=='NEW_ARRAY') { + if ($disk['type']=='Parity') $warning = $text; + } else { + if (in_array($disk['status'],['DISK_INVALID','DISK_DSBL_NEW','DISK_WRONG','DISK_NEW'])) $warning = $text; } } } @@ -302,24 +306,26 @@ function cache_slots() { $out .= ""; return $out; } -$show = false; +$crypto = false; switch ($_POST['device']) { case 'array': - foreach ($disks as $disk) if ($disk['type']=='Data') $show |= strpos($disk['fsType'],'luks:')!==false; + $parity = array_filter($disks,'parity_only'); + $data = array_filter($disks,'data_only'); + foreach ($data as $disk) $crypto |= strpos($disk['fsType'],'luks:')!==false; if ($var['fsState']=='Stopped') { - foreach ($disks as $disk) {if ($disk['type']=='Parity') array_offline($disk);} + foreach ($parity as $disk) array_offline($disk); echo ""; - foreach ($disks as $disk) {if ($disk['type']=='Data') array_offline($disk);} + foreach ($data as $disk) array_offline($disk); echo "Slots:".array_slots().""; } else { - foreach ($disks as $disk) {if ($disk['type']=='Parity' && $disk['status']!='DISK_NP_DSBL') array_online($disk);} - foreach ($disks as $disk) {if ($disk['type']=='Data') array_online($disk);} + foreach ($parity as $disk) if ($disk['status']!='DISK_NP_DSBL') array_online($disk); + foreach ($data as $disk) array_online($disk); if ($display['total']) show_totals('Array of '.my_word($var['mdNumDisks']).' devices'); } break; case 'flash': $disk = &$disks['flash']; - $data = $diskio ? explode(' ',$diskio[$disk['device']]) : []; + $data = explode(' ',$diskio[$disk['device']] ?? ''); $disk['fsUsed'] = $disk['fsSize']-$disk['fsFree']; echo ""; echo "".device_info($disk,true).""; @@ -332,19 +338,20 @@ case 'flash': echo ""; break; case 'cache': - foreach ($disks as $disk) if ($disk['type']=='Cache') $show |= strpos($disk['fsType'],'luks:')!==false; + $cache = array_filter($disks,'cache_only'); + foreach ($cache as $disk) $crypto |= strpos($disk['fsType'],'luks:')!==false; if ($var['fsState']=='Stopped') { - foreach ($disks as $disk) {if ($disk['type']=='Cache') array_offline($disk);} + foreach ($cache as $disk) array_offline($disk); echo "Slots:".cache_slots().""; } else { - foreach ($disks as $disk) {if ($disk['type']=='Cache') array_online($disk);} + foreach ($cache as $disk) array_online($disk); if ($display['total'] && $var['cacheSbNumDisks']>1) show_totals('Pool of '.my_word($var['cacheNumDevices']).' devices'); } break; case 'open': foreach ($devs as $disk) { $dev = $disk['device']; - $data = $diskio ? explode(' ',$diskio[$dev]) : []; + $data = explode(' ',$diskio[$dev] ?? ''); $disk['name'] = $dev; $disk['type'] = 'New'; $disk['color'] = read_disk($dev,'color');