<?PHP
/* Copyright 2010, Lime Technology LLC.
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 */
/* Adapted by Bergware International (May 2012) */
?>
<form name="arrayOps" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="startState" value="<?=$var['mdState']?>">
<table class="array_status">
<?switch ($var['fsState']):
  case "Started":
?>  <tr>
    <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Started<?=(($var['startMode']=='Maintenance')?' - Maintenance Mode':'')?></strong></td>
    <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStop" value="Stop""<?=$confirm['stop']?' disabled':''?>></td>
    <td><strong>Stop</strong> will take the array off-line.
<?  if ($confirm['stop']):?>
    <br><input type="checkbox" name="confirmStop" value="OFF" onClick="arrayOps.cmdStop.disabled=!arrayOps.confirmStop.checked"> <small>Yes I want to do this</small>
<?  endif;?>
    </td>
    </tr>
<?  if ($var['fsNumUnformatted']>0):?>
      <tr>
      <td>Unformatted disk(s) present</td>
      <td><input type="submit" name="cmdFormat" value="Format" disabled><input type="hidden" name="unformatted_mask" value="<?=$var['fsUnformattedMask']?>"></td>
      <td><strong>Format</strong> will create a file system in all <strong>Unformatted</strong> disks, discarding all data currently on those disks.<br>
      <input type="checkbox" name="confirmFormat" value="OFF" onClick="arrayOps.cmdFormat.disabled=!arrayOps.confirmFormat.checked"> <small>Yes I want to do this</small>
      </td>
      </tr>
<?  endif;
    if ($var['mdResync']==0):
      if ($var['mdNumDisabled']==0):
        if ($var['mdNumInvalid']==0):
?>        <tr>
          <td>Parity is valid.</td>
          <td><input type="submit" name="cmdCheck" value="Check"></td>
          <td><strong>Check</strong> will start a Parity-Check.<br>
          <input type="checkbox" name="optionCorrect" value="correct" checked> <small>Write corrections to parity disk</small>
          </td>
          </tr>
<?        if ($var['sbSynced']==0):?>
            <tr>
            <td></td>
            <td></td>
            <td><em>Parity has not been checked yet.<em></td>
            </tr>
<?        else:?>
            <tr>
            <td></td>
            <td></td>
            <td>Last checked on <strong><?=my_time($var['sbSynced']).day_count($var['sbSynced'])?></strong>, finding <strong><?=$var['sbSyncErrs']?></strong> errors.
<?          $time = exec("grep 'sync done' /var/log/syslog | cut -f2 -d= | cut -f1 -ds");
            if ($time):?>
            <br><small>* Duration: <?=my_check($time);?></small>
<?          endif;?>
            </td></tr>
<?        endif;
        else:
          if ($var['mdInvalidDisk']==0):
?>          <tr>
            <td>Parity is invalid.</td>
            <td><input type="submit" name="cmdCheck" value="Sync"></td>
            <td><strong>Sync</strong> will start Parity-Sync.</td>
            </tr>
<?        else:?>
            <tr>
            <td>Data is invalid.</td>
            <td><input type="submit" name="cmdCheck" value="Rebuild"></td>
            <td><strong>Rebuild</strong> will start Data-Rebuild.</td>
            </tr>
<?        endif;
        endif;
      endif;
    else:
      if ($var['mdNumInvalid']==0):
        $checked = $var['mdResyncCorr']==0 ? "" : "checked";
?>      <tr>
        <td>Parity-Check in progress.</td>
        <td><input type="submit" name="cmdNoCheck" value="Cancel"></td>
         <td><strong>Cancel</strong> will stop the Parity-Check.<br>
        <input type="checkbox" name="optionCorrect" value="correct" <?=$checked?> disabled> <small>Write corrections to parity disk</small>
        </td>
        </tr>
<?    else:
        if ($var['mdInvalidDisk']==0):
?>        <tr>
          <td>Parity-Sync in progress.</td>
          <td><input type="submit" name="cmdNoCheck" value="Cancel"></td>
          <td><strong>Cancel</strong> will stop Parity-Sync.<br>
          WARNING: canceling Parity-Sync will leave the array unprotected!
          </td>
          </tr>
<?      else:?>
          <tr>
          <td>Data-Rebuild in progress.</td>
          <td><input type="submit" name="cmdNoCheck" value="Cancel"></td>
          <td><strong>Cancel</strong> will stop Data-Rebuild.<br>
          WARNING: canceling Data-Rebuild will leave the array unprotected!
          </td>
          </tr>
<?      endif;
      endif;
