'use strict'; const $ = id => document.getElementById(id); const isDSM = location.pathname === '/dsm'; $('home').hidden = isDSM; $('dsm').hidden = !isDSM; $(isDSM ? 'dsm-nav' : 'home-nav').classList.add('active'); $('breadcrumb').textContent = isDSM ? 'DSM' : 'Übersicht'; let token = '', demo = false, busy = false, restarting = false, canRestart = false; const history = {down: [], up: []}; const number = n => n.toLocaleString('de-DE', {maximumFractionDigits: 1}); const bytes = n => {if(n == null) return '—'; const unit = n >= 2**40 ? [2**40,'TiB'] : n >= 2**30 ? [2**30,'GiB'] : n >= 2**20 ? [2**20,'MiB'] : [1024,'KiB']; return `${number(n/unit[0])} ${unit[1]}`;}; const escape = s => String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); function fixture(){return {cpu:18.4,ram:{total:8*2**30,free:5.2*2**30},interfaces:[{name:'eth0',status:'up',down:24.8*2**20,up:6.3*2**20},{name:'eth1',status:'down',down:0,up:0}],pools:[{name:'vg1000',total:32*2**40,free:4*2**40}],volumes:[{name:'/volume1',total:28*2**40,free:12.6*2**40}],raids:[{name:'md2',level:'raid6',status:'OK',action:'idle'}],disks:Array.from({length:8},(_,i)=>({name:`sata${i+1}`,model:'Beispiellaufwerk · 8 TB',status:'OK',temperature:32+i%4})),dns:'Demo · Läuft',timestamp:Date.now()/1000,storage_age:0};} function chart(key, color){const c=$(key+'-chart'),ctx=c.getContext('2d'),arr=history[key];ctx.clearRect(0,0,c.width,c.height); if(arr.length<2)return;const max=Math.max(...arr,1);ctx.beginPath();arr.forEach((v,i)=>{const x=i*300/59,y=44-v/max*38;i?ctx.lineTo(x,y):ctx.moveTo(x,y);});ctx.strokeStyle=color;ctx.lineWidth=2;ctx.stroke();} function render(d){ $('cpu').textContent=d.cpu==null?'—':number(d.cpu)+' %';$('cpu-bar').value=d.cpu||0; const ram=d.ram.total&&d.ram.free!=null?100*(1-d.ram.free/d.ram.total):null; $('ram').textContent=ram==null?'—':number(ram)+' %';$('ram-bar').value=ram||0; $('ram-detail').textContent=ram==null?'Nicht verfügbar':`${bytes(d.ram.total-d.ram.free)} von ${bytes(d.ram.total)}`; for(const [key,id,color] of [['down','download','#65dfb3'],['up','upload','#80b6ff']]){const measured=d.interfaces.filter(n=>n[key]!=null);const sum=measured.length?measured.reduce((a,n)=>a+n[key],0):null;$(id).textContent=sum==null?'—':bytes(sum)+'/s';if(sum!=null){history[key].push(sum);if(history[key].length>60)history[key].shift();}chart(key,color);} $('network').innerHTML=d.interfaces.map(n=>`
Keine physischen Schnittstellen verfügbar.
'; $('storage').innerHTML=[...d.pools.map(p=>({...p,label:'Pool / LVM'})),...d.volumes.map(p=>({...p,label:'Volume'}))].map(p=>`Pool-Kapazität nicht verfügbar.
')+d.raids.map(r=>`${escape(r.name)} · ${escape(r.level)} · ${escape(r.status)} · ${escape(r.action)}
`).join(''); $('disks').innerHTML=d.disks.map(x=>`