100 lines
3.5 KiB
PHP
100 lines
3.5 KiB
PHP
<?php
|
|
$pdo = module_fn('pi_control', 'pdo');
|
|
module_fn('pi_control', 'ensure_schema');
|
|
$table = fn(string $name) => module_fn('pi_control', 'table', $name);
|
|
$assets = app()->assets();
|
|
if ($assets) {
|
|
$assets->addStyle('/module/pi_control/asset?file=pi_control.css');
|
|
}
|
|
|
|
$notice = null;
|
|
$error = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
require_admin();
|
|
$label = trim((string)($_POST['label'] ?? ''));
|
|
$command = trim((string)($_POST['command'] ?? ''));
|
|
$adminOnly = !empty($_POST['admin_only']) ? 1 : 0;
|
|
$timeoutSec = (int)($_POST['timeout_sec'] ?? 0);
|
|
|
|
if ($label === '' || $command === '') {
|
|
$error = 'Bitte Label und Command angeben.';
|
|
} else {
|
|
$stmt = $pdo->prepare(
|
|
'INSERT INTO ' . $table('commands') . ' (label, command, admin_only, timeout_sec) VALUES (:label, :command, :admin_only, :timeout_sec)'
|
|
);
|
|
$stmt->execute([
|
|
'label' => $label,
|
|
'command' => $command,
|
|
'admin_only' => $adminOnly,
|
|
'timeout_sec' => $timeoutSec > 0 ? $timeoutSec : null,
|
|
]);
|
|
$notice = 'Befehl gespeichert.';
|
|
}
|
|
}
|
|
|
|
$commands = $pdo->query('SELECT * FROM ' . $table('commands') . ' ORDER BY id DESC')->fetchAll(PDO::FETCH_ASSOC);
|
|
?>
|
|
<div class="card">
|
|
<div class="pill">Pi Control</div>
|
|
<h1 style="margin-top:.75rem;">Befehle</h1>
|
|
<p class="muted">Verwalte vordefinierte SSH-Befehle.</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 Befehl</strong>
|
|
<form method="post" class="form-grid" style="margin-top:.75rem;">
|
|
<input type="text" name="label" placeholder="Label" required>
|
|
<textarea name="command" rows="4" placeholder="Command" required></textarea>
|
|
<input type="number" name="timeout_sec" placeholder="Timeout (Sek., optional)">
|
|
<label class="muted" style="display:flex; gap:8px; align-items:center;">
|
|
<input type="checkbox" name="admin_only" value="1">
|
|
Nur Admin
|
|
</label>
|
|
<button class="cta-button" type="submit">Speichern</button>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="card" style="background:var(--panel-2);">
|
|
<strong>Vorhandene Befehle</strong>
|
|
<div style="margin-top:.75rem; overflow:auto;">
|
|
<table class="table" style="min-width:560px;">
|
|
<thead>
|
|
<tr>
|
|
<th>Label</th>
|
|
<th>Command</th>
|
|
<th>Timeout</th>
|
|
<th>Admin</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (!$commands): ?>
|
|
<tr><td colspan="4" class="muted">Keine Befehle vorhanden.</td></tr>
|
|
<?php endif; ?>
|
|
<?php foreach ($commands as $c): ?>
|
|
<tr>
|
|
<td><?= e($c['label'] ?? '') ?></td>
|
|
<td class="muted" style="max-width:360px;">
|
|
<code><?= e($c['command'] ?? '') ?></code>
|
|
</td>
|
|
<td><?= !empty($c['timeout_sec']) ? e((string)$c['timeout_sec']) . 's' : 'default' ?></td>
|
|
<td><?= !empty($c['admin_only']) ? 'ja' : 'nein' ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|