diff --git a/docs/configuration.md b/docs/configuration.md index 90465063..e8ed4579 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -126,6 +126,14 @@ This should be a full URL ending with a /. Defaults to null meaning assume localhost. +### controller.favicon_url + +URL of the icon shown in the browser tab. +A relative URL is relative to the web interface root, so `static/icon.png` loads `icon.png` from the `static` folder in the controller's working directory. + +Defaults to null meaning use the Clusterio logo. + + ### controller.static_url Used to override where static assets such as the web bundle is loaded from. diff --git a/packages/controller/src/Controller.ts b/packages/controller/src/Controller.ts index 11618c0d..304255a5 100644 --- a/packages/controller/src/Controller.ts +++ b/packages/controller/src/Controller.ts @@ -48,6 +48,11 @@ const logSizeGauge = new Gauge( type InstanceId = { instanceId: number }; +const htmlEscapes: Record = { "&": "&", "<": "<", ">": ">", "\"": """, "'": "'" }; +function escapeHtml(text: string) { + return text.replace(/[&<>"']/g, char => htmlEscapes[char]); +} + type ControllerDebugEvents = { "message": [ { direction: "in" | "out", content: string } ], }; @@ -1720,8 +1725,16 @@ export default class Controller { path.join(import.meta.dirname, "..", "..", "..", "web", "index.html"), "utf8", ).then(async (content) => { + const config: lib.ControllerConfig = res.app.locals.controller.config; + let faviconUrl = config.get("controller.favicon_url"); + // Relative to the web root rather than the page + if (faviconUrl && !/^([a-z][a-z0-9+.-]*:|\/)/i.test(faviconUrl)) { + faviconUrl = webRoot + faviconUrl; + } + const favicon = faviconUrl ? `` : ""; content = content - .replace(/__CLUSTER_NAME__/g, res.app.locals.controller.config.get("controller.name")) + .replace(/__CLUSTER_NAME__/g, () => escapeHtml(config.get("controller.name"))) + .replace(/__FAVICON__/g, () => favicon) .replace(/__WEB_ROOT__/g, webRoot) .replace(/__STATIC_ROOT__/g, staticRoot) .replace(/__IMPORT_MAP__/g, () => importMap) diff --git a/packages/controller/web/index.html b/packages/controller/web/index.html index a153d69e..272702f5 100644 --- a/packages/controller/web/index.html +++ b/packages/controller/web/index.html @@ -4,7 +4,9 @@ + __CLUSTER_NAME__ + __FAVICON__