Menu="OtherSettings"
Title="Disk Settings"
Icon="icon-disks"
Tag="icon-disk"
---
<?PHP
/* Copyright 2005-2025, Lime Technology
 * Copyright 2012-2025, 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.
 */
?>
<?
require_once "$docroot/webGui/include/Preselect.php";
$events = explode('|',$var['smEvents'] ?? $numbers);

$default = parse_ini_file("$docroot/webGui/default.cfg",true);
$reply   = '/var/tmp/luks.reply';
$keyfile = is_file($var['luksKeyfile']);
$encrypt = false;
foreach ($disks as $disk) if (isset($disk['fsType']) && strncmp($disk['fsType'],'luks:',5)===0) $encrypt = true;
?>
<script>
String.prototype.celsius = function(){return Math.round((parseInt(this)-32)*5/9).toString();}

function base64(str) {
  return window.btoa(unescape(encodeURIComponent(str)));
}

function doDispatch(form) {
  var fields = {};
<?if ($display['unit']=='F'):?>
  form.display_hot.value = form.display_hot.value.celsius();
  form.display_max.value = form.display_max.value.celsius();
  form.display_hotssd.value = form.display_hotssd.value.celsius();
  form.display_maxssd.value = form.display_maxssd.value.celsius();
<?endif;?>
  fields['#cfg'] = "/boot/config/plugins/dynamix/dynamix.cfg";
  fields['#cleanup'] = true;
  $(form).find('input[name^="display_"]').each(function(){fields[$(this).attr('name')] = $(this).val(); $(this).prop('disabled',true);});
  $(form).find('select[name^="display_"]').each(function(){fields[$(this).attr('name')] = $(this).val(); $(this).prop('disabled',true);});
  $.post('/webGui/include/Dispatcher.php',fields);
}

function prepareDiskSettings(form) {
  var events = [];
  for (var i=0; i < <?=count($preselect)?>; i++) {
    if (form.elements['at'+i].checked) events.push(form.elements['at'+i].value);
    form.elements['at'+i].disabled = true;
  }
  var custom = form.smCustom.value.trim();
  var custom = custom.length ? custom.split(',') : [];
  for (var i=0; i < custom.length; i++) events.push(custom[i].trim());
  form.smEvents.value = events.join('|');
  if (form.smEvents.value == '<?=$numbers?>') form.smEvents.value = '';
  if (form.smLevel.value == 1.00) form.smLevel.value = '';
}

function setIndex(form) {
  form.smIndex.value = form.smType.selectedIndex;
}

