// Config Validation System for LibrePortal Web UI // Validates JSON config files before loading the main interface // Global validator instance window.ConfigValidator = function() { let validationResults = null; let hasValidated = false; // Validate all config files this.validateAllConfigs = async function() { // Use client-side validation directly return this.fallbackValidation(); }; // Fallback client-side validation this.fallbackValidation = async function() { const results = { valid: true, errors: [], warnings: [], suggestions: [] }; // Check if unified config file exists (file existence check only) const configFiles = [ { name: 'Unified System Config', path: '/data/config/generated/configs.json' } ]; for (const config of configFiles) { try { const response = await fetch(config.path, { method: 'HEAD' }); if (!response.ok) { results.valid = false; results.errors.push(`Config file '${config.name}' not found: ${config.path}`); continue; } //console.log(`Config file exists: ${config.name}`); } catch (error) { results.valid = false; results.errors.push(`Failed to check ${config.name}: ${error.message}`); } } // Add suggestions if there are issues if (!results.valid) { results.suggestions = [ "Run 'libreportal run' to fix configuration issues", "Check config file permissions and ownership", "Ensure Docker is running and accessible" ]; } validationResults = results; hasValidated = true; return results; }; // Show validation error message this.showValidationError = function() { if (!hasValidated) { return; } if (validationResults.valid) { return; // No error to show } // Create error overlay const errorOverlay = document.createElement('div'); errorOverlay.className = 'config-validation-overlay'; errorOverlay.innerHTML = `

⚠️ Configuration Issues Detected

Errors:

    ${validationResults.errors.map(error => `
  • ${this.escapeHtml(error)}
  • `).join('')}
${validationResults.warnings.length > 0 ? `

Warnings:

    ${validationResults.warnings.map(warning => `
  • ${this.escapeHtml(warning)}
  • `).join('')}
` : ''}

Suggestions:

    ${validationResults.suggestions.map(suggestion => `
  • ${this.escapeHtml(suggestion)}
  • `).join('')}
`; // Add styles errorOverlay.innerHTML += ` `; document.body.appendChild(errorOverlay); }; // Escape HTML to prevent XSS this.escapeHtml = function(text) { const div = document.createElement('div'); div.textContent = text; return div.innerHTML; }; // Get validation status this.isValid = function() { return hasValidated && validationResults.valid; }; // Get validation errors this.getErrors = function() { return hasValidated ? validationResults.errors : []; }; // Get validation warnings this.getWarnings = function() { return hasValidated ? validationResults.warnings : []; }; };