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.
142 lines
4.3 KiB
PHP
142 lines
4.3 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 "=== Data Placement Order Verification ===\n\n";
|
|
|
|
// Test with simple data first
|
|
$testData = 'HELLO WORLD';
|
|
$config = new QrCodeConfig(
|
|
version: QrCodeVersion::fromNumber(1),
|
|
errorCorrectionLevel: ErrorCorrectionLevel::M,
|
|
encodingMode: EncodingMode::BYTE
|
|
);
|
|
|
|
echo "Test data: '{$testData}'\n";
|
|
echo "Expected: Should decode to 'HELLO WORLD'\n\n";
|
|
|
|
$matrix = QrCodeGenerator::generate($testData, $config);
|
|
$size = $matrix->getSize();
|
|
|
|
// Simulate reading data bits back in placement order
|
|
echo "Reading data bits from matrix (unmasking first)...\n";
|
|
|
|
// First, we need to know which mask was used
|
|
// Extract format info to determine mask
|
|
$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";
|
|
|
|
// Now read data bits in placement order and unmask them
|
|
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 = [];
|
|
$bitIndex = 0;
|
|
|
|
// Read in same order as placement
|
|
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;
|
|
}
|
|
|
|
// Read bit
|
|
$maskedBit = $matrix->getModuleAt($row, $currentCol)->isDark() ? 1 : 0;
|
|
|
|
// Unmask
|
|
$unmaskedBit = $mask->shouldInvert($row, $currentCol) ? (1 - $maskedBit) : $maskedBit;
|
|
|
|
$dataBits[] = $unmaskedBit;
|
|
$bitIndex++;
|
|
}
|
|
}
|
|
}
|
|
|
|
echo "Read {$bitIndex} data bits\n";
|
|
|
|
// Convert bits 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 first few bytes
|
|
echo "=== Decoding Attempt ===\n";
|
|
if (count($codewords) >= 3) {
|
|
// First byte should be mode indicator (0100 = 4)
|
|
$mode = $codewords[0];
|
|
echo "Mode indicator: {$mode} (expected: 4 for byte mode)\n";
|
|
|
|
// Second byte should be character count
|
|
$charCount = $codewords[1];
|
|
echo "Character count: {$charCount} (expected: " . strlen($testData) . ")\n";
|
|
|
|
// Next bytes should be data
|
|
echo "First data bytes: ";
|
|
for ($i = 2; $i < min(2 + strlen($testData), count($codewords)); $i++) {
|
|
echo chr($codewords[$i]);
|
|
}
|
|
echo "\n";
|
|
}
|
|
|
|
|