Jump to content

Max download size


keldek

Recommended Posts

Hello, I'm not sure if this is the appropriate place for my question, but I think this would be an apache solved issue so here goes:

 

I'm using apache 2.2.4 and would like to set a limit on how much a user can download per day.

 

I'm using .htaccess/.htpasswd for user management (as my payment processor doesn't seem to support a db driven method of user management), which I'm sure could still work for what I need to do, considering every time a user logs in and downloads a file it also places their username in the access logs

 

An example of what I'd like to do is:

 

User "John" logs in to the members area. John can download an unlimited amount of files up to 2gb total. Once John has reached a total 2GB worth of downloads, he gets redirected to a specified page.

 

Any help, or ideas on this would be greatly appreciated and thank you in advance

Link to comment
Share on other sites

Apache has a module for this. Its called mod_cband.

 

Here is a how-to on installing and configing this module:

http://www.howtoforge.com/mod_cband_apache2_bandwidth_quota_throttling

 

If you dont admin the apache server - then you will have to do some sort of php download manager. There are PHP download manager scripts you can use, or you can use your own.

 

-steve

Link to comment
Share on other sites

I have mod_cband installed already and it doesn't seem to be what I need.

 

From the documentation I've read, I can set a max transfer quota (bandwidth), but not a max file size type quote.

 

I don't want to limit traffic really in any way, but once a user downloads a maximum of 2gb worth of files (.zip, .rar, .mp3, wmv, etc), they'd be redirected to a page saying they've exceeded their allowed limit for the day. The hope is to prevent password sharing and maintain some integrity with our members

Link to comment
Share on other sites

You might have to use VirtualHosts to seperate out users fully. I.e. user.host.com

 

Also - is it total transfer quota your are looking for? or

"Max file Size" Quota per user?

 

Thats about all I know about mod_cband Im afraid. That howtoforge website seems to provide a good how-to on it.

 

-steve

 

Link to comment
Share on other sites

I don't know if the VirtualHost method will work as we have 500+ users and get new users daily, users cancel daily, etc.

 

And yes, "Max file Size" Quota per user is exactly what I'm looking for :D

 

Say user John downloads 19 files that are ~100mb in size, once John downloads ~100mb file #20 (which would put him at 2gb total), he'd get redirected to a specified page when he attempts to download another file that day. The limit would be reset every 24 hours.

Link to comment
Share on other sites

its exactly what u want:

 

mod_cband is an Apache 2 module provided to solve the problem of limiting users' and virtualhosts' bandwidth usage. The current versions can set virtualhosts' and users' bandwidth quotas, maximal download speed (like in mod_bandwidth), requests-per-second speed and the maximal number of simultanous IP connections (like in mod_limitipconn)

 

http://cband.linux.pl/

 

Name 	CBandLimit
Description 	Specifies bandwidth limit for virtualhost
Context 	<Virtualhost>
Syntax 	CBandLimit limit

limit - bandwidth quota size, available units: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)

Example 	CBandLimit 10M
Specifies 10 * 1000 * 1000 bytes bandwidth quota

CBandLimit 10Mi
Specifies 10 * 1024 * 1024 bytes bandwidth quota 

 

Name 	CBandExceededURL
Description 	Specifies a URL where mod_cband should redirect all requests to a virtualhost when the configured transfer limit is exceeded NOTE: If you don't specify the exceeded URL location then standard 503 Service Unavailable will be sent
Context 	<Virtualhost>
Syntax 	CBandExceededURL URL

 

Name 	CBandPeriod
Description 	Specifies a period after which a virtualhost's usages are cleared
Context 	<Virtualhost>
Syntax 	CBandPeriod period

period - available units: S (seconds), M (minutes), H (hours), D (days), W (weeks)

Example 	CBandPeriod 1W
CBandPeriod 14D
CBandPeriod 60M

 

just do some reading mang :)

Link to comment
Share on other sites

I don't want to set a bandwidth quota though.

 

Name 	CBandLimit
Description 	Specifies bandwidth limit for virtualhost
Context 	<Virtualhost>
Syntax 	CBandLimit limit

limit - bandwidth quota size, available units: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)

Example 	CBandLimit 10M
Specifies 10 * 1000 * 1000 bytes bandwidth quota

CBandLimit 10Mi
Specifies 10 * 1024 * 1024 bytes bandwidth quota 

 

This only sets a limit for the Server or VirtualHost as a whole, meaning that once your Server/VHost reaches this limit then all users will recieve an error, be redirected, or speeds decreased. This directive does not work on a per user basis. While mod_cband does include directives on a per user basis, those directives are still for bandwidth quotas, not max download size quotas.

 

The other 2 samples of code do what I want (redirect), but I need to accomplish Step 1 (file size limit) before worrying about Step 2 (redirecting those who have exceeded their limit).

 

I've done several hours reading up on mod_cband, and I have it incorporated in my VHosts, but it does not provide a solution for what I want to do.

 

To clarify. I do not care about how fast a user downloads, this is NOT my goal. My goal is to set a maximum limit on total SIZE that a user can download per day (for specific file types), NOT throttling or limiting their bandwidth.

Link to comment
Share on other sites

then:

 

Name 	CBandUserLimit
Description 	Specifies bandwidth limit for a cband user
Context 	<CBandUser>
Syntax 	CBandUserLimit limit

limit - bandwidth quota size, available units: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)

Example 	CBandUserLimit 10M
Specifies 10 * 1000 * 1000 bytes bandwidth quota

CBandUserLimit 10Mi
Specifies 10 * 1024 * 1024 bytes bandwidth quota

Link to comment
Share on other sites

Our site is based on subscriptions, which means that using the <CBandUser> directive is very unrealistic for my needs. It would be impossible to keep the v-host config updated with the ever changing user base we have. If mod_cband had an option to use say "CBandRemoteLimit 10M" then I could flow with that. But after reading through all of their documentation, this is not an option.

 

The only directives for a "remote" client (which bases the directive on a per IP address basis) are for speed, connections, and max requests.

 

I *could* however use the CBandClassLimit directive, but I'd have to list every IP address range on the internet in order for this to actually work, which would also undoubtedly cause a server crash less than 10 seconds after restarting apache with that form of directive in place.

 

When I created this thread, I was hoping there was some way to log (via maybe .htaccess or php/database perhaps) when a user logs in to the members area, keep track of how much was downloaded per day, redirect if the maximum has been reached, and reset the quota every 24 hours.

 

I've read everything I possibly can on mod_cband and it doesn't do what I need :(

 

 

Link to comment
Share on other sites

How do you serve the files to be downloaded?

 

You probably will have to use a download script which will check for a quota and then serve a file.

 

A quick and dirty way (may not be good), would be to have the download script to a grep for the user in your apache logs for that day, and add up the total downloaded for a user.

Ideally you would have a proper download script with a MySQL database logging all usage of users. You can then see the high users etc. etc.

Im sure there is an open source file download manager that you can get working.

 

Let us know how you get on.

 

-steve

Link to comment
Share on other sites

Our downloads are handled via php, when a user goes to download a file, it calls the download.php, which calls the file and begins the download. The files themselves are not directly accessible via the web and can only be downloaded using this page.

 

I figured I could build on this script itself, and will probably be the path I take. Only problem is, php isn't exactly my strong suit hehe. I'll begin the search, trial, and error process and see what I can come up with :D

Link to comment
Share on other sites

Hi,

 

You can retrive the file size as follows:

$filesz = filesize($filename);

 

If you do not need to use the data for statistics, you should only store the total amount of daily downloaded filesize.

If you allow multiple login for users, you should check the value each time download.php is called.

 

Hope this helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.