ByteLimit
ByteLimit gives you an opportunity to limit user's uploud/download when user downloads too much.
This script uses a result file of IP Flow Meter:
HOST
IN OUT
TOTAL
192.168.1.3 12345
6666684 6679029
192.168.2.5 1232314
12345 1244659
10.167.9.6 6645632
123 6645755
You should configure this program without DNS resolution.
How does ByteLimit work? ByteLimit compares a number of bytes, that each IP has downloaded with the allowed number.
Then it creates a list of IPs to limit. After that your HTB script is scanned for flowid number of each IP. Finally your script
is rewrited to a new file with new limits.
I strongly suggest making a backup copy of your HTB script.
Download
Requirements:
1. IP Flow Meter configured correctly. HowTo
2. Your HTB script should include only tc commands (each line starts with 'tc', clear IPs - no $computer1),
commentary and #!/bin/bash (etc.).
3. Each user should have his own flowid.
4. I suggest having 2 HTB scripts - one bandwidthing upload and the second one download.
You will configure ByteLimit to edit only one of files (it will work faster).
Installation:
1. Download ByteLimit and place files in e.g. /bytelimit/.
2. Edit /bytelimit/ByteLimit.cpp file and change the #define values:
#define SOURCE_FILE "/ipfm/ipfm"
// Path to result file of IP Flow Meter.
#define IP_LIST "/bytelimit/iplist"
// File with a list of IPs (see below).
#define RCHTB "/configs/rc.htb_download"
// Path to old HTB file.
#define RESULT "/configs/rc.htb_download_lim"
// New HTB file (including limits).
#define WAY "dst"
// "dst" for download or "src" for upload.
3. Create IP_LIST file. Format: [IP] [how many Kbytes can be downloaded] [new speed (kbit)]. If you don't place an IP here, it has no limits. For example:
192.168.1.3 5242880 10
192.168.2.5 6291456 20
10.167.9.6 9437184 30
192.168.1.3 can download 5GB and his speed will be limited to 10kbit after crossing this limit.
4. Compile ByteLimit.cpp:
g++ ByteLimit.cpp -o ByteLimit
5. Edit /bytelimit/Limit and put currect values.
6. Edit crontab to run /bytelimit/Limit (as root) for example each day and your oryginal script first day each mounth.
Copyright by Lukasz Antoniak (L.Antoniak@stud.elka.pw.edu.pl). All rights reserved.
|