fix func script
This commit is contained in:
parent
b6605b4706
commit
d2a4108139
|
|
@ -13,13 +13,13 @@ $ThumbprintFile = "$CertStorePath\thumbprint.txt"
|
|||
$RdpSign = "$env:SystemRoot\System32\rdpsign.exe"
|
||||
# ===============================
|
||||
|
||||
# Фикс TLS для Windows Server (обязательно!)
|
||||
# Фикс TLS для Windows Server
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13
|
||||
|
||||
# Проверка прав администратора
|
||||
$IsAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
|
||||
|
||||
# Цвета и форматирование
|
||||
# Цвета
|
||||
$HeaderColor = "Cyan"
|
||||
$SuccessColor = "Green"
|
||||
$ErrorColor = "Red"
|
||||
|
|
@ -38,7 +38,6 @@ function Get-Thumbprint {
|
|||
if (Test-Path $ThumbprintFile) {
|
||||
return (Get-Content $ThumbprintFile -Raw).Trim()
|
||||
}
|
||||
# Пробуем найти установленный сертификат по субъекту
|
||||
$Cert = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -like "*Help-D*" } | Select-Object -First 1
|
||||
if ($Cert) { return $Cert.Thumbprint }
|
||||
return $null
|
||||
|
|
@ -53,12 +52,10 @@ function Install-Certificate {
|
|||
return
|
||||
}
|
||||
|
||||
# Создание папки
|
||||
if (-not (Test-Path $CertStorePath)) {
|
||||
New-Item -ItemType Directory -Path $CertStorePath -Force | Out-Null
|
||||
}
|
||||
|
||||
# Скачивание PFX
|
||||
$CertUrl = "$GiteaUrl/$RepoPath/$CertFileName"
|
||||
$CertPath = "$CertStorePath\$CertFileName"
|
||||
|
||||
|
|
@ -72,7 +69,6 @@ function Install-Certificate {
|
|||
return
|
||||
}
|
||||
|
||||
# Установка
|
||||
Write-Host "`n🔐 Установка в хранилища..." -ForegroundColor $GrayColor
|
||||
$SecurePass = ConvertTo-SecureString -String $CertPassword -AsPlainText -Force
|
||||
|
||||
|
|
@ -103,7 +99,6 @@ function Install-Certificate {
|
|||
}
|
||||
}
|
||||
|
||||
# Очистка PFX
|
||||
Remove-Item $CertPath -Force -ErrorAction SilentlyContinue
|
||||
Write-Host "`n🗑️ PFX-файл удалён (безопасность)" -ForegroundColor $GrayColor
|
||||
Write-Host "`n✅ Установка завершена!" -ForegroundColor $SuccessColor
|
||||
|
|
@ -139,7 +134,6 @@ function Sign-RdpFiles {
|
|||
$FileName = Split-Path $File -Leaf
|
||||
Write-Host " 📝 $FileName ... " -NoNewline -ForegroundColor $GrayColor
|
||||
|
||||
# Пробуем SHA256 → SHA1
|
||||
$Args = "/sha256", $Thumb, $File
|
||||
& $RdpSign @Args 2>&1 | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
|
|
@ -165,19 +159,16 @@ function Sign-AllDesktopRdp {
|
|||
|
||||
$Files = @()
|
||||
|
||||
# Рабочий стол текущего пользователя
|
||||
$CurrentUserDesktop = [Environment]::GetFolderPath("Desktop")
|
||||
if (Test-Path $CurrentUserDesktop) {
|
||||
$Files += Get-ChildItem -Path $CurrentUserDesktop -Filter "*.rdp" -File | Select-Object -ExpandProperty FullName
|
||||
}
|
||||
|
||||
# Рабочие столы всех пользователей (Public + профили)
|
||||
$PublicDesktop = "C:\Users\Public\Desktop"
|
||||
if (Test-Path $PublicDesktop) {
|
||||
$Files += Get-ChildItem -Path $PublicDesktop -Filter "*.rdp" -File | Select-Object -ExpandProperty FullName
|
||||
}
|
||||
|
||||
# Сканируем C:\Users\*\Desktop
|
||||
$UserFolders = Get-ChildItem "C:\Users" -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -notmatch "Public|Default|All Users" }
|
||||
foreach ($User in $UserFolders) {
|
||||
$UserDesktop = "$($User.FullName)\Desktop"
|
||||
|
|
@ -186,15 +177,12 @@ function Sign-AllDesktopRdp {
|
|||
}
|
||||
}
|
||||
|
||||
# RemoteApp: Packaged Programs
|
||||
$RemoteAppPath = "C:\Program Files\Packaged Programs"
|
||||
if (Test-Path $RemoteAppPath) {
|
||||
$Files += Get-ChildItem -Path $RemoteAppPath -Filter "*.rdp" -File -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
|
||||
# Также ищем .msc файлы для RemoteApp (если нужно)
|
||||
$Files += Get-ChildItem -Path $RemoteAppPath -Filter "*.msc" -File -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
|
||||
}
|
||||
|
||||
# Убираем дубликаты
|
||||
$Files = $Files | Select-Object -Unique
|
||||
|
||||
if ($Files.Count -eq 0) {
|
||||
|
|
@ -260,7 +248,6 @@ function Remove-Certificate {
|
|||
}
|
||||
}
|
||||
|
||||
# Удаляем файл с отпечатком
|
||||
if (Test-Path $ThumbprintFile) {
|
||||
Remove-Item $ThumbprintFile -Force
|
||||
Write-Host " ✅ Удалён файл отпечатка" -ForegroundColor $SuccessColor
|
||||
|
|
@ -276,7 +263,10 @@ function Check-Certificate {
|
|||
$Thumb = Get-Thumbprint
|
||||
|
||||
Write-Host "📋 Информация:" -ForegroundColor $HeaderColor
|
||||
Write-Host " Отпечаток (из файла): $($Thumb ?? 'не найден')" -ForegroundColor $GrayColor
|
||||
|
||||
# PS 5.1 совместимая проверка
|
||||
$ThumbDisplay = if ($Thumb) { $Thumb } else { "не найден" }
|
||||
Write-Host " Отпечаток (из файла): $ThumbDisplay" -ForegroundColor $GrayColor
|
||||
|
||||
$Stores = @{
|
||||
"LocalMachine\My" = "Приватный ключ (для подписи)"
|
||||
|
|
@ -287,13 +277,13 @@ function Check-Certificate {
|
|||
foreach ($StoreName in $Stores.Keys) {
|
||||
$Store = "Cert:\LocalMachine\$StoreName"
|
||||
$Cert = Get-ChildItem $Store -ErrorAction SilentlyContinue | Where-Object { $_.Thumbprint -eq $Thumb }
|
||||
$Status = if ($Cert) { "✅ Установлен" } else { "❌ Не найден" }
|
||||
$Color = if ($Cert) { $SuccessColor } else { $ErrorColor }
|
||||
Write-Host " $($Stores[$StoreName]): " -NoNewline
|
||||
Write-Host "$Status" -ForegroundColor $Color
|
||||
if ($Cert) {
|
||||
Write-Host " $($Stores[$StoreName]): ✅ Установлен" -ForegroundColor $SuccessColor
|
||||
} else {
|
||||
Write-Host " $($Stores[$StoreName]): ❌ Не найден" -ForegroundColor $ErrorColor
|
||||
}
|
||||
}
|
||||
|
||||
# Проверка rdpsign.exe
|
||||
Write-Host "`n🔧 Инструменты:" -ForegroundColor $HeaderColor
|
||||
if (Test-Path $RdpSign) {
|
||||
Write-Host " rdpsign.exe: ✅ Найден" -ForegroundColor $SuccessColor
|
||||
|
|
|
|||
Loading…
Reference in New Issue