Link to home
Start Free TrialLog in
Avatar of onewheelhk
onewheelhkFlag for Australia

asked on

How can I limit downloads for each user?

I have a client who runs a boarding house (mostly for international students). There are 5 rooms and people stay there for 2-weeks to 2 years. She gives them 50GB of broadband download per month on a wireless connection but they often use all the quota by mid-month and then everyone staying there is throttled back to dial-up speed (this is a common for ISP plans in Australia). Ideally she wants a way to limit each user to a certain download per month (say 10GB each) and then throttle just that user to dial-up speed allowing the others in the house to still have broadband. Does anyone have any ideas how I could set this up?
Avatar of Ultra_Master
Ultra_Master

Hi,

Try the following code that allows you to download a file with a speed limit you specify :
// local file that should be send to the client
$local_file = 'file_to_download.zip';
// filename that the user gets as default
$download_file = 'your-download-name.zip';
 
// set the download rate limit (=> 20,5 kb/s)
$download_rate = 20.5; 
if(file_exists($local_file) && is_file($local_file)) {
    // send headers
    header('Cache-control: private');
    header('Content-Type: application/octet-stream'); 
    header('Content-Length: '.filesize($local_file));
    header('Content-Disposition: filename='.$download_file);
 
    // flush content
    flush();    
    // open file stream
    $file = fopen($local_file, "r");    
    while(!feof($file)) {
 
        // send the current file part to the browser
        print fread($file, round($download_rate * 1024));    
 
        // flush the content to the browser
        flush();
 
        // sleep one second
        sleep(1);    
    }    
 
    // close file stream
    fclose($file);}
else {
    die('Error: The file '.$local_file.' does not exist!');
}

Open in new window

Avatar of onewheelhk

ASKER

The users are using their own PCs so I think I'm looking for a router/firewall solution or software (maybe hotspot or internet cafe type software) that will be the best for this scenario.  From my reseach so far, it seems that routers don' t have the capability to set up user names and passwords for each user on a wireless network and then measure and throttle when appropriate. So I'm thinking that I'll have to put a PC with 2 network cards between the wireless LAN and the modem - but I'm wondering which software can do this.
I thought of the client server issue.
As I can see this is more like actual Internet traffic usage oriented.
In this case, you can take a look at this:
http://sourceforge.net/apps/trac/ipcop/wiki
http://www.ipcop.org/1.4.0/en/admin/html/services.html#services_shaping

Good luck
Thanks for those suggestions. But I want to give download quotas to each user and only shape the individual user if he/she exceeds that limit.  These tools only seem to be able to shape by protocol.
ASKER CERTIFIED SOLUTION
Avatar of Ultra_Master
Ultra_Master

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pierre François
With the "advanced proxy" addon (see: http://www.advproxy.net) of the IPCop firewall (see http://sourceforge.net/apps/trac/ipcop/wiki as Ultra Master told you), you can limit the download speed per host. There is no volume limit per host. So you will have to set the download speed manually once a specific user has exhausted his quota.
Since there is no volume limit per host, how will we know when the specific user has exhausted his quota?
I expected that question... :D  You are right. I was looking for some addon doing that, but I only found an addon measuring the traffic on each interface, not for each host (Net-Traffic).

Well, there is a binary program called fetchipac that you can run from the crontab table and that collects information from the kernel about traffic on the several interfaces and stores it in a database. It can log the size, source and destination of each packet, and some other information. It is a part of the standard IPCop. Anyway, I see it is present in all my different configurations, in the directory /usr/sbin.

Sumarized data as recorded by fetchipac can be viewed by running ipacsum.

See http://martybugs.net/linux/ipac.cgi

Not trivial, but if you succeed, you can write an addon for IPCop in perl (just kidding, however...), inspired by net-traffic.

The beautiful thing with IPCop and ssh is that you can execute some commands remotely by issuing: ssh -P 222 hostname.remote.ipcop.box -l root "ipacsum options" from the command line of your local desktop.
SoftPerfect looks really good  - apart from one thing. The users are defined by IP addresses or MAC addresses. My client wants to look after this herself - I think configuring MAC addresses for users would be time-consuming & error prone (remembers some guests only stay a few weeks, and students may want to use several devices) and IP addresses can be guessed (or even if I chose several random numbers, it does not take a lot of IT ability to ask to use your neighbor's laptop for a minute and find out the IP address they are using and use it yourself when that person is out of the house). Ideally, I want a solution with usernames and passwords....
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for all your help but the IPCop solution looks a bit complex to set up and administer.  It would be OK if she had a full-time IT admin - but the client wants to administer this herself and does not know Linux and would prefer windows if possible.  This is the email that I sent her on this issue.


".... I initially thought it would be easy to find software to authenticate each user on the network and monitor their download volume –but unfortunately simple software to do this doesn’t seem to exist. I think the reason is that many countries (in particular the USA where much software is written) have unlimited download volumes from their ISPs and so do not have this problem.

Anyway this is a list of potential solutions – from cheap and simple to more expensive that you could try:

-      Your current connection speed has a theoretical speed of up to 10,000 Kbps but in reality is probably less than 2,000 Kbps (You can test your current speed at http://www.speedtest.net/ )  which after shaping  slows to 64Kbps.  Your ISP, Netspeed, has a plan which is unlimited but only 256Kbps for $79.95 per month. This is 4 times faster than you have been getting when shaped but admittedly a lot slower than before. However, this solution is the simplest as it only requires a phone call to your ISP.

The following solutions require a PC to be installed (around $500 for a new simple PC)

-      Softperfect Bandwidth Manager Software – US$99 per licence needs to be installed on a computer next to the modem. Almost does what you want, but it defines users by IP address (it would be fairly easy to guess or find out another person’s IP address) or MAC address (which is a little time-consuming and error-prone to configure). The lite version of this software US$35 could just measure the users’ downloads and you could (probably) see which person (s) are the ones using up all the usage and then ask them to stop doing so (or maybe pay more rent). More details at http://www.softperfect.com/products/bandwidth/ 

-      Anamedia hotspot software - US$200 per licence. Does most of what you need, except that it cannot shape the users down to a slower speed, it can only cut them off.  Also, sometime towards the end of the month you would need to access software to allow another month’s access.  This is geared for internet cafes/hotels which sell their services, so alternatively you could charge your guests usage by time or download amount. Eg Give them 8GB free, then charge them $10 for a further 3GB (this would still be within your plan but would make them think twice about downloading so much.) More details at http://www.antamedia.com/hotspot/ 

You can advise your guests that they can measure their own downloads with software like Netmeter (http://www.softpedia.com/get/Network-Tools/Bandwidth-Tools/NetMeter.shtml).

My recommendation would be to try the slower plan first and see if that speed is acceptable to your guests (256kbps is not too bad – a few years ago it would have been considered fast). But I’m happy to help you implement the other solutions too if you want, just let me know,

Roz

I appreciate all your help so I've divided the points between you even though no solution was perfect for me this time. Thanks