Module conversion to 5.x

emzi - September 2, 2007 - 15:45
Project:FileRequest
Version:HEAD
Component:Code
Category:feature request
Priority:critical
Assigned:emzi
Status:active
Description

Recently we needed this module functionality for one of our projects, so I had to convert it to current Drupal version.
Added new feature: do the same job for empty referrer if needed, controlled by switch.
Also did some cleanup job along with conversion. Module still has some questionable code, but no doubt is fully operational.
Unfortunately drupal.org does not allow tar.gz attachments, so anyone interested may get patched module here: http://www.torlin.com/files/filerequest-5.x-1.x-dev.tar.gz

#1

NITEMAN - November 3, 2007 - 13:03

Is this module maintaned?
I think file transfer resume thru private metod is a must have.

#2

NITEMAN - November 3, 2007 - 17:36
Priority:normal» critical

A little bug is that anonimous users can download. I've achieved to workaroun this doing the following in filerequest.module _filerequest_download() function:

Add $filepath = implode('/', $args); affter $args = func_get_args(); without removing $config["filename"] = implode('/', $args);
Comment foreach line and the }
Change $headers = module_invoke_all($module, 'file_download', $_GET['file']); to $headers = module_invoke_all('file_download', $filepath);

Final function code looks as follows:

/**
* Process the download request. If it's a file leecher redirect it to the
* associated node, otherwise return an access_denied error.
*/
function _filerequest_download() {
  define("__DRUPAL_BASE_DIR", dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR);
  require_once("downloadhandler.php");

  $args = func_get_args();
  //BY NITEMAN
  $filepath = implode('/', $args);
  // END BY NITEMAN
  $config["filename"] = implode('/', $args);
  $config["filereq_antileech_enabled"] = variable_get('filereq_antileech_enabled', true);
  $config["filereq_antileech_regex"] = variable_get('filereq_antileech_regex', preg_quote($_SERVER["HTTP_HOST"]));
  $config["filereq_antileech_image_mode"] = variable_get('filereq_antileech_image_mode', 0);
  $config["filereq_antileech_image_file"] = variable_get('filereq_antileech_image_file', "modules/filerequest/watermark.png");

  if (!__fr_can_download_file($config)) define("__FILEREQ_LEECH", $file);

  if (defined("__FILEREQ_LEECH"))
  {
    global $__fr_reporting_leech;
    if ($__fr_reporting_leech) __fr_delayed_report();
    $result = db_result(db_query("SELECT nid FROM {files} WHERE filepath = '%s'", $config["filename"]));
    if ($result !== false)
    {
      drupal_goto("node/".$result);
      exit;
    }
    drupal_access_denied();
    return;
  }
  $config["filename"] = file_create_path($config["filename"]);
  if (file_exists($config["filename"])) {
    $list = module_list();
    // BY NITEMAN foreach ($list as $module) {
      // BY NITEMAN $headers = module_invoke_all($module, 'file_download', $_GET['file']);
      $headers = module_invoke_all('file_download', $filepath);
      if (in_array(-1, $headers)) {
        return drupal_access_denied();
      }
      else if (count($headers)) {
        // set custom headers
        $forceMime = '';
        foreach ($headers as $header) {
          header($header);
          if (preg_match('#^Content-Type: (.*)$#i', $header, $match)) {
            $forceMime = $match[1];
          }
        }
        // make sure no caching headers are set
        header("Cache-Control:");
        header("Pragma:");
        header("Expires:");
        // unset other headers we (might) set
        header("Content-Range:");
        header("Content-Length:");
        header("Content-Type:");
        header("Last-Modified:");
        header("Content-Disposition:");
        __fr_process_download($config["filename"], preg_match("#(\?|&)download(&|$)#", $_SERVER["REQUEST_URI"]), $config["watermark"], $forceMime);
        exit();
      }
    // BY NITEMAN}
  }
  drupal_not_found();
}

Every change is marked with NITEMAN word ;)

#3

Darren Oh - May 20, 2008 - 03:13

This should be fixed in Drupal core. We could use a review of issue 91934 to help get file transfer resume support for private downloads in core.

 
 

Drupal is a registered trademark of Dries Buytaert.