<# .SYNOPSIS Audit wszystkich paczek aktualizacji cmsPRO pod katem buggy http:// URL. .DESCRIPTION Skanuje rekursywnie kazdy ZIP w updates/ (cmsPro.zip oraz updates/**/ver_*.zip). Dla kazdego ZIP-a sprawdza czy zawiera pliki kandydujace (autoload/class.S.php, autoload/Shared/Helpers/Helpers.php, autoload/admin/factory/class.Update.php) i czy te pliki zawieraja ciag 'http://www.cmspro.project-dc.pl'. Output: audit-report.md (tabela markdown sortowana po wersji). Skrypt NIE modyfikuje paczek. #> [CmdletBinding()] param( [string]$UpdatesDir = "C:\visual studio code\projekty\cmsPRO\updates", [string]$ReportPath = "C:\visual studio code\projekty\cmsPRO\.paul\phases\04h-hotfix-https-updates\audit-report.md" ) $ErrorActionPreference = "Stop" Add-Type -AssemblyName System.IO.Compression.FileSystem $BuggyPattern = 'http://www.cmspro.project-dc.pl' $SuspectFiles = @( 'autoload/class.S.php', 'autoload/Shared/Helpers/Helpers.php', 'autoload/admin/factory/class.Update.php' ) function Test-ZipForBug { param([string]$ZipPath) $result = [PSCustomObject]@{ Package = (Resolve-Path $ZipPath).Path.Substring($UpdatesDir.Length).TrimStart('\','/') FilesPresent = @() BuggyFiles = @() HasBuggyUrl = $false Action = 'N/A' Error = $null } try { $zip = [System.IO.Compression.ZipFile]::OpenRead($ZipPath) foreach ($entry in $zip.Entries) { $name = $entry.FullName.Replace('\','/') if ($SuspectFiles -contains $name) { $result.FilesPresent += $name $reader = New-Object System.IO.StreamReader($entry.Open()) $content = $reader.ReadToEnd() $reader.Close() if ($content -match [regex]::Escape($BuggyPattern)) { $result.BuggyFiles += $name $result.HasBuggyUrl = $true } } } $zip.Dispose() } catch { $result.Error = $_.Exception.Message } if ($result.HasBuggyUrl) { $result.Action = 'PATCH' } elseif ($result.FilesPresent) { $result.Action = 'OK (already https)' } else { $result.Action = 'N/A (no suspect files)' } return $result } Write-Host "Skanuje $UpdatesDir ..." -ForegroundColor Cyan $zips = @() $baseInstall = Join-Path $UpdatesDir 'cmsPro.zip' if (Test-Path $baseInstall) { $zips += $baseInstall } $zips += Get-ChildItem -Path $UpdatesDir -Filter 'ver_*.zip' -Recurse | Sort-Object FullName | ForEach-Object { $_.FullName } Write-Host "Znaleziono $($zips.Count) paczek." -ForegroundColor Cyan $results = @() $i = 0 foreach ($zip in $zips) { $i++ Write-Progress -Activity "Audit paczek" -Status "$i / $($zips.Count): $(Split-Path $zip -Leaf)" -PercentComplete (($i / $zips.Count) * 100) $results += Test-ZipForBug -ZipPath $zip } Write-Progress -Activity "Audit paczek" -Completed # --- Raport --- $buggy = $results | Where-Object { $_.HasBuggyUrl } $ok = $results | Where-Object { $_.FilesPresent -and -not $_.HasBuggyUrl } $none = $results | Where-Object { -not $_.FilesPresent } $errored = $results | Where-Object { $_.Error } $lines = @() $lines += '# Audit Report: paczki aktualizacji cmsPRO (HTTP -> HTTPS bug)' $lines += '' $lines += "**Data:** $(Get-Date -Format 'yyyy-MM-dd HH:mm')" $lines += "**Katalog:** ``$UpdatesDir``" $lines += "**Wzorzec buggy:** ``$BuggyPattern``" $lines += '' $lines += '## Podsumowanie' $lines += '' $lines += "| Kategoria | Liczba |" $lines += "|-----------|--------|" $lines += "| Paczek przeskanowanych | $($results.Count) |" $lines += "| **PATCH (buggy http://)** | **$($buggy.Count)** |" $lines += "| OK (juz https albo brak URL) | $($ok.Count) |" $lines += "| N/A (brak plikow podejrzanych) | $($none.Count) |" $lines += "| Bledy | $($errored.Count) |" $lines += '' $lines += '## Paczki wymagajace patcha (HasBuggyUrl=true)' $lines += '' if ($buggy) { $lines += '| # | Paczka | Buggy pliki |' $lines += '|---|--------|-------------|' $idx = 0 foreach ($r in $buggy) { $idx++ $lines += "| $idx | ``$($r.Package)`` | $($r.BuggyFiles -join ', ') |" } } else { $lines += '_Brak paczek do patcha._' } $lines += '' $lines += '## Paczki zawierajace pliki ale juz na https (OK)' $lines += '' if ($ok) { $lines += '| # | Paczka | Pliki obecne |' $lines += '|---|--------|--------------|' $idx = 0 foreach ($r in $ok) { $idx++ $lines += "| $idx | ``$($r.Package)`` | $($r.FilesPresent -join ', ') |" } } else { $lines += '_Brak._' } $lines += '' $lines += '## Bledy odczytu' $lines += '' if ($errored) { foreach ($r in $errored) { $lines += "- ``$($r.Package)`` -- $($r.Error)" } } else { $lines += '_Brak._' } $lines += '' $lines += '## Pelna lista (raw)' $lines += '' $lines += '| Paczka | FilesPresent | HasBuggyUrl | Action |' $lines += '|--------|--------------|-------------|--------|' foreach ($r in $results) { $files = if ($r.FilesPresent) { ($r.FilesPresent -join '; ') } else { '-' } $lines += "| ``$($r.Package)`` | $files | $($r.HasBuggyUrl) | $($r.Action) |" } $utf8 = New-Object System.Text.UTF8Encoding $false [System.IO.File]::WriteAllText($ReportPath, ($lines -join "`r`n"), $utf8) Write-Host "" Write-Host "Audit zakonczony." -ForegroundColor Green Write-Host " Paczek: $($results.Count)" Write-Host " Do patcha: $($buggy.Count)" -ForegroundColor Yellow Write-Host " OK: $($ok.Count)" Write-Host " N/A: $($none.Count)" Write-Host " Bledy: $($errored.Count)" Write-Host "Raport: $ReportPath" -ForegroundColor Cyan