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.7 KiB
PHP
126 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
use App\Framework\QrCode\ErrorCorrection\ReedSolomonEncoder;
|
|
use App\Framework\QrCode\ValueObjects\EncodingMode;
|
|
use App\Framework\QrCode\ValueObjects\QrCodeVersion;
|
|
|
|
echo "=== Encoding Issue Analysis ===\n\n";
|
|
|
|
$testData = 'HELLO WORLD';
|
|
echo "Test data: '{$testData}'\n";
|
|
echo "Length: " . strlen($testData) . " bytes\n\n";
|
|
|
|
// Expected codewords from QR code specification
|
|
$expectedCodewords = [64, 180, 132, 84, 196, 196, 242, 5, 116, 245, 174, 59, 64, 109, 236, 233];
|
|
echo "Expected codewords (16):\n";
|
|
echo implode(', ', $expectedCodewords) . "\n\n";
|
|
|
|
// Step-by-step encoding
|
|
$version = QrCodeVersion::fromNumber(1);
|
|
$encodingMode = EncodingMode::BYTE;
|
|
|
|
// 1. Mode indicator
|
|
$modeBits = $encodingMode->getModeBits();
|
|
echo "1. Mode indicator: {$modeBits} (4 bits)\n";
|
|
|
|
// 2. Character count
|
|
$charCountBits = $encodingMode->getCharacterCountBits($version);
|
|
$countBits = str_pad(decbin(strlen($testData)), $charCountBits, '0', STR_PAD_LEFT);
|
|
echo "2. Character count: {$countBits} (8 bits) = " . strlen($testData) . "\n";
|
|
|
|
// 3. Data bytes
|
|
$dataBits = '';
|
|
for ($i = 0; $i < strlen($testData); $i++) {
|
|
$byte = ord($testData[$i]);
|
|
$byteBits = str_pad(decbin($byte), 8, '0', STR_PAD_LEFT);
|
|
$dataBits .= $byteBits;
|
|
echo "3.{$i} Data byte '{$testData[$i]}': {$byteBits} = {$byte}\n";
|
|
}
|
|
|
|
// 4. Build bit string
|
|
$bits = $modeBits . $countBits . $dataBits;
|
|
echo "\nTotal bits: " . strlen($bits) . "\n";
|
|
|
|
// 5. Get EC info
|
|
$ecInfo = ReedSolomonEncoder::getECInfo(1, 'M');
|
|
$requiredBits = $ecInfo['dataCodewords'] * 8;
|
|
echo "Required bits: {$requiredBits}\n";
|
|
echo "Bits needed: " . ($requiredBits - strlen($bits)) . "\n\n";
|
|
|
|
// 6. Terminator (up to 4 bits)
|
|
$terminatorLength = min(4, max(0, $requiredBits - strlen($bits)));
|
|
$bits .= str_repeat('0', $terminatorLength);
|
|
echo "After terminator ({$terminatorLength} bits): " . strlen($bits) . " bits\n";
|
|
|
|
// 7. Pad to multiple of 8
|
|
$remainder = strlen($bits) % 8;
|
|
if ($remainder !== 0) {
|
|
$bits .= str_repeat('0', 8 - $remainder);
|
|
}
|
|
echo "After padding to 8: " . strlen($bits) . " bits\n";
|
|
|
|
// 8. Add pad codewords
|
|
$padBytes = ['11101100', '00010001'];
|
|
$padIndex = 0;
|
|
while (strlen($bits) < $requiredBits) {
|
|
$bits .= $padBytes[$padIndex % 2];
|
|
$padIndex++;
|
|
}
|
|
echo "After pad codewords ({$padIndex} added): " . strlen($bits) . " bits\n\n";
|
|
|
|
// 9. Convert to codewords
|
|
$codewords = [];
|
|
for ($i = 0; $i < strlen($bits); $i += 8) {
|
|
$byte = substr($bits, $i, 8);
|
|
$codewords[] = bindec($byte);
|
|
}
|
|
|
|
echo "Generated codewords (16):\n";
|
|
echo implode(', ', $codewords) . "\n\n";
|
|
|
|
// Compare bit by bit
|
|
echo "=== Bit-by-Bit Comparison ===\n";
|
|
$expectedBits = '';
|
|
foreach ($expectedCodewords as $cw) {
|
|
$expectedBits .= str_pad(decbin($cw), 8, '0', STR_PAD_LEFT);
|
|
}
|
|
|
|
echo "Our bits (128):\n";
|
|
echo $bits . "\n\n";
|
|
echo "Expected bits (128):\n";
|
|
echo $expectedBits . "\n\n";
|
|
|
|
// Find differences
|
|
$differences = [];
|
|
for ($i = 0; $i < 128; $i++) {
|
|
if ($bits[$i] !== $expectedBits[$i]) {
|
|
$differences[] = $i;
|
|
}
|
|
}
|
|
|
|
if (empty($differences)) {
|
|
echo "✅ All bits match!\n";
|
|
} else {
|
|
echo "❌ " . count($differences) . " bits differ at positions: ";
|
|
echo implode(', ', array_slice($differences, 0, 20));
|
|
if (count($differences) > 20) {
|
|
echo " ...";
|
|
}
|
|
echo "\n\n";
|
|
|
|
// Show first 10 differences in detail
|
|
echo "First differences:\n";
|
|
for ($i = 0; $i < min(10, count($differences)); $i++) {
|
|
$pos = $differences[$i];
|
|
$codeword = (int)($pos / 8);
|
|
$bitInCodeword = $pos % 8;
|
|
echo " Bit {$pos} (Codeword {$codeword}, bit {$bitInCodeword}): got '{$bits[$pos]}', expected '{$expectedBits[$pos]}'\n";
|
|
}
|
|
}
|
|
|
|
|