v0.39.1
This commit is contained in:
1 parent
53d92e0da6
commit
08d1608ef5
21 files changed
+928
-408
No files matched your search
+222
-20
@@ -18,11 +18,11 @@ window.rustProxyCacheRules = (() => {
|
||||
response_header: { ops: ["exists", "equals", "contains", "regex"], name: true, stages: ["response", "deliver"] },
|
||||
};
|
||||
const ACTIONS = {
|
||||
request: ["pass", "lookup", "strip_cookies", "strip_query", "hash_header", "hash_cookie", "set_request_header", "remove_request_header"],
|
||||
request: ["pass", "lookup", "strip_cookies", "remove_named_cookies", "strip_query", "hash_header", "hash_cookie", "set_request_header", "remove_request_header"],
|
||||
response: ["ttl", "grace", "no_store", "allow_store", "ignore_cache_control", "strip_set_cookie", "set_backend_header", "remove_backend_header"],
|
||||
deliver: ["set_header", "default_header", "remove_header"],
|
||||
};
|
||||
const ASPECTS = { pass: "request_routing", lookup: "request_routing", strip_cookies: "request_cookies", strip_query: "request_query", ttl: "ttl", grace: "grace", no_store: "store", allow_store: "store" };
|
||||
const ASPECTS = { pass: "request_routing", lookup: "request_routing", strip_cookies: "request_cookies", remove_named_cookies: "request_cookies", strip_query: "request_query", ttl: "ttl", grace: "grace", no_store: "store", allow_store: "store" };
|
||||
const tk = (prefix, value) => t(`${prefix}${String(value).split("_").map(part => part[0].toUpperCase() + part.slice(1)).join("")}`);
|
||||
const fieldLabel = field => tk("cacheRuleField", field);
|
||||
const opLabel = op => tk("cacheRuleOp", op);
|
||||
@@ -84,6 +84,7 @@ window.rustProxyCacheRules = (() => {
|
||||
case "pass": return "return (pass);";
|
||||
case "lookup": return rule.hash_stage ? "return (lookup);" : "return (hash);";
|
||||
case "strip_cookies": return a.keep?.length ? `# keep only cookies: ${a.keep.join(", ")}\nset req.http.Cookie = regsuball(req.http.Cookie, "(^|;\\s*)(?!(${a.keep.map(reEsc).join("|")})=)[^;=]+=[^;]*", "");` : "unset req.http.Cookie;";
|
||||
case "remove_named_cookies": return `remove_req_cookies(${(a.names || []).map(name => `"${esc(name)}"`).join(", ")});`;
|
||||
case "strip_query": return a.keep_only ? `# keep only query parameters: ${(a.params || []).join(", ")}` : (a.params?.length ? `set req.url = regsuball(req.url, "([?&])(${a.params.map(p => globRe(p).replace(/\.\*/g, "[^=&]*")).join("|")})=[^&]*", "\\1");` : `set req.url = regsub(req.url, "\\?.*$", "");`);
|
||||
case "hash_header": return `hash_data(req.http.${a.name});`;
|
||||
case "hash_cookie": return `hash_data(regsub(req.http.Cookie, "^.*(?:^|;\\s*)${reEsc(a.name)}=([^;]*).*$", "\\1"));`;
|
||||
@@ -121,6 +122,8 @@ window.rustProxyCacheRules = (() => {
|
||||
limits.push("One or more graphical conditions have no guaranteed VCL import round-trip.");
|
||||
if (rule.actions.some(a => ["hash_cookie", "strip_query", "strip_cookies", "default_header", "ignore_cache_control"].includes(a.type)))
|
||||
limits.push("One or more graphical actions are only approximated in this VCL display.");
|
||||
if (rule.actions.some(a => a.type === "remove_named_cookies"))
|
||||
limits.push("remove_req_cookies() is a RustProxy extension, not standard Varnish VCL.");
|
||||
const notes = limits.map(limit => `# PREVIEW LIMITATION: ${limit}`).join("\n");
|
||||
const description = notes ? `${head}\n${notes}` : head;
|
||||
return conditions.length ? `${description}\nif (${joined}) {\n${body}\n}` : `${description}\n${body.replace(/^ {4}/gm, "")}`;
|
||||
@@ -148,6 +151,7 @@ window.rustProxyCacheRules = (() => {
|
||||
const actions = rule.actions.map(a => {
|
||||
if (a.type === "ttl" || a.type === "grace") return `${actionLabel(a.type)} ${fmtDuration(a.seconds)}`;
|
||||
if (a.type === "strip_query") return `${actionLabel(a.type)}${a.params?.length ? `: ${a.params.join(", ")}` : ""}`;
|
||||
if (a.type === "remove_named_cookies") return `${actionLabel(a.type)}: ${(a.names || []).join(", ")}`;
|
||||
if (a.type === "set_header" || a.type === "default_header" || a.type === "set_backend_header" || a.type === "set_request_header") return `${actionLabel(a.type)}: ${a.name || "-"}${a.value ? ` = ${a.value}` : ""}`;
|
||||
if (a.type === "remove_header" || a.type === "remove_backend_header" || a.type === "remove_request_header" || a.type === "hash_header" || a.type === "hash_cookie") return `${actionLabel(a.type)}: ${a.name || "-"}`;
|
||||
return actionLabel(a.type);
|
||||
@@ -159,6 +163,21 @@ window.rustProxyCacheRules = (() => {
|
||||
for (const [unit, size] of [...durationUnits].reverse()) if (seconds >= size && seconds % size === 0) return `${seconds / size}${unit}`;
|
||||
return `${seconds}s`;
|
||||
}
|
||||
// These are ordinary graphical rules, not a separate VCL engine. Keep
|
||||
// privacy boundaries fail-closed: rules which can increase cache reuse or
|
||||
// alter downstream caching start disabled until the operator reviews them.
|
||||
const templatePass = (label, conditions, match = "all") => ({
|
||||
name: t(label), stage: "request", match, conditions,
|
||||
actions: [{ type: "pass" }], stop: true,
|
||||
});
|
||||
const templatePath = (value) => ({ field: "path", operator: "regex", values: [value] });
|
||||
const templateResponse = (label, conditions, actions, enabled = false) => ({
|
||||
name: t(label), stage: "response", match: "all", conditions, actions, enabled,
|
||||
});
|
||||
const templateDeliver = (label, conditions, actions, enabled = true) => ({
|
||||
name: t(label), stage: "deliver", match: "all", conditions, actions, enabled,
|
||||
});
|
||||
const protectedPaths = "^/(?:admin|auth|login|logout|user|users|account|profile|settings|dashboard|cart|checkout|orders|billing|payment)(?:/|[?]|$)";
|
||||
const TEMPLATES = {
|
||||
wordpress: () => [{ name: t("cacheRuleTplWordpress"), stage: "request", match: "any", conditions: [{ field: "path", operator: "regex", values: ["^/(wp-admin|wp-login\\.php|xmlrpc\\.php|wp-json)"] }, { field: "header", name: "cookie", operator: "regex", values: ["wordpress_logged_in_|comment_author_|woocommerce_items_in_cart|wp-postpass_"] }], actions: [{ type: "pass" }] }],
|
||||
static: () => [
|
||||
@@ -177,9 +196,9 @@ window.rustProxyCacheRules = (() => {
|
||||
{ name: t("cacheRuleTplCdnRemaining"), stage: "request", match: "all", conditions: [{ field: "header", name: "Cookie", operator: "exists" }], actions: [{ type: "pass" }], stop: true },
|
||||
];
|
||||
},
|
||||
// Opt-in for a verified public vhost. Do not try to infer the Cookie
|
||||
// Domain: it is absent from the HTTP Cookie request header. Disabled by
|
||||
// default; the operator must review the private-path exclusions first.
|
||||
// Separate from the CDN template: remove only explicitly named cookies
|
||||
// confirmed to be irrelevant to this Vhost. HTTP Cookie has no Domain
|
||||
// attribute, so no origin inference or wildcard session-cookie removal.
|
||||
publiccookies: () => [{
|
||||
name: t("cacheRuleTplPubliccookies"), enabled: false, stage: "request", match: "all",
|
||||
conditions: [
|
||||
@@ -188,7 +207,7 @@ window.rustProxyCacheRules = (() => {
|
||||
{ field: "header", name: "Authorization", operator: "exists", negate: true },
|
||||
{ field: "path", operator: "regex", values: ["^/(admin|api|auth|login|logout|account|profile|user|settings|dashboard|cart|checkout|panel|konto|wp-admin|wp-login[.]php)(/|[?]|$)"], negate: true },
|
||||
],
|
||||
actions: [{ type: "strip_cookies", keep: [] }, { type: "lookup" }], stop: true,
|
||||
actions: [{ type: "remove_named_cookies", names: ["REPLACE_WITH_VERIFIED_PARENT_COOKIE_NAME"] }], stop: false,
|
||||
}],
|
||||
tracking: () => [{ name: t("cacheRuleTplTracking"), stage: "request", match: "all", conditions: [], actions: [{ type: "strip_query", params: ["utm_*", "fbclid", "gclid", "msclkid", "mc_cid", "mc_eid", "_ga"] }] }],
|
||||
api: () => [{ name: t("cacheRuleTplApi"), stage: "request", match: "all", conditions: [{ field: "path", operator: "prefix", values: ["/api/"] }], actions: [{ type: "pass" }] }],
|
||||
@@ -199,7 +218,110 @@ window.rustProxyCacheRules = (() => {
|
||||
browser: () => [{ name: t("cacheRuleTplBrowser"), stage: "deliver", match: "all", conditions: [{ field: "extension", operator: "equals", values: ["css", "js", "mjs", "png", "jpg", "jpeg", "gif", "webp", "avif", "svg", "ico", "woff", "woff2"] }, { field: "status", operator: "equals", values: ["200"] }], actions: [{ type: "set_header", name: "Cache-Control", value: "public, max-age=2592000" }] }],
|
||||
nobrowser: () => [{ name: t("cacheRuleTplNoBrowser"), stage: "deliver", match: "any", conditions: [{ field: "content_type", operator: "prefix", values: ["text/html"] }, { field: "path", operator: "prefix", values: ["/admin", "/account"] }], actions: [{ type: "set_header", name: "Cache-Control", value: "no-store" }] }],
|
||||
security: () => [{ name: t("cacheRuleTplSecurity"), stage: "deliver", match: "all", conditions: [], actions: [{ type: "default_header", name: "X-Content-Type-Options", value: "nosniff" }, { type: "default_header", name: "Referrer-Policy", value: "strict-origin-when-cross-origin" }] }],
|
||||
// Safety and authenticated traffic. No rule below removes unknown cookies.
|
||||
safemethods: () => [templatePass("cacheRuleTplSafemethods", [{ field: "method", operator: "equals", values: ["GET", "HEAD"], negate: true }])],
|
||||
authbypass: () => [templatePass("cacheRuleTplAuthbypass", [{ field: "header", name: "Authorization", operator: "exists" }])],
|
||||
cookiepass: () => [templatePass("cacheRuleTplCookiepass", [{ field: "header", name: "Cookie", operator: "exists" }])],
|
||||
sessioncookies: () => [templatePass("cacheRuleTplSessioncookies", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:session|sessionid|PHPSESSID|laravel_session|connect[.]sid|sid)="] }])],
|
||||
privateroutes: () => [
|
||||
templatePass("cacheRuleTplPrivateroutesPass", [templatePath(protectedPaths)]),
|
||||
templateResponse("cacheRuleTplPrivateroutesStore", [templatePath(protectedPaths)], [{ type: "no_store" }], true),
|
||||
templateDeliver("cacheRuleTplPrivateroutesBrowser", [templatePath(protectedPaths)], [{ type: "set_header", name: "Cache-Control", value: "private, no-store" }]),
|
||||
],
|
||||
preview: () => [templatePass("cacheRuleTplPreview", [
|
||||
templatePath("^/(?:preview|draft)(?:/|[?]|$)"),
|
||||
{ field: "query", name: "preview", operator: "exists" },
|
||||
{ field: "query", name: "draft", operator: "exists" },
|
||||
], "any")],
|
||||
checkout: () => [templatePass("cacheRuleTplCheckout", [templatePath("^/(?:cart|checkout|payment|billing|orders?)(?:/|[?]|$)")])],
|
||||
webhooks: () => [templatePass("cacheRuleTplWebhooks", [templatePath("^/(?:webhooks?|callbacks?|hooks)(?:/|[?]|$)")])],
|
||||
healthchecks: () => [templatePass("cacheRuleTplHealthchecks", [templatePath("^/(?:health|healthz|readyz|livez|metrics|status)(?:/|[?]|$)")])],
|
||||
graphql: () => [templatePass("cacheRuleTplGraphql", [templatePath("^/graphql(?:/|[?]|$)")])],
|
||||
streaming: () => [templatePass("cacheRuleTplStreaming", [
|
||||
{ field: "header", name: "Accept", operator: "contains", values: ["text/event-stream"] },
|
||||
{ field: "header", name: "Upgrade", operator: "exists" },
|
||||
], "any")],
|
||||
signedurls: () => [templatePass("cacheRuleTplSignedurls", [
|
||||
...["token", "access_token", "signature", "sig", "auth_token"].map(name => ({ field: "query", name, operator: "exists" })),
|
||||
], "any")],
|
||||
// Framework-specific guards are independent from the CDN allowlist.
|
||||
woocommerce: () => [templatePass("cacheRuleTplWoocommerce", [
|
||||
templatePath("^/(?:cart|checkout|my-account)(?:/|[?]|$)"),
|
||||
{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:wordpress_logged_in_[^=;]*|woocommerce_items_in_cart|wp_woocommerce_session_[^=;]*|woocommerce_cart_hash)="] },
|
||||
], "any")],
|
||||
django: () => [templatePass("cacheRuleTplDjango", [{ field: "cookie", name: "sessionid", operator: "exists" }])],
|
||||
laravel: () => [templatePass("cacheRuleTplLaravel", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:laravel_session|PHPSESSID)="] }])],
|
||||
authjs: () => [templatePass("cacheRuleTplAuthjs", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:__Secure-)?(?:next-auth[.]session-token|authjs[.]session-token)="] }])],
|
||||
aspnet: () => [templatePass("cacheRuleTplAspnet", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:[.]AspNetCore[.]Cookies|ASP[.]NET_SessionId)="] }])],
|
||||
drupal: () => [templatePass("cacheRuleTplDrupal", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:S?SESS[a-fA-F0-9]+)="] }])],
|
||||
// Cache acceleration must be opt-in: names, routes, representation privacy,
|
||||
// Vary, and origin Cache-Control must be checked before activation.
|
||||
publicjson: () => [templateResponse("cacheRuleTplPublicjson", [
|
||||
{ field: "path", operator: "prefix", values: ["/api/public/"] },
|
||||
{ field: "status", operator: "equals", values: ["200"] },
|
||||
{ field: "content_type", operator: "prefix", values: ["application/json"] },
|
||||
], [{ type: "ttl", seconds: 60 }, { type: "grace", seconds: 30 }])],
|
||||
publicpages: () => [templateResponse("cacheRuleTplPublicpages", [
|
||||
templatePath("^/(?:blog|news|articles|catalog|products)(?:/|[?]|$)"),
|
||||
{ field: "status", operator: "equals", values: ["200"] },
|
||||
{ field: "content_type", operator: "prefix", values: ["text/html"] },
|
||||
], [{ type: "ttl", seconds: 300 }, { type: "grace", seconds: 60 }])],
|
||||
feeds: () => [templateResponse("cacheRuleTplFeeds", [
|
||||
templatePath("^/(?:feed|rss|rss[.]xml|atom[.]xml)(?:/|[?]|$)"),
|
||||
{ field: "status", operator: "equals", values: ["200"] },
|
||||
], [{ type: "ttl", seconds: 600 }])],
|
||||
sitemap: () => [templateResponse("cacheRuleTplSitemap", [
|
||||
templatePath("^/(?:sitemap(?:_index)?[.]xml|sitemap/)") ,
|
||||
{ field: "status", operator: "equals", values: ["200"] },
|
||||
], [{ type: "ttl", seconds: 3600 }])],
|
||||
hashedassets: () => [templateResponse("cacheRuleTplHashedassets", [
|
||||
templatePath("^/(?:assets|static|build)/[^?]*[.-][a-zA-Z0-9_-]{8,}[.](?:js|mjs|css|png|webp|avif|svg|woff2?)(?:[?]|$)"),
|
||||
{ field: "status", operator: "equals", values: ["200"] },
|
||||
], [{ type: "ttl", seconds: 31536000 }])],
|
||||
imagecache: () => [templateResponse("cacheRuleTplImagecache", [
|
||||
{ field: "extension", operator: "equals", values: ["png", "jpg", "jpeg", "webp", "avif", "gif", "svg"] },
|
||||
{ field: "status", operator: "equals", values: ["200"] },
|
||||
], [{ type: "ttl", seconds: 86400 }])],
|
||||
fontcache: () => [templateResponse("cacheRuleTplFontcache", [
|
||||
{ field: "extension", operator: "equals", values: ["woff", "woff2", "ttf", "otf"] },
|
||||
{ field: "status", operator: "equals", values: ["200"] },
|
||||
], [{ type: "ttl", seconds: 2592000 }])],
|
||||
searchttl: () => [templateResponse("cacheRuleTplSearchttl", [
|
||||
{ field: "path", operator: "prefix", values: ["/search"] },
|
||||
{ field: "status", operator: "equals", values: ["200"] },
|
||||
], [{ type: "ttl", seconds: 15 }])],
|
||||
// Cache blocking AND browser no-store are separate stages: a deliver rule
|
||||
// alone cannot prevent a shared-cache HIT. Purge old objects on activation.
|
||||
nocachehtml: () => [
|
||||
templateResponse("cacheRuleTplNocachehtmlResponse", [{ field: "content_type", operator: "prefix", values: ["text/html"] }], [{ type: "no_store" }], true),
|
||||
templateDeliver("cacheRuleTplNocachehtmlDeliver", [{ field: "content_type", operator: "prefix", values: ["text/html"] }], [{ type: "set_header", name: "Cache-Control", value: "no-store" }]),
|
||||
],
|
||||
privateapi: () => [
|
||||
templatePass("cacheRuleTplPrivateapiPass", [{ field: "path", operator: "prefix", values: ["/api/private/"] }]),
|
||||
templateResponse("cacheRuleTplPrivateapiStore", [{ field: "path", operator: "prefix", values: ["/api/private/"] }], [{ type: "no_store" }], true),
|
||||
templateDeliver("cacheRuleTplPrivateapiBrowser", [{ field: "path", operator: "prefix", values: ["/api/private/"] }], [{ type: "set_header", name: "Cache-Control", value: "private, no-store" }]),
|
||||
],
|
||||
privatedownloads: () => [
|
||||
{ ...templatePass("cacheRuleTplPrivatedownloadsPass", [{ field: "path", operator: "prefix", values: ["/private-downloads/"] }]), enabled: false },
|
||||
templateDeliver("cacheRuleTplPrivatedownloadsBrowser", [{ field: "path", operator: "prefix", values: ["/private-downloads/"] }], [{ type: "set_header", name: "Cache-Control", value: "private, no-store" }], false),
|
||||
],
|
||||
stagingnoindex: () => [templateDeliver("cacheRuleTplStagingnoindex", [], [{ type: "default_header", name: "X-Robots-Tag", value: "noindex, nofollow" }], false)],
|
||||
frameguard: () => [templateDeliver("cacheRuleTplFrameguard", [], [{ type: "default_header", name: "X-Frame-Options", value: "SAMEORIGIN" }], false)],
|
||||
};
|
||||
// Display order is deliberate. Parent-domain cookie cleanup stays a
|
||||
// distinct template and can be inserted before CDN strip/pass guards.
|
||||
const TEMPLATE_GROUPS = [
|
||||
{ id: "privacy", keys: ["safemethods", "authbypass", "cookiepass", "sessioncookies", "privateroutes", "preview", "checkout", "webhooks", "healthchecks", "graphql", "streaming", "signedurls", "nocachehtml", "privateapi", "privatedownloads"] },
|
||||
{ id: "frameworks", keys: ["wordpress", "woocommerce", "django", "laravel", "authjs", "aspnet", "drupal"] },
|
||||
{ id: "cookies", keys: ["cdn", "publiccookies"] },
|
||||
{ id: "public", keys: ["publicjson", "publicpages", "feeds", "sitemap", "hashedassets", "imagecache", "fontcache", "searchttl", "static", "tracking"] },
|
||||
{ id: "variants", keys: ["language"] },
|
||||
{ id: "delivery", keys: ["headers", "browser", "nobrowser", "security", "stagingnoindex", "frameguard"] },
|
||||
{ id: "other", keys: ["api"] },
|
||||
];
|
||||
const templateName = key => t(key === "nobrowser" ? "cacheRuleTplNoBrowser" : `cacheRuleTpl${key[0].toUpperCase()}${key.slice(1)}`);
|
||||
const templateHelp = key => t(`cacheRuleTplHelp${key[0].toUpperCase()}${key.slice(1)}`);
|
||||
const templateAvailable = (key, scope) => scope === "vhost" || key !== "publiccookies";
|
||||
function applicableGlobals(vhostId) {
|
||||
return (envelope?.config?.cache?.rules || []).filter(rule => rule.enabled !== false && (!rule.vhosts?.length || rule.vhosts.includes(vhostId)));
|
||||
}
|
||||
@@ -287,15 +409,42 @@ window.rustProxyCacheRules = (() => {
|
||||
helpLinks.append(guide, docs);
|
||||
root.append(helpLinks);
|
||||
}
|
||||
const templates = select([["", t("cacheRulesTemplates")], ...Object.keys(TEMPLATES).filter(key => scope === "vhost" || key !== "publiccookies").map(key => [key, t(`cacheRuleTpl${key[0].toUpperCase()}${key.slice(1)}`)])], "", t("cacheRulesTemplates"));
|
||||
const templates = el("select");
|
||||
const placeholder = el("option", t("cacheRulesTemplates")); placeholder.value = "";
|
||||
templates.append(placeholder);
|
||||
for (const group of TEMPLATE_GROUPS) {
|
||||
const visible = group.keys.filter(key => templateAvailable(key, scope));
|
||||
if (!visible.length) continue;
|
||||
const optgroup = document.createElement("optgroup");
|
||||
optgroup.label = t(`cacheRuleTplGroup${group.id[0].toUpperCase()}${group.id.slice(1)}`);
|
||||
for (const key of visible) {
|
||||
const option = el("option", templateName(key));
|
||||
option.value = key;
|
||||
option.title = templateHelp(key);
|
||||
optgroup.append(option);
|
||||
}
|
||||
templates.append(optgroup);
|
||||
}
|
||||
templates.setAttribute("aria-label", t("cacheRulesTemplates"));
|
||||
templates.classList.add("cache-rules-templates");
|
||||
const browseButton = el("button", t("cacheRuleCatalogBrowse"), "outline");
|
||||
browseButton.type = "button"; browseButton.setAttribute("aria-expanded", "false");
|
||||
const importButton = el("button", t("cacheRulesImportVcl"), "outline"); importButton.type = "button";
|
||||
const exportButton = el("button", t("cacheRulesExportVcl"), "outline"); exportButton.type = "button";
|
||||
const addButton = el("button", t("cacheRulesAdd"), "primary"); addButton.type = "button";
|
||||
toolbar.append(templates, importButton, exportButton, addButton);
|
||||
toolbar.append(templates, browseButton, importButton, exportButton, addButton);
|
||||
const ignoreWrap = el("label", undefined, "check cache-rules-ignore"), ignoreBox = el("input", undefined, "switch"); ignoreBox.type = "checkbox"; ignoreBox.checked = ignoreGlobal; if (options.ignoreId !== "") ignoreBox.id = options.ignoreId || "vh-cache-ignore-global-rules";
|
||||
ignoreWrap.append(ignoreBox, el("span", t("cacheRulesIgnoreGlobal")));
|
||||
const notices = el("div", undefined, "cache-rules-notices");
|
||||
const catalog = el("section", undefined, "cache-rule-catalog"); catalog.hidden = true;
|
||||
const catalogHeading = el("h4", t("cacheRuleCatalogTitle"));
|
||||
const catalogNote = el("p", t("cacheRuleCatalogHelp"), "fine");
|
||||
const catalogSearch = el("input", undefined, "cache-rule-catalog-search");
|
||||
catalogSearch.type = "search";
|
||||
catalogSearch.placeholder = t("cacheRuleCatalogSearch");
|
||||
catalogSearch.setAttribute("aria-label", t("cacheRuleCatalogSearch"));
|
||||
const catalogGroups = el("div", undefined, "cache-rule-catalog-groups");
|
||||
catalog.append(catalogHeading, catalogNote, catalogSearch, catalogGroups);
|
||||
const list = el("div", undefined, "cache-rules-list");
|
||||
const empty = el("p", t(scope === "vhost" ? "cacheRulesEmptyVhost" : "cacheRulesEmpty"), "fine cache-rules-empty");
|
||||
const importBox = el("div", undefined, "cache-rules-import"); importBox.hidden = true;
|
||||
@@ -322,8 +471,8 @@ window.rustProxyCacheRules = (() => {
|
||||
const tester = buildTester();
|
||||
root.append(toolbar);
|
||||
if (scope === "vhost") root.append(ignoreWrap);
|
||||
root.append(notices, importBox, list, empty, exportBox, tester.node);
|
||||
for (const isolated of [tester.node, importBox]) for (const type of ["input", "change"]) isolated.addEventListener(type, event => event.stopPropagation());
|
||||
root.append(notices, catalog, importBox, list, empty, exportBox, tester.node);
|
||||
for (const isolated of [tester.node, importBox, catalog]) for (const type of ["input", "change"]) isolated.addEventListener(type, event => event.stopPropagation());
|
||||
root.addEventListener("keydown", event => { if (event.key === "Enter" && event.target.matches?.("input:not([type=checkbox])")) event.preventDefault(); });
|
||||
function taken() { return new Set(rules.map(rule => rule.id)); }
|
||||
if (scope === "global") {
|
||||
@@ -462,6 +611,7 @@ window.rustProxyCacheRules = (() => {
|
||||
const nameInput = placeholder => { const node = textInput(action.name, placeholder); node.addEventListener("input", () => { action.name = node.value.trim(); changed(); }); return node; };
|
||||
switch (action.type) {
|
||||
case "strip_cookies": params.append(listInput("keep", t("cacheRuleKeepCookies"))); break;
|
||||
case "remove_named_cookies": params.append(listInput("names", t("cacheRuleRemoveNamedCookies"))); break;
|
||||
case "strip_query": {
|
||||
const keepOnly = el("label", undefined, "check"), box = el("input", undefined, "switch"); box.type = "checkbox"; box.checked = !!action.keep_only; keepOnly.append(box, el("span", t("cacheRuleKeepOnly")));
|
||||
box.addEventListener("change", () => { action.keep_only = box.checked; changed(); });
|
||||
@@ -554,17 +704,69 @@ window.rustProxyCacheRules = (() => {
|
||||
node.append(bodyWrap);
|
||||
return { node };
|
||||
}
|
||||
function addRules(items) {
|
||||
const ids = taken(); let added = 0;
|
||||
for (const item of items) {
|
||||
if (rules.length >= MAX_RULES) { toast(t("cacheRulesLimit"), true); break; }
|
||||
function addRules(items, templateKey = "") {
|
||||
if (rules.length + items.length > MAX_RULES) { toast(t("cacheRulesLimit"), true); return 0; }
|
||||
const ids = taken();
|
||||
const addedRules = items.map(item => {
|
||||
const rule = normalize({ ...item, id: slug(item.id || item.name, ids), vhosts: scope === "global" ? item.vhosts || [] : [] });
|
||||
ids.add(rule.id); rules.push(rule); added++;
|
||||
}
|
||||
render(); if (added) changed();
|
||||
return added;
|
||||
ids.add(rule.id);
|
||||
return rule;
|
||||
});
|
||||
// The parent-name rule must execute before the independent CDN cookie
|
||||
// strip / remaining-cookie pass checks; never move or merge CDN rules.
|
||||
const cdnIndex = templateKey === "publiccookies" ? rules.findIndex(rule =>
|
||||
/^CDN:/.test(rule.name || "") && rule.conditions.some(c => c.field === "header" && String(c.name || "").toLowerCase() === "cookie") &&
|
||||
rule.actions.some(a => a.type === "strip_cookies" || a.type === "pass")) : -1;
|
||||
if (cdnIndex >= 0) rules.splice(cdnIndex, 0, ...addedRules);
|
||||
else rules.push(...addedRules);
|
||||
if (addedRules.length) open.add(addedRules[0].id);
|
||||
render();
|
||||
if (addedRules.length) changed();
|
||||
return addedRules.length;
|
||||
}
|
||||
templates.addEventListener("change", () => { const make = TEMPLATES[templates.value]; templates.value = ""; if (!make) return; const added = addRules(make()); if (added) toast(t("cacheRulesTemplateAdded").replace("{count}", added)); });
|
||||
function addTemplate(key) {
|
||||
const make = TEMPLATES[key];
|
||||
if (!make || !templateAvailable(key, scope)) return;
|
||||
const items = make(), added = addRules(items, key);
|
||||
if (!added) return;
|
||||
const needsReview = items.some(item => item.enabled === false);
|
||||
toast(t(needsReview ? "cacheRuleCatalogAddedDisabled" : "cacheRulesTemplateAdded").replace("{count}", added));
|
||||
}
|
||||
function renderCatalog() {
|
||||
catalogGroups.replaceChildren();
|
||||
const query = catalogSearch.value.trim().toLocaleLowerCase();
|
||||
let shown = 0;
|
||||
for (const group of TEMPLATE_GROUPS) {
|
||||
const matches = group.keys.filter(key => templateAvailable(key, scope) &&
|
||||
(!query || `${templateName(key)} ${templateHelp(key)} ${t(`cacheRuleTplGroup${group.id[0].toUpperCase()}${group.id.slice(1)}`)}`.toLocaleLowerCase().includes(query)));
|
||||
if (!matches.length) continue;
|
||||
const section = el("section", undefined, "cache-rule-catalog-group");
|
||||
section.append(el("h5", t(`cacheRuleTplGroup${group.id[0].toUpperCase()}${group.id.slice(1)}`)));
|
||||
for (const key of matches) {
|
||||
const card = el("div", undefined, "cache-rule-catalog-card");
|
||||
const copy = el("div", undefined, "cache-rule-catalog-card-copy");
|
||||
const heading = el("strong", templateName(key));
|
||||
const description = el("p", templateHelp(key), "fine");
|
||||
copy.append(heading, description);
|
||||
if (TEMPLATES[key]().some(rule => rule.enabled === false))
|
||||
copy.append(el("span", t("cacheRuleCatalogReview"), "cache-rule-catalog-review"));
|
||||
const add = el("button", t("cacheRuleCatalogAdd"), "outline");
|
||||
add.type = "button";
|
||||
add.setAttribute("aria-label", `${t("cacheRuleCatalogAdd")}: ${templateName(key)}`);
|
||||
add.addEventListener("click", () => addTemplate(key));
|
||||
card.append(copy, add); section.append(card); shown++;
|
||||
}
|
||||
catalogGroups.append(section);
|
||||
}
|
||||
if (!shown) catalogGroups.append(el("p", t("cacheRuleCatalogEmpty"), "fine"));
|
||||
}
|
||||
browseButton.addEventListener("click", () => {
|
||||
catalog.hidden = !catalog.hidden;
|
||||
browseButton.setAttribute("aria-expanded", String(!catalog.hidden));
|
||||
if (!catalog.hidden) { renderCatalog(); catalogSearch.focus(); }
|
||||
});
|
||||
catalogSearch.addEventListener("input", renderCatalog);
|
||||
templates.addEventListener("change", () => { const key = templates.value; templates.value = ""; addTemplate(key); });
|
||||
addButton.addEventListener("click", () => { const rule = blankRule(taken()); rules.push(rule); open.add(rule.id); render(); changed(); list.lastElementChild?.scrollIntoView?.({ block: "nearest", behavior: "smooth" }); });
|
||||
importButton.addEventListener("click", () => { importBox.hidden = !importBox.hidden; if (importBox.hidden) resetImportPreview(); else importText.focus(); });
|
||||
importCancel.addEventListener("click", () => { importBox.hidden = true; resetImportPreview(); });
|
||||
@@ -627,5 +829,5 @@ window.rustProxyCacheRules = (() => {
|
||||
if (options.autoLoadHits !== false) void refreshHits();
|
||||
return { node: root, read, ignoreGlobal: () => ignoreGlobal, set(next) { rules = (next || []).map(normalize); open = new Set(); render(); }, refreshHits };
|
||||
}
|
||||
return { create, exportVcl, TEMPLATES };
|
||||
return { create, exportVcl, TEMPLATES, TEMPLATE_GROUPS };
|
||||
})();
|
||||
@@ -2470,6 +2470,65 @@ html[data-dashboard-density=normal] #panel-overview .stat>span,
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
|
||||
/* Searchable, grouped one-click cache/VCL rule library. The native select
|
||||
above remains for quick keyboard access and existing editor workflows. */
|
||||
.cache-rule-catalog {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
padding: 14px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--rp-radius-surface, 0px);
|
||||
background: var(--panel2);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.cache-rule-catalog>h4,
|
||||
.cache-rule-catalog>p,
|
||||
.cache-rule-catalog-card p { margin: 0; }
|
||||
|
||||
.cache-rule-catalog-search { width: min(100%, 480px); }
|
||||
|
||||
.cache-rule-catalog-groups {
|
||||
max-height: 540px;
|
||||
overflow: auto;
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
padding-right: 4px;
|
||||
}
|
||||
|
||||
.cache-rule-catalog-group { display: grid; gap: 7px; min-width: 0; }
|
||||
.cache-rule-catalog-group>h5 { margin: 0; font-size: 13px; }
|
||||
|
||||
.cache-rule-catalog-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 9px 11px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--rp-radius-surface, 0px);
|
||||
background: var(--panel);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.cache-rule-catalog-card-copy {
|
||||
display: grid;
|
||||
gap: 3px;
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.cache-rule-catalog-card-copy strong { font-size: 13px; line-height: 1.4; }
|
||||
.cache-rule-catalog-card-copy p { font-size: 12px; }
|
||||
.cache-rule-catalog-review { color: var(--accent); font-size: 11px; }
|
||||
.cache-rule-catalog-card>button { flex: 0 0 auto; }
|
||||
|
||||
@media (max-width: 540px) {
|
||||
.cache-rule-catalog { padding: 9px; }
|
||||
.cache-rule-catalog-card { align-items: flex-start; }
|
||||
}
|
||||
|
||||
.cache-rules-notices {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
|
||||
Reference in new issue
Block a user