update
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Wstrzykuje "kotwice fixa" do ver_1.519.zip.
|
||||
|
||||
.DESCRIPTION
|
||||
ver_1.519.zip oryginalnie zawiera tylko class.Articles.php.
|
||||
Dodaje do niego:
|
||||
- autoload/class.S.php z ver_1.518.zip (juz patched, https://)
|
||||
- autoload/admin/factory/class.Update.php z ver_1.517.zip (juz patched, https://)
|
||||
|
||||
Cel: kazda nowa instalacja cmsPRO przechodzaca update do 1.519 dostaje
|
||||
klient HTTPS dla mechanizmu wykrywania nowych wersji.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$UpdatesDir = "C:\visual studio code\projekty\cmsPRO\updates"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
|
||||
$Target = Join-Path $UpdatesDir '1.50\ver_1.519.zip'
|
||||
$SrcS = Join-Path $UpdatesDir '1.50\ver_1.518.zip'
|
||||
$SrcUpd = Join-Path $UpdatesDir '1.50\ver_1.517.zip'
|
||||
|
||||
# Backup target (oddzielny od standardowego .bak po patch-packages.ps1)
|
||||
$bak = "$Target.preanchor.bak"
|
||||
if (-not (Test-Path $bak)) {
|
||||
Copy-Item -LiteralPath $Target -Destination $bak -Force
|
||||
Write-Host "Backup utworzony: $bak" -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
function Read-EntryBytes {
|
||||
param([string]$ZipPath, [string]$EntryName)
|
||||
$zip = [System.IO.Compression.ZipFile]::OpenRead($ZipPath)
|
||||
try {
|
||||
$entry = $zip.Entries | Where-Object { $_.FullName.Replace('\','/') -eq $EntryName } | Select-Object -First 1
|
||||
if (-not $entry) { throw "Entry not found: $EntryName in $ZipPath" }
|
||||
$stream = $entry.Open()
|
||||
$ms = New-Object System.IO.MemoryStream
|
||||
$stream.CopyTo($ms)
|
||||
$stream.Close()
|
||||
return $ms.ToArray()
|
||||
} finally {
|
||||
$zip.Dispose()
|
||||
}
|
||||
}
|
||||
|
||||
function Add-EntryFromBytes {
|
||||
param([string]$ZipPath, [string]$EntryName, [byte[]]$Content)
|
||||
$zip = [System.IO.Compression.ZipFile]::Open($ZipPath, [System.IO.Compression.ZipArchiveMode]::Update)
|
||||
try {
|
||||
# remove existing if present
|
||||
$existing = $zip.Entries | Where-Object { $_.FullName.Replace('\','/') -eq $EntryName } | Select-Object -First 1
|
||||
if ($existing) { $existing.Delete() }
|
||||
$newEntry = $zip.CreateEntry($EntryName, [System.IO.Compression.CompressionLevel]::Optimal)
|
||||
$stream = $newEntry.Open()
|
||||
$stream.Write($Content, 0, $Content.Length)
|
||||
$stream.Close()
|
||||
} finally {
|
||||
$zip.Dispose()
|
||||
}
|
||||
}
|
||||
|
||||
# 1. Read source files
|
||||
Write-Host "Czytam autoload/class.S.php z ver_1.518.zip..." -ForegroundColor Cyan
|
||||
$bytesS = Read-EntryBytes -ZipPath $SrcS -EntryName 'autoload/class.S.php'
|
||||
Write-Host " -> $($bytesS.Length) bytes"
|
||||
|
||||
Write-Host "Czytam autoload/admin/factory/class.Update.php z ver_1.517.zip..." -ForegroundColor Cyan
|
||||
$bytesUpd = Read-EntryBytes -ZipPath $SrcUpd -EntryName 'autoload/admin/factory/class.Update.php'
|
||||
Write-Host " -> $($bytesUpd.Length) bytes"
|
||||
|
||||
# 2. Verify they contain https:// (sanity check)
|
||||
$strS = [System.Text.Encoding]::UTF8.GetString($bytesS)
|
||||
$strUpd = [System.Text.Encoding]::UTF8.GetString($bytesUpd)
|
||||
if ($strS -match 'http://www\.cmspro\.project-dc\.pl' -or $strS -notmatch 'https://www\.cmspro\.project-dc\.pl') {
|
||||
throw "class.S.php z ver_1.518.zip nie jest patched (nadal ma http:// lub brak URL)"
|
||||
}
|
||||
if ($strUpd -match 'http://www\.cmspro\.project-dc\.pl' -or $strUpd -notmatch 'https://www\.cmspro\.project-dc\.pl') {
|
||||
throw "class.Update.php z ver_1.517.zip nie jest patched"
|
||||
}
|
||||
Write-Host "Sanity check OK: oba pliki maja https://" -ForegroundColor Green
|
||||
|
||||
# 3. Inject into ver_1.519.zip
|
||||
Write-Host "Wstrzykuje do ver_1.519.zip..." -ForegroundColor Cyan
|
||||
Add-EntryFromBytes -ZipPath $Target -EntryName 'autoload/class.S.php' -Content $bytesS
|
||||
Add-EntryFromBytes -ZipPath $Target -EntryName 'autoload/admin/factory/class.Update.php' -Content $bytesUpd
|
||||
|
||||
# 4. Verify
|
||||
Write-Host "Weryfikacja..." -ForegroundColor Cyan
|
||||
$zip = [System.IO.Compression.ZipFile]::OpenRead($Target)
|
||||
$entries = $zip.Entries | ForEach-Object { $_.FullName.Replace('\','/') }
|
||||
$zip.Dispose()
|
||||
|
||||
$ok = $true
|
||||
foreach ($req in @('autoload/class.S.php', 'autoload/admin/factory/class.Update.php', 'autoload/admin/controls/class.Articles.php')) {
|
||||
if ($entries -contains $req) {
|
||||
Write-Host " [OK] $req"
|
||||
} else {
|
||||
Write-Host " [MISSING] $req" -ForegroundColor Red
|
||||
$ok = $false
|
||||
}
|
||||
}
|
||||
|
||||
# Re-check no http://
|
||||
$rezip = [System.IO.Compression.ZipFile]::OpenRead($Target)
|
||||
foreach ($e in $rezip.Entries) {
|
||||
$n = $e.FullName.Replace('\','/')
|
||||
if ($n -in @('autoload/class.S.php', 'autoload/admin/factory/class.Update.php')) {
|
||||
$r = New-Object System.IO.StreamReader($e.Open())
|
||||
$c = $r.ReadToEnd(); $r.Close()
|
||||
if ($c -match 'http://www\.cmspro\.project-dc\.pl') {
|
||||
Write-Host " [BUGGY] $n nadal ma http://" -ForegroundColor Red
|
||||
$ok = $false
|
||||
} else {
|
||||
Write-Host " [HTTPS] $n czyste" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
}
|
||||
$rezip.Dispose()
|
||||
|
||||
if ($ok) {
|
||||
$sha = (Get-FileHash -Algorithm SHA256 -Path $Target).Hash.ToLower()
|
||||
Write-Host ""
|
||||
Write-Host "ver_1.519.zip jest teraz kotwica fixa." -ForegroundColor Green
|
||||
Write-Host " SHA256: $sha"
|
||||
} else {
|
||||
Write-Host "Wystapily problemy - sprawdz reczny." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user