diff --git a/migrations/0047_opnsense_library.sql b/migrations/0047_opnsense_library.sql new file mode 100644 index 0000000..4b75e13 --- /dev/null +++ b/migrations/0047_opnsense_library.sql @@ -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 +$$; diff --git a/tests/browser/order-composer.spec.ts b/tests/browser/order-composer.spec.ts index ec19030..add8a33 100644 --- a/tests/browser/order-composer.spec.ts +++ b/tests/browser/order-composer.spec.ts @@ -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); diff --git a/web/src/order-composer.tsx b/web/src/order-composer.tsx index 7cee763..dd65a39 100644 --- a/web/src/order-composer.tsx +++ b/web/src/order-composer.tsx @@ -647,8 +647,8 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu Neustartskript auswählen )} - + {hasOPNsense &&
OPNsense verwendet die POSIX-Shell von FreeBSD. Wählen Sie eine passende Revision; Linux-spezifische Programme wie systemctl stehen hier nicht zur Verfügung.
} {scripts.data && !heads.length &&Für diesen Kunden sind noch keine Skripte veröffentlicht.
} {revision && ( <> diff --git a/web/src/script-catalog.ts b/web/src/script-catalog.ts index 3a1acad..b4b01cb 100644 --- a/web/src/script-catalog.ts +++ b/web/src/script-catalog.ts @@ -14,7 +14,7 @@ export interface Revision extends Script { script_sha256: string; } export const interpreterNames: Record