Zen Cart Logo
Forums / Bug Reports / Doc Product Type Download by redirect redirects to wrong .pub folder

Doc Product Type Download by redirect redirects to wrong .pub folder

Views: 8,232

Results 1 to 14 of 14
29 May 2019, 8:14 PM
#1
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Doc Product Type Download by redirect redirects to wrong .pub folder

156B
upload 156b fileset to mydomain.com/156
vanilla install into SUB-directory with demo products
make sure the subdirectory ( /156 in my case ) is appended in every field of the install window.

Change pub folder permissions to 777

Category: mixed product types
Product: sample of document product type $0.93

Add to cart
checkout using check/money order

Admin: change order status to delivered

Go to customer account.
Attempt to download product file

Redirects to ROOT pub folder instead of subdirectory install /156/pub folder
Thus, receive a 404 error because the folder/file does not exist in the Root pub folder

temp product download folder is in the /156/pub folder where expected to be.

30 May 2019, 7:55 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

As this issue appears similar to: https://www.zen-cart.com/showthread.php?225021-Cant-download-on-Free-orders and also to another thread about filling in the install fields that I can't seem to find at the moment, but recall discussing before.

Want to be sure/understand the statement about verifying that the subdirectory v156 being added to every field.

So the two fields where asked to identify the domain... what was entered was http://DOMAIN/v156 or https://DOMAIN/v156? Where DOMAIN is the domain name for your site and http: or https: was used as applicable, but both fields also included the subdirectory?

30 May 2019, 8:12 PM
#3
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

mc12345678:

As this issue appears similar to: https://www.zen-cart.com/showthread.php?225021-Cant-download-on-Free-orders and also to another thread about filling in the install fields that I can't seem to find at the moment, but recall discussing before.

Want to be sure/understand the statement about verifying that the subdirectory v156 being added to every field.

So the two fields where asked to identify the domain... what was entered was http://DOMAIN/v156 or https://DOMAIN/v156? Where DOMAIN is the domain name for your site and http: or https: was used as applicable, but both fields also included the subdirectory?

I note that the answer to my question will be a no because I incorrectly referenced the sub-directory name that is provided some 4 times in the original post. My example entries should have been: http://DOMAIN/156 or https://DOMAIN/156, though the questions still apply.

30 May 2019, 9:03 PM
#4
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

mc12345678:

As this issue appears similar to: https://www.zen-cart.com/showthread.php?225021-Cant-download-on-Free-orders and also to another thread about filling in the install fields that I can't seem to find at the moment, but recall discussing before.

Want to be sure/understand the statement about verifying that the subdirectory v156 being added to every field.

So the two fields where asked to identify the domain... what was entered was http://DOMAIN/v156 or https://DOMAIN/v156? Where DOMAIN is the domain name for your site and http: or https: was used as applicable, but both fields also included the subdirectory?

Surely you know ... about the 2nd or 3rd screen of an install where the there are 6 or 8 "paths". When you install to a subdirectory, some of those fields are prepopulated with the subdirectory appended to the root path and some do not.

I appended the subdirectory to all the ones that were not prepopulated to included the subdirectory. There's really no explanation on that screen of the install.

There are a few other irons in the fire today. I will step through another install into a different server subdirectory and get a screen print of the install screen for you.

Yes, this is nothing new. I had expected it to be corrected in the 156b. That's why I abandoned all work on 156 a couple of months ago.

30 May 2019, 9:50 PM
#5
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

Actually, it is the 2nd screen of a default install.
Left side is the default, prepopulated addresses.
Right side has the subdirectory appended.

I hoped/tried to provide enough info in the original post to duplicate the issue, step by step.

Attachment 18469

30 May 2019, 11:52 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

Well, you did identify what you did, though that was an unexpected action and why I had asked.

The best definition I found in the first page of search for "domain name definition" appeared to be from: https://www.webopedia.com/TERM/D/domain_name.html

Where the example provided in my opinion offering the simplest of explanations is: "For example, in the URL http://www.pcwebopedia.com/index.html, the domain name is pcwebopedia.com."

