Self-Hosted Downloads : Host your own downloadable products
	http://wiki.foxycart.com/integration:foxycart:self_hosted_downloads
	Version 0.1.0, 2008-02-18
	Created by Jeremy Saye (software@jeremysaye.com)
	Updated to version 0.3.0 for Amazon S3 by David Hollander (david@sparkweb.net)
	Distributed under the GPL License (see LICENSE.TXT for more information)
	Copyright (C) 2008 Jeremy Saye

=====================================================================
Purpose

This application is intended to extend/interface with the FoxyCart! e-commerce platform (http://www.foxycart.com). It allows clients to purchase downloadable products (such as software) through FoxyCart! and yet host and manage those products on their own server, or even using shared hosting. The client is emailed a unique, secure download link which will provide them with their purchased file. Downloads can be restricted with an expiration date or maximum number of downloads. The products and downloads are managed via a MySQL database. Files can be stored directly inside this database for maximum security against fraudulent downloads.

=====================================================================
Contents of the Application

	* config.inc.php : the configuration file
	* download.php : the script for users to download the file
	* generateLink.php : the script to process FoxyCart XML, generate the download links and email them to the customer

	* include/class.rc4crypt.php : RC4 class for encryption
	* include/class.xmlparser_php4.php : XML parser class for PHP 4
	* include/class.xmlparser_php5.php : XML parser class for PHP 5

	* setup/install.php : the database setup script
	* setup/testPost.php : the script for testing the application
	* setup/importProducts.php : the script to import product data into the application
	* setup/products.csv : a sample products file to use with importProducts.php

	* README.TXT : the documentation for the application
	* LICENSE.TXT : the GPL license

=====================================================================
Installation

* Upload the archive to your webserver and extract it (many FTP programs will do this for you automatically).

* Rename the default 'download_app' directory as you like. The entire application can even sit directly inside the document root.

* Open config.inc.php and customize the values. All of the options are fully explained within that file. The rest of the application is dependent on the database configuration being correct here (host, username, password, etc).

* Run the install.php script in a browser. This will look something like: 
http://yoursite.com/download_app/setup/install.php
The script will confirm your config file and create the necessary tables in your MySQL database.

* Customize the products.csv file (this can be renamed) with your product configuration.

* Upload the product files to the download directory specified in config.inc.php.

* Import your products into the database by opening the setup/importProducts.php script in a browser.

* Test the installation with the testPost.php script inside setup/. Customize the values at the top of the script and run it in your browser. You'll see 'foxy' displayed if all is well.

* The contents of the 'setup/' directory are not needed at this point and can be safely removed. importProducts.php will be useful for making updates to the product data later, however.

* Be sure to configure FoxyCart to post to the generateLink.php script.

=====================================================================
Usage

Once everything is set up, FoxyCart will automatically post your transactions at regular intervals throughout the day. The generateLink.php script will process the data, verify that each transaction and product are valid, generate secure download links and email them to the customer. When the customer clicks on the link, they are taken to download.php, which will verify their data and then send the appropriate file so long as the download has not expired. The admin user will be emailed if any problem occcurs.

If you have a database management application such as phpMyAdmin, it will be very easy to browse the Download table to scan for downloads that have not been fulfilled and such. The number of downloads and the most recent download date are stored for each purchase.

=====================================================================
Security Considerations

Remove the contents of the setup/ directory when you are finished with those scripts, or change the permissions on the directory so that it is not world-readable. Only allow permission to the directory again when you need to update products.csv.

If the download files are small enough, it is most secure to store them directly inside the database, in file_data. Access to that data is only allowed through a valid download link. The only problem with this approach is that some servers do not allow BLOB fields in MySQL databases to store more than a fixed amount of data, which may be 2MB, 8MB, 16MB, etc. Check in phpMyAdmin to see your current limit.

If the files will not fit in the database's file_data field, they should be stored in a protected directory. The directory may be outside of your document root (not necessarily if you are using shared hosting, however). Ensure that the apache user has permission to the directory.

=====================================================================
Legal

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.