Add daily scans and Ninja burst mode
This commit is contained in:
@@ -9,6 +9,7 @@ param(
|
||||
[string]$UploadMode = "auto",
|
||||
[string]$VulnerabilityCsvPath = "",
|
||||
[string]$MirrorRoot = "",
|
||||
[switch]$SuppressTriggerExit,
|
||||
[ValidateSet("status", "attack-only", "cve-critical", "attack-plus-cve")]
|
||||
[string]$Mode = "status"
|
||||
)
|
||||
@@ -227,8 +228,8 @@ Write-Host "Total CVEs: $totalCves"
|
||||
Write-Host "Report: $outputFullPath"
|
||||
Write-Host "Runner exit code: $runnerExitCode"
|
||||
|
||||
if ($monitorTriggered) {
|
||||
if ($monitorTriggered -and -not $SuppressTriggerExit) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
exit 0
|
||||
exit $runnerExitCode
|
||||
|
||||
50
scripts/run-ocsentinel-scheduled.ps1
Normal file
50
scripts/run-ocsentinel-scheduled.ps1
Normal file
@@ -0,0 +1,50 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[ValidateSet("daily", "burst")]
|
||||
[string]$Kind = "daily"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$monitorScript = Join-Path $scriptDir "run-ocsentinel-monitor.ps1"
|
||||
$secretPath = "C:\ProgramData\OCSentinel\secrets\ocsentinel-upload-secret.dat"
|
||||
$mutexName = "Global\OfficeComSentinelScan"
|
||||
|
||||
function Get-NinjaBurstEnabled {
|
||||
if (Get-Command -Name "Get-NinjaProperty" -ErrorAction SilentlyContinue) {
|
||||
return [bool](Get-NinjaProperty -Name "ocsentinelburst" -Type "Checkbox")
|
||||
}
|
||||
|
||||
if (Get-Command -Name "Ninja-Property-Get" -ErrorAction SilentlyContinue) {
|
||||
$value = Ninja-Property-Get -Name "ocsentinelburst"
|
||||
return [string]$value -match "^(1|true|yes)$"
|
||||
}
|
||||
|
||||
Write-Warning "Ninja custom-field reader is unavailable; burst scan skipped."
|
||||
return $false
|
||||
}
|
||||
|
||||
if ($Kind -eq "burst" -and -not (Get-NinjaBurstEnabled)) {
|
||||
Write-Host "OfficeCom Sentinel burst check: disabled."
|
||||
exit 0
|
||||
}
|
||||
|
||||
$createdNew = $false
|
||||
$mutex = [Threading.Mutex]::new($false, $mutexName, [ref]$createdNew)
|
||||
try {
|
||||
if (-not $mutex.WaitOne(0)) {
|
||||
Write-Host "OfficeCom Sentinel scan skipped: another scan is already running."
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Host "OfficeCom Sentinel scheduled $Kind scan started."
|
||||
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $monitorScript -Mode status -UploadMode required -SecretPath $secretPath -SuppressTriggerExit
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
finally {
|
||||
if ($null -ne $mutex) {
|
||||
try { $mutex.ReleaseMutex() } catch { }
|
||||
$mutex.Dispose()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user