From f44a31a46acf15e2b6feb3e03621176fa3bcfce3 Mon Sep 17 00:00:00 2001 From: bdaylik Date: Mon, 25 Mar 2024 13:11:43 +0300 Subject: [PATCH 1/5] update omr-quota to compare in kbits as mentioned in GUI (#308) vnstat by default reports the values in bits, however the OMR UI configuration asks values to be given in kbits. This commit fixes the omr-quota script by converting vnstat output to kbits. --- omr-quota/files/bin/omr-quota | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/omr-quota/files/bin/omr-quota b/omr-quota/files/bin/omr-quota index 65c2a2693..61198c9fb 100755 --- a/omr-quota/files/bin/omr-quota +++ b/omr-quota/files/bin/omr-quota @@ -11,8 +11,10 @@ shift # main loop while true; do OMR_QUOTA_REAL_INTERFACE="$(ifstatus $OMR_QUOTA_INTERFACE | jsonfilter -e '@.l3_device')" - rx=`vnstat -i $OMR_QUOTA_REAL_INTERFACE --json | jsonfilter -q -e '@.interfaces[0].traffic.month[-1].rx' | tr -d "\n"` - tx=`vnstat -i $OMR_QUOTA_REAL_INTERFACE --json | jsonfilter -q -e '@.interfaces[0].traffic.month[-1].tx' | tr -d "\n"` + rx_bits=`vnstat -i $OMR_QUOTA_REAL_INTERFACE --json | jsonfilter -q -e '@.interfaces[0].traffic.month[-1].rx' | tr -d "\n"` + tx_bits=`vnstat -i $OMR_QUOTA_REAL_INTERFACE --json | jsonfilter -q -e '@.interfaces[0].traffic.month[-1].tx' | tr -d "\n"` + rx=$((rx_bits/1024)) + tx=$((tx_bits/1024)) tt=$((rx + tx)) if [ -n "$OMR_QUOTA_RX" ] && [ "$OMR_QUOTA_RX" -gt 0 ] && [ -n "$rx" ] && [ "$OMR_QUOTA_RX" -le "$rx" ]; then if [ "$(ifstatus $OMR_QUOTA_INTERFACE | jsonfilter -e '@.up')" = "true" ]; then From 605be52f28247fe1d4db48a585c625fb014e7fc1 Mon Sep 17 00:00:00 2001 From: bdaylik Date: Mon, 25 Mar 2024 13:12:38 +0300 Subject: [PATCH 2/5] update vnstat_backup service to use default DatabaseDir if not specified (#307) --- openmptcprouter/files/etc/init.d/vnstat_backup | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openmptcprouter/files/etc/init.d/vnstat_backup b/openmptcprouter/files/etc/init.d/vnstat_backup index 02e9be314..37e2b4ebf 100755 --- a/openmptcprouter/files/etc/init.d/vnstat_backup +++ b/openmptcprouter/files/etc/init.d/vnstat_backup @@ -10,12 +10,13 @@ START=98 STOP=10 vnstat_option() { - sed -ne "s/^[;]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" /etc/vnstat.conf + sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" /etc/vnstat.conf } BACKUP_FILE=/etc/vnstat_backup.tar.gz LOGGER_TAG=vnstat_backup VNSTAT_DIR="$(vnstat_option DatabaseDir)" +[ -n "$VNSTAT_DIR" ] || VNSTAT_DIR="/var/lib/vnstat" _chk_omrquota() { config_get enabled $1 enabled From bb483535fa8167c2b201b6ddeff4525a4787d3a3 Mon Sep 17 00:00:00 2001 From: bdaylik Date: Mon, 25 Mar 2024 14:14:55 +0300 Subject: [PATCH 3/5] update omr-quota to up the interface when its usage is below threshold (#309) Existing condition for the upping the interface asks for all 3 checks to have positive values (RX, TX and TT). However this is not necessary as some can be set to 0 to disable the check. This modification makes sure that if the above checks for RX, TX and TT values have failed, thus the usage is still below the set quota, the interface is set to be up. Thanks to this modification its possible to set only one check positive (e.g. TT) and let the script automatically down and up the interface as expected. --- omr-quota/files/bin/omr-quota | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omr-quota/files/bin/omr-quota b/omr-quota/files/bin/omr-quota index 61198c9fb..b615ea8f6 100755 --- a/omr-quota/files/bin/omr-quota +++ b/omr-quota/files/bin/omr-quota @@ -31,7 +31,7 @@ while true; do logger -t "OMR-QUOTA" "Set interface $OMR_QUOTA_INTERFACE down, RX+TX quota reached" ifdown $OMR_QUOTA_INTERFACE fi - elif [ -n "$OMR_QUOTA_RX" ] && [ "$OMR_QUOTA_RX" -gt 0 ] && [ -n "$OMR_QUOTA_TX" ] && [ "$OMR_QUOTA_TX" -gt 0 ] && [ -n "$OMR_QUOTA_TT" ] && [ "$OMR_QUOTA_TT" -gt 0 ] && [ "$(ifstatus $OMR_QUOTA_INTERFACE | jsonfilter -e '@.up')" = "false" ]; then + elif [ "$(ifstatus $OMR_QUOTA_INTERFACE | jsonfilter -e '@.up')" = "false" ]; then logger -t "OMR-QUOTA" "Set interface $OMR_QUOTA_INTERFACE up" ifup $OMR_QUOTA_INTERFACE fi From 4be2308e8b1920a0884c81895dc7f84a9b5bba8c Mon Sep 17 00:00:00 2001 From: bdaylik Date: Mon, 25 Mar 2024 14:16:08 +0300 Subject: [PATCH 4/5] update vnstat_backup service to start before and end after the vnstat service (#310) Currently vnstat_backup service runs after vnstat runs and overwrites newly initialized database of vnstat causing it to crash and restart. Moving vnstat_backup service before vnstat lets it create the database before vnstat runs. This allows an error free operation. --- openmptcprouter/files/etc/init.d/vnstat_backup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openmptcprouter/files/etc/init.d/vnstat_backup b/openmptcprouter/files/etc/init.d/vnstat_backup index 37e2b4ebf..1434285d3 100755 --- a/openmptcprouter/files/etc/init.d/vnstat_backup +++ b/openmptcprouter/files/etc/init.d/vnstat_backup @@ -6,8 +6,8 @@ EXTRA_HELP=< Date: Mon, 25 Mar 2024 11:13:21 +0100 Subject: [PATCH 5/5] Change proxy firewall priority --- shadowsocks-libev/files/nft-rules/chain.uc | 2 +- shadowsocks-rust/files/nft-rules/chain.uc | 2 +- v2ray-core/files/usr/share/v2ray-rules/chain.uc | 2 +- xray-core/files/usr/share/xray-rules/chain.uc | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shadowsocks-libev/files/nft-rules/chain.uc b/shadowsocks-libev/files/nft-rules/chain.uc index 3b2cc0813..9da09f27a 100644 --- a/shadowsocks-libev/files/nft-rules/chain.uc +++ b/shadowsocks-libev/files/nft-rules/chain.uc @@ -43,7 +43,7 @@ let type, hook, priority, redir_port; if (proto == "tcp") { type = "nat"; hook = "prerouting"; - priority = -1; + priority = 1; redir_port = o_redir_tcp_port; } else if (proto == "udp") { type = "filter"; diff --git a/shadowsocks-rust/files/nft-rules/chain.uc b/shadowsocks-rust/files/nft-rules/chain.uc index 3b2cc0813..9da09f27a 100644 --- a/shadowsocks-rust/files/nft-rules/chain.uc +++ b/shadowsocks-rust/files/nft-rules/chain.uc @@ -43,7 +43,7 @@ let type, hook, priority, redir_port; if (proto == "tcp") { type = "nat"; hook = "prerouting"; - priority = -1; + priority = 1; redir_port = o_redir_tcp_port; } else if (proto == "udp") { type = "filter"; diff --git a/v2ray-core/files/usr/share/v2ray-rules/chain.uc b/v2ray-core/files/usr/share/v2ray-rules/chain.uc index c0855c674..34075d9c8 100644 --- a/v2ray-core/files/usr/share/v2ray-rules/chain.uc +++ b/v2ray-core/files/usr/share/v2ray-rules/chain.uc @@ -43,7 +43,7 @@ let type, hook, priority, redir_port; if (proto == "tcp") { type = "nat"; hook = "prerouting"; - priority = -1; + priority = 1; redir_port = o_redir_tcp_port; } else if (proto == "udp") { type = "filter"; diff --git a/xray-core/files/usr/share/xray-rules/chain.uc b/xray-core/files/usr/share/xray-rules/chain.uc index cb46ba5e8..be456b014 100644 --- a/xray-core/files/usr/share/xray-rules/chain.uc +++ b/xray-core/files/usr/share/xray-rules/chain.uc @@ -43,7 +43,7 @@ let type, hook, priority, redir_port; if (proto == "tcp") { type = "nat"; hook = "prerouting"; - priority = -1; + priority = 1; redir_port = o_redir_tcp_port; } else if (proto == "udp") { type = "filter";