<?php

/*
Desencripta el texto recibido
 */
function desencriptar($valor)
{
    $clave   = 'keyencriptacioncaceres';
    //$iv_size = mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CBC);
    $iv      = base64_decode("C9fBxl1EWtYTL1/M8jfstw==");

    $valor     = str_replace(" ", "+", $valor);
    $decrypted = openssl_decrypt($valor, "AES-256-CBC", $clave, 0, $iv);

    return $decrypted;
};

if (!empty($_POST)) {
    if ($_POST["src_file"]) {
        $src_file = $_POST["src_file"];
    }
} else {
    $token       = $_REQUEST['l'];
    $localizador = desencriptar($token);

    if ($_REQUEST['w'] == 1) {
        $url_passbook = 'https://www.marquesdecaceres.com/wp-content/plugins/visitas/modules/visitas/reservas';
    } else {
        $url_passbook = 'https://reservas.marquesdecaceres.com/reservas/admin';
    }

    $src_file = $url_passbook . '/files/passbook/' . $localizador . '/' . $localizador;

}

header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/vnd.apple.pkpass");
header('Content-Disposition: attachment; filename="' . basename($src_file) . '.pkpass"');

readfile($src_file . '.pkpass');
exit;
