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:
132
tests/debug/test-bit-order-in-codewords.php
Normal file
132
tests/debug/test-bit-order-in-codewords.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use App\Framework\QrCode\QrCodeGenerator;
|
||||
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 "=== Testing Bit Order in Codewords ===\n\n";
|
||||
|
||||
$testData = 'HELLO WORLD';
|
||||
$config = new QrCodeConfig(
|
||||
version: QrCodeVersion::fromNumber(1),
|
||||
errorCorrectionLevel: ErrorCorrectionLevel::M,
|
||||
encodingMode: EncodingMode::BYTE
|
||||
);
|
||||
|
||||
// Expected encoding:
|
||||
// Mode: 0100 (4 bits)
|
||||
// Count: 00001011 (8 bits = 11)
|
||||
// So first codeword should be: 01000000 = 64
|
||||
|
||||
echo "Expected encoding:\n";
|
||||
echo " Mode (4 bits): 0100\n";
|
||||
echo " Count (8 bits): 00001011\n";
|
||||
echo " First codeword (8 bits): 01000000 = 64\n\n";
|
||||
|
||||
// But wait - if we read bits MSB-first, the first codeword should contain:
|
||||
// Bits 0-7: 01000000 = 64
|
||||
// But mode indicator is only 4 bits, so we need to look at the first 4 bits only
|
||||
|
||||
// Let's check what we actually get
|
||||
$matrix = QrCodeGenerator::generate($testData, $config);
|
||||
$size = $matrix->getSize();
|
||||
|
||||
// Extract format info
|
||||
$formatCols = [0, 1, 2, 3, 4, 5, 7, 8, $size - 1, $size - 2, $size - 3, $size - 4, $size - 5, $size - 6, $size - 7];
|
||||
$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];
|
||||
}
|
||||
|
||||
$maskBits = substr($unmasked, 2, 3);
|
||||
$maskPattern = bindec($maskBits);
|
||||
|
||||
use App\Framework\QrCode\Masking\MaskPattern as MaskPatternEnum;
|
||||
|
||||
$mask = match($maskPattern) {
|
||||
0 => MaskPatternEnum::PATTERN_0,
|
||||
1 => MaskPatternEnum::PATTERN_1,
|
||||
2 => MaskPatternEnum::PATTERN_2,
|
||||
3 => MaskPatternEnum::PATTERN_3,
|
||||
4 => MaskPatternEnum::PATTERN_4,
|
||||
5 => MaskPatternEnum::PATTERN_5,
|
||||
6 => MaskPatternEnum::PATTERN_6,
|
||||
7 => MaskPatternEnum::PATTERN_7,
|
||||
};
|
||||
|
||||
// Read first 16 bits (mode + count)
|
||||
$dataBits = [];
|
||||
$bitCount = 0;
|
||||
|
||||
for ($col = $size - 1; $col >= 1 && $bitCount < 16; $col -= 2) {
|
||||
if ($col === 6) {
|
||||
$col--;
|
||||
}
|
||||
|
||||
$upward = ((int) (($size - 1 - $col) / 2) % 2) === 0;
|
||||
|
||||
for ($i = 0; $i < $size && $bitCount < 16; $i++) {
|
||||
$row = $upward ? ($size - 1 - $i) : $i;
|
||||
|
||||
for ($c = 0; $c < 2 && $bitCount < 16; $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;
|
||||
}
|
||||
|
||||
$maskedBit = $matrix->getModuleAt($row, $currentCol)->isDark() ? 1 : 0;
|
||||
$unmaskedBit = $mask->shouldInvert($row, $currentCol) ? (1 - $maskedBit) : $maskedBit;
|
||||
$dataBits[] = $unmaskedBit;
|
||||
$bitCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$bitString = implode('', $dataBits);
|
||||
echo "First 16 bits read: {$bitString}\n";
|
||||
|
||||
// First 4 bits = mode
|
||||
$modeBits = substr($bitString, 0, 4);
|
||||
$mode = bindec($modeBits);
|
||||
echo " Mode (bits 0-3): {$modeBits} = {$mode} (expected: 0100 = 4)\n";
|
||||
|
||||
// Next 8 bits = count
|
||||
$countBits = substr($bitString, 4, 8);
|
||||
$count = bindec($countBits);
|
||||
echo " Count (bits 4-11): {$countBits} = {$count} (expected: 00001011 = 11)\n\n";
|
||||
|
||||
if ($mode === 4 && $count === 11) {
|
||||
echo "✅ Mode and count are CORRECT!\n";
|
||||
echo "\nThe problem is that we're reading whole codewords (8 bits) instead of\n";
|
||||
echo "reading the mode indicator (4 bits) separately!\n";
|
||||
} else {
|
||||
echo "❌ Mode or count is WRONG!\n";
|
||||
}
|
||||
|
||||
// Now let's see what the first codeword actually is
|
||||
$firstCodewordBits = substr($bitString, 0, 8);
|
||||
$firstCodeword = bindec($firstCodewordBits);
|
||||
echo "\nFirst codeword (bits 0-7): {$firstCodewordBits} = {$firstCodeword}\n";
|
||||
echo "This is WRONG because it includes mode (4 bits) + part of count (4 bits)\n";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user