Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Core/Api/ExtensionEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ Acepta un enlace de GitHub (owner/repo, …/tree/ref/carpeta, …/releases/tag/x
g.MapGet("/{id}/log", (string id, ExtensionManager m) => TypedResults.Ok(new ExtensionLogResponse(m.GetLog(id))))
.WithSummary("Registro de scripts de la extensión");

// Iconos: imágenes de terceros. Con "sandbox" y nosniff, un SVG abierto fuera de un <img>
// no puede ejecutar nada con el origen del panel.
g.MapGet("/{id}/icon", (string id, HttpContext ctx, ExtensionManager m) =>
{
var file = m.ResolveIconFile(id);
if (file is null) return Results.NotFound();
IconHeaders(ctx);
return Results.File(file, ExtensionFormat.IconContentType(file));
}).WithSummary("Icono de una extensión instalada");

g.MapGet("/catalogs/icon", async (string url, int index, HttpContext ctx, ExtensionManager m, CancellationToken ct) =>
{
var icon = await m.GetCatalogIconAsync(url, index, ct);
if (icon is not { } i) return Results.NotFound();
IconHeaders(ctx);
return Results.Bytes(i.Bytes, i.ContentType);
}).WithSummary("Icono de una entrada de catálogo (se descarga de GitHub y se guarda una hora)");

g.MapGet("/catalogs", (bool? refresh, ExtensionManager m, CancellationToken ct) =>
Guard(async () => Results.Ok(await m.GetCatalogsAsync(refresh == true, ct))))
.WithSummary("Catálogos y sus extensiones");
Expand Down Expand Up @@ -84,6 +102,16 @@ Acepta un enlace de GitHub (owner/repo, …/tree/ref/carpeta, …/releases/tag/x
return app;
}

static void IconHeaders(HttpContext ctx)
{
var h = ctx.Response.Headers;
h["Content-Security-Policy"] = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
h["X-Content-Type-Options"] = "nosniff";
h["Cross-Origin-Resource-Policy"] = "same-origin";
// La URL lleva la versión (?v=), así que puede guardarse.
h["Cache-Control"] = "private, max-age=86400";
}

/// <summary>Errores esperables → 400/409/502 con el mensaje (ya traducido), no un 500.</summary>
static async Task<IResult> Guard(Func<Task<IResult>> action)
{
Expand Down
100 changes: 90 additions & 10 deletions Core/wwwroot/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,73 @@ let extTimer = null;
let extPreview = null; // vista previa en el modal de instalación
let extOpWatch = null; // sondeo mientras corre una operación

// Categorías que entiende el panel, en el orden del backend (ExtensionFormat.KnownCategories).
const EXT_CATEGORIES = ['remote-desktop', 'streaming', 'display', 'input', 'audio', 'network', 'games', 'monitoring', 'tools'];
let extCategory = ''; // filtro elegido ('' = todas); se recuerda en este navegador
try { extCategory = localStorage.getItem('osms.ext.category') || ''; } catch { /* sin almacenamiento */ }

function extCapLabel(cap) { return t(`ext.cap.${cap}`); }
function extCategoryLabel(cat) { return t(`ext.category.${cat}`); }

// Entrada de catálogo de una instalada (para lo que no trae su manifiesto).
function extCatalogEntryOf(x) {
for (const c of extCatalogs)
for (const e of c.extensions || [])
if (e.installedId === x.id) return e;
return null;
}

// Categorías e icono de una instalada: los suyos o, si no trae, los que le da su catálogo.
function extInstalledCategories(x) {
if (x.categories && x.categories.length) return x.categories;
const e = extCatalogEntryOf(x);
return e && e.categories ? e.categories : [];
}

function extInstalledIcon(x) {
return x.iconUrl || (extCatalogEntryOf(x) || {}).iconUrl || null;
}

function extIcon(url, name) {
const letter = esc((name || '?').trim().charAt(0).toUpperCase() || '?');
// Si la imagen no carga, se queda la inicial (está debajo).
return `<div class="ext-icon" aria-hidden="true"><span>${letter}</span>${
url ? `<img src="${esc(url)}" alt="" loading="lazy" decoding="async" onerror="this.remove()">` : ''}</div>`;
}

function extCategoryChips(cats) {
return (cats || []).map(c => `<span class="chip chip-cat">${esc(extCategoryLabel(c))}</span>`).join('');
}

function setExtCategory(cat) {
extCategory = cat;
try { cat ? localStorage.setItem('osms.ext.category', cat) : localStorage.removeItem('osms.ext.category'); } catch { /* idem */ }
renderExtensions();
}

// Barra de filtros: "Todas" y cada categoría que tenga alguna extensión (instalada o en catálogos).
function renderExtCategoryBar(installed, available) {
const counts = new Map();
const seen = new Set();
const add = (key, cats) => {
if (seen.has(key)) return;
seen.add(key);
for (const c of cats) counts.set(c, (counts.get(c) || 0) + 1);
};
for (const x of installed) add(`i:${x.id}`, extInstalledCategories(x));
for (const { e } of available) add(e.installedId ? `i:${e.installedId}` : `c:${e.repo}/${e.path || ''}`, e.categories || []);

const present = EXT_CATEGORIES.filter(c => counts.has(c));
if (extCategory && !present.includes(extCategory)) extCategory = '';
const bar = byId('ext-categories');
if (!present.length) { bar.classList.add('hidden'); renderInto(bar, ''); return; }
bar.classList.remove('hidden');
const btn = (cat, label, n) =>
`<button type="button" class="chip chip-btn${extCategory === cat ? ' active' : ''}" aria-pressed="${extCategory === cat}"
onclick="setExtCategory('${cat}')">${esc(label)}${n === undefined ? '' : ` <b>${n}</b>`}</button>`;
renderInto(bar, btn('', t('ext.categoryAll'), seen.size) +
present.map(c => btn(c, extCategoryLabel(c), counts.get(c))).join(''));
}

async function loadExtensions() {
const res = await api('GET', '/api/extensions');
Expand All @@ -29,24 +95,35 @@ async function loadExtensionCatalogs(refresh = false) {

// ── Vista principal ─────────────────────────────────────────────────────────
function renderExtensions() {
const list = extState.installed || [];
byId('ext-count').textContent = list.length;
renderInto(byId('ext-installed-grid'), list.length
? list.map(extCard).join('')
: `<div class="empty-state"><p>${esc(t('ext.noneInstalled'))}</p></div>`);
const all = extState.installed || [];
byId('ext-count').textContent = all.length;

const q = (byId('ext-search').value || '').trim().toLowerCase();
const rows = [];
const allRows = [];
for (const c of extCatalogs) {
for (const e of c.extensions || []) {
const text = `${e.name} ${e.description || ''} ${e.repo} ${(e.tags || []).join(' ')}`.toLowerCase();
if (!q || text.includes(q)) rows.push({ c, e });
const cats = (e.categories || []).map(extCategoryLabel).join(' ');
const text = `${e.name} ${e.description || ''} ${e.repo} ${(e.tags || []).join(' ')} ${cats}`.toLowerCase();
if (!q || text.includes(q)) allRows.push({ c, e });
}
}
renderExtCategoryBar(all, allRows);

const inCategory = cats => !extCategory || cats.includes(extCategory);
const list = all.filter(x => inCategory(extInstalledCategories(x)));
const rows = allRows.filter(({ e }) => inCategory(e.categories || []));
const emptyFiltered = `<div class="empty-state"><p>${esc(t('ext.noneInCategory', { category: extCategoryLabel(extCategory) }))}</p></div>`;

renderInto(byId('ext-installed-grid'), list.length
? list.map(extCard).join('')
: all.length && extCategory ? emptyFiltered
: `<div class="empty-state"><p>${esc(t('ext.noneInstalled'))}</p></div>`);

const errors = extCatalogs.filter(c => c.error)
.map(c => `<div class="card-warning">${esc(c.name)}: ${esc(t('ext.catalogError', { msg: c.error }))}</div>`).join('');
renderInto(byId('ext-available-grid'), errors + (rows.length
? rows.map(({ c, e }) => extCatalogCard(c, e)).join('')
: allRows.length && extCategory ? emptyFiltered
: `<div class="empty-state"><p>${esc(t('ext.noneAvailable'))}</p></div>`));
}

Expand All @@ -63,6 +140,7 @@ function extCard(x) {
const cat = extCatalogs.find(c => c.url === x.catalogUrl);
return `<div class="session-card ext-card${x.enabled ? '' : ' is-stopped'}" id="ext-${esc(x.id)}">
<div class="card-header">
${extIcon(extInstalledIcon(x), x.name)}
<div class="card-title-wrap">
<div class="card-title">${esc(x.name)}</div>
<div class="card-subtitle">${esc(x.version)} · <a href="${esc(x.repoUrl)}" target="_blank" rel="noopener noreferrer">${esc(x.repo)}</a>${
Expand All @@ -71,7 +149,7 @@ function extCard(x) {
<button class="icon-btn" type="button" onclick="extMenu(event,'${esc(x.id)}')" aria-label="${esc(t('nav.more'))}">${uiIcon('more')}</button>
</div>
${x.description ? `<p class="ext-desc">${esc(x.description)}</p>` : ''}
<div class="card-chips">${extChips(x.capabilities)}${status.join('')}${
<div class="card-chips">${extCategoryChips(extInstalledCategories(x))}${extChips(x.capabilities)}${status.join('')}${
cat ? `<span class="chip" title="${esc(cat.url)}">${esc(t('ext.fromCatalog', { catalog: cat.name }))}</span>` : ''}</div>
</div>`;
}
Expand All @@ -83,14 +161,15 @@ function extCatalogCard(c, e) {
const args = JSON.stringify({ source: e.repo, path: e.path, catalogUrl: c.url }).replace(/"/g, '&quot;');
return `<div class="session-card ext-card">
<div class="card-header">
${extIcon(e.iconUrl, e.name)}
<div class="card-title-wrap">
<div class="card-title">${esc(e.name)}</div>
<div class="card-subtitle"><a href="${esc(e.repoUrl)}" target="_blank" rel="noopener noreferrer">${esc(e.repo)}${
e.path ? '/' + esc(e.path) : ''}</a> · ${esc(c.name)}${c.official ? ` <span class="chip chip-ok">${esc(t('ext.official'))}</span>` : ''}</div>
</div>
</div>
${e.description ? `<p class="ext-desc">${esc(e.description)}</p>` : ''}
<div class="card-chips">${installed}${pinned}${tags}</div>
<div class="card-chips">${extCategoryChips(e.categories)}${installed}${pinned}${tags}</div>
<div class="card-actions">
<button class="btn btn-primary btn-sm" type="button" onclick="openExtInstall(${args})">${esc(e.installedId ? t('ext.reinstall') : t('ext.install'))}</button>
</div>
Expand Down Expand Up @@ -199,6 +278,7 @@ function showExtPreview(p, { update = false } = {}) {
${row(t('ext.commit'), `<code>${esc(p.commit)}</code>`)}
${row(t('ext.sha256'), `<code class="ext-hash">${esc(p.sha256)}</code><br><span class="muted">${esc(t(p.sha256Pinned ? 'ext.sha256Pinned' : 'ext.sha256Unpinned'))}</span>`)}
${row(t('ext.license'), esc(p.license || ''))}
${(p.categories || []).length ? row(t('ext.categories'), esc(p.categories.map(extCategoryLabel).join(', '))) : ''}
${p.homepage ? row(t('ext.homepage'), `<a href="${esc(p.homepage)}" target="_blank" rel="noopener noreferrer">${esc(p.homepage)}</a>`) : ''}
</div>
<ul class="ext-caps">${caps}</ul>
Expand Down
1 change: 1 addition & 0 deletions Core/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
<button class="btn btn-primary btn-sm" type="button" onclick="openExtInstall()" data-i18n="ext.installLink">+ Instalar desde enlace</button>
</div>
</div>
<div class="ext-categories hidden" id="ext-categories" role="toolbar" data-i18n-aria="ext.categories" aria-label="Categorías"></div>
<h3 class="ext-section-title" data-i18n="ext.installed">Instaladas</h3>
<div class="sessions-grid" id="ext-installed-grid">
<div class="empty-state"><p data-i18n="empty.loading">Cargando…</p></div>
Expand Down
12 changes: 12 additions & 0 deletions Core/wwwroot/locales/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@
"ext.noneAvailable": "Вашите каталози не съдържат разширения.",
"ext.search": "Търсене…",
"ext.refresh": "Опресняване",
"ext.categories": "Категории",
"ext.categoryAll": "Всички",
"ext.noneInCategory": "Няма разширения в „{category}“.",
"ext.category.remote-desktop": "Отдалечен работен плот",
"ext.category.streaming": "Стрийминг",
"ext.category.display": "Дисплеи",
"ext.category.input": "Контролери и въвеждане",
"ext.category.audio": "Звук",
"ext.category.network": "Мрежа",
"ext.category.games": "Игри",
"ext.category.monitoring": "Наблюдение",
"ext.category.tools": "Инструменти",
"ext.cap.component": "Инсталира софтуер",
"ext.cap.component_desc": "Изпълнява инсталационния си скрипт като SYSTEM, с пълен контрол над този компютър.",
"ext.cap.hooks": "Скриптове за сесии",
Expand Down
12 changes: 12 additions & 0 deletions Core/wwwroot/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@
"ext.noneAvailable": "Vaše katalogy neobsahují žádná rozšíření.",
"ext.search": "Hledat…",
"ext.refresh": "Obnovit",
"ext.categories": "Kategorie",
"ext.categoryAll": "Vše",
"ext.noneInCategory": "V kategorii „{category}“ nejsou žádná rozšíření.",
"ext.category.remote-desktop": "Vzdálená plocha",
"ext.category.streaming": "Streamování",
"ext.category.display": "Displeje",
"ext.category.input": "Ovladače a vstup",
"ext.category.audio": "Zvuk",
"ext.category.network": "Síť",
"ext.category.games": "Hry",
"ext.category.monitoring": "Monitorování",
"ext.category.tools": "Nástroje",
"ext.cap.component": "Instaluje software",
"ext.cap.component_desc": "Spouští svůj instalační skript jako SYSTEM, s plnou kontrolou nad tímto PC.",
"ext.cap.hooks": "Skripty relací",
Expand Down
12 changes: 12 additions & 0 deletions Core/wwwroot/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@
"ext.noneAvailable": "Deine Kataloge enthalten keine Erweiterungen.",
"ext.search": "Suchen…",
"ext.refresh": "Aktualisieren",
"ext.categories": "Kategorien",
"ext.categoryAll": "Alle",
"ext.noneInCategory": "Keine Erweiterungen in „{category}“.",
"ext.category.remote-desktop": "Remotedesktop",
"ext.category.streaming": "Streaming",
"ext.category.display": "Anzeigen",
"ext.category.input": "Controller und Eingabe",
"ext.category.audio": "Audio",
"ext.category.network": "Netzwerk",
"ext.category.games": "Spiele",
"ext.category.monitoring": "Überwachung",
"ext.category.tools": "Werkzeuge",
"ext.cap.component": "Installiert Software",
"ext.cap.component_desc": "Führt sein Installationsskript als SYSTEM aus, mit voller Kontrolle über diesen PC.",
"ext.cap.hooks": "Sitzungsskripte",
Expand Down
12 changes: 12 additions & 0 deletions Core/wwwroot/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@
"ext.noneAvailable": "Your catalogs don't list any extensions.",
"ext.search": "Search…",
"ext.refresh": "Refresh",
"ext.categories": "Categories",
"ext.categoryAll": "All",
"ext.noneInCategory": "No extensions in “{category}”.",
"ext.category.remote-desktop": "Remote desktop",
"ext.category.streaming": "Streaming",
"ext.category.display": "Displays",
"ext.category.input": "Controllers and input",
"ext.category.audio": "Audio",
"ext.category.network": "Network",
"ext.category.games": "Games",
"ext.category.monitoring": "Monitoring",
"ext.category.tools": "Tools",
"ext.cap.component": "Installs software",
"ext.cap.component_desc": "Runs its install script as SYSTEM, with full control of this PC.",
"ext.cap.hooks": "Session scripts",
Expand Down
12 changes: 12 additions & 0 deletions Core/wwwroot/locales/en_GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@
"ext.noneAvailable": "Your catalogues don't list any extensions.",
"ext.search": "Search…",
"ext.refresh": "Refresh",
"ext.categories": "Categories",
"ext.categoryAll": "All",
"ext.noneInCategory": "No extensions in “{category}”.",
"ext.category.remote-desktop": "Remote desktop",
"ext.category.streaming": "Streaming",
"ext.category.display": "Displays",
"ext.category.input": "Controllers and input",
"ext.category.audio": "Audio",
"ext.category.network": "Network",
"ext.category.games": "Games",
"ext.category.monitoring": "Monitoring",
"ext.category.tools": "Tools",
"ext.cap.component": "Installs software",
"ext.cap.component_desc": "Runs its install script as SYSTEM, with full control of this PC.",
"ext.cap.hooks": "Session scripts",
Expand Down
12 changes: 12 additions & 0 deletions Core/wwwroot/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@
"ext.noneAvailable": "Your catalogs don't list any extensions.",
"ext.search": "Search…",
"ext.refresh": "Refresh",
"ext.categories": "Categories",
"ext.categoryAll": "All",
"ext.noneInCategory": "No extensions in “{category}”.",
"ext.category.remote-desktop": "Remote desktop",
"ext.category.streaming": "Streaming",
"ext.category.display": "Displays",
"ext.category.input": "Controllers and input",
"ext.category.audio": "Audio",
"ext.category.network": "Network",
"ext.category.games": "Games",
"ext.category.monitoring": "Monitoring",
"ext.category.tools": "Tools",
"ext.cap.component": "Installs software",
"ext.cap.component_desc": "Runs its install script as SYSTEM, with full control of this PC.",
"ext.cap.hooks": "Session scripts",
Expand Down
12 changes: 12 additions & 0 deletions Core/wwwroot/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@
"ext.noneAvailable": "Tus catálogos no tienen extensiones.",
"ext.search": "Buscar…",
"ext.refresh": "Actualizar",
"ext.categories": "Categorías",
"ext.categoryAll": "Todas",
"ext.noneInCategory": "No hay extensiones en «{category}».",
"ext.category.remote-desktop": "Escritorio remoto",
"ext.category.streaming": "Streaming",
"ext.category.display": "Pantallas",
"ext.category.input": "Mandos y entrada",
"ext.category.audio": "Audio",
"ext.category.network": "Red",
"ext.category.games": "Juegos",
"ext.category.monitoring": "Monitorización",
"ext.category.tools": "Herramientas",
"ext.cap.component": "Instala software",
"ext.cap.component_desc": "Ejecuta su script de instalación como SYSTEM, con control total del PC.",
"ext.cap.hooks": "Scripts de sesión",
Expand Down
12 changes: 12 additions & 0 deletions Core/wwwroot/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@
"ext.noneAvailable": "Vos catalogues ne proposent aucune extension.",
"ext.search": "Rechercher…",
"ext.refresh": "Actualiser",
"ext.categories": "Catégories",
"ext.categoryAll": "Toutes",
"ext.noneInCategory": "Aucune extension dans « {category} ».",
"ext.category.remote-desktop": "Bureau à distance",
"ext.category.streaming": "Streaming",
"ext.category.display": "Écrans",
"ext.category.input": "Manettes et saisie",
"ext.category.audio": "Audio",
"ext.category.network": "Réseau",
"ext.category.games": "Jeux",
"ext.category.monitoring": "Supervision",
"ext.category.tools": "Outils",
"ext.cap.component": "Installe des logiciels",
"ext.cap.component_desc": "Exécute son script d'installation en tant que SYSTEM, avec un contrôle total de ce PC.",
"ext.cap.hooks": "Scripts de session",
Expand Down
12 changes: 12 additions & 0 deletions Core/wwwroot/locales/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@
"ext.noneAvailable": "A katalógusaid nem tartalmaznak bővítményt.",
"ext.search": "Keresés…",
"ext.refresh": "Frissítés",
"ext.categories": "Kategóriák",
"ext.categoryAll": "Összes",
"ext.noneInCategory": "Nincs bővítmény a(z) „{category}” kategóriában.",
"ext.category.remote-desktop": "Távoli asztal",
"ext.category.streaming": "Streamelés",
"ext.category.display": "Kijelzők",
"ext.category.input": "Kontrollerek és bevitel",
"ext.category.audio": "Hang",
"ext.category.network": "Hálózat",
"ext.category.games": "Játékok",
"ext.category.monitoring": "Megfigyelés",
"ext.category.tools": "Eszközök",
"ext.cap.component": "Szoftvert telepít",
"ext.cap.component_desc": "A telepítőszkriptjét SYSTEM-ként futtatja, teljes hozzáféréssel ehhez a PC-hez.",
"ext.cap.hooks": "Munkamenet-szkriptek",
Expand Down
Loading
Loading