refactor(deployment): Remove WireGuard VPN dependency and restore public service access
Remove WireGuard integration from production deployment to simplify infrastructure: - Remove docker-compose-direct-access.yml (VPN-bound services) - Remove VPN-only middlewares from Grafana, Prometheus, Portainer - Remove WireGuard middleware definitions from Traefik - Remove WireGuard IPs (10.8.0.0/24) from Traefik forwarded headers All monitoring services now publicly accessible via subdomains: - grafana.michaelschiemer.de (with Grafana native auth) - prometheus.michaelschiemer.de (with Basic Auth) - portainer.michaelschiemer.de (with Portainer native auth) All services use Let's Encrypt SSL certificates via Traefik.
This commit is contained in:
196
tests/debug/test-data-placement-validation.php
Normal file
196
tests/debug/test-data-placement-validation.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use App\Framework\QrCode\QrCodeGenerator;
|
||||
use App\Framework\QrCode\ErrorCorrection\ReedSolomonEncoder;
|
||||
use App\Framework\QrCode\ValueObjects\ErrorCorrectionLevel;
|
||||
use App\Framework\QrCode\ValueObjects\QrCodeConfig;
|
||||
use App\Framework\QrCode\ValueObjects\QrCodeVersion;
|
||||
use App\Framework\QrCode\ValueObjects\EncodingMode;
|
||||
|
||||
echo "=== Data Placement Validation ===\n\n";
|
||||
|
||||
$testData = 'HELLO WORLD';
|
||||
$config = new QrCodeConfig(
|
||||
version: QrCodeVersion::fromNumber(1),
|
||||
errorCorrectionLevel: ErrorCorrectionLevel::M,
|
||||
encodingMode: EncodingMode::BYTE
|
||||
);
|
||||
|
||||
$matrix = QrCodeGenerator::generate($testData, $config);
|
||||
|
||||
// Get expected data codewords
|
||||
$ecInfo = ReedSolomonEncoder::getECInfo(1, 'M');
|
||||
echo "Data codewords: {$ecInfo['dataCodewords']}\n";
|
||||
echo "EC codewords: {$ecInfo['ecCodewords']}\n";
|
||||
echo "Total codewords: {$ecInfo['totalCodewords']}\n\n";
|
||||
|
||||
// Verify data can be read back from matrix
|
||||
echo "=== Reading Data from Matrix ===\n";
|
||||
|
||||
// We need to:
|
||||
// 1. Read format info to get mask pattern
|
||||
// 2. Read data bits from matrix (in correct order)
|
||||
// 3. Unmask the data
|
||||
// 4. Decode to get original data
|
||||
|
||||
// Step 1: Read format info
|
||||
$formatCols = [0, 1, 2, 3, 4, 5, 7, 8, 20, 19, 18, 17, 16, 15, 14];
|
||||
$formatH = '';
|
||||
foreach ($formatCols as $col) {
|
||||
$formatH .= $matrix->getModuleAt(8, $col)->isDark() ? '1' : '0';
|
||||
}
|
||||
|
||||
$xorMask = '101010000010010';
|
||||
$unmasked = '';
|
||||
for ($i = 0; $i < 15; $i++) {
|
||||
$unmasked .= (int)$formatH[$i] ^ (int)$xorMask[$i];
|
||||
}
|
||||
|
||||
$maskPattern = bindec(substr($unmasked, 2, 3));
|
||||
echo "Mask Pattern: {$maskPattern}\n\n";
|
||||
|
||||
// Step 2: Read data bits from matrix (in placement order)
|
||||
// ISO/IEC 18004 Section 7.7.3: Column pairs, right-to-left, zig-zag up/down
|
||||
$size = $matrix->getSize();
|
||||
$dataBits = '';
|
||||
$bitCount = 0;
|
||||
$maxBits = $ecInfo['totalCodewords'] * 8;
|
||||
|
||||
for ($col = $size - 1; $col >= 1; $col -= 2) {
|
||||
if ($col === 6) {
|
||||
$col--;
|
||||
}
|
||||
|
||||
$upward = ((int) (($size - 1 - $col) / 2) % 2) === 0;
|
||||
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$row = $upward ? ($size - 1 - $i) : $i;
|
||||
|
||||
for ($c = 0; $c < 2; $c++) {
|
||||
$currentCol = $col - $c;
|
||||
|
||||
// Skip function patterns
|
||||
if (
|
||||
($row <= 8 && $currentCol <= 8) ||
|
||||
($row <= 7 && $currentCol >= $size - 8) ||
|
||||
($row >= $size - 8 && $currentCol <= 7) ||
|
||||
$row === 6 || $currentCol === 6 ||
|
||||
($row === 8 && (($currentCol >= 0 && $currentCol <= 5) || $currentCol === 7 || $currentCol === 8 || $currentCol >= $size - 8)) ||
|
||||
($currentCol === 8 && (($row >= 0 && $row <= 5) || $row === 7 || $row === 8 || $row >= $size - 7)) ||
|
||||
($row === 13 && $currentCol === 8) // Dark module
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($bitCount < $maxBits) {
|
||||
$isDark = $matrix->getModuleAt($row, $currentCol)->isDark();
|
||||
$dataBits .= $isDark ? '1' : '0';
|
||||
$bitCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "Read {$bitCount} bits from matrix\n";
|
||||
echo "Expected: {$maxBits} bits\n\n";
|
||||
|
||||
// Step 3: Unmask the data
|
||||
require_once __DIR__ . '/../../src/Framework/QrCode/Masking/MaskPattern.php';
|
||||
use App\Framework\QrCode\Masking\MaskPattern;
|
||||
|
||||
$maskPatternEnum = MaskPattern::from($maskPattern);
|
||||
$unmaskedBits = '';
|
||||
$bitIndex = 0;
|
||||
|
||||
// Re-read with unmasking
|
||||
for ($col = $size - 1; $col >= 1; $col -= 2) {
|
||||
if ($col === 6) {
|
||||
$col--;
|
||||
}
|
||||
|
||||
$upward = ((int) (($size - 1 - $col) / 2) % 2) === 0;
|
||||
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$row = $upward ? ($size - 1 - $i) : $i;
|
||||
|
||||
for ($c = 0; $c < 2; $c++) {
|
||||
$currentCol = $col - $c;
|
||||
|
||||
// Skip function patterns
|
||||
if (
|
||||
($row <= 8 && $currentCol <= 8) ||
|
||||
($row <= 7 && $currentCol >= $size - 8) ||
|
||||
($row >= $size - 8 && $currentCol <= 7) ||
|
||||
$row === 6 || $currentCol === 6 ||
|
||||
($row === 8 && (($currentCol >= 0 && $currentCol <= 5) || $currentCol === 7 || $currentCol === 8 || $currentCol >= $size - 8)) ||
|
||||
($currentCol === 8 && (($row >= 0 && $row <= 5) || $row === 7 || $row === 8 || $row >= $size - 7)) ||
|
||||
($row === 13 && $currentCol === 8)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($bitIndex < $maxBits) {
|
||||
$isDark = $matrix->getModuleAt($row, $currentCol)->isDark();
|
||||
|
||||
// Unmask if mask pattern says to invert
|
||||
if ($maskPatternEnum->shouldInvert($row, $currentCol)) {
|
||||
$isDark = !$isDark;
|
||||
}
|
||||
|
||||
$unmaskedBits .= $isDark ? '1' : '0';
|
||||
$bitIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "Unmasked bits: {$bitIndex} bits\n\n";
|
||||
|
||||
// Step 4: Decode data
|
||||
// First 4 bits: Mode indicator
|
||||
$modeBits = substr($unmaskedBits, 0, 4);
|
||||
echo "Mode indicator (bits 0-3): {$modeBits}\n";
|
||||
|
||||
if ($modeBits === '0100') {
|
||||
echo "✅ Mode indicator correct (Byte mode)\n";
|
||||
} else {
|
||||
echo "❌ Mode indicator incorrect (expected 0100, got {$modeBits})\n";
|
||||
}
|
||||
|
||||
// Next 8 bits: Character count
|
||||
$countBits = substr($unmaskedBits, 4, 8);
|
||||
$count = bindec($countBits);
|
||||
echo "Character count (bits 4-11): {$countBits} = {$count}\n";
|
||||
echo "Expected: " . strlen($testData) . "\n";
|
||||
|
||||
if ($count === strlen($testData)) {
|
||||
echo "✅ Character count correct\n";
|
||||
} else {
|
||||
echo "❌ Character count incorrect\n";
|
||||
}
|
||||
|
||||
// Next: Data bytes
|
||||
echo "\nData bytes:\n";
|
||||
$dataStart = 12;
|
||||
for ($i = 0; $i < min($count, 11); $i++) {
|
||||
$byteBits = substr($unmaskedBits, $dataStart + $i * 8, 8);
|
||||
$byte = bindec($byteBits);
|
||||
$char = chr($byte);
|
||||
|
||||
$expected = $testData[$i] ?? '';
|
||||
$expectedByte = $expected ? ord($expected) : 0;
|
||||
|
||||
echo " Byte {$i}: {$byteBits} = {$byte} ('{$char}')";
|
||||
|
||||
if ($byte === $expectedByte) {
|
||||
echo " ✅\n";
|
||||
} else {
|
||||
echo " ❌ (expected: " . str_pad(decbin($expectedByte), 8, '0', STR_PAD_LEFT) . " = {$expectedByte} ('{$expected}'))\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user