diff --git a/limitator b/limitator index dd64e8e..91485e1 100644 --- a/limitator +++ b/limitator @@ -14,8 +14,6 @@ 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 START_TIME limitator start_time '07:00' # Starting time of internet plan limited hours. -config_get END_TIME limitator end_time '23: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. @@ -137,14 +135,10 @@ 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) + 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 -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_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 + iptables -I $IPTABLES_FORWARD 2 -j $IPTABLES_CHAIN + iptables -I $IPTABLES_INPUT -i $WAN_DEV ! -s $INTRANET -j $IPTABLES_CHAIN + iptables -I $IPTABLES_OUTPUT -o $WAN_DEV ! -d $INTRANET -j $IPTABLES_CHAIN } start() { diff --git a/www/js/main.js b/www/js/main.js index 64e6fb6..4212bae 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -50,10 +50,10 @@ function getCounters(funcToParse) { function parseCounters(data) { let counters = JSON.parse(data); - document.getElementById("remaining").innerHTML = bytesToMegas(counters.remaining); - document.getElementById("used_bytes").innerHTML = bytesToMegas(counters.used_bytes); - document.getElementById("current_quota").innerHTML = bytesToMegas(counters.current_quota); - document.getElementById("total_quota").innerHTML = bytesToMegas(counters.total_quota); + document.getElementById("remaining").innerHTML = bytesToGigas(counters.remaining); + document.getElementById("used_bytes").innerHTML = bytesToGigas(counters.used_bytes); + document.getElementById("current_quota").innerHTML = bytesToGigas(counters.current_quota); + document.getElementById("total_quota").innerHTML = bytesToGigas(counters.total_quota); updateSpeed(counters.used_bytes); } @@ -77,6 +77,10 @@ function updateSpeed(used_bytes) { chart.update(); } +function bytesToGigas(number) { + return (number / 1024 / 1024 / 1024).toFixed(1) + ' GB'; +} + function bytesToMegas(number) { return (number / 1024 / 1024).toFixed(1) + ' MB'; }