picontrol
This commit is contained in:
103
modules/pi_control/bootstrap.php
Normal file
103
modules/pi_control/bootstrap.php
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
use App\ModuleConfigException;
|
||||||
|
|
||||||
|
$moduleName = 'pi_control';
|
||||||
|
|
||||||
|
modules()->registerFunction($moduleName, 'table', function (string $name): string {
|
||||||
|
$prefix = 'picontrol_';
|
||||||
|
$sanitized = preg_replace('/[^a-zA-Z0-9_]/', '', $name);
|
||||||
|
return $prefix . $sanitized;
|
||||||
|
});
|
||||||
|
|
||||||
|
modules()->registerFunction($moduleName, 'pdo', function () use ($moduleName): \PDO {
|
||||||
|
$settings = modules()->settings($moduleName);
|
||||||
|
$useSeparate = !empty($settings['use_separate_db']);
|
||||||
|
|
||||||
|
if ($useSeparate) {
|
||||||
|
// Uses module-specific DB config
|
||||||
|
$module = modules()->get($moduleName);
|
||||||
|
$fallback = $module['db_defaults'] ?? [];
|
||||||
|
return modules()->modulePdo($moduleName, $fallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
$base = app()->basePdo();
|
||||||
|
if (!$base) {
|
||||||
|
throw new ModuleConfigException(
|
||||||
|
$moduleName,
|
||||||
|
'Base-DB ist deaktiviert. Bitte Base-DB aktivieren oder eigene Modul-DB konfigurieren.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $base;
|
||||||
|
});
|
||||||
|
|
||||||
|
modules()->registerFunction($moduleName, 'ensure_schema', function () use ($moduleName): void {
|
||||||
|
$pdo = module_fn($moduleName, 'pdo');
|
||||||
|
$table = fn(string $name) => module_fn($moduleName, 'table', $name);
|
||||||
|
|
||||||
|
$driver = (string)$pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||||
|
|
||||||
|
$hostTable = $table('hosts');
|
||||||
|
$cmdTable = $table('commands');
|
||||||
|
$runTable = $table('runs');
|
||||||
|
|
||||||
|
if ($driver === 'pgsql') {
|
||||||
|
$pdo->exec("CREATE TABLE IF NOT EXISTS {$hostTable} (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name VARCHAR(120) NOT NULL,
|
||||||
|
host VARCHAR(255) NOT NULL,
|
||||||
|
port INTEGER NOT NULL DEFAULT 22,
|
||||||
|
username VARCHAR(120) NOT NULL,
|
||||||
|
auth_type VARCHAR(20) NOT NULL DEFAULT 'key',
|
||||||
|
key_path TEXT NULL,
|
||||||
|
password TEXT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)");
|
||||||
|
$pdo->exec("CREATE TABLE IF NOT EXISTS {$cmdTable} (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
label VARCHAR(160) NOT NULL,
|
||||||
|
command TEXT NOT NULL,
|
||||||
|
admin_only BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)");
|
||||||
|
$pdo->exec("CREATE TABLE IF NOT EXISTS {$runTable} (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
host_id INTEGER NULL,
|
||||||
|
command_id INTEGER NULL,
|
||||||
|
command_text TEXT NOT NULL,
|
||||||
|
status VARCHAR(20) NOT NULL DEFAULT 'pending',
|
||||||
|
output TEXT NULL,
|
||||||
|
created_by VARCHAR(120) NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)");
|
||||||
|
} else {
|
||||||
|
$pdo->exec("CREATE TABLE IF NOT EXISTS {$hostTable} (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name VARCHAR(120) NOT NULL,
|
||||||
|
host VARCHAR(255) NOT NULL,
|
||||||
|
port INTEGER NOT NULL DEFAULT 22,
|
||||||
|
username VARCHAR(120) NOT NULL,
|
||||||
|
auth_type VARCHAR(20) NOT NULL DEFAULT 'key',
|
||||||
|
key_path TEXT NULL,
|
||||||
|
password TEXT NULL,
|
||||||
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)");
|
||||||
|
$pdo->exec("CREATE TABLE IF NOT EXISTS {$cmdTable} (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
label VARCHAR(160) NOT NULL,
|
||||||
|
command TEXT NOT NULL,
|
||||||
|
admin_only INTEGER NOT NULL DEFAULT 0,
|
||||||
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)");
|
||||||
|
$pdo->exec("CREATE TABLE IF NOT EXISTS {$runTable} (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
host_id INTEGER NULL,
|
||||||
|
command_id INTEGER NULL,
|
||||||
|
command_text TEXT NOT NULL,
|
||||||
|
status VARCHAR(20) NOT NULL DEFAULT 'pending',
|
||||||
|
output TEXT NULL,
|
||||||
|
created_by VARCHAR(120) NULL,
|
||||||
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
});
|
||||||
45
modules/pi_control/module.json
Normal file
45
modules/pi_control/module.json
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"title": "Pi Control",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Verwaltung und Steuerung von Raspberry Pis (SSH/Commands/Presets).",
|
||||||
|
"menu": [
|
||||||
|
{ "label": "Übersicht", "href": "/module/pi_control" },
|
||||||
|
{ "label": "Hosts", "href": "/module/pi_control/hosts" },
|
||||||
|
{ "label": "Befehle", "href": "/module/pi_control/commands" },
|
||||||
|
{ "label": "Konsole", "href": "/module/pi_control/console" },
|
||||||
|
{ "label": "Setup", "href": "/modules/setup/pi_control" }
|
||||||
|
],
|
||||||
|
"sidebar": {
|
||||||
|
"enabled": true,
|
||||||
|
"collapsible": true,
|
||||||
|
"default": "collapsed",
|
||||||
|
"items": [
|
||||||
|
{ "label": "Übersicht", "href": "/module/pi_control" },
|
||||||
|
{ "label": "Hosts", "href": "/module/pi_control/hosts" },
|
||||||
|
{ "label": "Befehle", "href": "/module/pi_control/commands" },
|
||||||
|
{ "label": "Konsole", "href": "/module/pi_control/console" },
|
||||||
|
{ "label": "Setup", "href": "/modules/setup/pi_control" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"setup": {
|
||||||
|
"fields": [
|
||||||
|
{ "name": "use_separate_db", "label": "Eigene Modul-DB nutzen", "type": "checkbox", "required": false, "help": "Wenn aktiv, werden die DB-Daten unten verwendet. Sonst wird die Base-DB genutzt." },
|
||||||
|
{ "name": "db.driver", "label": "DB Driver", "type": "text", "required": false, "help": "z.B. pgsql, mysql, sqlite" },
|
||||||
|
{ "name": "db.host", "label": "DB Host", "type": "text", "required": false },
|
||||||
|
{ "name": "db.port", "label": "DB Port", "type": "number", "required": false },
|
||||||
|
{ "name": "db.dbname", "label": "DB Name", "type": "text", "required": false },
|
||||||
|
{ "name": "db.schema", "label": "DB Schema", "type": "text", "required": false },
|
||||||
|
{ "name": "db.user", "label": "DB User", "type": "text", "required": false },
|
||||||
|
{ "name": "db.password", "label": "DB Passwort", "type": "password", "required": false }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"db_defaults": {
|
||||||
|
"driver": "pgsql",
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 5432,
|
||||||
|
"dbname": "",
|
||||||
|
"schema": "public",
|
||||||
|
"user": "",
|
||||||
|
"password": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
90
modules/pi_control/pages/commands.php
Normal file
90
modules/pi_control/pages/commands.php
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<?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();
|
||||||
|
$label = trim((string)($_POST['label'] ?? ''));
|
||||||
|
$command = trim((string)($_POST['command'] ?? ''));
|
||||||
|
$adminOnly = !empty($_POST['admin_only']) ? 1 : 0;
|
||||||
|
|
||||||
|
if ($label === '' || $command === '') {
|
||||||
|
$error = 'Bitte Label und Command angeben.';
|
||||||
|
} else {
|
||||||
|
$stmt = $pdo->prepare(
|
||||||
|
'INSERT INTO ' . $table('commands') . ' (label, command, admin_only) VALUES (:label, :command, :admin_only)'
|
||||||
|
);
|
||||||
|
$stmt->execute([
|
||||||
|
'label' => $label,
|
||||||
|
'command' => $command,
|
||||||
|
'admin_only' => $adminOnly,
|
||||||
|
]);
|
||||||
|
$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" style="display:grid; gap:10px; margin-top:.75rem;">
|
||||||
|
<input type="text" name="label" placeholder="Label" required>
|
||||||
|
<textarea name="command" rows="4" placeholder="Command" required></textarea>
|
||||||
|
<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>Admin</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (!$commands): ?>
|
||||||
|
<tr><td colspan="3" 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['admin_only']) ? 'ja' : 'nein' ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
125
modules/pi_control/pages/console.php
Normal file
125
modules/pi_control/pages/console.php
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
$hosts = $pdo->query('SELECT * FROM ' . $table('hosts') . ' ORDER BY name ASC')->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
$commands = $pdo->query('SELECT * FROM ' . $table('commands') . ' ORDER BY label ASC')->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$hostId = (int)($_POST['host_id'] ?? 0);
|
||||||
|
$commandId = (int)($_POST['command_id'] ?? 0);
|
||||||
|
$rawCommand = trim((string)($_POST['command_text'] ?? ''));
|
||||||
|
|
||||||
|
if ($hostId <= 0) {
|
||||||
|
$error = 'Bitte einen Host wählen.';
|
||||||
|
} elseif ($commandId <= 0 && $rawCommand === '') {
|
||||||
|
$error = 'Bitte einen Befehl wählen oder einen Befehl eingeben.';
|
||||||
|
} else {
|
||||||
|
$selectedCommand = '';
|
||||||
|
if ($commandId > 0) {
|
||||||
|
foreach ($commands as $c) {
|
||||||
|
if ((int)$c['id'] === $commandId) {
|
||||||
|
if (!auth_is_admin() && !empty($c['admin_only'])) {
|
||||||
|
$error = 'Dieser Befehl ist nur für Admins.';
|
||||||
|
} else {
|
||||||
|
$selectedCommand = (string)$c['command'];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$error) {
|
||||||
|
$commandText = $selectedCommand !== '' ? $selectedCommand : $rawCommand;
|
||||||
|
$stmt = $pdo->prepare(
|
||||||
|
'INSERT INTO ' . $table('runs') . ' (host_id, command_id, command_text, status, created_by) VALUES (:host_id, :command_id, :command_text, :status, :created_by)'
|
||||||
|
);
|
||||||
|
$stmt->execute([
|
||||||
|
'host_id' => $hostId,
|
||||||
|
'command_id' => $commandId > 0 ? $commandId : null,
|
||||||
|
'command_text' => $commandText,
|
||||||
|
'status' => 'pending',
|
||||||
|
'created_by' => auth_display_name() ?: null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$notice = 'Befehl wurde erfasst. (Execution-Backend folgt)';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$runs = $pdo->query('SELECT * FROM ' . $table('runs') . ' ORDER BY id DESC LIMIT 20')->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
?>
|
||||||
|
<div class="card">
|
||||||
|
<div class="pill">Pi Control</div>
|
||||||
|
<h1 style="margin-top:.75rem;">Konsole</h1>
|
||||||
|
<p class="muted">Wähle einen Host und führe einen Befehl aus.</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>Ausführen</strong>
|
||||||
|
<form method="post" style="display:grid; gap:10px; margin-top:.75rem;">
|
||||||
|
<select name="host_id" required>
|
||||||
|
<option value="">Host wählen</option>
|
||||||
|
<?php foreach ($hosts as $h): ?>
|
||||||
|
<option value="<?= e((string)$h['id']) ?>"><?= e($h['name'] ?? $h['host']) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select name="command_id">
|
||||||
|
<option value="">Preset auswählen (optional)</option>
|
||||||
|
<?php foreach ($commands as $c): ?>
|
||||||
|
<?php if (!auth_is_admin() && !empty($c['admin_only'])) { continue; } ?>
|
||||||
|
<option value="<?= e((string)$c['id']) ?>"><?= e($c['label'] ?? '') ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<textarea name="command_text" rows="3" placeholder="Oder Command direkt eingeben"></textarea>
|
||||||
|
<button class="cta-button" type="submit">Befehl senden</button>
|
||||||
|
</form>
|
||||||
|
<p class="muted" style="margin-top:.5rem;">Hinweis: Execution-Backend wird im nächsten Schritt ergänzt.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card" style="background:var(--panel-2);">
|
||||||
|
<strong>Letzte Runs</strong>
|
||||||
|
<div style="margin-top:.75rem; overflow:auto;">
|
||||||
|
<table class="table" style="min-width:560px;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Command</th>
|
||||||
|
<th>Von</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (!$runs): ?>
|
||||||
|
<tr><td colspan="4" class="muted">Noch keine Runs.</td></tr>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php foreach ($runs as $r): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?= e((string)$r['id']) ?></td>
|
||||||
|
<td><?= e($r['status'] ?? '') ?></td>
|
||||||
|
<td class="muted" style="max-width:360px;"><code><?= e($r['command_text'] ?? '') ?></code></td>
|
||||||
|
<td><?= e($r['created_by'] ?? '') ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
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>
|
||||||
32
modules/pi_control/pages/index.php
Normal file
32
modules/pi_control/pages/index.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
$pdo = module_fn('pi_control', 'pdo');
|
||||||
|
module_fn('pi_control', 'ensure_schema');
|
||||||
|
$table = fn(string $name) => module_fn('pi_control', 'table', $name);
|
||||||
|
|
||||||
|
$hostCount = (int)$pdo->query('SELECT COUNT(*) FROM ' . $table('hosts'))->fetchColumn();
|
||||||
|
$cmdCount = (int)$pdo->query('SELECT COUNT(*) FROM ' . $table('commands'))->fetchColumn();
|
||||||
|
$runCount = (int)$pdo->query('SELECT COUNT(*) FROM ' . $table('runs'))->fetchColumn();
|
||||||
|
?>
|
||||||
|
<div class="card">
|
||||||
|
<div class="pill">Pi Control</div>
|
||||||
|
<h1 style="margin-top:.75rem;">Raspberry Pi Steuerung</h1>
|
||||||
|
<p class="muted">SSH Hosts verwalten, Befehle definieren und Aktionen ausführen.</p>
|
||||||
|
|
||||||
|
<div class="grid" style="margin-top:1rem;">
|
||||||
|
<div class="card" style="background:var(--panel-2);">
|
||||||
|
<strong>Hosts</strong>
|
||||||
|
<div class="muted" style="margin-top:.35rem;">Registriert: <?= e((string)$hostCount) ?></div>
|
||||||
|
<div style="margin-top:.75rem;"><a class="nav-link" href="/module/pi_control/hosts">Hosts verwalten</a></div>
|
||||||
|
</div>
|
||||||
|
<div class="card" style="background:var(--panel-2);">
|
||||||
|
<strong>Befehle</strong>
|
||||||
|
<div class="muted" style="margin-top:.35rem;">Presets: <?= e((string)$cmdCount) ?></div>
|
||||||
|
<div style="margin-top:.75rem;"><a class="nav-link" href="/module/pi_control/commands">Befehle verwalten</a></div>
|
||||||
|
</div>
|
||||||
|
<div class="card" style="background:var(--panel-2);">
|
||||||
|
<strong>Konsole</strong>
|
||||||
|
<div class="muted" style="margin-top:.35rem;">Runs: <?= e((string)$runCount) ?></div>
|
||||||
|
<div style="margin-top:.75rem;"><a class="nav-link" href="/module/pi_control/console">Konsole öffnen</a></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user