diff --git a/CHANGELOG.md b/CHANGELOG.md index 327da6c..efbbc9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [1.24.1] - 2026-10-30 + +### Fixed +- **Detección Dinámica de Lenguaje y Resaltado en Editor de Scripts de Plugins (`PluginSettingsComponent`, `PluginService`)**: + - Corregido el badge de cabecera del editor de código en `plugin-settings` que mostraba estáticamente `POWERSHELL` incluso en scripts de Bash/Linux (`#!/bin/bash`). + - Incorporada la propiedad declarativa `language?: string` en `SchemaField` (`PluginService`), permitiendo a los plugins especificar directamente su sintaxis (ej. `bash`, `powershell`, `sh`). + - Detección automática inteligente como respaldo según el atributo `field.language`, el nombre de la clave (`linux`, `bash`, `ps1`, etc.) o el shebang del script (`#!/bin/bash`, `#!/bin/sh`). + - Adaptación contextual del motor de coloreado de sintaxis para comandos (`echo`, `mount`, `losetup`, `update-initramfs`, etc.), palabras clave (`if`, `fi`, `then`, `do`, `done`, etc.) y banderas de Linux (`--bind`, `-o`, etc.). + ## [1.24.0] - 2026-10-28 ### Added diff --git a/ogWebconsole/package.json b/ogWebconsole/package.json index a81be82..2db9697 100644 --- a/ogWebconsole/package.json +++ b/ogWebconsole/package.json @@ -1,6 +1,6 @@ { "name": "og-webconsole", - "version": "1.24.0", + "version": "1.24.1", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/ogWebconsole/src/app/components/plugins/plugin-settings/plugin-settings.component.html b/ogWebconsole/src/app/components/plugins/plugin-settings/plugin-settings.component.html index 5904d9a..450365b 100644 --- a/ogWebconsole/src/app/components/plugins/plugin-settings/plugin-settings.component.html +++ b/ogWebconsole/src/app/components/plugins/plugin-settings/plugin-settings.component.html @@ -136,7 +136,7 @@ - PowerShell + {{ getScriptLanguage(field) }}
@if (field.action) { @@ -159,7 +159,7 @@ @if (!isEditingScript(field.key)) {
- @for (line of getScriptLines(configData[field.key]); track $index) { + @for (line of getScriptLines(configData[field.key], field); track $index) {
{{ $index + 1 }} diff --git a/ogWebconsole/src/app/components/plugins/plugin-settings/plugin-settings.component.ts b/ogWebconsole/src/app/components/plugins/plugin-settings/plugin-settings.component.ts index 6552711..9d0fe35 100644 --- a/ogWebconsole/src/app/components/plugins/plugin-settings/plugin-settings.component.ts +++ b/ogWebconsole/src/app/components/plugins/plugin-settings/plugin-settings.component.ts @@ -208,10 +208,35 @@ export class PluginSettingsComponent implements OnInit, OnChanges, OnDestroy { }); } - getScriptLines(script: string): SafeHtml[] { + getScriptLanguage(field: SchemaField): string { + if (field.language) { + const lang = field.language.toLowerCase().trim(); + if (['bash', 'sh', 'shell'].includes(lang)) return 'BASH'; + if (['powershell', 'ps1', 'ps'].includes(lang)) return 'POWERSHELL'; + return field.language.toUpperCase(); + } + + const key = (field.key || '').toLowerCase(); + if (key.includes('linux') || key.includes('bash') || key.includes('sh')) { + return 'BASH'; + } + if (key.includes('win') || key.includes('powershell') || key.includes('ps1')) { + return 'POWERSHELL'; + } + + const scriptContent = (this.configData[field.key] || '').trim(); + if (scriptContent.startsWith('#!/bin/') || scriptContent.startsWith('#!/usr/bin/')) { + return 'BASH'; + } + + return 'POWERSHELL'; + } + + getScriptLines(script: string, field?: SchemaField): SafeHtml[] { if (!script) return []; + const lang = field ? this.getScriptLanguage(field) : 'POWERSHELL'; const lines = script.split('\n'); - return lines.map(line => this.highlightLine(line)); + return lines.map(line => this.highlightLine(line, lang)); } private escapeHtml(str: string): string { @@ -221,7 +246,7 @@ export class PluginSettingsComponent implements OnInit, OnChanges, OnDestroy { .replace(/>/g, '>'); } - private highlightLine(rawLine: string): SafeHtml { + private highlightLine(rawLine: string, lang: string = 'POWERSHELL'): SafeHtml { const trimmed = rawLine.trim(); if (trimmed.length === 0) { @@ -243,20 +268,37 @@ export class PluginSettingsComponent implements OnInit, OnChanges, OnDestroy { return `___STR_${strings.length - 1}___`; }); - // 2. Parámetros / flags (/r, /t, -c, etc.) - escaped = escaped.replace(/(\s)([\/-][a-zA-Z0-9?]+)/g, '$1$2'); + if (lang === 'BASH') { + // 2. Parámetros / flags Linux (--bind, -o, -u, etc.) + escaped = escaped.replace(/(\s)(--?[a-zA-Z0-9?_-]+)/g, '$1$2'); - // 3. Comandos ejecutables - escaped = escaped.replace(/\b(uwfmgr\.exe|shutdown|powershell\.exe|cmd\.exe)\b/gi, '$1'); + // 3. Comandos ejecutables Linux + escaped = escaped.replace(/\b(echo|exit|reboot|shutdown|mount|umount|losetup|update-initramfs|modprobe|rm|mkdir|touch|cp|mv|cat|grep|sed|awk|systemctl|sleep|read)\b/gi, '$1'); - // 4. Subcomandos y palabras clave - escaped = escaped.replace(/\b(overlay|filter|volume|file|enable|disable|protect|set-type|set-size|add-exclusion)\b/gi, '$1'); + // 4. Palabras clave y control de flujo Bash + escaped = escaped.replace(/\b(if|then|else|elif|fi|case|esac|for|while|until|do|done|in|function|set|unset|export|source)\b/gi, '$1'); - // 5. Valores y tipos - escaped = escaped.replace(/\b(RAM|DISK|true|false)\b/gi, '$1'); + // 5. Valores y booleanos + escaped = escaped.replace(/\b(RAM|DISK|true|false)\b/gi, '$1'); - // 6. Números - escaped = escaped.replace(/\b(\d+)\b/g, '$1'); + // 6. Números + escaped = escaped.replace(/\b(\d+)\b/g, '$1'); + } else { + // 2. Parámetros / flags Windows (/r, /t, -c, etc.) + escaped = escaped.replace(/(\s)([\/-][a-zA-Z0-9?]+)/g, '$1$2'); + + // 3. Comandos ejecutables Windows + escaped = escaped.replace(/\b(uwfmgr\.exe|shutdown|powershell\.exe|cmd\.exe)\b/gi, '$1'); + + // 4. Subcomandos y palabras clave + escaped = escaped.replace(/\b(overlay|filter|volume|file|enable|disable|protect|set-type|set-size|add-exclusion)\b/gi, '$1'); + + // 5. Valores y tipos + escaped = escaped.replace(/\b(RAM|DISK|true|false)\b/gi, '$1'); + + // 6. Números + escaped = escaped.replace(/\b(\d+)\b/g, '$1'); + } // Restaurar cadenas escaped = escaped.replace(/___STR_(\d+)___/g, (_, index) => { diff --git a/ogWebconsole/src/app/services/plugin.service.ts b/ogWebconsole/src/app/services/plugin.service.ts index 72dec95..68484f6 100644 --- a/ogWebconsole/src/app/services/plugin.service.ts +++ b/ogWebconsole/src/app/services/plugin.service.ts @@ -69,6 +69,7 @@ export interface SchemaField { description?: string; descriptionKey?: string; type: 'text' | 'number' | 'select' | 'checkbox' | 'textarea'; + language?: string; options?: string[]; default: any; action?: FieldAction;