Enforce customer boundaries on token administration and finalize fleet navigation
This commit is contained in:
+558
-99
@@ -1,5 +1,16 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { objectId, page, pretty, record, request, session, tenantPath, type RecordValue, type Session, type Tenant } from './api';
|
||||
import {
|
||||
objectId,
|
||||
page,
|
||||
pretty,
|
||||
record,
|
||||
request,
|
||||
session,
|
||||
tenantPath,
|
||||
type RecordValue,
|
||||
type Session,
|
||||
type Tenant
|
||||
} from './api';
|
||||
import { AdminControl } from './management';
|
||||
import { allowed } from './safety';
|
||||
import { CatalogCheckNotice } from './catalog-check';
|
||||
@@ -14,130 +25,578 @@ import { SystemNonstartReview } from './system-nonstart-review';
|
||||
const unknown = 'Nicht gemeldet';
|
||||
const number = new Intl.NumberFormat('de-DE', { maximumFractionDigits: 1 });
|
||||
const date = new Intl.DateTimeFormat('de-DE', { dateStyle: 'medium', timeStyle: 'short' });
|
||||
function label(value: unknown) { return typeof value === 'string' && value.trim() ? value : unknown; }
|
||||
function label(value: unknown) {
|
||||
return typeof value === 'string' && value.trim() ? value : unknown;
|
||||
}
|
||||
function time(value: unknown) {
|
||||
const t = typeof value === 'string' ? Date.parse(value) : NaN;
|
||||
return Number.isFinite(t) ? date.format(t) : unknown;
|
||||
}
|
||||
function gib(v: unknown) { return typeof v === 'number' && Number.isFinite(v) && v >= 0 ? number.format(v / 2 ** 30) : null; }
|
||||
function gib(v: unknown) {
|
||||
return typeof v === 'number' && Number.isFinite(v) && v >= 0 ? number.format(v / 2 ** 30) : null;
|
||||
}
|
||||
function capacity(free: unknown, total: unknown) {
|
||||
const f = gib(free), t = gib(total);
|
||||
const f = gib(free),
|
||||
t = gib(total);
|
||||
return f === null && t === null ? unknown : `${f ?? '–'} / ${t ?? '–'} GiB`;
|
||||
}
|
||||
function cpu(d: RecordValue) {
|
||||
const model = label(d.cpu_model), count = d.cpu_logical_count;
|
||||
const threads = typeof count === 'number' && count > 0 ? `${count} log. CPU${count === 1 ? '' : 's'}` : '';
|
||||
return { primary: model === unknown ? threads || unknown : model, secondary: model === unknown ? '' : threads };
|
||||
const model = label(d.cpu_model),
|
||||
count = d.cpu_logical_count;
|
||||
const threads =
|
||||
typeof count === 'number' && count > 0 ? `${count} log. CPU${count === 1 ? '' : 's'}` : '';
|
||||
return {
|
||||
primary: model === unknown ? threads || unknown : model,
|
||||
secondary: model === unknown ? '' : threads
|
||||
};
|
||||
}
|
||||
const states: Record<string,string> = { online: 'Online', offline: 'Offline', never_seen: 'Ohne Erstkontakt', revoked: 'Widerrufen', archived: 'Archiviert', replaced: 'Ersetzt', unverified: 'Identität unbestätigt' };
|
||||
const states: Record<string, string> = {
|
||||
online: 'Online',
|
||||
offline: 'Offline',
|
||||
never_seen: 'Ohne Erstkontakt',
|
||||
revoked: 'Widerrufen',
|
||||
archived: 'Archiviert',
|
||||
replaced: 'Ersetzt',
|
||||
unverified: 'Identität unbestätigt'
|
||||
};
|
||||
function Presence({ d }: { d: RecordValue }) {
|
||||
const state = typeof d.lifecycle === 'string' && d.lifecycle !== 'current' ? d.lifecycle : String(d.status);
|
||||
return <span className={'presence ' + (state === 'online' ? 'online' : state === 'offline' ? 'offline' : 'historic')}><i/>{states[state] ?? 'Unbekannt'}</span>;
|
||||
const state =
|
||||
typeof d.lifecycle === 'string' && d.lifecycle !== 'current' ? d.lifecycle : String(d.status);
|
||||
return (
|
||||
<span
|
||||
className={
|
||||
'presence ' + (state === 'online' ? 'online' : state === 'offline' ? 'offline' : 'historic')
|
||||
}
|
||||
>
|
||||
<i />
|
||||
{states[state] ?? 'Unbekannt'}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
function Storage({ d }: { d: RecordValue }) {
|
||||
const free = d.disk_free_bytes, total = d.disk_total_bytes;
|
||||
return <><span>{capacity(free,total)}</span>{typeof free === 'number' && typeof total === 'number' && free >= 0 && free <= total && total > 0 &&
|
||||
<span className="capacity-track" title={`${number.format(100*free/total)} % frei`} aria-hidden="true"><i style={{ width: `${100*(total-free)/total}%` }}/></span>}</>;
|
||||
const free = d.disk_free_bytes,
|
||||
total = d.disk_total_bytes;
|
||||
return (
|
||||
<>
|
||||
<span>{capacity(free, total)}</span>
|
||||
{typeof free === 'number' &&
|
||||
typeof total === 'number' &&
|
||||
free >= 0 &&
|
||||
free <= total &&
|
||||
total > 0 && (
|
||||
<span
|
||||
className="capacity-track"
|
||||
title={`${number.format((100 * free) / total)} % frei`}
|
||||
aria-hidden="true"
|
||||
>
|
||||
<i style={{ width: `${(100 * (total - free)) / total}%` }} />
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
type Target = { customer: string; ids: string[] };
|
||||
type Props = {
|
||||
auth: Session; customers: Tenant[]; filter: string; onFilter: (id: string) => void;
|
||||
selection: Target; onSelection: (s: Target) => void;
|
||||
onScripts: () => void; onEnroll: () => void; onOperation: (customer: string, id: string) => void;
|
||||
detailPath: string;
|
||||
auth: Session;
|
||||
customers: Tenant[];
|
||||
filter: string;
|
||||
onFilter: (id: string) => void;
|
||||
selection: Target;
|
||||
onSelection: (s: Target) => void;
|
||||
onScripts: () => void;
|
||||
onEnroll: () => void;
|
||||
onOperation: (customer: string, id: string) => void;
|
||||
};
|
||||
function devicePath(customer: string, asset: string) { return tenantPath(customer, '/devices/' + encodeURIComponent(asset)); }
|
||||
function devicePath(customer: string, asset: string) {
|
||||
return tenantPath(customer, '/devices/' + encodeURIComponent(asset));
|
||||
}
|
||||
|
||||
function DeviceDetail({ customer, asset, agent, auth, back, openOperation, changed }: {
|
||||
customer: string; asset: string; agent: string; auth: Session; back: () => void;
|
||||
openOperation: (id: string) => void; changed: () => void;
|
||||
function DeviceDetail({
|
||||
customer,
|
||||
asset,
|
||||
agent,
|
||||
auth,
|
||||
back,
|
||||
openOperation,
|
||||
changed
|
||||
}: {
|
||||
customer: string;
|
||||
asset: string;
|
||||
agent: string;
|
||||
auth: Session;
|
||||
back: () => void;
|
||||
openOperation: (id: string) => void;
|
||||
changed: () => void;
|
||||
}) {
|
||||
const path = devicePath(customer, asset);
|
||||
const detail = useResource(async signal => record(await request(path+'?agent_id='+encodeURIComponent(agent), { signal })), [customer,asset,agent], true);
|
||||
const membership = useResource(async signal => session(await request('/auth/session', { signal, tenantId: customer })), [customer,auth.principal.id]);
|
||||
const [busy, setBusy] = useState(false), [error, setError] = useState<string|null>(null);
|
||||
const detail = useResource(
|
||||
async (signal) => record(await request(path + '?agent_id=' + encodeURIComponent(agent), { signal })),
|
||||
[customer, asset, agent],
|
||||
true
|
||||
);
|
||||
const membership = useResource(
|
||||
async (signal) => session(await request('/auth/session', { signal, tenantId: customer })),
|
||||
[customer, auth.principal.id]
|
||||
);
|
||||
const [busy, setBusy] = useState(false),
|
||||
[error, setError] = useState<string | null>(null);
|
||||
const d = detail.data;
|
||||
const scoped = membership.data;
|
||||
const volumes = Array.isArray(d?.volumes) ? d.volumes.map(v=>record(v)) : [];
|
||||
const jobs = Array.isArray(d?.recent_jobs) ? d.recent_jobs.map(v=>record(v)) : null;
|
||||
const volumes = Array.isArray(d?.volumes) ? d.volumes.map((v) => record(v)) : [];
|
||||
const jobs = Array.isArray(d?.recent_jobs) ? d.recent_jobs.map((v) => record(v)) : null;
|
||||
const facts = d && [
|
||||
['Kunde', label(d.customer_name)], ['Betriebssystem',label(d.os)], ['RAM', gib(d.ram_total_bytes) === null ? unknown : gib(d.ram_total_bytes)+' GiB'],
|
||||
['CPU',[cpu(d).primary,cpu(d).secondary].filter(Boolean).join(' · ')], ['Speicher frei / gesamt',capacity(d.disk_free_bytes,d.disk_total_bytes)],
|
||||
['Letzter Kontakt',time(d.last_contact_at)], ['Inventar erhoben',time(d.observed_at)], ['Agentversion',label(d.agent_version)]
|
||||
['Kunde', label(d.customer_name)],
|
||||
['Betriebssystem', label(d.os)],
|
||||
['RAM', gib(d.ram_total_bytes) === null ? unknown : gib(d.ram_total_bytes) + ' GiB'],
|
||||
['CPU', [cpu(d).primary, cpu(d).secondary].filter(Boolean).join(' · ')],
|
||||
['Speicher frei / gesamt', capacity(d.disk_free_bytes, d.disk_total_bytes)],
|
||||
['Letzter Kontakt', time(d.last_contact_at)],
|
||||
['Inventar erhoben', time(d.observed_at)],
|
||||
['Agentversion', label(d.agent_version)]
|
||||
];
|
||||
return <div className="device-detail">
|
||||
<button className="quiet" onClick={back}><NavIcon name="zurueck"/> Zur Geräteliste</button>
|
||||
<ErrorBox error={detail.error ?? membership.error ?? error}/>
|
||||
{!d && !detail.error && <p>Inventar wird geladen …</p>}
|
||||
{d && <><div className="page-title"><div><h1>{label(d.hostname)}</h1><Presence d={d}/></div></div>
|
||||
<section><h2>Geräteinformationen</h2><dl className="facts">{facts?.map(([k,v])=><div key={k}><dt>{k}</dt><dd>{v}</dd></div>)}</dl></section>
|
||||
{volumes.length > 0 && <section><h2>Laufwerke</h2><div className="table"><table><thead><tr><th>Laufwerk</th><th>Speicher frei / gesamt</th></tr></thead><tbody>{volumes.map((v,i)=><tr key={i}><td>{label(v.name)}</td><td>{capacity(v.free_bytes,v.total_bytes)}</td></tr>)}</tbody></table></div></section>}
|
||||
{jobs && <section><h2>Letzte Aufträge</h2>{jobs.length === 0 ? <p className="muted">Keine Aufträge für dieses Gerät.</p> : <ul className="job-list">{jobs.map(j=><li key={objectId(j,'job')}><button className="link" onClick={()=>openOperation(objectId(j,'operation'))}>Auftrag vom {time(j.created_at)}</button><span>{label(j.state)}</span></li>)}</ul>}</section>}
|
||||
<section><details><summary>Technische Daten</summary><CatalogCheckNotice device={d}/><pre aria-label="Vollständiges Geräteinventar">{pretty(d)}</pre></details>
|
||||
{scoped && allowed(scoped,'devices:revoke') && <details><summary>Gerät verwalten</summary>
|
||||
{['archived','current'].includes(String(d.lifecycle)) && <button disabled={busy} onClick={async()=>{
|
||||
setBusy(true);setError(null);
|
||||
try { await request(path+'/archive',{csrf:scoped.csrf_token,body:{archived:d.lifecycle!=='archived'}});changed(); }
|
||||
catch(e){ setError(errorText(e)); } finally{ setBusy(false); }
|
||||
}}>{d.lifecycle==='archived' ? 'Zurück in den Bestand' : 'In die Historie verschieben'}</button>}
|
||||
{d.lifecycle==='current' && <AdminControl auth={scoped} path={path+'/revocation'} permission="devices:revoke" title="Geräteidentität widerrufen" warning="Der Widerruf unterbricht die Geräteverwaltung und sperrt neue Starts. Die Wiederaufnahme erfordert eine neue Registrierung." done={changed}/>}
|
||||
</details>}</section>
|
||||
{scoped && customer===recoveryTenant && asset===recoveryAsset && allowed(scoped,'inventory:read') && <details><summary>Entwicklungsabnahmen</summary><SystemNonstartReview auth={scoped}/><SyncAlignmentReview auth={scoped}/><EchoProbeReview auth={scoped}/><EchoCompletionReview auth={scoped}/><RecoveryReview auth={scoped}/></details>}
|
||||
</>}
|
||||
</div>;
|
||||
return (
|
||||
<div className="device-detail">
|
||||
<button className="quiet" onClick={back}>
|
||||
<NavIcon name="zurueck" /> Zur Geräteliste
|
||||
</button>
|
||||
<ErrorBox error={detail.error ?? membership.error ?? error} />
|
||||
{!d && !detail.error && <p>Inventar wird geladen …</p>}
|
||||
{d && (
|
||||
<>
|
||||
<div className="page-title">
|
||||
<div>
|
||||
<h1>{label(d.hostname)}</h1>
|
||||
<Presence d={d} />
|
||||
</div>
|
||||
</div>
|
||||
<section>
|
||||
<h2>Geräteinformationen</h2>
|
||||
<dl className="facts">
|
||||
{facts?.map(([k, v]) => (
|
||||
<div key={k}>
|
||||
<dt>{k}</dt>
|
||||
<dd>{v}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</section>
|
||||
{volumes.length > 0 && (
|
||||
<section>
|
||||
<h2>Laufwerke</h2>
|
||||
<div className="table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Laufwerk</th>
|
||||
<th>Speicher frei / gesamt</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{volumes.map((v, i) => (
|
||||
<tr key={i}>
|
||||
<td>{label(v.name)}</td>
|
||||
<td>{capacity(v.free_bytes, v.total_bytes)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
{jobs && (
|
||||
<section>
|
||||
<h2>Letzte Aufträge</h2>
|
||||
{jobs.length === 0 ? (
|
||||
<p className="muted">Keine Aufträge für dieses Gerät.</p>
|
||||
) : (
|
||||
<ul className="job-list">
|
||||
{jobs.map((j) => (
|
||||
<li key={objectId(j, 'job')}>
|
||||
<button className="link" onClick={() => openOperation(objectId(j, 'operation'))}>
|
||||
Auftrag vom {time(j.created_at)}
|
||||
</button>
|
||||
<span>{label(j.state)}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
<section>
|
||||
<details>
|
||||
<summary>Technische Daten</summary>
|
||||
<CatalogCheckNotice device={d} />
|
||||
<pre aria-label="Vollständiges Geräteinventar">{pretty(d)}</pre>
|
||||
</details>
|
||||
{scoped && allowed(scoped, 'devices:revoke') && (
|
||||
<details>
|
||||
<summary>Gerät verwalten</summary>
|
||||
{['archived', 'current'].includes(String(d.lifecycle)) && (
|
||||
<button
|
||||
disabled={busy}
|
||||
onClick={async () => {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await request(path + '/archive', {
|
||||
csrf: scoped.csrf_token,
|
||||
body: { archived: d.lifecycle !== 'archived' }
|
||||
});
|
||||
changed();
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{d.lifecycle === 'archived'
|
||||
? 'Zurück in den Bestand'
|
||||
: 'In die Historie verschieben'}
|
||||
</button>
|
||||
)}
|
||||
{d.lifecycle === 'current' && (
|
||||
<AdminControl
|
||||
auth={scoped}
|
||||
path={path + '/revocation'}
|
||||
permission="devices:revoke"
|
||||
title="Geräteidentität widerrufen"
|
||||
warning="Der Widerruf unterbricht die Geräteverwaltung und sperrt neue Starts. Die Wiederaufnahme erfordert eine neue Registrierung."
|
||||
done={changed}
|
||||
/>
|
||||
)}
|
||||
</details>
|
||||
)}
|
||||
</section>
|
||||
{scoped &&
|
||||
customer === recoveryTenant &&
|
||||
asset === recoveryAsset &&
|
||||
allowed(scoped, 'inventory:read') && (
|
||||
<details>
|
||||
<summary>Entwicklungsabnahmen</summary>
|
||||
<SystemNonstartReview auth={scoped} />
|
||||
<SyncAlignmentReview auth={scoped} />
|
||||
<EchoProbeReview auth={scoped} />
|
||||
<EchoCompletionReview auth={scoped} />
|
||||
<RecoveryReview auth={scoped} />
|
||||
</details>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function Devices({ auth, customers, filter, onFilter, selection, onSelection, onEnroll, onScripts, onOperation }: Props) {
|
||||
const [search,setSearch]=useState(''), [query,setQuery]=useState(''), [status,setStatus]=useState(''), [history,setHistory]=useState(false);
|
||||
const [routes,setRoutes]=useState<string[]>([]), [target,setTarget]=useState<{customer:string;asset:string;agent:string}|null>(null);
|
||||
const cursor=routes[routes.length-1];
|
||||
useEffect(()=>{ const timer=setTimeout(()=>{ setQuery(search.trim());setRoutes([]); },200);return ()=>clearTimeout(timer); },[search]);
|
||||
const list=useResource(async signal=>{
|
||||
if(target) return null;
|
||||
const params=new URLSearchParams({view:history?'history':'current',limit:'40'});
|
||||
if(query) params.set('q',query);if(status && !history) params.set('status',status);if(cursor) params.set('cursor',cursor);
|
||||
const path=filter?tenantPath(filter,'/devices'):'/api/v1/devices';
|
||||
return page(await request(path+'?'+params, {signal}));
|
||||
},[filter,query,history,status,cursor,target],true);
|
||||
function setView(historic:boolean){setRoutes([]);setHistory(historic);onSelection({customer:'',ids:[]});}
|
||||
function select(d:RecordValue,checked:boolean) {
|
||||
const asset=objectId(d,'asset'),customer=objectId(d,'tenant');
|
||||
if(checked && selection.ids.length && customer!==selection.customer) return;
|
||||
const ids=checked?[...selection.ids,asset]:selection.ids.filter(id=>id!==asset);
|
||||
onSelection({ customer:ids.length?customer:'',ids });
|
||||
export function Devices({
|
||||
detailPath,
|
||||
auth,
|
||||
customers,
|
||||
filter,
|
||||
onFilter,
|
||||
selection,
|
||||
onSelection,
|
||||
onEnroll,
|
||||
onScripts,
|
||||
onOperation
|
||||
}: Props) {
|
||||
const [search, setSearch] = useState(''),
|
||||
[query, setQuery] = useState(''),
|
||||
[status, setStatus] = useState(''),
|
||||
[history, setHistory] = useState(false);
|
||||
const [routes, setRoutes] = useState<string[]>([]);
|
||||
const [customerId, assetId, agentId] = detailPath.split('/');
|
||||
const target =
|
||||
customerId && assetId && agentId ? { customer: customerId, asset: assetId, agent: agentId } : null;
|
||||
const back = () => {
|
||||
window.location.hash = 'geraete';
|
||||
};
|
||||
const cursor = routes[routes.length - 1];
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
setQuery(search.trim());
|
||||
setRoutes([]);
|
||||
}, 200);
|
||||
return () => clearTimeout(timer);
|
||||
}, [search]);
|
||||
const list = useResource(
|
||||
async (signal) => {
|
||||
if (target) return null;
|
||||
const params = new URLSearchParams({ view: history ? 'history' : 'current', limit: '40' });
|
||||
if (query) params.set('q', query);
|
||||
if (status && !history) params.set('status', status);
|
||||
if (cursor) params.set('cursor', cursor);
|
||||
const path = filter ? tenantPath(filter, '/devices') : '/api/v1/devices';
|
||||
return page(await request(path + '?' + params, { signal }));
|
||||
},
|
||||
[filter, query, history, status, cursor, detailPath],
|
||||
true
|
||||
);
|
||||
function setView(historic: boolean) {
|
||||
setRoutes([]);
|
||||
setHistory(historic);
|
||||
onSelection({ customer: '', ids: [] });
|
||||
}
|
||||
if(target) return <DeviceDetail key={target.agent} {...target} auth={auth} back={()=>setTarget(null)} openOperation={id=>onOperation(target.customer,id)}
|
||||
changed={()=>{setTarget(null);setRoutes([]);onSelection({customer:'',ids:[]});list.reload();}}/>;
|
||||
return <>
|
||||
<div className="page-title"><div><h1>Geräte</h1></div>{allowed(auth,'devices:enroll') && <button className="primary" onClick={onEnroll}><NavIcon name="plus"/> Gerät aufnehmen</button>}</div>
|
||||
<section className="fleet" aria-label="Gerätebestand">
|
||||
<div className="fleet-tabs"><button aria-pressed={!history} onClick={()=>{if(history)setView(false);}}>Bestand</button><button aria-pressed={history} onClick={()=>{if(!history)setView(true);}}>Historie</button></div>
|
||||
<div className="filters"><label className="search-box"><span className="sr-only">Hostname suchen</span><NavIcon name="suchen"/><input type="search" placeholder="Hostname suchen …" maxLength={120} value={search} onChange={e=>setSearch(e.target.value)}/></label>
|
||||
<label><span>Kunde</span><select value={filter} onChange={e=>{setRoutes([]);onFilter(e.target.value);}}><option value="">Alle Kunden</option>{customers.map(c=><option value={c.tenant_id} key={c.tenant_id}>{c.name}</option>)}</select></label>
|
||||
{!history && <label><span>Status</span><select value={status} onChange={e=>{setRoutes([]);setStatus(e.target.value);}}><option value="">Jeder Status</option><option value="online">Online</option><option value="offline">Offline</option></select></label>}
|
||||
function select(d: RecordValue, checked: boolean) {
|
||||
const asset = objectId(d, 'asset'),
|
||||
customer = objectId(d, 'tenant');
|
||||
if (checked && selection.ids.length && customer !== selection.customer) return;
|
||||
const ids = checked ? [...selection.ids, asset] : selection.ids.filter((id) => id !== asset);
|
||||
onSelection({ customer: ids.length ? customer : '', ids });
|
||||
}
|
||||
if (target)
|
||||
return (
|
||||
<DeviceDetail
|
||||
key={target.agent}
|
||||
{...target}
|
||||
auth={auth}
|
||||
back={back}
|
||||
openOperation={(id) => onOperation(target.customer, id)}
|
||||
changed={() => {
|
||||
back();
|
||||
setRoutes([]);
|
||||
onSelection({ customer: '', ids: [] });
|
||||
list.reload();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<div className="page-title">
|
||||
<div>
|
||||
<h1>Geräte</h1>
|
||||
</div>
|
||||
{allowed(auth, 'devices:enroll') && (
|
||||
<button className="primary" onClick={onEnroll}>
|
||||
<NavIcon name="plus" /> Gerät aufnehmen
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<ErrorBox error={list.error}/>
|
||||
{history && <p className="history-hint">Ausgemusterte Geräte und Registrierungen ohne bestätigte Identität.</p>}
|
||||
{!list.data && !list.error && <p className="list-message">Geräte werden geladen …</p>}
|
||||
{list.data && <><div className="table fleet-table"><table><thead><tr>{!history && <th className="target-col"><span className="sr-only">Ziel auswählen</span></th>}{['Hostname','OS','Status','Speicher frei / gesamt','RAM','CPU','Kunde'].map(h=><th scope="col" key={h}>{h}</th>)}</tr></thead>
|
||||
<tbody>{list.data.items.map(d=>{
|
||||
const asset=objectId(d,'asset'), agent=objectId(d,'agent'),customer=objectId(d,'tenant'),model=cpu(d);
|
||||
const show=()=>setTarget({asset,agent,customer});
|
||||
const another=selection.ids.length>0 && selection.customer!==customer;
|
||||
return <tr key={agent} onClick={show}>
|
||||
{!history && <td className="target-col" onClick={e=>e.stopPropagation()}><input type="checkbox" aria-label={'Ziel '+asset} title={another?'Aufträge werden je Kunde geplant':'Für Auftrag auswählen'} disabled={another} checked={selection.customer===customer && selection.ids.includes(asset)} onChange={e=>select(d,e.target.checked)}/></td>}
|
||||
<td className="hostname"><button className="host-link" onClick={e=>{e.stopPropagation();show();}}>{label(d.hostname)}</button></td>
|
||||
<td data-label="OS">{label(d.os)}</td><td data-label="Status" className="device-presence"><Presence d={d}/>{d.status==='offline' && d.lifecycle==='current' && <small>Zuletzt {time(d.last_contact_at)}</small>}</td>
|
||||
<td data-label="Speicher frei / gesamt" className="storage"><Storage d={d}/></td><td data-label="RAM">{gib(d.ram_total_bytes)===null?unknown:gib(d.ram_total_bytes)+' GiB'}</td>
|
||||
<td data-label="CPU">{model.primary}{model.secondary && <small>{model.secondary}</small>}</td><td data-label="Kunde">{label(d.customer_name)}</td>
|
||||
</tr>;
|
||||
})}</tbody></table></div>
|
||||
{!list.data.items.length && <div className="empty-list"><NavIcon name="geraete"/><h3>{query||filter||status?'Keine passenden Geräte':'Keine Geräte in dieser Ansicht'}</h3>{(query||filter||status) && <button className="quiet" onClick={()=>{setSearch('');setQuery('');setRoutes([]);setStatus('');onFilter('');}}>Filter zurücksetzen</button>}</div>}
|
||||
<div className="list-footer"><span>{list.data.items.length} {list.data.items.length===1?'Gerät':'Geräte'}{cursor||list.data.next_cursor?' auf dieser Seite':''} · Stand {time(list.data.as_of)}</span>
|
||||
{(cursor||list.data.next_cursor) && <div><button className="quiet" disabled={!cursor} onClick={()=>setRoutes(old=>old.slice(0,-1))}>Zurück</button><button className="quiet" disabled={!list.data.next_cursor} onClick={()=>{const next=list.data?.next_cursor;if(next)setRoutes(old=>[...old,next]);}}>Weiter</button></div>}</div>
|
||||
</>}
|
||||
</section>
|
||||
{!!selection.ids.length && <div className="selection"><div><strong>{selection.ids.length} {selection.ids.length===1?'Gerät':'Geräte'} ausgewählt</strong><small>{customers.find(c=>c.tenant_id===selection.customer)?.name}</small></div>
|
||||
<button className="quiet" onClick={()=>onSelection({customer:'',ids:[]})}>Auswahl aufheben</button><button onClick={onScripts}>Skript auswählen</button></div>}
|
||||
</>;
|
||||
<section className="fleet" aria-label="Gerätebestand">
|
||||
<div className="fleet-tabs">
|
||||
<button
|
||||
aria-pressed={!history}
|
||||
onClick={() => {
|
||||
if (history) setView(false);
|
||||
}}
|
||||
>
|
||||
Bestand
|
||||
</button>
|
||||
<button
|
||||
aria-pressed={history}
|
||||
onClick={() => {
|
||||
if (!history) setView(true);
|
||||
}}
|
||||
>
|
||||
Historie
|
||||
</button>
|
||||
</div>
|
||||
<div className="filters">
|
||||
<label className="search-box">
|
||||
<span className="sr-only">Hostname suchen</span>
|
||||
<NavIcon name="suchen" />
|
||||
<input
|
||||
type="search"
|
||||
placeholder="Hostname suchen …"
|
||||
maxLength={120}
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<span>Kunde</span>
|
||||
<select
|
||||
value={filter}
|
||||
onChange={(e) => {
|
||||
setRoutes([]);
|
||||
onFilter(e.target.value);
|
||||
}}
|
||||
>
|
||||
<option value="">Alle Kunden</option>
|
||||
{customers.map((c) => (
|
||||
<option value={c.tenant_id} key={c.tenant_id}>
|
||||
{c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
{!history && (
|
||||
<label>
|
||||
<span>Status</span>
|
||||
<select
|
||||
value={status}
|
||||
onChange={(e) => {
|
||||
setRoutes([]);
|
||||
setStatus(e.target.value);
|
||||
}}
|
||||
>
|
||||
<option value="">Jeder Status</option>
|
||||
<option value="online">Online</option>
|
||||
<option value="offline">Offline</option>
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
<ErrorBox error={list.error} />
|
||||
{history && (
|
||||
<p className="history-hint">
|
||||
Ausgemusterte Geräte und Registrierungen ohne bestätigte Identität.
|
||||
</p>
|
||||
)}
|
||||
{!list.data && !list.error && <p className="list-message">Geräte werden geladen …</p>}
|
||||
{list.data && (
|
||||
<>
|
||||
<div className="table fleet-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
{!history && (
|
||||
<th className="target-col">
|
||||
<span className="sr-only">Ziel auswählen</span>
|
||||
</th>
|
||||
)}
|
||||
{['Hostname', 'OS', 'Status', 'Speicher frei / gesamt', 'RAM', 'CPU', 'Kunde'].map(
|
||||
(h) => (
|
||||
<th scope="col" key={h}>
|
||||
{h}
|
||||
</th>
|
||||
)
|
||||
)}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{list.data.items.map((d) => {
|
||||
const asset = objectId(d, 'asset'),
|
||||
agent = objectId(d, 'agent'),
|
||||
customer = objectId(d, 'tenant'),
|
||||
model = cpu(d);
|
||||
const show = () => {
|
||||
window.location.hash = ['geraete', customer, asset, agent]
|
||||
.map(encodeURIComponent)
|
||||
.join('/');
|
||||
};
|
||||
const another = selection.ids.length > 0 && selection.customer !== customer;
|
||||
return (
|
||||
<tr key={agent} onClick={show}>
|
||||
{!history && (
|
||||
<td className="target-col" onClick={(e) => e.stopPropagation()}>
|
||||
<input
|
||||
type="checkbox"
|
||||
aria-label={'Ziel ' + asset}
|
||||
title={
|
||||
another ? 'Aufträge werden je Kunde geplant' : 'Für Auftrag auswählen'
|
||||
}
|
||||
disabled={another}
|
||||
checked={selection.customer === customer && selection.ids.includes(asset)}
|
||||
onChange={(e) => select(d, e.target.checked)}
|
||||
/>
|
||||
</td>
|
||||
)}
|
||||
<td className="hostname">
|
||||
<button
|
||||
className="host-link"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
show();
|
||||
}}
|
||||
>
|
||||
{label(d.hostname)}
|
||||
</button>
|
||||
</td>
|
||||
<td data-label="OS">{label(d.os)}</td>
|
||||
<td data-label="Status" className="device-presence">
|
||||
<Presence d={d} />
|
||||
{d.status === 'offline' && d.lifecycle === 'current' && (
|
||||
<small>Zuletzt {time(d.last_contact_at)}</small>
|
||||
)}
|
||||
</td>
|
||||
<td data-label="Speicher frei / gesamt" className="storage">
|
||||
<Storage d={d} />
|
||||
</td>
|
||||
<td data-label="RAM">
|
||||
{gib(d.ram_total_bytes) === null ? unknown : gib(d.ram_total_bytes) + ' GiB'}
|
||||
</td>
|
||||
<td data-label="CPU">
|
||||
{model.primary}
|
||||
{model.secondary && <small>{model.secondary}</small>}
|
||||
</td>
|
||||
<td data-label="Kunde">{label(d.customer_name)}</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{!list.data.items.length && (
|
||||
<div className="empty-list">
|
||||
<NavIcon name="geraete" />
|
||||
<h3>
|
||||
{query || filter || status
|
||||
? 'Keine passenden Geräte'
|
||||
: 'Keine Geräte in dieser Ansicht'}
|
||||
</h3>
|
||||
{(query || filter || status) && (
|
||||
<button
|
||||
className="quiet"
|
||||
onClick={() => {
|
||||
setSearch('');
|
||||
setQuery('');
|
||||
setRoutes([]);
|
||||
setStatus('');
|
||||
onFilter('');
|
||||
}}
|
||||
>
|
||||
Filter zurücksetzen
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="list-footer">
|
||||
<span>
|
||||
{list.data.items.length} {list.data.items.length === 1 ? 'Gerät' : 'Geräte'}
|
||||
{cursor || list.data.next_cursor ? ' auf dieser Seite' : ''} · Stand{' '}
|
||||
{time(list.data.as_of)}
|
||||
</span>
|
||||
{(cursor || list.data.next_cursor) && (
|
||||
<div>
|
||||
<button
|
||||
className="quiet"
|
||||
disabled={!cursor}
|
||||
onClick={() => setRoutes((old) => old.slice(0, -1))}
|
||||
>
|
||||
Zurück
|
||||
</button>
|
||||
<button
|
||||
className="quiet"
|
||||
disabled={!list.data.next_cursor}
|
||||
onClick={() => {
|
||||
const next = list.data?.next_cursor;
|
||||
if (next) setRoutes((old) => [...old, next]);
|
||||
}}
|
||||
>
|
||||
Weiter
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
{!!selection.ids.length && (
|
||||
<div className="selection">
|
||||
<div>
|
||||
<strong>
|
||||
{selection.ids.length} {selection.ids.length === 1 ? 'Gerät' : 'Geräte'} ausgewählt
|
||||
</strong>
|
||||
<small>{customers.find((c) => c.tenant_id === selection.customer)?.name}</small>
|
||||
</div>
|
||||
<button className="quiet" onClick={() => onSelection({ customer: '', ids: [] })}>
|
||||
Auswahl aufheben
|
||||
</button>
|
||||
<button onClick={onScripts}>Skript auswählen</button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
+305
-73
@@ -258,87 +258,319 @@ function UnknownClosure({ tenantId, id, job, auth, done }: { tenantId: string; i
|
||||
await request(tenantPath(tenantId, `/jobs/${encodeURIComponent(id)}/unknown-closure`), { csrf: auth.csrf_token, body: { attempt_id: stringField(job, 'attempt_id'), revision: job.revision, reason: reason.trim() } }); setConfirmed(false); done();
|
||||
} catch (e) { setError(errorText(e)); } finally { setBusy(false); } }}>{auth.principal.simulated ? 'SIMULIERT: Unknown-Job ausdrücklich abschließen' : 'Unknown-Job ausdrücklich abschließen'}</button></section>;
|
||||
}
|
||||
const pages: Record<NavKey,string> = { geraete: 'Geräte', auftraege: 'Aufträge', skripte: 'Skripte', kunden: 'Kunden', verwaltung: 'Verwaltung' };
|
||||
const pages: Record<NavKey, string> = {
|
||||
geraete: 'Geräte',
|
||||
auftraege: 'Aufträge',
|
||||
skripte: 'Skripte',
|
||||
kunden: 'Kunden',
|
||||
verwaltung: 'Verwaltung'
|
||||
};
|
||||
function currentRoute() {
|
||||
const [key = 'geraete',tab] = window.location.hash.slice(1).split('/');
|
||||
return { page: (Object.hasOwn(pages,key) ? key : 'geraete') as NavKey, tab: tab ?? '' };
|
||||
const [key = 'geraete', ...parts] = window.location.hash.slice(1).split('/');
|
||||
return { page: (Object.hasOwn(pages, key) ? key : 'geraete') as NavKey, tab: parts.join('/') };
|
||||
}
|
||||
function go(page: NavKey, tab = '') {
|
||||
window.location.hash = page + (tab ? '/' + tab : '');
|
||||
}
|
||||
function go(page: NavKey, tab = '') { window.location.hash = page + (tab ? '/' + tab : ''); }
|
||||
|
||||
function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
|
||||
const [route,setRoute] = useState(currentRoute);
|
||||
useEffect(()=>{ const change=()=>{setRoute(currentRoute());window.scrollTo(0,0);}; window.addEventListener('hashchange',change);return ()=>window.removeEventListener('hashchange',change); },[]);
|
||||
useEffect(()=>{document.title=pages[route.page]+' · Rust Discovery';},[route.page]);
|
||||
const tenants=useResource(async signal=>{
|
||||
const data=record(await request('/api/v1/tenants',{signal}));
|
||||
return {items:page(data).items.map(tenant),canManage:data.can_manage_customers===true};
|
||||
},[auth.principal.id]);
|
||||
const customers=tenants.data?.items ?? auth.tenants;
|
||||
const [customer,setCustomer]=useState(auth.tenants[0]?.tenant_id ?? '');
|
||||
const [fleetFilter,setFleetFilter]=useState('');
|
||||
const [selection,setSelection]=useState<{customer:string;ids:string[]}>({customer:'',ids:[]});
|
||||
const [error,setError]=useState<string|null>(null);
|
||||
const [planId,setPlan]=useState<string|null>(null), [operationId,setOperation]=useState<string|null>(null);
|
||||
function switchCustomer(id:string) {
|
||||
if(id===customer)return;
|
||||
setSelection({customer:'',ids:[]});setPlan(null);setOperation(null);setCustomer(id);
|
||||
const [route, setRoute] = useState(currentRoute);
|
||||
useEffect(() => {
|
||||
const change = () => {
|
||||
setRoute(currentRoute());
|
||||
window.scrollTo(0, 0);
|
||||
};
|
||||
window.addEventListener('hashchange', change);
|
||||
return () => window.removeEventListener('hashchange', change);
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
document.title = pages[route.page] + ' · Rust Discovery';
|
||||
}, [route.page]);
|
||||
const tenants = useResource(
|
||||
async (signal) => {
|
||||
const data = record(await request('/api/v1/tenants', { signal }));
|
||||
return { items: page(data).items.map(tenant), canManage: data.can_manage_customers === true };
|
||||
},
|
||||
[auth.principal.id]
|
||||
);
|
||||
const customers = tenants.data?.items ?? auth.tenants;
|
||||
const [customer, setCustomer] = useState(auth.tenants[0]?.tenant_id ?? '');
|
||||
const [fleetFilter, setFleetFilter] = useState('');
|
||||
const [selection, setSelection] = useState<{ customer: string; ids: string[] }>({
|
||||
customer: '',
|
||||
ids: []
|
||||
});
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [planId, setPlan] = useState<string | null>(null),
|
||||
[operationId, setOperation] = useState<string | null>(null);
|
||||
function switchCustomer(id: string) {
|
||||
if (id === customer) return;
|
||||
setSelection({ customer: '', ids: [] });
|
||||
setPlan(null);
|
||||
setOperation(null);
|
||||
setCustomer(id);
|
||||
}
|
||||
function selectFleetCustomer(id:string) {
|
||||
setFleetFilter(id);setSelection({customer:'',ids:[]});
|
||||
if(id) switchCustomer(id);
|
||||
function selectFleetCustomer(id: string) {
|
||||
setFleetFilter(id);
|
||||
setSelection({ customer: '', ids: [] });
|
||||
if (id) switchCustomer(id);
|
||||
}
|
||||
const primaryTenant=auth.tenants[0]?.tenant_id;
|
||||
const current = useResource(async signal=>{
|
||||
if(!customer || customer===primaryTenant)return {id:customer,auth};
|
||||
const scoped=session(await request('/auth/session',{signal,tenantId:customer}));
|
||||
return {id:customer,auth:scoped};
|
||||
},[customer,auth]);
|
||||
const primaryTenant = auth.tenants[0]?.tenant_id;
|
||||
const current = useResource(
|
||||
async (signal) => {
|
||||
if (!customer || customer === primaryTenant) return { id: customer, auth };
|
||||
const scoped = session(await request('/auth/session', { signal, tenantId: customer }));
|
||||
return { id: customer, auth: scoped };
|
||||
},
|
||||
[customer, auth]
|
||||
);
|
||||
// Gate rendering during a tenant change; a previously loaded session is scoped to its own customer.
|
||||
const scoped=current.data?.id===customer ? current.data.auth : null;
|
||||
const customerName=customers.find(c=>c.tenant_id===customer)?.name ?? '';
|
||||
const openOperation=(id:string)=>{setPlan(null);setOperation(id);go('auftraege');};
|
||||
const showPlan=(id:string)=>{setOperation(null);setPlan(id);go('auftraege');};
|
||||
const selected=selection.customer===customer?selection.ids:[];
|
||||
const tabs: [string,string][]= [['zugang','MCP-Tokens'],['aufnahme','Agent-Releases & Aufnahme'],['kataloge','Paketkataloge'],['rechte','Rechte & Ausführungsstopp']];
|
||||
const adminTab=tabs.some(([id])=>id===route.tab)?route.tab:'zugang';
|
||||
return <div className="workbench">
|
||||
<aside className="sidebar">
|
||||
<a className="brand" href="#geraete" aria-label="Rust Discovery – Geräte"><span className="brand-mark" aria-hidden="true"><i/><i/><i/></span>Rust Discovery</a>
|
||||
<nav aria-label="Hauptnavigation">{(Object.entries(pages) as [NavKey,string][]).map(([key,title])=><a key={key} href={'#'+key} aria-current={route.page===key?'page':undefined}><NavIcon name={key}/><span>{title}</span></a>)}</nav>
|
||||
<div className="account"><div><span className="account-dot" aria-hidden="true"/><span title={auth.principal.id}>{auth.principal.display_name}</span></div><button onClick={async()=>{
|
||||
try {await request('/auth/logout',{csrf:auth.csrf_token,body:{}});window.history.replaceState(null,'',window.location.pathname+window.location.search);logout();}
|
||||
catch(e){setError(errorText(e));}
|
||||
}}><NavIcon name="abmelden"/> Abmelden</button></div>
|
||||
</aside>
|
||||
<div className="work-area"><header className="topline"><div className="crumb"><span>Arbeitsbereich</span><i aria-hidden="true">/</i><b>{pages[route.page]}</b></div>
|
||||
{route.page!=='geraete' && route.page!=='kunden' && <label className="context"><span>Kunde</span><select value={customer} onChange={e=>switchCustomer(e.target.value)}>{customers.map(c=><option value={c.tenant_id} key={c.tenant_id}>{c.name}</option>)}</select></label>}
|
||||
</header>
|
||||
{auth.principal.simulated && <aside className="simulation" role="status">SIMULIERT · dev/test-Testprincipal · Genehmigung ist eine Entwicklungs-Browsersimulation, kein menschlicher Produktions-Freigabenachweis.</aside>}
|
||||
<main className="content"><ErrorBox error={error}/><ErrorBox error={tenants.error}/><ErrorBox error={current.error}/>
|
||||
{route.page==='geraete' && <Devices auth={scoped ?? auth} customers={customers} filter={fleetFilter} onFilter={selectFleetCustomer}
|
||||
selection={selection} onSelection={value=>{if(value.customer)switchCustomer(value.customer);setSelection(value);}}
|
||||
onEnroll={()=>go('verwaltung','aufnahme')} onScripts={()=>go('skripte')}
|
||||
onOperation={(tenantId,id)=>{switchCustomer(tenantId);openOperation(id);}}/>}
|
||||
{route.page==='kunden' && <><div className="page-title"><h1>Kunden</h1></div><CustomerManagement auth={auth} customers={customers} canManage={tenants.data?.canManage===true} onChange={tenants.reload} onSelect={id=>{selectFleetCustomer(id);go('geraete');}}/></>}
|
||||
{!['geraete','kunden'].includes(route.page) && (!customer || !scoped) && !current.error && <p>Kundenbereich wird geladen …</p>}
|
||||
{scoped && <React.Fragment key={customer}>
|
||||
{route.page==='skripte' && <><div className="page-title"><h1>Skripte</h1><a className="soft-button" href="#geraete">Geräte auswählen</a></div>
|
||||
{selected.length>0 && <p className="target-note">{selected.length} {selected.length===1?'Zielgerät':'Zielgeräte'} für {customerName} ausgewählt</p>}
|
||||
<ScriptLibrary tenantId={customer} auth={scoped} selected={selected} showPlan={showPlan}/></>}
|
||||
{route.page==='auftraege' && <><div className="page-title"><h1>Aufträge</h1>{route.tab!=='neu' && <a className="soft-button" href="#auftraege/neu"><NavIcon name="plus"/> Auftrag planen</a>}</div>
|
||||
{route.tab==='neu' ? <><a className="quiet" href="#geraete">Geräte auswählen</a><p className="target-note">{selected.length} {selected.length===1?'Zielgerät':'Zielgeräte'} für {customerName} ausgewählt</p><Planner tenantId={customer} auth={scoped} selected={selected} showPlan={showPlan}/></> : <>
|
||||
{operationId && <OperationDetail key={operationId} tenantId={customer} id={operationId} auth={scoped} openPlan={id=>setPlan(id)}/>}
|
||||
{planId && <PlanDetail key={planId} tenantId={customer} id={planId} auth={scoped} onOperation={setOperation}/>}
|
||||
<Operations tenantId={customer} open={openOperation}/></>}</>}
|
||||
{route.page==='verwaltung' && <><div className="page-title"><h1>Verwaltung</h1></div><nav className="subnav" aria-label="Verwaltungsbereiche">{tabs.map(([id,title])=><a href={'#verwaltung/'+id} key={id} aria-current={adminTab===id?'page':undefined}>{title}</a>)}</nav>
|
||||
{adminTab==='zugang' && <McpTokenManagement tenantId={customer} auth={scoped}/>}
|
||||
{adminTab==='aufnahme' && <AgentReleaseCatalog tenantId={customer} auth={scoped} customerName={customerName} enrollmentOpen/>}
|
||||
{adminTab==='kataloge' && <><Catalog tenantId={customer} auth={scoped}/><WindowsMsiCatalog tenantId={customer} auth={scoped}/></>}
|
||||
{adminTab==='rechte' && <TenantControls tenantId={customer} auth={scoped}/>}</>}
|
||||
</React.Fragment>}
|
||||
</main></div>
|
||||
</div>;
|
||||
const scoped = current.data?.id === customer ? current.data.auth : null;
|
||||
const customerName = customers.find((c) => c.tenant_id === customer)?.name ?? '';
|
||||
const openOperation = (id: string) => {
|
||||
setPlan(null);
|
||||
setOperation(id);
|
||||
go('auftraege');
|
||||
};
|
||||
const showPlan = (id: string) => {
|
||||
setOperation(null);
|
||||
setPlan(id);
|
||||
go('auftraege');
|
||||
};
|
||||
const selected = selection.customer === customer ? selection.ids : [];
|
||||
const tabs: [string, string][] = [
|
||||
['zugang', 'MCP-Tokens'],
|
||||
['aufnahme', 'Agent-Releases & Aufnahme'],
|
||||
['kataloge', 'Paketkataloge'],
|
||||
['rechte', 'Rechte & Ausführungsstopp']
|
||||
];
|
||||
const adminTab = tabs.some(([id]) => id === route.tab) ? route.tab : 'zugang';
|
||||
return (
|
||||
<div className="workbench">
|
||||
<aside className="sidebar">
|
||||
<a className="brand" href="#geraete" aria-label="Rust Discovery – Geräte">
|
||||
<span className="brand-mark" aria-hidden="true">
|
||||
<i />
|
||||
<i />
|
||||
<i />
|
||||
</span>
|
||||
Rust Discovery
|
||||
</a>
|
||||
<nav aria-label="Hauptnavigation">
|
||||
{(Object.entries(pages) as [NavKey, string][]).map(([key, title]) => (
|
||||
<a key={key} href={'#' + key} aria-current={route.page === key ? 'page' : undefined}>
|
||||
<NavIcon name={key} />
|
||||
<span>{title}</span>
|
||||
</a>
|
||||
))}
|
||||
</nav>
|
||||
<div className="account">
|
||||
<div>
|
||||
<span className="account-dot" aria-hidden="true" />
|
||||
<span title={auth.principal.id}>{auth.principal.display_name}</span>
|
||||
</div>
|
||||
<button
|
||||
onClick={async () => {
|
||||
try {
|
||||
await request('/auth/logout', { csrf: auth.csrf_token, body: {} });
|
||||
window.history.replaceState(null, '', window.location.pathname + window.location.search);
|
||||
logout();
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
}
|
||||
}}
|
||||
>
|
||||
<NavIcon name="abmelden" /> Abmelden
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
<div className="work-area">
|
||||
<header className="topline">
|
||||
<div className="crumb">
|
||||
<span>Arbeitsbereich</span>
|
||||
<i aria-hidden="true">/</i>
|
||||
<b>{pages[route.page]}</b>
|
||||
</div>
|
||||
{route.page !== 'geraete' && route.page !== 'kunden' && (
|
||||
<label className="context">
|
||||
<span>Kunde</span>
|
||||
<select value={customer} onChange={(e) => switchCustomer(e.target.value)}>
|
||||
{customers.map((c) => (
|
||||
<option value={c.tenant_id} key={c.tenant_id}>
|
||||
{c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
</header>
|
||||
{auth.principal.simulated && (
|
||||
<aside className="simulation" role="status">
|
||||
SIMULIERT · dev/test-Testprincipal · Genehmigung ist eine Entwicklungs-Browsersimulation,
|
||||
kein menschlicher Produktions-Freigabenachweis.
|
||||
</aside>
|
||||
)}
|
||||
<main className="content">
|
||||
<ErrorBox error={error} />
|
||||
<ErrorBox error={tenants.error} />
|
||||
<ErrorBox error={current.error} />
|
||||
{route.page === 'geraete' && (
|
||||
<Devices
|
||||
detailPath={route.tab}
|
||||
auth={scoped ?? auth}
|
||||
customers={customers}
|
||||
filter={fleetFilter}
|
||||
onFilter={selectFleetCustomer}
|
||||
selection={selection}
|
||||
onSelection={(value) => {
|
||||
if (value.customer) switchCustomer(value.customer);
|
||||
setSelection(value);
|
||||
}}
|
||||
onEnroll={() => go('verwaltung', 'aufnahme')}
|
||||
onScripts={() => go('skripte')}
|
||||
onOperation={(tenantId, id) => {
|
||||
switchCustomer(tenantId);
|
||||
openOperation(id);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{route.page === 'kunden' && (
|
||||
<>
|
||||
<div className="page-title">
|
||||
<h1>Kunden</h1>
|
||||
</div>
|
||||
<CustomerManagement
|
||||
auth={auth}
|
||||
customers={customers}
|
||||
canManage={tenants.data?.canManage === true}
|
||||
onChange={tenants.reload}
|
||||
onSelect={(id) => {
|
||||
selectFleetCustomer(id);
|
||||
go('geraete');
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{!['geraete', 'kunden'].includes(route.page) && (!customer || !scoped) && !current.error && (
|
||||
<p>Kundenbereich wird geladen …</p>
|
||||
)}
|
||||
{scoped && (
|
||||
<React.Fragment key={customer}>
|
||||
{route.page === 'skripte' && (
|
||||
<>
|
||||
<div className="page-title">
|
||||
<h1>Skripte</h1>
|
||||
<a className="soft-button" href="#geraete">
|
||||
Geräte auswählen
|
||||
</a>
|
||||
</div>
|
||||
{selected.length > 0 && (
|
||||
<p className="target-note">
|
||||
{selected.length} {selected.length === 1 ? 'Zielgerät' : 'Zielgeräte'} für{' '}
|
||||
{customerName} ausgewählt
|
||||
</p>
|
||||
)}
|
||||
<ScriptLibrary
|
||||
tenantId={customer}
|
||||
auth={scoped}
|
||||
selected={selected}
|
||||
showPlan={showPlan}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{route.page === 'auftraege' && (
|
||||
<>
|
||||
<div className="page-title">
|
||||
<h1>Aufträge</h1>
|
||||
{route.tab !== 'neu' && (
|
||||
<a className="soft-button" href="#auftraege/neu">
|
||||
<NavIcon name="plus" /> Auftrag planen
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
{route.tab === 'neu' ? (
|
||||
<>
|
||||
<a className="quiet" href="#geraete">
|
||||
Geräte auswählen
|
||||
</a>
|
||||
<p className="target-note">
|
||||
{selected.length} {selected.length === 1 ? 'Zielgerät' : 'Zielgeräte'} für{' '}
|
||||
{customerName} ausgewählt
|
||||
</p>
|
||||
<Planner
|
||||
tenantId={customer}
|
||||
auth={scoped}
|
||||
selected={selected}
|
||||
showPlan={showPlan}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{operationId && (
|
||||
<OperationDetail
|
||||
key={operationId}
|
||||
tenantId={customer}
|
||||
id={operationId}
|
||||
auth={scoped}
|
||||
openPlan={(id) => setPlan(id)}
|
||||
/>
|
||||
)}
|
||||
{planId && (
|
||||
<PlanDetail
|
||||
key={planId}
|
||||
tenantId={customer}
|
||||
id={planId}
|
||||
auth={scoped}
|
||||
onOperation={setOperation}
|
||||
/>
|
||||
)}
|
||||
<Operations tenantId={customer} open={openOperation} />
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{route.page === 'verwaltung' && (
|
||||
<>
|
||||
<div className="page-title">
|
||||
<h1>Verwaltung</h1>
|
||||
</div>
|
||||
<nav className="subnav" aria-label="Verwaltungsbereiche">
|
||||
{tabs.map(([id, title]) => (
|
||||
<a
|
||||
href={'#verwaltung/' + id}
|
||||
key={id}
|
||||
aria-current={adminTab === id ? 'page' : undefined}
|
||||
>
|
||||
{title}
|
||||
</a>
|
||||
))}
|
||||
</nav>
|
||||
{adminTab === 'zugang' && <McpTokenManagement tenantId={customer} auth={scoped} />}
|
||||
{adminTab === 'aufnahme' && (
|
||||
<AgentReleaseCatalog
|
||||
tenantId={customer}
|
||||
auth={scoped}
|
||||
customerName={customerName}
|
||||
enrollmentOpen
|
||||
/>
|
||||
)}
|
||||
{adminTab === 'kataloge' && (
|
||||
<>
|
||||
<Catalog tenantId={customer} auth={scoped} />
|
||||
<WindowsMsiCatalog tenantId={customer} auth={scoped} />
|
||||
</>
|
||||
)}
|
||||
{adminTab === 'rechte' && <TenantControls tenantId={customer} auth={scoped} />}
|
||||
</>
|
||||
)}
|
||||
</React.Fragment>
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function App() {
|
||||
const [auth, setAuth] = useState<Session | null>(null), [loading, setLoading] = useState(true), [error, setError] = useState<string | null>(null);
|
||||
const config = useResource(async signal => authConfig(await request('/auth/config', { signal })), []);
|
||||
|
||||
+16
-2
@@ -8,8 +8,22 @@ const glyphs = {
|
||||
suchen: 'M16 16l5 5 M18 10a8 8 0 1 1-16 0 8 8 0 0 1 16 0',
|
||||
plus: 'M12 5v14 M5 12h14',
|
||||
abmelden: 'M10 4H4v16h6 M8 12h13 M16 7l5 5-5 5',
|
||||
zurueck: 'M20 12H4 M10 6l-6 6 6 6',
|
||||
zurueck: 'M20 12H4 M10 6l-6 6 6 6'
|
||||
};
|
||||
export function NavIcon({ name }: { name: keyof typeof glyphs }) {
|
||||
return <svg className="nav-icon" aria-hidden="true" focusable="false" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65" strokeLinecap="round" strokeLinejoin="round"><path d={glyphs[name]}/></svg>;
|
||||
return (
|
||||
<svg
|
||||
className="nav-icon"
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.65"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d={glyphs[name]} />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
+42
-10
@@ -1,15 +1,47 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
export const errorText = (error: unknown) => error instanceof Error ? error.message : 'Unbekannter Fehler';
|
||||
export function ErrorBox({ error }: { error: string | null }) { return error ? <div role="alert" className="error">{error}</div> : null; }
|
||||
export function useResource<T>(load: (signal: AbortSignal) => Promise<T>, deps: React.DependencyList, poll = false) {
|
||||
const [data, setData] = useState<T | null>(null), [error, setError] = useState<string | null>(null), [revision, setRevision] = useState(0);
|
||||
export const errorText = (error: unknown) =>
|
||||
error instanceof Error ? error.message : 'Unbekannter Fehler';
|
||||
export function ErrorBox({ error }: { error: string | null }) {
|
||||
return error ? (
|
||||
<div role="alert" className="error">
|
||||
{error}
|
||||
</div>
|
||||
) : null;
|
||||
}
|
||||
export function useResource<T>(
|
||||
load: (signal: AbortSignal) => Promise<T>,
|
||||
deps: React.DependencyList,
|
||||
poll = false
|
||||
) {
|
||||
const [data, setData] = useState<T | null>(null),
|
||||
[error, setError] = useState<string | null>(null),
|
||||
[revision, setRevision] = useState(0);
|
||||
useEffect(() => {
|
||||
let active = true; const controller = new AbortController(); let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
setData(null); setError(null);
|
||||
const run = async () => { try { const result = await load(controller.signal); if (active) { setData(result); setError(null); } } catch (e) { if (active) setError(errorText(e)); }
|
||||
finally { if (active && poll) timer = setTimeout(run, 4000); } };
|
||||
void run(); return () => { active = false; controller.abort(); clearTimeout(timer); };
|
||||
let active = true;
|
||||
const controller = new AbortController();
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
setData(null);
|
||||
setError(null);
|
||||
const run = async () => {
|
||||
try {
|
||||
const result = await load(controller.signal);
|
||||
if (active) {
|
||||
setData(result);
|
||||
setError(null);
|
||||
}
|
||||
} catch (e) {
|
||||
if (active) setError(errorText(e));
|
||||
} finally {
|
||||
if (active && poll) timer = setTimeout(run, 4000);
|
||||
}
|
||||
};
|
||||
void run();
|
||||
return () => {
|
||||
active = false;
|
||||
controller.abort();
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [...deps, revision]);
|
||||
return { data, error, reload: () => setRevision(v => v + 1) };
|
||||
return { data, error, reload: () => setRevision((v) => v + 1) };
|
||||
}
|
||||
|
||||
+2
-2
@@ -46,8 +46,8 @@ thead th { background:#f7f9f8; color:var(--subtle); font-weight:620; font-size:.
|
||||
.login form > button { width:100%; margin-top:12px; }
|
||||
.workbench { display:grid; grid-template-columns:195px minmax(0,1fr); min-height:100vh; }
|
||||
.sidebar { position:sticky; top:0; height:100vh; height:100dvh; background:var(--nav); color:#eef7f3; display:flex; flex-direction:column; padding:25px 12px 15px; }
|
||||
.brand { display:flex; align-items:center; gap:10px; padding:0 7px; color:white; text-decoration:none; font-weight:675; font-size:1.13rem; letter-spacing:-.035em; white-space:nowrap; }
|
||||
.brand-mark { width:28px; height:28px; position:relative; transform:rotate(-6deg); display:inline-block; }
|
||||
.brand { display:flex; align-items:center; gap:9px; padding:0 4px; color:white; text-decoration:none; font-weight:675; font-size:1.06rem; letter-spacing:-.035em; white-space:nowrap; }
|
||||
.brand-mark { width:24px; flex:none; height:28px; position:relative; transform:rotate(-6deg); display:inline-block; }
|
||||
.brand-mark i { position:absolute; width:18px; height:13px; border:2px solid #85c7a9; background:var(--nav); border-radius:3px; transform:skewY(-17deg); left:4px; top:11px; }
|
||||
.brand-mark i:nth-child(2) { top:7px; } .brand-mark i:nth-child(3) { top:3px; background:#b5e9c7; border-color:#b5e9c7; }
|
||||
.sidebar nav { margin-top:36px; display:grid; gap:5px; }
|
||||
|
||||
Reference in New Issue
Block a user