<?php

error_reporting(E_ALL);
@ini_set("display_errors", true);
/*
Here we perform the PHP test routine.
*/
if (curlpsr("https://www.paypal.com/", array("x_test" => 1))) {
    echo '<div>Test succeeded :-) Lookin\' good here. Your cURL extension is functioning properly, with SSL enabled too.</div>';
} else {
    if (ini_get("safe_mode")) {
        echo '<div>Test failed, but your server is running with <code>safe_mode = on</code>.<br />Please check with your hosting company to be sure.</div>';
    } else {
        if (ini_get("open_basedir")) {
            echo '<div>Test failed, but your server is running with <code>open_basedir</code>.<br />Please check with your hosting company to be sure.</div>';
        } else {
            // Otherwise, the test failed.
            echo '<div>Sorry, this test failed!</div>';
        }
    }
}
/*
Curl operation for posting data and reading response.
*/
function curlpsr($url = FALSE, $postvars = array(), $max_con_secs = 20, $max_stream_secs = 20, $headers = array())
{
    if (($url = trim($url)) && ($c = curl_init())) {
        if (is_array($postvars)) {
            // Because cURL can't deal with complex arrays.
            // Since cURL can't deal with complex arrays, we force this to a query string.
            $postvars = http_build_query($postvars, null, "&");
while (@ob_end_clean()) {
}
// Clean any existing output buffers.
if (empty($_POST) || !is_array($_POST)) {
    exit;
}
foreach ($config as $_key => $_value) {
    $config[strtolower($_key)] = $_value;
}
unset($_key, $_value);
$_p = get_magic_quotes_gpc() ? stripslashes_deep($_POST) : $_POST;
$_p = trim_deep($_p);
if ((preg_match("/^(.+?)(?:\\||\$)/i", (string) @$_p["custom"], $_m) || preg_match("/~(.+?)~/i", (string) @$_p["rp_invoice_id"], $_m)) && !empty($config[$_m[1]])) {
    $_paypal_ipn_server_ip = $_ip = "173.0.81.1";
    // See list of IPs here: <https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_golivechecklist>.
    echo trim(curlpsr($_url = $config[$_m[1]], http_build_query($_p, null, "&"), 20, 20, array("REMOTE_ADDR: " . $_ip, "HTTP_X_FORWARDED_FOR: " . $_ip)));
}
unset($_paypal_ipn_server_ip, $_ip, $_url, $_m);
/*
---- Do NOT edit anything below, unless you know what you're doing. --------------------------------------------------------*/
function trim_deep($value = FALSE)
{
    return is_array($value) ? array_map("trim_deep", $value) : trim((string) $value);
}
function stripslashes_deep($value = FALSE)
{
    return is_array($value) ? array_map("stripslashes_deep", $value) : stripslashes((string) $value);
}
function curlpsr($url = FALSE, $post_vars = array(), $max_con_secs = 20, $max_stream_secs = 20, $headers = array())
{
    if (($url = trim($url)) && ($curl = curl_init())) {
header("HTTP/1.0 200 OK");
header("Content-Type: text/plain; charset=UTF-8");
while (@ob_end_clean()) {
}
// Clean any existing output buffers.
if (empty($_POST) || !is_array($_POST)) {
    exit;
}
foreach ($config as $_key => $_value) {
    $config[strtolower($_key)] = $_value;
}
unset($_key, $_value);
$_p = get_magic_quotes_gpc() ? stripslashes_deep($_POST) : $_POST;
$_p = trim_deep($_p);
if (is_object($_jwt = JWT::decode((string) @$_p["jwt"], $key)) && !empty($_jwt->request->sellerData->cs) && preg_match("/^(.+?)(?:\\||\$)/i", (string) $_jwt->request->sellerData->cs, $_m) && !empty($config[$_m[1]])) {
    echo trim(curlpsr($_url = $config[$_m[1]], http_build_query($_p, null, "&")));
}
unset($_jwt, $_url, $_m);
/*
---- Do NOT edit anything below, unless you know what you're doing. --------------------------------------------------------*/
function trim_deep($value = FALSE)
{
    return is_array($value) ? array_map("trim_deep", $value) : trim((string) $value);
}
function stripslashes_deep($value = FALSE)
{
    return is_array($value) ? array_map("stripslashes_deep", $value) : stripslashes((string) $value);
}
function curlpsr($url = FALSE, $post_vars = array(), $max_con_secs = 20, $max_stream_secs = 20, $headers = array())
{
    if (($url = trim($url)) && ($curl = curl_init())) {
---- Configuration: --------------------------------------------------------------------------------------------------------*/
$CONFIG = array("[YOUR DOMAIN]" => "[FULL URL TO AN IPN HANDLER FOR YOUR DOMAIN]", "www.site1.com" => "http://www.site1.com/?s2member_paypal_notify=1", "www.site2.com" => "http://www.site2.com/?s2member_paypal_notify=1");
/*
---- Do NOT edit anything below, unless you know what you're doing. --------------------------------------------------------*/
foreach ($CONFIG as $key => $value) {
    $CONFIG[strtolower($key)] = $value;
}
unset($key, $value);
/*
Fork IPN transactions out to particular domains.
*/
preg_match("/^(.+?)(?:\\||\$)/i", (string) @$_POST["custom"], $custom);
preg_match("/~(.+?)~/i", (string) @$_POST["rp_invoice_id"], $rp_invoice_id);
/**/
if ((!empty($custom[1]) || !empty($rp_invoice_id[1])) && strtolower($domain = !empty($custom[1]) ? $custom[1] : $rp_invoice_id[1]) && !empty($CONFIG[$domain])) {
    header("HTTP/1.0 200 OK") . exit(trim(curlpsr($CONFIG[$domain], http_build_query($_POST))));
} else {
    header("HTTP/1.0 500 Error") . exit;
}
/*
cURL operation for posting data and reading response.
*/
function curlpsr($url = FALSE, $postvars = array(), $max_con_secs = 20, $max_stream_secs = 20, $headers = array())
{
    if (($url = trim($url)) && ($c = curl_init())) {
        if (is_array($postvars)) {
            /* Because cURL can't deal with complex arrays. */
            /* Since cURL can't deal with complex arrays, we force this to a query string. */
            $postvars = http_build_query($postvars);
        }
        /**/
@ignore_user_abort(true);
header("HTTP/1.0 200 OK");
header("Content-Type: text/plain; charset=UTF-8");
while (@ob_end_clean()) {
}
// Clean any existing output buffers.
if (empty($_POST) || !is_array($_POST)) {
    exit;
}
$_p = get_magic_quotes_gpc() ? stripslashes_deep($_POST) : $_POST;
$_p = trim_deep($_p);
$_paypal_ipn_server_ip = $_ip = "216.113.188.202";
// See list of IPs here: <https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_golivechecklist>.
$_p["custom"] = $config["custom"];
$_p["item_number"] = $config["item_number"];
echo trim(curlpsr($config["proxy_ipn_handler_url"], http_build_query($_p, null, "&"), 20, 20, array("REMOTE_ADDR: " . $_ip, "HTTP_X_FORWARDED_FOR: " . $_ip)));
unset($_paypal_ipn_server_ip, $_ip);
// ---- Do NOT edit anything below, unless you know what you're doing. --------------------------------------------------------
function trim_deep($value = FALSE)
{
    return is_array($value) ? array_map("trim_deep", $value) : trim((string) $value);
}
function stripslashes_deep($value = FALSE)
{
    return is_array($value) ? array_map("stripslashes_deep", $value) : stripslashes((string) $value);
}
function curlpsr($url = FALSE, $post_vars = array(), $max_con_secs = 20, $max_stream_secs = 20, $headers = array())
{
    if (($url = trim($url)) && ($curl = curl_init())) {
        if (is_array($post_vars)) {
            $post_vars = http_build_query($post_vars);