fix: review GATE A — reemplazo de contrasenas sin 3er operando y ANSI 5.1-compat

- wordpress/deploy.ps1: -replace no acepta tercer operando (count) en
  ninguna version de PS; bucle linea a linea (1a = root, 2a = MYSQL_PASSWORD)
- los 4 deploy.ps1: escape ANSI con [char]27 en vez de backtick-e
  (incompatible con Windows PowerShell 5.1); guard solo con NO_COLOR
This commit is contained in:
hermes committed 2026-09-12 18:56:00 +02:00
1 parent 0d07146162
commit 6c3a594a14
4 files changed
+32 -13

No files matched your search

+4 -2
View File
@@ -15,8 +15,10 @@ param(
$ErrorActionPreference = 'Stop'
$Green = "`e[32m"; $Cyan = "`e[36m"; $Yellow = "`e[33m"; $Red = "`e[31m"; $Bold = "`e[1m"; $NC = "`e[0m"
if ($env:NO_COLOR -or -not $PSStyle) {
# Escape ANSI via [char]27 (compatible con Windows PowerShell 5.1 y PS 7+)
$Esc = [char]27
$Green = "$Esc[32m"; $Cyan = "$Esc[36m"; $Yellow = "$Esc[33m"; $Red = "$Esc[31m"; $Bold = "$Esc[1m"; $NC = "$Esc[0m"
if ($env:NO_COLOR) {
$Green = $Cyan = $Yellow = $Red = $Bold = $NC = ''
}
+4 -2
View File
@@ -15,8 +15,10 @@ param(
$ErrorActionPreference = 'Stop'
$Green = "`e[32m"; $Cyan = "`e[36m"; $Yellow = "`e[33m"; $Red = "`e[31m"; $Bold = "`e[1m"; $NC = "`e[0m"
if ($env:NO_COLOR -or -not $PSStyle) {
# Escape ANSI via [char]27 (compatible con Windows PowerShell 5.1 y PS 7+)
$Esc = [char]27
$Green = "$Esc[32m"; $Cyan = "$Esc[36m"; $Yellow = "$Esc[33m"; $Red = "$Esc[31m"; $Bold = "$Esc[1m"; $NC = "$Esc[0m"
if ($env:NO_COLOR) {
$Green = $Cyan = $Yellow = $Red = $Bold = $NC = ''
}
+4 -2
View File
@@ -15,8 +15,10 @@ param(
$ErrorActionPreference = 'Stop'
$Green = "`e[32m"; $Cyan = "`e[36m"; $Yellow = "`e[33m"; $Red = "`e[31m"; $Bold = "`e[1m"; $NC = "`e[0m"
if ($env:NO_COLOR -or -not $PSStyle) {
# Escape ANSI via [char]27 (compatible con Windows PowerShell 5.1 y PS 7+)
$Esc = [char]27
$Green = "$Esc[32m"; $Cyan = "$Esc[36m"; $Yellow = "$Esc[33m"; $Red = "$Esc[31m"; $Bold = "$Esc[1m"; $NC = "$Esc[0m"
if ($env:NO_COLOR) {
$Green = $Cyan = $Yellow = $Red = $Bold = $NC = ''
}
+20 -7
View File
@@ -15,8 +15,10 @@ param(
$ErrorActionPreference = 'Stop'
$Green = "`e[32m"; $Cyan = "`e[36m"; $Yellow = "`e[33m"; $Red = "`e[31m"; $Bold = "`e[1m"; $NC = "`e[0m"
if ($env:NO_COLOR -or -not $PSStyle) {
# Escape ANSI via [char]27 (compatible con Windows PowerShell 5.1 y PS 7+)
$Esc = [char]27
$Green = "$Esc[32m"; $Cyan = "$Esc[36m"; $Yellow = "$Esc[33m"; $Red = "$Esc[31m"; $Bold = "$Esc[1m"; $NC = "$Esc[0m"
if ($env:NO_COLOR) {
$Green = $Cyan = $Yellow = $Red = $Bold = $NC = ''
}
@@ -92,11 +94,22 @@ if (-not (Test-Path $EnvFile)) {
$rng.GetBytes($Bytes); $WpPass = ($Bytes | ForEach-Object { $_.ToString('x2') }) -join ''
$rng.Dispose()
# La 1a coincidencia es MYSQL_ROOT_PASSWORD, la 2a MYSQL_PASSWORD (orden del .env.example)
$Content = Get-Content $EnvFile -Raw
$Content = $Content -replace 'change-me-to-a-strong-password', $RootPass, 1
$Content = $Content -replace 'change-me-to-a-strong-password', $WpPass, 1
Set-Content $EnvFile -Value $Content -NoNewline
# 1a coincidencia en el fichero = MYSQL_ROOT_PASSWORD, 2a = MYSQL_PASSWORD.
# -replace no acepta tercer operando (count) en ninguna version de PS,
# asi que se recorre linea a linea.
$Lines = Get-Content $EnvFile
$Replaced = 0
for ($i = 0; $i -lt $Lines.Count; $i++) {
if ($Lines[$i] -like '*change-me-to-a-strong-password*') {
if ($Replaced -eq 0) {
$Lines[$i] = $Lines[$i] -replace 'change-me-to-a-strong-password', $RootPass
} else {
$Lines[$i] = $Lines[$i] -replace 'change-me-to-a-strong-password', $WpPass
}
$Replaced++
}
}
Set-Content $EnvFile -Value $Lines
Info "Contrasenas generadas en $EnvFile"
}