Another way I have thought about it is, I have an email address associated with my domain. Even if my site is served in a sub-directory, the email address doesn't include the sub-directory in the email address.

It may not play a role in this, but at least in future installations that you may do in a sub-directory shouldn't have to spend that extra time/thought on it. In fact, the only real time I've seen where I've had to really make modifications to these options has been if the server did not have a dedicated SSL for the site, but was instead on a shared server. In those cases, I've had to change the https: domain to that of the host's domain and some variation of the user's account.

But that again is for information/edification.

31 May 2019, 12:45 AM
#7
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

What I did was unexpected or the result was unexpected?

My thinking is that the zencart install should put things together so that they fall into the proper place when using the demo data. Isn't that the purpose of the demo data; to show how things are intended to work?

Putting the download files into the pub folder of the subdirectory where the entire cart was installed is one thing.

Having the download links which are saved into the customer order info/account info direct to a pub folder in the root directory just doesn't seem to be functioning as intended.

IOW, save the file in one location but direct the customer to a similar but completely different location.

So to satisfy my curiosity.... is this functioning as expected or is this a bug?

31 May 2019, 12:35 PM
#8
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

RixStix:

What I did was unexpected or the result was unexpected?

My thinking is that the zencart install should put things together so that they fall into the proper place when using the demo data. Isn't that the purpose of the demo data; to show how things are intended to work?

Putting the download files into the pub folder of the subdirectory where the entire cart was installed is one thing.

Having the download links which are saved into the customer order info/account info direct to a pub folder in the root directory just doesn't seem to be functioning as intended.

IOW, save the file in one location but direct the customer to a similar but completely different location.

So to satisfy my curiosity.... is this functioning as expected or is this a bug?
Well, just ran an install using the "setup" that you provided and without even performing a download operation can tell that I would likely come across the same issue that you have seen and well, even though I wrote that part of the sentence I went ahead and tried to download.

As suspected, the attempt to setup as described in the original post of this thread has caused the issue experienced.

By identifying the domain as domain/sub-directory, that information has populated HTTP_SERVER and left the DIR_WS_CATALOG to be populated with a single slash '/'. The result of this when attempting a download is that the DIR_FS_ related information is used to populate the server's files, but the DIR_WS_ portion is used to tell the customer's browser how to "reach" the file... The result of that though is for the browser to actually just try to reach the path that starts with a slash (the value of DIR_WS_CATALOG) with the remainder of the path to the public folder and the temporary file/folder name as built off of the true domain name (which in the above image is chainweavers.info with the prefix of http:). So the browser is told to go to the root of your store, but the pub folder in the file system for your current store actually is prepared to provide that file.

In this particular store, having performed an install in the same way as described and shown above, the HTTP_SERVER, HTTPS_SERVER, DIR_WS_CATALOG, and DIR_WS_HTTPS_CATALOG variables on the store side are incorrectly populated for the desire/need of this particular store/configuration. With that configuration showing that the HTTP_SERVER contains both the domain name and the sub-folder with an ending that has no slash, and then the DIR_WS_CATALOG variable to be a single slash. In a "normal" install where the site is simply being installed in a sub-folder to be accessed as a sub-folder, I would expect HTTP_SERVER to be just the domain name and DIR_WS_CATALOG to be '/156/'. If this were the case for this store, then the download by redirect would work as expected.

Okay, so that "fixes" this store, but there are occasions and configurations where a site needs to have a "sub-folder" as part of the domain name such as on a shared account where the host offers a SSL, but only through "building" off of the host's account. This also is seen when new domains are setup and perhaps only the ip address and "account name" is available. In those cases, the problem identified by RixStix would occur where the download would be attempted from the "host's" folder rather than the store's folder. To account for this, though I haven't tested all of the other possibilities of the download configurations (e.g. file is remotely retrieved, filename is modified for browser output, etc...) nor download methods (other than redirect), I propose the following change in:

