Source of the YABS board

These are the exact bytes the server runs. Compare the hash with your own sha256sum of the downloaded copy: if the two match, the page you read is the program you reviewed.
source.php · 102 lines · 3.6 KiB · sha256 ff5d32732e8257ef84e0b1069744fd3ca316e501eb2992b7ceedd6d4ea4ed4bc · download · board · README

<?php
// Shows the exact bytes of the board's own files, so a visitor can check them
// instead of trusting the page. Whitelist only: no path comes from the URL.
// ?raw=1 returns text/plain for a local sha256sum diff.

declare(strict_types=1);
error_reporting(E_ALL & ~E_DEPRECATED);
ini_set('display_errors', '0');

const 
FILES = ['index.php', 'probe.sh', 'racks.php', 'history.php', 'source.php', 'README.md', 'llms.txt'];

function 
h(?string $s): string
{
    return 
htmlspecialchars((string) $s, ENT_QUOTES, 'UTF-8');
}

function 
kib(int $bytes): string
{
    return 
$bytes < 1024 ? $bytes . ' B' : number_format($bytes / 1024, 1) . ' KiB';
}

$file = (string) ($_GET['f'] ?? 'index.php');
if (!
in_array($file, FILES, true)) {
    
http_response_code(404);
    
header('Content-Type: text/plain; charset=utf-8');
    echo 
"Unknown file. Choose one of: " . implode(', ', FILES) . "\n";
    exit;
}

$path = __DIR__ . '/' . $file;
$src = (string) file_get_contents($path);
$hash = (string) hash_file('sha256', $path);
$size = strlen($src);
$lines = substr_count($src, "\n") + 1;

if (isset(
$_GET['raw'])) {
    
header('Content-Type: text/plain; charset=utf-8');
    
header('X-Content-Type-Options: nosniff');
    
header('Content-Length: ' . $size);
    echo 
$src;
    exit;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>YABS board source: <?= h($file) ?></title>
<link rel="icon" href="data:,">
<style>
  :root { color-scheme: dark; }
  body { margin: 0; background: #0d1117; color: #c9d1d9;
         font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
  header { padding: 14px 18px 10px; border-bottom: 1px solid #21262d; }
  h1 { margin: 0 0 6px; font-size: 15px; font-weight: 600; letter-spacing: .04em; }
  nav { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 6px; }
  nav a { padding: 2px 8px; border: 1px solid #30363d; border-radius: 5px; color: #8b949e; }
  nav a.on { background: #21262d; color: #c9d1d9; border-color: #58a6ff; }
  a { color: #58a6ff; text-decoration: none; }
  a:hover { text-decoration: underline; }
  .mut { color: #8b949e; }
  .hash { color: #7ee787; word-break: break-all; }
  pre { margin: 0; padding: 14px 18px 40px; overflow-x: auto; font-size: 12px; line-height: 1.45; }
  code .default, pre { color: #c9d1d9; }
</style>
</head>
<body>
<header>
  <h1>Source of the YABS board</h1>
  <div class="mut">
    These are the exact bytes the server runs. Compare the hash with your own
    <code>sha256sum</code> of the downloaded copy: if the two match, the page you
    read is the program you reviewed.
  </div>
  <nav>
    <?php foreach (FILES as $f): ?>
      <a href="?f=<?= h(rawurlencode($f)) ?>"<?= $f === $file ? ' class="on"' : '' ?>><?= h($f) ?></a>
    <?php endforeach; ?>
  </nav>
  <div class="mut">
    <?= h($file) ?> &middot; <?= $lines ?> lines &middot; <?= kib($size) ?>
    &middot; sha256 <span class="hash"><?= h($hash) ?></span>
    &middot; <a href="?f=<?= h(rawurlencode($file)) ?>&amp;raw=1">download</a>
    &middot; <a href="./">board</a>
    &middot; <a href="README.md">README</a>
  </div>
</header>
<pre><?php
// highlight_string escapes the source itself, so the output cannot inject HTML.
// It also hardcodes a light palette, which is unreadable here: remap it.
echo strtr(highlight_string($src, true), [
    
'#79c0ff' => '#79c0ff',   // variables, names
    
'#ff7b72' => '#ff7b72',   // keywords
    
'#a5d6ff' => '#a5d6ff',   // strings
    
'#8b949e' => '#8b949e',   // comments
    
'#c9d1d9' => '#c9d1d9',   // default text
]);
?></pre>
</body>
</html>