Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e444500175 | ||
|
|
f4847d768a |
@@ -1,5 +1,5 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
START=95
|
||||
START=99
|
||||
STOP=01
|
||||
|
||||
EXTRA_COMMANDS="save reset show json"
|
||||
@@ -18,6 +18,7 @@ config_get INTRANET limitator intranet '10.0.0.0/8' # Traffic in Intranet does n
|
||||
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_NETWORK3 limitator exclude_network3 # Traffic originated in specified network does not count for quota.
|
||||
config_get EXCLUDE_NETWORK4 limitator exclude_network4 # Traffic originated in specified network does not count for quota.
|
||||
config_get USED_BYTES_FILE limitator used_bytes_file '/root/limitator/used_bytes' # A persistent file to save used bytes value.
|
||||
config_get LOG_FILE limitator log_file '/root/limitator/log' # A persistent file to log.
|
||||
config_get IPTABLES_CHAIN limitator iptables_chain 'LIMITATOR' # Name of iptables chain.
|
||||
@@ -39,7 +40,11 @@ get_iptables_quota_rule_num(){
|
||||
if [ -n "$EXCLUDE_NETWORK" ];then
|
||||
if [ -n "$EXCLUDE_NETWORK2" ];then
|
||||
if [ -n "$EXCLUDE_NETWORK3" ];then
|
||||
echo -n 7
|
||||
if [ -n "$EXCLUDE_NETWORK4" ];then
|
||||
echo -n 9
|
||||
else
|
||||
echo -n 7
|
||||
fi
|
||||
else
|
||||
echo -n 5
|
||||
fi
|
||||
@@ -137,6 +142,10 @@ set_iptables_rule(){
|
||||
iptables --wait -I $IPTABLES_CHAIN 5 -s $EXCLUDE_NETWORK3 -j ACCEPT
|
||||
iptables --wait -I $IPTABLES_CHAIN 6 -d $EXCLUDE_NETWORK3 -j ACCEPT
|
||||
fi
|
||||
if [ -n "$EXCLUDE_NETWORK4" ];then
|
||||
iptables --wait -I $IPTABLES_CHAIN 7 -s $EXCLUDE_NETWORK4 -j ACCEPT
|
||||
iptables --wait -I $IPTABLES_CHAIN 8 -d $EXCLUDE_NETWORK4 -j ACCEPT
|
||||
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
|
||||
|
||||
@@ -147,7 +156,23 @@ set_iptables_rule(){
|
||||
iptables -I $IPTABLES_OUTPUT -o $WAN_DEV ! -d $INTRANET -j $IPTABLES_CHAIN
|
||||
}
|
||||
|
||||
check_time_is_valid(){
|
||||
local current_time=$(date +'%s')
|
||||
local retries=0
|
||||
|
||||
while [ $current_time -lt 1780000000 ]; do
|
||||
if [ $retries -ge 60 ]; then
|
||||
echo "No valid date after 60 retries, exiting" >> $LOG_FILE
|
||||
exit 1
|
||||
fi
|
||||
sleep 10
|
||||
((retries++))
|
||||
current_time=$(date +'%s')
|
||||
done
|
||||
}
|
||||
|
||||
start() {
|
||||
check_time_is_valid
|
||||
set_iptables_rule
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user