?>    <tr>
      <td>Total size:</td>
      <td><strong><?=my_scale($var['mdResync']*1024, $units).' '.$units?></strong></td>
      <td></td>
      </tr>
      <tr>
      <td>Current position:</td>
      <td><strong><?=my_scale($var['mdResyncPos']*1024, $units).' '.$units?> (<?=round(($var['mdResyncPos']/($var['mdResync']/100+1)), 1)?> %)</strong></td>
      <td></td>
      </tr>
      <tr>
      <td>Estimated speed:</td>
      <td><strong><?=my_scale(($var['mdResyncDb']/$var['mdResyncDt'])*1024, $units, 1).' '.$units?>/sec</strong></td>
      <td></td>
      </tr>
      <tr>
      <td>Estimated finish:</td>
      <td><strong><?=end_time(max(1,round(((($var['mdResyncDt']*(($var['mdResync']-$var['mdResyncPos'])/($var['mdResyncDb']/100+1)))/100)/60),0)))?></strong></td>
      <td></td>
      </tr>
<?    if ($var['mdNumInvalid']==0):
        if ($var['mdResyncCorr']==0):
?>        <tr>
          <td>Sync errors detected:</td>
          <td><strong><?=$var['sbSyncErrs']?></strong></td>
          </tr>
<?      else:?>
          <tr>
          <td>Sync errors corrected:</td>
          <td><strong><?=$var['sbSyncErrs']?></strong></td>
          </tr>
<?      endif;
      endif;
    endif;
    break;
  case "Mounting":
?>  <tr>
    <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Starting...</strong></td>
    <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
    <td></td>
    </tr>
<?  break;
  case "Formatting":
?>  <tr>
    <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Started, formatting...</strong></td>
    <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
    <td></td>
    </tr>
<?  break;
  case "Copying":
?>  <tr>
    <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Starting, copy <?=$var['fsCopyPrcnt']?> % complete...</strong></td>
    <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
    <td></td>
    </tr>
<?  break;
  case "Clearing":
?>  <tr>
    <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Starting, clear <?=$var['fsClearPrcnt']?> % complete...</strong></td>
    <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
    <td></td>
    </tr>
<?  break;
  case "Stopping":
?>  <tr>
    <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopping...</strong></td>
    <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStop" value="Stop" disabled></td>
    <td></td>
    </tr>
<?  break;
  case "Stopped":
    switch ($var['mdState']):
    case "STOPPED":
      if ($var['mdNumInvalid']==0):
?>      <tr>
        <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Configuration valid.</td>
        <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start"></td>
        <td><strong>Start</strong> will bring the array on-line.</td>
        </tr>
<?    else:
        if ($var['mdNumDisabled']!=0):
?>        <tr>
          <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Configuration valid.</td>
          <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start"></td>
          <td><strong>Start</strong> will bring the array on-line (array will be unprotected).</td>
          </tr>
<?      else:
          if ($var['mdInvalidDisk']==0):
?>          <tr>
            <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Configuration valid.</td>
            <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start"></td>
            <td><strong>Start</strong> will bring the array on-line and start Parity-Sync.</td>
            </tr>
<?        else:?>
            <tr>
            <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Configuration valid.</td>
            <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start"></td>
            <td><strong>Start</strong> will bring the array on-line and start Data-Rebuild.</td>
            </tr>
<?        endif;
        endif;
      endif;
?>    <tr>
      <td></td>
      <td><input type="checkbox" name="startMode" value="Maintenance"> Maintenance mode</td>
      <td></td>
      </tr>
<?    break;
    case "NEW_ARRAY":
?>    <tr>
      <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Initial configuration</td>
      <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start"></td><td><strong>Start</strong> will record all disk information, bring the array on-line, and start Parity-Sync (if <em>parity</em> is present).
       The array is immediately available, but is unprotected until Parity-Sync completes.</td>
      </tr>
      <tr>
      <td></td>
      <td><input type="checkbox" name="md_invalidslot" value="99"> Parity is valid</td>
      <td></td>
      </tr>
      <tr>
      <td></td>
      <td><input type="checkbox" name="startMode" value="Maintenance"> Maintenance mode</td>
      <td></td>
      </tr>
<?    break;
    case "UNPROTECTED_EXPANSION":
?>    <tr>
      <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Found <?=$var['mdNumNew']?> new disk(s).</td>
      <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start"></td>
      <td><strong>Start</strong> will record the new disk information and bring the expanded array on-line.</td>
      </tr>
      <tr>
      <td></td>
      <td><input type="checkbox" name="startMode" value="Maintenance"> Maintenance mode</td>
      <td></td>
      </tr>
<?    break;
    case "PROTECTED_EXPANSION":
