<?php

include 'AES256.php';

$bn_passphrases = [
    "jb%!SZfM%AwwS7JmdM!",
    "An@BelLa2015!@1m"
];

$bn_request = $_GET['e'];
$bn_req = null;

// Função para tentar descriptografar com todas as passphrases
function tryDecrypt($request, $passphrases) {
    foreach ($passphrases as $passphrase) {
        $decrypted = \mervick\aesEverywhere\AES256::decrypt($request, $passphrase);
        if ($decrypted) {
            return $decrypted;
        }
    }
    return false;
}

$bn_req = tryDecrypt($bn_request, $bn_passphrases);

// Verifica se a descriptografia foi bem-sucedida
if ($bn_req === false) {
    // Retorna erro caso a descriptografia falhe
    http_response_code(400);
    echo json_encode(['error' => 'Invalid decryption']);
    exit;
}

// URL do painel
$bn_api = file_get_contents('http://sub35nj7kmmlk.shop/api/authentication.php?e&' . $bn_req);

header('Content-Type: application/json');
$action = $_GET['action'] ?? null;

switch ($action) {
    case 'auth':
        echo $bn_api;
        break;

    case 'changeChannel':
        echo json_encode(['success' => true]);
        break;

    default:
        http_response_code(400);
        echo json_encode(['success' => false]);
   //     echo json_encode(['error' => 'Invalid action']);
        break;
}
?>