Files
flowmanager/settings.php
2025-10-05 09:11:23 +00:00

70 lines
2.3 KiB
PHP

<?php
include 'include/include_header.php';
// Laad opgeslagen omgevingen (optioneel uit een JSON-bestand)
$env_file = 'environments.json';
$environments = [];
if(file_exists($env_file)) {
$environments = json_decode(file_get_contents($env_file), true);
}
// Verwerk toevoegen van nieuwe omgeving
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['name'], $_POST['ip'])) {
$name = trim($_POST['name']);
$ip = trim($_POST['ip']);
if ($name && $ip) {
$environments[] = ['name' => $name, 'ip' => $ip];
file_put_contents($env_file, json_encode($environments, JSON_PRETTY_PRINT));
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
}
// Verwerk verwijderen van omgeving
if (isset($_GET['delete'])) {
$index = intval($_GET['delete']);
if (isset($environments[$index])) {
array_splice($environments, $index, 1);
file_put_contents($env_file, json_encode($environments, JSON_PRETTY_PRINT));
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
}
?>
<div class="container my-5">
<h2>Node-RED Omgevingen Beheer</h2>
<!-- Formulier voor toevoegen -->
<form method="POST" class="row g-3 my-3">
<div class="col-md-5">
<input type="text" name="name" class="form-control" placeholder="Naam omgeving" required>
</div>
<div class="col-md-5">
<input type="text" name="ip" class="form-control" placeholder="IP-adres" required>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-success w-100">Toevoegen</button>
</div>
</form>
<!-- Omgevingen kaarten -->
<div class="row row-cols-1 row-cols-md-3 g-4">
<?php foreach($environments as $index => $env): ?>
<div class="col">
<div class="card h-100 p-3">
<div class="card-body">
<h5 class="card-title">
<i class="bi bi-hdd-network me-2" style="font-size: 1.5rem;"></i>
<?= htmlspecialchars($env['name']) ?>
</h5>
<p class="card-text">IP-adres: <?= htmlspecialchars($env['ip']) ?></p>
<a href="http://<?= htmlspecialchars($env['ip']) ?>:1880" target="_blank" class="btn btn-primary btn-sm">Open Node-RED</a>
<a href="?delete=<?= $index ?>" class="btn btn-danger btn-sm">Verwijderen</a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>