Forums / Managing Customers and Orders / Log Downloads With IP Address

Log Downloads With IP Address

Started by webcasts on 19 Sep 2012, 4:18 PM · Views: 875

Results 1 to 4 of 4
19 Sep 2012, 4:18 PM
#1
webcasts avatar

webcasts

New Zenner

Join Date:
Sep 2012
Posts:
2
Plugin Contributions:
0

Log Downloads With IP Address

I am having a problem with people purchasing files, downloading them and then reversing their charges claiming that they never downloaded the product. I can see on the ORDERS page that there there are no downloads available (which means they did download) and I can also verify this by getting into the table ORDERS_PRODUCTS_DOWNLOADS. However, is there a report, or a way to create an SQL that will take that relational database and be able to query the ip address, time of the download, etc. to show a report of when and from where the file(s) were downloaded so I can use that to dispute the reversal charges from PayPal? I would be willing to pay for it.

19 Sep 2012, 8:09 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: Log Downloads With IP Address

This should work ... Add these 2 new files, and since you're using v1.5.0 instead of v1.5.1, you'll need to make the one file-edit shown below.

It will create a download_activity_history.csv in the /cache/ folder (or the /logs/ folder on v1.5.1+) containing download history when new downloads happen.

  1. /includes/classes/observers/class.observer_download_logging.php
<?php
/**
 * @package plugins
 * @copyright Copyright 2003-2012 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 *
 * Designed for v1.5.1
 */

class observer_download_logging extends base {

  function __construct() {
    $this->attach($this, array('NOTIFY_DOWNLOAD_READY_TO_START'));
    if (!defined('DIR_FS_LOGS')) define('DIR_FS_LOGS', DIR_FS_SQL_CACHE);
  }

  function update(&$class, $eventID, $paramsArray = array())
  {
    $origin_filename = $paramsArray[0];
    $browser_filename = $paramsArray[1];
    $downloadFilesize = $paramsArray[2];
    $ip_address = $paramsArray[3];
    $orderData = $paramsArray[4];
    // contains 'date_purchased_day', 'download_count', 'download_maxdays', 'orders_products_filename',
    // and all the info from the orders table record


    // check that the logging file exists, and write headers to it if file isn't found
    if (!file_exists(DIR_FS_LOGS . '/download_activity_history.csv')) {
      $headers = array();
      $headers[] = 'date';
      $headers[] = 'order_number';
      $headers[] = 'customer_number';
      $headers[] = 'ordered_from_ip_address';
      $headers[] = 'origin_filename';
      $headers[] = 'browser_filename';
      $headers[] = 'download_filesize';
      $headers[] = 'download_ip_address';
      error_log(implode(',', $headers) . "\n", 3, DIR_FS_LOGS . '/download_activity_history.csv');
    }

    $logged_info = array();
    $logged_info[] = date('M-d-Y H:i:s');
    $logged_info[] = $orderData['orders_id'];
    $logged_info[] = $_SESSION['customer_id'];
    $logged_info[] = $orderData['ip_address'];
    $logged_info[] = $origin_filename;
    $logged_info[] = $browser_filename;
    $logged_info[] = $downloadFilesize;
    $logged_info[] = $ip_address;
    error_log(implode(',', $logged_info ). "\n", 3, DIR_FS_LOGS . '/download_activity_history.csv');


  }
}
  1. /includes/auto_loaders/config.observer_download_logging.php
<?php
/**
 *
 * @package plugins
 * @copyright Copyright 2003-2012 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 */
/**
 * Designed for v1.5.1
 */
if (!defined('IS_ADMIN_FLAG')) {
 die('Illegal Access');
}
$autoLoadConfig[190][] = array('autoType'=>'class',
                              'loadFile'=>'observers/class.observer_download_logging.php');
$autoLoadConfig[190][] = array('autoType'=>'classInstantiate',
                              'className'=>'observer_download_logging',
                              'objectName'=>'observer_download_logging');
  1. To make it work on v1.5.0 instead of v1.5.1, you'll need to do the following edit:
    /includes/modules/pages/download/header_php.php, line 153:
    $zco_notifier->notify('NOTIFY_DOWNLOAD_READY_TO_START', $origin_filename, $browser_filename, $downloadFilesize, $_SESSION['customers_host_address']);
```change to:```
    $zco_notifier->notify('NOTIFY_DOWNLOAD_READY_TO_START', [B]array([/B]$origin_filename, $browser_filename, $downloadFilesize, $_SESSION['customers_host_address'][B], $downloads->fields)[/B]);

If it works for you, donations appreciated: https://www.zen-cart.com/donate

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

20 Sep 2012, 11:25 PM
#3
webcasts avatar

webcasts

New Zenner

Join Date:
Sep 2012
Posts:
2
Plugin Contributions:
0

Re: Log Downloads With IP Address

WONDERFUL! I WILL donate (again!) because I truly believe in supporting such great programs like this one. One question, if I do these changes and then decide to upgrade to 1.5.1, will I have to do some special installation steps to accommodate these new logs working?

21 Sep 2012, 3:04 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: Log Downloads With IP Address

Webcasts:

One question, if I do these changes and then decide to upgrade to 1.5.1, will I have to do some special installation steps to accommodate these new logs working?
No changes required. It'll work with 1.5.1 just fine. That's where I tested it :)

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.