?>    <tr>
      <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Found <?=$var['mdNumNew']?> new disk(s).</td>
      <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
      <td><strong>Start</strong> will record the new disk information and bring the expanded array on-line. All new disks which have not been factory-erased will be cleared first; and, the array will be available after the clear completes. This process takes time, but the array remains protected at all times. Caution: any
      data on the new disk(s) will be erased! If you want to preserve the data on
      the new disk(s), reset the array configuration and rebuild parity instead.<br>
      <input type="checkbox" name="confirmStart" value="OFF" onClick="arrayOps.cmdStart.disabled=!arrayOps.confirmStart.checked"> <small>Yes I want to do this</small>
      </td>
      </tr>
      <tr>
      <td></td>
      <td><input type="checkbox" name="startMode" value="Maintenance"> Maintenance mode</td>
      <td></td>
      </tr>
<?    break;
    case "DISABLE_DISK":
      if ($var['mdMissingDisk']==0):
?>      <tr>
        <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Missing <em>parity</em>.</td>
        <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
        <td><strong>Start</strong> will disable the <em>parity</em> disk and then bring the array on-line. The array
        will be unprotected; install a new <em>parity</em> disk as soon as possible.<br>
        <input type="checkbox" name="confirmStart" value="OFF" onClick="arrayOps.cmdStart.disabled=!arrayOps.confirmStart.checked"> <small>Yes I want to do this</small>
        </td>
        </tr>
<?    else:?>
        <tr>
        <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Missing disk.</td>
        <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
        <td><strong>Start</strong> will disable the missing disk and then bring the array on-line. The disks data will be available, but the array
        will be unprotected; install a new disk as soon as possible.<br>
        <input type="checkbox" name="confirmStart" value="OFF" onClick="arrayOps.cmdStart.disabled=!arrayOps.confirmStart.checked"> <small>Yes I want to do this</small>
        </td>
        </tr>
<?    endif;?>
      <tr>
      <td></td>
      <td><input type="checkbox" name="startMode" value="Maintenance"> Maintenance mode</td>
      <td></td>
      </tr>
<?    break;
    case "RECON_DISK":
      if ($var['mdDisabledDisk']==0):
?>      <tr>
        <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. New <em>parity</em> disk installed.</td>
        <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
        <td><strong>Start</strong> will bring the array on-line and start Parity-Sync.<br>
        <input type="checkbox" name="confirmStart" value="OFF" onClick="arrayOps.cmdStart.disabled=!arrayOps.confirmStart.checked"> <small>Yes I want to do this</small>
        </td>
        </tr>
<?    else:?>
        <tr>
        <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Disabled disk replaced.</td>
        <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
        <td><strong>Start</strong> will bring the array on-line, start Data-Rebuild,  and then  expand the file system (if possible).<br>
        <input type="checkbox" name="confirmStart" value="OFF" onClick="arrayOps.cmdStart.disabled=!arrayOps.confirmStart.checked"> <small>Yes I want to do this</small>
        </td>
        </tr>
<?    endif;?>
      <tr>
      <td></td>
      <td><input type="checkbox" name="startMode" value="Maintenance"> Maintenance mode</td>
      <td></td>
      </tr>
<?    break;
    case "UPGRADE_DISK":
      if ($var['mdMissingDisk']==0):
?>      <tr>
        <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Upgrading <em>parity</em>.</td>
        <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
        <td><strong>Start</strong> will bring the array on-line and start Parity-Sync.<br>
        <input type="checkbox" name="confirmStart" value="OFF" onClick="arrayOps.cmdStart.disabled=!arrayOps.confirmStart.checked"> <small>Yes I want to do this</small>
        </td>
        </tr>
<?    else:?>
        <tr>
        <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Upgrading disk.</td>
        <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
        <td><strong>Start</strong> will bring the array on-line, start Data-Rebuild, and then expand the file system.<br>
        <input type="checkbox" name="confirmStart" value="OFF" onClick="arrayOps.cmdStart.disabled=!arrayOps.confirmStart.checked"> <small>Yes I want to do this</small>
        </td>
        </tr>
<?    endif;?>
      <tr>
      <td></td>
      <td><input type="checkbox" name="startMode" value="Maintenance"> Maintenance mode</td>
      <td></td>
      </tr>
<?    break;
    case "SWAP_DSBL":
