From 6fa940dd43c1aa7202a8a021f5d3f1ccbad06037 Mon Sep 17 00:00:00 2001 From: PTah Date: Thu, 11 Jun 2026 14:59:17 +1000 Subject: [PATCH] fix: SendDeploySacNotice StrictMode and inline deploy task verify (2.0.29-SAC) Safe ServerDisplayName access for SAC deploy notice; deploy falls back to built-in schtasks XML check when TaskQuery file is missing on NETLOGON. --- Deploy-LoginMonitor.ps1 | 120 +++++++++++++++++++++++++++++++++++++--- Login_Monitor.ps1 | 11 ++-- version.txt | 2 +- 3 files changed, 119 insertions(+), 14 deletions(-) diff --git a/Deploy-LoginMonitor.ps1 b/Deploy-LoginMonitor.ps1 index bb0d522..526bbbb 100644 --- a/Deploy-LoginMonitor.ps1 +++ b/Deploy-LoginMonitor.ps1 @@ -250,6 +250,8 @@ function Copy-RdpMonitorDeployBundle { if (-not (Test-Path -LiteralPath $src)) { if ($rel -eq $SacClientName) { Write-DeployLog "Предупреждение: на шаре нет $SacClientName — SAC недоступен до публикации файла на шару." + } elseif ($rel -eq 'RdpMonitor-TaskQuery.ps1') { + Write-DeployLog "Предупреждение: на шаре нет RdpMonitor-TaskQuery.ps1 — выполните update-rdp-monitor.ps1 на сервере публикации." } continue } @@ -978,6 +980,11 @@ function Import-RdpMonitorDeployTaskQueryModule { $candidates.Add((Join-Path $InstallRoot 'RdpMonitor-TaskQuery.ps1')) | Out-Null if (-not [string]::IsNullOrWhiteSpace($ShareRoot)) { $candidates.Add((Join-Path $ShareRoot 'RdpMonitor-TaskQuery.ps1')) | Out-Null + } + $deployScriptPath = $PSCommandPath + if ([string]::IsNullOrWhiteSpace($deployScriptPath)) { $deployScriptPath = $MyInvocation.MyCommand.Path } + if (-not [string]::IsNullOrWhiteSpace($deployScriptPath)) { + $candidates.Add((Join-Path (Split-Path -Parent $deployScriptPath) 'RdpMonitor-TaskQuery.ps1')) | Out-Null } else { try { $candidates.Add((Join-Path (Resolve-SourceShareRoot) 'RdpMonitor-TaskQuery.ps1')) | Out-Null @@ -993,10 +1000,110 @@ function Import-RdpMonitorDeployTaskQueryModule { return $false } +function Initialize-RdpMonitorDeployTaskQuery { + param([string]$ShareRoot = '') + + if (Get-Command Test-RdpMonitorScheduledTaskNeedsUnlimitedExecutionTimeLimit -ErrorAction SilentlyContinue) { + return $true + } + if (Import-RdpMonitorDeployTaskQueryModule -ShareRoot $ShareRoot) { + return $true + } + + Write-DeployLog "RdpMonitor-TaskQuery.ps1 не найден — deploy использует встроенную проверку schtasks /XML." + . $script:RdpMonitorDeployTaskQueryInlineScript + return $true +} + +$script:RdpMonitorDeployTaskQueryInlineScript = { + function Get-RdpMonitorSchtasksExe { + return Join-Path $env:SystemRoot 'System32\schtasks.exe' + } + + function Get-RdpMonitorScheduledTaskXmlDocument { + param([Parameter(Mandatory = $true)][string]$TaskName) + $exe = Get-RdpMonitorSchtasksExe + $prevEa = $ErrorActionPreference + try { + $ErrorActionPreference = 'SilentlyContinue' + $raw = & $exe /Query /TN $TaskName /XML 2>&1 + if ($LASTEXITCODE -ne 0) { return $null } + $text = ($raw | Out-String).Trim() + if ([string]::IsNullOrWhiteSpace($text)) { return $null } + if ($text -notmatch '(?s)