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.
150 lines
4.6 KiB
PHP
150 lines
4.6 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 "=== Full Decode Test (Correct Interpretation) ===\n\n";
|
|
|
|
$testData = 'HELLO WORLD';
|
|
$config = new QrCodeConfig(
|
|
version: QrCodeVersion::fromNumber(1),
|
|
errorCorrectionLevel: ErrorCorrectionLevel::M,
|
|
encodingMode: EncodingMode::BYTE
|
|
);
|
|
|
|
echo "Test data: '{$testData}'\n\n";
|
|
|
|
$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 ALL data bits
|
|
$dataBits = [];
|
|
$bitCount = 0;
|
|
|
|
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;
|
|
}
|
|
|
|
$maskedBit = $matrix->getModuleAt($row, $currentCol)->isDark() ? 1 : 0;
|
|
$unmaskedBit = $mask->shouldInvert($row, $currentCol) ? (1 - $maskedBit) : $maskedBit;
|
|
$dataBits[] = $unmaskedBit;
|
|
$bitCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
$bitString = implode('', $dataBits);
|
|
echo "Read {$bitCount} data bits\n\n";
|
|
|
|
// Decode correctly:
|
|
// 1. Mode indicator (4 bits)
|
|
$modeBits = substr($bitString, 0, 4);
|
|
$mode = bindec($modeBits);
|
|
echo "Mode (bits 0-3): {$modeBits} = {$mode} (expected: 4)\n";
|
|
|
|
if ($mode !== 4) {
|
|
echo "❌ Mode is wrong!\n";
|
|
exit(1);
|
|
}
|
|
|
|
// 2. Character count (8 bits for version 1-9 byte mode)
|
|
$countBits = substr($bitString, 4, 8);
|
|
$count = bindec($countBits);
|
|
echo "Count (bits 4-11): {$countBits} = {$count} (expected: " . strlen($testData) . ")\n";
|
|
|
|
if ($count !== strlen($testData)) {
|
|
echo "❌ Count is wrong!\n";
|
|
exit(1);
|
|
}
|
|
|
|
// 3. Data bytes (8 bits each)
|
|
$dataStart = 12; // After mode (4) + count (8)
|
|
$decodedData = '';
|
|
for ($i = 0; $i < $count; $i++) {
|
|
$byteStart = $dataStart + ($i * 8);
|
|
if ($byteStart + 8 <= strlen($bitString)) {
|
|
$byteBits = substr($bitString, $byteStart, 8);
|
|
$byte = bindec($byteBits);
|
|
$decodedData .= chr($byte);
|
|
}
|
|
}
|
|
|
|
echo "\nDecoded data: '{$decodedData}'\n";
|
|
echo "Expected data: '{$testData}'\n";
|
|
|
|
if ($decodedData === $testData) {
|
|
echo "✅ DECODING IS CORRECT!\n";
|
|
echo "\nThis means the QR code structure is correct.\n";
|
|
echo "If it still doesn't scan, the issue might be:\n";
|
|
echo "1. Reed-Solomon error correction (EC codewords)\n";
|
|
echo "2. SVG rendering (Quiet Zone, module size)\n";
|
|
echo "3. Some scanner apps require specific implementations\n";
|
|
} else {
|
|
echo "❌ Decoded data doesn't match!\n";
|
|
echo "First difference at position: ";
|
|
for ($i = 0; $i < min(strlen($decodedData), strlen($testData)); $i++) {
|
|
if ($decodedData[$i] !== $testData[$i]) {
|
|
echo "{$i} (got '{$decodedData[$i]}' (ord: " . ord($decodedData[$i]) . "), expected '{$testData[$i]}' (ord: " . ord($testData[$i]) . "))\n";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|