'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}
${esc(s.build)}`], ['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' : 'fehlt – wird automatisch installiert'], ['Akku', s.battery || '–'], ['Agent-Pfad', s.root]]; $('#sysinfo').innerHTML = items.map(([k, v]) => `
${k}
${/<|&/.test(v) && k !== 'Seriennummer' ? v : esc(v)}
`).join(''); } function renderSummary() { const o = S.office, prod = PRODUCTS.find(p => p.id === o.product); $('#summary').innerHTML = [ `${arr(S.apps).length} Programme`, `Office: ${esc(prod?.name || o.product)} (${o.arch}-Bit, ${esc(S.officeMode)})`, `${arr(S.shortcuts).length} Desktop-Icons`, `Energieplan: ${esc(S.power.plan || 'unverändert')}`, S.system.computerName ? `Neuer Name: ${esc(S.system.computerName)}` : '' ].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]) => `

${esc(c)}

${list.map(a => ``).join('')}
`).join(''); syncCatalogChecks(); const local = arr(await api('GET', '/api/local-installers')); $('#localFile').innerHTML = local.length ? local.map(f => ``).join('') : ''; } $('#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 => `
${esc(a.name)}
${esc(a.source)} · ${esc(a.source === 'local' ? a.path : a.id)}
`).join('') : '

Nichts ausgewählt.

'; 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 = '

Suche …

'; 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) => `
${esc(r.name)}
${esc(r.id)} · ${esc(r.version)}
`).join('') : '

Keine Treffer.

'; $('#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 => ``).join(''); $('#officeApps').innerHTML = OFFICE_APPS.map(([id, n]) => ``).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 => ``).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 => ``).join('') : 'keine für dieses Produkt'; } 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) => `
${esc(s.name)}
${esc(s.target)}
`).join('') : '

Keine geplant.

'; } $('#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 => `
${esc(s.name)}
${esc(s.target)}
`).join('') : '

Keine Verknüpfungen.

'; $('#iconList').innerHTML = arr(icons).map(i => ``).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 = `

${esc(b.edition)} · TPM: ${b.tpmPresent ? (b.tpmReady ? 'bereit' : 'nicht bereit') : 'nicht vorhanden'}

`; if (!b.available) h += `

${esc(b.message)}

`; h += arr(b.volumes).map(v => `
${esc(v.mount)} ${esc(v.type)}
Status: ${esc(v.status)} · Schutz: ${esc(v.protection)} · ${esc(v.method)}
Schutzvorrichtungen: ${esc(arr(v.protectors).join(', ') || '–')}
`).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 = '

Suche läuft … (kann einige Minuten dauern)

'; const j = await waitJob(r.job); updates = arr(j.result); $('#updCount').textContent = updates.length; $('#updList').innerHTML = updates.length ? updates.map((u, i) => ``).join('') : `

${j.state.startsWith('Fertig') ? 'Keine Updates gefunden – System ist aktuell.' : 'Suche fehlgeschlagen, siehe Aufgaben-Protokoll.'}

`; })); $('#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 => `
${esc(n)}
`).join('') : '

Keine Profile gespeichert.

'; } $('#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 => `
${esc(j.title)}
#${j.id} · ${j.created}
${esc(stateName(j.state))}
`).join('') : '

Noch keine Aufgaben.

'; 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) => `${l}`); 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 = '

Agent beendet.

Das Fenster kann geschlossen werden.

'; }); }; // ---------------------------------------------------------------- Start function renderAll() { renderOffice(); renderSelectedApps(); renderPlanned(); renderSummary(); } (async () => { if (!TOKEN) { document.body.innerHTML = '

Kein Zugriffstoken

Bitte die vollständige URL (mit ?token=…) aus dem Agent-Fenster öffnen.

'; 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) => ``).join(''); $('#tzSelect').insertAdjacentHTML('beforeend', arr(p.timezones).map(t => ``).join('')); fillForms(); }); if (location.hash) showTab(location.hash.slice(1)); pollJobs(); })();