?>    <tr>
      <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Ugrading disk/swapping parity.</td>
      <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
      <td><strong>Start</strong> will  copy the parity information to the new <em>parity</em> disk, expand the file system  of the data disk (if possible); and then bring the array on-line and start Data-Rebuild.<br>
      <input type="checkbox" name="confirmStart" value="OFF" onClick="arrayOps.cmdStart.disabled=!arrayOps.confirmStart.checked"> <small>Yes I want to do this</small>
      </td>
      </tr>
      <tr>
      <td></td>
      <td><input type="checkbox" name="startMode" value="Maintenance"> Maintenance mode</td>
      <td></td>
      </tr>
<?    break;
    case "RECORD_DISKS":
?>    <tr>
      <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Two or more disks are wrong.</td>
      <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
      <td><strong>Start</strong> will  just record the new disk positions and bring the array on-line. We recommend you start a
      Parity-Check afterwards just to be safe.<br>
      <input type="checkbox" name="confirmStart" value="OFF" onClick="arrayOps.cmdStart.disabled=!arrayOps.confirmStart.checked"> <small>Yes I want to do this</small>
      </td>
      </tr>
      <tr>
      <td></td>
      <td><input type="checkbox" name="startMode" value="Maintenance"> Maintenance mode</td>
      <td></td>
      </tr>
<?    break;
    case "ERROR:INVALID_EXPANSION":
?>    <tr>
      <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Invalid expansion.</td>
      <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
      <td>You may not add new disks when there exists missing, wrong, or disabled disk(s).</td>
      </tr>
<?    break;
    case "ERROR:NEW_DISK_TOO_SMALL":
?>    <tr>
      <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Replacment disk is too small.</td>
      <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
      <td>The replacement disk must be as big or bigger than the original.</td>
      </tr>
<?    break;
    case "ERROR:PARITY_NOT_BIGGEST":
?>    <tr>
      <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Disk in parity slot is not biggest.</td>
      <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
      <td>If this is a new array, move the largest disk into the <em>parity</em> slot. If you are adding a new disk or replacing a disabled disk, try Parity-Swap.</td>
      </tr>
<?    break;
    case "ERROR:TOO_MANY_MISSING_DISKS":
?>    <tr>
      <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. Invalid configuration.</td>
      <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
      <td>Too many wrong and/or missing disks!</td>
      </tr>
<?    break;
    case "ERROR:NO_DATA_DISKS":
?>    <tr>
      <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. No data disks.</td>
      <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
      <td>No array data disks have been assigned!</td>
      </tr>
<?    break;
    case "ERROR:NO_RAID_DISKS":
?>    <tr>
      <td><img src="<?=$root?>/style/<?=$var['mdColor']?>.gif" class="icon"><strong>Stopped</strong>. No devices.</td>
      <td><input type="button" value="Refresh" onclick="refresh();"><input type="submit" name="cmdStart" value="Start" disabled></td>
      <td>No array disk devices have been assigned!</td>
      </tr>
<?    break;
    endswitch;
  endswitch;
?></table>
</form>

<p class=ContentTitle></p>
<hr>
<form name="otherOps" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="startState" value="<?=$var['mdState']?>">
<table class="array_status">
<?switch ($var['fsState']):
  case "Started":
?>  <tr>
    <td></td>
    <td><input type="submit" name="cmdSpinUpAll" value="Spin Up"></td>
    <td><strong>Spin Up</strong> will immediately spin up all disks.</td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="cmdSpinDownAll" value="Spin Down"></td>
    <td><strong>Spin Down</strong> will immediately spin down all disks.</td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="clearStatistics" value="Clear Statistics"></td>
    <td><strong>Clear Statistics</strong> will immediately clear all disk statistics.</td>
    </tr>
<?  break;
  case "Stopped":
?>  <tr>
    <td></td>
    <td><input type="submit" name="cmdIdentify" value="Identify"></td>
    <td><strong>Identify</strong> will briefly read from each disk in order.</td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="reboot" value="Reboot"<?=$confirm['down']?' disabled':''?>></td>
    <td><strong>Reboot</strong> will activate a system reset.
<?  if ($confirm['down']):?>
    <br><input type="checkbox" name="confirmReboot" value="OFF" onClick="otherOps.reboot.disabled=!otherOps.confirmReboot.checked"> <small>Yes I want to do this</small>
<?  endif;?>
    </td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="shutdown" value="Power down"<?=$confirm['down']?' disabled':''?>></td>
    <td><strong>Power down</strong> will activate a <em>clean</em> power down.
<?  if ($confirm['down']):?>
    <br><input type="checkbox" name="confirmShutdown" value="OFF" onClick="otherOps.shutdown.disabled=!otherOps.confirmShutdown.checked"> <small>Yes I want to do this</small>
<?  endif;?>
    </td>
    </tr>
<?  break;
  endswitch;?>
</table>
</form>
<?$confirm['warn'] = false;?>