From 28dc5f542d6151e69c8bbfdf314fa00f843436a0 Mon Sep 17 00:00:00 2001 From: Eneko Nieto Date: Sat, 6 Aug 2022 18:47:18 +0200 Subject: [PATCH] Time limitation re-enabled --- config/limitator | 4 +++- limitator | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/config/limitator b/config/limitator index 7516496..a5194cb 100644 --- a/config/limitator +++ b/config/limitator @@ -1,6 +1,8 @@ config limitator 'limitator' + option monthly_quota '90' option wan_dev 'eth1.1' option exclude_network '10.0.2.0/24' + option exclude_network '10.0.3.0/24' option iptables_forward 'FORWARD' option iptables_input 'INPUT' - option iptables_output 'OUTPUT' \ No newline at end of file + option iptables_output 'OUTPUT' diff --git a/limitator b/limitator index 821b1dc..ada78c4 100644 --- a/limitator +++ b/limitator @@ -13,7 +13,9 @@ EOF config_load "limitator" config_get MONTHLY_QUOTA limitator quota 15 # Monthly quota in GB 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 13 # 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 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. @@ -134,11 +136,16 @@ set_iptables_rule(){ fi 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 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 2 -j $IPTABLES_CHAIN - iptables --wait -I $IPTABLES_INPUT -i $WAN_DEV ! -s $INTRANET -j $IPTABLES_CHAIN - iptables --wait -I $IPTABLES_OUTPUT -o $WAN_DEV ! -d $INTRANET -j $IPTABLES_CHAIN + iptables -I $IPTABLES_FORWARD 2 -m time --timestart $start_time_utc --timestop $end_time_utc -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_OUTPUT -o $WAN_DEV ! -d $INTRANET -m time --timestart $start_time_utc --timestop $end_time_utc -j $IPTABLES_CHAIN } start() {