PowerShell-HTTP-Server mit Web-/Desktop-Oberflaeche: Programme (winget/Store), Office-ODT-Konfigurator, Desktop-Icons, System/Sicherheit, Energie, BitLocker, Windows-/Treiber-Updates, Profile und Job-Queue. Co-Authored-By: Claude Opus 5.5 <[email protected]>
412 lines
27 KiB
JavaScript
412 lines
27 KiB
JavaScript
'use strict';
|
||
// ---------------------------------------------------------------- Basis
|
||
const $ = (s, r = document) => r.querySelector(s);
|
||
const $$ = (s, r = document) => [...r.querySelectorAll(s)];
|
||
const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
||
|
||
const urlToken = new URLSearchParams(location.search).get('token');
|
||
if (urlToken) { sessionStorage.setItem('kdsToken', urlToken); history.replaceState(null, '', '/' + location.hash); }
|
||
const TOKEN = sessionStorage.getItem('kdsToken') || '';
|
||
|
||
async function api(method, path, body, raw) {
|
||
const r = await fetch(path, {
|
||
method, headers: { 'X-Token': TOKEN, 'Content-Type': 'application/json' },
|
||
body: body === undefined ? undefined : (typeof body === 'string' ? body : JSON.stringify(body))
|
||
});
|
||
if (raw) return r.text();
|
||
const data = await r.json().catch(() => null);
|
||
if (!r.ok) throw new Error(data?.error || `HTTP ${r.status}`);
|
||
return data;
|
||
}
|
||
const arr = v => v == null ? [] : Array.isArray(v) ? v : [v];
|
||
|
||
function toast(msg, isErr, onClick) {
|
||
const d = document.createElement('div');
|
||
d.textContent = msg; if (isErr) d.className = 'err';
|
||
d.onclick = () => { onClick?.(); d.remove(); };
|
||
$('#toast').append(d); setTimeout(() => d.remove(), isErr ? 8000 : 4000);
|
||
}
|
||
async function guard(fn) { try { return await fn(); } catch (e) { toast(e.message, true); } }
|
||
|
||
// ---------------------------------------------------------------- Zustand / Profil
|
||
const DEFAULTS = () => ({
|
||
name: '',
|
||
apps: [],
|
||
office: {
|
||
product: 'O365ProPlusRetail', channel: 'Current', arch: '64', languages: ['de-de'],
|
||
exclude: ['Groove', 'Lync', 'Bing'], extraProducts: [], pidKey: '', company: '',
|
||
updates: true, removeMsi: true, migrateArch: true, sharedComputer: false, disableVba: true, ooxmlDefault: true, showUi: false
|
||
},
|
||
officeMode: 'online',
|
||
shortcuts: [],
|
||
system: { computerName: '', timeZone: '', showExtensions: true, disableConsumer: true },
|
||
security: { defender: true, firewall: true, smartScreen: true, uac: false, disableSmb1: true, disableAutorun: true, lsaProtection: false, telemetryMin: false, rdp: 'keep', localAdminName: '', localAdminPassword: '' },
|
||
power: { plan: 'balanced', monitorAc: 15, monitorDc: 5, sleepAc: 0, sleepDc: 15, hibernateAc: 0, hibernateDc: 60, lidAc: 'nothing', lidDc: 'sleep', buttonAc: 'shutdown', buttonDc: 'shutdown', hibernate: '', fastStartup: 'off' },
|
||
bitlocker: { method: 'XtsAes256', usedSpaceOnly: true, skipHardwareTest: true, usePin: false, pin: '', backupAad: false, backupAd: false },
|
||
steps: ['system', 'security', 'power', 'apps', 'office', 'shortcuts', 'updates']
|
||
});
|
||
let S = DEFAULTS();
|
||
try { const saved = JSON.parse(localStorage.getItem('kdsState') || 'null'); if (saved) S = deepMerge(DEFAULTS(), saved); } catch { }
|
||
|
||
function deepMerge(base, add) {
|
||
for (const k of Object.keys(add || {})) {
|
||
if (add[k] && typeof add[k] === 'object' && !Array.isArray(add[k]) && base[k] && typeof base[k] === 'object') deepMerge(base[k], add[k]);
|
||
else base[k] = add[k];
|
||
}
|
||
return base;
|
||
}
|
||
const getPath = p => p.split('.').reduce((o, k) => o?.[k], S);
|
||
function setPath(p, v) { const ks = p.split('.'); const last = ks.pop(); ks.reduce((o, k) => o[k] ??= {}, S)[last] = v; }
|
||
function persist() { try { localStorage.setItem('kdsState', JSON.stringify(S)); } catch { } renderSummary(); }
|
||
|
||
// generische Formularbindung: data-bind="pfad" und data-bind-list="pfad" (Checkbox-Gruppen)
|
||
function bindForms() {
|
||
$$('[data-bind]').forEach(el => {
|
||
el.addEventListener(el.type === 'checkbox' ? 'change' : 'input', () => {
|
||
let v = el.type === 'checkbox' ? el.checked : el.value;
|
||
if (el.type === 'number') v = el.value === '' ? '' : Number(el.value);
|
||
setPath(el.dataset.bind, v); persist(); onChange(el.dataset.bind);
|
||
});
|
||
if (el.tagName === 'SELECT') el.addEventListener('change', () => el.dispatchEvent(new Event('input')));
|
||
});
|
||
$$('[data-bind-list]').forEach(box => box.addEventListener('change', () => {
|
||
setPath(box.dataset.bindList, $$('input:checked', box).map(i => i.value)); persist(); onChange(box.dataset.bindList);
|
||
}));
|
||
}
|
||
function fillForms() {
|
||
$$('[data-bind]').forEach(el => {
|
||
const v = getPath(el.dataset.bind);
|
||
if (el.type === 'checkbox') el.checked = !!v; else el.value = v ?? '';
|
||
});
|
||
$$('[data-bind-list]').forEach(box => {
|
||
const v = arr(getPath(box.dataset.bindList));
|
||
$$('input', box).forEach(i => i.checked = v.includes(i.value));
|
||
});
|
||
$$('#steps input').forEach(i => i.checked = arr(S.steps).includes(i.value));
|
||
$('#profileName').textContent = 'Profil: ' + (S.name || '(ungespeichert)');
|
||
$$('.pinonly').forEach(e => e.classList.toggle('hidden', !S.bitlocker.usePin));
|
||
}
|
||
function onChange(path) {
|
||
if (path.startsWith('office')) { if (path === 'office.product') { renderOfficeChannels(); renderOfficeExtras(); } updateOfficeXml(); }
|
||
if (path === 'bitlocker.usePin') fillForms();
|
||
}
|
||
function loadState(obj) { S = deepMerge(DEFAULTS(), obj); persist(); fillForms(); renderAll(); }
|
||
|
||
// ---------------------------------------------------------------- Navigation
|
||
function showTab(t) {
|
||
$$('#nav a').forEach(a => a.classList.toggle('active', a.dataset.tab === t));
|
||
$$('.tab').forEach(s => s.classList.toggle('active', s.id === 'tab-' + t));
|
||
({ shortcuts: loadShortcuts, bitlocker: loadBitlocker, profiles: loadProfiles, jobs: pollJobs, power: loadPower, office: loadOfficeBuilds })[t]?.();
|
||
}
|
||
$('#nav').onclick = e => { const a = e.target.closest('a'); if (a) showTab(a.dataset.tab); };
|
||
|
||
// ---------------------------------------------------------------- Übersicht
|
||
async function loadStatus() {
|
||
const s = await api('GET', '/api/status');
|
||
const tpm = s.tpm ? (s.tpm.present ? (s.tpm.ready ? 'vorhanden, bereit' : 'vorhanden, nicht bereit') : 'nicht vorhanden') : 'unbekannt';
|
||
const items = [['Computer', s.computerName], ['Hersteller / Modell', `${s.manufacturer} ${s.model}`], ['Seriennummer', s.serial],
|
||
['Windows', `${s.os}<br><span class="muted small">${esc(s.build)}</span>`], ['Prozessor', s.cpu], ['RAM', s.ramGB + ' GB'],
|
||
['Systemlaufwerk', `${s.diskFreeGB} GB frei von ${s.diskSizeGB} GB`], ['TPM', tpm], ['Domäne', s.partOfDomain ? s.domain : 'Arbeitsgruppe'],
|
||
['winget', s.winget ? 'verfügbar' : '<span style="color:var(--err)">fehlt – wird automatisch installiert</span>'], ['Akku', s.battery || '–'], ['Agent-Pfad', s.root]];
|
||
$('#sysinfo').innerHTML = items.map(([k, v]) => `<div class="stat"><div class="k">${k}</div><div class="v">${/<|&/.test(v) && k !== 'Seriennummer' ? v : esc(v)}</div></div>`).join('');
|
||
}
|
||
function renderSummary() {
|
||
const o = S.office, prod = PRODUCTS.find(p => p.id === o.product);
|
||
$('#summary').innerHTML = [
|
||
`<b>${arr(S.apps).length}</b> Programme`, `Office: <b>${esc(prod?.name || o.product)}</b> (${o.arch}-Bit, ${esc(S.officeMode)})`,
|
||
`<b>${arr(S.shortcuts).length}</b> Desktop-Icons`, `Energieplan: <b>${esc(S.power.plan || 'unverändert')}</b>`,
|
||
S.system.computerName ? `Neuer Name: <b>${esc(S.system.computerName)}</b>` : ''
|
||
].filter(Boolean).join(' · ');
|
||
}
|
||
$('#steps').onchange = () => { S.steps = $$('#steps input:checked').map(i => i.value); persist(); };
|
||
$('#btnRunAll').onclick = () => guard(async () => {
|
||
if (!S.steps.length) return toast('Keine Schritte ausgewählt', true);
|
||
if (S.steps.includes('bitlocker')) S.bitlocker.action = 'enable';
|
||
if (!confirm(`Einrichtung mit ${S.steps.length} Schritten jetzt starten?`)) return;
|
||
const r = await api('POST', '/api/run-profile', S); jobStarted(r.job);
|
||
});
|
||
|
||
// ---------------------------------------------------------------- Programme
|
||
let catalog = [];
|
||
async function loadCatalog() {
|
||
catalog = arr((await api('GET', '/api/catalog'))?.apps);
|
||
const groups = {};
|
||
catalog.forEach(a => (groups[a.category] ??= []).push(a));
|
||
$('#catalog').innerHTML = Object.entries(groups).map(([c, list]) => `<div class="cat"><h3>${esc(c)}</h3><div class="checks">${list.map(a =>
|
||
`<label><input type="checkbox" data-app="${esc(a.id)}"> ${esc(a.name)}</label>`).join('')}</div></div>`).join('');
|
||
syncCatalogChecks();
|
||
const local = arr(await api('GET', '/api/local-installers'));
|
||
$('#localFile').innerHTML = local.length ? local.map(f => `<option>${esc(f)}</option>`).join('') : '<option value="">(keine Dateien in installers\\)</option>';
|
||
}
|
||
$('#catalog').onchange = e => {
|
||
const id = e.target.dataset.app; if (!id) return;
|
||
const a = catalog.find(x => x.id === id);
|
||
if (e.target.checked) addApp({ name: a.name, id: a.id, source: a.source, override: a.override });
|
||
else removeApp(id);
|
||
};
|
||
function syncCatalogChecks() { $$('#catalog input').forEach(i => i.checked = S.apps.some(a => a.id === i.dataset.app)); }
|
||
function addApp(a) { if (S.apps.some(x => x.id === a.id)) return; S.apps.push(a); persist(); renderSelectedApps(); }
|
||
function removeApp(id) { S.apps = S.apps.filter(a => a.id !== id); persist(); renderSelectedApps(); }
|
||
function renderSelectedApps() {
|
||
$('#appCount').textContent = S.apps.length;
|
||
$('#selectedApps').innerHTML = S.apps.length ? S.apps.map(a => `<div class="item"><div class="grow"><div>${esc(a.name)}</div>
|
||
<div class="sub">${esc(a.source)} · ${esc(a.source === 'local' ? a.path : a.id)}</div></div>
|
||
<button class="small ghost" data-rm="${esc(a.id)}">✕</button></div>`).join('') : '<p class="muted">Nichts ausgewählt.</p>';
|
||
syncCatalogChecks();
|
||
}
|
||
$('#selectedApps').onclick = e => { const id = e.target.dataset.rm; if (id) removeApp(id); };
|
||
async function doSearch() {
|
||
const q = $('#appSearch').value.trim(); if (!q) return;
|
||
$('#searchResults').innerHTML = '<p class="muted">Suche …</p>';
|
||
await guard(async () => {
|
||
const res = arr(await api('GET', `/api/winget/search?q=${encodeURIComponent(q)}&source=${$('#appSource').value}`));
|
||
$('#searchResults').innerHTML = res.length ? res.map((r, i) => `<div class="item"><div class="grow"><div>${esc(r.name)}</div>
|
||
<div class="sub">${esc(r.id)} · ${esc(r.version)}</div></div><button class="small" data-add="${i}">+ Hinzufügen</button></div>`).join('') : '<p class="muted">Keine Treffer.</p>';
|
||
$('#searchResults').onclick = e => { const i = e.target.dataset.add; if (i != null) { addApp(res[i]); e.target.textContent = '✓'; } };
|
||
});
|
||
}
|
||
$('#btnSearch').onclick = doSearch;
|
||
$('#appSearch').onkeydown = e => { if (e.key === 'Enter') doSearch(); };
|
||
$('#btnAddLocal').onclick = () => {
|
||
const f = $('#localFile').value; if (!f) return;
|
||
addApp({ name: f.split('\\').pop(), id: 'local:' + f, source: 'local', path: f, args: $('#localArgs').value });
|
||
};
|
||
$('#btnInstallApps').onclick = () => guard(async () => {
|
||
if (!S.apps.length) return toast('Keine Programme ausgewählt', true);
|
||
jobStarted((await api('POST', '/api/apps/install', { apps: S.apps })).job);
|
||
});
|
||
$('#btnUpgradeAll').onclick = $('#btnWingetUpg').onclick = () => guard(async () => jobStarted((await api('POST', '/api/apps/upgrade-all', {})).job));
|
||
|
||
// ---------------------------------------------------------------- Office
|
||
const PRODUCTS = [
|
||
{ id: 'O365ProPlusRetail', name: 'Microsoft 365 Apps for enterprise', channels: ['Current', 'MonthlyEnterprise', 'SemiAnnual', 'SemiAnnualPreview', 'BetaChannel'], extras: ['VisioProRetail', 'ProjectProRetail'] },
|
||
{ id: 'O365BusinessRetail', name: 'Microsoft 365 Apps for business', channels: ['Current', 'MonthlyEnterprise', 'SemiAnnual'], extras: ['VisioProRetail', 'ProjectProRetail'] },
|
||
{ id: 'ProPlus2024Volume', name: 'Office LTSC Professional Plus 2024 (Volumenlizenz)', channels: ['PerpetualVL2024'], extras: ['VisioPro2024Volume', 'ProjectPro2024Volume'] },
|
||
{ id: 'Standard2024Volume', name: 'Office LTSC Standard 2024 (Volumenlizenz)', channels: ['PerpetualVL2024'], extras: ['VisioStd2024Volume', 'ProjectStd2024Volume'] },
|
||
{ id: 'ProPlus2021Volume', name: 'Office LTSC Professional Plus 2021 (Volumenlizenz)', channels: ['PerpetualVL2021'], extras: ['VisioPro2021Volume', 'ProjectPro2021Volume'] },
|
||
{ id: 'HomeBusiness2024Retail', name: 'Office Home & Business 2024', channels: ['Current'], extras: [] },
|
||
{ id: 'Home2024Retail', name: 'Office Home 2024', channels: ['Current'], extras: [] }
|
||
];
|
||
const CHANNEL_NAMES = { Current: 'Aktueller Kanal', MonthlyEnterprise: 'Monatlicher Enterprise-Kanal', SemiAnnual: 'Halbjährlicher Enterprise-Kanal', SemiAnnualPreview: 'Halbjährlich (Vorschau)', BetaChannel: 'Beta', PerpetualVL2024: 'LTSC 2024', PerpetualVL2021: 'LTSC 2021' };
|
||
const OFFICE_APPS = [['Word', 'Word'], ['Excel', 'Excel'], ['PowerPoint', 'PowerPoint'], ['Outlook', 'Outlook (klassisch)'], ['OutlookForWindows', 'Outlook (neu)'], ['OneNote', 'OneNote'],
|
||
['Access', 'Access'], ['Publisher', 'Publisher'], ['Teams', 'Teams'], ['OneDrive', 'OneDrive'], ['Lync', 'Skype for Business'], ['Groove', 'OneDrive for Business (alt)'], ['Bing', 'Bing-Suche in Chrome']];
|
||
|
||
function renderOffice() {
|
||
$('#officeProduct').innerHTML = PRODUCTS.map(p => `<option value="${p.id}">${esc(p.name)}</option>`).join('');
|
||
$('#officeApps').innerHTML = OFFICE_APPS.map(([id, n]) => `<label><input type="checkbox" value="${id}"> ${n}</label>`).join('');
|
||
$('#officeProduct').value = S.office.product;
|
||
renderOfficeChannels(); renderOfficeExtras(); renderOfficeApps(); updateOfficeXml();
|
||
}
|
||
function renderOfficeChannels() {
|
||
const p = PRODUCTS.find(x => x.id === S.office.product) || PRODUCTS[0];
|
||
$('#officeChannel').innerHTML = p.channels.map(c => `<option value="${c}">${CHANNEL_NAMES[c] || c}</option>`).join('');
|
||
if (!p.channels.includes(S.office.channel)) S.office.channel = p.channels[0];
|
||
$('#officeChannel').value = S.office.channel;
|
||
S.office.extraProducts = arr(S.office.extraProducts).filter(e => p.extras.includes(e));
|
||
}
|
||
function renderOfficeExtras() {
|
||
const p = PRODUCTS.find(x => x.id === S.office.product) || PRODUCTS[0];
|
||
const label = e => `${e.startsWith('Visio') ? 'Visio' : 'Project'} ${/Std/.test(e) ? 'Standard' : 'Professional'} ${(e.match(/\d{4}/) || [''])[0]}`;
|
||
$('#officeExtras').innerHTML = p.extras.length ? p.extras.map(e => `<label><input type="checkbox" value="${e}" ${arr(S.office.extraProducts).includes(e) ? 'checked' : ''}> ${label(e)}</label>`).join('') : '<span class="muted small">keine für dieses Produkt</span>';
|
||
}
|
||
function renderOfficeApps() { $$('#officeApps input').forEach(i => i.checked = !arr(S.office.exclude).includes(i.value)); }
|
||
$('#officeApps').onchange = () => { S.office.exclude = $$('#officeApps input:not(:checked)').map(i => i.value); persist(); updateOfficeXml(); };
|
||
$('#officeExtras').onchange = () => { S.office.extraProducts = $$('#officeExtras input:checked').map(i => i.value); persist(); updateOfficeXml(); };
|
||
let xmlTimer;
|
||
function updateOfficeXml() {
|
||
clearTimeout(xmlTimer);
|
||
xmlTimer = setTimeout(() => guard(async () => { $('#officeXml').textContent = await api('POST', '/api/office/xml', S.office, true); }), 250);
|
||
}
|
||
$('#btnXmlDownload').onclick = () => download('configuration.xml', $('#officeXml').textContent, 'application/xml');
|
||
$('#btnXmlCopy').onclick = () => navigator.clipboard.writeText($('#officeXml').textContent).then(() => toast('XML kopiert'));
|
||
$('#btnOffice').onclick = () => guard(async () => {
|
||
jobStarted((await api('POST', '/api/office/install', { office: S.office, mode: S.officeMode, name: S.name })).job);
|
||
});
|
||
async function loadOfficeBuilds() {
|
||
const b = arr(await api('GET', '/api/office/configs').catch(() => []));
|
||
$('#officeBuilds').innerHTML = b.length ? 'Vorhandene Builds auf dem Stick: ' + b.map(esc).join(', ') : 'Noch kein Offline-Build auf dem Stick.';
|
||
}
|
||
|
||
// ---------------------------------------------------------------- Desktop-Icons
|
||
let presets = [];
|
||
function scFromForm() {
|
||
return { type: $('#scType').value, name: $('#scName').value.trim(), target: $('#scTarget').value.trim(), args: $('#scArgs').value, icon: $('#scIcon').value.trim() };
|
||
}
|
||
$('#scType').onchange = () => $$('.lnkonly').forEach(e => e.classList.toggle('hidden', $('#scType').value === 'url'));
|
||
$('#btnScCreate').onclick = () => guard(async () => {
|
||
const s = scFromForm(); if (!s.name || !s.target) return toast('Name und Ziel angeben', true);
|
||
await api('POST', '/api/shortcuts', s); toast('Verknüpfung angelegt'); loadShortcuts();
|
||
});
|
||
$('#btnScPlan').onclick = () => {
|
||
const s = scFromForm(); if (!s.name || !s.target) return toast('Name und Ziel angeben', true);
|
||
S.shortcuts = arr(S.shortcuts).filter(x => x.name !== s.name).concat(s); persist(); renderPlanned();
|
||
};
|
||
function renderPlanned() {
|
||
const l = arr(S.shortcuts);
|
||
$('#scPlanned').innerHTML = l.length ? l.map((s, i) => `<div class="item"><div class="grow"><div>${esc(s.name)}</div><div class="sub">${esc(s.target)}</div></div>
|
||
<button class="small ghost" data-i="${i}">✕</button></div>`).join('') : '<p class="muted">Keine geplant.</p>';
|
||
}
|
||
$('#scPlanned').onclick = e => { const i = e.target.dataset.i; if (i != null) { S.shortcuts.splice(i, 1); persist(); renderPlanned(); } };
|
||
$('#btnScApplyAll').onclick = () => guard(async () => {
|
||
for (const s of arr(S.shortcuts)) { try { await api('POST', '/api/shortcuts', s); } catch (e) { toast(`${s.name}: ${e.message}`, true); } }
|
||
toast('Verknüpfungen angelegt'); loadShortcuts();
|
||
});
|
||
async function loadShortcuts() {
|
||
const [cur, icons] = await Promise.all([api('GET', '/api/shortcuts'), api('GET', '/api/icons')]);
|
||
$('#scCurrent').innerHTML = arr(cur).length ? arr(cur).map(s => `<div class="item"><div class="grow"><div>${esc(s.name)}</div><div class="sub">${esc(s.target)}</div></div>
|
||
<button class="small danger" data-del="${esc(s.file)}">Löschen</button></div>`).join('') : '<p class="muted">Keine Verknüpfungen.</p>';
|
||
$('#iconList').innerHTML = arr(icons).map(i => `<option value="${esc(i)}">`).join('');
|
||
}
|
||
$('#scCurrent').onclick = e => {
|
||
const f = e.target.dataset.del; if (!f || !confirm(`"${f}" vom Desktop aller Benutzer löschen?`)) return;
|
||
guard(async () => { await api('DELETE', '/api/shortcuts?file=' + encodeURIComponent(f)); loadShortcuts(); });
|
||
};
|
||
$('#btnScRefresh').onclick = loadShortcuts;
|
||
$('#scPresets').onclick = e => {
|
||
const p = presets[e.target.dataset.p]; if (!p) return;
|
||
S.shortcuts = arr(S.shortcuts).filter(x => x.name !== p.name).concat({ ...p }); persist(); renderPlanned();
|
||
};
|
||
|
||
// ---------------------------------------------------------------- System / Sicherheit / Energie
|
||
$$('[data-run]').forEach(b => b.onclick = () => guard(async () => {
|
||
const k = b.dataset.run; jobStarted((await api('POST', '/api/' + k, { [k]: S[k] })).job);
|
||
}));
|
||
const ACTIONS = [['', 'unverändert'], ['nothing', 'Nichts unternehmen'], ['sleep', 'Energiesparmodus'], ['hibernate', 'Ruhezustand'], ['shutdown', 'Herunterfahren']];
|
||
$$('select.act').forEach(s => s.innerHTML = ACTIONS.map(([v, n]) => `<option value="${v}">${n}</option>`).join(''));
|
||
async function loadPower() { const p = await api('GET', '/api/power').catch(() => null); if (p) $('#powerState').textContent = 'Aktuell: ' + p.active; }
|
||
|
||
// ---------------------------------------------------------------- BitLocker
|
||
async function loadBitlocker() {
|
||
$('#blStatus').textContent = 'Lade …';
|
||
await guard(async () => {
|
||
const b = await api('GET', '/api/bitlocker');
|
||
let h = `<p class="small">${esc(b.edition)} · TPM: <b>${b.tpmPresent ? (b.tpmReady ? 'bereit' : 'nicht bereit') : 'nicht vorhanden'}</b></p>`;
|
||
if (!b.available) h += `<p style="color:var(--err)">${esc(b.message)}</p>`;
|
||
h += arr(b.volumes).map(v => `<div class="vol"><b>${esc(v.mount)}</b> <span class="muted small">${esc(v.type)}</span><br>
|
||
Status: ${esc(v.status)} · Schutz: <b style="color:${v.protection === 'On' ? 'var(--ok)' : 'var(--warn)'}">${esc(v.protection)}</b> · ${esc(v.method)}<br>
|
||
<span class="small muted">Schutzvorrichtungen: ${esc(arr(v.protectors).join(', ') || '–')}</span>
|
||
<div class="bar"><i style="width:${Number(v.percent) || 0}%"></i></div></div>`).join('');
|
||
$('#blStatus').innerHTML = h;
|
||
});
|
||
}
|
||
$('#btnBlRefresh').onclick = loadBitlocker;
|
||
$$('[data-bl]').forEach(b => b.onclick = () => guard(async () => {
|
||
const action = b.dataset.bl;
|
||
if (action === 'enable' && S.bitlocker.usePin && !/^\d{6,20}$/.test(S.bitlocker.pin || '')) return toast('PIN muss 6–20 Ziffern haben', true);
|
||
if (action === 'disable' && !confirm('BitLocker wirklich deaktivieren und das Laufwerk entschlüsseln?')) return;
|
||
jobStarted((await api('POST', '/api/bitlocker', { bitlocker: { ...S.bitlocker, action } })).job);
|
||
}));
|
||
|
||
// ---------------------------------------------------------------- Updates
|
||
let updates = [];
|
||
$$('[data-scan]').forEach(b => b.onclick = () => guard(async () => {
|
||
const type = b.dataset.scan;
|
||
const r = await api('POST', '/api/updates/scan', { type }); jobStarted(r.job, true);
|
||
$('#updList').innerHTML = '<p class="muted">Suche läuft … (kann einige Minuten dauern)</p>';
|
||
const j = await waitJob(r.job);
|
||
updates = arr(j.result);
|
||
$('#updCount').textContent = updates.length;
|
||
$('#updList').innerHTML = updates.length ? updates.map((u, i) => `<label class="item"><input type="checkbox" data-u="${i}" checked>
|
||
<div class="grow"><div>${esc(u.title)}</div><div class="sub">${u.type === 'Driver' ? 'Treiber' : 'Windows'} · ${esc(u.class)} ${u.kb ? '· KB' + esc(u.kb) : ''} · ${u.sizeMB} MB</div></div></label>`).join('')
|
||
: `<p class="muted">${j.state.startsWith('Fertig') ? 'Keine Updates gefunden – System ist aktuell.' : 'Suche fehlgeschlagen, siehe Aufgaben-Protokoll.'}</p>`;
|
||
}));
|
||
$('#btnUpdSel').onclick = () => guard(async () => {
|
||
const ids = $$('#updList input:checked').map(i => updates[i.dataset.u].id);
|
||
if (!ids.length) return toast('Nichts ausgewählt', true);
|
||
jobStarted((await api('POST', '/api/updates/install', { ids })).job);
|
||
});
|
||
$('#btnUpdAll').onclick = () => guard(async () => jobStarted((await api('POST', '/api/updates/install', { all: true, type: 'all' })).job));
|
||
$('#btnVendor').onclick = () => guard(async () => jobStarted((await api('POST', '/api/updates/vendor', {})).job));
|
||
$('#btnWinget').onclick = () => guard(async () => jobStarted((await api('POST', '/api/winget/install', {})).job));
|
||
$('#btnReboot').onclick = () => { if (confirm('Computer jetzt neu starten?')) guard(() => api('POST', '/api/reboot', {})); };
|
||
|
||
// ---------------------------------------------------------------- Profile
|
||
async function loadProfiles() {
|
||
const l = arr(await api('GET', '/api/profiles'));
|
||
$('#profileList').innerHTML = l.length ? l.map(n => `<div class="item"><div class="grow">${esc(n)}</div>
|
||
<button class="small primary" data-load="${esc(n)}">Laden</button><button class="small danger" data-pdel="${esc(n)}">✕</button></div>`).join('') : '<p class="muted">Keine Profile gespeichert.</p>';
|
||
}
|
||
$('#profileList').onclick = e => guard(async () => {
|
||
const { load, pdel } = e.target.dataset;
|
||
if (load) { loadState(await api('GET', '/api/profiles/' + encodeURIComponent(load))); toast(`Profil "${load}" geladen`); }
|
||
if (pdel && confirm(`Profil "${pdel}" löschen?`)) { await api('DELETE', '/api/profiles/' + encodeURIComponent(pdel)); loadProfiles(); }
|
||
});
|
||
$('#btnProfileSave').onclick = () => guard(async () => {
|
||
const n = $('#profileSaveName').value.trim().replace(/[^\w\-. ]/g, '_');
|
||
if (!n) return toast('Namen angeben', true);
|
||
S.name = n; persist();
|
||
await api('POST', '/api/profiles/' + encodeURIComponent(n), JSON.stringify(S, null, 2));
|
||
toast(`Profil "${n}" gespeichert`); fillForms(); loadProfiles();
|
||
});
|
||
$('#btnExport').onclick = () => download((S.name || 'profil') + '.json', JSON.stringify(S, null, 2), 'application/json');
|
||
$('#importFile').onchange = async e => { const f = e.target.files[0]; if (f) guard(async () => { loadState(JSON.parse(await f.text())); toast('Profil importiert'); }); e.target.value = ''; };
|
||
$('#btnReset').onclick = () => { if (confirm('Alle Einstellungen auf Standard zurücksetzen?')) loadState(DEFAULTS()); };
|
||
|
||
function download(name, text, type) {
|
||
const a = document.createElement('a'); a.href = URL.createObjectURL(new Blob([text], { type })); a.download = name; a.click();
|
||
setTimeout(() => URL.revokeObjectURL(a.href), 1000);
|
||
}
|
||
|
||
// ---------------------------------------------------------------- Aufgaben
|
||
let selJob = null, jobTimer = null, knownStates = {};
|
||
const stateClass = s => s === 'Laeuft' ? 'run' : s === 'Fertig' ? 'ok' : s.includes('Fehler') ? 'warn' : /Fehlg|Abgeb/.test(s) ? 'err' : '';
|
||
const stateName = s => s === 'Laeuft' ? 'Läuft' : s;
|
||
function jobStarted(id, quiet) {
|
||
if (!quiet) toast(`Aufgabe ${id} gestartet – zum Protokoll klicken`, false, () => { selJob = id; showTab('jobs'); });
|
||
selJob ??= id; pollJobs();
|
||
}
|
||
async function pollJobs() {
|
||
clearTimeout(jobTimer);
|
||
try {
|
||
const jobs = arr(await api('GET', '/api/jobs')).reverse();
|
||
const active = jobs.filter(j => j.state === 'Laeuft' || j.state === 'Wartet').length;
|
||
$('#jobBadge').textContent = active; $('#jobBadge').classList.toggle('hidden', !active);
|
||
for (const j of jobs) {
|
||
if (knownStates[j.id] && knownStates[j.id] !== j.state && !/Laeuft|Wartet/.test(j.state))
|
||
toast(`${j.title}: ${j.state}`, /Fehl|Abgeb/.test(j.state), () => { selJob = j.id; showTab('jobs'); });
|
||
knownStates[j.id] = j.state;
|
||
}
|
||
$('#jobList').innerHTML = jobs.length ? jobs.map(j => `<div class="item click ${j.id === selJob ? 'sel' : ''}" data-j="${j.id}">
|
||
<div class="grow"><div>${esc(j.title)}</div><div class="sub">#${j.id} · ${j.created}</div></div><span class="state ${stateClass(j.state)}">${esc(stateName(j.state))}</span></div>`).join('')
|
||
: '<p class="muted">Noch keine Aufgaben.</p>';
|
||
if (selJob && $('#tab-jobs').classList.contains('active')) {
|
||
const j = await api('GET', '/api/jobs/' + selJob);
|
||
$('#jobTitle').textContent = `#${j.id} ${j.title} – ${stateName(j.state)}`;
|
||
const pre = $('#jobLog'), atBottom = pre.scrollTop + pre.clientHeight >= pre.scrollHeight - 30;
|
||
pre.innerHTML = esc(j.log || '').replace(/^.*\[(ERROR|WARN|OK)\].*$/gm, (l, lv) => `<span class="${lv}">${l}</span>`);
|
||
if (atBottom) pre.scrollTop = pre.scrollHeight;
|
||
$('#btnJobStop').classList.toggle('hidden', !/Laeuft|Wartet/.test(j.state));
|
||
}
|
||
jobTimer = setTimeout(pollJobs, active ? 1500 : 5000);
|
||
} catch { jobTimer = setTimeout(pollJobs, 5000); }
|
||
}
|
||
$('#jobList').onclick = e => { const it = e.target.closest('[data-j]'); if (it) { selJob = it.dataset.j; pollJobs(); } };
|
||
$('#btnJobStop').onclick = () => { if (selJob && confirm('Aufgabe abbrechen?')) guard(async () => { await api('DELETE', '/api/jobs/' + selJob); pollJobs(); }); };
|
||
async function waitJob(id) {
|
||
for (; ;) {
|
||
await new Promise(r => setTimeout(r, 2000));
|
||
const j = await api('GET', '/api/jobs/' + id);
|
||
if (!/Laeuft|Wartet/.test(j.state)) return j;
|
||
}
|
||
}
|
||
|
||
$('#btnShutdown').onclick = () => { if (confirm('Agent beenden? Laufende Aufgaben werden abgebrochen.')) api('POST', '/api/shutdown', {}).finally(() => { document.body.innerHTML = '<main><h1>Agent beendet.</h1><p>Das Fenster kann geschlossen werden.</p></main>'; }); };
|
||
|
||
// ---------------------------------------------------------------- Start
|
||
function renderAll() { renderOffice(); renderSelectedApps(); renderPlanned(); renderSummary(); }
|
||
(async () => {
|
||
if (!TOKEN) { document.body.innerHTML = '<main><h1>Kein Zugriffstoken</h1><p>Bitte die vollständige URL (mit ?token=…) aus dem Agent-Fenster öffnen.</p></main>'; return; }
|
||
bindForms(); renderAll(); fillForms();
|
||
await guard(loadStatus);
|
||
await guard(loadCatalog);
|
||
await guard(async () => {
|
||
const p = await api('GET', '/api/presets');
|
||
presets = arr(p.shortcuts);
|
||
$('#scPresets').innerHTML = presets.map((s, i) => `<button data-p="${i}">+ ${esc(s.name)}</button>`).join('');
|
||
$('#tzSelect').insertAdjacentHTML('beforeend', arr(p.timezones).map(t => `<option value="${esc(t.id)}">${esc(t.name)}</option>`).join(''));
|
||
fillForms();
|
||
});
|
||
if (location.hash) showTab(location.hash.slice(1));
|
||
pollJobs();
|
||
})();
|