Integrate the currently deployed server functionality with the reviewed WebUI

This commit is contained in:
2026-11-18 09:05:06 +01:00
17 changed files with 261 additions and 83 deletions
+42 -40
View File
@@ -27,6 +27,7 @@ import {
scriptPlatform,
type Identity,
type Interpreter,
type Revision,
type Script
} from './script-catalog';
import { ScriptFields } from './script-library';
@@ -137,9 +138,9 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
const ticket = canPlanScript ? savedTicket : null;
const [mode, setMode] = useState<'library' | 'once' | 'reboot'>(() => canPlanScript ? 'library' : 'reboot');
const [revisionId, choose] = useState('');
const [libraryIdentity, setLibraryIdentity] = useState<Identity | null>(null);
const [linux, setLinux] = useState<Script>(() => emptyScript('posix_sh'));
const [windows, setWindows] = useState<Script>(() => emptyScript('powershell'));
const [fullRoot, setFullRoot] = useState(false);
const [reason, setReason] = useState('');
const [start, setStart] = useState(() => localDate(Date.now()));
const [end, setEnd] = useState(() => localDate(Date.now() + 3600000));
@@ -221,6 +222,9 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
);
const revision = scripts.data?.find((r) => r.revision_id === revisionId);
const heads = latestRevisions(scripts.data ?? []);
const identity = mode === 'library'
? libraryIdentity ?? revision?.execution_identity
: (hasWindows ? windows : linux).execution_identity;
const rebootIdentity = hasWindows ? 'system' : 'root';
const rebootAsset = mode === 'reboot' && step === 2 && selected.length === 1 ? selected[0] : null;
const rebootTarget = useResource(async signal => {
@@ -248,8 +252,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
issues.push(
`Dieses Skript unterstützt ${interpreterNames[revision.interpreter]}. Inkompatible Geräte: ${incompatible.map((d) => d?.name).join(', ')}.`
);
const identity = revision.execution_identity;
if (identity !== 'agent_service' && !allowed(auth, identity + ':execute'))
if (identity && identity !== 'agent_service' && !allowed(auth, identity + ':execute'))
issues.push('Die Berechtigung für ' + identityNames[identity] + ' fehlt.');
}
if (mode === 'reboot') {
@@ -285,16 +288,14 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
const windowUpdate =
mode === 'library' &&
revision?.script_sha256 === windowsUpdateScriptHash &&
revision.execution_identity === 'system';
const identity =
mode === 'library' ? revision?.execution_identity : (hasWindows ? windows : linux).execution_identity;
const maxRuntime = windowUpdate
? 3600
: identity === 'system'
? 120
: identity === 'root' && (mode === 'library' || fullRoot)
? 300
: 3600;
identity === 'system';
const maxRuntime = windowUpdate ? 3600 : identity === 'system' ? 120 : identity === 'root' ? 300 : 3600;
function chooseLibrary(next: Revision | undefined) {
choose(next?.revision_id ?? '');
setLibraryIdentity(null);
setRuntime(next?.script_sha256 === windowsUpdateScriptHash && next.execution_identity === 'system' ? 3600 : 120);
setLimit(65536);
}
async function prepare(e: FormEvent) {
e.preventDefault();
if (lock.current || !(mode === 'reboot' ? canPlanReboot : canPlanScript) || issues.length || !selected.length) return;
@@ -354,7 +355,10 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
if (!revision) throw Error('Wählen Sie eine Skriptversion.');
raw = await request(path('/script-revisions/' + revision.revision_id + '/plan'), {
csrf: auth.csrf_token,
body: { ...bound, schedule, max_runtime_seconds: runtime, max_output_bytes: limit }
body: {
...bound, schedule, max_runtime_seconds: runtime, max_output_bytes: limit,
...(libraryIdentity ? { execution_identity: libraryIdentity } : {})
}
});
} else {
const variants = [hasLinux ? linux : null, hasWindows ? windows : null]
@@ -375,7 +379,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
expected_stdout: expectedStdout(expected, expectedFormat),
timeout_seconds: runtime,
max_output_bytes: limit,
...(identity === 'system' || (identity === 'root' && fullRoot)
...(identity === 'system' || identity === 'root'
? { privileged_script_profile: fullMaintenanceScriptProfile }
: {})
};
@@ -399,7 +403,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
!selected.includes(j.assetId) ||
j.revision?.id !== (mode === 'library' ? revisionId : undefined) ||
j.script !== script?.script_utf8 ||
j.identity !== script.execution_identity ||
j.identity !== identity ||
j.interpreter !== script.interpreter ||
j.runtimeSeconds !== runtime ||
j.outputBytes !== limit ||
@@ -701,9 +705,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
required
value={revision?.name ?? ''}
onChange={(e) => {
const next = heads.find((h) => h.name === e.target.value);
choose(next?.revision_id ?? '');
setRuntime(next?.script_sha256 === windowsUpdateScriptHash ? 3600 : 120);
chooseLibrary(heads.find((h) => h.name === e.target.value));
}}
>
<option value="">Skript wählen</option>
@@ -721,15 +723,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
Version
<select
value={revisionId}
onChange={(e) => {
choose(e.target.value);
setRuntime(
scripts.data?.find((r) => r.revision_id === e.target.value)?.script_sha256 ===
windowsUpdateScriptHash
? 3600
: 120
);
}}
onChange={(e) => chooseLibrary(scripts.data?.find((r) => r.revision_id === e.target.value))}
>
{scripts.data
?.filter((r) => r.name === revision.name)
@@ -740,12 +734,23 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
))}
</select>
</label>
<p>
{interpreterNames[revision.interpreter]} · {identityNames[revision.execution_identity]}
</p>
{revision.execution_identity !== 'agent_service' && (
<p className="warning">Das Skript benötigt erhöhte Rechte auf den ausgewählten Geräten.</p>
)}
<p>{interpreterNames[revision.interpreter]}</p>
<label>
Ausführen als
<select value={identity} onChange={(e) => {
const next = e.target.value as Identity;
setLibraryIdentity(next);
setRuntime(revision.script_sha256 === windowsUpdateScriptHash && next === 'system' ? 3600 : 120);
setLimit(65536);
}}>
<option value="agent_service">{identityNames.agent_service}</option>
{(['root', 'system'] as const).filter((value) =>
value === (revision.interpreter === 'powershell' ? 'system' : 'root')
).map((value) => (
<option key={value} value={value} disabled={!allowed(auth, value + ':execute')}>{identityNames[value]}</option>
))}
</select>
</label>
</>
)}
</>
@@ -753,12 +758,6 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
<>
{hasLinux && <ScriptFieldsForPlatform script={linux} change={setLinux} auth={auth} windows={false} />}
{hasWindows && <ScriptFieldsForPlatform script={windows} change={setWindows} auth={auth} windows />}
{linux.execution_identity === 'root' && hasLinux && (
<label>
<input type="checkbox" checked={fullRoot} onChange={(e) => setFullRoot(e.target.checked)} />
Vollwartung als root anfordern
</label>
)}
</>
) : (
<p className="warning">
@@ -766,6 +765,9 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, on
Der Agent muss nach dem Neustart wieder Kontakt aufnehmen.
</p>
)}
{mode !== 'reboot' && identity && identity !== 'agent_service' && (
<p className="warning">Der genehmigte Skriptauftrag erhält volle Hostrechte als {identityNames[identity]}.</p>
)}
<label>
Begründung
<input required maxLength={1024} value={reason} onChange={(e) => setReason(e.target.value)} />