-
Notifications
You must be signed in to change notification settings - Fork 0
Downloadaccess
'''An alternative download engine for MediaAttach'''
downloadAccess grants direct access to files instead of print the file's content as MediaAttach does and thus is mainly thought for big files.
It makes use of apache mod_rewrite's {{{RewriteMap}}} feature. Therefore it has some special requirements:
- Apache 2.1 or later
- Access to the vhost entry of the Domain
- Permission to exec a PHP script
downloadAccess pipes requests to files in a certain path to an PHP script. This script build up a connection to the MediaAttach data to identify the file and check whether the user has access to the file. If yes it rewrites the request to the file in a secret (the MediaAttach upload folder) directory. From the user's view it looks like the file is located in the given path. If the user has no access or if the file was not found we redirect (replacing the URL) to a Zikula page.
Since there is now script handling the download itself there are no execution timeouts which leads to broken files. In addition it's well performance for sites with many downloads.
- Copy source:misc/downloadAccess/dls.php somewhere to your server. Can be outside of your Webroot
- Set execution permission to dls.php (chmod +x dls.php)
- Copy source:misc/downloadAccess/redirect.php to modules/MediaAttach/pnuser or config/functions/MediaAttach/pnuser
- The MediaAttach file directory must be placed inside the webroot and accessible for every user. Use a random name to enhance security (Neither the MediaAttach download engine nor downloadAccess will show the directory to the user. So only be sure that they won't find it out nontheless)
Edit the dls.php and set the paths in lines 6 and 10 to your settings!
- Line 6: Logfile. If you does not want to log, comment this line and all lines with "fwrite"!
- Line 10: The path to your zikula root. We set this as our working directory to have easy access to the zikula files.
''The following RewriteRules must be set directly into the {{{}}} settings of your domain! This is a security measure of apache and can not be tourned off.'' {{{ RewriteEngine On RewriteMap MAdls prg:/path/to/your/dls.php RewriteCond %{HTTP_COOKIE} ZSID3=([^;]+) RewriteRule ^/downloads/(.+)$ /${MAdls:%1;$1} [PT,L] }}} If your Zikula installation is in a subdirectory, try {{{RewriteBase}}}! {{{ZSID3}}} seems to be the default name of the Zikula Session cookie. It may differ in your configuration.
Now we're using /downloads as the working directory.
You have to restart apache after edit this file!
Now you may test the whole thing by looking up a filename in your MA files directory and call it by http://example.org/downloads/filename.ext
By now you can create static links to the files in MediaAttach to use downloadAccess. If you want to use it without changing templates etc. you may edit MediaAttach/pnuser/download.php and integrate it there.
See source:misc/downloadAccess/download.php for examples!
If something does not work first have a look into the log files!
The downloadAccess-log gives informations about:
- absolute and relative (web) path to the MA files
- Incomming information (< SESSIONID;FILENAME)
- Outgoing information (> FILEPATH)
If no log information exists, there is definitive a problem :)
The apache logs may also give some hints!
You may start the dls.php in a shell to see if any error occurs. The script should not output anything unless you input a line (paste SESSIONID;FILENAME string from log file)
If you still can't track the error, write to philipp [at] zikula.org and hope for help ;)