Compare commits

...
2 Commits
2 changed files with 22 additions and 28 deletions

No files matched your search

+1 -1
View File
@@ -29,4 +29,4 @@ scp -rO www root@ROUTER:/
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) 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).
4) In /etc/config/limitator set `iptables_args` to a space. The included version of iptables does not support `--wait` argument. Does not use empty string, it will assume variable is unset and it will use default value.
+21 -27
View File
@@ -23,8 +23,7 @@ config_get USED_BYTES_FILE limitator used_bytes_file '/root/limitator/used_bytes
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.
config_get IPTABLES_FORWARD limitator iptables_forward 'forwarding_rule' # Name of iptables rule for forward.
config_get IPTABLES_INPUT limitator iptables_input 'input_rule' # Name of iptables rule for input.
config_get IPTABLES_OUTPUT limitator iptables_output 'output_rule' # Name of iptables rule for output.
config_get IPTABLES_ARGS limitator iptables_args '--wait' # Additional arguments for iptables commands.
get_saved_used_bytes(){
local used_bytes
@@ -57,7 +56,7 @@ get_iptables_quota_rule_num(){
}
get_current_used_bytes(){
local used_bytes=$(iptables --wait -vnxL $IPTABLES_CHAIN $(get_iptables_quota_rule_num) | awk '{print $2}')
local used_bytes=$(iptables $IPTABLES_ARGS -vnxL $IPTABLES_CHAIN $(get_iptables_quota_rule_num) | awk '{print $2}')
if [ -n "$used_bytes" ];then
echo -n $used_bytes
else
@@ -110,50 +109,45 @@ get_json(){
}
reset_quota(){
iptables --wait -Z $IPTABLES_CHAIN $(get_iptables_quota_rule_num)
iptables $IPTABLES_ARGS -Z $IPTABLES_CHAIN $(get_iptables_quota_rule_num)
echo -n 0 > ${USED_BYTES_FILE}
}
del_iptables_rule(){
iptables --wait -F $IPTABLES_CHAIN
for chain_name in $IPTABLES_FORWARD $IPTABLES_INPUT $IPTABLES_OUTPUT
iptables $IPTABLES_ARGS -F $IPTABLES_CHAIN
while true
do
while true
do
line=$(iptables --wait -L $chain_name|sed -e '1,2d'|grep -n $IPTABLES_CHAIN|head -1|cut -d : -f 1 2>/dev/null)
[ -n "$(echo $line|grep -E ^[[:digit:]]+$)" ] && iptables --wait -D $chain_name $line || break
done
line=$(iptables $IPTABLES_ARGS -L $IPTABLES_FORWARD|sed -e '1,2d'|grep -n $IPTABLES_CHAIN|head -1|cut -d : -f 1 2>/dev/null)
[ -n "$(echo $line|grep -E ^[[:digit:]]+$)" ] && iptables $IPTABLES_ARGS -D $IPTABLES_FORWARD $line || break
done
iptables --wait -D $IPTABLES_FORWARD 1
iptables --wait -X $IPTABLES_CHAIN
iptables $IPTABLES_ARGS -D $IPTABLES_FORWARD 1
iptables $IPTABLES_ARGS -X $IPTABLES_CHAIN
}
set_iptables_rule(){
iptables --wait -N $IPTABLES_CHAIN
iptables $IPTABLES_ARGS -N $IPTABLES_CHAIN
if [ -n "$EXCLUDE_NETWORK" ];then
iptables --wait -I $IPTABLES_CHAIN 1 -s $EXCLUDE_NETWORK -j ACCEPT
iptables --wait -I $IPTABLES_CHAIN 2 -d $EXCLUDE_NETWORK -j ACCEPT
iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 1 -s $EXCLUDE_NETWORK -j ACCEPT
iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 2 -d $EXCLUDE_NETWORK -j ACCEPT
fi
if [ -n "$EXCLUDE_NETWORK2" ];then
iptables --wait -I $IPTABLES_CHAIN 3 -s $EXCLUDE_NETWORK2 -j ACCEPT
iptables --wait -I $IPTABLES_CHAIN 4 -d $EXCLUDE_NETWORK2 -j ACCEPT
iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 3 -s $EXCLUDE_NETWORK2 -j ACCEPT
iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 4 -d $EXCLUDE_NETWORK2 -j ACCEPT
fi
if [ -n "$EXCLUDE_NETWORK3" ];then
iptables --wait -I $IPTABLES_CHAIN 5 -s $EXCLUDE_NETWORK3 -j ACCEPT
iptables --wait -I $IPTABLES_CHAIN 6 -d $EXCLUDE_NETWORK3 -j ACCEPT
iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 5 -s $EXCLUDE_NETWORK3 -j ACCEPT
iptables $IPTABLES_ARGS -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
iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 7 -s $EXCLUDE_NETWORK4 -j ACCEPT
iptables $IPTABLES_ARGS -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
iptables $IPTABLES_ARGS -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 $IPTABLES_ARGS -I $IPTABLES_CHAIN $(($(get_iptables_quota_rule_num) + 1)) -j REJECT 2>> $LOG_FILE
iptables --wait -I $IPTABLES_FORWARD 1 -d $INTRANET -s $INTRANET -j ACCEPT
iptables $IPTABLES_ARGS -I $IPTABLES_FORWARD 1 -d $INTRANET -s $INTRANET -j ACCEPT
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
}
check_time_is_valid(){