module_fn('pi_control', 'table', $name); $assets = app()->assets(); if ($assets) { $assets->addStyle('/module/pi_control/asset?file=pi_control.css'); $assets->addScript('/module/pi_control/asset?file=commands.js', 'footer', true); } $notice = null; $error = null; if (isset($_GET['reorder_json'])) { require_admin(); $payload = json_decode(file_get_contents('php://input'), true); $order = is_array($payload['order'] ?? null) ? $payload['order'] : []; if ($order) { $stmt = $pdo->prepare('UPDATE ' . $table('commands') . ' SET sort_order = :sort_order WHERE id = :id'); $pos = 1; foreach ($order as $id) { $stmt->execute([ 'sort_order' => $pos++, 'id' => (int)$id, ]); } } header('Content-Type: application/json; charset=utf-8'); echo json_encode(['ok' => true]); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { require_admin(); $deleteId = (int)($_POST['delete_id'] ?? 0); $editId = (int)($_POST['id'] ?? 0); $label = trim((string)($_POST['label'] ?? '')); $command = trim((string)($_POST['command'] ?? '')); $adminOnly = !empty($_POST['admin_only']) ? 1 : 0; $timeoutSec = (int)($_POST['timeout_sec'] ?? 0); if ($deleteId > 0) { $stmt = $pdo->prepare('DELETE FROM ' . $table('commands') . ' WHERE id = :id'); $stmt->execute(['id' => $deleteId]); $notice = 'Befehl gelöscht.'; } else { if ($label === '' || $command === '') { $error = 'Bitte Label und Command angeben.'; } else { if ($editId > 0) { $stmt = $pdo->prepare( 'UPDATE ' . $table('commands') . ' SET label = :label, command = :command, admin_only = :admin_only, timeout_sec = :timeout_sec WHERE id = :id' ); $stmt->execute([ 'id' => $editId, 'label' => $label, 'command' => $command, 'admin_only' => $adminOnly, 'timeout_sec' => $timeoutSec > 0 ? $timeoutSec : null, ]); $notice = 'Befehl aktualisiert.'; } else { $nextSort = (int)$pdo->query('SELECT COALESCE(MAX(sort_order), 0) + 1 FROM ' . $table('commands'))->fetchColumn(); $stmt = $pdo->prepare( 'INSERT INTO ' . $table('commands') . ' (label, command, admin_only, timeout_sec, sort_order) VALUES (:label, :command, :admin_only, :timeout_sec, :sort_order)' ); $stmt->execute([ 'label' => $label, 'command' => $command, 'admin_only' => $adminOnly, 'timeout_sec' => $timeoutSec > 0 ? $timeoutSec : null, 'sort_order' => $nextSort, ]); $notice = 'Befehl gespeichert.'; } } } } $commands = $pdo->query('SELECT * FROM ' . $table('commands') . ' ORDER BY COALESCE(sort_order, id) ASC, id ASC')->fetchAll(PDO::FETCH_ASSOC); ?> 'Befehle', ]) ?>

Befehle

Verwalte vordefinierte SSH-Befehle.

Vorhandene Befehle
Keine Befehle vorhanden.
  • ⋮⋮
    Admin
    Timeout:

Reihenfolge per Drag & Drop ändern.