Files
netwatch/app/modules/connections/list.php
2026-02-12 09:55:27 +01:00

209 lines
7.0 KiB
PHP

<?php
/**
* app/modules/connections/list.php
*
* Übersicht der Netzwerkverbindungen
* - Tabellarische Liste aller Verbindungen
* - Filter nach Geräten, VLANs, Status
* - Später: Visuelle Netzwerk-Topologie
*/
// =========================
// Filter einlesen
// =========================
$search = trim($_GET['search'] ?? '');
$deviceId = (int)($_GET['device_id'] ?? 0);
// =========================
// WHERE-Clause bauen
// =========================
$where = [];
$types = '';
$params = [];
if ($search !== '') {
$where[] = "(d1.name LIKE ? OR d2.name LIKE ? OR dpt1.name LIKE ? OR dpt2.name LIKE ?)";
$types .= "ssss";
$params[] = "%$search%";
$params[] = "%$search%";
$params[] = "%$search%";
$params[] = "%$search%";
}
if ($deviceId > 0) {
$where[] = "(d1.id = ? OR d2.id = ?)";
$types .= "ii";
$params[] = $deviceId;
$params[] = $deviceId;
}
$whereSql = $where ? "WHERE " . implode(" AND ", $where) : "";
// =========================
// Verbindungen laden
// =========================
$connections = $sql->get(
"SELECT
c.id,
c.port_a_type, c.port_a_id, c.port_b_type, c.port_b_id,
d1.name AS device_a_name,
d2.name AS device_b_name,
dpt1.name AS port_a_name,
dpt2.name AS port_b_name,
c.vlan_config,
c.comment
FROM connections c
LEFT JOIN device_ports dpt1 ON c.port_a_type = 'device' AND c.port_a_id = dpt1.id
LEFT JOIN devices d1 ON dpt1.device_id = d1.id
LEFT JOIN device_ports dpt2 ON c.port_b_type = 'device' AND c.port_b_id = dpt2.id
LEFT JOIN devices d2 ON dpt2.device_id = d2.id
$whereSql
ORDER BY d1.name, d2.name",
$types,
$params
);
// =========================
// Filter-Daten
// =========================
$devices = $sql->get("SELECT id, name FROM devices ORDER BY name", "", []);
?>
<div class="connections-container">
<h1>Netzwerkverbindungen</h1>
<!-- =========================
Filter-Toolbar
========================= -->
<div class="filter-form">
<form method="GET">
<input type="hidden" name="module" value="connections">
<input type="hidden" name="action" value="list">
<input type="text" name="search" placeholder="Suche nach Gerät oder Port…"
value="<?php echo htmlspecialchars($search); ?>" class="search-input">
<select name="device_id">
<option value="">- Alle Geräte -</option>
<?php foreach ($devices as $device): ?>
<option value="<?php echo $device['id']; ?>"
<?php echo $device['id'] === $deviceId ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($device['name']); ?>
</option>
<?php endforeach; ?>
</select>
<button type="submit" class="button">Filter</button>
<a href="?module=connections&action=list" class="button">Reset</a>
<a href="?module=connections&action=save" class="button button-primary">+ Neue Verbindung</a>
</form>
</div>
<!-- =========================
Verbindungs-Tabelle
========================= -->
<?php if (!empty($connections)): ?>
<table class="connections-list">
<thead>
<tr>
<th>Von (Gerät → Port)</th>
<th>Nach (Gerät → Port)</th>
<th>VLANs</th>
<th>Beschreibung</th>
<th>Status</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
<?php foreach ($connections as $conn): ?>
<?php
$comment = trim($conn['comment'] ?? '');
$hasMissingInfo = empty($conn['device_a_name']) || empty($conn['device_b_name'])
|| empty($conn['port_a_name']) || empty($conn['port_b_name']);
$commentLower = mb_strtolower($comment, 'UTF-8');
$warningFromComment = preg_match('/warn|achtung|critical/', $commentLower);
$hasWarning = $hasMissingInfo || $warningFromComment;
?>
<tr>
<td>
<strong><?php echo htmlspecialchars($conn['device_a_name'] ?? 'N/A'); ?></strong><br>
<small><?php echo htmlspecialchars($conn['port_a_name'] ?? '—'); ?></small>
</td>
<td>
<strong><?php echo htmlspecialchars($conn['device_b_name'] ?? 'N/A'); ?></strong><br>
<small><?php echo htmlspecialchars($conn['port_b_name'] ?? '—'); ?></small>
</td>
<td>
<small>
<?php
if ($conn['vlan_config']) {
$vlan = json_decode($conn['vlan_config'], true);
echo htmlspecialchars(implode(', ', (array)$vlan));
} else {
echo '—';
}
?>
</small>
</td>
<td>
<small><?php echo htmlspecialchars($conn['comment'] ?? ''); ?></small>
</td>
<td class="status-cell">
<?php if ($hasWarning): ?>
<span class="status-badge status-badge-warning" title="Unvollständige oder kritische Verbindung">
⚠️ Warnung
</span>
<?php else: ?>
<span class="status-badge status-badge-ok" title="Verbindung vollständig">
✔️ OK
</span>
<?php endif; ?>
</td>
<td class="actions">
<a href="?module=connections&action=edit&id=<?php echo $conn['id']; ?>" class="button button-small">Bearbeiten</a>
<a href="#" class="button button-small button-danger"
data-confirm-delete="true"
data-confirm-message="Diese Verbindung wirklich löschen?"
data-confirm-feedback="Löschen noch nicht implementiert">
Löschen
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<div class="empty-state">
<p>Keine Verbindungen gefunden.</p>
<p>
<a href="?module=connections&action=save" class="button button-primary">
Erste Verbindung anlegen
</a>
</p>
</div>
<?php endif; ?>
</div>
<!-- =========================
Sidebar / Details
========================= -->
<aside class="sidebar">
<!-- TODO: Details zum ausgewählten Gerät anzeigen -->
<!--
- Gerätename
- Gerätetyp
- Ports
- VLANs
- Verbindungen
-->
<!-- TODO: Verbindung bearbeiten / löschen -->
</aside>