From 084494cfa8a3dbe3af4f89d3369fc71185d5bc68 Mon Sep 17 00:00:00 2001 From: PTah Date: Mon, 1 Jun 2026 09:08:14 +1000 Subject: [PATCH] fix: SAC JSON serialize daily report without PSMethod cycle 2.0.1-SAC Convert-AnyToJsonSerializable returns plain arrays and skips PSMethod/ScriptBlock instead of Generic.List objects that broke JavaScriptSerializer. Co-authored-by: Cursor --- Login_Monitor.ps1 | 2 +- README.md | 2 +- Sac-Client.ps1 | 35 +++++++++++++++++++++++++++++------ version.txt | 2 +- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Login_Monitor.ps1 b/Login_Monitor.ps1 index a19b3d5..1a38db2 100644 --- a/Login_Monitor.ps1 +++ b/Login_Monitor.ps1 @@ -82,7 +82,7 @@ $script:MonitorStopRequested = $false # строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах). # Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только # исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1). -$ScriptVersion = "2.0.0-SAC" +$ScriptVersion = "2.0.1-SAC" # Логи (все под InstallRoot) $LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log" diff --git a/README.md b/README.md index c261eea..88d626c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ PowerShell-набор для мониторинга входов в Windows с - Документация по развёртыванию: **[Docs/README.md](Docs/README.md)** (RDP-монитор, Exchange, NETLOGON). - **`Encrypt-DpapiForRdpMonitor.ps1`** — опционально для подготовки DPAPI-строк токена/chat id и пароля SMTP (`$MailSmtpPasswordProtectedB64` в файле настроек). - **Локальные настройки RDP-монитора:** **`login_monitor.settings.ps1`** в каталоге установки (образец **`login_monitor.settings.example.ps1`**). При автообновлении **`Login_Monitor.ps1`** с шары файл настроек **не перезаписывается** (как **`exchange_monitor.settings.ps1`** для Exchange). -- **Security Alert Center (SAC):** модуль **`Sac-Client.ps1`** (копируется вместе с `Login_Monitor.ps1`). Режимы **`$UseSAC`**: `off` | `exclusive` | `dual` | `fallback` — контракт в репозитории **security-alert-center** (`docs/agent-integration.md`). Версия релиза: **`$ScriptVersion`** и **`version.txt`** (сейчас **2.0.0-SAC**); **`Sac-Client.ps1`** передаёт ту же версию в SAC (`product_version`). +- **Security Alert Center (SAC):** модуль **`Sac-Client.ps1`** (копируется вместе с `Login_Monitor.ps1`). Режимы **`$UseSAC`**: `off` | `exclusive` | `dual` | `fallback` — контракт в репозитории **security-alert-center** (`docs/agent-integration.md`). Версия релиза: **`$ScriptVersion`** и **`version.txt`** (сейчас **2.0.1-SAC**); **`Sac-Client.ps1`** передаёт ту же версию в SAC (`product_version`). ## Что изменилось (важное) diff --git a/Sac-Client.ps1 b/Sac-Client.ps1 index e49c2fd..522d939 100644 --- a/Sac-Client.ps1 +++ b/Sac-Client.ps1 @@ -170,9 +170,32 @@ function Get-SacOccurredAtIso { function Convert-AnyToJsonSerializable { param($Value) if ($null -eq $Value) { return $null } - if ($Value -is [string] -or $Value -is [bool] -or $Value -is [int] -or $Value -is [long] -or $Value -is [double] -or $Value -is [decimal]) { + if ($Value -is [string] -or $Value -is [bool] -or $Value -is [char]) { return $Value } + if ($Value -is [byte] -or $Value -is [sbyte] -or $Value -is [int16] -or $Value -is [uint16] -or + $Value -is [int] -or $Value -is [uint] -or $Value -is [long] -or $Value -is [ulong] -or + $Value -is [float] -or $Value -is [double] -or $Value -is [decimal]) { + return $Value + } + if ($Value -is [datetime] -or $Value -is [datetimeoffset] -or $Value -is [guid]) { + return [string]$Value + } + if ($Value -is [System.Management.Automation.PSMethod] -or + $Value -is [System.Management.Automation.ScriptBlock] -or + $Value -is [Delegate]) { + return $null + } + if ($Value -is [pscustomobject]) { + $out = @{} + foreach ($prop in $Value.PSObject.Properties) { + if ($prop.MemberType -notin @('NoteProperty', 'Property', 'AliasProperty', 'CodeProperty', 'ScriptProperty')) { + continue + } + $out[$prop.Name] = Convert-AnyToJsonSerializable $prop.Value + } + return $out + } if ($Value -is [hashtable] -or $Value -is [System.Collections.IDictionary]) { $out = @{} foreach ($key in $Value.Keys) { @@ -181,11 +204,11 @@ function Convert-AnyToJsonSerializable { return $out } if ($Value -is [System.Collections.IEnumerable]) { - $list = New-Object System.Collections.Generic.List[object] - foreach ($item in $Value) { - $list.Add((Convert-AnyToJsonSerializable $item)) | Out-Null - } - return $list + return ,@( + foreach ($item in $Value) { + Convert-AnyToJsonSerializable $item + } + ) } return [string]$Value } diff --git a/version.txt b/version.txt index feaa960..a6515ba 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.0.0-SAC +2.0.1-SAC