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

Update omr-tracker for multi IPs server

This commit is contained in:
Ycarus (Yannick Chabanois) 2021-01-25 09:32:23 +01:00
parent 16ab9a7722
commit 087561e002
3 changed files with 113 additions and 98 deletions

View file

@ -39,84 +39,103 @@ _check_server() {
_check_master() {
local name=$1
local count=0
config_get master $1 master
config_get ip $1 ip
config_get port $1 port "65500"
config_get disabled $1 disabled
[ "$master" = "1" ] && [ -n "$ip" ] && [ "$disabled" != "1" ] && {
#_ping_server $ip
_check_server $ip $port
[ "$server_ping" = true ] && [ "$(uci -q get shadowsocks-libev.sss0.server | tr -d '\n')" != "$ip" ] && {
logger -t "OMR-Tracker-Server" "Master server up, set it back"
logger -t "OMR-Tracker-Server" "$(uci -q get shadowsocks-libev.sss0.server | tr -d '\n') - $ip"
uci -q batch <<-EOF >/dev/null
set shadowsocks-libev.sss0.server=$ip
commit shadowsocks-libev
set v2ray.omrout.s_vmess_address=$ip
set v2ray.omrout.s_vless_address=$ip
commit v2ray
set glorytun.vpn.host=$ip
commit glorytun
set dsvpn.vpn.host=$ip
commit dsvpn
set mlvpn.general.host=$ip
commit mlvpn
del openvpn.omr.remote
add_list openvpn.omr.remote=$ip
commit openvpn
EOF
/etc/init.d/openmptcprouter-vps get_openvpn_key $name >/dev/null 2>/dev/null
/etc/init.d/shadowsocks-libev restart >/dev/null 2>/dev/null
/etc/init.d/v2ray restart >/dev/null 2>/dev/null
/etc/init.d/glorytun restart >/dev/null 2>/dev/null
/etc/init.d/glorytun-udp restart >/dev/null 2>/dev/null
/etc/init.d/mlvpn restart >/dev/null 2>/dev/null
/etc/init.d/openvpn restart >/dev/null 2>/dev/null
/etc/init.d/dsvpn restart >/dev/null 2>/dev/null
set_ip() {
local ip=$1
#_ping_server $ip
_check_server $ip $port
[ "$server_ping" = true ] && [ "$(uci -q get shadowsocks-libev.sss${count}.server | tr -d '\n')" != "$ip" ] && {
logger -t "OMR-Tracker-Server" "Master server up, set it back"
logger -t "OMR-Tracker-Server" "$(uci -q get shadowsocks-libev.sss${count}.server | tr -d '\n') - $ip"
uci -q batch <<-EOF >/dev/null
set shadowsocks-libev.sss${count}.server=$ip
commit shadowsocks-libev
EOF
if [ "$count" -eq "0" ]; then
uci -q batch <<-EOF >/dev/null
set v2ray.omrout.s_vmess_address=$ip
set v2ray.omrout.s_vless_address=$ip
commit v2ray
set glorytun.vpn.host=$ip
commit glorytun
set dsvpn.vpn.host=$ip
commit dsvpn
set mlvpn.general.host=$ip
commit mlvpn
del openvpn.omr.remote
add_list openvpn.omr.remote=$ip
commit openvpn
EOF
/etc/init.d/openmptcprouter-vps get_openvpn_key $name >/dev/null 2>/dev/null
/etc/init.d/v2ray restart >/dev/null 2>/dev/null
/etc/init.d/glorytun restart >/dev/null 2>/dev/null
/etc/init.d/glorytun-udp restart >/dev/null 2>/dev/null
/etc/init.d/mlvpn restart >/dev/null 2>/dev/null
/etc/init.d/openvpn restart >/dev/null 2>/dev/null
/etc/init.d/dsvpn restart >/dev/null 2>/dev/null
fi
/etc/init.d/shadowsocks-libev restart >/dev/null 2>/dev/null
}
count=$((count+1))
}
config_list_foreach $1 ip set_ip
break
}
}
_check_backup() {
local name=$1
local count=0
config_get backup $1 backup
config_get ip $1 ip
config_get port $1 port
config_get disabled $1 disabled
[ "$backup" = "1" ] && [ -n "$ip" ] && [ "$disabled" != "1" ] && {
#_ping_server $ip
_check_server $ip $port
[ "$server_ping" = true ] && [ "$(uci -q get shadowsocks-libev.sss0.server | tr -d '\n')" = "$ip" ] && break
[ "$server_ping" = true ] && [ "$(uci -q get shadowsocks-libev.sss0.server | tr -d '\n')" != "$ip" ] && {
logger -t "OMR-Tracker-Server" "Use backup server $1 ($ip)"
uci -q batch <<-EOF >/dev/null
set shadowsocks-libev.sss0.server=$ip
commit shadowsocks-libev
set v2ray.omrout.s_vmess_address=$ip
set v2ray.omrout.s_vless_address=$ip
commit v2ray
set glorytun.vpn.host=$ip
commit glorytun
set dsvpn.vpn.host=$ip
commit dsvpn
set mlvpn.general.host=$ip
commit mlvpn
del openvpn.omr.remote
add_list openvpn.omr.remote=$ip
commit openvpn
EOF
/etc/init.d/openmptcprouter-vps get_openvpn_key $name >/dev/null 2>/dev/null
/etc/init.d/shadowsocks-libev restart >/dev/null 2>/dev/null
/etc/init.d/v2ray restart >/dev/null 2>/dev/null
/etc/init.d/glorytun restart >/dev/null 2>/dev/null
/etc/init.d/glorytun-udp restart >/dev/null 2>/dev/null
/etc/init.d/mlvpn restart >/dev/null 2>/dev/null
/etc/init.d/openvpn restart >/dev/null 2>/dev/null
/etc/init.d/dsvpn restart >/dev/null 2>/dev/null
sleep $waittest
break
set_ip() {
#_ping_server $ip
_check_server $ip $port
[ "$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" ] && {
logger -t "OMR-Tracker-Server" "Use backup server $1 ($ip)"
uci -q batch <<-EOF >/dev/null
set shadowsocks-libev.sss${count}.server=$ip
commit shadowsocks-libev
EOF
if [ "$count" -eq "0" ]; then
uci -q batch <<-EOF >/dev/null
set v2ray.omrout.s_vmess_address=$ip
set v2ray.omrout.s_vless_address=$ip
commit v2ray
set glorytun.vpn.host=$ip
commit glorytun
set dsvpn.vpn.host=$ip
commit dsvpn
set mlvpn.general.host=$ip
commit mlvpn
del openvpn.omr.remote
add_list openvpn.omr.remote=$ip
commit openvpn
EOF
/etc/init.d/openmptcprouter-vps get_openvpn_key $name >/dev/null 2>/dev/null
/etc/init.d/v2ray restart >/dev/null 2>/dev/null
/etc/init.d/glorytun restart >/dev/null 2>/dev/null
/etc/init.d/glorytun-udp restart >/dev/null 2>/dev/null
/etc/init.d/mlvpn restart >/dev/null 2>/dev/null
/etc/init.d/openvpn restart >/dev/null 2>/dev/null
/etc/init.d/dsvpn restart >/dev/null 2>/dev/null
fi
/etc/init.d/shadowsocks-libev restart >/dev/null 2>/dev/null
sleep $waittest
break
}
count=$((count+1))
}
config_list_foreach $1 ip set_ip
}
}

View file

@ -49,6 +49,7 @@ retry=${OMR_TRACKER_TRIES:-4}
proxy=${OMR_TRACKER_PROXY:-127.0.0.1:1111}
hosts=${OMR_TRACKER_HOSTS:-1.1.1.1 1.0.0.1}
wait_test=${OMR_TRACKER_WAIT_TEST:-0}
server=${OMR_TRACKER_SERVER:-sss0}
nodns=0
@ -65,9 +66,9 @@ while true; do
}
if [ "$(curl -s -I -w %{http_code} --socks5 ${proxy} --max-time ${timeout} $host -o /dev/null)" != "000" ]; then
nocontact=""
[ "${last}" -ge "${retry}" ] || [ "$(uci -q get openmptcprouter.omr.shadowsocks)" = "" ] && {
[ "${last}" -ge "${retry}" ] || [ "$(uci -q get openmptcprouter.omr.ss_$[name})" = "" ] && {
_log "Shadowsocks is up (can contact via http ${host})"
uci -q set openmptcprouter.omr.shadowsocks="up"
uci -q set openmptcprouter.omr.ss_${name}="up"
uci -q commit openmptcprouter.omr
}
if [ -z "$(iptables -t nat -L -n | grep ss_rules)" ] && [ "$(uci -q get shadowsocks-libev.ss_rules.disabled)" != "1" ]; then
@ -83,15 +84,15 @@ while true; do
[ "${last}" -ge "${retry}" ] && {
if [ -n "$(iptables -t nat -L -n | grep ssr)" ]; then
_log "Shadowsocks is down (can't contact via http ${nocontact})"
uci -q set openmptcprouter.omr.shadowsocks="down"
uci -q set openmptcprouter.omr.ss_${name}="down"
uci -q commit openmptcprouter.omr
/etc/init.d/shadowsocks-libev rules_down 2> /dev/null
[ "$(uci show openmptcprouter.omr | grep ss | grep up)" = "" ] && /etc/init.d/shadowsocks-libev rules_down 2> /dev/null
_get_ip
server_ping=false
server="$(uci -q get shadowsocks-libev.sss0.server)"
_ping_server $server
serverip="$(uci -q get shadowsocks-libev.${server}.server)"
_ping_server $serverip
if [ "$server_ping" = false ]; then
_log "Server ($server) seems down, no answer to ping"
_log "Server $server ($serverip) seems down, no answer to ping"
fi
sleep $wait_test
fi