domovoy/templates/discovery/index.php

166 lines
7.4 KiB
PHP

<?php ob_start(); ?>
<h2>Сканирование сети</h2>
<!-- Add Range Form -->
<div class="card mb-4">
<div class="card-header">Добавить диапазон</div>
<div class="card-body">
<form method="POST" action="/discovery/ranges/create" class="row g-2">
<div class="col-md-4">
<input type="text" name="name" class="form-control" placeholder="Название (Home LAN)" required>
</div>
<div class="col-md-3">
<input type="text" name="cidr" class="form-control" placeholder="CIDR (192.168.1.0/24)" required>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary w-100">Добавить</button>
</div>
</form>
</div>
</div>
<!-- Network Ranges -->
<div class="card mb-4">
<div class="card-header">Диапазоны</div>
<div class="card-body">
<?php if (empty($ranges)): ?>
<p class="text-muted">Нет диапазонов. Добавьте первый диапазон выше.</p>
<?php else: ?>
<table class="table table-sm">
<thead>
<tr>
<th>Название</th>
<th>CIDR</th>
<th>Статус</th>
<th>Действия</th>
</tr>
</thead>
<tbody>
<?php foreach ($ranges as $range): ?>
<tr>
<td><?= htmlspecialchars($range->name) ?></td>
<td><?= htmlspecialchars($range->cidr) ?></td>
<td>
<?php if ($range->enabled): ?>
<span class="badge bg-success">Включён</span>
<?php else: ?>
<span class="badge bg-secondary">Выключен</span>
<?php endif; ?>
</td>
<td>
<form method="POST" action="/discovery/ranges/toggle" class="d-inline">
<input type="hidden" name="id" value="<?= $range->id ?>">
<button type="submit" class="btn btn-sm btn-outline-secondary">
<?= $range->enabled ? 'Выключить' : 'Включить' ?>
</button>
</form>
<form method="POST" action="/discovery/ranges/delete" class="d-inline" onsubmit="return confirm('Удалить?')">
<input type="hidden" name="id" value="<?= $range->id ?>">
<button type="submit" class="btn btn-sm btn-outline-danger">Удалить</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<form method="POST" action="/discovery/scan" class="mt-3">
<button type="submit" class="btn btn-success" <?= empty($ranges) ? 'disabled' : '' ?>>
Запустить скан
</button>
</form>
</div>
</div>
<!-- Scan Jobs -->
<div class="card mb-4">
<div class="card-header">История сканирования</div>
<div class="card-body">
<?php if (empty($scanJobs)): ?>
<p class="text-muted">Нет запусков сканирования.</p>
<?php else: ?>
<table class="table table-sm">
<thead>
<tr>
<th>Тип</th>
<th>Статус</th>
<th>Запущен</th>
<th>Завершён</th>
</tr>
</thead>
<tbody>
<?php foreach ($scanJobs as $job): ?>
<tr>
<td><?= htmlspecialchars($job->type) ?></td>
<td>
<?php
$badgeClass = match ($job->status) {
'pending' => 'bg-warning',
'running' => 'bg-info',
'done' => 'bg-success',
'failed' => 'bg-danger',
default => 'bg-secondary',
};
?>
<span class="badge <?= $badgeClass ?>"><?= htmlspecialchars($job->status) ?></span>
</td>
<td><?= $job->startedAt?->format('Y-m-d H:i:s') ?? '-' ?></td>
<td><?= $job->finishedAt?->format('Y-m-d H:i:s') ?? '-' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
<!-- New Hosts -->
<div class="card mb-4">
<div class="card-header">Новые находки (<?= count($newHosts) ?>)</div>
<div class="card-body">
<?php if (empty($newHosts)): ?>
<p class="text-muted">Нет новых находок.</p>
<?php else: ?>
<table class="table table-sm">
<thead>
<tr>
<th>IP</th>
<th>Hostname</th>
<th>MAC</th>
<th>Vendor</th>
<th>Порты</th>
<th>Уверенность</th>
<th>Действия</th>
</tr>
</thead>
<tbody>
<?php foreach ($newHosts as $host): ?>
<tr>
<td><?= htmlspecialchars($host->ipAddress) ?></td>
<td><?= htmlspecialchars($host->hostname ?? '-') ?></td>
<td><?= htmlspecialchars($host->macAddress ?? '-') ?></td>
<td><?= htmlspecialchars($host->vendor ?? '-') ?></td>
<td><?= empty($host->openPorts) ? '-' : implode(', ', $host->openPorts) ?></td>
<td><?= $host->confidence ?>%</td>
<td>
<form method="POST" action="/devices/from-host" class="d-inline">
<input type="hidden" name="host_id" value="<?= $host->id ?>">
<input type="hidden" name="name" value="<?= htmlspecialchars($host->hostname ?: $host->ipAddress) ?>">
<button type="submit" class="btn btn-sm btn-outline-primary">Создать устройство</button>
</form>
<form method="POST" action="/discovery/hosts/ignore" class="d-inline">
<input type="hidden" name="host_id" value="<?= $host->id ?>">
<button type="submit" class="btn btn-sm btn-outline-secondary">Игнорировать</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
<?php $content = ob_get_clean(); ?>
<?php require dirname(__DIR__) . '/layout.php'; ?>