From b97b554f84f9b5abcd17d5facc57c9e9f41a896e Mon Sep 17 00:00:00 2001 From: OfficeCom Codex Date: Sat, 25 Jul 2026 20:58:54 +0200 Subject: [PATCH] Add NinjaOne client configuration and upload test --- scripts/configure-ocsentinel-ninja.ps1 | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 scripts/configure-ocsentinel-ninja.ps1 diff --git a/scripts/configure-ocsentinel-ninja.ps1 b/scripts/configure-ocsentinel-ninja.ps1 new file mode 100644 index 0000000..f200d5a --- /dev/null +++ b/scripts/configure-ocsentinel-ninja.ps1 @@ -0,0 +1,58 @@ +[CmdletBinding()] +param( + [string]$WebhookUrl = "", + [string]$SecretValue = "" +) + +$ErrorActionPreference = "Stop" + +function Get-NinjaValue { + param([Parameter(Mandatory)][string]$Name) + + $value = [Environment]::GetEnvironmentVariable($Name, "Process") + return if ($null -eq $value) { "" } else { $value.Trim() } +} + +if ([string]::IsNullOrWhiteSpace($WebhookUrl)) { + $WebhookUrl = Get-NinjaValue -Name "webhookurl" +} + +if ([string]::IsNullOrWhiteSpace($SecretValue)) { + $SecretValue = Get-NinjaValue -Name "secretvalue" +} + +if ([string]::IsNullOrWhiteSpace($WebhookUrl) -or [string]::IsNullOrWhiteSpace($SecretValue)) { + throw "WebhookUrl and SecretValue must be supplied as NinjaOne script variables." +} + +$installRoot = Join-Path $env:ProgramFiles "OCSentinel" +$configPath = Join-Path $installRoot "config\ocsentinel-client.json" +$secretScript = Join-Path $installRoot "scripts\protect-ocsentinel-secret.ps1" +$monitorScript = Join-Path $installRoot "scripts\run-ocsentinel-monitor.ps1" +$secretPath = "C:\ProgramData\OCSentinel\secrets\ocsentinel-upload-secret.dat" + +foreach ($path in @($configPath, $secretScript, $monitorScript)) { + if (-not (Test-Path -LiteralPath $path)) { + throw "OCSentinel installation is incomplete. Missing: $path" + } +} + +$config = Get-Content -LiteralPath $configPath -Raw | ConvertFrom-Json +$config.n8nWebhookUrl = $WebhookUrl +$config.environment = "production" +$config | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $configPath -Encoding UTF8 +Write-Host "OCSentinel upload endpoint configured." + +& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $secretScript -SecretValue $SecretValue +if ($LASTEXITCODE -ne 0) { + throw "Writing the protected upload secret failed with code $LASTEXITCODE" +} + +Write-Host "Running signed OCSentinel test scan and upload." +& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $monitorScript ` + -Mode status ` + -ClientConfigPath $configPath ` + -SecretPath $secretPath ` + -UploadMode required + +exit $LASTEXITCODE