<?php
session_start();
$PASSWORD = 'GOGETAIO';
$isAuthenticated = isset($_SESSION['aio_auth']) && $_SESSION['aio_auth'] === true;
$errorMsg = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['password']) && trim($_POST['password']) === $PASSWORD) {
        $_SESSION['aio_auth'] = true;
        $isAuthenticated = true;
    } else {
        $errorMsg = 'Incorrect password.';
    }
}

if ($isAuthenticated && isset($_GET['file'])) {
    $file = basename($_GET['file']);
    $filepath = __DIR__ . '/downloads/' . $file;
    if (file_exists($filepath) && is_file($filepath)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="' . $file . '"');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($filepath));
        ob_clean();
        flush();
        readfile($filepath);
        exit;
    } else {
        die("File not found.");
    }
}
?>
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>AIO Relay™ - Downloads</title>
  <meta name="description" content="Download AIO Relay™ Windows installers." />
  <style>
    @font-face {
      font-family: "Ethnocentric";
      src: url("assets/fonts/ethnocen.ttf") format("truetype");
      font-weight: 400;
      font-style: normal;
      font-display: swap;
    }
    :root {
      --bg: #0b0c0f;
      --panel: #14161b;
      --panel-2: #101217;
      --text: #e7e7e7;
      --muted: #a6a9b0;
      --accent: #e50914;
      --accent-2: #b50912;
      --stroke: #2a2d36;
    }

    * {
      box-sizing: border-box;
    }

    body {
      margin: 0;
      font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
      background: var(--bg);
      color: var(--text);
    }

    .container {
      max-width: 880px;
      margin: 0 auto;
      padding: 40px 20px 72px;
    }

    header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 14px;
      margin-bottom: 24px;
    }

    .nav {
      display: flex;
      gap: 12px;
      flex-wrap: wrap;
      font-size: 13px;
      color: var(--muted);
    }

    .nav a {
      color: inherit;
      text-decoration: none;
    }

    .nav a:hover {
      color: #fff;
    }

    .card {
      background: linear-gradient(180deg, var(--panel), var(--panel-2));
      border: 1px solid var(--stroke);
      border-radius: 14px;
      padding: 20px;
    }

    .grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 14px;
      margin-top: 16px;
    }

    .download-tile {
      border: 1px solid var(--stroke);
      border-radius: 12px;
      background: rgba(0, 0, 0, 0.2);
      padding: 14px;
    }

    .download-tile h3 {
      margin: 0 0 8px;
      font-size: 16px;
    }

    .download-tile p {
      margin: 0 0 10px;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.5;
    }

    .cta {
      display: inline-block;
      padding: 10px 14px;
      border-radius: 999px;
      border: 1px solid var(--accent);
      background: linear-gradient(180deg, var(--accent), var(--accent-2));
      color: #fff;
      text-decoration: none;
      font-weight: 800;
      font-size: 13px;
    }

    .note {
      margin-top: 16px;
      padding: 12px;
      border: 1px solid var(--stroke);
      border-radius: 10px;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.5;
      background: rgba(0, 0, 0, 0.18);
    }

    code {
      color: #fff;
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
      font-size: 12px;
    }

    .downloads-content.locked {
      filter: blur(6px);
      pointer-events: none;
      user-select: none;
    }

    .downloads-gate {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.86);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 9999;
      padding: 16px;
    }

    .downloads-gate-card {
      width: min(420px, 100%);
      background: linear-gradient(180deg, var(--panel), var(--panel-2));
      border: 1px solid var(--stroke);
      border-radius: 12px;
      padding: 18px;
    }

    .downloads-gate-row {
      display: flex;
      gap: 10px;
      margin-top: 10px;
    }

    .downloads-gate-row input {
      flex: 1;
      background: #000;
      border: 1px solid var(--stroke);
      border-radius: 8px;
      color: #fff;
      padding: 10px;
    }

    .downloads-gate-row button {
      border: 1px solid var(--accent);
      background: linear-gradient(180deg, var(--accent), var(--accent-2));
      color: #fff;
      border-radius: 8px;
      padding: 10px 12px;
      font-weight: 700;
      cursor: pointer;
    }

    .downloads-gate-status {
      margin-top: 8px;
      font-size: 12px;
      color: #ff6b6b;
      min-height: 16px;
    }

    @media (max-width: 760px) {
      .grid {
        grid-template-columns: 1fr;
      }
    }
  </style>
<script>
  window.chatpilotConfig = {
    chatbotId: "49832136a92545f896462610c6644b54",
    domain: "https://go.aiobots.us"
  }
</script>
<script
  src="https://go.aiobots.us/embed.min.js"
  charset="utf-8"
  defer
