Compare commits
6 Commits
dfcb1698e6
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e8391545b | |||
| e5c985fe00 | |||
| 42676e5b51 | |||
| 062b6da045 | |||
| d571db9700 | |||
| 144f20be81 |
27
README.md
27
README.md
@@ -3,17 +3,30 @@
|
|||||||
|
|
||||||
### Install
|
### Install
|
||||||
1) Copy `limitator` to `/etc/init.d/`
|
1) Copy `limitator` to `/etc/init.d/`
|
||||||
|
```
|
||||||
|
scp -O limitator root@ROUTER:/etc/init.d
|
||||||
|
```
|
||||||
2) Run `chmod +x /etc/init.d/limitator`
|
2) Run `chmod +x /etc/init.d/limitator`
|
||||||
3) Copy `config/limitator` to `/etc/config/`
|
3) Copy `config/limitator` to `/etc/config/`
|
||||||
4) Edit `/etc/config/` if needed.
|
```
|
||||||
|
scp -O config/limitator root@ROUTER:/etc/config
|
||||||
|
```
|
||||||
|
4) Edit `/etc/config/limitator` if needed.
|
||||||
5) Copy `www/*` to `/www/`
|
5) Copy `www/*` to `/www/`
|
||||||
|
```
|
||||||
|
scp -rO www root@ROUTER:/
|
||||||
|
```
|
||||||
6) Run `chmod +x /www/cgi-bin/limitator.json`
|
6) Run `chmod +x /www/cgi-bin/limitator.json`
|
||||||
7) Run `opkg update && opkg install iptables-mod-extra coreutils-date`
|
7) Run `opkg update && opkg install iptables-mod-extra coreutils-date`
|
||||||
8) Run `mkdir ~/limitator`
|
8) Run `opkg install iptables-mod-extra`
|
||||||
9) Run `crontab -e` and copy&paste contents in `crontab` file.
|
9) Run `opkg install coreutils-date`
|
||||||
10) Run `/etc/init.d/limitator enable`
|
10) Run `mkdir ~/limitator`
|
||||||
11) Reboot.
|
11) Run `crontab -e` and copy&paste contents in `crontab` file.
|
||||||
|
12) Run `/etc/init.d/limitator enable`
|
||||||
|
13) Reboot.
|
||||||
|
|
||||||
### Additional steps for Backfire 10.03
|
### Additional steps for Backfire 10.03
|
||||||
1) Install iptables-mod-ipopt
|
1) Change packages source in /etc/opkg.conf putting http://web.archive.org/web/20260213065024id_/ before the URL. For example: http://web.archive.org/web/20260213065024id_/https://archive.openwrt.org/backfire/10.03.1/brcm-2.4/packages
|
||||||
2) Delete /bin/date link
|
2) Install iptables-mod-ipopt (NO ESTOY SEGURO, SIN PONERLO FUNCIONA Y EN EL WRT54G DABA ERROR EL COMANDO IPTABLES CON EL MODULO QUOTA Y LO TENÍA INSTALADO)
|
||||||
|
3) Delete /bin/date link
|
||||||
|
4) Cannot scp files, you need to paste but vi messes with idents. Use `:set noai` command in vi. Other option is using wget from other routers (not an option for limitator.json).
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
config limitator 'limitator'
|
config limitator 'limitator'
|
||||||
option monthly_quota '90'
|
option quota '150'
|
||||||
option wan_dev 'eth1.1'
|
option wan_dev 'eth1.1'
|
||||||
option exclude_network '10.0.2.0/24'
|
option exclude_network '10.0.1.0/24'
|
||||||
option exclude_network '10.0.3.0/24'
|
option exclude_network2 '10.0.3.0/24'
|
||||||
|
option exclude_network3 '10.0.0.0/24'
|
||||||
option iptables_forward 'FORWARD'
|
option iptables_forward 'FORWARD'
|
||||||
option iptables_input 'INPUT'
|
option iptables_input 'INPUT'
|
||||||
option iptables_output 'OUTPUT'
|
option iptables_output 'OUTPUT'
|
||||||
|
|||||||
4
crontab
4
crontab
@@ -5,8 +5,8 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|||||||
*/10 7-23 * * * /etc/init.d/limitator save &
|
*/10 7-23 * * * /etc/init.d/limitator save &
|
||||||
# Restart at midnight
|
# Restart at midnight
|
||||||
1 0 1-12,14-31 * * /etc/init.d/limitator restart &
|
1 0 1-12,14-31 * * /etc/init.d/limitator restart &
|
||||||
# Reset the quota monthly
|
# Reset the quota monthly (MUST BE START DAY!)
|
||||||
1 0 13 * * /etc/init.d/limitator reset &
|
1 0 1 * * /etc/init.d/limitator reset &
|
||||||
|
|
||||||
# Reboot at 4:30am every day
|
# Reboot at 4:30am every day
|
||||||
# Note: To avoid infinite reboot loop, wait 70 seconds
|
# Note: To avoid infinite reboot loop, wait 70 seconds
|
||||||
|
|||||||
23
limitator
23
limitator
@@ -11,11 +11,9 @@ EXTRA_HELP=<<EOF
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
config_load "limitator"
|
config_load "limitator"
|
||||||
config_get MONTHLY_QUOTA limitator quota 15 # Monthly quota in GB
|
config_get MONTHLY_QUOTA limitator quota 120 # Monthly quota in GB
|
||||||
config_get WAN_DEV limitator wan_dev 'wlan0' # Interface name for WAN
|
config_get WAN_DEV limitator wan_dev 'wlan0' # Interface name for WAN
|
||||||
config_get FIRST_DAY limitator first_day 13 # Day of month when internet plan starts accounting..
|
config_get FIRST_DAY limitator first_day 1 # Day of month when internet plan starts accounting.
|
||||||
config_get START_TIME limitator start_time '08:00' # Starting time of internet plan limited hours.
|
|
||||||
config_get END_TIME limitator end_time '22:00' # Ending time of internet plan limited hours.
|
|
||||||
config_get INTRANET limitator intranet '10.0.0.0/8' # Traffic in Intranet does not count for quota.
|
config_get INTRANET limitator intranet '10.0.0.0/8' # Traffic in Intranet does not count for quota.
|
||||||
config_get EXCLUDE_NETWORK limitator exclude_network # Traffic originated in specified network does not count for quota.
|
config_get EXCLUDE_NETWORK limitator exclude_network # Traffic originated in specified network does not count for quota.
|
||||||
config_get EXCLUDE_NETWORK2 limitator exclude_network2 # Traffic originated in specified network does not count for quota.
|
config_get EXCLUDE_NETWORK2 limitator exclude_network2 # Traffic originated in specified network does not count for quota.
|
||||||
@@ -89,7 +87,12 @@ get_total_quota_until_today(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_remaining_quota(){
|
get_remaining_quota(){
|
||||||
echo -n $(($(get_total_quota_until_today) - $(get_current_used_bytes)))
|
local remaining_quota=$(($(get_total_quota_until_today) - $(get_current_used_bytes)))
|
||||||
|
if [ $remaining_quota -lt 0 ]; then
|
||||||
|
echo 0
|
||||||
|
else
|
||||||
|
echo -n $remaining_quota
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
show_remaining_quota(){
|
show_remaining_quota(){
|
||||||
@@ -137,15 +140,11 @@ set_iptables_rule(){
|
|||||||
iptables --wait -I $IPTABLES_CHAIN $(get_iptables_quota_rule_num) -c 0 $(get_saved_used_bytes) -m quota --quota $(get_remaining_quota) -j ACCEPT 2>> $LOG_FILE
|
iptables --wait -I $IPTABLES_CHAIN $(get_iptables_quota_rule_num) -c 0 $(get_saved_used_bytes) -m quota --quota $(get_remaining_quota) -j ACCEPT 2>> $LOG_FILE
|
||||||
iptables --wait -I $IPTABLES_CHAIN $(($(get_iptables_quota_rule_num) + 1)) -j REJECT 2>> $LOG_FILE
|
iptables --wait -I $IPTABLES_CHAIN $(($(get_iptables_quota_rule_num) + 1)) -j REJECT 2>> $LOG_FILE
|
||||||
|
|
||||||
# Iptables requires UTC time
|
|
||||||
local start_time_utc=$(date -u +%H:%M --date=@$(date -d "today $START_TIME" +%s))
|
|
||||||
local end_time_utc=$(date -u +%H:%M --date=@$(date -d "today $END_TIME" +%s))
|
|
||||||
|
|
||||||
|
|
||||||
iptables --wait -I $IPTABLES_FORWARD 1 -d $INTRANET -s $INTRANET -j ACCEPT
|
iptables --wait -I $IPTABLES_FORWARD 1 -d $INTRANET -s $INTRANET -j ACCEPT
|
||||||
iptables -I $IPTABLES_FORWARD 2 -m time --timestart $start_time_utc --timestop $end_time_utc -j $IPTABLES_CHAIN
|
iptables -I $IPTABLES_FORWARD 2 -j $IPTABLES_CHAIN
|
||||||
iptables -I $IPTABLES_INPUT -i $WAN_DEV ! -s $INTRANET -m time --timestart $start_time_utc --timestop $end_time_utc -j $IPTABLES_CHAIN
|
iptables -I $IPTABLES_INPUT -i $WAN_DEV ! -s $INTRANET -j $IPTABLES_CHAIN
|
||||||
iptables -I $IPTABLES_OUTPUT -o $WAN_DEV ! -d $INTRANET -m time --timestart $start_time_utc --timestop $end_time_utc -j $IPTABLES_CHAIN
|
iptables -I $IPTABLES_OUTPUT -o $WAN_DEV ! -d $INTRANET -j $IPTABLES_CHAIN
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
<h3>Descripción</h3>
|
<h3>Descripción</h3>
|
||||||
<p>El periodo de facturación de internet comienza el día 13. La cuota mensual se divide entre la cantidad de días
|
<p>El periodo de facturación de internet comienza el día 1. La cuota mensual se divide entre la cantidad de días
|
||||||
del periodo de facturación y se va asignando según transcurren los días. Si se sobrepasa la cuota asignada se
|
del periodo de facturación y se va asignando según transcurren los días. Si se sobrepasa la cuota asignada se
|
||||||
corta la conexión a internet y hay que esperar a que transcurra el día para que se asigne la cuota del próximo
|
corta la conexión a internet y hay que esperar a que transcurra el día para que se asigne la cuota del próximo
|
||||||
día.</p>
|
día.</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user