(cors-origin). Use imports from site blocks or generated host routes.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); }
(cors-origin). Use imports from site blocks or generated host routes.
` and `