function eStore_check_stamping_flag_and_generate_download_key($retrieved_product, $product_id, $url = '', $payment_data = '')
{
    if ($retrieved_product->use_pdf_stamper == 1 && !empty($payment_data)) {
        if (WP_ESTORE_STAMP_PDF_FILE_AT_DOWNLOAD_TIME === '1') {
            //Check if file sould be stamped at download time option is enabled
            $download_key = eStore_generate_download_key($product_id, $url);
            return $download_key;
        }
        if (!empty($url)) {
            $src_file = $url;
        } else {
            $src_file = $retrieved_product->product_download_url;
        }
        eStore_payment_debug('Stamping request for product ID: ' . $product_id, true);
        //Check if it is a multiple file URL product
        $multi_file_product = false;
        $product_urls = explode(',', $retrieved_product->product_download_url);
        if (sizeof($product_urls) > 1) {
            $multi_file_product = true;
        }
        $txn_id = $payment_data['txn_id'];
        $force_restamp = false;
        if (isset($payment_data['force_restamp']) && $payment_data['force_restamp'] == '1') {
            //Don't lookup cached copy
            eStore_payment_debug('Force restamping is enabled in the request.', true);
            $force_restamp = true;
        }
        if (!empty($txn_id) && !$multi_file_product && !$force_restamp) {
            eStore_payment_debug('Checking for a reference to the stamped copy of the file for this transaction before invoking another stamp request:' . $txn_id, true);
            $cond = " txn_id = '{$txn_id}'";
            $result = WP_eStore_Db_Access::findAll(WP_ESTORE_DOWNLOAD_LINKS_TABLE_NAME, $cond);
            if ($result) {
                eStore_payment_debug('Found a reference to the stamped copy of a file. Performing an indepth check...', true);
                $random_key = get_option('eStore_random_code');
                foreach ($result as $download_item) {
                    $download_key = $download_item->download_key;
                    eStore_payment_debug('Decrypting download key: ' . $download_key, true);
                    $decrypted_data = RC4Crypt::decrypt($random_key, base64_decode(rawurldecode($download_key)));
                    list($product_id_of_stamped_file, $timestamp, $stamped_file_url) = explode('|', $decrypted_data);
                    eStore_payment_debug('Decrypted data... Product ID: ' . $product_id_of_stamped_file . ', Stamped File URL:' . $stamped_file_url, true);
                    if ($product_id == $product_id_of_stamped_file) {
                        eStore_payment_debug('Product IDs match. Using the existing stamped copy of the file.', true);
                        $new_download_key = eStore_generate_download_key($product_id_of_stamped_file, $stamped_file_url);
                        eStore_payment_debug('New Download Key: ' . $new_download_key, true);
                        return $new_download_key;
                    }
                }
                eStore_payment_debug('Product IDs do not match. Need to proceed with a fresh stamping.', true);
            } else {
                eStore_payment_debug('Could not find a reference to the stamped copy of a file', true);
            }
        }
        $stamped_file_url = eStore_stamp_pdf_file($payment_data, $src_file);
        if ($stamped_file_url === 'Error!') {
            eStore_payment_debug('PDF Stamping did not finish correctly!', false);
            $download_key = "Error with PDF stamping (Error code: PDF01). Perform a manual stamping and make sure the PDF stamper is working on your server.";
            return $download_key;
        }
        $download_key = eStore_generate_download_key($product_id, $stamped_file_url);
    } else {
        $download_key = eStore_generate_download_key($product_id, $url);
    }
    return $download_key;
}
Beispiel #2
0
if (!is_object($eStore_debug_manager)) {
    //Initialize debug mgr if it is not loaded yet
    $eStore_debug_manager = new eStore_dbgmgr(WP_ESTORE_PATH);
}
$time = time();
// Time download script was invoked.
global $wpdb;
$products_table_name = $wpdb->prefix . "wp_eStore_tbl";
$product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME;
$data = $_GET['file'];
$file_key = $data;
$current_access_count = -1;
$random_key = get_option('eStore_random_code');
$download_url_life = get_option('eStore_download_url_life');
$download_url_limit_count = get_option('eStore_download_url_limit_count');
$id_time = RC4Crypt::decrypt($random_key, base64_decode(rawurldecode($data)));
$product_id = "";
$timestamp = "";
$url = "";
$encrypted_args_array = explode('|', $id_time);
if (count($encrypted_args_array) > 2) {
    list($product_id, $timestamp, $url) = $encrypted_args_array;
} else {
    list($product_id, $timestamp) = $encrypted_args_array;
}
$theid = strip_tags($product_id);
$retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$theid}'", OBJECT);
if ($retrieved_product->id != $product_id) {
    eStore_dlvs::error(ESTORE_DLVS_PID, FALSE);
    exit;
}
 function cookie_test($cookie_timeout = 0, $cookie_name = '')
 {
     // Test for valid APR cookie.
     // Returns TRUE if a valid APR cookie, derived from $cookie_name exists.  If $cookie_name is an empty string, then
     // $cookie_name will be assigned the URL of the current browser page.  Returns FALSE if the named APR cookie does not
     // exist.  If $cookie_timeout is greater than zero, then FALSE will be returned if the APR cookie is older than
     // $cookie_timeout minutes.
     // -- The Assurer, 2012-04-30.
     global $eStore_debug_manager;
     // Need access to debug manager.
     if ($cookie_name == '') {
         $cookie_name = eStore_aprtp::curPageURL();
     }
     // Use URL of current browser page.
     $eStore_debug_manager->downloads("Authenticating APR request for: {$cookie_name}", ESTORE_LEVEL_STATUS);
     $random_key = get_option('eStore_random_code');
     $cookie_flavor = md5(RC4Crypt::encrypt($random_key, $cookie_name));
     // Derive the APR cookie name.
     if (!isset($_COOKIE["{$cookie_flavor}"])) {
         $eStore_debug_manager->downloads("\$_COOKIE[{$cookie_flavor}] not found.", ESTORE_LEVEL_STATUS);
         return FALSE;
         // No cookie for you!
     }
     if ($cookie_timeout > 0) {
         // Test for age of APR cookie, if $cookie_timeout is at least 1 minute...
         $cookie_time = (int) RC4Crypt::decrypt($random_key, base64_decode(rawurldecode($_COOKIE[$cookie_flavor])));
         $cookie_timeout = (int) ($cookie_timeout * 60 + $cookie_time);
         if ($cookie_timeout <= (int) time()) {
             $eStore_debug_manager->downloads("\$_COOKIE[{$cookie_flavor}] expired.", ESTORE_LEVEL_STATUS);
             return FALSE;
             // APR cookie has expired.
         }
     }
     return TRUE;
 }
            $k = $box[($box[$a] + $box[$j]) % 256];
            $cipher .= chr(ord($data[$i]) ^ $k);
        }
        return $cipher;
    }
    function decrypt($pwd, $data)
    {
        return RC4Crypt::encrypt($pwd, $data);
    }
}
if (!isset($_GET['file']) || empty($_GET['file'])) {
    echo 'Invalid Request';
    return;
}
$data = $_GET['file'];
$id_time = RC4Crypt::decrypt($secret, base64_decode(rawurldecode($data)));
list($upload_folder, $product_id, $timestamp) = explode('|', $id_time);
if (!isset($upload_folder)) {
    echo 'Invalid Request';
    return;
}
if (!isset($product_id)) {
    echo 'Invalid Request';
    return;
}
if ($timestamp < $time - $download_life * 60 * 60) {
    echo 'Link Expired';
    return;
}
function output_file($file, $name, $mime_type = '')
{