fix: InstallTasks before DPAPI, deploy elevation and installtasks logs (1.4.1)
This commit is contained in:
+32
-1
@@ -33,6 +33,18 @@ param(
|
|||||||
Set-StrictMode -Version Latest
|
Set-StrictMode -Version Latest
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
function Test-DeployRunningElevated {
|
||||||
|
try {
|
||||||
|
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||||
|
# LocalSystem (GPO startup / задачи SYSTEM): не всегда даёт true на BuiltInRole::Administrator.
|
||||||
|
if ($null -ne $id.User -and $id.User.Value -eq 'S-1-5-18') { return $true }
|
||||||
|
$p = New-Object Security.Principal.WindowsPrincipal($id)
|
||||||
|
return $p.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||||
|
} catch {
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$InstallRoot = [System.IO.Path]::GetFullPath("$env:ProgramData\RDP-login-monitor")
|
$InstallRoot = [System.IO.Path]::GetFullPath("$env:ProgramData\RDP-login-monitor")
|
||||||
$LocalScript = Join-Path $InstallRoot "Login_Monitor.ps1"
|
$LocalScript = Join-Path $InstallRoot "Login_Monitor.ps1"
|
||||||
$VersionStampPath = Join-Path $InstallRoot "deployed_version.txt"
|
$VersionStampPath = Join-Path $InstallRoot "deployed_version.txt"
|
||||||
@@ -206,6 +218,11 @@ try {
|
|||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (-not (Test-DeployRunningElevated)) {
|
||||||
|
Write-DeployLog "ОШИБКА: запустите Deploy из повышенной консоли PowerShell («Запуск от имени администратора»). Без этого дочерний Login_Monitor.ps1 -InstallTasks завершится с кодом 1 (нет прав на регистрацию задач)."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
Stop-RdpLoginMonitorMainProcesses
|
Stop-RdpLoginMonitorMainProcesses
|
||||||
|
|
||||||
Copy-Item -LiteralPath $sourceScript -Destination $LocalScript -Force
|
Copy-Item -LiteralPath $sourceScript -Destination $LocalScript -Force
|
||||||
@@ -214,9 +231,23 @@ try {
|
|||||||
$installArgs = @(
|
$installArgs = @(
|
||||||
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $LocalScript, '-InstallTasks'
|
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $LocalScript, '-InstallTasks'
|
||||||
)
|
)
|
||||||
$p = Start-Process -FilePath $PsExe -ArgumentList $installArgs -Wait -PassThru -WindowStyle Hidden
|
$instOut = Join-Path $InstallRoot "Logs\deploy_installtasks_stdout.log"
|
||||||
|
$instErr = Join-Path $InstallRoot "Logs\deploy_installtasks_stderr.log"
|
||||||
|
$p = Start-Process -FilePath $PsExe -ArgumentList $installArgs -Wait -PassThru -WindowStyle Hidden `
|
||||||
|
-RedirectStandardOutput $instOut -RedirectStandardError $instErr
|
||||||
if ($p.ExitCode -ne 0) {
|
if ($p.ExitCode -ne 0) {
|
||||||
Write-DeployLog "Предупреждение: InstallTasks завершился с кодом $($p.ExitCode)."
|
Write-DeployLog "Предупреждение: InstallTasks завершился с кодом $($p.ExitCode)."
|
||||||
|
foreach ($pair in @(@($instOut, 'stdout'), @($instErr, 'stderr'))) {
|
||||||
|
$lp = $pair[0]
|
||||||
|
$lbl = $pair[1]
|
||||||
|
if (Test-Path -LiteralPath $lp) {
|
||||||
|
$tail = Get-Content -LiteralPath $lp -Tail 40 -ErrorAction SilentlyContinue
|
||||||
|
if ($tail) {
|
||||||
|
Write-DeployLog "InstallTasks $lbl (хвост): $($tail -join ' | ')"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-DeployLog "Подсказка: полный вывод в Logs\deploy_installtasks_*.log; также см. login_monitor.log за это время."
|
||||||
} else {
|
} else {
|
||||||
Write-DeployLog "InstallTasks выполнен (код 0)."
|
Write-DeployLog "InstallTasks выполнен (код 0)."
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-18
@@ -69,7 +69,7 @@ $script:MonitorSingletonLockStream = $null
|
|||||||
# строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах).
|
# строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах).
|
||||||
# Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только
|
# Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только
|
||||||
# исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1).
|
# исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1).
|
||||||
$ScriptVersion = "1.4.0"
|
$ScriptVersion = "1.4.1"
|
||||||
|
|
||||||
# Логи (все под InstallRoot)
|
# Логи (все под InstallRoot)
|
||||||
$LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log"
|
$LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log"
|
||||||
@@ -491,6 +491,24 @@ function Start-RdpMonitorWatchdogMain {
|
|||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Watchdog и InstallTasks — до DPAPI/Telegram: Deploy вызывает -InstallTasks без зависимости от секретов на машине.
|
||||||
|
if ($Watchdog) {
|
||||||
|
Start-RdpMonitorWatchdogMain
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($InstallTasks) {
|
||||||
|
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||||
|
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
|
||||||
|
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||||||
|
Write-Log "InstallTasks: нужны права администратора."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Register-RdpMonitorScheduledTasksCore
|
||||||
|
Write-Log "InstallTasks: задачи планировщика обновлены."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
# --- Учётные данные Telegram (открытый текст или DPAPI Base64) ---
|
# --- Учётные данные Telegram (открытый текст или DPAPI Base64) ---
|
||||||
if (-not [string]::IsNullOrWhiteSpace($TelegramBotTokenProtectedB64)) {
|
if (-not [string]::IsNullOrWhiteSpace($TelegramBotTokenProtectedB64)) {
|
||||||
try {
|
try {
|
||||||
@@ -511,23 +529,6 @@ if (-not [string]::IsNullOrWhiteSpace($TelegramChatIDProtectedB64)) {
|
|||||||
if ($TelegramBotToken -eq '<TELEGRAM_BOT_TOKEN>') { $TelegramBotToken = "" }
|
if ($TelegramBotToken -eq '<TELEGRAM_BOT_TOKEN>') { $TelegramBotToken = "" }
|
||||||
if ($TelegramChatID -eq '<TELEGRAM_CHAT_ID>') { $TelegramChatID = "" }
|
if ($TelegramChatID -eq '<TELEGRAM_CHAT_ID>') { $TelegramChatID = "" }
|
||||||
|
|
||||||
if ($Watchdog) {
|
|
||||||
Start-RdpMonitorWatchdogMain
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($InstallTasks) {
|
|
||||||
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
|
|
||||||
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
|
|
||||||
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
||||||
Write-Log "InstallTasks: нужны права администратора."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
Register-RdpMonitorScheduledTasksCore
|
|
||||||
Write-Log "InstallTasks: задачи планировщика обновлены."
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function ConvertTo-TelegramHtml {
|
function ConvertTo-TelegramHtml {
|
||||||
param([string]$Text)
|
param([string]$Text)
|
||||||
if ($null -eq $Text) { return '' }
|
if ($null -eq $Text) { return '' }
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
1.4.0
|
1.4.1
|
||||||
|
|||||||
Reference in New Issue
Block a user