@studiometa/trafic-agent 0.1.32 → 0.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +4 -4
- package/dist/index.js +2 -2
- package/dist/{server-BgOOBUhR.js → server-DtqKdFMF.js} +94 -28
- package/dist/server-DtqKdFMF.js.map +1 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -2
- package/dist/setup/ddev.d.ts +28 -1
- package/dist/setup/ddev.d.ts.map +1 -1
- package/dist/setup/migrations/0010__catchall_entrypoints.d.ts +23 -0
- package/dist/setup/migrations/0010__catchall_entrypoints.d.ts.map +1 -0
- package/dist/setup/migrations/index.d.ts.map +1 -1
- package/dist/{setup-vg_pqnPs.js → setup-Pv2K4pJF.js} +42 -5
- package/dist/setup-Pv2K4pJF.js.map +1 -0
- package/dist/utils/traefik.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/server-BgOOBUhR.js.map +0 -1
- package/dist/setup-vg_pqnPs.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { d as validateConfig, i as runPendingMigrations, l as loadConfig, n as setup, r as listMigrations, s as startIdleScheduler, t as audit } from "./setup-
|
|
3
|
-
import {
|
|
2
|
+
import { d as validateConfig, i as runPendingMigrations, l as loadConfig, n as setup, r as listMigrations, s as startIdleScheduler, t as audit } from "./setup-Pv2K4pJF.js";
|
|
3
|
+
import { T as closeDb, b as warn, f as exec, h as isRoot, m as info, r as startServer, v as step, y as success } from "./server-DtqKdFMF.js";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
import { execSync, spawnSync } from "node:child_process";
|
|
6
6
|
import { parseArgs } from "node:util";
|
|
@@ -108,7 +108,7 @@ function runUpgrade(dryRun = false, reExecArgs) {
|
|
|
108
108
|
}
|
|
109
109
|
const alreadyReExeced = process.env["TRAFIC_UPGRADE_REEXEC"] === "1";
|
|
110
110
|
step("Check for updates");
|
|
111
|
-
const current = "0.1.
|
|
111
|
+
const current = "0.1.34";
|
|
112
112
|
info(`Current version: ${current}`);
|
|
113
113
|
const latest = fetchLatestVersion();
|
|
114
114
|
if (!latest) warn("Could not reach npm registry — skipping version check");
|
|
@@ -191,7 +191,7 @@ function printHelp() {
|
|
|
191
191
|
console.log(HELP.trim());
|
|
192
192
|
}
|
|
193
193
|
function printVersion() {
|
|
194
|
-
console.log("0.1.
|
|
194
|
+
console.log("0.1.34");
|
|
195
195
|
}
|
|
196
196
|
async function runStart(values) {
|
|
197
197
|
const config = loadConfig(values.config);
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as printAuditResults, c as stopIdleProjects, d as validateConfig, l as loadConfig, n as setup, o as runAudit, s as startIdleScheduler, t as audit, u as parseDuration } from "./setup-
|
|
2
|
-
import { A as
|
|
1
|
+
import { a as printAuditResults, c as stopIdleProjects, d as validateConfig, l as loadConfig, n as setup, o as runAudit, s as startIdleScheduler, t as audit, u as parseDuration } from "./setup-Pv2K4pJF.js";
|
|
2
|
+
import { A as initDb, B as stopProject, C as shouldNeverStop, D as getDb, E as getAccessLogs, F as getProjectFromHostname, G as parseBasicAuth, H as checkAuth, I as getProjectInfo, K as parseBearerToken, L as listProjects, M as setProjectStatus, N as updateProjectAccess, O as getIdleProjects, P as buildHostnameIndex, R as loadProjectList, S as loadProjectConfig, T as closeDb, U as matchHostname, V as watchProjectList, W as matchIp, j as logAccess, k as getProject, r as startServer, w as cleanOldLogs, x as getIdleTimeoutMs, z as startProject } from "./server-DtqKdFMF.js";
|
|
3
3
|
export { audit, buildHostnameIndex, checkAuth, cleanOldLogs, closeDb, getAccessLogs, getDb, getIdleProjects, getIdleTimeoutMs, getProject, getProjectFromHostname, getProjectInfo, initDb, listProjects, loadConfig, loadProjectConfig, loadProjectList, logAccess, matchHostname, matchIp, parseBasicAuth, parseBearerToken, parseDuration, printAuditResults, runAudit, setProjectStatus, setup, shouldNeverStop, startIdleScheduler, startProject, startServer, stopIdleProjects, stopProject, updateProjectAccess, validateConfig, watchProjectList };
|
|
@@ -774,6 +774,27 @@ function readToolPorts(io = nodeIo) {
|
|
|
774
774
|
}
|
|
775
775
|
return [...new Set(ports)];
|
|
776
776
|
}
|
|
777
|
+
/** Used when the global config does not say otherwise */
|
|
778
|
+
var DEFAULT_ROUTER_PORTS = {
|
|
779
|
+
http: "80",
|
|
780
|
+
https: "443"
|
|
781
|
+
};
|
|
782
|
+
/**
|
|
783
|
+
* Read the ports ddev-router serves projects on.
|
|
784
|
+
*
|
|
785
|
+
* Traefik names an entry point after its port, so these decide what the
|
|
786
|
+
* catch-all routers and the auth middleware must attach to. Hardcoding 80 and
|
|
787
|
+
* 443 is wrong on any server where the router was moved — which is every
|
|
788
|
+
* server running a host ingress in front of it.
|
|
789
|
+
*/
|
|
790
|
+
function readRouterPorts(io = nodeIo) {
|
|
791
|
+
const output = io.execSilent("su - ddev -c 'ddev config global'");
|
|
792
|
+
const read = (key, fallback) => new RegExp(`^${key}=(\\d+)$`, "m").exec(output)?.[1] ?? fallback;
|
|
793
|
+
return {
|
|
794
|
+
http: read("router-http-port", DEFAULT_ROUTER_PORTS.http),
|
|
795
|
+
https: read("router-https-port", DEFAULT_ROUTER_PORTS.https)
|
|
796
|
+
};
|
|
797
|
+
}
|
|
777
798
|
/**
|
|
778
799
|
* Build the static config attaching forward auth to every entry point.
|
|
779
800
|
*
|
|
@@ -781,7 +802,7 @@ function readToolPorts(io = nodeIo) {
|
|
|
781
802
|
* stopped project should show the waiting page, while a tool port has nothing
|
|
782
803
|
* to wait for.
|
|
783
804
|
*/
|
|
784
|
-
function buildStaticConfig(toolPorts) {
|
|
805
|
+
function buildStaticConfig(toolPorts, routerPorts = DEFAULT_ROUTER_PORTS) {
|
|
785
806
|
const webEntryPoint = (name) => ` ${name}:
|
|
786
807
|
http:
|
|
787
808
|
middlewares:
|
|
@@ -793,18 +814,25 @@ function buildStaticConfig(toolPorts) {
|
|
|
793
814
|
middlewares:
|
|
794
815
|
- trafic-auth@file
|
|
795
816
|
`;
|
|
817
|
+
const web = [routerPorts.http, routerPorts.https];
|
|
818
|
+
const tools = toolPorts.filter((port) => !web.includes(port));
|
|
796
819
|
return `entryPoints:
|
|
797
|
-
${webEntryPoint(
|
|
820
|
+
${web.map((port) => webEntryPoint(`http-${port}`)).join("")}${tools.map(toolEntryPoint).join("")}`;
|
|
798
821
|
}
|
|
799
822
|
/**
|
|
800
|
-
*
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
823
|
+
* Build the dynamic config: the middlewares, the agent service, and the
|
|
824
|
+
* catch-all routers that hand a stopped project to the waiting page.
|
|
825
|
+
*
|
|
826
|
+
* One catch-all per web entry point, each naming the entry point it serves.
|
|
827
|
+
* A router that names none is instantiated by Traefik on *every* entry point,
|
|
828
|
+
* and DDEV's router health check compares the number of router definitions in
|
|
829
|
+
* its config files against the number Traefik reports. Two unpinned
|
|
830
|
+
* definitions became fourteen instances on a server with six tool entry
|
|
831
|
+
* points, so the counts never matched, the health check waited out its
|
|
832
|
+
* timeout, and every `ddev start` failed after 60 seconds.
|
|
833
|
+
*/
|
|
834
|
+
function buildDynamicConfig(gatewayIp, routerPorts = DEFAULT_ROUTER_PORTS) {
|
|
835
|
+
return `# Trafic: Forward auth middleware definition
|
|
808
836
|
http:
|
|
809
837
|
middlewares:
|
|
810
838
|
trafic-auth:
|
|
@@ -822,22 +850,29 @@ http:
|
|
|
822
850
|
query: "/"
|
|
823
851
|
|
|
824
852
|
routers:
|
|
825
|
-
# Lowest priority, so a DDEV project router always wins.
|
|
826
|
-
# when none does
|
|
853
|
+
# Lowest priority, so a DDEV project router always wins. These only match
|
|
854
|
+
# when none does — which is what a stopped project produces, because DDEV
|
|
827
855
|
# removes that project's router and Traefik would otherwise answer 404.
|
|
828
|
-
# Without
|
|
856
|
+
# Without them the waiting page never appears and scale-to-zero never
|
|
829
857
|
# restarts anything. Auth is unaffected: it is attached at the entry
|
|
830
858
|
# point, not here, so this cannot reintroduce the bypass that #27 fixed.
|
|
831
859
|
#
|
|
832
|
-
#
|
|
833
|
-
#
|
|
860
|
+
# Each names exactly one entry point. Leaving entryPoints out attaches a
|
|
861
|
+
# router to all of them, which breaks DDEV's router health check — it
|
|
862
|
+
# counts definitions and compares them to what Traefik loaded.
|
|
834
863
|
trafic-catchall:
|
|
835
864
|
rule: "PathPrefix(\`/\`)"
|
|
865
|
+
entryPoints:
|
|
866
|
+
- http-${routerPorts.http}
|
|
836
867
|
priority: 1
|
|
837
868
|
service: trafic-service
|
|
838
869
|
|
|
870
|
+
# Carries tls, so it only matches the https entry point. The plain one
|
|
871
|
+
# above cannot serve it, and one alone would leave HTTP answering 404.
|
|
839
872
|
trafic-catchall-tls:
|
|
840
873
|
rule: "PathPrefix(\`/\`)"
|
|
874
|
+
entryPoints:
|
|
875
|
+
- http-${routerPorts.https}
|
|
841
876
|
priority: 1
|
|
842
877
|
service: trafic-service
|
|
843
878
|
tls: {}
|
|
@@ -848,23 +883,37 @@ http:
|
|
|
848
883
|
servers:
|
|
849
884
|
- url: "http://${gatewayIp}:9876"
|
|
850
885
|
`;
|
|
851
|
-
|
|
852
|
-
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Configure Traefik for forward auth
|
|
889
|
+
*/
|
|
890
|
+
function configureTraefik(io = nodeIo) {
|
|
891
|
+
step("Configure Traefik for forward auth");
|
|
892
|
+
io.exec("mkdir -p /home/ddev/.ddev/traefik/custom-global-config", { silent: true });
|
|
893
|
+
io.exec("chown -R ddev:ddev /home/ddev/.ddev", { silent: true });
|
|
894
|
+
const gatewayIp = getDockerGatewayIp(io);
|
|
895
|
+
const routerPorts = readRouterPorts(io);
|
|
896
|
+
const dynamicConfig = buildDynamicConfig(gatewayIp, routerPorts);
|
|
853
897
|
io.writeFile("/home/ddev/.ddev/traefik/custom-global-config/trafic.yaml", dynamicConfig);
|
|
854
898
|
io.exec("chown ddev:ddev /home/ddev/.ddev/traefik/custom-global-config/trafic.yaml", { silent: true });
|
|
855
|
-
const staticConfig = buildStaticConfig(readToolPorts(io));
|
|
899
|
+
const staticConfig = buildStaticConfig(readToolPorts(io), routerPorts);
|
|
856
900
|
io.writeFile("/home/ddev/.ddev/traefik/static_config.trafic.yaml", staticConfig);
|
|
857
901
|
io.exec("chown ddev:ddev /home/ddev/.ddev/traefik/static_config.trafic.yaml", { silent: true });
|
|
902
|
+
info(`Entry points: http-${routerPorts.http}, http-${routerPorts.https} (web) plus tool ports`);
|
|
858
903
|
success("Traefik configured with Trafic middleware");
|
|
859
904
|
}
|
|
860
905
|
//#endregion
|
|
861
906
|
//#region src/utils/traefik.ts
|
|
862
907
|
/**
|
|
863
908
|
* Files DDEV reads the dynamic Traefik configuration from, relative to the
|
|
864
|
-
* .ddev directory.
|
|
865
|
-
*
|
|
909
|
+
* .ddev directory.
|
|
910
|
+
*
|
|
911
|
+
* Only custom-global-config: DDEV copies that into the ddev-global-cache
|
|
912
|
+
* volume, which is where Traefik actually reads from. Setup used to write a
|
|
913
|
+
* second copy at the traefik root for older DDEV versions; migration 0010
|
|
914
|
+
* removes it, and nothing reads it on 1.25.
|
|
866
915
|
*/
|
|
867
|
-
var DYNAMIC_CONFIGS = ["traefik/
|
|
916
|
+
var DYNAMIC_CONFIGS = ["traefik/custom-global-config/trafic.yaml"];
|
|
868
917
|
/** Matches the host in an agent URL, e.g. http://172.17.0.1:9876/__auth__ */
|
|
869
918
|
var AGENT_URL = /http:\/\/(\d+\.\d+\.\d+\.\d+):(\d+)/g;
|
|
870
919
|
/**
|
|
@@ -1057,15 +1106,32 @@ function handleStatus(req, res) {
|
|
|
1057
1106
|
}));
|
|
1058
1107
|
}
|
|
1059
1108
|
/**
|
|
1109
|
+
* The path a request should be routed on, without the query string.
|
|
1110
|
+
*
|
|
1111
|
+
* `req.url` is a target, not a URL: it carries the query and, for a proxied
|
|
1112
|
+
* request, may be absolute. Parsing against a fixed base keeps a malformed or
|
|
1113
|
+
* absolute target from deciding the route, and a trailing slash is dropped so
|
|
1114
|
+
* `/__auth__/` and `/__auth__` are the same endpoint.
|
|
1115
|
+
*/
|
|
1116
|
+
function routePath(target) {
|
|
1117
|
+
let path;
|
|
1118
|
+
try {
|
|
1119
|
+
path = new URL(target ?? "/", "http://localhost").pathname;
|
|
1120
|
+
} catch {
|
|
1121
|
+
return "/";
|
|
1122
|
+
}
|
|
1123
|
+
return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1060
1126
|
* Request handler
|
|
1061
1127
|
*/
|
|
1062
1128
|
async function handleRequest(req, res) {
|
|
1063
|
-
const
|
|
1129
|
+
const path = routePath(req.url);
|
|
1064
1130
|
try {
|
|
1065
|
-
if (
|
|
1066
|
-
else if (
|
|
1067
|
-
else if (
|
|
1068
|
-
else if (
|
|
1131
|
+
if (path === "/__auth__" || path.startsWith("/__auth__/")) handleAuth(req, res);
|
|
1132
|
+
else if (path === "/__status__" || path.startsWith("/__status__/")) handleStatus(req, res);
|
|
1133
|
+
else if (path === "/__tls__") handleTlsAsk(req, res);
|
|
1134
|
+
else if (path === "/__health__") {
|
|
1069
1135
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1070
1136
|
res.end(JSON.stringify({
|
|
1071
1137
|
status: "ok",
|
|
@@ -1121,6 +1187,6 @@ function startServer(agentConfig) {
|
|
|
1121
1187
|
});
|
|
1122
1188
|
}
|
|
1123
1189
|
//#endregion
|
|
1124
|
-
export {
|
|
1190
|
+
export { initDb as A, stopProject as B, shouldNeverStop as C, getDb as D, getAccessLogs as E, getProjectFromHostname as F, parseBasicAuth as G, checkAuth as H, getProjectInfo as I, parseBearerToken as K, listProjects as L, setProjectStatus as M, updateProjectAccess as N, getIdleProjects as O, buildHostnameIndex as P, loadProjectList as R, loadProjectConfig as S, closeDb as T, matchHostname as U, watchProjectList as V, matchIp as W, setDryRun as _, configureDdev as a, warn as b, installDdev as c, error as d, exec as f, resetSteps as g, isRoot as h, addDdevAptRepo as i, logAccess as j, getProject as k, installSystemDeps as l, info as m, routePath as n, configureTraefik as o, execSilent as p, startServer as r, getDockerGatewayIp as s, allowTlsFor as t, nodeIo as u, step as v, cleanOldLogs as w, getIdleTimeoutMs as x, success as y, startProject as z };
|
|
1125
1191
|
|
|
1126
|
-
//# sourceMappingURL=server-
|
|
1192
|
+
//# sourceMappingURL=server-DtqKdFMF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-DtqKdFMF.js","names":[],"sources":["../src/utils/auth.ts","../src/utils/ddev.ts","../src/utils/db.ts","../src/utils/project-config.ts","../src/setup/steps.ts","../src/setup/io.ts","../src/setup/ddev.ts","../src/utils/traefik.ts","../src/server.ts"],"sourcesContent":["import type { AuthConfig, AuthRequest, AuthResult, AuthRule } from \"../types.js\";\n\n/**\n * Check if an IP matches a pattern (supports CIDR notation)\n */\nexport function matchIp(ip: string, pattern: string): boolean {\n // Exact match\n if (ip === pattern) return true;\n\n // CIDR notation\n if (pattern.includes(\"/\")) {\n return matchCidr(ip, pattern);\n }\n\n // Wildcard (e.g., 192.168.*)\n if (pattern.includes(\"*\")) {\n const regex = new RegExp(\n \"^\" + pattern.replace(/\\./g, \"\\\\.\").replace(/\\*/g, \".*\") + \"$\",\n );\n return regex.test(ip);\n }\n\n return false;\n}\n\n/**\n * Match IP against CIDR range\n */\nfunction matchCidr(ip: string, cidr: string): boolean {\n const [range, bits] = cidr.split(\"/\");\n const mask = parseInt(bits, 10);\n\n const ipNum = ipToNumber(ip);\n const rangeNum = ipToNumber(range);\n\n if (ipNum === null || rangeNum === null) return false;\n\n const maskNum = ~((1 << (32 - mask)) - 1);\n return (ipNum & maskNum) === (rangeNum & maskNum);\n}\n\n/**\n * Convert IP string to number\n */\nfunction ipToNumber(ip: string): number | null {\n const parts = ip.split(\".\");\n if (parts.length !== 4) return null;\n\n let num = 0;\n for (const part of parts) {\n const n = parseInt(part, 10);\n if (isNaN(n) || n < 0 || n > 255) return null;\n num = (num << 8) | n;\n }\n return num >>> 0; // Convert to unsigned\n}\n\n/**\n * Match hostname against a glob pattern\n */\nexport function matchHostname(hostname: string, pattern: string): boolean {\n // Exact match\n if (hostname === pattern) return true;\n\n // Glob pattern\n const regex = new RegExp(\n \"^\" +\n pattern\n .replace(/[.+^${}()|[\\]\\\\]/g, \"\\\\$&\")\n .replace(/\\*/g, \".*\")\n .replace(/\\?/g, \".\") +\n \"$\",\n );\n return regex.test(hostname);\n}\n\n/**\n * Parse Basic auth header\n */\nexport function parseBasicAuth(\n header: string,\n): { username: string; password: string } | null {\n if (!header.startsWith(\"Basic \")) return null;\n\n try {\n const encoded = header.slice(6);\n const decoded = Buffer.from(encoded, \"base64\").toString(\"utf-8\");\n const colonIndex = decoded.indexOf(\":\");\n if (colonIndex === -1) return null;\n\n return {\n username: decoded.slice(0, colonIndex),\n password: decoded.slice(colonIndex + 1),\n };\n } catch {\n return null;\n }\n}\n\n/**\n * Parse Bearer token from header\n */\nexport function parseBearerToken(header: string): string | null {\n if (!header.startsWith(\"Bearer \")) return null;\n return header.slice(7);\n}\n\n/**\n * Resolve the client address from the socket peer and X-Forwarded-For.\n *\n * Every proxy appends the address it saw, so the entries grow left to right\n * and the rightmost ones were added by the proxies closest to us. Counting\n * `trustedHops` from the right therefore lands on the client, while anything\n * further left is whatever the client sent and must be ignored.\n *\n * Reading the leftmost entry instead — as this used to — let a client set\n * `X-Forwarded-For: <allowed-ip>` and match the IP allowlist, which grants\n * access unconditionally.\n *\n * Falls back to the socket peer whenever the header cannot be trusted to\n * hold that many entries.\n */\nexport function resolveClientIp(\n socketIp: string,\n forwardedFor: string | undefined,\n trustedHops = 1,\n): string {\n if (!forwardedFor || trustedHops < 1) {\n return socketIp;\n }\n\n const entries = forwardedFor\n .split(\",\")\n .map((entry) => entry.trim())\n .filter(Boolean);\n\n // Fewer entries than trusted proxies means the chain is shorter than\n // configured — the socket peer is the only address we can rely on.\n if (entries.length < trustedHops) {\n return socketIp;\n }\n\n return entries[entries.length - trustedHops] ?? socketIp;\n}\n\n/**\n * Check authentication for a request\n */\nexport function checkAuth(request: AuthRequest, config: AuthConfig): AuthResult {\n const { hostname, ip, authorization } = request;\n\n const realIp = resolveClientIp(ip, request.forwardedFor, config.trustedProxyHops);\n\n // Check IP whitelist first (always allows)\n for (const pattern of config.allowedIps) {\n if (matchIp(realIp, pattern)) {\n return { allowed: true, reason: \"ip\" };\n }\n }\n\n // Check per-hostname rules\n for (const rule of config.rules) {\n if (matchHostname(hostname, rule.match)) {\n return checkRule(rule, realIp, authorization, config);\n }\n }\n\n // Apply default policy\n return applyDefaultPolicy(config, realIp, authorization);\n}\n\n/**\n * Check a specific rule\n */\nfunction checkRule(\n rule: AuthRule,\n ip: string,\n authorization: string | undefined,\n config: AuthConfig,\n): AuthResult {\n // Rule-specific IP whitelist\n if (rule.allowedIps) {\n for (const pattern of rule.allowedIps) {\n if (matchIp(ip, pattern)) {\n return { allowed: true, reason: \"rule\" };\n }\n }\n }\n\n switch (rule.policy) {\n case \"allow\":\n return { allowed: true, reason: \"rule\" };\n\n case \"deny\":\n return { allowed: false, reason: \"rule\" };\n\n case \"token\": {\n if (!authorization) return { allowed: false, reason: \"rule\" };\n const token = parseBearerToken(authorization);\n const tokens = rule.tokens ?? config.tokens;\n if (token && tokens.includes(token)) {\n return { allowed: true, reason: \"token\" };\n }\n return { allowed: false, reason: \"rule\" };\n }\n\n case \"basic\": {\n if (!authorization) return { allowed: false, reason: \"rule\" };\n const creds = parseBasicAuth(authorization);\n if (creds) {\n const credString = `${creds.username}:${creds.password}`;\n if (config.basicAuth.includes(credString)) {\n return { allowed: true, reason: \"basic\" };\n }\n }\n return { allowed: false, reason: \"rule\" };\n }\n\n default:\n return { allowed: false, reason: \"rule\" };\n }\n}\n\n/**\n * Apply default policy\n */\nfunction applyDefaultPolicy(\n config: AuthConfig,\n ip: string,\n authorization: string | undefined,\n): AuthResult {\n switch (config.defaultPolicy) {\n case \"allow\":\n return { allowed: true, reason: \"default\" };\n\n case \"deny\":\n return { allowed: false, reason: \"default\" };\n\n case \"basic\": {\n if (!authorization) return { allowed: false, reason: \"default\" };\n const creds = parseBasicAuth(authorization);\n if (creds) {\n const credString = `${creds.username}:${creds.password}`;\n if (config.basicAuth.includes(credString)) {\n return { allowed: true, reason: \"basic\" };\n }\n }\n // Also check tokens as fallback\n const token = parseBearerToken(authorization);\n if (token && config.tokens.includes(token)) {\n return { allowed: true, reason: \"token\" };\n }\n return { allowed: false, reason: \"default\" };\n }\n\n case \"token\": {\n if (!authorization) return { allowed: false, reason: \"default\" };\n const token = parseBearerToken(authorization);\n if (token && config.tokens.includes(token)) {\n return { allowed: true, reason: \"token\" };\n }\n return { allowed: false, reason: \"default\" };\n }\n\n default:\n return { allowed: false, reason: \"default\" };\n }\n}\n","import { readFileSync, existsSync, watch } from \"node:fs\";\nimport { execSync } from \"node:child_process\";\nimport type { DdevProject } from \"../types.js\";\n\n/** Strip a single pair of surrounding quotes. */\nfunction unquote(value: string): string {\n if (\n (value.startsWith('\"') && value.endsWith('\"')) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n return value.slice(1, -1);\n }\n\n return value;\n}\n\n/** A project name at the start of a line, e.g. `my-project:` */\nconst PROJECT_LINE = /^(\\S[^:]*):\\s*$/;\n\n/** An indented `approot: /path` belonging to the project above it */\nconst APPROOT_LINE = /^\\s+approot:\\s*(.+?)\\s*$/;\n\n/**\n * Load projects from DDEV's project_list.yaml\n * Returns a map of project name -> app root path\n *\n * The file nests the path under the project name:\n *\n * scalian:\n * approot: /home/ddev/www/scalian\n *\n * Indentation therefore has to be read. A flat key/value pass produces one\n * entry per line instead: the project mapped to an empty string, plus a\n * phantom project called `approot`. Both did damage — the empty path meant\n * `loadProjectConfig` looked for `.ddev/config.trafic.yaml` relative to the\n * working directory and never found it, so per-project settings were silently\n * ignored, and the phantom entered the hostname index, where the TLS ask\n * endpoint would vouch for `approot.<tld>` and have a certificate issued for\n * a project that does not exist.\n */\nexport function loadProjectList(\n projectListPath: string,\n): Map<string, string> {\n if (!existsSync(projectListPath)) {\n return new Map();\n }\n\n const projects = new Map<string, string>();\n let current: string | undefined;\n\n for (const line of readFileSync(projectListPath, \"utf-8\").split(\"\\n\")) {\n if (!line.trim() || line.trimStart().startsWith(\"#\")) {\n continue;\n }\n\n const project = PROJECT_LINE.exec(line);\n\n if (project) {\n current = unquote(project[1]!.trim());\n // Recorded now so a project keeps its hostname even if DDEV writes no\n // approot for it\n projects.set(current, \"\");\n continue;\n }\n\n const approot = APPROOT_LINE.exec(line);\n\n if (approot && current) {\n projects.set(current, unquote(approot[1]!));\n }\n }\n\n return projects;\n}\n\n/**\n * Build a hostname -> project name index\n */\nexport function buildHostnameIndex(\n projects: Map<string, string>,\n tld: string,\n): Map<string, string> {\n const index = new Map<string, string>();\n\n for (const [name] of projects) {\n // Primary hostname: project-name.tld\n index.set(`${name}.${tld}`, name);\n }\n\n return index;\n}\n\n/**\n * Get project name from hostname\n */\nexport function getProjectFromHostname(\n hostname: string,\n index: Map<string, string>,\n): string | undefined {\n return index.get(hostname);\n}\n\n/**\n * Watch project_list.yaml for changes\n */\nexport function watchProjectList(\n projectListPath: string,\n onChange: () => void,\n): void {\n if (!existsSync(projectListPath)) {\n console.warn(`Project list not found: ${projectListPath}`);\n return;\n }\n\n watch(projectListPath, (eventType) => {\n if (eventType === \"change\") {\n onChange();\n }\n });\n}\n\n/**\n * Get detailed project info using ddev describe\n */\nexport function getProjectInfo(name: string): DdevProject | undefined {\n try {\n const output = execSync(`ddev describe ${name} -j`, {\n encoding: \"utf-8\",\n timeout: 10000,\n });\n const data = JSON.parse(output);\n\n if (!data.raw) return undefined;\n\n const raw = data.raw;\n return {\n name: raw.name,\n status: raw.status,\n appRoot: raw.approot,\n httpURLs: raw.httpURLs ?? [],\n httpsURLs: raw.httpsURLs ?? [],\n type: raw.type,\n phpVersion: raw.php_version,\n dbType: raw.dbinfo?.dbType,\n };\n } catch {\n return undefined;\n }\n}\n\n/**\n * Start a DDEV project\n */\nexport function startProject(name: string): boolean {\n try {\n execSync(`ddev start ${name}`, {\n encoding: \"utf-8\",\n timeout: 120000, // 2 minutes\n stdio: \"pipe\",\n });\n return true;\n } catch (error) {\n console.error(`Failed to start project ${name}:`, error);\n return false;\n }\n}\n\n/**\n * Stop a DDEV project\n */\nexport function stopProject(name: string): boolean {\n try {\n execSync(`ddev stop ${name}`, {\n encoding: \"utf-8\",\n timeout: 60000, // 1 minute\n stdio: \"pipe\",\n });\n return true;\n } catch (error) {\n console.error(`Failed to stop project ${name}:`, error);\n return false;\n }\n}\n\n/**\n * List all DDEV projects with their status\n */\nexport function listProjects(): DdevProject[] {\n try {\n const output = execSync(\"ddev list -j\", {\n encoding: \"utf-8\",\n timeout: 30000,\n });\n const data = JSON.parse(output);\n\n if (!Array.isArray(data)) return [];\n\n return data.map((p: Record<string, unknown>) => ({\n name: p.name as string,\n status: p.status as DdevProject[\"status\"],\n appRoot: p.approot as string,\n httpURLs: (p.httpURLs as string[]) ?? [],\n httpsURLs: (p.httpsURLs as string[]) ?? [],\n type: p.type as string,\n }));\n } catch {\n return [];\n }\n}\n","import { DatabaseSync } from \"node:sqlite\";\nimport type { ProjectRecord, AccessLog } from \"../types.js\";\n\nlet db: DatabaseSync | null = null;\n\n/**\n * Initialize the database connection and schema\n */\nexport function initDb(dbPath: string): DatabaseSync {\n db = new DatabaseSync(dbPath);\n db.exec(\"PRAGMA journal_mode=WAL\");\n\n // Create tables\n db.exec(`\n CREATE TABLE IF NOT EXISTS projects (\n name TEXT PRIMARY KEY,\n last_access INTEGER NOT NULL,\n status TEXT NOT NULL DEFAULT 'stopped'\n );\n\n CREATE TABLE IF NOT EXISTS access_logs (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n project TEXT NOT NULL,\n timestamp INTEGER NOT NULL,\n ip TEXT NOT NULL,\n user_agent TEXT NOT NULL,\n path TEXT NOT NULL\n );\n\n CREATE INDEX IF NOT EXISTS idx_access_logs_project ON access_logs(project);\n CREATE INDEX IF NOT EXISTS idx_access_logs_timestamp ON access_logs(timestamp);\n `);\n\n return db;\n}\n\n/**\n * Get the database instance\n */\nexport function getDb(): DatabaseSync {\n if (!db) {\n throw new Error(\"Database not initialized. Call initDb first.\");\n }\n return db;\n}\n\n/**\n * Close the database connection\n */\nexport function closeDb(): void {\n if (db) {\n db.close();\n db = null;\n }\n}\n\n/**\n * Update project last access time\n */\nexport function updateProjectAccess(name: string): void {\n const database = getDb();\n const stmt = database.prepare(`\n INSERT INTO projects (name, last_access, status)\n VALUES (?, ?, 'running')\n ON CONFLICT(name) DO UPDATE SET last_access = excluded.last_access\n `);\n stmt.run(name, Date.now());\n}\n\n/**\n * Get project record\n */\nexport function getProject(name: string): ProjectRecord | undefined {\n const database = getDb();\n const stmt = database.prepare(\n \"SELECT name, last_access as lastAccess, status FROM projects WHERE name = ?\",\n );\n return stmt.get(name) as unknown as ProjectRecord | undefined;\n}\n\n/**\n * Set project status\n */\nexport function setProjectStatus(\n name: string,\n status: ProjectRecord[\"status\"],\n): void {\n const database = getDb();\n const stmt = database.prepare(`\n INSERT INTO projects (name, last_access, status)\n VALUES (?, ?, ?)\n ON CONFLICT(name) DO UPDATE SET status = excluded.status\n `);\n stmt.run(name, Date.now(), status);\n}\n\n/**\n * Get idle projects (last access older than threshold)\n */\nexport function getIdleProjects(thresholdMs: number): ProjectRecord[] {\n const database = getDb();\n const cutoff = Date.now() - thresholdMs;\n const stmt = database.prepare(`\n SELECT name, last_access as lastAccess, status\n FROM projects\n WHERE last_access < ? AND status = 'running'\n `);\n return stmt.all(cutoff) as unknown as ProjectRecord[];\n}\n\n/**\n * Log an access\n */\nexport function logAccess(log: Omit<AccessLog, \"id\">): void {\n const database = getDb();\n const stmt = database.prepare(`\n INSERT INTO access_logs (project, timestamp, ip, user_agent, path)\n VALUES (?, ?, ?, ?, ?)\n `);\n stmt.run(log.project, log.timestamp, log.ip, log.userAgent, log.path);\n}\n\n/**\n * Get recent access logs for a project\n */\nexport function getAccessLogs(project: string, limit = 100): AccessLog[] {\n const database = getDb();\n const stmt = database.prepare(`\n SELECT id, project, timestamp, ip, user_agent as userAgent, path\n FROM access_logs\n WHERE project = ?\n ORDER BY timestamp DESC\n LIMIT ?\n `);\n return stmt.all(project, limit) as unknown as AccessLog[];\n}\n\n/**\n * Clean old access logs (older than given days)\n */\nexport function cleanOldLogs(days: number): number {\n const database = getDb();\n const cutoff = Date.now() - days * 24 * 60 * 60 * 1000;\n const stmt = database.prepare(\"DELETE FROM access_logs WHERE timestamp < ?\");\n const result = stmt.run(cutoff);\n return Number(result.changes);\n}\n","import { readFileSync, existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\n/**\n * Per-project Trafic configuration\n * Read from .ddev/config.trafic.yaml\n */\nexport interface ProjectConfig {\n /** Auth policy override: allow | deny | basic | token */\n auth_policy?: \"allow\" | \"deny\" | \"basic\" | \"token\";\n /** Idle timeout override: \"never\" or duration like \"30m\", \"4h\" */\n idle_timeout?: string;\n}\n\n/**\n * Simple YAML parser for config.trafic.yaml\n * Only supports simple key: value pairs (no nesting, no arrays)\n */\nfunction parseSimpleYaml(content: string): Record<string, string> {\n const result: Record<string, string> = {};\n const lines = content.split(\"\\n\");\n\n for (const line of lines) {\n const trimmed = line.trim();\n\n // Skip empty lines and comments\n if (!trimmed || trimmed.startsWith(\"#\")) continue;\n\n const colonIndex = trimmed.indexOf(\":\");\n if (colonIndex === -1) continue;\n\n const key = trimmed.slice(0, colonIndex).trim();\n let value = trimmed.slice(colonIndex + 1).trim();\n\n // Remove quotes if present\n if (\n (value.startsWith('\"') && value.endsWith('\"')) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n value = value.slice(1, -1);\n }\n\n result[key] = value;\n }\n\n return result;\n}\n\n/**\n * Load project-specific Trafic config from .ddev/config.trafic.yaml\n */\nexport function loadProjectConfig(projectDir: string): ProjectConfig {\n const configPath = join(projectDir, \".ddev\", \"config.trafic.yaml\");\n\n if (!existsSync(configPath)) {\n return {};\n }\n\n try {\n const content = readFileSync(configPath, \"utf-8\");\n const parsed = parseSimpleYaml(content);\n\n const config: ProjectConfig = {};\n\n // Validate auth_policy\n if (parsed.auth_policy) {\n const policy = parsed.auth_policy.toLowerCase();\n if ([\"allow\", \"deny\", \"basic\", \"token\"].includes(policy)) {\n config.auth_policy = policy as ProjectConfig[\"auth_policy\"];\n }\n }\n\n // Validate idle_timeout\n if (parsed.idle_timeout) {\n config.idle_timeout = parsed.idle_timeout;\n }\n\n return config;\n } catch (error) {\n console.warn(`Failed to load project config from ${configPath}:`, error);\n return {};\n }\n}\n\n/**\n * Check if a project should never be stopped (idle_timeout = \"never\")\n */\nexport function shouldNeverStop(config: ProjectConfig): boolean {\n return config.idle_timeout?.toLowerCase() === \"never\";\n}\n\n/**\n * Get idle timeout in milliseconds, or undefined to use global default\n */\nexport function getIdleTimeoutMs(config: ProjectConfig): number | undefined {\n if (!config.idle_timeout) return undefined;\n if (shouldNeverStop(config)) return undefined;\n\n // Parse duration string (e.g., \"30m\", \"4h\", \"2h30m\")\n const regex = /(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?/;\n const match = config.idle_timeout.match(regex);\n if (!match) return undefined;\n\n const hours = parseInt(match[1] ?? \"0\", 10);\n const minutes = parseInt(match[2] ?? \"0\", 10);\n const seconds = parseInt(match[3] ?? \"0\", 10);\n\n const ms = (hours * 3600 + minutes * 60 + seconds) * 1000;\n return ms > 0 ? ms : undefined;\n}\n","import { execSync } from \"node:child_process\";\nimport { writeFileSync as fsWriteFile } from \"node:fs\";\n\nlet stepNumber = 0;\nlet dryRun = false;\n\n/**\n * Set dry-run mode\n */\nexport function setDryRun(value: boolean): void {\n dryRun = value;\n}\n\n/**\n * Reset step counter\n */\nexport function resetSteps(): void {\n stepNumber = 0;\n}\n\n/**\n * Log a step\n */\nexport function step(message: string): void {\n stepNumber++;\n console.log(`\\n\\x1b[36m[${stepNumber}]\\x1b[0m ${message}`);\n}\n\n/**\n * Log success\n */\nexport function success(message: string): void {\n console.log(` \\x1b[32m✓\\x1b[0m ${message}`);\n}\n\n/**\n * Log warning\n */\nexport function warn(message: string): void {\n console.log(` \\x1b[33m⚠\\x1b[0m ${message}`);\n}\n\n/**\n * Log error\n */\nexport function error(message: string): void {\n console.log(` \\x1b[31m✗\\x1b[0m ${message}`);\n}\n\n/**\n * Log info\n */\nexport function info(message: string): void {\n console.log(` ${message}`);\n}\n\n/**\n * Execute a command (or show in dry-run mode)\n */\nexport function exec(command: string, options?: { silent?: boolean }): string {\n if (dryRun) {\n if (!options?.silent) {\n console.log(` \\x1b[90m$ ${command}\\x1b[0m`);\n }\n return \"\";\n }\n\n try {\n return execSync(command, {\n encoding: \"utf-8\",\n stdio: options?.silent ? \"pipe\" : \"inherit\",\n });\n } catch (err) {\n const e = err as { status?: number; stderr?: string };\n throw new Error(`Command failed: ${command}\\n${e.stderr ?? \"\"}`);\n }\n}\n\n/**\n * Execute a command and return output (silent)\n */\nexport function execSilent(command: string): string {\n if (dryRun) {\n return \"\";\n }\n\n try {\n return execSync(command, {\n encoding: \"utf-8\",\n stdio: \"pipe\",\n }).trim();\n } catch {\n return \"\";\n }\n}\n\n/**\n * Check if a command exists\n */\nexport function commandExists(command: string): boolean {\n try {\n execSync(`which ${command}`, { stdio: \"pipe\" });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Check if running as root\n */\nexport function isRoot(): boolean {\n return process.getuid?.() === 0;\n}\n\n/**\n * Write a file (or show in dry-run mode)\n */\nexport function writeFile(path: string, content: string): void {\n if (dryRun) {\n console.log(` \\x1b[90mWrite ${path}:\\x1b[0m`);\n const lines = content.split(\"\\n\").slice(0, 5);\n for (const line of lines) {\n console.log(` \\x1b[90m ${line}\\x1b[0m`);\n }\n if (content.split(\"\\n\").length > 5) {\n console.log(` \\x1b[90m ...\\x1b[0m`);\n }\n return;\n }\n\n fsWriteFile(path, content);\n}\n","import { existsSync, readFileSync } from \"node:fs\";\nimport { commandExists, exec, execSilent, writeFile } from \"./steps.js\";\n\n/**\n * The effectful operations the setup steps need.\n *\n * Injected into every setup function so tests can drive them with plain\n * fakes — no module mocking — and so dry-run has one place to intercept\n * writes instead of each module reaching for `node:fs` itself.\n */\nexport interface SetupIo {\n /** Run a shell command. Throws when it exits non-zero. */\n exec(command: string, options?: { silent?: boolean }): string;\n /**\n * Run a probe. Returns trimmed stdout, or \"\" when the command fails.\n *\n * Use this wherever a non-zero exit is an answer rather than an error —\n * `id -u ddev` on a server without that user, for instance.\n */\n execSilent(command: string): string;\n /** Whether a command is on the PATH. */\n commandExists(command: string): boolean;\n /** Write a file. Honours dry-run. */\n writeFile(path: string, content: string): void;\n /** Whether a path exists. */\n fileExists(path: string): boolean;\n /** Read a UTF-8 file. */\n readFile(path: string): string;\n /** Process environment, for values like SUDO_USER. */\n env: Record<string, string | undefined>;\n}\n\n/**\n * The real implementation, used when no io is injected.\n *\n * `writeFile` comes from steps.js rather than `node:fs` so writes are\n * skipped in dry-run mode. Reads stay direct: they change nothing.\n */\nexport const nodeIo: SetupIo = {\n exec,\n execSilent,\n commandExists,\n writeFile,\n fileExists: existsSync,\n readFile: (path) => readFileSync(path, \"utf-8\"),\n env: process.env,\n};\n","import { nodeIo, type SetupIo } from \"./io.js\";\nimport { step, success, info } from \"./steps.js\";\n\n/**\n * Install system dependencies required by Trafic\n */\nexport function installSystemDeps(io: SetupIo = nodeIo): void {\n step(\"Install system dependencies\");\n\n io.exec(\"apt-get update -qq\", { silent: true });\n // gnupg and ca-certificates are needed to add the DDEV and NodeSource\n // apt repositories — a minimal Ubuntu image ships with neither\n io.exec(\n \"DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get install -y jq curl rsync gnupg ca-certificates\",\n { silent: true },\n );\n\n success(\"System dependencies installed: jq, curl, rsync, gnupg, ca-certificates\");\n}\n\n/**\n * Add the official DDEV apt repository and GPG key.\n * Idempotent: safe to call even if the repository is already configured.\n */\nexport function addDdevAptRepo(io: SetupIo = nodeIo): void {\n io.exec(\"install -m 0755 -d /etc/apt/keyrings\", { silent: true });\n io.exec(\n \"curl -fsSL https://pkg.ddev.com/apt/gpg.key | gpg --dearmor | tee /etc/apt/keyrings/ddev.gpg > /dev/null\",\n { silent: true },\n );\n io.exec(\"chmod a+r /etc/apt/keyrings/ddev.gpg\", { silent: true });\n io.exec(\n \"echo \\\"deb [signed-by=/etc/apt/keyrings/ddev.gpg] https://pkg.ddev.com/apt/ * *\\\" | tee /etc/apt/sources.list.d/ddev.list > /dev/null\",\n { silent: true },\n );\n}\n\n/**\n * Install DDEV\n */\nexport function installDdev(io: SetupIo = nodeIo): void {\n step(\"Install DDEV\");\n\n if (io.commandExists(\"ddev\")) {\n const version = io.exec(\"ddev --version 2>/dev/null | head -1\", { silent: true });\n info(`DDEV already installed: ${version?.trim() ?? \"unknown version\"}`);\n return;\n }\n\n // Install DDEV via the official apt repository\n // See https://docs.ddev.com/en/stable/users/install/ddev-installation/#debianubuntu\n info(\"Adding DDEV apt repository...\");\n addDdevAptRepo(io);\n\n info(\"Installing DDEV...\");\n io.exec(\"apt-get update -qq\", { silent: true });\n io.exec(\"DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get install -y ddev\", { silent: true });\n\n // Initialize mkcert certificate authority for the ddev user.\n // mkcert installs the CA into the home directory of the current user.\n // Since setup runs as root, we must point HOME to the ddev user's home\n // so the CA is trusted by DDEV when it runs as that user.\n io.exec(\"HOME=/home/ddev mkcert -install\", { silent: true });\n io.exec(\"chown -R ddev:ddev /home/ddev/.local/share/mkcert\", { silent: true });\n\n const version = io.exec(\"ddev --version 2>/dev/null | head -1\", { silent: true });\n success(`DDEV installed: ${version?.trim() ?? \"unknown version\"}`);\n}\n\n/**\n * Configure DDEV global settings for production\n *\n * Note on DNS and /etc/hosts:\n * When using a custom TLD (not ddev.site), DDEV may try to edit /etc/hosts\n * if it can't resolve project hostnames via DNS. To avoid this:\n * 1. Configure DNS so *.{tld} resolves to the server's IP (recommended)\n * 2. Or install dnsmasq for local wildcard DNS resolution\n *\n * With proper DNS, DDEV won't need sudo for hostname management.\n */\nexport function configureDdev(\n tld: string,\n email?: string,\n io: SetupIo = nodeIo,\n): void {\n step(\"Configure DDEV\");\n\n // Run as ddev user\n const ddevCmd = (cmd: string) => `su - ddev -c '${cmd}'`;\n\n // Configure all global settings in a single call\n io.exec(\n ddevCmd(\n `ddev config global --project-tld=${tld} --router-http-port=80 --router-https-port=443 --router-bind-all-interfaces=true --use-letsencrypt=${email ? \"true\" : \"false\"} ${email ? `--letsencrypt-email=${email}` : \"\"} --instrumentation-opt-in=false`,\n ),\n { silent: true },\n );\n\n success(`DDEV configured with TLD: ${tld}`);\n info(`Ensure DNS is configured: *.${tld} → server IP`);\n\n if (email) {\n success(`Let's Encrypt enabled with email: ${email}`);\n }\n\n success(\"DDEV global settings configured\");\n}\n\n/**\n * Install dnsmasq for local DNS resolution (optional)\n * This allows the server itself to resolve *.{tld} hostnames\n * without needing to edit /etc/hosts for each project\n */\nexport function installDnsmasq(tld: string, io: SetupIo = nodeIo): void {\n step(\"Install dnsmasq for local DNS\");\n\n io.exec(\"apt-get update && apt-get install -y dnsmasq\", { silent: true });\n\n // Get server's public IP\n const serverIp = io.exec(\n \"curl -4 -s ifconfig.me || hostname -I | awk '{print $1}'\",\n { silent: true },\n )?.trim() || \"127.0.0.1\";\n\n // Configure dnsmasq to resolve *.{tld} to server IP\n const dnsmasqConfig = `# Trafic: Local DNS for DDEV projects\n# Resolve all *.${tld} to this server\naddress=/${tld}/${serverIp}\n\n# Don't read /etc/resolv.conf\nno-resolv\n\n# Use upstream DNS for everything else\nserver=1.1.1.1\nserver=8.8.8.8\n\n# Listen on localhost only\nlisten-address=127.0.0.1\nbind-interfaces\n`;\n\n io.writeFile(\"/etc/dnsmasq.d/trafic.conf\", dnsmasqConfig);\n\n // Configure system to use local dnsmasq\n io.exec(\"systemctl restart dnsmasq\");\n io.exec(\"systemctl enable dnsmasq\");\n\n // Update resolv.conf to use local DNS first\n info(\"Configure /etc/resolv.conf to use 127.0.0.1 as primary DNS\");\n\n success(`dnsmasq configured: *.${tld} → ${serverIp}`);\n}\n\n/**\n * Get the Docker gateway IP reachable from inside DDEV containers on Linux.\n * DDEV runs containers on the `ddev_default` network — we inspect that first.\n * Falls back to the default `bridge` network, then to 172.17.0.1.\n * `host.docker.internal` is not available on Linux without extra configuration.\n */\nexport function getDockerGatewayIp(io: SetupIo = nodeIo): string {\n // Prefer the ddev_default network gateway — that's the network ddev-router is on\n const ddevIp = io.execSilent(\n \"docker network inspect ddev_default --format '{{range .IPAM.Config}}{{.Gateway}}{{end}}'\",\n );\n if (ddevIp) return ddevIp;\n\n // Fall back to the default bridge network\n const bridgeIp = io.execSilent(\n \"docker network inspect bridge --format '{{range .IPAM.Config}}{{.Gateway}}{{end}}'\",\n );\n return bridgeIp || \"172.17.0.1\";\n}\n\n/** DDEV tool ports, used when the global config does not say otherwise */\nconst DEFAULT_TOOL_PORTS = {\n \"mailpit-http-port\": \"8025\",\n \"mailpit-https-port\": \"8026\",\n \"xhgui-http-port\": \"8143\",\n \"xhgui-https-port\": \"8142\",\n} as const;\n\n/**\n * Read the ports DDEV publishes its tools on.\n *\n * ddev-router publishes these on 0.0.0.0, and Docker bypasses UFW for\n * published ports, so a firewall rule cannot protect them — the forward auth\n * middleware is the only thing that can. Read them rather than hardcode: they\n * are configurable, and an entry point Traefik does not know about is ignored.\n */\nexport function readToolPorts(io: SetupIo = nodeIo): string[] {\n const output = io.execSilent(\"su - ddev -c 'ddev config global'\");\n const ports: string[] = [];\n\n for (const [key, fallback] of Object.entries(DEFAULT_TOOL_PORTS)) {\n const match = new RegExp(`^${key}=(\\\\d+)$`, \"m\").exec(output);\n ports.push(match?.[1] ?? fallback);\n }\n\n return [...new Set(ports)];\n}\n\n/** The ports ddev-router serves projects on. */\nexport interface RouterPorts {\n http: string;\n https: string;\n}\n\n/** Used when the global config does not say otherwise */\nconst DEFAULT_ROUTER_PORTS: RouterPorts = { http: \"80\", https: \"443\" };\n\n/**\n * Read the ports ddev-router serves projects on.\n *\n * Traefik names an entry point after its port, so these decide what the\n * catch-all routers and the auth middleware must attach to. Hardcoding 80 and\n * 443 is wrong on any server where the router was moved — which is every\n * server running a host ingress in front of it.\n */\nexport function readRouterPorts(io: SetupIo = nodeIo): RouterPorts {\n const output = io.execSilent(\"su - ddev -c 'ddev config global'\");\n\n const read = (key: string, fallback: string): string =>\n new RegExp(`^${key}=(\\\\d+)$`, \"m\").exec(output)?.[1] ?? fallback;\n\n return {\n http: read(\"router-http-port\", DEFAULT_ROUTER_PORTS.http),\n https: read(\"router-https-port\", DEFAULT_ROUTER_PORTS.https),\n };\n}\n\n/**\n * Build the static config attaching forward auth to every entry point.\n *\n * The error page middleware stays on the web entry points only: a 502 from a\n * stopped project should show the waiting page, while a tool port has nothing\n * to wait for.\n */\nexport function buildStaticConfig(\n toolPorts: string[],\n routerPorts: RouterPorts = DEFAULT_ROUTER_PORTS,\n): string {\n const webEntryPoint = (name: string) => ` ${name}:\n http:\n middlewares:\n - trafic-auth@file\n - trafic-errors@file\n`;\n\n const toolEntryPoint = (port: string) => ` http-${port}:\n http:\n middlewares:\n - trafic-auth@file\n`;\n\n // A tool port that happens to equal a router port must not be emitted\n // twice: a duplicate key makes the whole static config invalid\n const web = [routerPorts.http, routerPorts.https];\n const tools = toolPorts.filter((port) => !web.includes(port));\n\n return `entryPoints:\n${web.map((port) => webEntryPoint(`http-${port}`)).join(\"\")}${tools.map(toolEntryPoint).join(\"\")}`;\n}\n\n/**\n * Build the dynamic config: the middlewares, the agent service, and the\n * catch-all routers that hand a stopped project to the waiting page.\n *\n * One catch-all per web entry point, each naming the entry point it serves.\n * A router that names none is instantiated by Traefik on *every* entry point,\n * and DDEV's router health check compares the number of router definitions in\n * its config files against the number Traefik reports. Two unpinned\n * definitions became fourteen instances on a server with six tool entry\n * points, so the counts never matched, the health check waited out its\n * timeout, and every `ddev start` failed after 60 seconds.\n */\nexport function buildDynamicConfig(\n gatewayIp: string,\n routerPorts: RouterPorts = DEFAULT_ROUTER_PORTS,\n): string {\n return `# Trafic: Forward auth middleware definition\nhttp:\n middlewares:\n trafic-auth:\n forwardAuth:\n address: \"http://${gatewayIp}:9876/__auth__\"\n authResponseHeaders:\n - \"X-Trafic-Project\"\n\n trafic-errors:\n errors:\n status:\n - \"502\"\n - \"503\"\n service: trafic-service\n query: \"/\"\n\n routers:\n # Lowest priority, so a DDEV project router always wins. These only match\n # when none does — which is what a stopped project produces, because DDEV\n # removes that project's router and Traefik would otherwise answer 404.\n # Without them the waiting page never appears and scale-to-zero never\n # restarts anything. Auth is unaffected: it is attached at the entry\n # point, not here, so this cannot reintroduce the bypass that #27 fixed.\n #\n # Each names exactly one entry point. Leaving entryPoints out attaches a\n # router to all of them, which breaks DDEV's router health check — it\n # counts definitions and compares them to what Traefik loaded.\n trafic-catchall:\n rule: \"PathPrefix(\\`/\\`)\"\n entryPoints:\n - http-${routerPorts.http}\n priority: 1\n service: trafic-service\n\n # Carries tls, so it only matches the https entry point. The plain one\n # above cannot serve it, and one alone would leave HTTP answering 404.\n trafic-catchall-tls:\n rule: \"PathPrefix(\\`/\\`)\"\n entryPoints:\n - http-${routerPorts.https}\n priority: 1\n service: trafic-service\n tls: {}\n\n services:\n trafic-service:\n loadBalancer:\n servers:\n - url: \"http://${gatewayIp}:9876\"\n`;\n}\n\n/**\n * Configure Traefik for forward auth\n */\nexport function configureTraefik(io: SetupIo = nodeIo): void {\n step(\"Configure Traefik for forward auth\");\n\n // Create custom Traefik config directories\n io.exec(\"mkdir -p /home/ddev/.ddev/traefik/custom-global-config\", { silent: true });\n io.exec(\"chown -R ddev:ddev /home/ddev/.ddev\", { silent: true });\n\n // Use the Docker bridge gateway IP instead of host.docker.internal —\n // the latter is not available on Linux without extra Docker configuration.\n const gatewayIp = getDockerGatewayIp(io);\n\n // Entry point names come from the ports, so both configs need them\n const routerPorts = readRouterPorts(io);\n\n // Dynamic configuration: the middlewares, the agent service and the\n // catch-all routers. Written to custom-global-config/, which DDEV copies\n // into the ddev-global-cache volume on project start. It used to be written\n // to the traefik root as well, for DDEV versions that watched it — nothing\n // reads that copy on 1.25, and having two made debugging harder.\n const dynamicConfig = buildDynamicConfig(gatewayIp, routerPorts);\n\n io.writeFile(\"/home/ddev/.ddev/traefik/custom-global-config/trafic.yaml\", dynamicConfig);\n io.exec(\"chown ddev:ddev /home/ddev/.ddev/traefik/custom-global-config/trafic.yaml\", { silent: true });\n\n // Static configuration: attaches trafic-auth to every entry point DDEV\n // publishes, and trafic-errors to the web ones, so every request goes\n // through auth regardless of which project router handles it.\n // DDEV merges all static_config.*.yaml files into .static_config.yaml on start.\n const staticConfig = buildStaticConfig(readToolPorts(io), routerPorts);\n\n io.writeFile(\"/home/ddev/.ddev/traefik/static_config.trafic.yaml\", staticConfig);\n io.exec(\"chown ddev:ddev /home/ddev/.ddev/traefik/static_config.trafic.yaml\", { silent: true });\n\n info(`Entry points: http-${routerPorts.http}, http-${routerPorts.https} (web) plus tool ports`);\n\n success(\"Traefik configured with Trafic middleware\");\n}\n","import { dirname, join } from \"node:path\";\nimport { getDockerGatewayIp } from \"../setup/ddev.js\";\nimport { nodeIo, type SetupIo } from \"../setup/io.js\";\n\n/**\n * Files DDEV reads the dynamic Traefik configuration from, relative to the\n * .ddev directory.\n *\n * Only custom-global-config: DDEV copies that into the ddev-global-cache\n * volume, which is where Traefik actually reads from. Setup used to write a\n * second copy at the traefik root for older DDEV versions; migration 0010\n * removes it, and nothing reads it on 1.25.\n */\nconst DYNAMIC_CONFIGS = [\"traefik/custom-global-config/trafic.yaml\"];\n\n/** Matches the host in an agent URL, e.g. http://172.17.0.1:9876/__auth__ */\nconst AGENT_URL = /http:\\/\\/(\\d+\\.\\d+\\.\\d+\\.\\d+):(\\d+)/g;\n\n/**\n * The address the forward-auth middleware currently points at.\n */\nexport function readForwardAuthAddress(content: string): string | undefined {\n const match = /http:\\/\\/(\\d+\\.\\d+\\.\\d+\\.\\d+):\\d+/.exec(content);\n return match?.[1];\n}\n\n/**\n * Point every agent URL in a dynamic config at a different host, keeping\n * each port as it was.\n */\nexport function rewriteForwardAuthAddress(\n content: string,\n gatewayIp: string,\n): string {\n return content.replace(AGENT_URL, `http://${gatewayIp}:$2`);\n}\n\n/**\n * Correct the forward-auth address if the Docker gateway has moved.\n *\n * setup runs `configureTraefik` before any DDEV project exists, so the\n * `ddev_default` network is absent and the address falls back to the default\n * bridge. Once a project starts, that address is stale. Migration 0006 exists\n * to fix it on servers provisioned earlier, but `markAllMigrationsApplied()`\n * marks it applied on fresh ones, so nothing ever recomputed it.\n *\n * Traefik watches the dynamic config, so rewriting the file is enough — no\n * restart. Any failure is logged and ignored: a stale address is survivable,\n * an agent that will not start is not.\n */\nexport function syncForwardAuthAddress(\n projectListPath: string,\n io: SetupIo = nodeIo,\n): void {\n try {\n const ddevDir = dirname(projectListPath);\n const gatewayIp = getDockerGatewayIp(io);\n const changed: string[] = [];\n\n for (const relative of DYNAMIC_CONFIGS) {\n const path = join(ddevDir, relative);\n\n if (!io.fileExists(path)) {\n continue;\n }\n\n const content = io.readFile(path);\n const current = readForwardAuthAddress(content);\n\n if (!current || current === gatewayIp) {\n continue;\n }\n\n io.writeFile(path, rewriteForwardAuthAddress(content, gatewayIp));\n changed.push(path);\n }\n\n if (changed.length > 0) {\n console.log(\n `Traefik forward auth: corrected address to ${gatewayIp} in ${changed.length} file(s)`,\n );\n }\n } catch (error) {\n console.warn(\n `Could not check the Traefik forward auth address: ${error instanceof Error ? error.message : error}`,\n );\n }\n}\n","import { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { readFileSync } from \"node:fs\";\nimport { resolve, dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { AgentConfig, AuthConfig } from \"./types.js\";\nimport { checkAuth, resolveClientIp } from \"./utils/auth.js\";\nimport {\n loadProjectList,\n buildHostnameIndex,\n watchProjectList,\n startProject,\n getProjectInfo,\n} from \"./utils/ddev.js\";\nimport {\n initDb,\n updateProjectAccess,\n logAccess,\n setProjectStatus,\n getProject,\n} from \"./utils/db.js\";\nimport { loadProjectConfig } from \"./utils/project-config.js\";\nimport { syncForwardAuthAddress } from \"./utils/traefik.js\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\n// State\nlet config: AgentConfig;\nlet projectList: Map<string, string>;\nlet hostnameIndex: Map<string, string>;\n// Cache of per-project configs (project name -> config)\nconst projectConfigs = new Map<string, ReturnType<typeof loadProjectConfig>>();\n\n/**\n * Load HTML template\n */\nfunction loadTemplate(name: string): string {\n const templatePath = resolve(__dirname, \"..\", \"templates\", `${name}.html`);\n try {\n return readFileSync(templatePath, \"utf-8\");\n } catch {\n return `<html><body><h1>${name}</h1></body></html>`;\n }\n}\n\n/**\n * Get effective auth config for a project (merges global + per-project)\n */\nfunction getEffectiveAuthConfig(projectName: string | undefined): AuthConfig {\n if (!projectName) return config.auth;\n\n const projectConfig = projectConfigs.get(projectName);\n if (!projectConfig?.auth_policy) return config.auth;\n\n // Override default policy with project-specific policy\n return {\n ...config.auth,\n defaultPolicy: projectConfig.auth_policy,\n };\n}\n\n/**\n * Handle forward auth requests from Traefik\n * Traefik sends the original request headers, we return 200 (allow) or 401 (deny)\n */\nfunction handleAuth(req: IncomingMessage, res: ServerResponse): void {\n const hostname = req.headers[\"x-forwarded-host\"] as string ?? \"\";\n // Keep the two apart: the socket peer cannot be forged, X-Forwarded-For\n // partly can. checkAuth decides which entry to trust.\n const socketIp = req.socket.remoteAddress ?? \"\";\n const forwardedFor = req.headers[\"x-forwarded-for\"] as string | undefined;\n const authorization = req.headers[\"authorization\"];\n const path = req.headers[\"x-forwarded-uri\"] as string ?? \"/\";\n\n // Find project from hostname\n const projectName = hostnameIndex.get(hostname);\n\n // Get effective auth config (global + per-project overrides)\n const authConfig = getEffectiveAuthConfig(projectName);\n\n const clientIp = resolveClientIp(\n socketIp,\n forwardedFor,\n authConfig.trustedProxyHops,\n );\n\n const result = checkAuth(\n {\n hostname,\n ip: socketIp,\n authorization,\n forwardedFor,\n },\n authConfig,\n );\n\n if (result.allowed) {\n // Log access and update last access time\n if (projectName) {\n updateProjectAccess(projectName);\n logAccess({\n project: projectName,\n timestamp: Date.now(),\n ip: clientIp,\n userAgent: req.headers[\"user-agent\"] ?? \"\",\n path,\n });\n }\n\n res.writeHead(200);\n res.end();\n } else {\n // Return 401 with WWW-Authenticate header for basic auth\n res.writeHead(401, {\n \"WWW-Authenticate\": 'Basic realm=\"Trafic\"',\n });\n res.end(\"Unauthorized\");\n }\n}\n\n/**\n * Handle errors middleware requests (502 from Traefik)\n * When a project is stopped, Traefik returns 502. We show a waiting page and start the project.\n */\nasync function handleErrors(\n req: IncomingMessage,\n res: ServerResponse,\n): Promise<void> {\n const hostname = req.headers[\"x-forwarded-host\"] as string ?? req.headers.host ?? \"\";\n const projectName = hostnameIndex.get(hostname);\n\n if (!projectName) {\n // Unknown project\n const template = loadTemplate(\"error\");\n res.writeHead(404, { \"Content-Type\": \"text/html\" });\n res.end(template.replace(\"{{message}}\", \"Project not found\"));\n return;\n }\n\n // Check if project is already starting\n const record = getProject(projectName);\n if (record?.status === \"starting\") {\n // Show waiting page\n const template = loadTemplate(\"wait\");\n res.writeHead(503, {\n \"Content-Type\": \"text/html\",\n \"Retry-After\": \"5\",\n });\n res.end(\n template\n .replace(/\\{\\{project\\}\\}/g, projectName)\n .replace(/\\{\\{hostname\\}\\}/g, hostname),\n );\n return;\n }\n\n // Mark as starting\n setProjectStatus(projectName, \"starting\");\n\n // Show waiting page immediately\n const template = loadTemplate(\"wait\");\n res.writeHead(503, {\n \"Content-Type\": \"text/html\",\n \"Retry-After\": \"5\",\n });\n res.end(\n template\n .replace(/\\{\\{project\\}\\}/g, projectName)\n .replace(/\\{\\{hostname\\}\\}/g, hostname),\n );\n\n // Start project in background\n setTimeout(() => {\n const success = startProject(projectName);\n setProjectStatus(projectName, success ? \"running\" : \"stopped\");\n }, 100);\n}\n\n/**\n * Decide whether Caddy may obtain a certificate for a hostname.\n *\n * Caddy's on-demand TLS asks before issuing for a name it has not seen.\n * Without a check, anyone pointing a DNS record at this server would make it\n * request a certificate, and Let's Encrypt quota is per registered domain —\n * a handful of strangers could exhaust it for every preview.\n */\nexport function allowTlsFor(\n domain: string,\n index: Map<string, string>,\n): boolean {\n return index.has(domain.toLowerCase());\n}\n\n/**\n * Handle Caddy's on-demand TLS ask. 2xx allows issuance, anything else denies.\n */\nfunction handleTlsAsk(req: IncomingMessage, res: ServerResponse): void {\n const url = new URL(req.url ?? \"/\", `http://${req.headers.host}`);\n const domain = url.searchParams.get(\"domain\") ?? \"\";\n\n if (allowTlsFor(domain, hostnameIndex)) {\n res.writeHead(200);\n res.end(\"ok\");\n return;\n }\n\n console.log(`TLS ask denied for unknown hostname: ${domain || \"(none)\"}`);\n res.writeHead(404, { \"Content-Type\": \"text/plain\" });\n res.end(\"Unknown project\");\n}\n\n/**\n * Handle status polling requests\n */\nfunction handleStatus(req: IncomingMessage, res: ServerResponse): void {\n const url = new URL(req.url ?? \"/\", `http://${req.headers.host}`);\n const projectName = url.searchParams.get(\"project\");\n\n if (!projectName) {\n res.writeHead(400, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ error: \"Missing project parameter\" }));\n return;\n }\n\n const info = getProjectInfo(projectName);\n const record = getProject(projectName);\n\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(\n JSON.stringify({\n name: projectName,\n status: info?.status ?? record?.status ?? \"unknown\",\n ready: info?.status === \"running\",\n }),\n );\n}\n\n/**\n * The path a request should be routed on, without the query string.\n *\n * `req.url` is a target, not a URL: it carries the query and, for a proxied\n * request, may be absolute. Parsing against a fixed base keeps a malformed or\n * absolute target from deciding the route, and a trailing slash is dropped so\n * `/__auth__/` and `/__auth__` are the same endpoint.\n */\nexport function routePath(target: string | undefined): string {\n let path: string;\n\n try {\n path = new URL(target ?? \"/\", \"http://localhost\").pathname;\n } catch {\n return \"/\";\n }\n\n return path.length > 1 && path.endsWith(\"/\") ? path.slice(0, -1) : path;\n}\n\n/**\n * Request handler\n */\nasync function handleRequest(\n req: IncomingMessage,\n res: ServerResponse,\n): Promise<void> {\n // Route on the path alone. Matching the raw URL meant a query string threw\n // every internal route off: Caddy's forward_auth passes the original query\n // through, so `/__auth__?s=term` missed the auth branch and fell to the\n // waiting page. Any URL carrying a query — a search, pagination, the\n // `wp-login.php?redirect_to=` an admin request lands on — answered 503 and\n // started an already-running project, and `startProject` is synchronous, so\n // it stalled the agent and every request waiting on it.\n const path = routePath(req.url);\n\n try {\n // Route requests\n if (path === \"/__auth__\" || path.startsWith(\"/__auth__/\")) {\n handleAuth(req, res);\n } else if (path === \"/__status__\" || path.startsWith(\"/__status__/\")) {\n handleStatus(req, res);\n } else if (path === \"/__tls__\") {\n handleTlsAsk(req, res);\n } else if (path === \"/__health__\") {\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ status: \"ok\", version: \"__VERSION__\" }));\n } else {\n // Default: errors middleware\n await handleErrors(req, res);\n }\n } catch (error) {\n console.error(\"Request error:\", error);\n res.writeHead(500, { \"Content-Type\": \"text/plain\" });\n res.end(\"Internal Server Error\");\n }\n}\n\n/**\n * Reload project list and their configs\n */\nfunction reloadProjects(): void {\n projectList = loadProjectList(config.projectListPath);\n hostnameIndex = buildHostnameIndex(projectList, config.tld);\n\n // Load per-project configs\n projectConfigs.clear();\n for (const [name, projectDir] of projectList) {\n const projectConfig = loadProjectConfig(projectDir);\n if (projectConfig.auth_policy || projectConfig.idle_timeout) {\n projectConfigs.set(name, projectConfig);\n console.log(` ${name}: auth=${projectConfig.auth_policy ?? \"default\"}, idle=${projectConfig.idle_timeout ?? \"default\"}`);\n }\n }\n\n console.log(`Loaded ${projectList.size} projects (${projectConfigs.size} with custom config)`);\n}\n\n/**\n * Start the agent server\n */\nexport function startServer(agentConfig: AgentConfig): void {\n config = agentConfig;\n\n // Initialize database\n initDb(config.dbPath);\n\n // setup wrote the forward auth address before any DDEV network existed, so\n // correct it now that one may have appeared\n syncForwardAuthAddress(config.projectListPath);\n\n // Load projects\n reloadProjects();\n\n // Watch for changes\n watchProjectList(config.projectListPath, () => {\n console.log(\"Project list changed, reloading...\");\n reloadProjects();\n });\n\n // Create HTTP server\n const server = createServer((req, res) => {\n handleRequest(req, res).catch((error) => {\n console.error(\"Unhandled error:\", error);\n if (!res.headersSent) {\n res.writeHead(500);\n res.end(\"Internal Server Error\");\n }\n });\n });\n\n server.listen(config.port, () => {\n console.log(`Trafic agent listening on port ${config.port}`);\n console.log(`TLD: ${config.tld}`);\n console.log(`Projects: ${projectList.size}`);\n });\n}\n"],"mappings":";;;;;;;;;;AAKA,SAAgB,QAAQ,IAAY,SAA0B;CAE5D,IAAI,OAAO,SAAS,OAAO;CAG3B,IAAI,QAAQ,SAAS,GAAG,GACtB,OAAO,UAAU,IAAI,OAAO;CAI9B,IAAI,QAAQ,SAAS,GAAG,GAItB,OAAO,IAHW,OAChB,MAAM,QAAQ,QAAQ,OAAO,KAAK,CAAC,CAAC,QAAQ,OAAO,IAAI,IAAI,GAEtD,CAAA,CAAM,KAAK,EAAE;CAGtB,OAAO;AACT;;;;AAKA,SAAS,UAAU,IAAY,MAAuB;CACpD,MAAM,CAAC,OAAO,QAAQ,KAAK,MAAM,GAAG;CACpC,MAAM,OAAO,SAAS,MAAM,EAAE;CAE9B,MAAM,QAAQ,WAAW,EAAE;CAC3B,MAAM,WAAW,WAAW,KAAK;CAEjC,IAAI,UAAU,QAAQ,aAAa,MAAM,OAAO;CAEhD,MAAM,UAAU,GAAG,KAAM,KAAK,QAAS;CACvC,QAAQ,QAAQ,cAAc,WAAW;AAC3C;;;;AAKA,SAAS,WAAW,IAA2B;CAC7C,MAAM,QAAQ,GAAG,MAAM,GAAG;CAC1B,IAAI,MAAM,WAAW,GAAG,OAAO;CAE/B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AuB;GACjC;EACF,CAAC;CACH,CAEA,CAAA,CAAO,OAAO,OAAO,YAAY;EAC/B,QAAQ,IAAI,kCAAkC,OAAO,MAAM;EAC3D,QAAQ,IAAI,QAAQ,OAAO,KAAK;EAChC,QAAQ,IAAI,aAAa,YAAY,MAAM;CAC7C,CAAC;AACH"}
|
package/dist/server.d.ts
CHANGED
|
@@ -8,6 +8,15 @@ import type { AgentConfig } from "./types.js";
|
|
|
8
8
|
* a handful of strangers could exhaust it for every preview.
|
|
9
9
|
*/
|
|
10
10
|
export declare function allowTlsFor(domain: string, index: Map<string, string>): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The path a request should be routed on, without the query string.
|
|
13
|
+
*
|
|
14
|
+
* `req.url` is a target, not a URL: it carries the query and, for a proxied
|
|
15
|
+
* request, may be absolute. Parsing against a fixed base keeps a malformed or
|
|
16
|
+
* absolute target from deciding the route, and a trailing slash is dropped so
|
|
17
|
+
* `/__auth__/` and `/__auth__` are the same endpoint.
|
|
18
|
+
*/
|
|
19
|
+
export declare function routePath(target: string | undefined): string;
|
|
11
20
|
/**
|
|
12
21
|
* Start the agent server
|
|
13
22
|
*/
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,YAAY,CAAC;AA6K1D;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzB,OAAO,CAET;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,YAAY,CAAC;AA6K1D;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzB,OAAO,CAET;AA8CD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAU5D;AA4DD;;GAEG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAmC1D"}
|
package/dist/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as startServer, t as allowTlsFor } from "./server-
|
|
2
|
-
export { allowTlsFor, startServer };
|
|
1
|
+
import { n as routePath, r as startServer, t as allowTlsFor } from "./server-DtqKdFMF.js";
|
|
2
|
+
export { allowTlsFor, routePath, startServer };
|
package/dist/setup/ddev.d.ts
CHANGED
|
@@ -46,6 +46,20 @@ export declare function getDockerGatewayIp(io?: SetupIo): string;
|
|
|
46
46
|
* are configurable, and an entry point Traefik does not know about is ignored.
|
|
47
47
|
*/
|
|
48
48
|
export declare function readToolPorts(io?: SetupIo): string[];
|
|
49
|
+
/** The ports ddev-router serves projects on. */
|
|
50
|
+
export interface RouterPorts {
|
|
51
|
+
http: string;
|
|
52
|
+
https: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Read the ports ddev-router serves projects on.
|
|
56
|
+
*
|
|
57
|
+
* Traefik names an entry point after its port, so these decide what the
|
|
58
|
+
* catch-all routers and the auth middleware must attach to. Hardcoding 80 and
|
|
59
|
+
* 443 is wrong on any server where the router was moved — which is every
|
|
60
|
+
* server running a host ingress in front of it.
|
|
61
|
+
*/
|
|
62
|
+
export declare function readRouterPorts(io?: SetupIo): RouterPorts;
|
|
49
63
|
/**
|
|
50
64
|
* Build the static config attaching forward auth to every entry point.
|
|
51
65
|
*
|
|
@@ -53,7 +67,20 @@ export declare function readToolPorts(io?: SetupIo): string[];
|
|
|
53
67
|
* stopped project should show the waiting page, while a tool port has nothing
|
|
54
68
|
* to wait for.
|
|
55
69
|
*/
|
|
56
|
-
export declare function buildStaticConfig(toolPorts: string[]): string;
|
|
70
|
+
export declare function buildStaticConfig(toolPorts: string[], routerPorts?: RouterPorts): string;
|
|
71
|
+
/**
|
|
72
|
+
* Build the dynamic config: the middlewares, the agent service, and the
|
|
73
|
+
* catch-all routers that hand a stopped project to the waiting page.
|
|
74
|
+
*
|
|
75
|
+
* One catch-all per web entry point, each naming the entry point it serves.
|
|
76
|
+
* A router that names none is instantiated by Traefik on *every* entry point,
|
|
77
|
+
* and DDEV's router health check compares the number of router definitions in
|
|
78
|
+
* its config files against the number Traefik reports. Two unpinned
|
|
79
|
+
* definitions became fourteen instances on a server with six tool entry
|
|
80
|
+
* points, so the counts never matched, the health check waited out its
|
|
81
|
+
* timeout, and every `ddev start` failed after 60 seconds.
|
|
82
|
+
*/
|
|
83
|
+
export declare function buildDynamicConfig(gatewayIp: string, routerPorts?: RouterPorts): string;
|
|
57
84
|
/**
|
|
58
85
|
* Configure Traefik for forward auth
|
|
59
86
|
*/
|
package/dist/setup/ddev.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ddev.d.ts","sourceRoot":"","sources":["../../src/setup/ddev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAG/C;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAY5D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAWzD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CA2BtD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,EACd,EAAE,GAAE,OAAgB,GACnB,IAAI,CAsBN;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,GA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wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EAAE,EACnB,WAAW,GAAE,WAAkC,GAC9C,MAAM,CAqBR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,WAAW,GAAE,WAAkC,GAC9C,MAAM,CAoDR;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAoC3D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Migration } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Migration 0010: pin the catch-all routers to their entry points.
|
|
4
|
+
*
|
|
5
|
+
* The routers added by 0009 named no entry point, so Traefik instantiated
|
|
6
|
+
* each on every one. DDEV's router health check counts router *definitions*
|
|
7
|
+
* across its config files and compares that to what Traefik reports, so two
|
|
8
|
+
* definitions showing up as fourteen instances never matched. The check waited
|
|
9
|
+
* out its timeout and `ddev start` failed after 60 seconds — on every server
|
|
10
|
+
* setup produces, because setup configures the tool entry points.
|
|
11
|
+
*
|
|
12
|
+
* Observed on a live server: 37 routers loaded against 22 expected, health
|
|
13
|
+
* still "starting" after 91s. With the routers pinned: 23 loaded, healthy
|
|
14
|
+
* immediately.
|
|
15
|
+
*
|
|
16
|
+
* Traefik reads its config from the ddev-global-cache volume and DDEV only
|
|
17
|
+
* copies `~/.ddev/traefik` into it when a project starts, so this restarts
|
|
18
|
+
* DDEV rather than the router alone.
|
|
19
|
+
*
|
|
20
|
+
* Idempotent: skipped once the config names entry points.
|
|
21
|
+
*/
|
|
22
|
+
export declare const migration0010CatchallEntrypoints: Migration;
|
|
23
|
+
//# sourceMappingURL=0010__catchall_entrypoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"0010__catchall_entrypoints.d.ts","sourceRoot":"","sources":["../../../src/setup/migrations/0010__catchall_entrypoints.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAQ7C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,gCAAgC,EAAE,SA+B9C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/setup/migrations/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/setup/migrations/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAYjF,iDAAiD;AACjD,eAAO,MAAM,qBAAqB,iCAAiC,CAAC;AAEpE,+CAA+C;AAC/C,eAAO,MAAM,cAAc,EAAE,SAAS,EAWrC,CAAC;AAMF;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,cAAc,CAqBnD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAG9D;AAMD;;GAEG;AACH,wBAAgB,cAAc,IAAI,kBAAkB,EAAE,CAMrD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,UAAQ,GAAG,IAAI,CAyBzD;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAU/C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as stopProject, C as shouldNeverStop, I as getProjectInfo, M as setProjectStatus, O as getIdleProjects, R as loadProjectList, S as loadProjectConfig, _ as setDryRun, a as configureDdev, b as warn, c as installDdev, d as error, f as exec, g as resetSteps, h as isRoot, i as addDdevAptRepo, l as installSystemDeps, m as info, o as configureTraefik, p as execSilent$1, s as getDockerGatewayIp, u as nodeIo, v as step, x as getIdleTimeoutMs, y as success } from "./server-DtqKdFMF.js";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { parse } from "smol-toml";
|
|
4
4
|
import { execSync } from "node:child_process";
|
|
@@ -1028,7 +1028,7 @@ http:
|
|
|
1028
1028
|
//#endregion
|
|
1029
1029
|
//#region src/setup/migrations/0009__scale_to_zero_fixes.ts
|
|
1030
1030
|
var UNIT_PATH = "/etc/systemd/system/trafic-agent.service";
|
|
1031
|
-
var DYNAMIC_CONFIG = "/home/ddev/.ddev/traefik/trafic.yaml";
|
|
1031
|
+
var DYNAMIC_CONFIG$1 = "/home/ddev/.ddev/traefik/trafic.yaml";
|
|
1032
1032
|
/**
|
|
1033
1033
|
* Migration 0009: Make scale-to-zero actually work.
|
|
1034
1034
|
*
|
|
@@ -1055,7 +1055,7 @@ var migration0009ScaleToZeroFixes = {
|
|
|
1055
1055
|
description: "Fix scale-to-zero: waiting page router and agent write access",
|
|
1056
1056
|
run() {
|
|
1057
1057
|
const unitNeedsWrite = !existsSync(UNIT_PATH) || !/^ReadWritePaths=.*\/home\/ddev(\s|$)/m.test(readFileSync(UNIT_PATH, "utf-8"));
|
|
1058
|
-
if (!existsSync(DYNAMIC_CONFIG) || !readFileSync(DYNAMIC_CONFIG, "utf-8").includes("trafic-catchall")) {
|
|
1058
|
+
if (!existsSync(DYNAMIC_CONFIG$1) || !readFileSync(DYNAMIC_CONFIG$1, "utf-8").includes("trafic-catchall")) {
|
|
1059
1059
|
configureTraefik();
|
|
1060
1060
|
exec("su - ddev -c 'DDEV_NONINTERACTIVE=true ddev poweroff && ddev start --all'", { silent: true });
|
|
1061
1061
|
}
|
|
@@ -1063,6 +1063,42 @@ var migration0009ScaleToZeroFixes = {
|
|
|
1063
1063
|
}
|
|
1064
1064
|
};
|
|
1065
1065
|
//#endregion
|
|
1066
|
+
//#region src/setup/migrations/0010__catchall_entrypoints.ts
|
|
1067
|
+
var DYNAMIC_CONFIG = "/home/ddev/.ddev/traefik/custom-global-config/trafic.yaml";
|
|
1068
|
+
/** The copy setup used to write for DDEV versions that watched the root. */
|
|
1069
|
+
var STALE_CONFIG = "/home/ddev/.ddev/traefik/trafic.yaml";
|
|
1070
|
+
/**
|
|
1071
|
+
* Migration 0010: pin the catch-all routers to their entry points.
|
|
1072
|
+
*
|
|
1073
|
+
* The routers added by 0009 named no entry point, so Traefik instantiated
|
|
1074
|
+
* each on every one. DDEV's router health check counts router *definitions*
|
|
1075
|
+
* across its config files and compares that to what Traefik reports, so two
|
|
1076
|
+
* definitions showing up as fourteen instances never matched. The check waited
|
|
1077
|
+
* out its timeout and `ddev start` failed after 60 seconds — on every server
|
|
1078
|
+
* setup produces, because setup configures the tool entry points.
|
|
1079
|
+
*
|
|
1080
|
+
* Observed on a live server: 37 routers loaded against 22 expected, health
|
|
1081
|
+
* still "starting" after 91s. With the routers pinned: 23 loaded, healthy
|
|
1082
|
+
* immediately.
|
|
1083
|
+
*
|
|
1084
|
+
* Traefik reads its config from the ddev-global-cache volume and DDEV only
|
|
1085
|
+
* copies `~/.ddev/traefik` into it when a project starts, so this restarts
|
|
1086
|
+
* DDEV rather than the router alone.
|
|
1087
|
+
*
|
|
1088
|
+
* Idempotent: skipped once the config names entry points.
|
|
1089
|
+
*/
|
|
1090
|
+
var migration0010CatchallEntrypoints = {
|
|
1091
|
+
id: "0010__catchall_entrypoints",
|
|
1092
|
+
description: "Pin the Traefik catch-all routers to their entry points",
|
|
1093
|
+
run() {
|
|
1094
|
+
const pinned = existsSync(DYNAMIC_CONFIG) && readFileSync(DYNAMIC_CONFIG, "utf-8").includes("entryPoints:");
|
|
1095
|
+
if (pinned && !existsSync(STALE_CONFIG)) return;
|
|
1096
|
+
if (!pinned) configureTraefik();
|
|
1097
|
+
if (existsSync(STALE_CONFIG)) exec(`rm -f ${STALE_CONFIG}`, { silent: true });
|
|
1098
|
+
if (!pinned) exec("su - ddev -c 'DDEV_NONINTERACTIVE=true ddev poweroff && ddev start --all'", { silent: true });
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
//#endregion
|
|
1066
1102
|
//#region src/setup/migrations/index.ts
|
|
1067
1103
|
/** Path to the persisted migration state file */
|
|
1068
1104
|
var MIGRATIONS_STATE_FILE = "/etc/trafic/.migrations.json";
|
|
@@ -1076,7 +1112,8 @@ var ALL_MIGRATIONS = [
|
|
|
1076
1112
|
migration0006TraefikGatewayIpFix,
|
|
1077
1113
|
migration0007UfwDockerTraficPort,
|
|
1078
1114
|
migration0008TraefikEntrypointMiddleware,
|
|
1079
|
-
migration0009ScaleToZeroFixes
|
|
1115
|
+
migration0009ScaleToZeroFixes,
|
|
1116
|
+
migration0010CatchallEntrypoints
|
|
1080
1117
|
];
|
|
1081
1118
|
/**
|
|
1082
1119
|
* Load the current migration state from disk.
|
|
@@ -1223,4 +1260,4 @@ async function audit() {
|
|
|
1223
1260
|
//#endregion
|
|
1224
1261
|
export { printAuditResults as a, stopIdleProjects as c, validateConfig as d, runPendingMigrations as i, loadConfig as l, setup as n, runAudit as o, listMigrations as r, startIdleScheduler as s, audit as t, parseDuration as u };
|
|
1225
1262
|
|
|
1226
|
-
//# sourceMappingURL=setup-
|
|
1263
|
+
//# sourceMappingURL=setup-Pv2K4pJF.js.map
|