Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

47 рядки
2.1KB

  1. param(
  2. [Parameter(Mandatory = $true)][string]$RequestPath,
  3. [Parameter(Mandatory = $true)][string]$ResultPath
  4. )
  5. $ErrorActionPreference = 'Stop'
  6. $result = @{ Success = $false; Output = ''; Error = '' }
  7. try {
  8. $projectRoot = Split-Path -Parent $PSScriptRoot
  9. $tempRoot = [System.IO.Path]::GetFullPath((Join-Path $projectRoot 'temp'))
  10. foreach ($path in @($RequestPath, $ResultPath)) {
  11. $resolved = [System.IO.Path]::GetFullPath($path)
  12. if (-not $resolved.StartsWith($tempRoot + [System.IO.Path]::DirectorySeparatorChar,
  13. [StringComparison]::OrdinalIgnoreCase)) {
  14. throw 'Hidden helper files must be under the project temp folder'
  15. }
  16. }
  17. $request = Get-Content -LiteralPath $RequestPath -Raw -Encoding UTF8 | ConvertFrom-Json
  18. $allowed = @('test-smtp-message.ps1', 'import-template.ps1', 'preview-template.ps1',
  19. 'review-campaign.ps1', 'send-campaign-test.ps1', 'approve-campaign.ps1',
  20. 'dispatch-control.ps1', 'dispatch-once.ps1', 'send-approved-campaign-test.ps1',
  21. 'export-report.ps1')
  22. if ($request.ScriptName -notin $allowed) { throw 'Unsupported hidden helper script' }
  23. $scriptPath = Join-Path $PSScriptRoot $request.ScriptName
  24. if (-not (Test-Path -LiteralPath $scriptPath -PathType Leaf)) {
  25. throw 'Hidden helper script is missing'
  26. }
  27. $parameters = @{ ConfigPath = [string]$request.ConfigPath }
  28. foreach ($property in $request.Parameters.PSObject.Properties) {
  29. if ($property.Name -notmatch '^[A-Za-z][A-Za-z0-9]*$' -or
  30. $property.Name -eq 'ConfigPath') { throw 'Invalid hidden helper parameter' }
  31. $parameters[$property.Name] = $property.Value
  32. }
  33. $result.Output = ((& $scriptPath @parameters | Out-String).Trim())
  34. $result.Success = $true
  35. }
  36. catch {
  37. $result.Error = $_.Exception.Message
  38. }
  39. finally {
  40. $json = ConvertTo-Json -InputObject $result -Compress -Depth 4
  41. $temporaryPath = $ResultPath + '.writing'
  42. [System.IO.File]::WriteAllText($temporaryPath, $json,
  43. (New-Object System.Text.UTF8Encoding($false)))
  44. [System.IO.File]::Move($temporaryPath, $ResultPath)
  45. }
  46. if (-not $result.Success) { exit 1 }

Powered by TurnKey Linux.