function prepareForm(form) {
<?if (!$keyfile):?>
  form.oldluks.value = base64(form.oldtext.value.replace(/\\"/g,'"'));
  form.oldtext.disabled = true;
  form.oldfile.disabled = true;
<?endif;?>
  var valid = new RegExp('^[ -~]+$');
  if (form.newinput.value == 'file') return true;
  if (valid.test(form.newtext.value)) {
    form.newluks.value = base64(form.newtext.value.replace(/\\"/g,'"'));
    form.newtext.disabled = true;
    form.newcopy.disabled = true;
    form.newfile.disabled = true;
    return true;
  } else {
    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 false;
  }
}

function getFileContent(event,form,file) {
  var input = event.target;
  var reader = new FileReader();
  reader.onload = function(){$(form).find('input[name="'+file+'"]').val(reader.result);};
  reader.readAsDataURL(input.files[0]);
}

function selectInput(val,old) {
  if (val=='text') {
    if (old==true) {
      $('div#oldfile').hide('slow');
      $('div#oldtext').show('slow');
    } else {
      $('div#newfile').hide('slow');
      $('div#newtext').show('slow');
      $('input[name="newkey"]').prop('disabled',$('input[name="newtext"]').val() == '' || $('input[name="newtext"]').val() != $('input[name="newcopy"]').val());
    }
  } else if (val=='file') {
    if (old==true) {
      $('div#oldtext').hide('slow');
      $('div#oldfile').show('slow');
    } else {
      $('div#newtext').hide('slow');
      $('div#newfile').show('slow');
      $('input[name="newkey"]').prop('disabled',$('input[name="newfile"]').val() == '');
    }
  }
}

function showInput(show, old) {
  if (old==true) {
    var input = $('input[name="oldtext"]');
  } else {
    var input = $('input[name="newtext"],input[name="newcopy"]');
  }
  input.attr('type', show ? 'text' : 'password');
}

function checkInput(form) {
  $(form).find('input[name="newkey"]').prop('disabled',form.newtext.value == '' || form.newtext.value != form.newcopy.value);
}

<?if (is_file($reply)):?>
<?[$text,$type] = explode("\0",file_get_contents($reply)); unlink($reply);?>
$(function() {
  swal({
    title:"_(Encryption Key Update)_",
    text:"<?=$text?>",
    html:true,
    type:"<?=$type?>",
    confirmButtonText:"_(Ok)_"
  });
});
<?endif;?>
</script>

<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onsubmit="doDispatch(this)">
_(Enable auto start)_:
: <select name="startArray">
  <?=mk_option($var['startArray'], "no", _('No'))?>
  <?=mk_option($var['startArray'], "yes", _('Yes'))?>
  </select>

:disk_enable_autostart_help:

_(Default spin down delay)_:
: <select name="spindownDelay">
  <?=mk_option($var['spindownDelay'], "0",  _('Never'))?>
  <?=mk_option($var['spindownDelay'], "15", "15 "._('minutes'))?>
  <?=mk_option($var['spindownDelay'], "30", "30 "._('minutes'))?>
  <?=mk_option($var['spindownDelay'], "45", "45 "._('minutes'))?>
  <?=mk_option($var['spindownDelay'], "1",  "1 "._('hour'))?>
  <?=mk_option($var['spindownDelay'], "2",  "2 "._('hours'))?>
  <?=mk_option($var['spindownDelay'], "3",  "3 "._('hours'))?>
  <?=mk_option($var['spindownDelay'], "4",  "4 "._('hours'))?>
  <?=mk_option($var['spindownDelay'], "5",  "5 "._('hours'))?>
  <?=mk_option($var['spindownDelay'], "6",  "6 "._('hours'))?>
  <?=mk_option($var['spindownDelay'], "7",  "7 "._('hours'))?>
  <?=mk_option($var['spindownDelay'], "8",  "8 "._('hours'))?>
  <?=mk_option($var['spindownDelay'], "9",  "9 "._('hours'))?>
  </select>

:disk_spindown_delay_help:

_(Enable spinup groups)_:
: <select name="spinupGroups">
  <?=mk_option($var['spinupGroups'], "no", _('No'))?>
  <?=mk_option($var['spinupGroups'], "yes", _('Yes'))?>
  </select>

:disk_spinup_groups_help:

_(Default file system for Array disks)_:
: <select name="defaultFsType">
  <?=mk_option($var['defaultFsType'], "xfs", _('xfs'));?>
  <?=mk_option($var['defaultFsType'], "zfs", _('zfs'));?>
  <?=mk_option($var['defaultFsType'], "btrfs", _('btrfs'));?>
  <?=mk_option($var['defaultFsType'], "ext4", _('ext4'));?>
  <?=mk_option($var['defaultFsType'], "reiserfs", _('reiserfs'), "disabled");?>
  <?=mk_option($var['defaultFsType'], "luks:xfs", _('xfs')." - "._('encrypted'));?>
  <?=mk_option($var['defaultFsType'], "luks:zfs", _('zfs')." - "._('encrypted'));?>
  <?=mk_option($var['defaultFsType'], "luks:btrfs", _('btrfs')." - "._('encrypted'));?>
  <?=mk_option($var['defaultFsType'], "luks:ext4", _('ext4')." - "._('encrypted'));?>
  <?=mk_option($var['defaultFsType'], "luks:reiserfs", _('reiserfs')." - "._('encrypted'), "disabled");?>
  </select>

:disk_default_file_system_help:

_(Shutdown time-out)_ (_(seconds)_):
: <input type="number" name="shutdownTimeout" maxlength="10" value="<?=$var['shutdownTimeout']?>" placeholder="90">

:disk_shutdown_timeout_help:

_(Tunable (poll_attributes))_:
: <input type="number" name="poll_attributes" maxlength="10" value="<?=$var['poll_attributes']?>" placeholder="<?=$var['poll_attributes_default']?>">

:disk_tunable_poll_attributes_help:

_(Tunable (enable NCQ))_:
: <select name="queueDepth">
  <?=mk_option($var['queueDepth'], "auto", _('Auto'))?>
  <?=mk_option($var['queueDepth'], "1", _('No'))?>
  </select>

:disk_tunable_enable_ncq_help:

_(Tunable (nr_requests))_:
: <input type="text" name="nr_requests" maxlength="10" value="<?=htmlspecialchars($var['nr_requests'])?>" placeholder="<?=_($var['nr_requests_default'])?>">

:disk_tunable_nr_requests_help:

_(Tunable (scheduler))_:
: <select name="md_scheduler">
  <?=mk_option($var['md_scheduler'], "auto", _('Auto'))?>
  <?=mk_option($var['md_scheduler'], "mq-deadline", _('mq-deadline'))?>
  <?=mk_option($var['md_scheduler'], "kyber", _('kyber'))?>
  <?=mk_option($var['md_scheduler'], "bfq", _('bfq'))?>
  <?=mk_option($var['md_scheduler'], "none", _('none'))?>
  </select>

:disk_tunable_scheduler_help:

_(Tunable (md_num_stripes))_:
: <input type="number" name="md_num_stripes" maxlength="10" value="<?=$var['md_num_stripes']?>" placeholder="<?=$var['md_num_stripes_default']?>">

:disk_tunable_md_num_stripes_help:

_(Tunable (md_queue_limit))_:
: <input type="number" name="md_queue_limit" maxlength="10" value="<?=$var['md_queue_limit']?>" placeholder="<?=$var['md_queue_limit_default']?>">

:disk_tunable_md_queue_limit_help:

_(Tunable (md_sync_limit))_:
: <input type="number" name="md_sync_limit" maxlength="10" value="<?=$var['md_sync_limit']?>" placeholder="<?=$var['md_sync_limit_default']?>">

:disk_tunable_md_sync_limit_help:

_(Tunable (md_write_method))_:
: <select name="md_write_method">
  <?=mk_option($var['md_write_method'], "auto", _('Auto'))?>
  <?=mk_option($var['md_write_method'], "0", _('read/modify/write'))?>
  <?=mk_option($var['md_write_method'], "1", _('reconstruct write'))?>
  </select>

:disk_tunable_md_write_method_help:

_(Enable NVME power monitoring)_:
: <select name="display_power">
  <?=mk_option($display['power'], "", _('No'))?>
  <?=mk_option($display['power'], "1", _('Yes'))?>
  </select>

_(Default warning disk utilization threshold)_ (%):
: <input type="number" min="0" max="100" name="display_warning" value="<?=$display['warning']?>" placeholder="<?=$default['display']['warning']?>">

:disk_default_warning_utilization_help:

_(Default critical disk utilization threshold)_ (%):
: <input type="number" min="0" max="100" name="display_critical" value="<?=$display['critical']?>" placeholder="<?=$default['display']['critical']?>">

:disk_default_critical_utilization_help:

_(Default warning disk temperature threshold)_ (&deg;<?=_var($display,'unit','C')?>):
: <input type="number" min="0" max="300" name="display_hot" value="<?=displayTemp($display['hot'])?>" placeholder="<?=displayTemp($default['display']['hot'])?>">

:disk_default_warning_temperature_help:

_(Default critical disk temperature threshold)_ (&deg;<?=_var($display,'unit','C')?>):
: <input type="number" min="0" max="300" name="display_max" value="<?=displayTemp($display['max'])?>" placeholder="<?=displayTemp($default['display']['max'])?>">

:disk_default_critical_temperature_help:

_(Default warning SSD temperature threshold)_ (&deg;<?=_var($display,'unit','C')?>):
: <input type="number" min="0" max="300" name="display_hotssd" value="<?=displayTemp($display['hotssd'])?>" placeholder="<?=displayTemp($default['display']['hotssd'])?>">

:ssd_default_warning_temperature_help:

_(Default critical SSD temperature threshold)_ (&deg;<?=_var($display,'unit','C')?>):
: <input type="number" min="0" max="300" name="display_maxssd" value="<?=displayTemp($display['maxssd'])?>" placeholder="<?=displayTemp($default['display']['maxssd'])?>">

:ssd_default_critical_temperature_help:

&nbsp;
: <span class="inline-block">
    <input type="submit" name="changeDisk" value="_(Apply)_" disabled>
    <input type="button" value="_(Done)_" onclick="done()">
  </span>
</form>

<?if ($encrypt && $var['fsState']=='Started'):?>
<div class="title">
  <span class="left">
    <i class="title fa fa-key"></i>_(Change encryption key)_
  </span>
</div>
<form markdown="1" method="POST" action="/update.php" target="progressFrame" onsubmit="return prepareForm(this)">
<input type="hidden" name="#file" value="">
<input type="hidden" name="#include" value="/webGui/include/update.encryption.php">
<input type="hidden" name="#reply" value="<?=$reply?>">
<input type="hidden" name="newdata" value="">
<input type="hidden" name="newluks" value="">
<?if (!$keyfile):?>
<input type="hidden" name="olddata" value="">
<input type="hidden" name="oldluks" value="">
<?endif;?>

_(Existing encryption key)_:
: <select name="oldinput" class="lock" onchange='selectInput(this.value,true)' <?=$keyfile?'disabled':''?>>
  <?=mk_option(1,'text',_('Passphrase'))?>
  <?=mk_option(1,'file',_('Keyfile'),$keyfile ? 'selected' : '')?>
  </select>

<?if (!$keyfile):?>
<div markdown="1" id="oldtext">
_(Enter existing passphrase)_:
: <div class="flex flex-row items-center gap-2">
    <input type="password" name="oldtext" class="lock" maxlength="512" value="" autocomplete="off" spellcheck="false">
    <label for="showPass">
      <input name="showPass" type="checkbox" class="lock" onchange="showInput(this.checked,true)">
      _(show passphrase)_
    </label>
  </div>

</div>
<div markdown="1" id="oldfile" style="display:none">
_(Select existing keyfile)_:
: <input type="file" name="oldfile" class="lock" onchange="getFileContent(event,this.form,'olddata')">

</div>
<?endif;?>

_(Change encryption key)_:
: <select name="newinput" class="lock" onchange='selectInput(this.value,false)'>
  <?=mk_option(1,'text',_('Passphrase'))?>
  <?=mk_option(1,'file',_('Keyfile'))?>
  </select>

<div markdown="1" id="newtext">
_(Type new passphrase)_:
: <div class="flex flex-row items-center gap-2">
    <input type="password" name="newtext" class="lock" maxlength="512" value="" autocomplete="off" spellcheck="false" onkeyup="checkInput(this.form)" placeholder="_(use printable characters only)_">
    <label for="showPass">
      <input name="showPass" type="checkbox" class="lock" onchange="showInput(this.checked,false)">
      _(show passphrase)_
    </label>
  </div>

_(Retype new passphrase)_:
: <input type="password" name="newcopy" class="lock" maxlength="512" value="" autocomplete="off" spellcheck="false" onkeyup="checkInput(this.form)">

</div>
<div markdown="1" id="newfile" style="display:none">
_(Select new keyfile)_:
: <input type="file" name="newfile" onchange="getFileContent(event,this.form,'newdata')">

</div>
&nbsp;
: <span class="inline-block">
    <input type="submit" name="newkey" value="_(Apply)_" disabled>
    <input type="button" value="_(Done)_" onclick="done()">
  </span>
</form>
<?endif;?>

<div class="title">
  <span class="left">
    <i class="title fa fa-plus-square"></i>_(Global SMART Settings)_
  </span>
</div>
<form markdown="1" name="smart_settings" method="POST" action="/update.php" target="progressFrame" onsubmit="prepareDiskSettings(this)">
<input type="hidden" name="#file" value="/boot/config/smart-all.cfg">
<input type="hidden" name="#include" value="webGui/include/update.smart.php">
<input type="hidden" name="#cleanup" value="true">
<input type="hidden" name="#top" value="1">
<input type="hidden" name="smEvents" value="">
<input type="hidden" name="smIndex" value="0">

_(Default SMART notification value)_:
: <select name="smSelect">
  <?=mk_option(_var($var,'smSelect'), "0", _('Raw'))?>
  <?=mk_option(_var($var,'smSelect'), "1", _('Normalized'))?>
  </select>

:disk_default_smart_notification_help:

_(Default SMART notification tolerance level)_:
: <select name="smLevel">
  <?=mk_option(_var($var,'smLevel'), "1.00", _('Absolute'))?>
  <?=mk_option(_var($var,'smLevel'), "1.05", "5%")?>
  <?=mk_option(_var($var,'smLevel'), "1.10", "10%")?>
  <?=mk_option(_var($var,'smLevel'), "1.15", "15%")?>
  <?=mk_option(_var($var,'smLevel'), "1.20", "20%")?>
  <?=mk_option(_var($var,'smLevel'), "1.25", "25%")?>
  <?=mk_option(_var($var,'smLevel'), "1.50", "50%")?>
  </select>

:disk_default_smart_tolerance_help:

_(Default SMART controller type)_:
: <select name="smType" onchange="setIndex(this.form)">
  <?=mk_option(_var($var,'smType'), "", _('Automatic'))?>
  <?=mk_option(_var($var,'smType'), "-d ata", "ATA")?>
  <?=mk_option(_var($var,'smType'), "-d nvme", "NVMe")?>
  <?=mk_option(_var($var,'smType'), "-d sat", "SAT")?>
  <?=mk_option(_var($var,'smType'), "-d scsi", "SCSI")?>
  <?=mk_option(_var($var,'smType'), "-d 3ware", "3Ware")?>
  <?=mk_option(_var($var,'smType'), "-d aacraid", "Adaptec")?>
  <?=mk_option(_var($var,'smType'), "-d areca", "Areca")?>
  <?=mk_option(_var($var,'smType'), "-d hpt", "HighPoint")?>
  <?=mk_option(_var($var,'smType'), "-d cciss", "HP cciss")?>
  <?=mk_option(_var($var,'smType'), "-d marvell", "Marvell")?>
  <?=mk_option(_var($var,'smType'), "-d megaraid", "MegaRAID")?>
  <?=mk_option(_var($var,'smType'), "-d usbcypress", "Cypress ATACB")?>
  <?=mk_option(_var($var,'smType'), "-d usbjmicron", "JMicron ATA pass-through")?>
  <?=mk_option(_var($var,'smType'), "-d usbprolific", "Prolific ATA pass-through")?>
  <?=mk_option(_var($var,'smType'), "-d usbsunplus", "Sunplus ATA pass-through")?>
  <?=mk_option(_var($var,'smType'), "-d sntasmedia", "ASMedia NVMe pass-through")?>
  <?=mk_option(_var($var,'smType'), "-d sntjmicron", "JMicron NVMe pass-through")?>
  <?=mk_option(_var($var,'smType'), "-d sntrealtek", "Realtek NVMe pass-through")?>
  </select>

:disk_default_smart_controller_help:

_(Default SMART attribute notifications)_:
: <input type="text" name="smCustom" value="<?=htmlspecialchars(_var($var,'smCustom'))?>"><span class="input-instructions">_(Custom attributes (use comma to separate numbers))_</span>

<?for ($x = 0; $x < count($preselect); $x++):?>
&nbsp;
: <span>
    <input type="checkbox" name="at<?=$x?>" value="<?=_var($preselect[$x],'code')?>" <?=in_array(_var($preselect[$x],'code'),$events)?' checked':''?>>
    <span class="code">
      _(Attribute)_ = <?=_var($preselect[$x],'code')?>
    </span>
    <?=_var($preselect[$x],'text')?>
  </span>
<?endfor;?>

:disk_default_smart_attribute_help:

<input type="submit" name="#default" value="_(Default)_">
: <span class="inline-block">
    <input type="submit" name="#apply" value="_(Apply)_" disabled>
    <input type="button" value="_(Done)_" onclick="done()">
  </span>
</form>
