From e9035bf6feb9e330d1758ce72dcf2c62258578d0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 3 May 2026 18:59:32 +0200 Subject: [PATCH] Improve Caddyfile editor for demo-style configs --- .dockerignore | 7 + Caddyfile_demo.txt | 79 ++ README.md | 6 +- app/index.php | 785 +++++++++++++++++- docker-compose.yml | 2 + .../2026-05-03-remote-deploy-debug.md | 34 + .../2026-04-27-koncad-ui-redesign-design.md | 264 ++++++ 7 files changed, 1130 insertions(+), 47 deletions(-) create mode 100644 .dockerignore create mode 100644 Caddyfile_demo.txt create mode 100644 docs/deployments/2026-05-03-remote-deploy-debug.md create mode 100644 docs/superpowers/specs/2026-04-27-koncad-ui-redesign-design.md diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5f1aba3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.claude +.superpowers +docs +caddy +deploy.sh +README.md diff --git a/Caddyfile_demo.txt b/Caddyfile_demo.txt new file mode 100644 index 0000000..c21ad61 --- /dev/null +++ b/Caddyfile_demo.txt @@ -0,0 +1,79 @@ + +(cors-origin) { + @match-cors-preflight-{args[0]} { + header Origin "{args[0]}" + method OPTIONS + } + handle @match-cors-preflight-{args[0]} { + header { + Access-Control-Allow-Origin "{args[0]}" + Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" + Access-Control-Allow-Headers * + Access-Control-Max-Age "3600" + defer + } + respond "" 204 + } + + @match-cors-request-{args[0]} { + header Origin "{args[0]}" + not method OPTIONS + } + handle @match-cors-request-{args[0]} { + header { + Access-Control-Allow-Origin "{http.request.header.origin}" + Access-Control-Expose-Headers * + defer + } + } +} + + +*.example.de { + tls { + issuer acme { + dns netcup { + customer_number {env.NETCUP_CUSTOMER_NUMBER} + api_key {env.NETCUP_API_KEY} + api_password {env.NETCUP_API_PASSWORD} + } + resolvers 8.8.8.8 1.1.1.1 + propagation_timeout 30m + propagation_delay 15m + } + } + + @jellyfin host jellyfin.example.de + handle @jellyfin { + encode gzip + reverse_proxy 192.168.1.7:8098 + } + + @auth host auth.example.de + handle @auth { + import cors-origin https://home.example.de + reverse_proxy 192.168.1.7:9091 + } + + @hassio host hassio.example.de + handle @hassio { + reverse_proxy 192.168.1.4:8123 + } + + @pdf host pdf.example.de + handle @pdf { + forward_auth 192.168.1.7:9091 { + uri /api/authz/forward-auth + copy_headers Remote-User Remote-Groups Remote-Email Remote-Name + } + reverse_proxy 192.168.1.7:3300 + } + + # Fallback for otherwise unhandled domains + handle { + abort + } +} + + + diff --git a/README.md b/README.md index 0fc34ae..2e998e5 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ Web UI for managing an existing dockerized [Caddy](https://caddyserver.com/) ins ## Features - **Structured editor** — separate panels for global options and each site block +- **Raw editor** — optional full Caddyfile editing escape hatch for advanced changes - **Admin API check** — blocks editing if Caddy's admin API is unreachable on load -- **Admin API toggle** — one checkbox adds/removes `admin :2019` from global options - **Upstream reachability check** — warns before deploy if any `reverse_proxy` target is unreachable, with option to deploy anyway - **Atomic deploy** — posts config to Caddy's `/load` endpoint; bad configs are rejected without disrupting the running instance @@ -76,9 +76,11 @@ On first load it imports your existing Caddyfile (read-only). After the first de | Action | Description | |--------|-------------| | **Global Options** panel | Edit top-level Caddy options (email, logging, etc.) | -| **Enable Admin API** checkbox | Adds/removes `admin :2019` from global options | +| **Raw Caddyfile** mode | Edit the full Caddyfile directly; deploy still uses Caddy's admin API, so no restart is required | | **+ Add Site** | Creates a new site block | | **Remove** (per site) | Deletes that site block | | **Deploy** | Validates and applies config via Caddy's `/load` API; shows errors inline if rejected | If any `reverse_proxy` upstream is unreachable at deploy time, a warning modal lists them — you can cancel or deploy anyway. + +Switching from raw mode back to structured mode reparses the file, so comments and exact formatting may be normalized. diff --git a/app/index.php b/app/index.php index aa236f8..3eda005 100644 --- a/app/index.php +++ b/app/index.php @@ -40,7 +40,7 @@ function dedent(array $lines): array { } function parseCaddyfile(string $content): array { - $result = ['global' => '', 'sites' => []]; + $result = ['global' => '', 'snippets' => [], 'sites' => []]; $lines = explode("\n", $content); $n = count($lines); $i = 0; @@ -62,7 +62,7 @@ function parseCaddyfile(string $content): array { continue; } - // Site block: address(es) { + // Site block or reusable snippet: address(es) { / (snippet-name) { if (preg_match('/^(.+?)\s*\{(.*)$/', $trimmed, $m)) { $address = trim($m[1]); $block = trim($m[2]) !== '' ? [trim($m[2])] : []; @@ -72,7 +72,12 @@ function parseCaddyfile(string $content): array { if ($depth > 0) $block[] = $lines[$i]; $i++; } - $result['sites'][] = ['address' => $address, 'body' => implode("\n", dedent($block))]; + $entry = ['address' => $address, 'body' => implode("\n", dedent($block))]; + if (preg_match('/^\(([A-Za-z0-9_.-]+)\)$/', $address, $sm)) { + $result['snippets'][] = ['name' => $sm[1], 'body' => $entry['body']]; + } else { + $result['sites'][] = $entry; + } continue; } @@ -81,9 +86,15 @@ function parseCaddyfile(string $content): array { return $result; } -function buildCaddyfile(string $global, array $sites): string { +function buildCaddyfile(string $global, array $snippets, array $sites): string { $out = ''; if (trim($global) !== '') $out .= "{\n" . $global . "\n}\n\n"; + foreach ($snippets as $snippet) { + $name = trim((string)($snippet['name'] ?? '')); + if ($name === '') continue; + $body = (string)($snippet['body'] ?? ''); + $out .= "({$name}) {\n" . $body . "\n}\n\n"; + } foreach ($sites as $site) { $out .= trim($site['address']) . " {\n" . $site['body'] . "\n}\n\n"; } @@ -179,19 +190,30 @@ if (isset($_GET['action'])) { } else { $raw = ''; } - echo json_encode(['ok' => true, 'data' => parseCaddyfile($raw)]); + echo json_encode(['ok' => true, 'data' => parseCaddyfile($raw), 'raw' => $raw]); exit; case 'save': $input = json_decode(file_get_contents('php://input'), true); if (!$input) { echo json_encode(['ok' => false, 'error' => 'Invalid JSON']); exit; } - $cf = buildCaddyfile($input['global'] ?? '', $input['sites'] ?? []); + if (($input['mode'] ?? 'structured') === 'raw') { + $cf = (string)($input['raw'] ?? ''); + } else { + $cf = buildCaddyfile($input['global'] ?? '', $input['snippets'] ?? [], $input['sites'] ?? []); + } $result = caddyLoad($cf); if ($result['ok']) file_put_contents(CADDYFILE_STORE, $cf); echo json_encode($result); exit; + case 'parse_raw': + $input = json_decode(file_get_contents('php://input'), true); + if (!$input) { echo json_encode(['ok' => false, 'error' => 'Invalid JSON']); exit; } + $raw = (string)($input['raw'] ?? ''); + echo json_encode(['ok' => true, 'data' => parseCaddyfile($raw)]); + exit; + case 'check_upstreams': $input = json_decode(file_get_contents('php://input'), true); $targets = $input['targets'] ?? []; @@ -388,6 +410,48 @@ main { } .toggle-wrap input { accent-color: var(--accent); cursor: pointer; } .toggle-hint { font-size: 0.75rem; color: var(--muted); } +.help-text { font-size: 0.78rem; color: var(--muted); line-height: 1.5; margin-bottom: 0.75rem; } + +.mode-bar { + display: flex; + align-items: center; + gap: 0.75rem; + flex-wrap: wrap; +} + +.mode-label { + font-size: 0.82rem; + color: var(--muted); +} + +.mode-buttons { + display: inline-flex; + border: 1px solid var(--border); + border-radius: 8px; + overflow: hidden; +} + +.mode-btn { + border: none; + border-right: 1px solid var(--border); + background: rgba(255,255,255,0.04); + color: var(--muted); + padding: 0.45rem 0.8rem; + font-size: 0.82rem; + cursor: pointer; +} + +.mode-btn:last-child { border-right: none; } +.mode-btn.active { + background: rgba(124,140,248,0.18); + color: var(--accent); + font-weight: 700; +} + +.mode-note { + font-size: 0.78rem; + color: var(--muted); +} /* ── Code editor ── */ textarea.code { @@ -408,6 +472,105 @@ textarea.code { } textarea.code:focus { border-color: var(--accent); } +.form-grid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); + gap: 0.75rem; + margin-bottom: 0.75rem; +} +.field label { + display: block; + font-size: 0.74rem; + color: var(--muted); + margin-bottom: 0.25rem; +} +.field input { + width: 100%; + background: #0d0f18; + border: 1px solid var(--border); + border-radius: 6px; + color: var(--text); + font-size: 0.84rem; + padding: 0.5rem 0.6rem; + outline: none; +} +.field input:focus { border-color: var(--accent); } +.check-row { + display: flex; + align-items: center; + gap: 0.45rem; + color: var(--muted); + font-size: 0.8rem; + min-height: 2.4rem; +} +.check-row input { accent-color: var(--accent); } +.builder { + border: 1px solid var(--border); + border-radius: 8px; + padding: 0.85rem; + margin-bottom: 0.85rem; + background: rgba(255,255,255,0.025); +} +.builder-title { + display: flex; + align-items: center; + gap: 0.5rem; + margin-bottom: 0.7rem; +} +.builder-title strong { font-size: 0.86rem; flex: 1; } +.quick-actions { + display: flex; + align-items: center; + gap: 0.45rem; + flex-wrap: wrap; + margin-bottom: 0.65rem; +} +.quick-actions-title { + color: var(--muted); + font-size: 0.76rem; + margin-right: 0.15rem; +} +.route-summary { + display: flex; + gap: 0.4rem; + flex-wrap: wrap; + margin-bottom: 0.75rem; +} +.route-pill { + font-size: 0.74rem; + color: var(--muted); + border: 1px solid var(--border); + border-radius: 999px; + padding: 0.18rem 0.5rem; + background: rgba(255,255,255,0.035); +} +.route-pill strong { color: var(--text); font-weight: 600; } +.snippet-list { display: flex; flex-direction: column; gap: 0.75rem; } +.snippet-card { + border: 1px solid var(--border); + border-radius: 8px; + padding: 0.75rem; + background: rgba(255,255,255,0.025); +} +.snippet-head { + display: flex; + align-items: center; + gap: 0.5rem; + margin-bottom: 0.65rem; +} +.snippet-name { + flex: 1; + background: #0d0f18; + border: 1px solid var(--border); + border-radius: 6px; + color: var(--accent); + font-family: 'JetBrains Mono', monospace; + font-size: 0.84rem; + padding: 0.45rem 0.6rem; + min-width: 0; +} +.snippet-name:focus { border-color: var(--accent); outline: none; } + /* ── Site cards ── */ .sites-bar { display: flex; @@ -463,6 +626,15 @@ textarea.code:focus { border-color: var(--accent); } } #no-sites { color: var(--muted); font-size: 0.875rem; padding: 0.25rem 0; display: none; } +#no-snippets { color: var(--muted); font-size: 0.875rem; padding: 0.25rem 0; display: none; } + +@media (max-width: 640px) { + header { align-items: flex-start; flex-wrap: wrap; } + header h1 { flex-basis: 100%; } + main { padding: 1rem; } + .site-card-header, .snippet-head { align-items: flex-start; flex-wrap: wrap; } + .site-address, .snippet-name { flex-basis: 100%; } +} /* ── Buttons ── */ .btn { @@ -561,6 +733,28 @@ textarea.code:focus { border-color: var(--accent); }
+
+ Editor mode +
+ + +
+ Structured mode is safer; raw mode is an escape hatch for advanced Caddyfile edits. +
+ + + +
@@ -573,15 +767,35 @@ textarea.code:focus { border-color: var(--accent); }
+ +
+
+ ▶ + Reusable Snippets + 0 +
+
+
Top-level Caddyfile snippets like (cors-origin). Use imports from site blocks or generated host routes.
+
+ + +
+
+
No reusable snippets configured.
+
+
+
Sites +
No sites configured. Click "+ Add Site" to create one.
+
@@ -600,7 +814,10 @@ textarea.code:focus { border-color: var(--accent); }
diff --git a/docker-compose.yml b/docker-compose.yml index ba1b0b6..0255a22 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,8 @@ services: koncad: + build: + context: . image: git.d4nn13.de/d4nn13/koncad:latest restart: unless-stopped volumes: diff --git a/docs/deployments/2026-05-03-remote-deploy-debug.md b/docs/deployments/2026-05-03-remote-deploy-debug.md new file mode 100644 index 0000000..da25e1f --- /dev/null +++ b/docs/deployments/2026-05-03-remote-deploy-debug.md @@ -0,0 +1,34 @@ +# Remote Deploy Debug Log + +Date: 2026-05-03 +Target: `daniel@172.30.16.10:/opt/KonCad` + +## Summary + +- The remote host was already running `koncad-koncad-1` on port `8080`. +- `/opt/KonCad` only contained deployment metadata (`Dockerfile`, `docker-compose.yml`, workflow files) and did not contain `app/`. +- The original deploy flow synced source files to `/opt/KonCad`, but `docker-compose.yml` used only the published image, so remote source changes were not applied unless the host rebuilt separately. + +## Changes made + +- Added `build: .` to `docker-compose.yml` so the server can build from the synced checkout. +- Updated `deploy.sh` to run `docker compose up -d --build` on the remote host after `rsync`. +- Added `--no-remote-restart` for cases where only file sync is wanted. +- Added `.dockerignore` and tightened `rsync` excludes so editor metadata and docs are not part of the deployment payload. + +## Remote checks performed + +- Confirmed container status with `docker ps`. +- Confirmed the live app answered on `http://127.0.0.1:8080/`. +- Confirmed the container mounts `/opt/caddy` read-only and persists `/data` in the `koncad_koncad_data` volume. +- Confirmed existing auth state is already present in `/data/.auth`. +- Rebuilt the container on the host with `docker compose up -d --build`. +- Verified `/opt/KonCad/app/index.php` and `/var/www/html/index.php` have the same SHA-256 hash after deploy. +- Verified `php -l /var/www/html/index.php` passes inside the running container. +- Verified KonCad can reach `http://caddy:2019/config/` from inside the container. +- Cleaned stale `.claude`, `.superpowers`, and `docs` directories from `/opt/KonCad` on the server. + +## Notes + +- Local PHP tooling was not available in this workspace (`php: command not found`), so syntax/runtime verification was done on the remote host. +- The Apache log still shows the harmless `Could not reliably determine the server's fully qualified domain name` startup warning from the base image. diff --git a/docs/superpowers/specs/2026-04-27-koncad-ui-redesign-design.md b/docs/superpowers/specs/2026-04-27-koncad-ui-redesign-design.md new file mode 100644 index 0000000..19c8093 --- /dev/null +++ b/docs/superpowers/specs/2026-04-27-koncad-ui-redesign-design.md @@ -0,0 +1,264 @@ + +# KonCad UI redesign — design + +Refresh the KonCad web UI with a "Soft Slate" visual style (GitHub / Notion-dark +inspired), light/dark via `prefers-color-scheme`, lightweight inline syntax +highlighting for the Caddyfile editors, and a handful of small UX wins. No +backend changes; same single-file PHP structure. + +## Goals + +- A modern, calm, information-dense look that fits a homelab tool you open + occasionally. +- Auto-respect the OS color-scheme preference (no manual toggle). +- Make the Caddyfile editors readable at a glance with simple syntax colors. +- Add a small set of polish improvements that the new look invites — without + changing what the app does or its data flow. + +## Non-goals + +- No changes to PHP backend logic (parser, save handler, upstream check, auth + model). +- No new dependencies. Stays a single-file PHP tool — no CDN, no build step. +- No structural rework — header / global panel / list of sites stays. +- No new features (no draft staging, no diff view, no per-directive forms, + no bulk site operations, no manual theme toggle). +- No editor features beyond highlighting (no line numbers, no bracket matching, + no autocomplete). + +## Visual system + +CSS custom properties on `:root` for dark, overridden inside +`@media (prefers-color-scheme: light)`. Both auth screens and the main page +use the same token set. + +| Token | Dark | Light | Used for | +|---|---|---|---| +| `--bg` | `#0d1117` | `#f6f8fa` | page background | +| `--surface` | `#161b22` | `#ffffff` | panels, cards | +| `--surface-2` | `#0d1117` | `#f6f8fa` | editor / nested surfaces | +| `--border` | `#21262d` | `#d0d7de` | every divider | +| `--text` | `#e6edf3` | `#1f2328` | primary text | +| `--muted` | `#7d8590` | `#656d76` | labels, subtle text | +| `--accent` | `#58a6ff` | `#0969da` | links, focus, addresses | +| `--accent-bg` | `rgba(88,166,255,0.12)` | `rgba(9,105,218,0.1)` | accent backgrounds, focus ring | +| `--ok` | `#3fb950` | `#1a7f37` | success status | +| `--warn` | `#d29922` | `#9a6700` | warnings | +| `--error` | `#f85149` | `#cf222e` | errors | + +**Type:** Inter via system stack +(`-apple-system, "Segoe UI", "Inter", system-ui, sans-serif`); JetBrains Mono +for code (with monospace fallback). Sizes: 13px base, 12px secondary, 11px +labels/badges. + +**Geometry:** 8px radius on inputs/buttons, 10px on panels. 1px borders +throughout — no drop shadows. Focus ring: `0 0 0 3px var(--accent-bg)` on +inputs and buttons. Spacing on a 4px grid. + +## Layout + +Same three regions as today. + +### Header (sticky) + +- Left: a small (18×18) gradient square logo mark + "KonCad" word in 700 + weight, `-0.01em` letter-spacing. +- Center: a status pill — `● Caddy ready` (green) on success, + `● Caddy unreachable` (red) when the admin API is down, `● Deploying…` + (amber, with a 1.4s pulse animation) during a deploy. Pill background uses + a tinted version of its color. +- Right: primary `Deploy` button (green, GitHub-style primary) and a quiet + `Log out` ghost button when auth is enabled. + +### Main column + +- `max-width: 960px` centered, 1.5rem horizontal padding. +- **Global Options panel** — surface card with a header strip + (`Global Options` title + a small grey badge counting non-blank, + non-comment lines, e.g. `2 directives`). Body holds the highlighted editor. +- **Sites section** — section title `Sites` with a `+ Add site` ghost button on + the right, then a vertical list of site cards. + +### Site card + +- **Collapsed**: chevron, address (mono, `--accent` color), a one-line summary + chip (`→ host:port` if the body has a `reverse_proxy` line, else + `N directives`), and a `Remove` ghost-danger button visible on hover. +- **Expanded**: address bar, the highlighted editor, and any + `upstream-warnings` rendering area (existing slot, restyled). + +### Empty state for sites + +A dashed-border placeholder card replacing the current grey one-liner: small +icon (`⊕` or similar), heading `No sites yet`, and an inline primary +`+ Add site` button. + +### Auth screens (setup / login) + +Same centered-card pattern, retoned to the new tokens. Logo mark + "KonCad" +header, subtitle (`Create your login credentials` / `Sign in to continue`), +form with one username + one password input and a primary submit button. +Inline error message uses `--error`. + +### Modals & toasts + +- **Upstream warning modal**: same content, retoned. Dark-mode backdrop gets + `backdrop-filter: blur(4px)`. +- **Toasts**: same triggers, restyled. Slide in with + `transform: translateY(8px) → 0`, fade. Auto-dismiss at 5s (unchanged). + +## Highlighted editor + +Textarea-overlay technique. Native cursor, undo, IME, copy/paste behavior is +preserved; the highlighted layer is purely decorative. + +### Markup per editor + +```html +
+ + +
+``` + +### Mechanics + +- `
` and `