includes/classes/observers/auto.downloads_via_redirect.php

Change from:

  /**
   * Class constructor
   */
  public function __construct()
  {

    if (DOWNLOAD_BY_REDIRECT != 'true') return false;

    $this->pubFolder = DIR_FS_DOWNLOAD_PUBLIC;
    $this->wsPubFolder = DIR_WS_DOWNLOAD_PUBLIC;

    // attach listener
    $this->attach($this, array('NOTIFY_DOWNLOAD_READY_TO_REDIRECT'));

    $this->gc_cleanup_time = 0;
    if (defined('SYMLINK_GARBAGE_COLLECTION_THRESHOLD') && (int)SYMLINK_GARBAGE_COLLECTION_THRESHOLD > 300) {
        $this->gc_cleanup_time = (int)SYMLINK_GARBAGE_COLLECTION_THRESHOLD;
    }
  }

to:

  /**
   * Class constructor
   */
  public function __construct()
  {

    if (DOWNLOAD_BY_REDIRECT != 'true') return false;

    $this->pubFolder = DIR_FS_DOWNLOAD_PUBLIC;
    
    $server_path = HTTP_SERVER;

    if (strpos($server_path, '//') !== false) {
      $server_path = substr($server_path, strpos($server_path, '//') + 2);
    }
    
    if (strpos($server_path, '/') !== false) {
      $server_path = substr($server_path, strpos($server_path, '/') + 1);
    }

    if (substr($server_path, 0, 1) !== '/') {
      $server_path = '/' . $server_path;
    }

    $this->wsPubFolder = $server_path . DIR_WS_DOWNLOAD_PUBLIC;

    // attach listener
    $this->attach($this, array('NOTIFY_DOWNLOAD_READY_TO_REDIRECT'));

    $this->gc_cleanup_time = 0;
    if (defined('SYMLINK_GARBAGE_COLLECTION_THRESHOLD') && (int)SYMLINK_GARBAGE_COLLECTION_THRESHOLD > 300) {
        $this->gc_cleanup_time = (int)SYMLINK_GARBAGE_COLLECTION_THRESHOLD;
    }
  }

For the issue related to the current site, I recommend that unless there is a known reason to change the sub-folder information or the domain name to accept the default values as they are for the current installation when installing to a sub-folder and move on. Ie. in this case, the information presented on the left side of the image in this post was perfectly fine for the configuration described as needed. To correct the current installation (not requiring a full reinstall unless want to just to see that it works as expected) in HTTP_SERVER type entries, remove '/156' and in DIR_WS_CATALOG type entries add '/156' as a prefix to the existing '/' so that it reads '/156/'.

changing from:

define('HTTP_SERVER', 'http://domain.com/156');
define('HTTPS_SERVER', 'https://domain.com/156');

define('DIR_WS_CATALOG', '/');
define('DIR_WS_HTTPS_CATALOG', '/');

to:

define('HTTP_SERVER', 'http://domain.com');
define('HTTPS_SERVER', 'https://domain.com');

define('DIR_WS_CATALOG', '/156/');
define('DIR_WS_HTTPS_CATALOG', '/156/');
31 May 2019, 1:02 PM
#9
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

Oops, minor code adjustment to ensure functionality for sites that do not have a sub-directory in their HTTP_SERVER related fields and to add code comments which led to discovering a need for a change:

