diff --git a/meshcentral-config-schema.json b/meshcentral-config-schema.json index 77504a7e..076d4c0c 100644 --- a/meshcentral-config-schema.json +++ b/meshcentral-config-schema.json @@ -1988,15 +1988,41 @@ "type": "object" }, "customFiles": { - "type": "array", - "description": "Advanced customization system allowing multiple CSS and JavaScript file configurations per domain. Each configuration can target specific templates using the 'scope' property, enabling granular control over where custom files are loaded. All custom files are loaded after the default custom.css and custom.js files.", - "items": { + "type": "object", + "description": "Advanced customization system allowing multiple CSS and JavaScript file configurations per domain. Each configuration is identified by a unique name and can target specific templates using the 'scope' property, enabling granular control over where custom files are loaded. All custom files are loaded after the default custom.css and custom.js files.", + "properties": { + "example-config": { + "type": "object", + "description": "Example configuration - replace 'example-config' with your desired name", + "properties": { + "css": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Ordered list of custom CSS files to load. Files are loaded in the specified order after the default custom.css. Place files in the meshcentral-data/public/styles/ directory. Example: [\"theme.css\", \"overrides.css\", \"mobile.css\"]" + }, + "js": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Ordered list of custom JavaScript files to load. Files are loaded in the specified order after the default custom.js. Place files in the meshcentral-data/public/scripts/ directory. Example: [\"analytics.js\", \"custom-functions.js\", \"ui-enhancements.js\"]" + }, + "scope": { + "type": "array", + "items": { + "type": "string" + }, + "description": "List of template names where these custom files should be loaded. If not specified or empty, files will NOT be loaded anywhere. Use 'all' to load on all templates. Available template names: all, default, default3, default-mobile, login, login2, login-mobile, messenger, message, message2, invite, agentinvite, player, xterm, mstsc, ssh, sharing, sharing-mobile, download, download2, terms, terms-mobile, error404, error4042, error404-mobile. Example: [\"default3\", \"login2\", \"player\"] or [\"all\"]" + } + } + } + }, + "additionalProperties": { "type": "object", + "description": "Custom file configuration identified by a unique name", "properties": { - "name": { - "type": "string", - "description": "Unique name for this custom files configuration. Used for identification and debugging purposes." - }, "css": { "type": "array", "items": { @@ -2018,8 +2044,7 @@ }, "description": "List of template names where these custom files should be loaded. If not specified or empty, files will NOT be loaded anywhere. Use 'all' to load on all templates. Available template names: all, default, default3, default-mobile, login, login2, login-mobile, messenger, message, message2, invite, agentinvite, player, xterm, mstsc, ssh, sharing, sharing-mobile, download, download2, terms, terms-mobile, error404, error4042, error404-mobile. Example: [\"default3\", \"login2\", \"player\"] or [\"all\"]" } - }, - "required": ["name"] + } } }, "consentMessages": { diff --git a/sample-config-advanced.json b/sample-config-advanced.json index 58fb5ed6..430d6c8a 100644 --- a/sample-config-advanced.json +++ b/sample-config-advanced.json @@ -347,6 +347,18 @@ "autoAcceptIfNoUser": false, "oldStyle": true }, + "_customFiles": { + "desktop-theme": { + "css": ["theme.css"], + "js": ["theme.js"], + "scope": ["all"] + }, + "mobile-theme": { + "css": ["theme.css", "test.css"], + "js": ["analytics.js", "test.js"], + "scope": ["login2", "login"] + } + }, "_notificationMessages": { "title": "MeshCentral", "desktop": "{0} started a remote desktop session.", diff --git a/webserver.js b/webserver.js index 11c45555..7c7c84a6 100644 --- a/webserver.js +++ b/webserver.js @@ -9462,16 +9462,17 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF return null; } - function generateCustomCSSTags(customFilesArray, currentTemplate) { + function generateCustomCSSTags(customFilesObject, currentTemplate) { var cssTags = ''; cssTags += '\n '; - if (customFilesArray) { - if (Array.isArray(customFilesArray)) { - for (var i = 0; i < customFilesArray.length; i++) { - var customFileConfig = customFilesArray[i]; + if (customFilesObject) { + if (Array.isArray(customFilesObject)) { + // Legacy array support - convert to object format + for (var i = 0; i < customFilesObject.length; i++) { + var customFileConfig = customFilesObject[i]; if (customFileConfig && customFileConfig.css && Array.isArray(customFileConfig.css)) { if ((customFileConfig.scope && customFileConfig.scope.indexOf('all') !== -1) || (currentTemplate && customFileConfig.scope && customFileConfig.scope.indexOf(currentTemplate) !== -1)) { @@ -9481,9 +9482,23 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF } } } - } else if (customFilesArray.css && Array.isArray(customFilesArray.css)) { - for (var i = 0; i < customFilesArray.css.length; i++) { - cssTags += '\n '; + } else if (customFilesObject.css && Array.isArray(customFilesObject.css)) { + // Legacy single object support + for (var i = 0; i < customFilesObject.css.length; i++) { + cssTags += '\n '; + } + } else if (typeof customFilesObject === 'object') { + // New object format - iterate through each custom file configuration + for (var configName in customFilesObject) { + var customFileConfig = customFilesObject[configName]; + if (customFileConfig && customFileConfig.css && Array.isArray(customFileConfig.css)) { + if ((customFileConfig.scope && customFileConfig.scope.indexOf('all') !== -1) || + (currentTemplate && customFileConfig.scope && customFileConfig.scope.indexOf(currentTemplate) !== -1)) { + for (var j = 0; j < customFileConfig.css.length; j++) { + cssTags += '\n '; + } + } + } } } } @@ -9491,15 +9506,16 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF return cssTags.trim(); } - function generateCustomJSTags(customFilesArray, currentTemplate) { + function generateCustomJSTags(customFilesObject, currentTemplate) { var jsTags = ''; jsTags += '\n '; - if (customFilesArray) { - if (Array.isArray(customFilesArray)) { - for (var i = 0; i < customFilesArray.length; i++) { - var customFileConfig = customFilesArray[i]; + if (customFilesObject) { + if (Array.isArray(customFilesObject)) { + // Legacy array support - convert to object format + for (var i = 0; i < customFilesObject.length; i++) { + var customFileConfig = customFilesObject[i]; if (customFileConfig && customFileConfig.js && Array.isArray(customFileConfig.js)) { if ((customFileConfig.scope && customFileConfig.scope.indexOf('all') !== -1) || (currentTemplate && customFileConfig.scope && customFileConfig.scope.indexOf(currentTemplate) !== -1)) { @@ -9509,9 +9525,23 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF } } } - } else if (customFilesArray.js && Array.isArray(customFilesArray.js)) { - for (var i = 0; i < customFilesArray.js.length; i++) { - jsTags += '\n '; + } else if (customFilesObject.js && Array.isArray(customFilesObject.js)) { + // Legacy single object support + for (var i = 0; i < customFilesObject.js.length; i++) { + jsTags += '\n '; + } + } else if (typeof customFilesObject === 'object') { + // New object format - iterate through each custom file configuration + for (var configName in customFilesObject) { + var customFileConfig = customFilesObject[configName]; + if (customFileConfig && customFileConfig.js && Array.isArray(customFileConfig.js)) { + if ((customFileConfig.scope && customFileConfig.scope.indexOf('all') !== -1) || + (currentTemplate && customFileConfig.scope && customFileConfig.scope.indexOf(currentTemplate) !== -1)) { + for (var j = 0; j < customFileConfig.js.length; j++) { + jsTags += '\n '; + } + } + } } } }