<?php
header("Content-Type: application/x-mpegURL");
header("Cache-Control: no-cache");

$user = $_GET['username'] ?? '';
$pass = $_GET['password'] ?? '';

$db = new PDO("sqlite:/var/www/html/db.sqlite");
$stmt = $db->prepare("SELECT * FROM users WHERE username=? AND password=?");
$stmt->execute([$user, $pass]);
$u = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$u || time() > $u['expires']) {
    http_response_code(403);
    exit;
}

echo "#EXTM3U\n";

/*
  TEST-KANÄLE
  Noch KEINE echten Streams
*/
echo "#EXTINF:-1,TEST CHANNEL 1\n";
echo "http://{$_SERVER['HTTP_HOST']}/stream.php?id=1\n";

echo "#EXTINF:-1,TEST CHANNEL 2\n";
echo "http://{$_SERVER['HTTP_HOST']}/stream.php?id=2\n";