New code suggestion:

  /**
   * Class constructor
   */
  public function __construct()
  {

    if (DOWNLOAD_BY_REDIRECT != 'true') return false;

    $this->pubFolder = DIR_FS_DOWNLOAD_PUBLIC;

    $server_path = HTTP_SERVER;

    // Remove the protocol from the path if present.
    if (strpos($server_path, '//') !== false) {
      $server_path = substr($server_path, strpos($server_path, '//') + 2);
    }

    // Remove the domain name from the path, if present.
    // if HTTP_SERVER does not contain a sub-directory then no change needed.
    // else remove the domain name and prefix the path to begin at the domain name.
    // Note that there are other potential incorrect configurations that are not tested here, such as 
    //   HTTP_SERVER ending with one or more slashes ('/'), DIR_WS_CATALOG not beginning with a slash, etc...
    if (strpos($server_path, '/') === false) {
      $server_path = '';
    } else {
      // Remove the domain name from the path if present.
      $server_path = substr($server_path, strpos($server_path, '/') + 1);

      // Prefix the path to ensure starting at the base of the domain name.
      if (substr($server_path, 0, 1) !== '/') {
        $server_path = '/' . $server_path;
      }
    }

    $this->wsPubFolder = $server_path . DIR_WS_DOWNLOAD_PUBLIC;

    // attach listener
    $this->attach($this, array('NOTIFY_DOWNLOAD_READY_TO_REDIRECT'));

    $this->gc_cleanup_time = 0;
    if (defined('SYMLINK_GARBAGE_COLLECTION_THRESHOLD') && (int)SYMLINK_GARBAGE_COLLECTION_THRESHOLD > 300) {
        $this->gc_cleanup_time = (int)SYMLINK_GARBAGE_COLLECTION_THRESHOLD;
    }
  }
31 May 2019, 1:13 PM
#10
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

Or life could be made "easy" by simply changing:

    $this->wsPubFolder = DIR_WS_DOWNLOAD_PUBLIC;

to this:

    $this->wsPubFolder = HTTP_SERVER . DIR_WS_DOWNLOAD_PUBLIC;

Unless there is some known reason that it was designed to not use that initial information in support of the other capabilities incorporated for downloads.

31 May 2019, 2:42 PM
#11
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

TNX for the explanation.

This is my sandbox server and used to record my install steps while testing functionality for when I actually upgrade the live server. Re-installs here are not a problem. Then, import existing database to this sandbox and start over with my data instead of demo data.

Modifying the distribution fileset is a near guarantee that future upgrades will not go as expected (as least for me) since there is no guarantee that any or which of the changes you suggest will make it to the future distribution fileset.

I just expected the vanilla install with demo data to be a functional demonstration before beginning customization or importation of existing data.

31 May 2019, 2:59 PM
#12
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

RixStix:

TNX for the explanation.

This is my sandbox server and used to record my install steps while testing functionality for when I actually upgrade the live server. Re-installs here are not a problem. Then, import existing database to this sandbox and start over with my data instead of demo data.

Modifying the distribution fileset is a near guarantee that future upgrades will not go as expected (as least for me) since there is no guarantee that any or which of the changes you suggest will make it to the future distribution fileset.

I just expected the vanilla install with demo data to be a functional demonstration before beginning customization or importation of existing data.

It is, though should be installed in accordance with the data defined. Ie. Not doing anything on that second screen other than confirming that you approve the installation was all that was necessary. That is inline also with your desire: default install with demo data to work as expected... :)

You did inadvertently identify an issue that I would say needs to be fixed, but through an abnormal process. The installation generally is straight forward offering those that need to do "special" things a way to do that up front rather than sifting through files, phpmyadmin, etc... For example, for me, typically on the database screen I have to modify localhost to something else because the server(s) accessed no longer support a "localhost" designation because the mysql database is maintained on a different server/reference. But, for those that have simply installed all on their one server, localhost works...

31 May 2019, 4:09 PM
#13
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

OK, so if I had accepted the default it would function as expected/intended? No problem. I will do that. That's all you had to say. I didn't see any explanation or notes regarding the subdirectory entries so I assumed that was a hiccup.

3 Jun 2019, 3:59 AM
#14
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Doc Product Type Download by redirect redirects to wrong .pub folder

PR submitted offering "both" methods of fix in the branch. Two commits submitted. First commit is the simple solution, the second replaces the first by removing the domain portion of the address from the full web-page address.

https://github.com/zencart/zencart/pull/2395

Note: this does not change the installation process nor the information on the installation page, it only addresses how the code should function for downloads when the HTTP_SERVER constant has one or more sub-directories in its define.