# =====================================================
# УСТАНОВКА ЭЦП ПРЕДСЕДАТЕЛЯ
# Контейнер копируется в HDIMAGE, сертификат устанавливается
# =====================================================
# === НАСТРОЙКИ ===
$ServerShare = "\\10.0.2.21\Disk_M\ОБМЕН\fss_ecp"
$NetContainerPath = "$ServerShare\fssrpred.000"
$NetCertPath = "$ServerShare\cert_pred.cer"
$ContainerName = "fssrpred"
# === ЛОКАЛЬНЫЕ ПУТИ ===
$LocalAppData = [Environment]::GetFolderPath("LocalApplicationData")
$CryptoProPath = Join-Path $LocalAppData "Crypto-Pro"
$LocalContainerPath = Join-Path $CryptoProPath $ContainerName
$MarkerFile = Join-Path $LocalAppData "Clinic_Chairman_Deployed_v1.txt"
$LogFile = Join-Path $LocalAppData "Clinic_Chairman_Deploy.log"
# === ФУНКЦИЯ ЛОГИРОВАНИЯ ===
function Write-Log {
param([string]$Message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Add-Content -Path $LogFile -Value "$timestamp | $env:COMPUTERNAME | $env:USERNAME | $Message" -ErrorAction SilentlyContinue
}
# === ПРОВЕРКА: УЖЕ УСТАНОВЛЕНО? ===
if (Test-Path $MarkerFile) { Exit }
Write-Log "=== НАЧАЛО УСТАНОВКИ ==="
# === ШАГ 1: ПРОВЕРКА СЕТЕВЫХ РЕСУРСОВ ===
if (-not (Test-Path $NetContainerPath)) {
Write-Log "ОШИБКА: Контейнер не найден: $NetContainerPath"
Exit
}
if (-not (Test-Path $NetCertPath)) {
Write-Log "ОШИБКА: Сертификат не найден: $NetCertPath"
Exit
}
Write-Log "Сетевые ресурсы доступны"
# === ШАГ 2: КОПИРОВАНИЕ КОНТЕЙНЕРА В HDIMAGE ===
try {
if (-not (Test-Path $CryptoProPath)) {
New-Item -Path $CryptoProPath -ItemType Directory -Force | Out-Null
}
if (-not (Test-Path $LocalContainerPath)) {
New-Item -Path $LocalContainerPath -ItemType Directory -Force | Out-Null
}
Copy-Item -Path "$NetContainerPath\*" -Destination $LocalContainerPath -Force -Recurse
$filesCount = (Get-ChildItem -Path $LocalContainerPath -File).Count
Write-Log "Контейнер скопирован в $LocalContainerPath (файлов: $filesCount)"
if ($filesCount -eq 0) {
Write-Log "ОШИБКА: Файлы не скопировались"
Exit
}
} catch {
Write-Log "ОШИБКА копирования: $_"
Exit
}
# === ШАГ 3: ИМПОРТ СЕРТИФИКАТА ===
try {
certutil.exe -user -addstore "My" $NetCertPath | Out-Null
Write-Log "Сертификат импортирован в хранилище"
$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" |
Where-Object { $_.NotAfter -gt (Get-Date) } |
Select-Object -First 1
if ($cert) {
Write-Log "Сертификат: $($cert.Subject)"
}
} catch {
Write-Log "ОШИБКА импорта сертификата: $_"
}
# === ШАГ 4: МАРКЕР ===
New-Item -Path $MarkerFile -ItemType File -Force | Out-Null
Write-Log "=== УСТАНОВКА ЗАВЕРШЕНА ==="
Write-Log ""
Write-Log "Контейнер находится: $LocalContainerPath"
Write-Log ""
Write-Log "Если КриптоПро не видит контейнер:"
Write-Log "1. КриптоПро CSP → Сервис → Установить личный сертификат"
Write-Log "2. Обзор → выберите primary.key из папки выше"
Write-Log "3. Далее → Готово"