></script>
</head>
  <?php if (!$isAuthenticated): ?>
  <div class="downloads-gate" id="downloads-gate" aria-hidden="false">
    <form method="POST" class="downloads-gate-card" role="dialog" aria-modal="true" aria-label="Downloads Access">
      <h2 style="margin: 0 0 8px; font-size: 18px;">Downloads Locked</h2>
      <p style="margin: 0; color: var(--muted); font-size: 13px;">Enter access password to view installer links.</p>
      <div class="downloads-gate-row">
        <input type="password" name="password" id="downloads-password" placeholder="Password" autofocus>
        <button type="submit" id="downloads-unlock">Unlock</button>
      </div>
      <div class="downloads-gate-status" id="downloads-gate-status"><?= htmlspecialchars($errorMsg) ?></div>
    </form>
  </div>
  <?php endif; ?>
  
  <?php if ($isAuthenticated): ?>


<body>
  <div class="container downloads-content" id="downloads-content">
    <header>
      <h1 style="margin: 0; font-size: 26px; font-family: 'Ethnocentric', 'Orbitron', 'Bank Gothic', 'Eurostile', system-ui, -apple-system, Segoe UI, Roboto, sans-serif; font-weight: 400; letter-spacing: 0.7px;">AIO <span style="color: var(--accent);">RELAY</span> Downloads</h1>
      <nav class="nav">
        <a href="index.html">Home</a>
        <a href="checkout.html">Checkout</a>
        <a href="install.html">Install Guide</a>
        <a href="status.html">Status</a>
      </nav>
    </header>

    <div class="card">
      <p style="margin: 0; color: var(--muted);">
        Use the installer package to get started. This package targets Windows (MediaMTX architecture).
      </p>
      <div class="grid">
        <div class="download-tile">
          <h3>Setup EXE (v3.0.0 — Latest)</h3>
          <p>The landmark v3.0 release introduces the modular EIA-310 Rack Architecture, full-hardware NVENC broadcast pipelines, the 8-channel VMix-style audio mixer, Stage 2 Ingest Switchboard with seamless hot-switching (Studio, Encoder, and Playlist sources), dedicated WaveMeter visualizer deck, and pre-announcement support for the upcoming Call-In Studio.</p>
          <a class="cta" href="?file=AIORelay_3.0.0_x64-setup.exe">Download v3.0.0</a>
        </div>
        <div class="download-tile">
          <h3>Deployment Checklist (PDF)</h3>
          <p>Production deployment and quick-reference checklist.</p>
          <a class="cta" href="?file=AIO_Relay_Checklist_v2.1.0.pdf">Open checklist</a>
        </div>
      </div>
      <div class="note">
        Download the v3.0.0 installer package, run it on Windows, then follow the full install/operation flow on the
        <a href="install.html" style="color: #fff;">Install Guide</a> page.
      </div>
      <div class="note">
        <strong>Active Release Policy:</strong> To guarantee maximum broadcast reliability and eliminate legacy regressions, AIO Relay maintains an active-release distribution policy where only the latest fully certified engine (v3.0.0) is published. In perpetuity, prior legacy builds (including v2.1.5 and earlier) have been permanently retired from public distribution. The complete release evolution is chronicled on the
        <a href="status.html" style="color: #fff;">Status + Release History</a> page.
      </div>
      <div class="note">
        Release v3.0.0 | Website updated 2026-10-26 | See <a href="status.html" style="color: #fff;">Status + roadmap</a>
      </div>

    </div>

    <div class="card" style="margin-top: 16px;">
      <h2 style="margin: 0 0 12px; font-size: 18px;">Important Transparency / FAQ</h2>
      <div class="note">
        <strong>Why does Ingest Telemetry say 720p when I set Studio to 1080p?</strong><br/>
        AIO Relay uses an intelligent WebRTC engine for the local Studio. If you set the target resolution to 1080p, the browser dynamically downscales resolution based on local bandwidth/CPU availability to maintain a smooth framerate. This is correct behavior, and the telemetry strictly reports the exact feed dimensions arriving at the encoder.
      </div>
      <div class="note">
        <strong>Why are my Live Ingest Bitrates empty (-)?</strong><br/>
        Live WebRTC feeds (Browser Studio) do not write a static bitrate into their stream headers. Because of this, FFprobe returns a null value (displayed as `-`). This is completely normal; you should rely on the <strong>Bandwidth Monitor</strong> for real-time network throughput instead!
      </div>
      <div class="note">
        <strong>Are my settings safe when upgrading to v3.0?</strong><br/>
        Yes! Upgrading from prior releases (v2.0, v2.1.x) to v3.0 is 100% seamless. The profile migration logic safely migrates your saved destinations, credentials, and settings. In v3.0, the EIA-310 cabinet layout defaults to the clean broadcast rack, and session controls (MUTE ALL and CYA) initialize unmuted with the curtain up by design.
      </div>
    </div>
  </div>

  
  <?php endif; ?>
</body>
</html>
