Seed versioned OPNsense scripts and label the shared POSIX interpreter
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
-- As with the Linux/Windows starting revisions, preserve any existing customer revision.
|
||||
CREATE FUNCTION seed_opnsense_scripts(target_tenant uuid) RETURNS void
|
||||
LANGUAGE plpgsql SET search_path = pg_catalog, public AS $$
|
||||
DECLARE previous_tenant text := coalesce(current_setting('app.tenant_id', true), '');
|
||||
BEGIN
|
||||
PERFORM set_config('app.tenant_id', target_tenant::text, true);
|
||||
INSERT INTO public.script_revisions(tenant_id,name,version,interpreter,execution_identity,created_by,script_utf8)
|
||||
SELECT target_tenant,name,1,'posix_sh',identity,'system:bootstrap',body
|
||||
FROM (VALUES
|
||||
('OPNsense · Version und Ausführungskonto','agent_service',$sh$#!/bin/sh
|
||||
set -eu
|
||||
/usr/local/sbin/opnsense-version
|
||||
/usr/bin/uname -sr
|
||||
/usr/bin/id
|
||||
$sh$),
|
||||
('OPNsense · Aktive Firewallregeln anzeigen','root',$sh$#!/bin/sh
|
||||
set -eu
|
||||
[ -x /usr/local/sbin/opnsense-version ]
|
||||
exec /sbin/pfctl -sr
|
||||
$sh$)) AS scripts(name,identity,body)
|
||||
ON CONFLICT (tenant_id,name,version) DO NOTHING;
|
||||
PERFORM set_config('app.tenant_id', previous_tenant, true);
|
||||
END
|
||||
$$;
|
||||
REVOKE ALL ON FUNCTION seed_opnsense_scripts(uuid) FROM PUBLIC;
|
||||
|
||||
CREATE OR REPLACE FUNCTION seed_tenant_script_library() RETURNS trigger
|
||||
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, public AS $$
|
||||
DECLARE previous_tenant text := coalesce(current_setting('app.tenant_id', true), '');
|
||||
BEGIN
|
||||
PERFORM set_config('app.tenant_id', NEW.tenant_id::text, true);
|
||||
PERFORM public.seed_windows_update_script(NEW.tenant_id);
|
||||
PERFORM public.seed_standard_diagnostic_scripts(NEW.tenant_id);
|
||||
PERFORM public.seed_restart_scripts(NEW.tenant_id);
|
||||
PERFORM public.seed_windows_restart_receipt(NEW.tenant_id);
|
||||
PERFORM public.seed_opnsense_scripts(NEW.tenant_id);
|
||||
PERFORM set_config('app.tenant_id', previous_tenant, true);
|
||||
RETURN NEW;
|
||||
END
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
LOCK TABLE tenants IN SHARE ROW EXCLUSIVE MODE;
|
||||
PERFORM public.seed_opnsense_scripts(tenant_id) FROM tenants;
|
||||
END
|
||||
$$;
|
||||
@@ -568,7 +568,7 @@ test('publishes versions in the library and keeps the earlier script readable',
|
||||
await page.getByRole('button', { name: 'Version veröffentlichen' }).click();
|
||||
await expect(page.getByRole('status')).toContainText('Version 2 veröffentlicht.');
|
||||
await page.getByText('Frühere Versionen (1)').click();
|
||||
await page.getByText('Version 1 · Linux · Shell · Agent-Dienstkonto').click();
|
||||
await page.getByText('Version 1 · POSIX-Shell · Agent-Dienstkonto').click();
|
||||
await expect(page.locator('pre').filter({ hasText: 'uname -s' })).toBeVisible();
|
||||
await page.getByRole('button', { name: 'Zur Skriptbibliothek' }).click();
|
||||
await expect(page.getByRole('row').filter({ hasText: script.name })).toHaveCount(1);
|
||||
|
||||
@@ -647,8 +647,8 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
Neustartskript auswählen
|
||||
</button>
|
||||
)}
|
||||
<label>
|
||||
Bibliotheksskript
|
||||
<label>
|
||||
Bibliotheksskript
|
||||
<select
|
||||
required
|
||||
value={revision?.name ?? ''}
|
||||
@@ -663,7 +663,8 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</label>
|
||||
{hasOPNsense && <p className="muted">OPNsense verwendet die POSIX-Shell von FreeBSD. Wählen Sie eine passende Revision; Linux-spezifische Programme wie systemctl stehen hier nicht zur Verfügung.</p>}
|
||||
{scripts.data && !heads.length && <p>Für diesen Kunden sind noch keine Skripte veröffentlicht.</p>}
|
||||
{revision && (
|
||||
<>
|
||||
|
||||
@@ -14,7 +14,7 @@ export interface Revision extends Script {
|
||||
script_sha256: string;
|
||||
}
|
||||
export const interpreterNames: Record<Interpreter, string> = {
|
||||
posix_sh: 'Linux · Shell',
|
||||
posix_sh: 'POSIX-Shell',
|
||||
bash: 'Linux · Bash',
|
||||
powershell: 'Windows · PowerShell'
|
||||
};
|
||||
|
||||
@@ -117,7 +117,7 @@ export function ScriptLibrary({ tenantId, auth }: { tenantId: string; auth: Sess
|
||||
const latest = versions[0];
|
||||
const query = search.trim().normalize('NFC').toLocaleLowerCase('de');
|
||||
const shown = latestRevisions(library.data ?? []).filter((item) =>
|
||||
(!platform || scriptPlatform(item.interpreter) === platform) &&
|
||||
(!platform || (platform==='opnsense' ? item.interpreter==='posix_sh' : scriptPlatform(item.interpreter) === platform)) &&
|
||||
item.name.normalize('NFC').toLocaleLowerCase('de').includes(query));
|
||||
function edit(existing?: Revision) {
|
||||
setBase(existing?.version ?? 0);
|
||||
@@ -258,7 +258,8 @@ export function ScriptLibrary({ tenantId, auth }: { tenantId: string; auth: Sess
|
||||
<label><span>Plattform</span>
|
||||
<select aria-label="Plattform" value={platform} onChange={e => setPlatform(e.target.value)}>
|
||||
<option value="">Alle Plattformen</option>
|
||||
<option value="linux">Linux</option>
|
||||
<option value="linux">Linux</option>
|
||||
<option value="opnsense">OPNsense (POSIX-Shell)</option>
|
||||
<option value="windows">Windows</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
Reference in New Issue
Block a user