This commit is contained in:
2026-03-08 00:12:59 +01:00
parent 12c2ce4817
commit a43747568a
7 changed files with 157 additions and 19 deletions

View File

@@ -11,6 +11,27 @@ if ($assets) {
$notice = null;
$error = null;
if (isset($_GET['status_json'])) {
require_admin();
$id = (int)($_GET['id'] ?? 0);
$stmt = $pdo->prepare('SELECT * FROM ' . $table('hosts') . ' WHERE id = :id LIMIT 1');
$stmt->execute(['id' => $id]);
$host = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$host) {
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['ok' => false, 'error' => 'not_found']);
exit;
}
$settings = modules()->settings('pi_control');
$strictHostKey = !empty($settings['terminal_strict_hostkey']);
$reachable = hostReachable((string)($host['host'] ?? ''), (int)($host['port'] ?? 22));
$authOk = $reachable ? hostAuthOk($host, $strictHostKey) : false;
$status = !$reachable ? 'down' : ($authOk ? 'ok' : 'auth');
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['ok' => true, 'status' => $status]);
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
require_admin();
$deleteId = (int)($_POST['delete_id'] ?? 0);
@@ -223,12 +244,6 @@ function hostAuthOk(array $host, bool $strictHostKey): bool
<?php else: ?>
<div class="host-grid" style="margin-top:.75rem;">
<?php foreach ($hosts as $h): ?>
<?php
$portVal = (int)($h['port'] ?? 22);
$reachable = hostReachable((string)($h['host'] ?? ''), $portVal);
$authOk = $reachable ? hostAuthOk($h, $strictHostKey) : false;
$statusClass = !$reachable ? 'status-down' : ($authOk ? 'status-ok' : 'status-auth');
?>
<div class="host-card"
data-host-id="<?= e((string)$h['id']) ?>"
data-name="<?= e((string)($h['name'] ?? '')) ?>"
@@ -244,7 +259,7 @@ function hostAuthOk(array $host, bool $strictHostKey): bool
<div class="host-card-body">
<div class="host-card-header">
<div class="host-card-title">
<span class="status-dot <?= $statusClass ?>"></span>
<span class="status-dot status-auth" data-host-status></span>
<strong><?= e((string)($h['name'] ?? '')) ?></strong>
</div>
<details class="action-menu">