As user 1, when I go to download a file that is listed in webfm, it takes me to /webfm_send/~Workspace~test.txt and gives me an access denied message.

I added debug code to print the filename before the access denied message. The file name that prints via dpm is sites/default/files/Workspace/test.txt

This file exists:

$ ls -la sites/default/files/Workspace/test.txt 
-rw-rw-r-- 1 apache apache 7 Feb  8 06:24 sites/default/files/Workspace/test.txt

Note that image files behave OK with their popup, but I have the same issue as test.txt with all non image files. The allowed extensions in the permissions config include the files I'm having trouble with.

Any suggestions on how to debug this?

Comments

nhck’s picture

Well those ~ are really strange there in your url? You should check your pathauto/path/url alias settings if they point to the right thing.

For debugging this problem you can do the following:
The function webfm_file_download takes care of the permission issues.
So you can check which filepath actually gets checked for by webfm. I modified the function for you:

function webfm_file_download($filepath) {
  if (!_webfm_managed_by_webfm($filepath)) {
    //file is not within webfm tree
    return NULL;
  }
   dpm($filepath, 'File is managed by webfm, this is the requested filepath:'); //TODO FOR DEBUG ONLY DO NOT USE IN PRODUCTION
  $file = webfm_get_file_record(NULL, $filepath);
	dpm($file, 'This data is stored by webfm about this file'); //TODO FOR DEBUG ONLY DO NOT USE IN PRODUCTION
  if (_webfm_check_access(NULL, $file)) {
    $filename = _webfm_basename($filepath);
    //filenames in IE containing dots will screw up the
    //filename unless we add this
    if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
      $filename = rawurlencode($filename);
    }
	dpm($filename, 'We will provide this file name for download'); //TODO FOR DEBUG ONLY DO NOT USE IN PRODUCTION
    //count download
    //TODO
    // Counting downloads should be an options.
    // If optoin is introduced also change $f = webfm_get_file_record(NULL, $filepath);
    if (!empty($file->fid)) {
      $cnt = array();
      $cnt['dl_cnt'] = (int)$file->dl_cnt + 1;
      webfm_dbupdate_file($file->fid, '', $cnt);
    }

    //prepare headers
    $header = array();
    if (_webfm_force_download()) {
      $header[] = 'Pragma: no-cache';
      $header[] = 'Cache-Control: no-cache, must-revalidate';
      $header[] = 'Content-Disposition: attachment; filename="'. $filename .'";' ;
    }
    else {
      $header[] = 'Pragma: public'; // required
      $header[] = 'Expires: 0';
      $header[] = 'Cache-Control: must-revalidate, post-check=0, pre-check=0';
      $header[] = 'Content-Transfer-Encoding: binary';
      $header[] = 'Content-Disposition: inline; filename="'. $filename .'";' ;
    }

    $header[] = 'Content-Type: '. file_get_mimetype($filename);
    $header[] = 'Content-Length: '. (string)(@filesize($filepath));
    $header[] = 'Connection: close';
    return $header;
  }
  else {
    dpm('access was denied by webfm');//TODO FOR DEBUG ONLY DO NOT USE IN PRODUCTION
    //access denied
    return -1;
  }
}

If the file access is denied by webfm actually, we will have to go into what goes wrong in _webfm_check_access()

Thank you.

mmilano’s picture

Status: Active » Closed (works as designed)

Thanks for the debug code. Sorry I didn't respond sooner, I must have missed the notification.

The debug messages reflected the valid file.

I added some debug to function file_download() in files.inc and invoked each active module individually to see what was returning the -1 to deny my download.

It is the CKEditor module.

I'm not sure what the resolution is yet, but I am closing this because it doesn't seem to be related to webfm.

Your time is much appreciated. Thank you.

mmilano’s picture

Updated the ckeditor module from 6.x-1.8 to 6.x-1.9 and the problem is fixed.

mmilano’s picture

Issue summary: View changes

markup