No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

73 líneas
3.1KB

  1. [CmdletBinding()]
  2. param(
  3. [string]$SiteName = 'WscMvc',
  4. [string]$PoolName = 'WscMvc',
  5. [string]$PhysicalPath,
  6. [int]$Port = 8090
  7. )
  8. $ErrorActionPreference = 'Stop'
  9. Import-Module WebAdministration
  10. if (-not $PhysicalPath) {
  11. # IIS's site root is the "public" folder only - Framework/Controllers/
  12. # tests/tools/docs/logs are siblings of it, never served. See
  13. # docs/ARCHITECTURE.md.
  14. $PhysicalPath = Join-Path (Split-Path -Parent $PSScriptRoot) 'public'
  15. }
  16. if (-not (Test-Path $PhysicalPath)) {
  17. throw "PhysicalPath does not exist: $PhysicalPath"
  18. }
  19. if (-not (Test-Path "IIS:\AppPools\$PoolName")) {
  20. New-WebAppPool -Name $PoolName | Out-Null
  21. Set-ItemProperty "IIS:\AppPools\$PoolName" -Name managedRuntimeVersion -Value ''
  22. Set-ItemProperty "IIS:\AppPools\$PoolName" -Name enable32BitAppOnWin64 -Value $false
  23. Write-Output "Created app pool $PoolName (64-bit, no managed code)"
  24. } else {
  25. Write-Output "App pool $PoolName already exists"
  26. }
  27. if (-not (Test-Path "IIS:\Sites\$SiteName")) {
  28. New-Website -Name $SiteName -Port $Port -PhysicalPath $PhysicalPath -ApplicationPool $PoolName | Out-Null
  29. Write-Output "Created site $SiteName on port $Port -> $PhysicalPath"
  30. } else {
  31. $existingPath = (Get-Website -Name $SiteName).PhysicalPath
  32. if ($existingPath -ne $PhysicalPath) {
  33. Set-ItemProperty "IIS:\Sites\$SiteName" -Name physicalPath -Value $PhysicalPath
  34. Write-Output "Site $SiteName already existed; updated physicalPath $existingPath -> $PhysicalPath"
  35. } else {
  36. Write-Output "Site $SiteName already exists with the correct physicalPath"
  37. }
  38. }
  39. # Default.asp needs Server.MapPath("../logs") to reach logs/, which lives
  40. # outside the "public" webroot by design. Scoped to just this site via
  41. # /commit:apphost (writes a <location path="SiteName"> block in
  42. # applicationHost.config) rather than unlocking system.webServer/asp
  43. # machine-wide, which would affect every site on the host. See
  44. # docs/DECISIONS.md for why the machine-wide unlock approach is avoided.
  45. $appcmd = "$env:windir\system32\inetsrv\appcmd.exe"
  46. & $appcmd set config $SiteName -section:system.webServer/asp "/enableParentPaths:True" /commit:apphost | Out-Null
  47. $parentPathsNow = & $appcmd list config $SiteName -section:system.webServer/asp
  48. Write-Output "enableParentPaths config: $parentPathsNow"
  49. # logs/ is a sibling of $PhysicalPath (see Default.asp's Server.MapPath("../logs")).
  50. # Classic ASP impersonates IUSR for anonymous requests on this host - grant it
  51. # (via IIS_IUSRS) write access scoped to exactly this folder, nothing else.
  52. # Idempotent: re-running icacls /grant is safe, it doesn't duplicate the ACE.
  53. $logsPath = Join-Path (Split-Path -Parent $PhysicalPath) 'logs'
  54. if (-not (Test-Path $logsPath)) {
  55. New-Item -ItemType Directory -Path $logsPath | Out-Null
  56. Write-Output "Created $logsPath"
  57. }
  58. & icacls $logsPath /grant "IIS_IUSRS:(OI)(CI)M" | Out-Null
  59. Write-Output "Granted IIS_IUSRS write access on $logsPath"
  60. Start-WebAppPool -Name $PoolName -ErrorAction SilentlyContinue
  61. Start-Website -Name $SiteName -ErrorAction SilentlyContinue
  62. Get-Website -Name $SiteName | Select-Object Name, State, PhysicalPath, ApplicationPool

Powered by TurnKey Linux.