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.
155 lines
4.7 KiB
PHP
155 lines
4.7 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 "=== Complete QR Code Decode Test ===\n\n";
|
|
|
|
// Test with simple known data
|
|
$testData = 'HELLO WORLD';
|
|
$config = new QrCodeConfig(
|
|
version: QrCodeVersion::fromNumber(1),
|
|
errorCorrectionLevel: ErrorCorrectionLevel::M,
|
|
encodingMode: EncodingMode::BYTE
|
|
);
|
|
|
|
echo "Test data: '{$testData}'\n";
|
|
echo "Expected mode: 4 (Byte mode)\n";
|
|
echo "Expected count: " . strlen($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);
|
|
|
|
echo "Mask pattern: {$maskPattern}\n\n";
|
|
|
|
// Read ALL data bits (not just first 20)
|
|
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,
|
|
};
|
|
|
|
$dataBits = [];
|
|
$bitCount = 0;
|
|
|
|
// Read in placement order
|
|
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++;
|
|
}
|
|
}
|
|
}
|
|
|
|
echo "Read {$bitCount} data bits\n";
|
|
|
|
// Convert to codewords
|
|
$codewords = [];
|
|
for ($i = 0; $i < count($dataBits); $i += 8) {
|
|
if ($i + 8 <= count($dataBits)) {
|
|
$byte = '';
|
|
for ($j = 0; $j < 8; $j++) {
|
|
$byte .= (string)$dataBits[$i + $j];
|
|
}
|
|
$codewords[] = bindec($byte);
|
|
}
|
|
}
|
|
|
|
echo "Extracted " . count($codewords) . " codewords\n";
|
|
echo "First 10 codewords: " . implode(', ', array_slice($codewords, 0, 10)) . "\n\n";
|
|
|
|
// Try to decode
|
|
if (count($codewords) >= 3) {
|
|
$mode = $codewords[0];
|
|
$charCount = $codewords[1];
|
|
|
|
echo "Decoded mode: {$mode} (expected: 4)\n";
|
|
echo "Decoded count: {$charCount} (expected: " . strlen($testData) . ")\n";
|
|
|
|
if ($mode === 4 && $charCount === strlen($testData)) {
|
|
echo "✅ Mode and count are CORRECT!\n\n";
|
|
|
|
// Decode data
|
|
$decodedData = '';
|
|
for ($i = 2; $i < 2 + strlen($testData) && $i < count($codewords); $i++) {
|
|
$decodedData .= chr($codewords[$i]);
|
|
}
|
|
|
|
echo "Decoded data: '{$decodedData}'\n";
|
|
echo "Expected data: '{$testData}'\n";
|
|
|
|
if ($decodedData === $testData) {
|
|
echo "✅ Data decoding is CORRECT!\n";
|
|
} else {
|
|
echo "❌ Data decoding is WRONG!\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]}', expected '{$testData[$i]}')\n";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
echo "❌ Mode or count is WRONG!\n";
|
|
}
|
|
} else {
|
|
echo "❌ Not enough codewords to decode\n";
|
|
}
|
|
|
|
|