$ErrorActionPreference = "Stop";
trap { $host.SetShouldExit(1) }

Write-Host "Running pre-start"

$PORT="<%= p("diego.rep.enable_legacy_api_endpoints") ? p("diego.rep.listen_addr").sub(/^0\.0\.0\.0:/, "") : p("diego.rep.listen_addr_admin").sub(/^127\.0\.0\.1:/, "")%>"

if ($PORT -eq "") {
  Write-Error "Unable to find the port for rep_windows"
}
if (-Not (Get-NetFirewallRule | Where-Object { $_.DisplayName -eq "RepPort" })) {
  New-NetFirewallRule -DisplayName "RepPort" -Action Allow -Direction Inbound -Enabled True -LocalPort $PORT -Protocol TCP
  if (-Not (Get-NetFirewallRule | Where-Object { $_.DisplayName -eq "RepPort" })) {
    Write-Error "Unable to add RepPort firewall rule"
  }
}

$ErrorActionPreference = "Stop";
trap { $host.SetShouldExit(1) }

Write-Host "Running pre-start"

$PORT="<%= p("diego.rep.enable_legacy_api_endpoints") ? p("diego.rep.listen_addr").sub(/^0\.0\.0\.0:/, "") : p("diego.rep.listen_addr_admin").sub(/^127\.0\.0\.1:/, "")%>"

if ($PORT -eq "") {
  Write-Error "Unable to find the port for rep_windows"
}
if (-Not (Get-NetFirewallRule | Where-Object { $_.DisplayName -eq "RepPort" })) {
  New-NetFirewallRule -DisplayName "RepPort" -Action Allow -Direction Inbound -Enabled True -LocalPort $PORT -Protocol TCP
  if (-Not (Get-NetFirewallRule | Where-Object { $_.DisplayName -eq "RepPort" })) {
    Write-Error "Unable to add RepPort firewall rule"
  }
}

$PORT="<%= p("diego.rep.listen_addr_securable").match(/:(\d+)/)[1]%>"

if ($PORT -eq "") {
  Write-Error "Unable to find the listen_addr_securable port for rep_windows"
}
if (-Not (Get-NetFirewallRule | Where-Object { $_.DisplayName -eq "SecureRepPort" })) {
  New-NetFirewallRule -DisplayName "SecureRepPort" -Action Allow -Direction Inbound -Enabled True -LocalPort $PORT -Protocol TCP
  if (-Not (Get-NetFirewallRule | Where-Object { $_.DisplayName -eq "SecureRepPort" })) {
    Write-Error "Unable to add RepPort firewall rule"
  }
}

Add windows firewall rule for listen_addr_securable
Add windows firewall rule for listen_addr_securable

vsphere stmecells need to have explicit rule added for accessing rep on
listen_addr_securable.

[#137093839]

Signed-off-by: Amin Jamali <828117156edecfc83d6e458626bc6ccd219cba0e@pivotal.io>
