Add reproducible build system, native Unraid plugin, and WebUI
- versions.env pins podman, conmon, crun, netavark, aardvark-dns, passt, and fuse-overlayfs to verified upstream source checksums; SlackBuild recipes, scripts/build-packages.sh, checksums.sh, release.sh, and update-versions.sh implement the reproducible pipeline; GitHub Actions workflows build in a Slackware container and publish releases without committing any binaries. - plugin/podman.plg installs/updates/removes all eight packages (the seven components plus the plugin's own unraid-podman scaffolding package) via upgradepkg, using the official Unraid array-event hook mechanism (event/disks_mounted, event/stopping) instead of editing /boot/config/go. rc.podman and the sbin/ helper scripts implement storage creation, config seeding/sync, preflight checks, autostart with per-container Safe-Mode, and package verify/update/rollback. - webui/plugins/podman implements the Dashboard, Containers, Pods, Images, Volumes, Networks, Logs, Terminal, Compose, and Settings panels against the approved mockup (webui/mockups/prototype.html), talking to podman system service exclusively via PodmanClient.php (libpod REST API over the Unix socket), with two documented exceptions: Terminal's one-shot exec model and Compose's use of the podman compose CLI, since libpod has no REST equivalent for either. - docs/ARCHITECTURE.md and docs/ROADMAP.md record the design decisions and honest current status (syntax-checked, unit- and integration-tested against fake sockets/servers; not yet run against a real Unraid/Podman/Slackware system). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
* ajax/compose.php
|
||||
*
|
||||
* Backs the Compose panel — and is the ONE deliberate exception to
|
||||
* "talk to podman.sock, never shell out" in this entire WebUI.
|
||||
*
|
||||
* Why: libpod's REST API has no endpoint that understands
|
||||
* docker-compose.yml/compose.yaml at all. The closest thing,
|
||||
* POST /libpod/kube/play, takes Kubernetes YAML, not Compose YAML, and
|
||||
* correctly translating arbitrary Compose files into Kube manifests is a
|
||||
* substantial project of its own (this is exactly what `podman compose` /
|
||||
* `podman-compose` already do). Reimplementing that translation from
|
||||
* scratch here — instead of using the `podman compose` CLI, which IS the
|
||||
* project's own supported way to run Compose files — would be more
|
||||
* fragile, not more "API-native": there is no API to be native to for
|
||||
* this one feature. So this file, and only this file, runs the
|
||||
* `podman compose` CLI via proc_open(), with strict input validation
|
||||
* (project names are matched against a fixed pattern, never interpolated
|
||||
* into a shell string) rather than passing user input through a shell.
|
||||
*
|
||||
* Compose projects live under $bootDir/compose/<project>/compose.yaml —
|
||||
* see docs/ARCHITECTURE.md; this mirrors how autostart/networks/backups
|
||||
* are all rooted under /boot/config/plugins/podman/ for the same
|
||||
* boot-persistence reasons.
|
||||
*
|
||||
* Actions (?action=...):
|
||||
* list GET -> known projects with up/down status
|
||||
* get GET (&project=...) -> raw compose.yaml content
|
||||
* up POST {"project": "..."}
|
||||
* down POST {"project": "..."}
|
||||
* pull POST {"project": "..."}
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
$composeDir = $podmanConfig->bootDir . '/compose';
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
podman_json_response(compose_list($composeDir));
|
||||
break;
|
||||
|
||||
case 'get':
|
||||
$project = (string) ($_GET['project'] ?? '');
|
||||
podman_json_response(['yaml' => compose_read($composeDir, $project)]);
|
||||
break;
|
||||
|
||||
case 'up':
|
||||
podman_json_response(compose_run($composeDir, require_project(podman_read_json_body()), ['up', '-d']));
|
||||
break;
|
||||
|
||||
case 'down':
|
||||
podman_json_response(compose_run($composeDir, require_project(podman_read_json_body()), ['down']));
|
||||
break;
|
||||
|
||||
case 'pull':
|
||||
podman_json_response(compose_run($composeDir, require_project(podman_read_json_body()), ['pull']));
|
||||
break;
|
||||
|
||||
default:
|
||||
podman_json_error("Unknown action '{$action}'", 400);
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $body */
|
||||
function require_project(array $body): string
|
||||
{
|
||||
$project = (string) ($body['project'] ?? '');
|
||||
if (!is_valid_project_name($project)) {
|
||||
podman_json_error('Missing or invalid project name', 400);
|
||||
}
|
||||
return $project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Project names come from the user (a form field when creating a new
|
||||
* compose project, or a value round-tripped from list()). Restricting
|
||||
* them to a fixed safe character set here — BEFORE they're ever used to
|
||||
* build a filesystem path or a command argument — is what makes it safe
|
||||
* to pass them to proc_open() at all.
|
||||
*/
|
||||
function is_valid_project_name(string $name): bool
|
||||
{
|
||||
return $name !== '' && preg_match('/^[a-zA-Z0-9_-]+$/', $name) === 1;
|
||||
}
|
||||
|
||||
/** @return array<int,array<string,mixed>> */
|
||||
function compose_list(string $composeDir): array
|
||||
{
|
||||
if (!is_dir($composeDir)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$projects = [];
|
||||
foreach (scandir($composeDir) ?: [] as $entry) {
|
||||
if ($entry === '.' || $entry === '..' || !is_valid_project_name($entry)) {
|
||||
continue;
|
||||
}
|
||||
$yamlPath = $composeDir . '/' . $entry . '/compose.yaml';
|
||||
if (!is_file($yamlPath)) {
|
||||
continue;
|
||||
}
|
||||
$projects[] = [
|
||||
'name' => $entry,
|
||||
'path' => $yamlPath,
|
||||
'status' => compose_status($composeDir, $entry),
|
||||
];
|
||||
}
|
||||
|
||||
usort($projects, static fn($a, $b) => strcmp($a['name'], $b['name']));
|
||||
return $projects;
|
||||
}
|
||||
|
||||
/** Best-effort "up"/"down" status via `podman compose ps`; degrades to "unknown" rather than failing the whole list. */
|
||||
function compose_status(string $composeDir, string $project): string
|
||||
{
|
||||
$result = run_compose_command($composeDir, $project, ['ps', '--format', 'json'], 5);
|
||||
if ($result['exitCode'] !== 0) {
|
||||
return 'unknown';
|
||||
}
|
||||
$decoded = json_decode($result['output'], true);
|
||||
return (is_array($decoded) && count($decoded) > 0) ? 'up' : 'down';
|
||||
}
|
||||
|
||||
function compose_read(string $composeDir, string $project): string
|
||||
{
|
||||
if (!is_valid_project_name($project)) {
|
||||
podman_json_error('Invalid project name', 400);
|
||||
}
|
||||
$path = $composeDir . '/' . $project . '/compose.yaml';
|
||||
$content = is_file($path) ? file_get_contents($path) : false;
|
||||
if ($content === false) {
|
||||
podman_json_error("compose.yaml not found for project '{$project}'", 404);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
function compose_run(string $composeDir, string $project, array $subcommand): array
|
||||
{
|
||||
$result = run_compose_command($composeDir, $project, $subcommand, 300);
|
||||
if ($result['exitCode'] !== 0) {
|
||||
podman_json_error("podman compose " . implode(' ', $subcommand) . " failed:\n" . $result['output'], 502);
|
||||
}
|
||||
return ['output' => $result['output']];
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs `podman compose -f <project>/compose.yaml <subcommand...>` via
|
||||
* proc_open with an argv array (never a shell string — proc_open with an
|
||||
* array argument bypasses the shell entirely, so there is no injection
|
||||
* surface even though $project has already been validated above too).
|
||||
*
|
||||
* @param array<int,string> $subcommand
|
||||
* @return array{exitCode:int,output:string}
|
||||
*/
|
||||
function run_compose_command(string $composeDir, string $project, array $subcommand, int $timeoutSeconds): array
|
||||
{
|
||||
$yamlPath = $composeDir . '/' . $project . '/compose.yaml';
|
||||
$argv = array_merge(['podman', 'compose', '-f', $yamlPath], $subcommand);
|
||||
|
||||
$descriptors = [1 => ['pipe', 'w'], 2 => ['pipe', 'w']];
|
||||
$process = proc_open($argv, $descriptors, $pipes, $composeDir . '/' . $project);
|
||||
if (!is_resource($process)) {
|
||||
return ['exitCode' => 127, 'output' => 'Could not start podman compose process'];
|
||||
}
|
||||
|
||||
stream_set_timeout($pipes[1], $timeoutSeconds);
|
||||
$stdout = stream_get_contents($pipes[1]) ?: '';
|
||||
$stderr = stream_get_contents($pipes[2]) ?: '';
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
$exitCode = proc_close($process);
|
||||
|
||||
return ['exitCode' => $exitCode, 'output' => trim($stdout . $stderr)];
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* ajax/containers.php
|
||||
*
|
||||
* Backs the Containers panel (and the container rows nested inside the
|
||||
* Pods panel — see ajax/pods.php). All actions go through PodmanClient,
|
||||
* i.e. the real libpod REST API over podman.sock; nothing here shells out.
|
||||
*
|
||||
* Actions (?action=...):
|
||||
* list GET -> normalized array of containers for the table view
|
||||
* inspect GET (&id=...) -> raw inspect JSON, for a detail dialog
|
||||
* start POST {"id": "..."}
|
||||
* stop POST {"id": "...", "timeout": 10}
|
||||
* restart POST {"id": "...", "timeout": 10}
|
||||
* remove POST {"id": "...", "force": false}
|
||||
* logs GET (&id=...&tail=200) -> plain text
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
podman_json_response(containers_list($client));
|
||||
break;
|
||||
|
||||
case 'inspect':
|
||||
$id = (string) ($_GET['id'] ?? '');
|
||||
if ($id === '') {
|
||||
podman_json_error('Missing id', 400);
|
||||
}
|
||||
podman_json_response($client->inspectContainer($id));
|
||||
break;
|
||||
|
||||
case 'logs':
|
||||
$id = (string) ($_GET['id'] ?? '');
|
||||
if ($id === '') {
|
||||
podman_json_error('Missing id', 400);
|
||||
}
|
||||
$tail = (int) ($_GET['tail'] ?? 200);
|
||||
podman_json_response(['text' => $client->containerLogs($id, $tail)]);
|
||||
break;
|
||||
|
||||
case 'start':
|
||||
$body = podman_read_json_body();
|
||||
$client->startContainer(require_id($body));
|
||||
podman_json_response(['status' => 'started']);
|
||||
break;
|
||||
|
||||
case 'stop':
|
||||
$body = podman_read_json_body();
|
||||
$client->stopContainer(require_id($body), (int) ($body['timeout'] ?? $podmanConfig->stopTimeoutSeconds));
|
||||
podman_json_response(['status' => 'stopped']);
|
||||
break;
|
||||
|
||||
case 'restart':
|
||||
$body = podman_read_json_body();
|
||||
$client->restartContainer(require_id($body), (int) ($body['timeout'] ?? $podmanConfig->stopTimeoutSeconds));
|
||||
podman_json_response(['status' => 'restarted']);
|
||||
break;
|
||||
|
||||
case 'remove':
|
||||
$body = podman_read_json_body();
|
||||
$client->removeContainer(require_id($body), (bool) ($body['force'] ?? false));
|
||||
podman_json_response(['status' => 'removed']);
|
||||
break;
|
||||
|
||||
default:
|
||||
podman_json_error("Unknown action '{$action}'", 400);
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $body */
|
||||
function require_id(array $body): string
|
||||
{
|
||||
$id = (string) ($body['id'] ?? '');
|
||||
if ($id === '') {
|
||||
podman_json_error('Missing id in request body', 400);
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes libpod's /containers/json entries into exactly what the
|
||||
* Containers table (javascript/containers.js) renders — keeping this
|
||||
* shaping logic server-side means the frontend never has to know libpod's
|
||||
* raw field names/quirks (e.g. Names is an array, State vs Status, etc).
|
||||
*
|
||||
* @return array<int,array<string,mixed>>
|
||||
*/
|
||||
function containers_list(PodmanClient $client): array
|
||||
{
|
||||
$raw = $client->listContainers(true);
|
||||
$out = [];
|
||||
|
||||
foreach ($raw as $c) {
|
||||
$names = $c['Names'] ?? [];
|
||||
$name = is_array($names) && count($names) > 0 ? ltrim((string) $names[0], '/') : podman_short_id((string) ($c['Id'] ?? ''));
|
||||
|
||||
$ports = [];
|
||||
foreach (($c['Ports'] ?? []) as $p) {
|
||||
if (isset($p['host_port'], $p['container_port'])) {
|
||||
$ports[] = "{$p['host_port']}:{$p['container_port']}/" . ($p['protocol'] ?? 'tcp');
|
||||
} elseif (isset($p['container_port'])) {
|
||||
$ports[] = "{$p['container_port']}/" . ($p['protocol'] ?? 'tcp');
|
||||
}
|
||||
}
|
||||
|
||||
$startedAt = podman_parse_time($c['StartedAt'] ?? null);
|
||||
$state = strtolower((string) ($c['State'] ?? 'unknown'));
|
||||
|
||||
$out[] = [
|
||||
'id' => (string) ($c['Id'] ?? ''),
|
||||
'shortId' => podman_short_id((string) ($c['Id'] ?? '')),
|
||||
'name' => $name,
|
||||
'image' => (string) ($c['Image'] ?? ''),
|
||||
'state' => $state,
|
||||
'status' => (string) ($c['Status'] ?? ''),
|
||||
'health' => $c['Health']['Status'] ?? null,
|
||||
'ports' => $ports,
|
||||
'pod' => $c['Pod'] ?? null,
|
||||
'podName' => $c['PodName'] ?? null,
|
||||
'uptimeSeconds' => ($state === 'running' && $startedAt !== null) ? (time() - $startedAt) : null,
|
||||
'createdAt' => podman_parse_time($c['Created'] ?? null),
|
||||
];
|
||||
}
|
||||
|
||||
usort($out, static fn($a, $b) => strcmp($a['name'], $b['name']));
|
||||
return $out;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* ajax/exec.php
|
||||
*
|
||||
* Backs the Terminal panel — and this is the one panel where "exclusively
|
||||
* via podman system service, no shell hacks" needs an honest caveat
|
||||
* spelled out rather than silently glossed over:
|
||||
*
|
||||
* libpod's real exec API (POST /containers/{id}/exec, then
|
||||
* POST /exec/{id}/start) is used here — PodmanClient::execRun() never
|
||||
* shells out to the `podman` binary. But that API's interactive mode works
|
||||
* by HTTP connection hijacking: the HTTP connection is upgraded into a raw
|
||||
* bidirectional byte stream for the lifetime of the shell session. That
|
||||
* model assumes a long-lived process holding the socket open on both ends
|
||||
* (an actual terminal emulator, or a WebSocket bridge) — it does not fit
|
||||
* PHP-FPM's request/response lifecycle, where each AJAX call is a fresh,
|
||||
* independent, short-lived process with no memory of any previous one.
|
||||
*
|
||||
* Rather than fake interactivity with something that would break on the
|
||||
* first multi-line prompt, `sudo`, or interactive editor, this endpoint
|
||||
* offers a deliberately simpler, honest contract: one command in, its
|
||||
* complete output back, using Tty=true so output reads like a real
|
||||
* terminal (colors, prompts-in-output, etc. survive) but with no
|
||||
* persistent shell state (`cd` does not carry over between calls — see
|
||||
* the "cwd" parameter below, which javascript/terminal.js tracks
|
||||
* client-side and resends every time instead).
|
||||
*
|
||||
* A true interactive PTY (arrow-key history, tab completion, vim, ...)
|
||||
* would need a WebSocket-capable process sitting between the browser and
|
||||
* podman.sock — out of scope for this PHP/AJAX stack; tracked as a
|
||||
* follow-up rather than implemented as a shell-out workaround.
|
||||
*
|
||||
* Actions (?action=...):
|
||||
* run POST {"id": "...", "cmd": "ls -la", "cwd": "/config"}
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
switch ($action) {
|
||||
case 'run':
|
||||
$body = podman_read_json_body();
|
||||
$id = (string) ($body['id'] ?? '');
|
||||
$commandLine = (string) ($body['cmd'] ?? '');
|
||||
$cwd = (string) ($body['cwd'] ?? '');
|
||||
|
||||
if ($id === '' || trim($commandLine) === '') {
|
||||
podman_json_error('Missing id or cmd in request body', 400);
|
||||
}
|
||||
|
||||
// The command line is run through the container's own shell
|
||||
// (sh -c) so the user can type ordinary shell syntax (pipes,
|
||||
// globs, env vars) in the terminal box, exactly like a real
|
||||
// shell prompt would accept — still one real exec API call, just
|
||||
// with /bin/sh as the interpreter instead of us parsing shell
|
||||
// syntax ourselves in PHP.
|
||||
$output = $client->execRun($id, ['/bin/sh', '-c', $commandLine], $cwd);
|
||||
|
||||
podman_json_response(['output' => $output]);
|
||||
break;
|
||||
|
||||
default:
|
||||
podman_json_error("Unknown action '{$action}'", 400);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* ajax/images.php
|
||||
*
|
||||
* Backs the Images panel.
|
||||
*
|
||||
* Actions (?action=...):
|
||||
* list GET -> normalized image list
|
||||
* pull POST {"reference": "docker.io/library/postgres:16"}
|
||||
* remove POST {"id": "...", "force": false}
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
podman_json_response(images_list($client));
|
||||
break;
|
||||
|
||||
case 'pull':
|
||||
$body = podman_read_json_body();
|
||||
$reference = (string) ($body['reference'] ?? '');
|
||||
if ($reference === '') {
|
||||
podman_json_error('Missing reference in request body', 400);
|
||||
}
|
||||
podman_json_response($client->pullImage($reference));
|
||||
break;
|
||||
|
||||
case 'remove':
|
||||
$body = podman_read_json_body();
|
||||
$id = (string) ($body['id'] ?? '');
|
||||
if ($id === '') {
|
||||
podman_json_error('Missing id in request body', 400);
|
||||
}
|
||||
$client->removeImage($id, (bool) ($body['force'] ?? false));
|
||||
podman_json_response(['status' => 'removed']);
|
||||
break;
|
||||
|
||||
default:
|
||||
podman_json_error("Unknown action '{$action}'", 400);
|
||||
}
|
||||
|
||||
/** @return array<int,array<string,mixed>> */
|
||||
function images_list(PodmanClient $client): array
|
||||
{
|
||||
$raw = $client->listImages();
|
||||
|
||||
// In-use counts let the frontend show "0" (safe to remove) vs a
|
||||
// positive count, without a separate round trip per image.
|
||||
$usageCounts = [];
|
||||
foreach ($client->listContainers(true) as $c) {
|
||||
$imageId = (string) ($c['ImageID'] ?? '');
|
||||
if ($imageId !== '') {
|
||||
$usageCounts[$imageId] = ($usageCounts[$imageId] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
$out = [];
|
||||
foreach ($raw as $img) {
|
||||
$id = (string) ($img['Id'] ?? '');
|
||||
$repoTags = $img['RepoTags'] ?? [];
|
||||
$repository = '<none>';
|
||||
$tag = '<none>';
|
||||
if (is_array($repoTags) && count($repoTags) > 0 && is_string($repoTags[0]) && str_contains($repoTags[0], ':')) {
|
||||
[$repository, $tag] = explode(':', $repoTags[0], 2);
|
||||
}
|
||||
|
||||
$out[] = [
|
||||
'id' => $id,
|
||||
'shortId' => podman_short_id($id),
|
||||
'repository' => $repository,
|
||||
'tag' => $tag,
|
||||
'sizeBytes' => (int) ($img['Size'] ?? 0),
|
||||
'sizeFormatted' => podman_format_bytes((int) ($img['Size'] ?? 0)),
|
||||
// Unlike containers' Created/StartedAt (RFC3339 strings), libpod
|
||||
// reports image Created as a Unix timestamp integer directly.
|
||||
'createdAt' => isset($img['Created']) ? (int) $img['Created'] : null,
|
||||
'usedBy' => $usageCounts[$id] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
usort($out, static fn($a, $b) => strcmp($a['repository'], $b['repository']));
|
||||
return $out;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* ajax/networks.php
|
||||
*
|
||||
* Backs the Networks panel. See docs/ARCHITECTURE.md section 8 for why
|
||||
* networks created here are netavark-backed and deliberately isolated
|
||||
* from Docker's own docker0/custom-network space.
|
||||
*
|
||||
* Actions (?action=...):
|
||||
* list GET -> normalized network list with subnet/gateway/usage
|
||||
* create POST {"name": "...", "driver": "bridge", "subnet": "...", "gateway": "..."}
|
||||
* remove POST {"name": "...", "force": false}
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
podman_json_response(networks_list($client));
|
||||
break;
|
||||
|
||||
case 'create':
|
||||
$body = podman_read_json_body();
|
||||
$name = (string) ($body['name'] ?? '');
|
||||
if ($name === '') {
|
||||
podman_json_error('Missing name in request body', 400);
|
||||
}
|
||||
podman_json_response($client->createNetwork(
|
||||
$name,
|
||||
(string) ($body['driver'] ?? 'bridge'),
|
||||
isset($body['subnet']) ? (string) $body['subnet'] : null,
|
||||
isset($body['gateway']) ? (string) $body['gateway'] : null
|
||||
));
|
||||
break;
|
||||
|
||||
case 'remove':
|
||||
$body = podman_read_json_body();
|
||||
$name = (string) ($body['name'] ?? '');
|
||||
if ($name === '') {
|
||||
podman_json_error('Missing name in request body', 400);
|
||||
}
|
||||
// podman0, the default bridge, refuses removal API-side — no
|
||||
// special-casing needed here, PodmanApiException surfaces podman's
|
||||
// own rejection message as-is.
|
||||
$client->removeNetwork($name, (bool) ($body['force'] ?? false));
|
||||
podman_json_response(['status' => 'removed']);
|
||||
break;
|
||||
|
||||
default:
|
||||
podman_json_error("Unknown action '{$action}'", 400);
|
||||
}
|
||||
|
||||
/** @return array<int,array<string,mixed>> */
|
||||
function networks_list(PodmanClient $client): array
|
||||
{
|
||||
$raw = $client->listNetworks();
|
||||
|
||||
$usageCounts = [];
|
||||
foreach ($client->listContainers(true) as $c) {
|
||||
$nets = $c['Networks'] ?? [];
|
||||
if (is_array($nets)) {
|
||||
foreach ($nets as $netName) {
|
||||
if (is_string($netName)) {
|
||||
$usageCounts[$netName] = ($usageCounts[$netName] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$out = [];
|
||||
foreach ($raw as $n) {
|
||||
$name = (string) ($n['name'] ?? '');
|
||||
$subnets = $n['subnets'] ?? [];
|
||||
$subnet = is_array($subnets) && count($subnets) > 0 ? (string) ($subnets[0]['subnet'] ?? '') : '';
|
||||
$gateway = is_array($subnets) && count($subnets) > 0 ? (string) ($subnets[0]['gateway'] ?? '') : '';
|
||||
|
||||
$out[] = [
|
||||
'name' => $name,
|
||||
'driver' => (string) ($n['driver'] ?? 'bridge'),
|
||||
'subnet' => $subnet,
|
||||
'gateway' => $gateway,
|
||||
'isDefault' => $name === 'podman',
|
||||
'containers' => $usageCounts[$name] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
usort($out, static fn($a, $b) => strcmp($a['name'], $b['name']));
|
||||
return $out;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* ajax/pods.php
|
||||
*
|
||||
* Backs the Pods panel. A pod is rendered as its own card with the member
|
||||
* containers nested inside (see javascript/pods.js) — listPods() gives us
|
||||
* the membership, and we cross-reference the container list for per-member
|
||||
* status/image/ports rather than issuing one inspect call per container.
|
||||
*
|
||||
* Actions (?action=...):
|
||||
* list GET -> pods with nested container summaries
|
||||
* start POST {"name": "..."}
|
||||
* stop POST {"name": "...", "timeout": 10}
|
||||
* remove POST {"name": "...", "force": false}
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
podman_json_response(pods_list($client));
|
||||
break;
|
||||
|
||||
case 'start':
|
||||
$body = podman_read_json_body();
|
||||
$client->startPod(require_name($body));
|
||||
podman_json_response(['status' => 'started']);
|
||||
break;
|
||||
|
||||
case 'stop':
|
||||
$body = podman_read_json_body();
|
||||
$client->stopPod(require_name($body), (int) ($body['timeout'] ?? $podmanConfig->stopTimeoutSeconds));
|
||||
podman_json_response(['status' => 'stopped']);
|
||||
break;
|
||||
|
||||
case 'remove':
|
||||
$body = podman_read_json_body();
|
||||
$client->removePod(require_name($body), (bool) ($body['force'] ?? false));
|
||||
podman_json_response(['status' => 'removed']);
|
||||
break;
|
||||
|
||||
default:
|
||||
podman_json_error("Unknown action '{$action}'", 400);
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $body */
|
||||
function require_name(array $body): string
|
||||
{
|
||||
$name = (string) ($body['name'] ?? '');
|
||||
if ($name === '') {
|
||||
podman_json_error('Missing name in request body', 400);
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/** @return array<int,array<string,mixed>> */
|
||||
function pods_list(PodmanClient $client): array
|
||||
{
|
||||
$pods = $client->listPods();
|
||||
$containersByPod = [];
|
||||
foreach (containers_grouped_by_pod($client) as $podId => $members) {
|
||||
$containersByPod[$podId] = $members;
|
||||
}
|
||||
|
||||
$out = [];
|
||||
foreach ($pods as $p) {
|
||||
$id = (string) ($p['Id'] ?? '');
|
||||
$out[] = [
|
||||
'id' => $id,
|
||||
'name' => (string) ($p['Name'] ?? ''),
|
||||
'status' => strtolower((string) ($p['Status'] ?? 'unknown')),
|
||||
'containersTotal' => (int) ($p['NumContainers'] ?? count($containersByPod[$id] ?? [])),
|
||||
'infraId' => $p['InfraId'] ?? null,
|
||||
'members' => $containersByPod[$id] ?? [],
|
||||
];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/** @return array<string,array<int,array<string,mixed>>> keyed by pod id */
|
||||
function containers_grouped_by_pod(PodmanClient $client): array
|
||||
{
|
||||
$grouped = [];
|
||||
foreach ($client->listContainers(true) as $c) {
|
||||
$podId = $c['Pod'] ?? null;
|
||||
if (!is_string($podId) || $podId === '') {
|
||||
continue;
|
||||
}
|
||||
$names = $c['Names'] ?? [];
|
||||
$name = is_array($names) && count($names) > 0 ? ltrim((string) $names[0], '/') : podman_short_id((string) ($c['Id'] ?? ''));
|
||||
$grouped[$podId][] = [
|
||||
'id' => (string) ($c['Id'] ?? ''),
|
||||
'name' => $name,
|
||||
'image' => (string) ($c['Image'] ?? ''),
|
||||
'state' => strtolower((string) ($c['State'] ?? 'unknown')),
|
||||
];
|
||||
}
|
||||
return $grouped;
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* ajax/settings.php
|
||||
*
|
||||
* Backs the Settings panel. Unlike every other ajax/*.php file, this one
|
||||
* is NOT primarily a PodmanClient consumer — plugin settings (podman.cfg,
|
||||
* the autostart list, installed package versions) are unraid-podman's own
|
||||
* data on /boot, not a libpod-managed resource, so there is no API to call
|
||||
* here in the first place. Writes go straight to the same files
|
||||
* plugin/sbin/podman-config.sh and podman-autostart.sh read, using the
|
||||
* same paths (see include/Config.php, which mirrors podman-common.sh's
|
||||
* path constants).
|
||||
*
|
||||
* Actions (?action=...):
|
||||
* get GET -> current settings + autostart list + package versions
|
||||
* save POST {"storagePath": "...", "storageImageSizeGb": 20,
|
||||
* "enabled": true, "stopTimeoutSeconds": 10}
|
||||
* autostart_save POST {"names": ["postgres", "nextcloud", ...]}
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
switch ($action) {
|
||||
case 'get':
|
||||
podman_json_response(settings_get($podmanConfig));
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
$body = podman_read_json_body();
|
||||
settings_save($podmanConfig, $body);
|
||||
podman_json_response(['status' => 'saved']);
|
||||
break;
|
||||
|
||||
case 'autostart_save':
|
||||
$body = podman_read_json_body();
|
||||
$names = $body['names'] ?? null;
|
||||
if (!is_array($names)) {
|
||||
podman_json_error('Missing names array in request body', 400);
|
||||
}
|
||||
autostart_save($podmanConfig, $names);
|
||||
podman_json_response(['status' => 'saved']);
|
||||
break;
|
||||
|
||||
default:
|
||||
podman_json_error("Unknown action '{$action}'", 400);
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
function settings_get(PodmanConfig $config): array
|
||||
{
|
||||
return [
|
||||
'storagePath' => $config->storagePath,
|
||||
'storageImageSizeGb' => $config->storageImageSizeGb,
|
||||
'enabled' => $config->enabled,
|
||||
'stopTimeoutSeconds' => $config->stopTimeoutSeconds,
|
||||
'autostart' => autostart_read($config),
|
||||
'packageVersions' => installed_package_versions(),
|
||||
];
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $input */
|
||||
function settings_save(PodmanConfig $config, array $input): void
|
||||
{
|
||||
$storagePath = isset($input['storagePath']) ? (string) $input['storagePath'] : $config->storagePath;
|
||||
if (!storage_path_is_safe($storagePath)) {
|
||||
podman_json_error(
|
||||
"storagePath ({$storagePath}) is under /mnt/user (FUSE/shfs). " .
|
||||
'The overlay storage driver needs a real mounted filesystem — use a cache pool or a specific disk path instead.',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
$lines = [
|
||||
'# Rewritten by the unraid-podman WebUI (ajax/settings.php).',
|
||||
'# Applies on the next "rc.podman restart" — see plugin/rc.d/rc.podman.',
|
||||
'STORAGE_PATH="' . $storagePath . '"',
|
||||
'STORAGE_IMAGE_SIZE_GB="' . (int) ($input['storageImageSizeGb'] ?? $config->storageImageSizeGb) . '"',
|
||||
'PODMAN_ENABLED="' . ((bool) ($input['enabled'] ?? $config->enabled) ? 'yes' : 'no') . '"',
|
||||
'STOP_TIMEOUT="' . (int) ($input['stopTimeoutSeconds'] ?? $config->stopTimeoutSeconds) . '"',
|
||||
'CONFIG_SCHEMA_VERSION="1"',
|
||||
'',
|
||||
];
|
||||
|
||||
$target = $config->bootDir . '/podman.cfg';
|
||||
if (file_put_contents($target, implode("\n", $lines), LOCK_EX) === false) {
|
||||
podman_json_error("Could not write {$target} — check permissions on /boot/config/plugins/podman/", 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors plugin/sbin/podman-common.sh's podman_storage_path_is_safe() —
|
||||
* kept in sync deliberately (both reject the same /mnt/user prefix, for
|
||||
* the same reason) rather than shelling out to the bash version, since
|
||||
* this is a one-line string check, not worth a process spawn for.
|
||||
*/
|
||||
function storage_path_is_safe(string $path): bool
|
||||
{
|
||||
return $path !== '/mnt/user' && !str_starts_with($path, '/mnt/user/');
|
||||
}
|
||||
|
||||
/** @return array<int,string> */
|
||||
function autostart_read(PodmanConfig $config): array
|
||||
{
|
||||
if (!is_readable($config->autostartFile)) {
|
||||
return [];
|
||||
}
|
||||
$lines = file($config->autostartFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
|
||||
$names = [];
|
||||
foreach ($lines as $line) {
|
||||
$line = trim(preg_replace('/#.*$/', '', $line) ?? '');
|
||||
if ($line !== '') {
|
||||
$names[] = $line;
|
||||
}
|
||||
}
|
||||
return $names;
|
||||
}
|
||||
|
||||
/** @param array<int,mixed> $names */
|
||||
function autostart_save(PodmanConfig $config, array $names): void
|
||||
{
|
||||
$lines = array_map(static fn($n) => (string) $n, $names);
|
||||
$content = implode("\n", $lines) . (count($lines) > 0 ? "\n" : '');
|
||||
if (file_put_contents($config->autostartFile, $content, LOCK_EX) === false) {
|
||||
podman_json_error("Could not write {$config->autostartFile}", 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads /usr/local/share/unraid-podman/installed-versions.env — the same
|
||||
* manifest plugin/sbin/podman-verify-packages.sh and
|
||||
* podman-update-packages.sh use (see plugin/podman.plg's postinstall step,
|
||||
* which generates it) — so Settings shows exactly what those tools would
|
||||
* report, not a second, possibly-diverging source of truth.
|
||||
*
|
||||
* @return array<string,string>
|
||||
*/
|
||||
function installed_package_versions(): array
|
||||
{
|
||||
$path = '/usr/local/share/unraid-podman/installed-versions.env';
|
||||
if (!is_readable($path)) {
|
||||
return [];
|
||||
}
|
||||
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
|
||||
$out = [];
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '' || str_starts_with($line, '#')) {
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^([A-Z_][A-Z0-9_]*)="?([^"]*)"?$/', $line, $m)) {
|
||||
$out[$m[1]] = $m[2];
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* ajax/system.php
|
||||
*
|
||||
* Backs the Dashboard panel's summary tiles and the service-status line
|
||||
* shown in the page header — aggregates across several libpod endpoints
|
||||
* into the one shape javascript/dashboard.js needs, so the frontend
|
||||
* doesn't have to make (and wait on) five separate round trips.
|
||||
*
|
||||
* Actions (?action=...):
|
||||
* summary GET -> counts, storage usage, engine version, ping status
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
switch ($action) {
|
||||
case 'summary':
|
||||
podman_json_response(system_summary($client, $podmanConfig));
|
||||
break;
|
||||
|
||||
default:
|
||||
podman_json_error("Unknown action '{$action}'", 400);
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
function system_summary(PodmanClient $client, PodmanConfig $config): array
|
||||
{
|
||||
if (!$client->ping()) {
|
||||
return [
|
||||
'reachable' => false,
|
||||
'socketPath' => $config->socketPath,
|
||||
];
|
||||
}
|
||||
|
||||
$containers = $client->listContainers(true);
|
||||
$running = 0;
|
||||
foreach ($containers as $c) {
|
||||
if (strtolower((string) ($c['State'] ?? '')) === 'running') {
|
||||
$running++;
|
||||
}
|
||||
}
|
||||
|
||||
$pods = $client->listPods();
|
||||
$images = $client->listImages();
|
||||
$volumes = $client->listVolumes();
|
||||
$networks = $client->listNetworks();
|
||||
$info = $client->info();
|
||||
$df = $client->systemDf();
|
||||
|
||||
$imagesSize = 0;
|
||||
foreach (($df['Images'] ?? []) as $img) {
|
||||
$imagesSize += (int) ($img['Size'] ?? 0);
|
||||
}
|
||||
|
||||
return [
|
||||
'reachable' => true,
|
||||
'socketPath' => $config->socketPath,
|
||||
'podmanVersion' => $info['Version']['Version'] ?? null,
|
||||
'containers' => [
|
||||
'total' => count($containers),
|
||||
'running' => $running,
|
||||
],
|
||||
'pods' => count($pods),
|
||||
'images' => count($images),
|
||||
'volumes' => count($volumes),
|
||||
'networks' => count($networks),
|
||||
'storage' => [
|
||||
'imagesSizeBytes' => $imagesSize,
|
||||
'imagesSizeFormatted' => podman_format_bytes($imagesSize),
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* ajax/volumes.php
|
||||
*
|
||||
* Backs the Volumes panel. Bind-mounted appdata (e.g. /mnt/user/appdata/...)
|
||||
* intentionally does not appear here — only Podman-managed named volumes
|
||||
* do, since bind mounts aren't a libpod-managed resource at all (see
|
||||
* docs/ARCHITECTURE.md section 9).
|
||||
*
|
||||
* Actions (?action=...):
|
||||
* list GET -> normalized volume list, with usedBy counts
|
||||
* create POST {"name": "...", "driver": "local"}
|
||||
* remove POST {"name": "...", "force": false}
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
podman_json_response(volumes_list($client));
|
||||
break;
|
||||
|
||||
case 'create':
|
||||
$body = podman_read_json_body();
|
||||
$name = (string) ($body['name'] ?? '');
|
||||
if ($name === '') {
|
||||
podman_json_error('Missing name in request body', 400);
|
||||
}
|
||||
podman_json_response($client->createVolume($name, (string) ($body['driver'] ?? 'local')));
|
||||
break;
|
||||
|
||||
case 'remove':
|
||||
$body = podman_read_json_body();
|
||||
$name = (string) ($body['name'] ?? '');
|
||||
if ($name === '') {
|
||||
podman_json_error('Missing name in request body', 400);
|
||||
}
|
||||
$client->removeVolume($name, (bool) ($body['force'] ?? false));
|
||||
podman_json_response(['status' => 'removed']);
|
||||
break;
|
||||
|
||||
default:
|
||||
podman_json_error("Unknown action '{$action}'", 400);
|
||||
}
|
||||
|
||||
/** @return array<int,array<string,mixed>> */
|
||||
function volumes_list(PodmanClient $client): array
|
||||
{
|
||||
$raw = $client->listVolumes();
|
||||
|
||||
$usageCounts = [];
|
||||
foreach ($client->listContainers(true) as $c) {
|
||||
foreach (($c['Mounts'] ?? []) as $mount) {
|
||||
$volName = $mount['Name'] ?? null;
|
||||
if (is_string($volName) && $volName !== '') {
|
||||
$usageCounts[$volName] = ($usageCounts[$volName] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$out = [];
|
||||
foreach ($raw as $v) {
|
||||
$name = (string) ($v['Name'] ?? '');
|
||||
$out[] = [
|
||||
'name' => $name,
|
||||
'driver' => (string) ($v['Driver'] ?? 'local'),
|
||||
'mountpoint' => (string) ($v['Mountpoint'] ?? ''),
|
||||
'createdAt' => podman_parse_time($v['CreatedAt'] ?? null),
|
||||
'usedBy' => $usageCounts[$name] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
usort($out, static fn($a, $b) => strcmp($a['name'], $b['name']));
|
||||
return $out;
|
||||
}
|
||||
Reference in New Issue
Block a user