lots of php proofreading and html tab tidying up
This commit is contained in:
@ -9,7 +9,7 @@ date_default_timezone_set('America/Los_Angeles');
|
||||
$remove_hosts = [];
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
||||
if ($_POST['action'] === 'remove') {
|
||||
// The Remove form sends a comma‑separated string of short_id’s
|
||||
// The Remove form sends a comma-separated string of short_id’s
|
||||
if (!empty($_POST['remove_hosts'])) {
|
||||
$remove_hosts = array_filter(
|
||||
explode(',', $_POST['remove_hosts']),
|
||||
@ -156,7 +156,7 @@ if (!in_array($mode, $validModes, true)) {
|
||||
$apiConfig = [
|
||||
'cosmostat' => ['bind' => '10.200.27.20', 'port' => '5000'],
|
||||
/*'gali' => ['bind' => '10.200.27.20', 'port' => '5000'], // same as cosmostat*/
|
||||
'drive_health' => ['bind' => '0.0.0.0', 'port' => '5001'], // new API
|
||||
'drive_health' => ['bind' => '172.25.1.18', 'port' => '5001'], // new API
|
||||
];
|
||||
|
||||
/* ---------- Helper: fetch client details ---------- */
|
||||
@ -237,9 +237,6 @@ $systemComponents = $properties['system_components'] ?? [];
|
||||
$selectedHost = $clients[$selectedIdx]['hostname'] ?? 'Unknown';
|
||||
|
||||
|
||||
|
||||
/* ---- ---- */
|
||||
|
||||
/* ---- Sidebar Renderer ---- */
|
||||
|
||||
function renderSidebar(string $mode){
|
||||
@ -255,74 +252,54 @@ function renderSidebar(string $mode){
|
||||
<nav class="sidebar">
|
||||
<form method="get" id="modeForm">
|
||||
<label for="modeSelect">Mode:</label>
|
||||
<select name="mode" id="modeSelect" onchange="this.form.submit()">
|
||||
<select class="select-dark" name="mode" id="modeSelect" onchange="this.form.submit()">
|
||||
<?php foreach ($modes as $key => $label): ?><option value="<?= h($key) ?>" <?= $mode === $key ? 'selected' : '' ?>><?= h($label) ?></option>
|
||||
<?php endforeach; ?></select>
|
||||
</form>
|
||||
<p>
|
||||
|
||||
<?php if ($mode === 'drive_health'): ?>
|
||||
|
||||
<?php
|
||||
if ( !is_array($clients) || empty($clients) ) {
|
||||
// Graceful “no data” handling
|
||||
echo '<p style="margin:1rem 0; font-style:italic;">'
|
||||
. 'No hosts are available to manage at this time.'
|
||||
. '</p>';
|
||||
|
||||
<?php
|
||||
if ( !is_array($clients) || empty($clients) ) {
|
||||
// Graceful “no data” handling
|
||||
echo '<p style="margin:1rem 0; font-style:italic;">'
|
||||
. 'No hosts are available to manage at this time.'
|
||||
. '</p>';
|
||||
}
|
||||
?>
|
||||
<?php if (is_array($clients) && !empty($clients)): ?>
|
||||
<h3>Hosts</h3>
|
||||
<form method="get" id="driveHealthForm">
|
||||
<input type="hidden" name="mode" value="drive_health">
|
||||
<ul>
|
||||
<?php foreach ($clients as $c): ?>
|
||||
<?php $id = $c['short_id']; ?>
|
||||
<li>
|
||||
<label>
|
||||
<input type="checkbox" name="hosts[]" value="<?= h($id) ?>"
|
||||
<?= in_array($id, $selectedHosts, true) ? 'checked' : '' ?>>
|
||||
<?= h($c['name']) ?>
|
||||
</label>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul><p>
|
||||
<button type="submit" name="action" value="apply">Apply</button><p>
|
||||
<button type="submit" name="action" value="all">Select All</button><br>
|
||||
<button type="submit" name="action" value="none">Select None</button><p>
|
||||
</form>
|
||||
<!-- Remove host button (POST) -->
|
||||
<form method="post" id="removeForm">
|
||||
<input type="hidden" name="mode" value="drive_health">
|
||||
<input type="hidden" name="action" value="remove">
|
||||
<input type="hidden" name="remove_hosts" id="remove_hosts_input" value="">
|
||||
<button type="submit">Remove</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
?>
|
||||
<?php if (is_array($clients) && !empty($clients)): ?>
|
||||
|
||||
<?php if ($mode == 'cosmostat'): ?>
|
||||
|
||||
<input type="hidden" name="host" value="<?= h($selectedId) ?>">
|
||||
<h3>Endpoints</h3>
|
||||
<ol id="endpointList"></ol>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($mode == 'gali'): ?>
|
||||
|
||||
<h3>Shuttle Gali</h3>
|
||||
<?php endif; ?>
|
||||
<!--
|
||||
<?php if (!empty($remove_hosts)): ?>
|
||||
<h4>Remove Selected:</h4>
|
||||
<h3>Hosts</h3>
|
||||
<form method="get" id="driveHealthForm">
|
||||
<input type="hidden" name="mode" value="drive_health">
|
||||
<ul>
|
||||
<?php foreach ($remove_hosts as $sid): ?>
|
||||
<li><?= h($sid) ?></li>
|
||||
<?php foreach ($clients as $c): ?>
|
||||
<?php $id = $c['short_id']; ?>
|
||||
|
||||
<li>
|
||||
<label>
|
||||
<input type="checkbox" name="hosts[]" value="<?= h($id) ?>" <?= in_array($id, $selectedHosts, true) ? 'checked' : '' ?>><?= h($c['name']) ?>
|
||||
|
||||
</label>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
-->
|
||||
</ul><p>
|
||||
<button class="btn btn-primary" type="submit" name="action" value="apply">Apply</button><p>
|
||||
<button class="btn btn-primary" type="submit" name="action" value="all">Select All</button><p>
|
||||
<button class="btn btn-primary" type="submit" name="action" value="none">Select None</button><p>
|
||||
</form>
|
||||
<!-- Remove host button (POST) -->
|
||||
<form method="post" id="removeForm">
|
||||
<input type="hidden" name="mode" value="drive_health">
|
||||
<input type="hidden" name="action" value="remove">
|
||||
<input type="hidden" name="remove_hosts" id="remove_hosts_input" value="">
|
||||
<button class="btn btn-primary" type="submit">Remove</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($mode == 'gali'): ?>
|
||||
<h3>Shuttle Gali</h3>
|
||||
<?php endif; ?>
|
||||
|
||||
</nav>
|
||||
|
||||
@ -344,7 +321,8 @@ function renderMainContent(string $mode){
|
||||
echo '<div class="card"><p>No hosts selected.</p></div>';
|
||||
return;
|
||||
}
|
||||
echo '<div class="storage_client">';
|
||||
echo '
|
||||
<div class="storage_client">';
|
||||
foreach ($selectedHosts as $sid) {
|
||||
// Find the client that matches this short_id
|
||||
$c = null;
|
||||
@ -357,41 +335,49 @@ function renderMainContent(string $mode){
|
||||
if ($c === null) continue; // safety
|
||||
|
||||
$hostname = $c['name'] ?? 'Unknown';
|
||||
echo '<div class="card">
|
||||
';
|
||||
echo '<h2>Drive Health - ' . h($hostname) . '</h2>
|
||||
<h3>IP: '.h($c['ip']).'<br>
|
||||
Timestamp: '.date('F j, Y g:i a', (int) $c['timestamp']).' </h3>
|
||||
';
|
||||
echo '
|
||||
<div class="card">
|
||||
<h2>Drive Health - ' . h($hostname) . '</h2>
|
||||
<h3>IP: '.h($c['ip']).'<br>
|
||||
Timestamp: '.date('F j, Y g:i a', (int) $c['timestamp']).' </h3>
|
||||
';
|
||||
|
||||
if (isset($c['drives']) && is_array($c['drives']) && count($c['drives']) > 0) {
|
||||
echo '<table id="host_metrics_table">';
|
||||
echo '<thead><tr><th>Drive Letter</th><th>Disk ID</th><th>Health Status</th><th>Model</th><th>Capacity</th><th>Power On Hours</th><th>Host Writes</th><th>Wear Level</th></tr></thead>
|
||||
';
|
||||
echo '<tbody>
|
||||
';
|
||||
echo '
|
||||
<table id="host_metrics_table">
|
||||
<thead><tr>
|
||||
<th>Drive Letter</th><th>Disk ID</th><th>Health Metrics</th><th>Model</th><th>Serial</th><th>Capacity</th>
|
||||
</tr></thead>
|
||||
<tbody>';
|
||||
foreach ($c['drives'] as $drive) {
|
||||
echo '<tr>
|
||||
';
|
||||
echo '<td>' . h($drive['drive_letter'] ?? '') . '</td>';
|
||||
echo '<td>' . h("".$drive['disk_id'] ?? '') . '</td>';
|
||||
echo '<td>' . h($drive['health_status'] ?? '') . '</td>';
|
||||
echo '<td>' . h($drive['model'] ?? '') . '</td>';
|
||||
echo '<td>' . h($drive['capacity'] ?? '') . '</td>';
|
||||
echo '<td>' . h($drive['power_on_hours'] ?? '') . '</td>';
|
||||
echo '<td>' . h($drive['host_writes'] ?? '') . '</td>';
|
||||
echo '<td>' . h($drive['wear_level'] ?? '') . '</td>';
|
||||
echo '</tr>
|
||||
';
|
||||
$wear_gb = '';
|
||||
if (isset($drive['host_writes'])){
|
||||
$wear_gb = $drive['host_writes'].' wear';
|
||||
}
|
||||
echo '
|
||||
<tr>
|
||||
<td>' . h($drive['drive_letter'] ?? '') . '</td>
|
||||
<td>' . h("".$drive['disk_id'] ?? '') . '</td>
|
||||
<td>' .
|
||||
h($drive['health_status'] ?? '').'<br>'.
|
||||
h($drive['power_on_hours'] ?? '').'<br>'.
|
||||
h($wear_gb ?? '').
|
||||
'</td>
|
||||
<td>' . h($drive['model'] ?? '') . '</td>
|
||||
<td>' . h($drive['serial'] ?? '') . '</td>
|
||||
<td>' . h($drive['capacity'] ?? '') . '</td>
|
||||
</tr>';
|
||||
}
|
||||
echo '</tbody></table>
|
||||
';
|
||||
echo '
|
||||
</tbody></table> ';
|
||||
} else {
|
||||
echo '<p>No drive data available for this host.</p>';
|
||||
}
|
||||
echo '</div>';
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
echo '
|
||||
</div>';
|
||||
return;
|
||||
}
|
||||
?>
|
||||
@ -477,10 +463,12 @@ function renderMainContent(string $mode){
|
||||
<body>
|
||||
|
||||
<div class="wrapper">
|
||||
<!-- Sidebar -->
|
||||
<?php renderSidebar($mode); ?>
|
||||
<!-- Main content -->
|
||||
<?php renderMainContent($mode); ?>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<?php renderSidebar($mode); ?>
|
||||
|
||||
<!-- Main content -->
|
||||
<?php renderMainContent($mode); ?>
|
||||
|
||||
|
||||
</div> <!-- /wrapper -->
|
||||
@ -507,11 +495,11 @@ function renderMainContent(string $mode){
|
||||
<script>
|
||||
// Removal Handler
|
||||
document.getElementById('removeForm').addEventListener('submit', function (e) {
|
||||
// Grab all checked checkboxes from the Drive‑Health form
|
||||
// Grab all checked checkboxes from the Drive-Health form
|
||||
const checked = document.querySelectorAll('#driveHealthForm input[type="checkbox"][name="hosts[]"]:checked');
|
||||
const ids = Array.from(checked).map(cb => cb.value);
|
||||
|
||||
// Pass the comma‑separated list to the hidden input
|
||||
// Pass the comma-separated list to the hidden input
|
||||
document.getElementById('remove_hosts_input').value = ids.join(',');
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user