picontrol
This commit is contained in:
101
modules/pi_control/pages/hosts.php
Normal file
101
modules/pi_control/pages/hosts.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
$pdo = module_fn('pi_control', 'pdo');
|
||||
module_fn('pi_control', 'ensure_schema');
|
||||
$table = fn(string $name) => module_fn('pi_control', 'table', $name);
|
||||
|
||||
$notice = null;
|
||||
$error = null;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
require_admin();
|
||||
$name = trim((string)($_POST['name'] ?? ''));
|
||||
$host = trim((string)($_POST['host'] ?? ''));
|
||||
$port = (int)($_POST['port'] ?? 22);
|
||||
$username = trim((string)($_POST['username'] ?? ''));
|
||||
$authType = trim((string)($_POST['auth_type'] ?? 'key'));
|
||||
$keyPath = trim((string)($_POST['key_path'] ?? ''));
|
||||
$password = trim((string)($_POST['password'] ?? ''));
|
||||
|
||||
if ($name === '' || $host === '' || $username === '') {
|
||||
$error = 'Bitte Name, Host und Benutzer angeben.';
|
||||
} else {
|
||||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO ' . $table('hosts') . ' (name, host, port, username, auth_type, key_path, password) VALUES (:name, :host, :port, :username, :auth_type, :key_path, :password)'
|
||||
);
|
||||
$stmt->execute([
|
||||
'name' => $name,
|
||||
'host' => $host,
|
||||
'port' => $port > 0 ? $port : 22,
|
||||
'username' => $username,
|
||||
'auth_type' => $authType !== '' ? $authType : 'key',
|
||||
'key_path' => $keyPath !== '' ? $keyPath : null,
|
||||
'password' => $password !== '' ? $password : null,
|
||||
]);
|
||||
$notice = 'Host gespeichert.';
|
||||
}
|
||||
}
|
||||
|
||||
$hosts = $pdo->query('SELECT * FROM ' . $table('hosts') . ' ORDER BY id DESC')->fetchAll(PDO::FETCH_ASSOC);
|
||||
?>
|
||||
<div class="card">
|
||||
<div class="pill">Pi Control</div>
|
||||
<h1 style="margin-top:.75rem;">Hosts</h1>
|
||||
<p class="muted">Verwalte die Raspberry Pis, die du steuern möchtest.</p>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="card" style="margin-top:1rem; border-color:#ffb4a8; background:#fff5f3; color:#7a2114;">
|
||||
<?= e($error) ?>
|
||||
</div>
|
||||
<?php elseif ($notice): ?>
|
||||
<div class="card" style="margin-top:1rem; border-color:var(--accent-2);">
|
||||
<?= e($notice) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="grid" style="margin-top:1rem;">
|
||||
<div class="card" style="background:var(--panel-2);">
|
||||
<strong>Neuer Host</strong>
|
||||
<form method="post" style="display:grid; gap:10px; margin-top:.75rem;">
|
||||
<input type="text" name="name" placeholder="Name" required>
|
||||
<input type="text" name="host" placeholder="Host/IP" required>
|
||||
<input type="number" name="port" placeholder="Port" value="22">
|
||||
<input type="text" name="username" placeholder="SSH User" required>
|
||||
<input type="text" name="auth_type" placeholder="auth_type (key/pass)" value="key">
|
||||
<input type="text" name="key_path" placeholder="Key Path (optional)">
|
||||
<input type="password" name="password" placeholder="Password (optional)">
|
||||
<button class="cta-button" type="submit">Speichern</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card" style="background:var(--panel-2);">
|
||||
<strong>Registrierte Hosts</strong>
|
||||
<div style="margin-top:.75rem; overflow:auto;">
|
||||
<table class="table" style="min-width:560px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Host</th>
|
||||
<th>User</th>
|
||||
<th>Port</th>
|
||||
<th>Auth</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!$hosts): ?>
|
||||
<tr><td colspan="5" class="muted">Keine Hosts vorhanden.</td></tr>
|
||||
<?php endif; ?>
|
||||
<?php foreach ($hosts as $h): ?>
|
||||
<tr>
|
||||
<td><?= e($h['name'] ?? '') ?></td>
|
||||
<td><?= e($h['host'] ?? '') ?></td>
|
||||
<td><?= e($h['username'] ?? '') ?></td>
|
||||
<td><?= e((string)($h['port'] ?? 22)) ?></td>
|
||||
<td><?= e($h['auth_type'] ?? '') ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user