1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-15 03:51:51 +00:00

Small cleaning codes changes in OMR-Tracker scripts

This commit is contained in:
Ycarus (Yannick Chabanois) 2024-07-05 16:01:10 +02:00
parent 17f047fe01
commit e33bd66daf
3 changed files with 62 additions and 62 deletions

View file

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# shellcheck disable=SC1091,SC1090 # shellcheck disable=SC1091,SC1090
# vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 : # vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 :
@ -34,9 +34,10 @@ export OMR_TRACKER_INTERVAL_TRIES
export OMR_TRACKER_INTERVAL export OMR_TRACKER_INTERVAL
export OMR_TRACKER_NO_BIND export OMR_TRACKER_NO_BIND
dscp=56 # set DSCP CS7 (56) in outgoing packets #dscp=56 # set DSCP CS7 (56) in outgoing packets
initial_hosts="$OMR_TRACKER_HOSTS"
initial_hosts6="$OMR_TRACKER_HOSTS6" #initial_hosts="$OMR_TRACKER_HOSTS"
#initial_hosts6="$OMR_TRACKER_HOSTS6"
initial_timeout="$OMR_TRACKER_TIMEOUT" initial_timeout="$OMR_TRACKER_TIMEOUT"
wait_test=${OMR_TRACKER_WAIT_TEST:-0} wait_test=${OMR_TRACKER_WAIT_TEST:-0}
@ -102,15 +103,15 @@ _post_tracking() {
} }
_ping_server() { _ping_server() {
local servername=$1 local servername="$1"
[ -z "$servername" ] && return [ -z "$servername" ] && return
local disabled=$(uci -q get openmptcprouter.$1.disabled) local disabled=$(uci -q get openmptcprouter."$servername".disabled)
local device=$2 local device="$2"
if [ -n "$device" ] && [ "$disabled" != "1" ]; then if [ -n "$device" ] && [ "$disabled" != "1" ]; then
check_ping() { check_ping() {
serverip=$1 serverip="$1"
if [ -n "$serverip" ]; then if [ -n "$serverip" ]; then
_ping $serverip $device "yes" _ping "$serverip" "$device" "yes"
statusp=$? statusp=$?
if $(exit $statusp); then if $(exit $statusp); then
serverip_ping=true serverip_ping=true
@ -119,21 +120,21 @@ _ping_server() {
fi fi
} }
config_load openmptcprouter config_load openmptcprouter
config_list_foreach ${servername} ip check_ping config_list_foreach "${servername}" ip check_ping
fi fi
} }
_httping_server() { _httping_server() {
local servername=$1 local servername="$1"
[ -z "$servername" ] && return [ -z "$servername" ] && return
local disabled=$(uci -q get openmptcprouter.$1.disabled) local disabled=$(uci -q get openmptcprouter."$servername".disabled)
local port=$(uci -q get openmptcprouter.$1.port) local port=$(uci -q get openmptcprouter."$servername".port)
local device=$2 local device="$2"
if [ -n "$device" ] && [ "$disabled" != "1" ]; then if [ -n "$device" ] && [ "$disabled" != "1" ]; then
check_ping() { check_ping() {
serverip=$1 serverip="$1"
if [ -n "$serverip" ]; then if [ -n "$serverip" ]; then
_httping "${serverip}:${port}" $device "yes" true _httping "${serverip}:${port}" "$device" "yes" true
statusp=$? statusp=$?
if $(exit $statusp); then if $(exit $statusp); then
serverip_ping=true serverip_ping=true
@ -142,15 +143,15 @@ _httping_server() {
fi fi
} }
config_load openmptcprouter config_load openmptcprouter
config_list_foreach ${servername} ip check_ping config_list_foreach "${servername}" ip check_ping
fi fi
} }
_ping() { _ping() {
local host=$1 local host="$1"
[ -z "$host" ] && return [ -z "$host" ] && return
local device=$2 local device="$2"
local localip=$3 local localip="$3"
if [ -n "$OMR_TRACKER_INTERFACE" ] && { [ "$OMR_TRACKER_NO_BIND" = "1" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "3g" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "qmi" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "ncm" ]; }; then if [ -n "$OMR_TRACKER_INTERFACE" ] && { [ "$OMR_TRACKER_NO_BIND" = "1" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "3g" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "qmi" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "ncm" ]; }; then
ret=$(ping -I "${device}" \ ret=$(ping -I "${device}" \
-w "$OMR_TRACKER_TIMEOUT" \ -w "$OMR_TRACKER_TIMEOUT" \
@ -162,7 +163,7 @@ _ping() {
) && echo "$ret" | grep -sq " 0% packet loss" && { ) && echo "$ret" | grep -sq " 0% packet loss" && {
if [ "$localip" = "yes" ]; then if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n') OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
_update_rto "$OMR_TRACKER_LATENCY" #_update_rto "$OMR_TRACKER_LATENCY"
fi fi
return return
} }
@ -184,7 +185,7 @@ _ping() {
latency=$(echo "$ret" | grep rtt | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n') latency=$(echo "$ret" | grep rtt | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
[ -n "$latency" ] && { [ -n "$latency" ] && {
OMR_TRACKER_LATENCY="$latency" OMR_TRACKER_LATENCY="$latency"
_update_rto "$OMR_TRACKER_LATENCY" #_update_rto "$OMR_TRACKER_LATENCY"
} }
OMR_TRACKER_LOSS="$loss" OMR_TRACKER_LOSS="$loss"
fi fi
@ -208,7 +209,7 @@ _httping() {
) && echo "$ret" | grep -sq "1 ok" && { ) && echo "$ret" | grep -sq "1 ok" && {
if [ "$localip" = "yes" ]; then if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n') OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
_update_rto "$OMR_TRACKER_LATENCY" #_update_rto "$OMR_TRACKER_LATENCY"
fi fi
return return
} }
@ -220,7 +221,7 @@ _httping() {
) && echo "$ret" | grep -sq "1 ok" && { ) && echo "$ret" | grep -sq "1 ok" && {
if [ "$localip" = "yes" ]; then if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n') OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
_update_rto "$OMR_TRACKER_LATENCY" #_update_rto "$OMR_TRACKER_LATENCY"
fi fi
return return
} }
@ -238,7 +239,7 @@ _dns() {
one.one.one.one one.one.one.one
) && echo "$ret" | grep -sq "1.1.1.1" && { ) && echo "$ret" | grep -sq "1.1.1.1" && {
OMR_TRACKER_LATENCY=$(echo "$ret" | awk '/Query time/{print $4}') OMR_TRACKER_LATENCY=$(echo "$ret" | awk '/Query time/{print $4}')
_update_rto "$OMR_TRACKER_LATENCY" #_update_rto "$OMR_TRACKER_LATENCY"
return return
} }
false false
@ -267,8 +268,8 @@ while true; do
OMR_TRACKER_DEVICE_GATEWAY6= OMR_TRACKER_DEVICE_GATEWAY6=
serverip_ping=false serverip_ping=false
[ -z "$OMR_TRACKER_DEVICE" ] && { [ -z "$OMR_TRACKER_DEVICE" ] && {
network_get_device OMR_TRACKER_DEVICE $OMR_TRACKER_INTERFACE network_get_device OMR_TRACKER_DEVICE "$OMR_TRACKER_INTERFACE"
[ -z "$OMR_TRACKER_DEVICE" ] && network_get_physdev OMR_TRACKER_DEVICE $OMR_TRACKER_INTERFACE [ -z "$OMR_TRACKER_DEVICE" ] && network_get_physdev OMR_TRACKER_DEVICE "$OMR_TRACKER_INTERFACE"
[ -z "$OMR_TRACKER_DEVICE" ] && OMR_TRACKER_DEVICE=$(ifstatus "$OMR_TRACKER_INTERFACE" | jsonfilter -q -e '@["l3_device"]') [ -z "$OMR_TRACKER_DEVICE" ] && OMR_TRACKER_DEVICE=$(ifstatus "$OMR_TRACKER_INTERFACE" | jsonfilter -q -e '@["l3_device"]')
[ -z "$OMR_TRACKER_DEVICE" ] && OMR_TRACKER_DEVICE=$(ifstatus "${OMR_TRACKER_INTERFACE}_4" | jsonfilter -q -e '@["l3_device"]') [ -z "$OMR_TRACKER_DEVICE" ] && OMR_TRACKER_DEVICE=$(ifstatus "${OMR_TRACKER_INTERFACE}_4" | jsonfilter -q -e '@["l3_device"]')
#[ -z "$OMR_TRACKER_DEVICE" ] && config_get OMR_TRACKER_DEVICE "$OMR_TRACKER_INTERFACE" device #[ -z "$OMR_TRACKER_DEVICE" ] && config_get OMR_TRACKER_DEVICE "$OMR_TRACKER_INTERFACE" device
@ -278,7 +279,7 @@ while true; do
if [ -n "$OMR_TRACKER_DEVICE" ] && [ -d "/sys/class/net/$OMR_TRACKER_DEVICE" ]; then if [ -n "$OMR_TRACKER_DEVICE" ] && [ -d "/sys/class/net/$OMR_TRACKER_DEVICE" ]; then
if [ -n "$(ip link show $OMR_TRACKER_DEVICE | grep 'state UP')" ] || [ -n "$(ip link show $OMR_TRACKER_DEVICE | grep 'state UNKNOWN')" ]; then if [ -n "$(ip link show $OMR_TRACKER_DEVICE | grep 'state UP')" ] || [ -n "$(ip link show $OMR_TRACKER_DEVICE | grep 'state UNKNOWN')" ]; then
# retrieve iface ip and gateway # retrieve iface ip and gateway
if ([ "$OMR_TRACKER_FAMILY" = "ipv4" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]) && [ "$OMR_TRACKER_INTERFACE_PROTO" != "dhcpv6" ]; then if { [ "$OMR_TRACKER_FAMILY" = "ipv4" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]; } && [ "$OMR_TRACKER_INTERFACE_PROTO" != "dhcpv6" ]; then
OMR_TRACKER_DEVICE_IP=$(ip -4 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}') OMR_TRACKER_DEVICE_IP=$(ip -4 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}')
if [ -z "$OMR_TRACKER_DEVICE_IP" ]; then if [ -z "$OMR_TRACKER_DEVICE_IP" ]; then
OMR_TRACKER_DEVICE_IP=$(ip -4 addr show dev "$OMR_TRACKER_DEVICE" | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1) OMR_TRACKER_DEVICE_IP=$(ip -4 addr show dev "$OMR_TRACKER_DEVICE" | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1)

View file

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 : # vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 :
name=$0 name=$0
@ -41,7 +41,7 @@ _check_server() {
local host=$1 local host=$1
local port=$2 local port=$2
local k=0 local k=0
local valid_ip6=$(valid_subnet6 $host) local valid_ip6=$(valid_subnet6 "$host")
while [ "$server_ping" = false ] && [ "$k" -le "$retry" ]; do while [ "$server_ping" = false ] && [ "$k" -le "$retry" ]; do
if [ "$valid_ip6" != "ok" ]; then if [ "$valid_ip6" != "ok" ]; then
ret=$(curl \ ret=$(curl \
@ -67,7 +67,7 @@ _check_server() {
_check_server_intf() { _check_server_intf() {
local host=$1 local host=$1
local port=$2 local port=$2
local valid_ip6=$(valid_subnet6 $host) local valid_ip6=$(valid_subnet6 "$host")
for intf in $(multipath 2>/dev/null | awk '/default/ {print $1}'); do for intf in $(multipath 2>/dev/null | awk '/default/ {print $1}'); do
local k=0 local k=0
while [ "$server_ping" = false ] && [ "$k" -le "$retry" ]; do while [ "$server_ping" = false ] && [ "$k" -le "$retry" ]; do
@ -76,7 +76,7 @@ _check_server_intf() {
--max-time "$OMR_TRACKER_TIMEOUT" \ --max-time "$OMR_TRACKER_TIMEOUT" \
-s \ -s \
-k \ -k \
--interface $intf \ --interface "$intf" \
"https://${host}:${port}/" "https://${host}:${port}/"
) )
else else
@ -99,7 +99,7 @@ _check_server_intf() {
_get_server_name() { _get_server_name() {
local serverid=$1 local serverid=$1
local serverip=$2 local serverip=$2
config_get serveripc $serverid server config_get serveripc "$serverid" server
if [ "$serveripc" = "$serverip" ]; then if [ "$serveripc" = "$serverip" ]; then
servername=$serverid servername=$serverid
fi fi
@ -107,25 +107,25 @@ _get_server_name() {
_disable_current() { _disable_current() {
local serv=$1 local serv=$1
uci -q set openmptcprouter.${server}.current=0 uci -q set openmptcprouter."${server}".current=0
} }
_disable_redir() { _disable_redir() {
local redir=$1 local redir="$1"
local serverdisable=$2 local serverdisable="$2"
local shadowsocks="$3" local shadowsocks="$3"
config_get serverss $redir server config_get serverss "$redir" server
if [ "$serverss" = "$serverdisable" ]; then if [ "$serverss" = "$serverdisable" ]; then
uci -q set ${shadowsocks}.${redir}.disabled=1 uci -q set "${shadowsocks}"."${redir}".disabled=1
fi fi
} }
_enable_redir() { _enable_redir() {
local redir=$1 local redir="$1"
local shadowsocks="$2" local shadowsocks="$2"
config_get serverss $redir server config_get serverss "$redir" server
if [ "$serverss" = "sss${count}" ]; then if [ "$serverss" = "sss${count}" ]; then
uci -q set ${shadowsocks}.${redir}.disabled=0 uci -q set "${shadowsocks}"."${redir}".disabled=0
fi fi
} }
@ -164,7 +164,7 @@ _check_master() {
set_ip() { set_ip() {
ip="$serverip" ip="$serverip"
if [ "$server_ping" = true ]; then if [ "$server_ping" = true ]; then
if ([ -n "$(uci -q get shadowsocks-libev)" ] && [ "$(uci -q get shadowsocks-libev.sss${count}.server | tr -d '\n')" != "$ip" ]) || ([ -n "$(uci -q get shadowsocks-rust)" ] && [ "$(uci -q get shadowsocks-rust.sss${count}.server | tr -d '\n')" != "$ip" ]) || ([ -n "$(uci -q get openvpn.omr)" ] && [ -z "$(uci -q get openvpn.omr.remote | grep $ip)" ]); then if { [ -n "$(uci -q get shadowsocks-libev)" ] && [ "$(uci -q get shadowsocks-libev.sss${count}.server | tr -d '\n')" != "$ip" ]; } || { [ -n "$(uci -q get shadowsocks-rust)" ] && [ "$(uci -q get shadowsocks-rust.sss${count}.server | tr -d '\n')" != "$ip" ]; } || { [ -n "$(uci -q get openvpn.omr)" ] && [ -z "$(uci -q get openvpn.omr.remote | grep $ip)" ]; }; then
logger -t "OMR-Tracker-Server" "Master server ${name} up ($ip), set it back" logger -t "OMR-Tracker-Server" "Master server ${name} up ($ip), set it back"
changes="1" changes="1"
#logger -t "OMR-Tracker-Server" "$(uci -q get shadowsocks-libev.sss${count}.server | tr -d '\n') - $ip" #logger -t "OMR-Tracker-Server" "$(uci -q get shadowsocks-libev.sss${count}.server | tr -d '\n') - $ip"
@ -217,7 +217,7 @@ _check_master() {
set openmptcprouter.${name}.current='1' set openmptcprouter.${name}.current='1'
commit openmptcprouter commit openmptcprouter
EOF EOF
/etc/init.d/openmptcprouter-vps get_openvpn_key $name >/dev/null 2>/dev/null /etc/init.d/openmptcprouter-vps get_openvpn_key "$name" >/dev/null 2>/dev/null
#/etc/init.d/openmptcprouter-vps restart >/dev/null 2>/dev/null #/etc/init.d/openmptcprouter-vps restart >/dev/null 2>/dev/null
/etc/init.d/v2ray restart >/dev/null 2>/dev/null /etc/init.d/v2ray restart >/dev/null 2>/dev/null
/etc/init.d/xray restart >/dev/null 2>/dev/null /etc/init.d/xray restart >/dev/null 2>/dev/null
@ -259,11 +259,11 @@ _check_master() {
servername="" servername=""
config_load shadowsocks-libev config_load shadowsocks-libev
config_foreach _get_server_name server "$ip" config_foreach _get_server_name server "$ip"
[ -n "$servername" ] && config_foreach _disable_redir ss_redir $servername "shadowsocks-libev" [ -n "$servername" ] && config_foreach _disable_redir ss_redir "$servername" "shadowsocks-libev"
servername="" servername=""
config_load shadowsocks-rust config_load shadowsocks-rust
config_foreach _get_server_name server "$ip" config_foreach _get_server_name server "$ip"
[ -n "$servername" ] && config_foreach _disable_redir ss_redir $servername "shadowsocks-rust" [ -n "$servername" ] && config_foreach _disable_redir ss_redir "$servername" "shadowsocks-rust"
if [ -n "$(uci -q get openvpn.omr.remote | grep $ip)" ]; then if [ -n "$(uci -q get openvpn.omr.remote | grep $ip)" ]; then
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null
@ -329,10 +329,10 @@ _check_backup() {
local count=0 local count=0
local countips=0 local countips=0
local changes="0" local changes="0"
config_get backup $1 backup config_get backup "$1" backup
config_get ip $1 ip config_get ip "$1" ip
config_get port $1 port config_get port "$1" port
config_get disabled $1 disabled config_get disabled "$1" disabled
serverip="" serverip=""
[ "$backup" = "1" ] && [ -n "$ip" ] && [ "$disabled" != "1" ] && { [ "$backup" = "1" ] && [ -n "$ip" ] && [ "$disabled" != "1" ] && {
check_ip() { check_ip() {
@ -359,7 +359,7 @@ _check_backup() {
ip="$serverip" ip="$serverip"
#[ "$server_ping" = true ] && [ "$(uci -q get shadowsocks-libev.sss${count}.server | tr -d '\n')" = "$ip" ] && break #[ "$server_ping" = true ] && [ "$(uci -q get shadowsocks-libev.sss${count}.server | tr -d '\n')" = "$ip" ] && break
if [ "$server_ping" = true ]; then if [ "$server_ping" = true ]; then
if ([ -n "$(uci -q get shadowsocks-libev)" ] && [ "$(uci -q get shadowsocks-libev.sss${count}.server | tr -d '\n')" != "$ip" ]) || ([ -n "$(uci -q get shadowsocks-rust)" ] && [ "$(uci -q get shadowsocks-rust.sss${count}.server | tr -d '\n')" != "$ip" ]) || ([ -n "$(uci -q get openvpn.omr)" ] && [ -z "$(uci -q get openvpn.omr.remote | grep $ip)" ]); then if { [ -n "$(uci -q get shadowsocks-libev)" ] && [ "$(uci -q get shadowsocks-libev.sss${count}.server | tr -d '\n')" != "$ip" ]; } || { [ -n "$(uci -q get shadowsocks-rust)" ] && [ "$(uci -q get shadowsocks-rust.sss${count}.server | tr -d '\n')" != "$ip" ]; } || { [ -n "$(uci -q get openvpn.omr)" ] && [ -z "$(uci -q get openvpn.omr.remote | grep $ip)" ]; }; then
logger -t "OMR-Tracker-Server" "Use backup server $1 ($ip)" logger -t "OMR-Tracker-Server" "Use backup server $1 ($ip)"
changes="1" changes="1"
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null
@ -407,7 +407,7 @@ _check_backup() {
set openmptcprouter.${name}.current='1' set openmptcprouter.${name}.current='1'
commit openmptcprouter commit openmptcprouter
EOF EOF
/etc/init.d/openmptcprouter-vps get_openvpn_key $name >/dev/null 2>/dev/null /etc/init.d/openmptcprouter-vps get_openvpn_key "$name" >/dev/null 2>/dev/null
#/etc/init.d/openmptcprouter-vps restart >/dev/null 2>/dev/null #/etc/init.d/openmptcprouter-vps restart >/dev/null 2>/dev/null
/etc/init.d/v2ray restart >/dev/null 2>/dev/null /etc/init.d/v2ray restart >/dev/null 2>/dev/null
/etc/init.d/xray restart >/dev/null 2>/dev/null /etc/init.d/xray restart >/dev/null 2>/dev/null
@ -452,11 +452,11 @@ _check_backup() {
EOF EOF
config_load shadowsocks-libev config_load shadowsocks-libev
config_foreach _get_server_name server "$ip" config_foreach _get_server_name server "$ip"
[ -n "$servername" ] && config_foreach _disable_redir ss_redir $servername "shadowsocks-libev" [ -n "$servername" ] && config_foreach _disable_redir ss_redir "$servername" "shadowsocks-libev"
servername="" servername=""
config_load shadowsocks-rust config_load shadowsocks-rust
config_foreach _get_server_name server "$ip" config_foreach _get_server_name server "$ip"
[ -n "$servername" ] && config_foreach _disable_redir ss_redir $servername "shadowsocks-rust" [ -n "$servername" ] && config_foreach _disable_redir ss_redir "$servername" "shadowsocks-rust"
OMR_TRACKER_STATUS_MSG="No answer to ping and to API check" OMR_TRACKER_STATUS_MSG="No answer to ping and to API check"
mail_alert="$(uci -q get omr-tracker.server.mail_alert)" mail_alert="$(uci -q get omr-tracker.server.mail_alert)"

View file

@ -1,7 +1,6 @@
#!/bin/sh #!/bin/bash
# vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 : # vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 :
name=$0
basename="$(basename $0)" basename="$(basename $0)"
if [ -e /usr/sbin/iptables-nft ]; then if [ -e /usr/sbin/iptables-nft ]; then
@ -79,11 +78,11 @@ interval=${OMR_TRACKER_INTERVAL:-10}
retry=${OMR_TRACKER_TRIES:-4} retry=${OMR_TRACKER_TRIES:-4}
proxy=${OMR_TRACKER_PROXY:-127.0.0.1:1111} proxy=${OMR_TRACKER_PROXY:-127.0.0.1:1111}
hosts=${OMR_TRACKER_HOSTS:-1.1.1.1 1.0.0.1} hosts=${OMR_TRACKER_HOSTS:-1.1.1.1 1.0.0.1}
hosts6=${OMR_TRACKER_HOSTS6} #hosts6=${OMR_TRACKER_HOSTS6}
wait_test=${OMR_TRACKER_WAIT_TEST:-0} wait_test=${OMR_TRACKER_WAIT_TEST:-0}
server=${OMR_TRACKER_SERVER:-sss0} server=${OMR_TRACKER_SERVER:-sss0}
type=${OMR_TRACKER_SS_TYPE:-libev} type=${OMR_TRACKER_SS_TYPE:-libev}
nodns=0 #nodns=0
last=0 last=0
nocontact="" nocontact=""
@ -98,7 +97,7 @@ while true; do
[ "$host" = "$hosts" ] || { [ "$host" = "$hosts" ] || {
hosts="${hosts#* } $host" hosts="${hosts#* } $host"
} }
if [ "$(curl -s -I -w %{http_code} --socks5 ${proxy} --max-time ${timeout} $host -o /dev/null)" != "000" ]; then if [ "$(curl -s -I -w %{http_code} --socks5 "${proxy}" --max-time "${timeout}" "$host" -o /dev/null)" != "000" ]; then
nocontact="" nocontact=""
[ "${last}" -ge "${retry}" ] || [ "$(uci -q get openmptcprouter.omr.ss_${server})" = "" ] && { [ "${last}" -ge "${retry}" ] || [ "$(uci -q get openmptcprouter.omr.ss_${server})" = "" ] && {
_log "Shadowsocks $type ${server} is up (can contact via http ${host})" _log "Shadowsocks $type ${server} is up (can contact via http ${host})"
@ -127,26 +126,26 @@ while true; do
_log "Reload Shadowsocks rules" _log "Reload Shadowsocks rules"
/etc/init.d/shadowsocks-libev rules_up 2> /dev/null /etc/init.d/shadowsocks-libev rules_up 2> /dev/null
if ! /etc/init.d/shadowsocks-libev rules_exist ; then if ! /etc/init.d/shadowsocks-libev rules_exist ; then
/etc/init.d/shadowsocks-libev restart 2>&1 >/dev/null /etc/init.d/shadowsocks-libev restart >/dev/null 2>&1
fi fi
_get_ip _get_ip
elif [ "$type" = "rust" ] && [ "$(uci -q get shadowsocks-rust.ss_rules.disabled)" != "1" ]; then elif [ "$type" = "rust" ] && [ "$(uci -q get shadowsocks-rust.ss_rules.disabled)" != "1" ]; then
_log "Reload Shadowsocks Rust rules" _log "Reload Shadowsocks Rust rules"
/etc/init.d/shadowsocks-rust rules_up 2> /dev/null /etc/init.d/shadowsocks-rust rules_up 2> /dev/null
if ! /etc/init.d/shadowsocks-rust rules_exist ; then if ! /etc/init.d/shadowsocks-rust rules_exist ; then
/etc/init.d/shadowsocks-rust restart 2>&1 >/dev/null /etc/init.d/shadowsocks-rust restart >/dev/null 2>&1
fi fi
_get_ip _get_ip
fi fi
fi fi
[ "$(uci -q get openmptcprouter.omr.detected_public_ipv4)" = "" ] || ([ "$(uci -q get openmptcprouter.settings.disable_ipv6)" != "1" ] && [ "$(uci -q get openmptcprouter.omr.detected_public_ipv6)" = "" ]) && _get_ip [ "$(uci -q get openmptcprouter.omr.detected_public_ipv4)" = "" ] || { [ "$(uci -q get openmptcprouter.settings.disable_ipv6)" != "1" ] && [ "$(uci -q get openmptcprouter.omr.detected_public_ipv6)" = "" ]; } && _get_ip
last=0 last=0
OMR_TRACKER_STATUS="OK" OMR_TRACKER_STATUS="OK"
else else
last=$((last + 1 )) last=$((last + 1 ))
[ -z "$nocontact" ] && nocontact="$host" || nocontact="$nocontact, $host" [ -z "$nocontact" ] && nocontact="$host" || nocontact="$nocontact, $host"
[ "${last}" -ge "${retry}" ] && { [ "${last}" -ge "${retry}" ] && {
if [ "$OMR_TRACKER_PREV_STATUS" != "ERROR" ] && ([ -n "$($IPTABLES -w -t nat -L -n 2>/dev/null | grep ssr)" ] || [ -n "$(nft list ruleset 2>/dev/null | grep ss_r)" ] || [ -n "$(nft list ruleset 2>/dev/null | grep ssr_r)" ]); then if [ "$OMR_TRACKER_PREV_STATUS" != "ERROR" ] && { [ -n "$($IPTABLES -w -t nat -L -n 2>/dev/null | grep ssr)" ] || [ -n "$(nft list ruleset 2>/dev/null | grep ss_r)" ] || [ -n "$(nft list ruleset 2>/dev/null | grep ssr_r)" ]; }; then
_log "Shadowsocks $type ${server} is down (can't contact via http ${nocontact})" _log "Shadowsocks $type ${server} is down (can't contact via http ${nocontact})"
OMR_TRACKER_STATUS_MSG="Shadowsocks $type ${server} is down (can't contact via http ${nocontact})" OMR_TRACKER_STATUS_MSG="Shadowsocks $type ${server} is down (can't contact via http ${nocontact})"
uci -q set openmptcprouter.omr.ss_${server}="down" uci -q set openmptcprouter.omr.ss_${server}="down"