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.
126 lines
3.9 KiB
PHP
126 lines
3.9 KiB
PHP
<?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 Fix ===\n\n";
|
|
|
|
$testData = 'HELLO WORLD';
|
|
$config = new QrCodeConfig(
|
|
version: QrCodeVersion::fromNumber(1),
|
|
errorCorrectionLevel: ErrorCorrectionLevel::M,
|
|
encodingMode: EncodingMode::BYTE
|
|
);
|
|
|
|
// Manually encode to see what bits we expect
|
|
echo "Manual encoding:\n";
|
|
echo "Mode indicator (Byte): 0100\n";
|
|
echo "Character count (11): " . str_pad(decbin(11), 8, '0', STR_PAD_LEFT) . "\n";
|
|
echo "Data 'H': " . str_pad(decbin(ord('H')), 8, '0', STR_PAD_LEFT) . "\n";
|
|
echo "Data 'E': " . str_pad(decbin(ord('E')), 8, '0', STR_PAD_LEFT) . "\n\n";
|
|
|
|
$expectedFirstBits = "0100" . str_pad(decbin(11), 8, '0', STR_PAD_LEFT) . str_pad(decbin(ord('H')), 8, '0', STR_PAD_LEFT);
|
|
echo "Expected first 20 bits: {$expectedFirstBits}\n\n";
|
|
|
|
// Generate matrix
|
|
$matrix = QrCodeGenerator::generate($testData, $config);
|
|
$size = $matrix->getSize();
|
|
|
|
// Extract format info to get mask pattern
|
|
$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);
|
|
|
|
echo "Detected mask pattern: {$maskPattern}\n\n";
|
|
|
|
// Read actual bits
|
|
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,
|
|
};
|
|
|
|
$actualBits = '';
|
|
$bitCount = 0;
|
|
|
|
for ($col = $size - 1; $col >= 1 && $bitCount < 20; $col -= 2) {
|
|
if ($col === 6) {
|
|
$col--;
|
|
}
|
|
|
|
$upward = ((int) (($size - 1 - $col) / 2) % 2) === 0;
|
|
|
|
for ($i = 0; $i < $size && $bitCount < 20; $i++) {
|
|
$row = $upward ? ($size - 1 - $i) : $i;
|
|
|
|
// Read in same order as placement: right column first, then left
|
|
for ($c = 0; $c < 2 && $bitCount < 20; $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;
|
|
}
|
|
|
|
// Read and unmask
|
|
$maskedBit = $matrix->getModuleAt($row, $currentCol)->isDark() ? 1 : 0;
|
|
$unmaskedBit = $mask->shouldInvert($row, $currentCol) ? (1 - $maskedBit) : $maskedBit;
|
|
$actualBits .= (string)$unmaskedBit;
|
|
$bitCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
echo "Actual first 20 bits: {$actualBits}\n\n";
|
|
|
|
// Compare
|
|
$matches = 0;
|
|
for ($i = 0; $i < 20; $i++) {
|
|
if ($expectedFirstBits[$i] === $actualBits[$i]) {
|
|
$matches++;
|
|
} else {
|
|
echo "Bit {$i}: expected {$expectedFirstBits[$i]}, got {$actualBits[$i]}\n";
|
|
}
|
|
}
|
|
|
|
echo "\nMatch: {$matches}/20 bits\n";
|
|
|
|
if ($matches === 20) {
|
|
echo "✅ CORRECT!\n";
|
|
} else {
|
|
echo "❌ Still wrong\n";
|
|
}
|
|
|
|
|